home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / DOS / TEKST / AURORA2 / COUNTCHR.AML < prev    next >
Text File  |  1995-04-28  |  3KB  |  99 lines

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