home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol076 / wct3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-04-29  |  3.3 KB  |  136 lines

  1. /* 
  2.  
  3. word count program which also calculates column centimetres 
  4. of magazine (or newspaper) copy for would-be contributors. 
  5. Set up for Helvetica Medium phototype which is the body copy 
  6. used in Your Computer magazine, but can be easily changed 
  7. for others. Original structure taken from `The C Programming 
  8. Language', and substantially modified since then by Les Bell and
  9. Matt Whelan...
  10.  
  11. Version 1.02, 20/7/82
  12. */
  13.  
  14.  
  15. #include    <b:bdscio.h>
  16.  
  17. #define    YES    1
  18. #define    NO    0
  19. #define    EOF    0x1a
  20. #define ERROR    -1
  21. #define MASK    0x7f
  22.  
  23. char toupper();        
  24.  
  25. main(argc,argv)    /* count lines, words, chars in input file */
  26. char    **argv;
  27. {
  28.     int c, nl, nw, nc, inword, fd, m;
  29.     char    buf[BUFSIZ];
  30.  
  31.     if(argc != 2) {
  32.         printf("Usage: wc filename\n");
  33.         exit();
  34.     }
  35.  
  36.     if((fd = fopen(argv[1],buf)) == ERROR) {
  37.         printf("cannot open: %s\n",argv[1]);
  38.         exit();
  39.     }
  40.     inword = NO;
  41.     nl = nw = nc = 0;
  42.     while ((c = (getc(buf) & MASK)) != EOF)
  43.     {
  44.         ++nc;
  45.         if (c == '\n')
  46.             ++nl;
  47.         if (c == ' ' || c == '\n' || c == '\t' || c == 0x0d)
  48.             inword = NO;
  49.         else if (inword == NO) {
  50.             inword = YES;
  51.             ++nw;
  52.         }
  53.     }
  54.     menu();
  55.     while (m != "5") {                 /* the m!=5 is irrelevant, but at
  56.                           least sets up the loop */
  57.     printf("\n\nWhich would you like?   : ");
  58.     m = getchar();
  59.         switch (toupper(m)) {
  60.  
  61.         case '1':
  62.             printf("\n\n\n");
  63.             printf("\t\tnumber of chars = %d\n",nc);
  64.             printf("\t\tnumber of lines = %d\n",nl);
  65.             printf("\t\tnumber of words = %d\n",nw);
  66.             printf("\t\tcolumn centimetres = %d\n",nw/20);
  67.             break;
  68.         case '2':
  69.             printf("\n\n\n");
  70.             printf("\t\tnumber of chars = %d\n",nc);
  71.             printf("\t\tnumber of lines = %d\n",nl);
  72.             printf("\t\tnumber of words = %d\n",nw);
  73.             printf("\t\tcolumn centimetres = %d\n",nw/24);
  74.             break;
  75.         case '3':
  76.             printf("\n\n\n");
  77.             printf("\t\tnumber of chars = %d\n",nc);
  78.             printf("\t\tnumber of lines = %d\n",nl);
  79.             printf("\t\tnumber of words = %d\n",nw);
  80.             printf("\t\tcolumn centimetres = %d\n",nw/12);
  81.             break;
  82.         case '4':
  83.             printf("\n\n\n");
  84.             printf("\t\tnumber of chars = %d\n",nc);
  85.             printf("\t\tnumber of lines = %d\n",nl);
  86.             printf("\t\tnumber of words = %d\n",nw);
  87.             printf("\t\tcolumn centimetres = %d\n",nw/28);
  88.             break;
  89.         case 'X':
  90.             printf("\n\n\n");
  91.             printf("\t\tnumber of chars = %d\n",nc);
  92.             printf("\t\tnumber of lines = %d\n",nl);
  93.             printf("\t\tnumber of words = %d\n",nw);
  94.             printf("\n\nbibi\n");
  95.             exit();
  96.         case 'M':
  97.             menu();
  98.             break;
  99.         default:
  100.             putch(7);
  101.             printf("\n\nEnter 1-4 for measure, M for menu");
  102.             break;
  103.             }
  104.         }
  105. }
  106.  
  107. menu()
  108. {
  109.     printf(CLEARS);        /* Hope you have screen-clear defined
  110.                    in bdscio.h                */ 
  111.     printf("\n\n\n\n");
  112.     printf("\t\tSELECT:\n");
  113.     printf("\n\n");
  114.  
  115.     printf("\t\t<1> ---> 9/10 x 13 1/2 ems\n");   /*9point type, 1point
  116.                             leading - the standard 
  117.                             3-column type used in the
  118.                             magazine                */
  119.  
  120.     printf("\t\t<2> --->  8/9 x 13 1/2 ems\n");   /*slightly smaller type 
  121.                             over same column with 
  122.                             - used for copy with 
  123.                             "pocket programs"*/
  124.  
  125.     printf("\t\t<3> ---> 9/10 x  9 1/2 ems\n");   /*normal type size, 
  126.                             narrow column width 
  127.                             for news and "clinic" 
  128.                             pages */
  129.  
  130.     printf("\t\t<4> ---> 9/10 x 20 1/2 ems\n");   /* 2-column (1/2-page) 
  131.                              width*/
  132.  
  133.     printf("\t\t<X> ---> ++ eXit ++\n");
  134.  
  135. }
  136.