home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / hamradio / vefc24.zip / VEFC.C < prev    next >
Text File  |  1989-12-27  |  10KB  |  282 lines

  1. /**********************************************************************/
  2. /***  vefc.c                            WA8YCD  ***/
  3. /***  Ver 2.4                                            02 Sep 89  ***/
  4. /***                                    ***/
  5. /***  This utility provides a counting aid, a character inclusion   ***/
  6. /***  list, and sending time at 5, 13, and 20 wpm.            ***/
  7. /***                                    ***/
  8. /***  usage:    vefc textfile reportfile    [report to file]        ***/
  9. /***     or    vefc textfile            [report to screen]        ***/
  10. /***     or    vefc textfile > prn        [report to printer]     ***/
  11. /***  ____________________________________________________________  ***/
  12. /***  Change history:                            ***/
  13. /***  890505 WA8YCD   1.0 - original version--exclusions only        ***/
  14. /***  890521 WA8YCD   2.0 - display input with count columns        ***/
  15. /***  890525 WA8YCD   2.1 - include AND exclude list in report        ***/
  16. /***  890902 WA8YCD   2.2 - add counts to report for each letter    ***/
  17. /***  890908 WA8YCD   2.3 - Oops-Didn't print counts if all letters ***/
  18. /***                        were there. Also print input file name. ***/
  19. /***  891227 WA8YCD   2.4 - Latest data says numbers, punctuation,  ***/
  20. /***                        and prosigns ALL count as 2. Also, the  ***/
  21. /***                        newest SuperMorse (SM305) uses "=" not  ***/
  22. /***                        "-" for <BT> now.                       ***/
  23. /***  ____________________________________________________________  ***/
  24. /***  Copyright (c) 1989 Robert L. West, Jr., WA8YCD            ***/
  25. /***  Distribution of this program is allowed provided no monetary  ***/
  26. /***  compensation beyond reasonable reproduction costs is made.    ***/
  27. /***  It is provided as a public service to the amateur community.  ***/
  28. /***  ____________________________________________________________  ***/
  29. /***  Compiled using Turbo C Version 2.0 under MS-DOS 3.3           ***/
  30. /***  Turbo C (tm) Borland International. MS (r) MicroSoft Corp.    ***/
  31. /**********************************************************************/
  32.  
  33. #include <stdio.h>
  34.  
  35. #define  MIN_LTR      65
  36. #define  MAX_LTR      91
  37.  
  38. #define  MIN_NUM      48
  39. #define  MAX_NUM      58
  40.  
  41. #define  SK           36
  42. #define  COMMA        44
  43. #define  PERIOD       46
  44. #define  DN          47
  45. #define  BT           61           /* 2.4 */
  46. #define  QUERY        63
  47. #define  AR          64
  48.  
  49. #define  LENGTH_5     25
  50. #define  LENGTH_13    65
  51. #define  LENGTH_20   100
  52.  
  53. #define  TRUE           1
  54. #define  FALSE           0
  55.  
  56. main(argc, argv)
  57. int argc;
  58. char *argv[];
  59. {
  60.   int     i, no_zeros=1, output_to_file;
  61.   long     inch=0, counts[256];
  62.   float  test_time_5, test_time_13, test_time_20;
  63.   char    c;
  64.   FILE  *fopen(), *infile, *outfile;
  65.  
  66. /* first, see if the correct number of parameters are given... */
  67.   if (argc < 2)
  68.   { printf("\nusage:\n    freq input-filename [output-filename]\n");
  69.     printf("\n   if output-filename is omitted display appears \n");
  70.     printf("   on the screen.\n\n");
  71.     exit();
  72.   }
  73.  
  74. /* next, see if the first parameter can be opened as an input file... */
  75.   if ((infile = fopen(argv[1], "rb")) == NULL)
  76.   { printf("\nUnable to open input file, \"%s\"!\n\n", argv[1]);
  77.     printf("vefc:  abnormal termination.\n");
  78.     exit();
  79.   }
  80.  
  81. /* now, see if the second parameter can be opened as an output file... */
  82.   if (argc == 3)
  83.   { if ((outfile = fopen(argv[2], "w")) == NULL)
  84.     { printf("\nUnable to open output file, \"%s\"!\n\n", argv[2]);
  85.       printf("vefc:  abnormal termination.\n");
  86.       exit();
  87.     }
  88.   }
  89.   else
  90.   { if ((outfile = fopen("CON", "w")) == NULL)
  91.     { printf("\nUnable to open console for output!\n\n");
  92.       printf("vefc:  abnormal termination.\n");
  93.       exit();
  94.     }
  95.   }
  96.  
  97. /*************************************************************************/
  98. /***                                       ***/
  99. /*************************************************************************/
  100.  
  101.   fprintf(outfile, "- VE CODE EXAM VALIDATER ver 2.4,  12/27/89 -\n");
  102.   fprintf(outfile, "   Input File: \"%s\"\n", argv[1]);
  103.   fprintf(outfile, "\n");
  104.   fprintf(outfile, "        ");
  105.   fprintf(outfile, "....5...10...15...20...25");
  106.   fprintf(outfile, "        ");
  107.   fprintf(outfile, "...30...35...40...45...50\n");
  108.   fprintf(outfile, "%7ld ", inch);
  109.  
  110.   for (i=0; i<256; i++)
  111.     counts[i]=0;
  112.  
  113.   while((c=getc(infile)) != EOF)
  114.   {
  115.     if (c>='a' && c<='z')
  116.       c=c-'a'+'A';
  117.  
  118.     switch((int)c)
  119.     {
  120.       case 'A': case 'F': case 'K': case 'P': case 'U':
  121.       case 'B': case 'G': case 'L': case 'Q': case 'V':
  122.       case 'C': case 'H': case 'M': case 'R': case 'W':
  123.       case 'D': case 'I': case 'N': case 'S': case 'X':
  124.       case 'E': case 'J': case 'O': case 'T': case 'Y':
  125.       case 'Z':
  126.     counts[(int)c]++;
  127.     fprintf(outfile, "%c", c);
  128.         if  ( !(++inch % 50) )
  129.         { fprintf(outfile, "\n%7ld ", inch); }
  130.         else { if  ( !(inch % 25) )
  131.                  fprintf(outfile, "        "); }
  132.     break;
  133.  
  134.       case '0': case '1': case '2': case '3': case '4':
  135.       case '5': case '6': case '7': case '8': case '9':
  136.       case '/': case '@': case '$': case '=':
  137.       case '.': case ',': case '?':
  138.     counts[(int)c]++;
  139.     fprintf(outfile, "%c", c);
  140.         if  ( !(++inch % 50) )
  141.         { fprintf(outfile, "\n%7ld ", inch); }
  142.         else { if  ( !(inch % 25) )
  143.                  fprintf(outfile, "        "); }
  144.     fprintf(outfile, "_");
  145.         if  ( !(++inch % 50) )
  146.         { fprintf(outfile, "\n%7ld ", inch); }
  147.         else { if  ( !(inch % 25) )
  148.                  fprintf(outfile, "        "); }
  149.     break;
  150.  
  151.       default:
  152.     break;
  153.     }
  154.   }
  155.   fclose(infile);     /* We're finished with the input file, so close it */
  156.  
  157.   no_zeros = TRUE;
  158.   for (i=MIN_LTR; i<MAX_LTR; i++)
  159.     no_zeros = no_zeros && counts[i];
  160.   for (i=MIN_NUM; i<MAX_NUM; i++)
  161.     no_zeros = no_zeros && counts[i];
  162.   no_zeros = no_zeros && counts[PERIOD];
  163.   no_zeros = no_zeros && counts[COMMA];
  164.   no_zeros = no_zeros && counts[DN];
  165.   no_zeros = no_zeros && counts[QUERY];
  166.   no_zeros = no_zeros && counts[BT];
  167.   no_zeros = no_zeros && counts[AR];
  168.   no_zeros = no_zeros && counts[SK];
  169.  
  170.   if (no_zeros)
  171.   {
  172.     fprintf(outfile, "\n");
  173.     fprintf(outfile, "\n");
  174.     fprintf(outfile, "All required characters are contained in this test.\n");
  175.     fprintf(outfile, "\n");
  176.  
  177.     for (i=MIN_LTR; i<MAX_LTR; i++)
  178.       if (counts[i])
  179.     fprintf(outfile, " %s:%-7ld", &i, counts[i]);
  180.  
  181.     for (i=MIN_NUM; i<MAX_NUM; i++)
  182.       if (counts[i])
  183.     fprintf(outfile, " %s:%-7ld", &i, counts[i]);
  184.  
  185.     printf("\n");
  186.     if (counts[PERIOD])
  187.       fprintf(outfile, " %c:%-7ld", PERIOD, counts[PERIOD]);
  188.     if (counts[COMMA])
  189.       fprintf(outfile, " %c:%-7ld", COMMA, counts[COMMA]);
  190.     if (counts[DN])
  191.       fprintf(outfile, " %c:%-7ld", DN, counts[DN]);
  192.     if (counts[QUERY])
  193.       fprintf(outfile, " %c:%-7ld", QUERY, counts[QUERY]);
  194.     if (counts[BT])
  195.       fprintf(outfile, " %c:%-7ld", BT, counts[BT]);
  196.     if (counts[AR])
  197.       fprintf(outfile, " %c:%-7ld", AR, counts[AR]);
  198.     if (counts[SK])
  199.       fprintf(outfile, " %c:%-7ld", SK, counts[SK]);
  200.     fprintf(outfile, "\n");
  201.  
  202.   }
  203.   else
  204.   {
  205.     fprintf(outfile, "\n");
  206.     fprintf(outfile, "\n");
  207.     fprintf(outfile, "The following characters are in this test:\n");
  208.     fprintf(outfile, "\n");
  209.  
  210.     for (i=MIN_LTR; i<MAX_LTR; i++)
  211.       if (counts[i])
  212.     fprintf(outfile, " %s:%-7ld", &i, counts[i]);
  213.  
  214.     for (i=MIN_NUM; i<MAX_NUM; i++)
  215.       if (counts[i])
  216.     fprintf(outfile, " %s:%-7ld", &i, counts[i]);
  217.  
  218.     printf("\n");
  219.     if (counts[PERIOD])
  220.       fprintf(outfile, " %c:%-7ld", PERIOD, counts[PERIOD]);
  221.     if (counts[COMMA])
  222.       fprintf(outfile, " %c:%-7ld", COMMA, counts[COMMA]);
  223.     if (counts[DN])
  224.       fprintf(outfile, " %c:%-7ld", DN, counts[DN]);
  225.     if (counts[QUERY])
  226.       fprintf(outfile, " %c:%-7ld", QUERY, counts[QUERY]);
  227.     if (counts[BT])
  228.       fprintf(outfile, " %c:%-7ld", BT, counts[BT]);
  229.     if (counts[AR])
  230.       fprintf(outfile, " %c:%-7ld", AR, counts[AR]);
  231.     if (counts[SK])
  232.       fprintf(outfile, " %c:%-7ld", SK, counts[SK]);
  233.  
  234.     fprintf(outfile, "\n");
  235.     fprintf(outfile, "\n");
  236.     fprintf(outfile, "The following characters are not in this test:\n");
  237.     fprintf(outfile, "\n");
  238.  
  239.     for (i=MIN_LTR; i<MAX_LTR; i++)
  240.       if (!counts[i])
  241.     fprintf(outfile, " %s        ", &i);
  242.  
  243.     for (i=MIN_NUM; i<MAX_NUM; i++)
  244.       if (!counts[i])
  245.     fprintf(outfile, " %s        ", &i);
  246.  
  247.     if (!counts[PERIOD])
  248.       fprintf(outfile, " %c        ", PERIOD);
  249.     if (!counts[COMMA])
  250.       fprintf(outfile, " %c        ", COMMA);
  251.     if (!counts[DN])
  252.       fprintf(outfile, " %c        ", DN);
  253.     if (!counts[QUERY])
  254.       fprintf(outfile, " %c        ", QUERY);
  255.     if (!counts[BT])
  256.       fprintf(outfile, " %c        ", BT);
  257.     if (!counts[AR])
  258.       fprintf(outfile, " %c        ", AR);
  259.     if (!counts[SK])
  260.       fprintf(outfile, " %c        ", SK);
  261.  
  262.     fprintf(outfile, "\n");
  263.   }
  264.  
  265.   test_time_5  = (float) inch / LENGTH_5;
  266.   test_time_13 = (float) inch / LENGTH_13;
  267.   test_time_20 = (float) inch / LENGTH_20;
  268.  
  269.   fprintf(outfile, "\n");
  270.   fprintf(outfile, "This test contains %5d characters\n", inch);
  271.   fprintf(outfile, "\n");
  272.   fprintf(outfile, "This test lasts %8.2f minutes at  5 wpm.\n",
  273.            test_time_5);
  274.   fprintf(outfile, "This test lasts %8.2f minutes at 13 wpm.\n",
  275.            test_time_13);
  276.   fprintf(outfile, "This test lasts %8.2f minutes at 20 wpm.\n",
  277.            test_time_20);
  278.  
  279.   fclose(outfile);
  280.   printf("vefc 2.4 normal termination!\n");
  281. }
  282.