home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / TextEditors&Viewers / Texteditors / FFRED10.LHA / fpl / Comment.FPL < prev    next >
Encoding:
Text File  |  1994-11-05  |  3.8 KB  |  131 lines

  1. /*****************************************************************************
  2. ******************************************************* LineComment Routine **
  3. *****************************************************************************/
  4.  
  5. export void LineComment()
  6. {
  7.    int        width = ReadInfo("wall_right");
  8.    string    comment = PromptString("","Enter comment","");
  9.    int        col;
  10.    string    output;
  11.    string    startstop = "*";             /* Default chars are for */
  12.    string    body = "*";                     /* assembler mode */
  13.  
  14.    if ((strlen(comment)!=0) && (strlen(comment) < (width - 3 - 3)))
  15.    {
  16.       if (width==0)                         /* Fallback if no right_wall */
  17.       {
  18.          width = 79;
  19.       }
  20.  
  21.       if (ReadInfo("c_mode"))             /* C style comment chars */
  22.       {
  23.          startstop = "/";
  24.          body = "*";
  25.       }
  26.       
  27.       if (ReadInfo("line_length")!=1)     /* Only use newline if not invoked */
  28.       {                                     /* on an empty line */
  29.          End();
  30.          output = "\n";
  31.       }
  32.  
  33.       output = joinstr(output, startstop);
  34.       for (col = 2; col < width; col++)
  35.       {
  36.          output = joinstr(output, body);
  37.       }
  38.       output = joinstr(output, "\n");
  39.  
  40.       for (col = 1; col < (width -2-1-1 - strlen(comment)); col++)
  41.       {
  42.          output = joinstr(output, body);
  43.       }
  44.  
  45.       output = joinstr(output, " ", comment, " ", body, body, "\n");
  46.  
  47.       for (col = 1; col < width-1; col++)
  48.       {
  49.          output = joinstr(output, body);
  50.       }
  51.       Output(joinstr(output, startstop,"\n"));
  52.    }
  53.  
  54. }
  55.  
  56.  
  57. /*****************************************************************************
  58. ******************************************************** EOLComment Routine **
  59. *****************************************************************************/
  60.  
  61. export void EOLComment()
  62. {
  63.    int        cur_col;
  64.    int        dest_col = ReadInfo("comment_column");
  65.    string    output = "";
  66.    int        tabsize = ReadInfo("tab_size");
  67.    int        cursor_left=0;
  68.    int        dest_tabs,dest_spc,needed_tabs;
  69.  
  70.    End();
  71.    cur_col = ReadInfo("column");
  72.    if (cur_col < dest_col)                 /* Insert some tabs'n'spaces to   */
  73.    {                                     /* reach comment column if needed */
  74.       dest_tabs = dest_col/tabsize;
  75.       dest_spc = dest_col - tabsize*dest_tabs -1;
  76.       
  77.       needed_tabs = (dest_tabs*tabsize - cur_col)/tabsize +1;
  78.  
  79.       if (dest_spc>0 && dest_tabs==(cur_col/tabsize)) /* don't ask! :) */
  80.       {
  81.          needed_tabs--;
  82.       }
  83.       
  84.       if (needed_tabs <= 0)                 /* Only space insertion */
  85.       {
  86.          needed_tabs = 0;
  87.          dest_spc = dest_col - cur_col;     /* Recalc amount of spaces */
  88.       }
  89.  
  90.       
  91.       for (;needed_tabs > 0;needed_tabs--) /* Insert tabs */
  92.       {
  93.          output = joinstr(output, "\t");
  94.       }
  95.       
  96.       for (;dest_spc > 0;dest_spc--)     /* Insert spaces */
  97.       {
  98.          output = joinstr(output, " ");
  99.       }
  100.    }   
  101.                                          /* Determine comment type */
  102.    if (ReadInfo("c_mode"))                 /* C style */
  103.    {
  104.       output = joinstr(output, " /*  */");
  105.       cursor_left = 3;
  106.    }
  107.       
  108.    if (ReadInfo("asm_mode"))             /* Assembler style */
  109.    {
  110.       output = joinstr(output, " ;");
  111.    }
  112.    
  113.    Output(output);                         /* Do the output */
  114.    CursorLeft(cursor_left);                 /* and reposition cursor */
  115. }
  116.  
  117. /*****************************************************************************
  118. ****************************************************** Default key bindings **
  119. *****************************************************************************/
  120.  
  121. AssignKey("LineComment();",    "'esc' :");
  122. AssignKey("EOLComment();",    "'esc' ;");
  123.  
  124.  
  125. /*****************************************************************************
  126. ********************************************************** Public variables **
  127. *****************************************************************************/
  128.  
  129. ConstructInfo("comment_column","","","LIW","",1,999,41);
  130. ConstructInfo("wall_right", "", "", "WIL", "", 0, 999, 79);
  131.