* RFR005.QM * Written By Tom Hogshead * [ See RFRMxx.QM For Use ] * 8/23/91 * Key Subfile Description * ===== =============== ==================================================== * @(0) Count Words in a File * @(3) Alternate version of @0 by John Goodman * @(1) Count Characters in a Block * @(2) Count Characters in a File * @(4) Count Words in a Block by John Goodman * * {e:\up\RFRM*}--Return To RFRMxx.QM * (Calibrated) Test File * *-- eoi *  * -------------------------------------- * @(0) Macro To Count Words In File * -------------------------------------- * This macro counts the number of words in a File. A word is * defined as a string of characters contained in either the * DefaultWordSet or AltWordSet separated by a word delimiter. The * number of words in the File equal the number of lines in the NUL * file after execution. * @0 differs from @9 in that @9 considers a "word" to be at least one * letter or number separated by a space or the following word * separators: !@#$%^&*'()+|-=\,./;'[]<>?:"{} ... @9 counts words like * "can't" as two words; @0 counts them as one word. * Test macro using the calibrated file WORD (41 words). * [ Number of WORDS in File ] = [ Number of LINES in temp file ] @0 Macrobegin AltWordSet UnMarkBlock EndLine Dropanchor StoreScrBuff "c" Return BegFile LOOP: MarkWord jfalse 1: AppendScrBuff "c" Return 1: WordRight jtrue LOOP: EditFile "NUL" Return Quit EditFile Return GetScrBuff "c" Return UnMarkBlock DefaultWordSet BegFile DelLine EndFile * * 82 bytes Wed 02-20-1991 16:54:02 * 83 bytes Mon 07-15-1991 11:06:17 (TH @0, changed ! to NUL) * 45 bytes Wed 08-21-1991 23:55:04 (TH @0) *  * ---------------------------------------------------------------------- * @(1) Count Number Of Characters In A Block * ---------------------------------------------------------------------- * To: Mike Butler, RelayNet, May 4, 1991 15:16:09 * MB> Is there any way to create a macro to count the number of * MB> characters in a block? * This QEdit macro determines a block's byte size and provides a means * to calculate the Number of Characters in a block. Block Byte Size can * be useful for uploading CompuServe files where upload file descriptions * are limited to 465 bytes: * Block Byte Size = Size of block if it were a file * Character Count = (Block Byte Size) minus 2 x (Number of Lines) * Mark a block. Block need not be closed. Block byte size will be shown in * a window and in front of the last line of a copy of the block. Press * to remove the window from the screen and return to the our * starting point. To determine the number of actual characters in a block, * including spaces between text, subtract 2 x (number of lines in window) * from (byte size). The paragraph below with asterisks is 274 bytes, and * has 274 - 4 x 2 = 266 characters including spaces. * NOTE: c:temp and c:dir are temporary files created and deleted from the * disk. Rename files and run QMAC if this causes problems. This macro has * only been tested with DOS 3.3. SaveFile is used rather than WriteBlock * in case c:temp and c:dir exist before running. @1 Macrobegin Editfile "c:temp" Return * Load temp file killfile Quit * Kill/quit c:temp EditFile Return * Load empty c:temp Copyblock * Copy block to temp file EndFile DelLine * Delete extra blank line Savefile * Save temp file to get size DOS "Dir " Currentfilename * Get DIR list of c:temp ">C:dir" Return Return * Save DIR list of c:temp Editfile "C:dir" Return * Load DIR list Gotoline "5" Return * CursorDown to c:temp line Wordright Markword Copy * Copy size to scrap Killfile Quit * Kill/quit c:dir Editfile "c:temp" Return * Load c:temp Killfile * Kill it Endfile Begline * "Block size=" Paste * Paste block size at bottom Makebotofscreen * Re-position Pause * Press to remove block size Quit * Character Count = Block Size * minus 2 x Number of Lines * 114 bytes Sat 05-04-1991 15:15:25 * The following macro counts the number of characters in a File. After * running, the byte size of the File *without* spaces is shown in * column 1 on the last line. Subtract 2 x number of lines from the byte * size to get the number of actual characters in the File. *  * ---------------------------------------------------------------------- * @(2) Count Number Of Characters In A File * ---------------------------------------------------------------------- @2 Macrobegin UnMarkBlock * Un-mark all blocks BegFile Markblockbegin * Mark File EndFile Markblockend * Editfile "c:temp" Return * Load empty c:temp Killfile Quit * Kill/quit c:temp Editfile Return * Load empty temp file Copyblock Unmarkblock * Copy File to temp file Findreplace " " Return * Replace all single spaces DelLine Return "GN" Return * With Blanks, globally DELBLANKLINES: * Begfile * Get to begin of file CHK4BLANK: * Endline Begline * Check if line has text Jtrue NOTBLANK: * If so, go to NOTBLANK Delline * Or line is blank, delete it Jtrue CHK4BLANK: * Go check next line NOTBLANK: * Endpara *ELSE Move to paragraph end Cursordown * Move down to next line Jtrue CHK4BLANK: * If not eof, check again GETCOUNT: * Savefile * Save temp file to get size DOS "DIR " Currentfilename * Get DIR list of c:temp ">C:dir" Return Return * Save DIR list of c:dir Editfile "C:dir" Return * Load DIR list Gotoline "5" Return * Cursordown to c:temp line Wordright Markword Copy * Copy size to scrap Killfile Quit * Kill/quit c:dir Editfile "c:temp" Return * Load compressed c:temp Killfile * Kill c:temp disk copy Begline "Byte size=" Paste * Paste byte size at bottom Makebotofscreen * Re-position Pause * Press to remove window Quit * Character Count = Byte Size * minus 2 x Number of Lines * 92 bytes Wed 02-20-1991 17:02:29 * 141 bytes Sat 05-04-1991 15:38:07 changed temp file names, added pause * corrected gotoline "5" *  * --------------------------------------------- * @(3) Count Words in File * Alternate version of @0 by John Goodman * --------------------------------------------- * This macro will count the number of words in the current file. A * word is considered to be a sequence of one or more characters in * the AltWordSet delimited by at least one character that is not in * the AltWordSet (this definition should suffice for most * applications). The number of words in the file is displayed in a * separate window after they have been counted. When the Enter key * is pressed, the word count display will be removed and the cursor * will be positioned at the top of the original file. The macro * should work consistently regardless of mode toggle or QConfig * settings and will not change the edit status of the original * file. The macro does, however, set the word character set to * DefaultWordSet at the end of the macro. * @3 MacroBegin AltWordSet * Use alternate word character set UnmarkBlock BegFile * Remove blocks and start at top OneWindow * Remove any windows EditFile * Use the NUL file for counting "NUL" Return Quit * Make sure NUL file is empty HorizontalWindow * Create window for counting EditFile Return * Re-edit the NUL file DropAnchor * Start a block "0123456789" * Type digits 0-9 Copy BegLine * Make six copies of digits line Paste 6 MarkCharacter * Copy the digits w/out EOL char EndLine Copy UnmarkBlock PrevWindow * Return to original file MAINLOOP: * Loop for each word in file MarkWord * Test if a word at cursor position JFalse NEXTWORD: * If not, skip to next word NextWindow * Go to counting window EndFile BegLine * Go to ones digit position INCRLOOP: DelCh * Delete (increment) the current digit EndLine * Test if any digits remaining JTrue INCRDONE: Paste * Re-paste the 0-9 string UnmarkBlock CursorUp * Go to up next significant digit Jump INCRLOOP: * Increment next significant digit INCRDONE: PrevWindow * Return to original file NEXTWORD: WordRight * Go to next word right JTrue MAINLOOP: * If no words to right, display count BegFile * Return to beginning of original file NextWindow * Go to count window BegFile CursorRight * Go to top of 2nd column MarkColumn * Delete all but column 1 EndLine PageDown DeleteBlock JOINLOOP: * Join column 1 into a single line CursorUp JFalse PROMPT: JoinLine Jump JOINLOOP: PROMPT: EndLine * Go to end of count and display prompt " Words... Press to Continue" Pause * Wait for user to press Enter Quit CloseWindow * Delete the NUL file and close window DefaultWordSet * Reset default word set characters * * 167 bytes Fri 08-23-1991 21:29:35 (JG @3) *  * --------------------------------- * @(4) Count Words in Marked Block * --------------------------------- * This macro will count the number of words in the currently marked * block. Any type of block may be used and both block end points * need not be set. A word is considered to be a sequence of one or * more characters in the AltWordSet delimited by at least one * character that is not in the AltWordSet (this definition should * suffice for most applications). The number of words in the block * is displayed in a separate window after they have been counted. * When the Enter key is pressed, the word count display will be * removed and the cursor will be positioned at its original * location in the file (the original block will be unmarked). The * macro should work consistently regardless of mode toggle or * QConfig settings and will not change the edit status of the * original file. The macro does, however, set the word character * set to DefaultWordSet at the end of the macro. * @4 MacroBegin AltWordSet * Use alternate word character set OneWindow * Remove any windows EditFile * Use the NUL file for counting "NUL" Return Quit * Make sure NUL file is empty HorizontalWindow * Create window for counting EditFile Return * Re-edit the NUL file CopyBlock * Copy the block of text to NUL file JFalse END: * If no block, exit UnmarkBlock * Unmark the block SplitLine * Put blank line at top DropAnchor * Start a block "0123456789" * Type digits 0-9 Copy BegLine * Make six copies of digits line Paste 6 MarkCharacter * Copy the digits w/out EOL char EndLine Copy UnmarkBlock BegFile * Go to beginning of text CursorDown 7 MAINLOOP: * Loop for each word in file DeleteBlock * Delete the last word processed MarkWord * Test if a word at cursor position JFalse NEXTWORD: * If not, skip to next word CursorUp BegLine * Go to ones digit position INCRLOOP: DelCh * Delete (increment) the current digit EndLine * Test if any digits remaining JTrue INCRDONE: Paste * Re-paste the 0-9 string UnmarkBlock CursorUp * Go to up next significant digit Jump INCRLOOP: * Increment next significant digit INCRDONE: BegFile * Return to beginning of text CursorDown CursorDown * Many cursordowns instead of displaying CursorDown CursorDown * RepeatCmd prompt box many times CursorDown CursorDown CursorDown NEXTWORD: MarkCharacter * Block last word processed to delete it WordRight * Go to next word right JTrue MAINLOOP: * If no words to right, display count UnmarkBlock BegFile CursorRight * Go to top of 2nd column MarkColumn * Delete all but column 1 EndLine PageDown DeleteBlock JOINLOOP: * Join column 1 into a single line CursorUp JFalse PROMPT: JoinLine Jump JOINLOOP: PROMPT: EndLine * Go to end of count and display prompt " Words... Press to Continue" Pause * Wait for user to press Enter END: Quit CloseWindow * Delete the NUL file and close window DefaultWordSet * Reset default word set characters * * 183 bytes Fri 08-23-1991 17:45:40 (JG @4) * (Calibrated) Test File, 41 Words with @0 and @3 * 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴� WORD 컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커 * � 1 2 3 � * � � * � ! @ # $ % ^ & * ' ( ) + | - = \ , . / ; ' [ ] < > ? : " { } � * � � * � !@#$%^&*'()+|-=\,./;'[]<>?:"{} � * � � * � 4 5 6 � * � 126__Characters 41_Words(W/@0) 41_Words(W/@3) 7 8 9 aa � * � � * � __ Characters � * 읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴�