File: readfile.c

package info (click to toggle)
kdrill 6.5deb2-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,340 kB
  • sloc: ansic: 7,636; makefile: 47
file content (837 lines) | stat: -rw-r--r-- 17,407 bytes parent folder | download | duplicates (2)
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
/*
 * This file is for just setting up the structs, etc
 */
/* stdio SHOULD get included by Xos.h or something */
/* but it doesn't with sunos, at least */

#include <errno.h>
#include <stdio.h>	 /* for popen, and other things */
#include <stdlib.h>
#include <ctype.h>
#include <Xfuncs.h>	/* handles bzero redefine stuff */
#include <Xlib.h>
#include <Xatom.h>
#include <Xutil.h>
#include <Intrinsic.h>
#include <StringDefs.h>
#include <Xos.h>

#include "defs.h"
#include "utils.h"
#include "externs.h"

/* translations[] keeps track of which kanji it is okay to test the
 *	user on. Likewise with numberofkanji, highest, and lowest.
 *	YES, it is best to keep in a large array, otherwise
 *	it would be difficult to switch between grade levels.
 */
struct translationstruct *translations[MAXTRANSLATIONSALLOWED];
int numberofkanji=0, highestkanji=0, lowestkanji=0;

static char *dictname=NULL;
static char *edictname=NULL;

/* kdrill_getline:
 *	reads a line (from dictionary).
 *	Deals with 8-bit char reads (or attempts to)
 *	Also attempts to deal with the problem of variable line length.
 *	Reads in chunks, looking for newline.
 *	Note the MAXLINELEN define. We DO have a limit. We do NOT use
 *		malloc
 *
 *	Copies a line from FILE * to passed (unsigned char *)
 *
 *	Returns true (1) if read a line
 *	Returns false (0) if fail;
 *
 *	Used in "readstructs()", below. Also "readedict()"
 *
 *	Note that this expects static global getline_inptr to be NULL
 *	if we have just started reading a stream;
 */

int kdrill_getline(FILE *fp,unsigned char *s)
{
	char * val;
	char *endparse;

	val=fgets(s,MAXLINELEN,fp);
	
	if(val==NULL)
		return 0; /* probably EOF. We dont care */

	endparse=& s[strlen(s)-1];

	switch(*endparse){
		case 10:
		case 13:
			*endparse='\0';
	}

	return 1;

}

/* StripBrackets:
 *	Gets rid of those annoying {enlish}{english2} brackets.
 *	PRESUMES first char of source is '{'!!
 *      Well, actually, it nicely sets a null string if otherwise.
 *	See also StripSlash, below
 */
void StripBrackets(char *dest,unsigned char *source)
{
	unsigned char *parse = &source[1];

	if(source[0] != '{'){
		dest[0] = '\0';
		return;
	}
	/* (*dest) is always assumed to be needing a write */

	do {
		switch(*parse){
			case '{':
				*dest++ = ':';
				*dest++ = ' ';
				break;
			case '}':
				break;
			case '\n':
				*dest++='\0';
			default:
				*dest++ = *parse;				
		}
		parse++;
	} while((*parse != '\n') && (*parse != '\0'));
	*dest = '\0';
	return;
}
/* StripSlash
 *	Gets rid of /enlish/english2/ Slashes.
 *	Copies the cleaned up version of source, to topdest
 *
 *	This is for readedict. Probably nothing else should use it
 *	Modeled directly after StripBrackets
 *	PRESUMES first char of source is '/'!!
 *	Then looks for LAST '/'
 *	(Or will set topdest[0] to '\0')
 *
 *	We USED to translate middle ':' to '/'.
 *
 *	Source is actually assumed to be regular ascii signed char,
 *	but declared as unsigned to stop compiler warnings.
 *
 * return 0 OKAY, 1 bad line
 */
int StripSlash(char *topdest,unsigned char *source)
{
	char *dest;
	int englen;
	unsigned char *parse = source;

	if(*parse != '/'){
		topdest = '\0';
		return 1;
	}
	parse=strrchr(source, '/');
	if(parse<&source[2]){
		fprintf(stderr,"Error: english part too short\n");
		fprintf(stderr,"%s\n", source);
		return 1;
	}
	englen=parse- source - 1;
	strncpy(topdest, &source[1], parse- source - 1);
	topdest[englen]='\0';

	/* we've copied the relavant part over to topdest. Now rewrite
	 * in-place
	 */
	dest=topdest;
	dest=strchr(dest, '/');
	while(dest!=NULL){
		*dest=':';
		dest=strchr(dest, '/');
	}

	return 0;
}

/* Given a translation, return the index into translations[] that it
 * sits at
 */
int trans_to_index(TRANSLATION trans)
{
	return trans->kdrill_index;
}


/* read in kanji/kana part of edictfile line.
 * format is:
 *
 * KANA /english_1/.../
 *
 * or
 *
 * KANJI [KANA] /english_1/english_2/.../
 *
 *
 */
void ReadEdictPron(unsigned char **Pstring, struct translationstruct *trans)
{
	/* note that MAXLINELEN means we canot possibly run out of space */
	XChar2b kbuff[MAXLINELEN];
	XChar2b *kptr = kbuff;
	unsigned char *parse = *Pstring;

	/* Read in a 16-bit string.
	 * We dont know if its kana or kanji yet
	 */
	while(*parse && (*parse != '/'))
	{
		switch(*parse)
		{
		   case ' ':
			/* 0x2121 is ' ' */
			kptr->byte1 = 0x21;
			kptr->byte2 = 0x21;
			kptr++;
			parse++;			
			break;

		   case '[':
		        /* oops.. the kanji/kana switch */
			/* save what must be kanji, then start
			 * on kana
			 */
			kptr->byte1 = 0;
			kptr->byte2 = 0;

			trans->kanji =  dup_16(kbuff);
			kptr = kbuff;
			/* now reset buffer, and read in another char16
			 * string
			 */
			parse++;
			break;
		   case ']':
			parse++;
			while(*parse && (*parse != '/'))
				parse++;
			/* and then we will fall out of the top loop  */
			break;

		   default:
			kptr->byte1= (*parse++ & 0x7f);
			kptr->byte2= (*parse++ & 0x7f);
			kptr++;
		}
	}

	/* when we come out here, we will ALWAYS have kana in
	 * the kbuff
	 */
	
	kptr->byte1 = 0;
	kptr->byte2 = 0;

	trans->pronunciation =  dup_16(kbuff);


	*Pstring = parse;
}


/* Okay, it's not actually pronunciation we're reading in
 * We are reading the "on-yoni" and "kun-yoni" readings
 * in kanjidic. Also, the optional okurigami.
 *
 * Format:
 *     reading{.oku} [reading{.oku}] ...
 */


/* 0x2500 stuff is kanakana? (ON?)
 * 0x2400 is hiragana?  (KUN?)
 *
 *	We need to assume
 *	
 */
XChar2b * ReadPronunciation(unsigned char **Pstring)
{

	XChar2b kbuff[MAXLINELEN];
	XChar2b *kptr = kbuff;
	unsigned char *parse = *Pstring;
	enum {ERROR,READING, OKURIGANA,BLANK, DONE};
	int state=BLANK;

	if(*parse == '{'){
		/* only english exists,
		 *  (no kanji, even)
		 *   so set character to be unusable.
		 */
		return 0;
	}
	while(*parse == ' ')
		parse++;

	/* THIS is going to get yeuky.
	 *  We are going to parse a line segment which has
	 *  reading.oku  pairs.
	 * This is REALLY annoying, because the line jumps between
	 * 8 -bit and 16-bit chars
	 */

	/* okay, bad practice... you tell me what would be better :-/ */

	while(1){

		/* bug in gcc? If we put 
		 *	int state=BLANK;
		 * here, it gets reset each time through the while loop
		 */

		if(kptr >&kbuff[MAXLINELEN]){
			fprintf(stderr,"ERROR! overflow reading in kanjidic\n");
			fprintf(stderr,"%s\n",*Pstring);
			return 0;
		}

		switch(*parse){
			case '.':
				parse++;

				/* we ALWAYS need to close this off later */
				state = OKURIGANA;
				/* open paren */
				kptr->byte1 = 0x21;
				kptr->byte2 = 0x4a;
				kptr++;

				break;
			case '-':
				parse++;
#ifdef USEEXTRABLANKS
				if(state == BLANK){
					kptr->byte1 = 0x21;
					kptr->byte2 = 0x21;
					kptr++;
				}
#endif
				kptr->byte1 = 0x21;
				kptr->byte2 = 0x41;
				kptr++;
#ifdef USEEXTRABLANKS
				if(state != BLANK){
					kptr->byte1 = 0x21;
					kptr->byte2 = 0x21;
					kptr++;
				}
#endif
				continue;
				/* start at top of while again */

			case '\0':
			case '\n':
			case '\r':
			case '{':
				if(state == OKURIGANA){
					/* close paren */
					kptr->byte1 = 0x21;
					kptr->byte2 = 0x4b;
					kptr++;
				}
				state = DONE;
				break;

			case ' ':
				if(state == OKURIGANA){
					/* close paren */
					kptr->byte1 = 0x21;
					kptr->byte2 = 0x4b;
					kptr++;
				}
				state = BLANK;

				parse++;
				kptr->byte1 = 0x21;
				kptr->byte2 = 0x21;
				kptr++;
				break;

			default:
				if(*parse <127){
					if(state == OKURIGANA){
						/* close paren */
						kptr->byte1 = 0x21;
						kptr->byte2 = 0x4b;
						kptr++;
						puts("Kdrill.. error on kana read-in... ");
						puts("Expecting high bit char to start after '.'");
						printf("%s\n",*Pstring);
						
					}
					state = BLANK;
					parse++;
				} else {
					if(state != OKURIGANA)
						state = READING;
				}
				break;
		}

		if(state == DONE){
			break;
		}
		if(state == BLANK)
			continue;
		/* else read in another char */
		kptr->byte1= (*parse++ & 0x7f);
		kptr->byte2= (*parse++ & 0x7f);
		kptr++;

	} /* while(1) */

	/* copy out to struct, and exit */
	kptr->byte1 = 0;
	kptr->byte2 = 0;

	*Pstring = parse;
	return dup_16(kbuff);

}


/* readedict()
 * 
 *	Read in "edict.gz" if it exists
 *	[readstructs handles kanjidic reading]
 *	
 *	We only make very partial entries for edict entries
 *	We just fill out "english" and "pronunciation" entries.
 *
 *	If we cannot extract a kanji entry, the kanji pointer of a
 *	translation will be set to a shared string of '8' on its side
 *
 *	Note that we always start entries at index
 *	translations[MAXKANJIALLOWED+1]. This is to attempt to keep
 *	usefiles working
 *	
 */
void readedict()
{
	unsigned char instring[MAXLINELEN];
	unsigned char *parse, *slashparse;
	int slashcount;
	char edict[MAXLINELEN]; /*PATH to dictionary */
	FILE *fp;
	TRANSLATION newk=NULL,lastk;
	int nextindex = MAXKANJIALLOWED+1;
	int linecount=0;
	static XChar2b no_kanji[2]=
	{
		{0x0, 0x0},
		{0x0,  0x0}
	};

	no_kanji[0].byte1 = (NOKANJI >> 8);
	no_kanji[0].byte2 = (NOKANJI & 0xff);


	/* the following will be NULL if kanjidic not read in */
	lastk = translations[highestkanji];

	GetXtrmString("edictfile","Edictfile",edict);
	edictname = edict;

	if(strncmp(edictname,"none",4)==0){
		fprintf(stderr,"edictfile set to 'none'. Skippping.\n");
		return;
	}

	edictname=malloc(strlen(edict)+1);
	strcpy(edictname, edict);
	fp = open_compressed(edictname);
	if(fp == NULL)
	{
		fprintf(stderr,"Cannot open edict file %s. Skipping.\n",
			edictname);
		return;
	}
	printf("Opened dictionary %s \n",edictname);
	if(highestkanji == 0)
	{
		lowestkanji = nextindex;
	}

	while(kdrill_getline(fp, instring) != 0)
	{
		int instrlen;

		linecount++;
		if(linecount%1000 == 0)
		{
			putchar('.');
			fflush(stdout);
		}


		if(newk == NULL)
		{
			newk =  (struct translationstruct *)
				malloc(sizeof(struct translationstruct));
			if(newk == NULL)
			{
				fprintf(stderr,"OUT OF MEMORY!!\n");
				exit(errno);
			}
		}

		bzero(newk, sizeof(*newk));

		/* 1- read first part
		 * 2- read optional [part]
		 * 3- read english part
		 */

		parse = instring;

		newk->kanji = no_kanji;

		ReadEdictPron(&parse, newk);
		if(newk->pronunciation == NULL)
		{
			fprintf(stderr,"Error reading edict\n");
			newk = NULL;
			continue;
		}

		while((*parse != '/') && *parse)
		{
			parse++;
		}
		slashcount=1;
		slashparse = parse;
		while(*slashparse++)
		{
			if(*slashparse =='/')
				slashcount++;
		}
		/* need extra space for expansion */
		instrlen = strlen((char *)parse)+1+ slashcount*4;
		
		newk->english = (char *) malloc(instrlen);
		if(newk->english == NULL){
			perror("Cannot allocate memory for translation table\n");
			exit(errno);		
		}
		
		if(StripSlash(newk->english, parse)!=0){
			fprintf(stderr, "bad line: %s\n", instring);
		}

		/* Success! Set pointers appropriately */
		newk->kdrill_index=nextindex;
		translations[nextindex++] = newk;

                if (nextindex >= MAXTRANSLATIONSALLOWED) {
                    fprintf(stderr, "Too many entries in the edict file. Some entries were not read.");
                    break;
                }

		if(lastk != NULL)
		{
			lastk->nextk = newk;
		}
		lastk = newk;
		newk = NULL;
		
	}

	if(isapipe(fp)){
		pclose(fp);
	} else {
		fclose(fp);
	}
	if(nextindex != MAXKANJIALLOWED+1)
	{
		highestkanji = nextindex-1;
	}

	puts("");

	puts("NOTE: an \"infinity\" sign means there is no kanji.");
	puts("  Switch to \"show meaning\" option to show alternates.");

	return;

}

/* lets make sure we have one single unified skip encoding here! */
short skipfromthree(int one, int two, int three){

      int SKIPnum = (one<<12) | (two<<8) | three;

      if((one>0xf) | (two>0xf) | (three>0xff) | (SKIPnum <0) )
      {
#ifdef DEBUG
              printf("corrupted SKIP ('Px-x-x') entry: %d-%d-%d\n",
                     one, two, three);
#endif
              return 0;
      }


      return (short)(SKIPnum&0xffff);
}


/* parseskip
 * Take a string pointing to the first char AFTER the "P", in 
 * kanjidic.
 * So we expect a string like "4-5-11 xxx xxx xxx"
 *
 * We will then convert the three numbers into single byte values,
 * and put them in the short we return.
 * In hex, with a full short being [f][f][f][f], that would look like
 * [1][2][3][3], in nibble positions.
 * Although you really shouldn't care what we do with it, just remember that it
 * is a short. We call skipfromthree(), and so should anything else!
 *
 *
 */
short parseskip(char *input)
{
	int one, two, three;
	
	one = atoi(input);

	input++;
	if(*input != '-')
	{
#ifdef DEBUG
		puts("corrupted SKIP ('Px-x-x') entry");
#endif		
		return 0;
	}
	input++;
	two = atoi(input);

	input++;
	if(*input != '-')
		input++;
	if(*input != '-')
	{
#ifdef DEBUG
		puts("corrupted SKIP ('Px-x-x') entry");
#endif		
		return 0;
	}
	input++;
	three = atoi(input);

	return skipfromthree(one, two, three);
}

/* readstructs:
 *	the main dictionary reading routine for "kanjidic".
 *	Fills in the global translationstruct with
 *	all that is available for each selected kanji, in
 *	Grade, "pronunciation", english translation, and
 *	frequency of use (by native speakers)
 */
void readstructs(){
	unsigned char instring[MAXLINELEN];
	char dict[200];
	FILE *fp;
	TRANSLATION newk=NULL,lastk=NULL;

	GetXtrmString("kdictfile","Kdictfile",dict);
	dictname = dict;
#ifdef DEBUG
	printf("kdictfile from resources is\" %s\"\n",dictname);
#endif

	if(strncmp(dictname,"none",4)==0){
		fprintf(stderr,"kdictfile set to 'none'. Skippping.\n");
		return;
	}
	dictname=malloc(strlen(dict)+1);
	strcpy(dictname, dict);
	fp = open_compressed(dictname);
	if(fp == NULL)
	{
		fprintf(stderr,"Cannot open kanjidic file %s. Skipping.\n",
			dictname);
		return;
	}
	
	printf("Opened dictionary %s \n",dictname);


	if(fp ==NULL){
		fprintf(stderr,"Dictionary  not found\n");
		exit(-1);
	}

	while (kdrill_getline(fp,instring) != 0) {
		int Kanji;
		int freq,grade,N,U,H,Q,SKIP;
		unsigned char *parse;
		BYTE strokes;
		int instrlen;	/* length of pronunciation */

		if(strlen((char *)instring) <10) continue;

		/*try to get kanji Index right away */

#define BROKENFONTS 0
		
		Kanji = xtoi((char *)&instring[2]) + (BROKENFONTS);


		/* skip comments, kanji not specified in
		 * the usefile, and invalid single kanji
		 */	
		if(Kanji < MINKANJIALLOWED) {
			continue;
		}
		if(Kanji >MAXKANJIALLOWED) {
			continue;
		}

		parse = &instring[2];
		if(parse == NULL){
			continue;
		}
		/* now parse for grade level, frequency, and english */
		freq = grade = N = U = H = SKIP=0;
		strokes=0; Q = -1; /* remember, "0000" IS a valid Qval!*/

		nextword(&parse);

		/* Check for high bit set, which means
		 * start of kana definition of kana.
		 * We cheat a bit, and let this loop skip over
		 * numbers by the fact that they don't match
		 * the case statements.
		 */
		while ( (*parse < 127)  && (*parse != '{') ) {
			switch(*parse){
				case 'F':
					freq = atoi((char *)&parse[1]);
					break;
				case 'G':
					grade = atoi((char *)&parse[1]);
					break;
				case 'H':
					H = atoi((char *)&parse[1]);
					break;
				case 'N':
					N = atoi((char *)&parse[1]);
					break;
				case 'P':
					SKIP = parseskip((char *) &parse[1]);
					break;
				case 'Q':
					Q = atoi((char *)&parse[1]);
					break;
				case 'S':
					strokes= atoi((char *)&parse[1]);
					break;
				case 'U':
					U = xtoi((char *)&parse[1]);
					if(U&0xffff0000)
					{
						printf("got hi U: %x\n",
						       U);
					}
					break;
				default:
					parse++;
					break;
			}
			nextword(&parse);
		} /* while != '{' */
		
		
		/**********************************************
		 *  Now we know that we have a useable/wanted *
		 *  dictionary definition                     *
		 *********************************************/
		if((lowestkanji==highestkanji) && (highestkanji==0)){
 			lowestkanji = highestkanji = Kanji;
		} else{
			if(Kanji < lowestkanji) lowestkanji = Kanji;
			if (Kanji > highestkanji) highestkanji = Kanji;
		}

		lastk = newk;
		
		newk = (struct translationstruct *)
			malloc(sizeof(struct translationstruct));
		if (newk == NULL){
			perror("Cannot allocate memory for translation table\n");
			exit(errno);
		}
		newk->Sindex=SKIP;
		newk->Qindex=Q;
		newk->Uindex=U;
		newk->Hindex=H;
		newk->Nindex=N;
		newk->frequency = freq;
		newk->grade_level = grade;
		newk->Strokecount=strokes;
		newk->incorrect=0;
		newk->kanji=0;
		newk->pronunciation=0;
		newk->nextk = NULL;
#ifdef DEBUG
		printf("Q=%d, U=%d, freq=%d\n", Q, U, freq);
#endif
		
		newk->pronunciation = ReadPronunciation(&parse);
		if(newk->pronunciation == 0){
			free(newk);
			newk = lastk;
			continue;
		} else {
			XChar2b buff[2];

			buff[0].byte1 = (Kanji & 0xff00) >> 8;
			buff[0].byte2 = (Kanji & 0xff);
			buff[1].byte1 = 0;
			buff[1].byte2 = 0;
			newk->kanji = dup_16(buff);
		}
		if(lastk != NULL)
			lastk->nextk = newk;

		instrlen = strlen((char *)parse)+1;
		newk->english = (char *) malloc(instrlen);
		if(newk->english == NULL){
			perror("Cannot allocate memory for translation table\n");
			exit(errno);		
		}

		StripBrackets(newk->english, parse);
		newk->kdrill_index=Kanji;
		translations[Kanji] = newk;
		numberofkanji++;
		if(numberofkanji%1000 == 0)
		{
			putchar('.');
			fflush(stdout);
		}

	} /* and repeat until end of file */
	puts("");

	if(isapipe(fp)){
		pclose(fp);
	} else {
		fclose(fp);
	}

}