File: interface.c

package info (click to toggle)
chasen 2.0-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,148 kB
  • ctags: 1,075
  • sloc: ansic: 10,112; perl: 408; lisp: 405; makefile: 287; sh: 55
file content (169 lines) | stat: -rw-r--r-- 4,846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
   ѥȥꥷںץ for 
*/

#include <stdio.h>
#include <string.h>
#include "pat.h"

static FILE *out_file, *in_file; /* ֥ե롦ɥե */
static char line[50000]; /* Ϲ */
static char inkey[10000]; /*  */
static char kugiri[2]; /* ڤʸ */

/****************************************************
*                      USAGE                        *
****************************************************/
static void usage() {
  printf("pattool  Ver.1.1  96/10/28\n");
  printf("USAGE:\n");
  printf("\tNo option    ---  Interpreter Mode\n");
  printf("\t-F filename  ---  Make PAT file (\"filename.pat\")\n");
  exit(1);
}


/****************************************************
*  ե뤫ѥڤ
****************************************************/
static void make_pat_from_file() {
  char strtmp[1000];
  printf("Make Index File \"%s.pat\" from \"%s.int\"\n",inkey,inkey);
  strcpy(strtmp,inkey);
  strcat(strtmp,".int");
  if((dic_file[number_of_tree] = fopen(strtmp,"r")) == NULL) {
    fprintf(stderr,"No such File\n");  exit(1);
  }
  OL(Tree No.);OI(number_of_tree);
  (void)pat_init_tree_top(&tree_top[number_of_tree]);
  (void)insert_dic_data(dic_file[number_of_tree],&tree_top[number_of_tree],kugiri);
  number_of_tree++;
  return;
}


/****************************************************
*                      ᥤ                       *
****************************************************/
main(argc, argv)
    int argc;
    char **argv;
{
  char comm;
  int i;
  pat_node *tmp;
  char rslt[50000];
  char *op;   /* ޥɥ饤󥪥ץ̾ */
  char strtmp[1000];

  number_of_tree = 0; /* Ѥ뼭(ѥ)ο */

  kugiri[0] = '\t'; /* ڤʸΥǥեȤϥ */

  /* ޥɥ饤󥪥ץ */
  if (argc != 1)  /* ץ󤬤С */
    for (argv++; *argv && argv[0][0] == '-' && argv[0][1]; argv++) {
      for (op = &argv[0][1]; *op; op++) {
	switch (*op) {
	case 'F': /* PATե򤤤ʤäƥ */
	  if (!*++argv) usage();
	  strcpy(inkey,*argv);
	  /* ե륪ץ  ѥڤŤ*/
	  make_pat_from_file();
	  /* ѥڥ */
	  strcat(inkey,".pat");
	  (void)com_s(inkey,&tree_top[0]);
	  exit(0);
	default: /* Ȥ */
	  usage();
	}
      }
    }

#if defined(USE_HASH) && defined(NO_MMAP)
  th_hash_initialize(hash_array,HASH_SIZE);
#endif
  printf("PATTOOL for ChaSen1.0     Ver.1.1  Feb. 1997\n");
  printf("Interpreter Mode:  \'q\' exit, '?\' help\n");

  /* ޥɥ󥿥ץ꥿ */
  while(1){
    printf("> "); fflush(stdout);

    fgets(line, sizeof(line), stdin); /* ޥɤ */

    sscanf(line,"%c %s",&comm,inkey); 
    switch(comm){

    case 'F': /* ե뤫 */
      make_pat_from_file();
      break;

    case 'e': /* θ(exact match) */
      if(number_of_tree==0){ /* 顼 */
	fprintf(stderr,"!!! make or load PAT data before SEARCH.\n"); break;
      }
      rslt[0]='\0';/*ѿ*/
      for(i = 0; i < number_of_tree; i++){
        OL(DICT No.)OI(i);
	(void)pat_search_exact(dic_file[i],inkey, &tree_top[i],rslt);
      }
      printf("%s",rslt);
      break;

    case 'j': /* ʸμ(ChaSenʳ) */
      if(number_of_tree==0){ /* 顼 */
	fprintf(stderr,"!!! make or load PAT data before SEARCH.\n"); break;
      }
      (void)jisyohiki(inkey,&tree_top[0]);
      break;

    case 'k': /* ڤʸ */
      kugiri[0] = inkey[0];
      if(kugiri[0] == '\0') kugiri[0] = ' ';
      printf("partition = \"%s\"\n",kugiri);
      break;

    case 'O': /* ڤν */
      inkey[0] = '\0';
      (void)show_pat(&tree_top[0],stdout,inkey); /* ɸ */
      break;

    case 'S': /* ڤΥ */
      strcat(inkey,".pat");
      (void)com_s(inkey,&tree_top[0]);
      break;

    case 'L': /* ڤΥ */
      strcpy(strtmp,inkey);
      strcat(strtmp,".int");
      dic_file[number_of_tree] = fopen(strtmp,"r"); /* ѥΥץ */
      strcat(inkey,".pat");
      OL(Tree No.);OI(number_of_tree);
      (void)pat_init_tree_top(&tree_top[number_of_tree]);
      (void)com_l(inkey,&tree_top[number_of_tree]);
      number_of_tree++;
      break;

    case 'q': /* 󥿥ץ꥿νλ */
    case 'Q': /* 󥿥ץ꥿νλ */
/*      th_show_hash(hash_array,HASH_SIZE);*/
      printf("QUIT\n");
      return(0);

    default: /* إ */
      printf("command:\n\
              \tj [string] --- ChaSen search\n\
              \te [string] --- exact match search\n\
              \tF [file] --- make patricia tree from file\n\
              \tS [file] --- save patricia tree\n\
              \tL [file] --- load patricia tree\n\
              \tk [char] --- set partition character\n\
              \tq --- quit\n");
      break;
    }

    printf("ok\n"); fflush(stdout);  /* ץץ */
  }
}