-
Notifications
You must be signed in to change notification settings - Fork 0
/
gregg_db.c
620 lines (588 loc) · 22.6 KB
/
gregg_db.c
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*============================---(source-start)---============================*/
#include "gregg.h"
typedef struct cSOURCE tSOURCE;
struct cSOURCE {
char name [LEN_HUND];
short count;
};
static tSOURCE s_source [LEN_DESC];
static char s_nsource = 0;
/*====================------------------------------------====================*/
/*===---- header handling ----===*/
/*====================------------------------------------====================*/
static void o___HEADER__________o () { return; }
char
DB__head_write_one (FILE *a_file, char a_label [LEN_TERSE], int a_var)
{
char rc = 0;
rc = fwrite (&a_var, sizeof (int), 1, a_file);
DEBUG_OUTP yLOG_complex (a_label , "%4d %d", rc, a_var);
return rc;
}
char
DB__head_write (FILE *a_file, char a_name [LEN_LABEL], char a_ver [LEN_LABEL], int a_nlet, int a_npre, int a_nsuf, int a_nsrc, int a_nbas, int a_ndic, char a_heart [LEN_DESC])
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
int i = 0;
char t [LEN_HUND] = "";
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
/*---(defense)------------------------*/
DEBUG_OUTP yLOG_point ("a_file" , a_file);
--rce; if (a_file == NULL) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(name)------------------------*/
for (i = 0; i < LEN_LABEL; i++) t [i] = ' ';
strlcpy (t, a_name, LEN_LABEL);
rc = fwrite (t, LEN_LABEL, 1, a_file);
DEBUG_OUTP yLOG_complex ("name" , "%4d %s", rc, t);
/*---(version)---------------------*/
for (i = 0; i < LEN_LABEL; i++) t [i] = ' ';
strlcpy (t, a_ver , LEN_SHORT);
rc = fwrite (t, LEN_LABEL, 1, a_file);
DEBUG_OUTP yLOG_complex ("vernum" , "%4d %s", rc, t);
/*---(stats)-----------------------*/
rc = DB__head_write_one (a_file, "letters" , a_nlet);
rc = DB__head_write_one (a_file, "prefixes", a_npre);
rc = DB__head_write_one (a_file, "suffixes", a_nsuf);
rc = DB__head_write_one (a_file, "sources" , a_nsrc);
rc = DB__head_write_one (a_file, "bases" , a_nbas);
rc = DB__head_write_one (a_file, "words" , a_ndic);
/*---(heartbeat)-------------------*/
for (i = 0; i < LEN_DESC; i++) t [i] = '·';
strlcpy (t, a_heart , LEN_DESC);
rc = fwrite (t, LEN_DESC , 1, a_file);
DEBUG_OUTP yLOG_complex ("heart" , "%4d %s", rc, t);
/*---(force flush)-----------------*/
fflush (a_file);
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
char
DB__head_read_one (FILE *a_file, char a_label [LEN_TERSE], int *r_var)
{
char rc = 0;
int a = 0;
rc = fread (&a, sizeof (int), 1, a_file);
DEBUG_INPT yLOG_complex (a_label , "%4d %d", rc, a);
if (r_var != NULL) *r_var = a;
return 0;
}
char
DB__head_read (FILE *a_file, char r_name [LEN_LABEL], char r_ver [LEN_LABEL], int *r_nlet, int *r_npre, int *r_nsuf, int *r_nsrc, int *r_nbas, int *r_ndic, char r_heart [LEN_DESC])
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
char t [LEN_HUND] = "";
int a = 0;
/*---(header)-------------------------*/
DEBUG_INPT yLOG_enter (__FUNCTION__);
/*---(defense)------------------------*/
DEBUG_INPT yLOG_point ("a_file" , a_file);
--rce; if (a_file == NULL) {
DEBUG_INPT yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(name)------------------------*/
rc = fread (&t, LEN_LABEL, 1, a_file);
DEBUG_INPT yLOG_complex ("name" , "%4d %s", rc, t);
if (r_name != NULL) strlcpy (r_name , t, LEN_LABEL);
/*---(version)---------------------*/
rc = fread (&t, LEN_LABEL, 1, a_file);
DEBUG_INPT yLOG_complex ("version" , "%4d %s", rc, t);
if (r_ver != NULL) strlcpy (r_ver , t, LEN_LABEL);
/*---(stats)-----------------------*/
rc = DB__head_read_one (a_file, "letters" , &a);
if (r_nlet != NULL) *r_nlet = a;
rc = DB__head_read_one (a_file, "prefixes", &a);
if (r_npre != NULL) *r_npre = a;
rc = DB__head_read_one (a_file, "suffixes", &a);
if (r_nsuf != NULL) *r_nsuf = a;
rc = DB__head_read_one (a_file, "sources" , &a);
if (r_nsrc != NULL) *r_nsrc = a;
rc = DB__head_read_one (a_file, "bases" , &a);
if (r_nbas != NULL) *r_nbas = a;
rc = DB__head_read_one (a_file, "dicts" , &a);
if (r_ndic != NULL) *r_ndic = a;
/*---(heartbeat)-------------------*/
rc = fread (t, LEN_DESC , 1, a_file);
DEBUG_INPT yLOG_complex ("heart" , "%4d %s", rc, t);
if (r_heart != NULL) strlcpy (r_heart , t, LEN_DESC);
/*---(complete)-----------------------*/
DEBUG_INPT yLOG_exit (__FUNCTION__);
return 0;
}
/*============================--------------------============================*/
/*===---- source handling ----===*/
/*============================--------------------============================*/
static void o___SOURCE__________________o (void) {;}
char
SOURCE_add (char a_file [LEN_HUND])
{
/*---(locals)-------------------------*/
char rce = -10;
/*---(header)-------------------------*/
DEBUG_CONF yLOG_enter (__FUNCTION__);
/*---(defense)------------------------*/
DEBUG_CONF yLOG_point ("a_file" , a_file);
--rce; if (a_file == NULL) {
DEBUG_CONF yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(copy)---------------------------*/
strlcpy (s_source [s_nsource].name, a_file, LEN_HUND);
s_source [s_nsource].count = 0;
++s_nsource;
/*---(complete)-----------------------*/
DEBUG_CONF yLOG_exit (__FUNCTION__);
return 0;
}
char
SOURCE__purge (void)
{
/*---(locals)-------------------------*/
int i = 0;
/*---(header)-------------------------*/
DEBUG_CONF yLOG_enter (__FUNCTION__);
/*---(remove)-------------------------*/
for (i = 0; i < LEN_DESC; ++i) {
strlcpy (s_source [i].name, "", LEN_HUND);
s_source [i].count = 0;
}
s_nsource = 0;
/*---(complete)-----------------------*/
DEBUG_CONF yLOG_exit (__FUNCTION__);
return 0;
}
char
SOURCE_write (FILE *a_file)
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
short i = 0;
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
/*---(defense)------------------------*/
DEBUG_OUTP yLOG_point ("a_file" , a_file);
--rce; if (a_file == NULL) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
DEBUG_OUTP yLOG_value ("r_nfile" , s_nsource);
--rce; if (s_nsource <= 0) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(write all)----------------------*/
for (i = 0; i < s_nsource; ++i) {
rc = fwrite (&(s_source [i]), sizeof (tSOURCE), 1, a_file);
if (rc != 1) break;
}
/*---(check)--------------------------*/
DEBUG_OUTP yLOG_value ("i" , i);
--rce; if (s_nsource != i) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
char
SOURCE_read (FILE *a_file, short a_count)
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
short i = 0;
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
/*---(defense)------------------------*/
DEBUG_OUTP yLOG_point ("a_file" , a_file);
--rce; if (a_file == NULL) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
DEBUG_OUTP yLOG_value ("r_nfile" , s_nsource);
--rce; if (s_nsource > 0) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(write all)----------------------*/
for (i = 0; i < a_count; ++i) {
rc = fread (&(s_source [i]), sizeof (tSOURCE), 1, a_file);
if (rc != 1) break;
++s_nsource;
}
/*---(check)--------------------------*/
DEBUG_OUTP yLOG_value ("a_count" , a_count);
--rce; if (s_nsource != a_count) {
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
short SOURCE_inc (void) { ++(s_source [s_nsource - 1].count); return 0; }
/*====================------------------------------------====================*/
/*===---- main driver ----===*/
/*====================------------------------------------====================*/
static void o___DRIVER__________o () { return; }
char
DB_write (char a_name [LEN_HUND])
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
FILE *x_db = NULL;
int x_nlet, x_npre, x_nsuf, x_nsrc, x_nbas, x_ndic;
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
yURG_msg ('>', "write central database (write)...");
/*---(collect data)-------------------*/
x_nlet = LETTER_count ();
x_npre = PREFIX__count ();
x_nsuf = SUFFIX__count ();
x_nsrc = SOURCE__count ();
x_nbas = BASE__count ();
x_ndic = DICT__count ();
/*---(open)---------------------------*/
rc = SHARED_open (a_name, 'W', &x_db);
DEBUG_OUTP yLOG_value ("open" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be openned for writing");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(write header)-------------------*/
rc = DB__head_write (x_db, P_BASENAME, P_VERNUM, x_nlet, x_npre, x_nsuf, x_nsrc, x_nbas, x_ndic, my.heartbeat);
DEBUG_OUTP yLOG_value ("header" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database header could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database header successfully written");
/*---(letters)------------------------*/
rc = LETTER_write (x_db);
DEBUG_OUTP yLOG_value ("letters" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database letter table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in letter table successfully written", LETTER_count ());
/*---(prefixes)-----------------------*/
rc = PREFIX_write (x_db);
DEBUG_OUTP yLOG_value ("prefixes" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database prefix table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in prefix table successfully written", PREFIX__count ());
/*---(suffixes)-----------------------*/
rc = SUFFIX_write (x_db);
DEBUG_OUTP yLOG_value ("suffixes" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database suffix table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in suffix table successfully written", SUFFIX__count ());
/*---(sources)------------------------*/
rc = SOURCE_write (x_db);
DEBUG_OUTP yLOG_value ("sources" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database source table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in source table successfully written", SOURCE__count ());
/*---(bases index)--------------------*/
rc = BASE_index_new (BASE__count ());
DEBUG_OUTP yLOG_value ("new index" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database base index could not be created");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "base index table successfully created");
/*---(bases)--------------------------*/
rc = BASE_write (x_db);
DEBUG_OUTP yLOG_value ("sources" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database source table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in base table successfully written", BASE__count ());
/*---(words)--------------------------*/
rc = DICT_write (x_db);
DEBUG_OUTP yLOG_value ("words" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database dictionary table could not be written");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in dictionary table successfully written", DICT__count ());
/*---(bases index)--------------------*/
rc = BASE_index_free ();
DEBUG_OUTP yLOG_value ("free index", rc);
--rce; if (rc < 0) {
yURG_err ('f', "database base index could not be freed");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "base index table successfully freed");
/*---(flush)--------------------------*/
fflush (x_db);
yURG_msg ('-', "database contents flushed to disk");
/*---(close)--------------------------*/
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_value ("close" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be closed after writing");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database successfully closed");
/*---(summary)------------------------*/
yURG_msg ('-', "success, current database saved correctly");
yURG_msg (' ', "");
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
char
DB_read (char a_name [LEN_HUND])
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
FILE *x_db = NULL;
char x_name [LEN_LABEL] = "";
char x_ver [LEN_LABEL] = "";
int x_nlet, x_npre, x_nsuf, x_nsrc, x_nbas, x_ndic;
char x_heart [LEN_HUND] = "";
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
yURG_msg ('>', "read central database (read)...");
/*---(open)---------------------------*/
rc = SHARED_open (a_name, 'R', &x_db);
DEBUG_OUTP yLOG_value ("open" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be openned for writing");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(write header)-------------------*/
rc = DB__head_read (x_db, x_name, x_ver, &x_nlet, &x_npre, &x_nsuf, &x_nsrc, &x_nbas, &x_ndic, x_heart);
DEBUG_OUTP yLOG_value ("header" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database header could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database header successfully read");
/*---(letters)------------------------*/
rc = LETTER_read (x_db, x_nlet);
DEBUG_OUTP yLOG_value ("letters" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database letter table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in letter table successfully read", LETTER_count ());
/*---(prefixes)-----------------------*/
rc = PREFIX_read (x_db, x_npre);
DEBUG_OUTP yLOG_value ("prefixes" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database prefix table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in prefix table successfully read", PREFIX__count ());
/*---(suffixes)-----------------------*/
rc = SUFFIX_read (x_db, x_nsuf);
DEBUG_OUTP yLOG_value ("suffixes" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database suffix table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in suffix table successfully read", SUFFIX__count ());
/*---(sources)------------------------*/
rc = SOURCE_read (x_db, x_nsrc);
DEBUG_OUTP yLOG_value ("sources" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database source table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in source table successfully read", SOURCE__count ());
/*---(bases index)--------------------*/
rc = BASE_index_new (x_nbas);
DEBUG_OUTP yLOG_value ("new index" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database base index could not be created");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "base index table successfully created");
/*---(bases)--------------------------*/
rc = BASE_read (x_db, x_nbas);
DEBUG_OUTP yLOG_value ("sources" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database source table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in base table successfully read", BASE__count ());
/*---(words)--------------------------*/
rc = DICT_read (x_db, x_ndic);
DEBUG_OUTP yLOG_value ("words" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database dictionary table could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "%d in dictionary table successfully read", DICT__count ());
/*---(bases index)--------------------*/
rc = BASE_index_free ();
DEBUG_OUTP yLOG_value ("free index", rc);
--rce; if (rc < 0) {
yURG_err ('f', "database base index could not be freed");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "base index table successfully freed");
/*---(close)--------------------------*/
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_value ("close" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be closed after reading");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database successfully closed");
/*---(paginate)-----------------------*/
DICT_paginate ();
yURG_msg ('-', "dictionary paginated");
yMAP_refresh_full ();
yURG_msg ('-', "mapping refreshed");
/*---(summary)------------------------*/
yURG_msg ('-', "success, current database read correctly");
yURG_msg (' ', "");
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
char
DB_stats (char a_name [LEN_HUND])
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
char rc = 0;
FILE *x_db = NULL;
char x_name [LEN_LABEL] = "";
char x_ver [LEN_LABEL] = "";
int x_nlet, x_npre, x_nsuf, x_nsrc, x_nbas, x_ndic;
char x_heart [LEN_HUND] = "";
char t [LEN_LABEL] = "";
/*---(header)-------------------------*/
DEBUG_OUTP yLOG_enter (__FUNCTION__);
yURG_msg ('>', "retrieve central database statistics (stats)...");
/*---(open)---------------------------*/
rc = SHARED_open (a_name, 'R', &x_db);
DEBUG_OUTP yLOG_value ("open" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be openned for writing");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
/*---(write header)-------------------*/
rc = DB__head_read (x_db, x_name, x_ver, &x_nlet, &x_npre, &x_nsuf, &x_nsrc, &x_nbas, &x_ndic, x_heart);
DEBUG_OUTP yLOG_value ("header" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database header could not be read");
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database header successfully read");
/*---(close)--------------------------*/
rc = SHARED_close (&x_db);
DEBUG_OUTP yLOG_value ("close" , rc);
--rce; if (rc < 0) {
yURG_err ('f', "database could not be closed after reading");
DEBUG_OUTP yLOG_exitr (__FUNCTION__, rce);
return rce;
}
yURG_msg ('-', "database successfully closed");
/*---(display)------------------------*/
printf ("#!/usr/local/bin/gregg --stats\n");
printf ("db å%sæ\n" , a_name);
printf ("name å%sæ\n" , x_name);
printf ("ver å%sæ\n" , x_ver);
strl4main (x_nlet, t , 0, 'c', '-', LEN_LABEL);
printf ("letter %7.7s\n", t);
strl4main (x_npre, t , 0, 'c', '-', LEN_LABEL);
printf ("suffix %7.7s\n", t);
strl4main (x_nsuf, t , 0, 'c', '-', LEN_LABEL);
printf ("prefix %7.7s\n", t);
strl4main (x_nsrc, t , 0, 'c', '-', LEN_LABEL);
printf ("source %7.7s\n", t);
strl4main (x_nbas, t , 0, 'c', '-', LEN_LABEL);
printf ("base %7.7s\n", t);
strl4main (x_ndic, t , 0, 'c', '-', LEN_LABEL);
printf ("word %7.7s\n", t);
printf ("stamp å%sæ\n" , x_heart);
/*---(complete)-----------------------*/
DEBUG_OUTP yLOG_exit (__FUNCTION__);
return 0;
}
/*====================------------------------------------====================*/
/*===---- debugging ----===*/
/*====================------------------------------------====================*/
static void o___DEBUGGING_______o () { return; }
char SOURCE__count (void) { return s_nsource; }
char*
SOURCE__detail (char n)
{
/*---(locals)-----------+-----+-----+-*/
char rce = -10;
/*---(defense)------------------------*/
strcpy (g_print, "n/a");
if (n < 0 || n >= s_nsource) return g_print;
/*---(prepare)------------------------*/
sprintf (g_print, "%-2d %-5d %s", n, s_source [n].count, s_source [n].name);
/*---(complete)-----------------------*/
return g_print;
}