* Added comments to mkindex.c, to make its conversion easier.
git-svn-id: svn://svn.zoy.org/elk/trunk@134 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
		
							parent
							
								
									59c23788bb
								
							
						
					
					
						commit
						181c7bc863
					
				| 
						 | 
				
			
			@ -47,6 +47,7 @@ main(int ac, char **av) {
 | 
			
		|||
            if ((fp = fopen(fn, "r")) == 0) {
 | 
			
		||||
                perror(fn); exit(1);
 | 
			
		||||
            }
 | 
			
		||||
	    /* Traite tous les fichiers un par un */
 | 
			
		||||
            doit(fp);
 | 
			
		||||
            fclose(fp);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -60,17 +61,26 @@ doit(FILE *fp) {
 | 
			
		|||
    int n, need_nl = 0;
 | 
			
		||||
 | 
			
		||||
    line = 1;
 | 
			
		||||
    /* Proceed line by line */
 | 
			
		||||
    while (fgets(buf, 10000, fp) != NULL) {
 | 
			
		||||
        if (p = index(buf, '\n'))
 | 
			
		||||
            *p = 0;
 | 
			
		||||
        p = buf;
 | 
			
		||||
	/* Proceed char by char */
 | 
			
		||||
        while (*p) {
 | 
			
		||||
            if (*p == '@' && p[1] == '[') {
 | 
			
		||||
	    /* On cherche @[ , sinon on affiche le nouveau caractère */
 | 
			
		||||
            if (*p != '@' || p[1] != '[') {
 | 
			
		||||
                putchar(*p);
 | 
			
		||||
                need_nl = 1;
 | 
			
		||||
                p++;
 | 
			
		||||
                start = p;
 | 
			
		||||
            } else {
 | 
			
		||||
                p += 2;
 | 
			
		||||
                switch (*p) {
 | 
			
		||||
		/* @[. -> Ix */
 | 
			
		||||
                case '.':
 | 
			
		||||
                    macro = "Ix"; break;
 | 
			
		||||
		/* @[! -> Ix */
 | 
			
		||||
                case '!':
 | 
			
		||||
                    macro = "Id"; break;
 | 
			
		||||
                case 0:
 | 
			
		||||
| 
						 | 
				
			
			@ -80,45 +90,58 @@ doit(FILE *fp) {
 | 
			
		|||
                }
 | 
			
		||||
                p++;
 | 
			
		||||
                q = inx;
 | 
			
		||||
		/* On cherche ] */
 | 
			
		||||
                while (*p != ']') {
 | 
			
		||||
                    if (*p == 0)
 | 
			
		||||
                        error("missing ]");
 | 
			
		||||
		    /* Si ] est escapé, on l'imprime */
 | 
			
		||||
                    if (*p == '\\' && p[1] == ']')
 | 
			
		||||
                        p++;
 | 
			
		||||
                    *q++ = *p++;
 | 
			
		||||
                }
 | 
			
		||||
		/* inx devient ce qu'il y avait entre [ ] */
 | 
			
		||||
                if (q == inx)
 | 
			
		||||
                    error("empty index");
 | 
			
		||||
                *q = 0;
 | 
			
		||||
		/* Vire \f. '' `` \% de l'index et on le met dans arg */
 | 
			
		||||
                eatfont(inx, arg);
 | 
			
		||||
		/* Si le précédent caractère est un "(", on affiche "\\c" */
 | 
			
		||||
                if (start > buf && start[-1] == '(')
 | 
			
		||||
                        printf("\\c");
 | 
			
		||||
		/* Si need_nl == 1, on saute une ligne */
 | 
			
		||||
                if (need_nl)
 | 
			
		||||
                    putchar('\n');
 | 
			
		||||
		/* on affiche .Ix ou .Id */
 | 
			
		||||
                printf(".%s ", macro);
 | 
			
		||||
		/* On bouffe le caractère suivant de l'input */
 | 
			
		||||
                p++;
 | 
			
		||||
		/* Si arg commence par '=', on l'affiche entre "" */
 | 
			
		||||
                if (arg[0] == '=') {
 | 
			
		||||
                    printf("\"%s\"", arg+1);
 | 
			
		||||
		    /* S'il reste du data, on saute une ligne et si c'est
 | 
			
		||||
			une espace, on la saute sans l'afficher ; par
 | 
			
		||||
			ailleurs au prochain coup ça sera pas la peine de
 | 
			
		||||
			sauter une ligne */
 | 
			
		||||
                    if (*p) {
 | 
			
		||||
                        putchar('\n');
 | 
			
		||||
                        need_nl = 0;
 | 
			
		||||
                        if (*p == ' ')
 | 
			
		||||
                            p++;
 | 
			
		||||
                    }
 | 
			
		||||
		/* Si arg est du genre "foo|bar", on affiche
 | 
			
		||||
		    "bar, foo"\nfoo bar */
 | 
			
		||||
                } else if (q = index(arg, '|')) {
 | 
			
		||||
                    *q = 0; q++;
 | 
			
		||||
                    printf("\"%s, %s\"\n%s %s", q, arg, arg, q);
 | 
			
		||||
                    need_nl = 1;
 | 
			
		||||
                } else {
 | 
			
		||||
		/* Sinon on affiche "arg"\ninx */
 | 
			
		||||
                    printf("\"%s\"\n%s", arg, inx);
 | 
			
		||||
                    need_nl = 1;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                putchar(*p);
 | 
			
		||||
                need_nl = 1;
 | 
			
		||||
                p++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
	/* Si on a fini de parser, on saute une ligne */
 | 
			
		||||
        putchar('\n');
 | 
			
		||||
        need_nl = 0;
 | 
			
		||||
        line++;
 | 
			
		||||
| 
						 | 
				
			
			@ -127,12 +150,16 @@ doit(FILE *fp) {
 | 
			
		|||
 | 
			
		||||
eatfont(char *from, char *to) {
 | 
			
		||||
    while (*from) {
 | 
			
		||||
	/* "\f." -> "" */
 | 
			
		||||
        if (*from == '\\' && from[1] == 'f' && from[2]) {
 | 
			
		||||
            from += 3;
 | 
			
		||||
	/* "''" -> "" */
 | 
			
		||||
        } else if (*from == '\'' && from[1] == '\'') {
 | 
			
		||||
            from += 2;
 | 
			
		||||
	/* "``" -> "" */
 | 
			
		||||
        } else if (*from == '`' && from[1] == '`') {
 | 
			
		||||
            from += 2;
 | 
			
		||||
	/* "\%" -> "" */
 | 
			
		||||
        } else if (*from == '\\' && from[1] == '%') {
 | 
			
		||||
            from += 2;
 | 
			
		||||
        } else *to++ = *from++;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue