File: array-misc.c

package info (click to toggle)
sufary 2.1.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,236 kB
  • ctags: 782
  • sloc: ansic: 4,122; perl: 1,378; makefile: 726; sh: 664; tcl: 441; cpp: 192
file content (209 lines) | stat: -rw-r--r-- 4,056 bytes parent folder | download | duplicates (5)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*--------------------------------------------------------------*
 *                                                              *
 *           = array  - Suffix Array Υƥȸ =       *
 *                                                              *
 *  array-misc.c - init, mode, sort, bye, help ޥɥϥɥ *
 *                 ¾¿ʥ롼                         *
 *                                                              *
 *--------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sufary.h"
#include "array.h"

/* ⡼ɥơ֥ */
typedef struct mode_arg_{
  char *name;
  int mode;
} mode_arg;

static mode_arg arg_disp[] = {
  { "kwic", DISP_KWIC },
  { "index", DISP_INDEX },
  { "line", DISP_LINE },
  { "simple", DISP_SIMPLE },
  /* 970523  ά */
  { "k", DISP_KWIC },
  { "i", DISP_INDEX },
  { "l", DISP_LINE },
  { "s", DISP_SIMPLE },
  { NULL, -1 }
};

static mode_arg arg_sort[] = {
  { "index", SORT_INDEX },
  { "alphabetical", SORT_ALPHABETICAL },
  /* 970523  ά */
  { "i", SORT_INDEX },
  { "a", SORT_ALPHABETICAL },
  { NULL, -1 }
};


/**********************************************
 *           eresult com_init(char *cmd);
 *
 * purpose
 *   ϰϤν
 *
 * parameters
 *   cmd : ̤
 *
 * return value
 *   ץ³⡼
 *
 * description
 *
 **********************************************/
eresult com_init(char *cmd)
{
  int i;

  for (i = 0; i < arrays; i++){
    sa_reset(sufary[i]);
  }

  return CONT;
}

/**********************************************
 *        eresult com_mode_display(char *cmd);
 *
 * purpose
 *   ɽ⡼ɤѹ
 *
 * parameters
 *   cmd : ޥɥ饤(ɽ⡼)
 *
 * return value
 *   ץ³⡼
 *
 * description
 *
 **********************************************/
eresult com_mode_display(char *cmd)
{
  char *s;
  mode_arg *da;

  s = strtok(cmd, ct);
  if ( s == NULL ){
    ee = COMMAND;
    return ERROR;
  }

  for ( da = arg_disp; da->name != NULL; da++ ){
    if (strcmp(s, da->name) == 0){
      display_mode = da->mode;
      return CONT;
    }
  }
  ee = COMMAND;
  return ERROR;
}

/**********************************************
 *          eresult com_mode_sort(char *cmd);
 *
 * purpose
 *   ȥ⡼ɤѹ
 *
 * parameters
 *   cmd : ޥɥ饤(ȥ⡼)
 *
 * return value
 *   ץ³⡼
 *
 * description
 *
 **********************************************/
eresult com_mode_sort(char *cmd)
{
  char *s;
  mode_arg *sa;

  s = strtok(cmd, ct);
  if ( s == NULL ){
    ee = COMMAND;
    return ERROR;
  }

  for ( sa = arg_sort; sa->name != NULL; sa++ ){
    if (strcmp(s, sa->name) == 0){
      sort_mode = sa->mode;
      return CONT;
    }
  }
  ee = COMMAND;
  return ERROR;
}

/**********************************************
 *         eresult com_mode_mojibake(char *cmd);
 *
 * purpose
 *   ʸ⡼ɤѹ
 *
 * parameters
 *   cmd : ޥɥ饤(ȥ⡼)
 *
 * return value
 *   ץ³⡼
 **********************************************/
eresult com_mode_mojibake(char *cmd)
{
  char *s;

  s = strtok(cmd, ct);
  if ( s == NULL ){
    ee = COMMAND;
    return ERROR;
  }

  if(strcmp(s,"ON") == 0){
    mojibake_proc_flag = 1;
    printf("ON\n");
  }else{
    mojibake_proc_flag = 0;
    printf("OFF\n");
  }
  return CONT;
}

/**********************************************
 *         eresult com_set_kwic_width(char *cmd);
 *
 * purpose
 *   KWICꤹ롥
 *
 * parameters
 *   cmd : ޥɥ饤(ȥ⡼)
 *
 * return value
 *   ץ³⡼
 **********************************************/
eresult com_set_kwic_width(char *cmd)
{
  char *s;

  s = strtok(cmd, ct);
  if ( s == NULL ){
    ee = COMMAND;
    return ERROR;
  }
  if(!atoi(s)){
    ee = COMMAND;
    return ERROR;
  }
  kwic_width = atoi(s);
/*  if(kwic_width % 2 == 1){
    printf("%d != even number.\n",kwic_width);
    ee = COMMAND;
    return ERROR;
  }
*/
  return CONT;
}