home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / countchr.aml < prev    next >
Text File  |  1995-08-10  |  3KB  |  98 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        COUNTCHR.AML                                         */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro counts the number of characters in the    */
  6. /*               current file or in a marked block (if one exists).   */
  7. /*               The total number of characters reported is the       */
  8. /*               number of bytes that the file or marked block would  */
  9. /*               occupy on disk if it were saved (including delimiter */
  10. /*               chars).                                              */
  11. /*                                                                    */
  12. /* Usage:        Select this macro from the Macro List (on the Macro  */
  13. /*               menu), or run it from the macro picklist <shift f12> */
  14. /* ------------------------------------------------------------------ */
  15.  
  16.   include bootpath "define.aml"
  17.  
  18.   var total_char
  19.  
  20.   // edit windows only
  21.   if not wintype? "edit" then
  22.     msgbox "Edit windows only!"
  23.     return
  24.   end
  25.  
  26.   // if nothing is marked, then temporarily mark the whole file
  27.   if mark? then
  28.     if getcurrbuf <> getmarkbuf then
  29.       msgbox "Mark must be in current window"
  30.       return
  31.     end
  32.   else
  33.     tempmark = TRUE             // flag indicating temporary mark
  34.     markline 1 (getlines)       // mark entire file
  35.   end
  36.  
  37.   marktype = getmarktype        // get the mark type
  38.   firstline = getmarktop        // get the top line of the mark
  39.   lastline = getmarkbot         // get the bottom line of the mark
  40.   currbuf (getmarkbuf)          // make marked buffer the current buffer
  41.   pushcursor                    // save cursor position
  42.   row (getmarktop)              // goto the top of the marked block
  43.  
  44.   // do for all lines in the mark
  45.   repeat
  46.  
  47.     total_char = total_char +   // add size to total
  48.  
  49.       case marktype
  50.  
  51.         // line marks
  52.         when 'l'
  53.           getlinelen
  54.  
  55.         // column marks
  56.         when 'k'
  57.           sizeof (gettext (getmarkleft) (getmarkcols))
  58.  
  59.         // character/stream marks
  60.         otherwise
  61.           if getrow == firstline then
  62.             sizeof (gettext (getmarkleft)
  63.                           (if firstline == lastline then
  64.                              getmarkcols
  65.                            end))
  66.           elseif getrow == lastline then
  67.             sizeof (gettext 1 (getmarkright))
  68.           else
  69.             getlinelen
  70.           end
  71.       end
  72.  
  73.   until not down or getrow > lastline
  74.  
  75.   // restore cursor position
  76.   popcursor
  77.  
  78.   // compute the space that would be occupied by delimiter
  79.   // characters if the marked block was saved (zero for binary files)
  80.   if not getbinarylen then
  81.     delimitspace = getmarkrows * (sizeof (hex2bin _LineDlm))
  82.   end
  83.  
  84.   // destroy mark if temporary
  85.   if tempmark then
  86.     destroymark
  87.   end
  88.  
  89.   display
  90.  
  91.   // display the totals
  92.   shortbox (if? tempmark "Entire file: " "Marked Block: ") +
  93.            (thousands total_char + delimitspace) + " chars (" +
  94.            (thousands total_char) + " text + " +
  95.            (thousands delimitspace) + " delimiter)"
  96.          "Character Count"
  97.  
  98.