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

  1. /*
  2.  * dblock.c takes too long to compile, so this is separate.
  3.  *
  4.  * Robert W. Baldwin, December 1984.
  5.  */
  6.  
  7.  
  8. #include    <stdio.h>
  9. #include    "window.h"
  10. #include    "layout.h"
  11. #include    "specs.h"
  12. #include    "pqueue.h"
  13. #include    "cipher.h"
  14.  
  15. #include    "dblock.h"
  16.  
  17.  
  18. ecinfo    t_ecinfo;
  19.  
  20.  
  21. /* Try all the possible characters at the current position.
  22.  * Display those that do not generate any conflicts.
  23.  */
  24. dbstryall(dbs, k)
  25. gwindow    *dbs;
  26. key        k;
  27. {
  28.     int        col, pos;
  29.     int        oldrow, oldcol;
  30.     int        i;
  31.     int        tchar;
  32.     ecinfo    *ecbi;
  33.     dbsinfo    *dbsi;
  34.     int        pque_index;
  35.     pqueue_hdr    pque_hdr;
  36.     pqueue_ent    the_pque[MAXCHAR+1];
  37.  
  38.     dbsi = ((dbsinfo *) dbs->wprivate);
  39.     ecbi = &t_ecinfo;
  40.  
  41.     pque_init(&pque_hdr, 1000.0, &the_pque[0], MAXCHAR+1);
  42.     ec_init(dbsi->cbuf, dbsi->perm, ecbi);
  43.     
  44.     oldrow = dbs->wcur_row;
  45.     oldcol = dbs->wcur_col;
  46.     pos = dbsrc2pos(oldrow, oldcol);
  47.     dbstrypq(ecbi, &pque_hdr, pos);
  48.  
  49.     wl_setcur(dbs, dbsp2row(BLOCKSIZE), dbsp2col(BLOCKSIZE));
  50.  
  51.     tchar = 0;
  52.     for (col = 1 ; col < dbs->wwidth ; col++)  {
  53.         pque_index = col - 1;
  54.         if (pque_index >= pque_hdr.next_index)  break;
  55.         tchar = the_pque[pque_index].value1;
  56.         plnchars(1, char2sym(tchar));
  57.         }
  58.   alldone:
  59.     plnchars((dbs->wwidth) - col, ' ');
  60.     wl_setcur(dbs, oldrow, oldcol);
  61. }
  62.  
  63.  
  64. /* Try all chars in position pos.  Added them to a priority queue.
  65.  * The most likely character appears first.
  66.  */
  67. dbstrypq(ecbi, pque_hdr, pos)
  68. ecinfo        *ecbi;
  69. pqueue_hdr    *pque_hdr;
  70. int            pos;
  71. {
  72.     int        plainchar;
  73.     int        added;
  74.     float    score;
  75.     extern    float    score2_scale, score1_scale;
  76.     float    score1, score2;
  77.     float    sdev1, sdev2;        /* Standard Deviation for 1st and 2nd stats. */
  78.     gsinfo    tmpgsi;
  79.     gsinfo    *gsi;
  80.     int        gssbuf[BLOCKSIZE+1];
  81.  
  82.     gsi    = &tmpgsi;
  83.     gsi_init(gsi, ecbi->plaintext, gssbuf);
  84.  
  85.     for (plainchar = 0 ; plainchar <= MAXCHAR ; plainchar++)  {
  86.         gsi_clear(gsi);
  87.         added = gsi_class_guess(gsi, ecbi, pos, plainchar);
  88.         if (added > 0) {
  89.             sdev1 = gsi_1score(gsi);
  90.             if (sdev1 < 0.0)
  91.                 continue;
  92.             sdev2 = gsi_2score(gsi);
  93.             if (sdev2 < 0.0)
  94.                 continue;
  95.             score = sdev1 + sdev2;
  96.             pque_add(pque_hdr, score, plainchar, 0);
  97.             }
  98.         }
  99. }
  100.  
  101.  
  102. /* Word search from dictionary.  Try to find the word at the cursor position.
  103.  * The cursor must be at either the beginning or end of a word as indicated
  104.  * by the cursor being adjacent to a whitespace character.
  105.  * 
  106.  * For now, a pattern is extracted an a word lookup command gets executed.
  107.  * The keystroke argument, k, is not used.
  108.  */
  109. dbswrdsrch(dbs, k)
  110. gwindow    *dbs;
  111. key        k;
  112. {
  113.     int    oldrow, oldcol;        /* To reset cursor pos if needed. */
  114.     int    pos;            /* Char offset in block. */
  115.     int    prev_char;
  116.     ecinfo    *ecbi;
  117.     dbsinfo    *dbsi;
  118.     
  119.     dbsi = ((dbsinfo *) dbs->wprivate);
  120.     ecbi = &t_ecinfo;
  121.     ec_init(dbsi->cbuf, dbsi->perm, ecbi);
  122.     
  123.     oldrow = dbs->wcur_row;
  124.     oldcol = dbs->wcur_col;
  125.     pos = dbsrc2pos(oldrow, oldcol);
  126.     prev_char = pos > 0 ? dbsi->pbuf[pos-1] : NONE;
  127.     if (isletter(prev_char)) {
  128.         usrstatus(&user,
  129.            "Word Search: Cursor must be start of a word.");
  130.         return;
  131.         }
  132.  
  133. /*    websearch(&webster, ecbi, pos, TRUE); */
  134.     return;
  135. }
  136.