home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / cbw / part01 / sdriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-16  |  2.0 KB  |  124 lines

  1. /*
  2.  * Test driver for scoring stuff
  3.  */
  4.  
  5. #include    <stdio.h>
  6. #include    <math.h>
  7. #include    "window.h"
  8. #include    "specs.h"
  9. #include    "cipher.h"
  10.  
  11.  
  12. extern    str2gsi();
  13.  
  14. gsinfo    mygsi;
  15. int        kwnbuf[100], gssbuf[100];
  16.  
  17. /* Test routine for statistics. */
  18. main(argc, argv)
  19. int        argc;
  20. char    *argv[];
  21. {
  22.     char    *p;
  23.     int        c, i;
  24.     float    h;
  25.     char    plainbuf[BLOCKSIZE+1];
  26.     int        pvec[BLOCKSIZE+1];
  27.     float    pscore, fscore;
  28.     int        length;
  29.     gsinfo    *gsi;
  30.     char    str[100];
  31.  
  32.     printf("\nStatistics Test driver.  Type a line to see its score.\n\n");
  33.  
  34.     load_1stats_from("mss.stats");
  35.     load_2stats_from("mss-bigram.stats");
  36.  
  37.     gsi = &mygsi;
  38.     gsi->cknown = kwnbuf;
  39.     gsi->cguessed = gssbuf;
  40.  
  41.     while (TRUE) {
  42.         length = 0;
  43.         for (p = plainbuf ; (c=read_char(stdin)) != EOL ; *p++ = c )  {
  44.             length++;
  45.             }
  46.         *p = NULL;
  47.  
  48.         stripdots(plainbuf, str);
  49.         str2pvec(str, pvec);
  50.         pscore = pvec_1score(pvec);
  51.         printf("pvec_1score is %5.3f", pscore);
  52. /*
  53.         pscore = var_1score(pvec);
  54.         printf("var_1score is %5.3f", pscore);
  55.  
  56.         pscore = prob_1score(pvec);
  57.         printf(", and prob_1score is %.3e", pscore);
  58. */
  59.  
  60.         str2gsi(plainbuf, gsi);
  61.         pscore = gsi_score(gsi);
  62.         printf(", and gsi_score is %5.3f", pscore);
  63.  
  64.         printf("\n");
  65.         }
  66. }
  67.  
  68.  
  69. /* Fill in guess info block from string.  Treat all chars as
  70.  * consecutive, except "." means unknown.
  71.  */
  72. str2gsi(str, gsi)
  73. char    *str;
  74. gsinfo    *gsi;
  75. {
  76.     int        cpos_index, guessed_index;
  77.  
  78.     cpos_index = 0;
  79.     guessed_index = 0;
  80.     while (*str != NULL)  {
  81.         if (*str == '.')  {
  82.             (gsi->cguessed)[guessed_index] = NONE;
  83.             }
  84.         else {
  85.             gsi->cpos[cpos_index] = guessed_index;
  86.             cpos_index++;
  87.             (gsi->cguessed)[guessed_index] = 0377 & (*str);
  88.             }
  89.         (gsi->cknown)[guessed_index] = NONE;
  90.         guessed_index++;
  91.         str++;
  92.         }
  93.     gsi->cpos[cpos_index] = NONE;
  94.     (gsi->cknown)[guessed_index] = NONE;
  95.     (gsi->cguessed)[guessed_index] = NONE;
  96. }
  97.  
  98. /* Copy in to out deleting the character "."
  99.  */
  100. stripdots(in, out)
  101. char    *in, *out;        /* Null terminated strings. */
  102. {
  103.     while (*in != NULL)  {
  104.         if (*in != '.')
  105.             *out++ = *in++;
  106.         else
  107.             in++;
  108.         }
  109.     *out = NULL;
  110. }
  111.  
  112.  
  113. key    u_getkey()
  114. {
  115. }
  116.  
  117. keyer    topktab[] ={{0, NULL}};
  118.  
  119.  
  120. char    *quitcmd()
  121. {
  122.     exit(0);
  123. }
  124.