root/control.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. statisticsctrl
  2. matchingctrl
  3. addwdtree
  4. wdentalloc
  5. addwdpt
  6. printwdtree
  7. printwdptlist
  8. addmtlist
  9. mtentalloc
  10. printmtlist
  11. printcdtable

   1 /*
   2  *   Compound Text word statistics and search report
   3  *
   4  *   control.c : statistics & matching control
   5  *   $Id: control.c,v 1.3 2008/05/04 13:06:07 isao Exp $
   6  *
   7  *                                           Copyright(c) isao yasuda, 1998 
   8  */
   9 static char *rcs_id = "$Id: control.c,v 1.3 2008/05/04 13:06:07 isao Exp $";
  10 
  11 #include <stdio.h>
  12 #include <stdlib.h>
  13 #include <string.h>
  14 #include "staslova.h"
  15 #include "table.h"
  16 
  17 void
  18 statisticsctrl(unsigned char *wd)
  19 {
  20         if (lprf[0] & *(wd+1))
  21                 langroot[0] = addwdtree(langroot[0], wd, STAT);
  22         else if (lprf[1] & *(wd+1))
  23                 langroot[1] = addwdtree(langroot[1], wd, STAT);
  24         else
  25                 langroot[2] = addwdtree(langroot[2], wd, STAT);
  26 }
  27 
  28 void
  29 matchingctrl(unsigned char *wd)
  30 {
  31         struct cdent **cdp = cdtbl;
  32 
  33         while (*cdp != NULL) {
  34                 if (matchword(wd+2, *cdp) == MATCH) {
  35                         (*cdp)->mwdroot = addwdtree((*cdp)->mwdroot, wd, MTCT);
  36                         (*cdp)->tcount++;
  37                 }
  38                 cdp++;
  39         }
  40 }
  41 
  42 struct wdent *
  43 addwdtree(struct wdent *p, unsigned char *wd, int opt)
  44 {
  45         int ans;
  46 
  47         if (p == NULL) {
  48                 p = wdentalloc();
  49                 p->wdc = 1;
  50                 p->langinfo = *++wd;
  51                 p->mlwd = ++wd;
  52                 p->mthead = NULL;
  53                 p->mtlast = NULL;
  54                 if (opt == MTCT) {
  55                         p->mthead = addmtlist(p->mthead);
  56                         p->mtlast = p->mthead;
  57                 }
  58                 p->left_we = NULL;
  59                 p->right_we = NULL;
  60                 p->wdptl = NULL;
  61                 if (opt == STAT)
  62                         p->wdptl = addwdpt(p->wdptl, ++wdcount);
  63                 else
  64                         p->wdptl = addwdpt(p->wdptl, wdcount);
  65                 wdnum++;
  66         } else if ((ans = mlstrcmp(wd+2, p->mlwd)) == 0) {
  67                 p->wdc++;
  68                 if (opt == STAT)
  69                         p->wdptl = addwdpt(p->wdptl, ++wdcount);
  70                 else {
  71                         p->wdptl = addwdpt(p->wdptl, wdcount);
  72                         p->mtlast = addmtlist(p->mtlast);
  73                 }
  74         } else if (ans < 0)
  75                 p->left_we = addwdtree(p->left_we, wd, opt);
  76         else
  77                 p->right_we = addwdtree(p->right_we, wd, opt);
  78         return p;
  79 }
  80 
  81 struct wdent *
  82 wdentalloc(void)
  83 {
  84         struct wdent *p;
  85   
  86         if ((p = (struct wdent *) malloc(sizeof(struct wdent))) == NULL)
  87                 fprintf(stderr, "Word structure allocation failed.(wdentalloc)\n");
  88         return p;
  89 }
  90 
  91 struct ptent *
  92 addwdpt(struct ptent *p, int pt)
  93 {
  94         if (p == NULL) {
  95                 if ((p = (struct ptent *) malloc(sizeof(struct ptent))) == NULL)
  96                         fprintf(stderr, "Word point allocation failed.(addwdpt)\n");
  97                 p->wdpt = pt;
  98                 p->next = NULL;
  99         } else {
 100                 p->next = addwdpt(p->next, pt);
 101         }
 102         return p;
 103 }
 104 
 105 void
 106 printwdtree(struct wdent *p, int opt)
 107 {       
 108         if (p != NULL) {
 109                 printwdtree(p->left_we, opt);
 110                 printf("%s\t%06d", p->mlwd, p->wdc);
 111                 pwdptc = 0;
 112                 printwdptlist(p->wdptl);
 113                 printf("\n");
 114                 wdtotal += p->wdc;
 115                 wdnum++;
 116                 if (opt == MTCT)
 117                         if (outmode > '1')
 118                                 printmtlist(p->mthead);
 119                 printwdtree(p->right_we, opt);
 120         }
 121 }
 122 
 123 void
 124 printwdptlist(struct ptent *p)
 125 {
 126         if (p != NULL) {
 127                 if (pwdptc < usrwdptc && pwdptc < MAXWDPTC) {
 128                         printf("\t%06d", p->wdpt);
 129                         pwdptc++;
 130                         printwdptlist(p->next);
 131                 } else {
 132                         printf("\t*");
 133                 }
 134         }
 135 }
 136 struct mtent *
 137 addmtlist(struct mtent *mp)
 138 {
 139         if (mp == NULL) {
 140                 if ((mp = mtentalloc()) == NULL)
 141                         exit(1);
 142                 mp->ln = lno;
 143                 mp->next = NULL;
 144                 if ((mp->txt = getmaterial(CONTEXT)) == NULL)
 145                         exit(1);
 146                 return mp;
 147         } else {
 148                 mp->next = addmtlist(mp->next);
 149                 return mp->next;
 150         }
 151 }
 152 
 153 struct mtent *
 154 mtentalloc(void)
 155 {
 156         struct mtent *p;
 157 
 158         if ((p = (struct mtent *) malloc(sizeof(struct mtent))) == NULL)
 159                 fprintf(stderr, "Material structure allocation failed.(wdentalloc)\n");
 160         return p;
 161 }
 162     
 163 void
 164 printmtlist(struct mtent *mt)
 165 {
 166         if (mt != NULL) {
 167                 printf("***** [%d]\n%s\n", mt->ln, mt->txt);
 168                 printmtlist(mt->next);
 169         }
 170 }
 171 
 172 void
 173 printcdtable(struct cdent *cdp)
 174 {
 175         unsigned char **wp = cdp->cdpolish;
 176 
 177         printf("***** your expressions\t:%s", cdp->cdparm);
 178         if (((char *)strchr(cdp->cdparm, '\n')) == NULL)
 179                 printf("\n");
 180         printf("***** polish expression\t:");
 181         while (*wp != NULL)
 182                 printf("%s ", (**wp == EXP) ? (*wp++)+2 : *wp++);
 183         printf("\n");
 184         printf("***** total matching words\t:%d\n", cdp->tcount);
 185 }

/* [previous][next][first][last][top][bottom][index][help] */