home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / ONPOSTREFORMAT.SCRIPT < prev    next >
Encoding:
Text File  |  2001-06-19  |  2.4 KB  |  90 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 287 cm19990409 - added endLine parameter to CleanupMultilineComment
  4. /**
  5. @Event: onPostReformat~is called to allow custom modifications
  6. after a file has been reformatted. This script is called after
  7. the normal reformat has been completed. This implementation 
  8. just cleans up multiline comments by aligning all '*' in a 
  9. muliline comment that uses a '*' at the begining of each line.
  10. @EndTool:
  11. @Summary: onPostReformat~is called to adjust formatting 
  12. */
  13.  
  14. var gOutput = getOutput();
  15.  
  16. function DoCommand()
  17. {
  18.     var editor = getActiveEditor();
  19.     if (editor)
  20.     {
  21.         OnEvent(editor);
  22.         editor.setActive("PostReformat");
  23.     }
  24. }
  25.  
  26. function OnEvent(editor)
  27. {    
  28.     var startCommentData = editor.findFirst("<%", 0, 0);
  29.     while (startCommentData && startCommentData.found)
  30.     {
  31.         //gOutput.writeLine("Start = " + startCommentData.startLineIndex);
  32.         var endCommentData = editor.findFirst("%>", startCommentData.startLineIndex, startCommentData.startCharIndex);
  33.         if (endCommentData && endCommentData.found)
  34.         {
  35.             if (endCommentData.startLineIndex > startCommentData.startLineIndex)
  36.             {
  37.                 var nextLine = CleanupMultilineComment(editor, 
  38.                     startCommentData.startLineIndex, endCommentData.startLineIndex); //cm19990409
  39.                 startCommentData = editor.findFirst("<%", nextLine, 0);
  40.             }
  41.             else
  42.             {
  43.                 startCommentData = editor.findFirst("/*", endCommentData.startLineIndex+1, 0);
  44.             }
  45.             
  46.             //gOutput.writeLine("End = " + endCommentData.startLineIndex);
  47.         }
  48.         else
  49.         {
  50.             break;
  51.         }
  52.     }
  53.     return true;
  54. }
  55.  
  56. var gFirstRegExp = /(\s*\/\*)/;
  57. var gInnerRegExp = /(\s*\*)/;
  58.  
  59. function CleanupMultilineComment(editor, startLine, endLine) //cm19990409
  60. {
  61.     var indentLevel = editor.getIndentLevel(startLine);
  62.     var lineData = editor.copy(startLine);
  63.     if (gFirstRegExp.exec(lineData))
  64.     {
  65.         var length = RegExp.$1.length; 
  66.         startLine += 1;
  67.         editor.setIndentLevel(startLine, indentLevel);
  68.         lineData = editor.copy(startLine);                
  69.         while (gInnerRegExp.exec(lineData) && startLine <= endLine)
  70.         {
  71.             var commentIndent = RegExp.$1.length; 
  72.             if (commentIndent < length)
  73.             {
  74.                 editor.replace(" ", startLine, commentIndent-1, startLine, commentIndent-1);
  75.             }
  76.             startLine += 1;
  77.             lineData = editor.copy(startLine);        
  78.         }
  79.     }
  80.     else
  81.     {
  82.         startLine += 1;
  83.     }
  84.     return startLine;
  85. }
  86.  
  87.  
  88. !!/Script
  89.  
  90.