! comments.tes - Macro to convert C style comments to C++ style comments ! ! Note, this will handle nested comments but may get tripped up on quoted ! ! text with /* or */'s. You are welcome to add this as an exercize ! !COMMENTS.TEC! ! define macro name SQU will leave this in ! ! Uses Q-Registers R and L ! [R [L ! save R and L ! < ! loop ! W ! refresh screen ! :@S~*/~; ! search for right side of /*...*/ ! ! exit loop if right side not found ! .UR ! remember pointer position after */ ! -:@S~/*~"F ! if not search backwards for left end of /*...*/ ! @^A~Illegal nesting of /*...*/ ~ 0; ! exit loop ! ' ! endif ! W ! refresh the screen ! .+^Q-QR"G ! if left and right ends on same line ! -@FS~*~/~ ! replace * of /* with / to give // ! @FD~^E#^ES*/^E#^ES~ ! delete []*/[] ! ::@S~^M^J~"F ! if does not follow ! @I~ ~ ! insert ! ' ! endif ! W ! refresh the screen ! ! finished processing /*...*/ on same line ! F< ! go back to start of loop ! ' ! endif /*...*/ on same line ! ! if we are here we have /* followed by one or more [text]'s ! .UL ! remember pointer following /* ! @FD~^E#^ES*/^E#^ES~ ! replace []*/[] with nothing ! ! do an anchored search for , if not found insert ! ::@S~^M^J~"F@I~ ~' W ! refresh the screen ! ! search backwards towards /* replacing [][] ! ! with // (except of course for the to left of pointer ! ! start an inner loop ! < -2L ! backup 2 lines ! QL-.; ! exit inner loop if we went before /* ! ! replace [] with // ! @FS~^E#^ES ~ //~ W ! refresh the screen ! > ! end the inner loop ! ! at this point we have the /* line (and the one after that) to fix ! @FS~/*~//~ ! replace the /* with // ! ::@S~^E#^ES^M^J~"T ! if /* (now //) followed by [] ! @FR~ //~ ! replace [] with // ! | ! else ! L ! go to start of next line ! @I~//~ ! insert the missing // ! ' ! endif ! W ! refresh the screen ! > ! end the outer loop ! ! all done, better see how well we munged things up ! @^A~All done ~ ]L ]R ! restore L and R !