home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 141_01 / punct.c < prev    next >
Text File  |  1985-03-10  |  5KB  |  173 lines

  1. /* PUNCTUATION ERROR FINDER PROGRAM */
  2. /* r p sarna                     */
  3. /* 11 feb 84                      */
  4.  
  5. /* FINDS:                                       */
  6. /* periods, etc., proceeded by spaces           */
  7. /* periods, etc., not followed by spaces        */
  8. /* number of '(' and ')' and "                  */
  9. /* Sentences not beginning with capital letters */
  10.  
  11. #define VERSION "1.11"
  12.  
  13. #define COMMA ','
  14. #define PERIOD '.'
  15. #define LPAREN '('
  16. #define RPAREN ')'
  17. #define ON 1
  18. #define OFF 0
  19.  
  20. #include <bdscio.h>
  21.  
  22. main(argc,argv)
  23. char **argv;
  24. {
  25.     char ibuf[BUFSIZ];
  26.     char end_of_file;
  27.     char curr;
  28.     int icurr;
  29.     char prev;
  30.     int linefeed;
  31.     int leftparen;
  32.     int rightparen;
  33.     unsigned num_of_chars;
  34.     int line_num;
  35.     char period_flag;
  36.     int quotes;
  37.  
  38.     if ((strcmp(argv[1], "help") == 0) || (strcmp(argv[1],"HELP") == 0)) {
  39.         printf("\n%cPUNCTUATION ",0x1A);
  40.         printf("     r p sarna   Version %s\n", VERSION);
  41.         printf("\nThis program checks for improper punctuation.\n");
  42.         printf("\nThe program checks for:");
  43.         printf("\n     periods preceeded by a space");
  44.         printf("\n     commas preceeded by a space");
  45.         printf("\n     exclamation marks preceeded by a space");
  46.         printf("\n     question marks preceeded by a space");
  47.         printf("\n     periods not followed by a space");
  48.         printf("\n     commas not followed by a space");
  49.         printf("\n     exclamation points not followed by a space");
  50.         printf("\n     question marks not followed by a space");
  51.         printf("\n     unequal number of left and right parentheses");
  52.         printf("\n     odd number of quotes marks\n");
  53.         printf("\n\n     Note: characters are counted only up to 65,535 -- ");
  54.                 printf(  "\n           the count then starts over");
  55.         printf("\n\nUsage: A>punct d:filename.typ\n\n");
  56.         exit();
  57.     }
  58.  
  59.     if (argc != 2) {
  60.         printf("\nUsage: A>punct d:filename.typ \n");
  61.         printf("\n    or A>punct help\n\n");
  62.         putchar(7);
  63.         exit();
  64.     }
  65.  
  66.     if (fopen(argv[1], ibuf) == ERROR) {
  67.         printf("\n***** ERROR: can't find %s\n", argv[1]);
  68.         putchar(7);
  69.         exit();
  70.     }
  71.     
  72.     printf("\n\nPUNCTUATION CHECK PROGRAM  --  r p sarna  -- Ver. %s\n", VERSION);
  73.  
  74.     prev = ' ';
  75.     end_of_file = NO;
  76.     leftparen = 0;
  77.     rightparen = 0;
  78.     quotes = 0;
  79.     line_num = 1;
  80.     num_of_chars = 1;
  81.     period_flag = ON;
  82.     end_of_file = NO;
  83.  
  84.     while (end_of_file == NO) {
  85.  
  86.         if ((icurr = getc(ibuf)) == ERROR || (icurr == CPMEOF)) { 
  87.             end_of_file = YES;
  88.             continue;
  89.         }
  90.  
  91.         curr = icurr;
  92.  
  93.         if ((icurr == 0x0D) || (icurr == 0x8D)) {
  94.             line_num++;
  95.             prev = ' ';
  96.             curr = ' ';
  97.             continue;
  98.         }
  99.  
  100.         if (curr == 0x0A) continue;
  101.  
  102.         curr = curr & 0x7F;
  103.  
  104.         if (curr == '\t') curr = ' ';
  105.                                                    
  106.         num_of_chars++; 
  107.  
  108.         if ((prev == PERIOD) && (curr != ' '))
  109.             printf("\n*** ERROR-- no space after period in line number %d", line_num); 
  110.         ;
  111.  
  112.         if ((prev == '!') && (curr != ' '))
  113.             printf("\n*** ERROR-- no space after exclamation point in line number %d", line_num); 
  114.         ;
  115.  
  116.         if ((prev == '?') && (curr != ' '))
  117.             printf("\n*** ERROR-- no space after question mark in line number %d", line_num); 
  118.         ;
  119.  
  120.         if ((prev == ',') && (curr != ' '))
  121.             printf("\n*** ERROR-- no space after comma in line number %d", line_num); 
  122.         ;
  123.  
  124.         if ((curr == PERIOD) && (prev == ' '))
  125.             printf("\n*** ERROR-- space before period in line number %d", line_num );
  126.         ;    
  127.  
  128.         if ((curr == '?') && (prev == ' '))
  129.             printf("\n*** ERROR-- space before question mark in line number %d", line_num );
  130.         ;    
  131.  
  132.         if ((curr == '!') && (prev == ' '))
  133.             printf("\n*** ERROR-- space before exclamation point in line number %d", line_num );
  134.         ;    
  135.  
  136.         if ((curr == COMMA) && (prev == ' ')) 
  137.             printf("\n*** ERROR-- space before comma in line number %d", line_num);
  138.         ;
  139.  
  140.         if ((period_flag == ON) && (curr != ' ') && (curr > 0x5A))
  141.              printf("\n*** ERROR-- First letter of sentence not capitalized in line %d", line_num);
  142.         ;
  143.  
  144.         if ((period_flag == ON) && (curr > '!')) period_flag = OFF;
  145.  
  146.         if ((curr == PERIOD) || (curr == '!') || (curr == '?')) period_flag = ON;
  147.  
  148.         if (curr == LPAREN) leftparen++;
  149.  
  150.         if (curr == RPAREN) rightparen++;
  151.  
  152.         if (curr == '"' ) quotes++;
  153.  
  154.         prev = curr;
  155.  
  156.  
  157.     }
  158.  
  159.  
  160.     close(ibuf);
  161.  
  162.     printf("\n\nThere were %d left parentheses and %d right parentheses in '%s'", leftparen, rightparen, argv[1]);
  163.  
  164.     if (leftparen != rightparen) printf("\n**** NOTE: '%s' has unbalanced parentheses!!", argv[1]);
  165.  
  166.     printf("\n\nThere were %d quotes marks (%c) in '%s'", quotes, 0x22, argv[1]);
  167.  
  168.     if (quotes & 0x01) printf("\n**** NOTE: odd number of quotes used.");
  169.  
  170.     printf("\n\nThere were %d characters and %d lines in '%s'\n\n\n", num_of_chars, (line_num - 1), argv[1]);
  171.  
  172. }
  173.