* 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:
sam 2003-09-09 19:22:37 +00:00
parent 59c23788bb
commit 181c7bc863
1 changed files with 32 additions and 5 deletions

View File

@ -47,6 +47,7 @@ main(int ac, char **av) {
if ((fp = fopen(fn, "r")) == 0) { if ((fp = fopen(fn, "r")) == 0) {
perror(fn); exit(1); perror(fn); exit(1);
} }
/* Traite tous les fichiers un par un */
doit(fp); doit(fp);
fclose(fp); fclose(fp);
} }
@ -60,17 +61,26 @@ doit(FILE *fp) {
int n, need_nl = 0; int n, need_nl = 0;
line = 1; line = 1;
/* Proceed line by line */
while (fgets(buf, 10000, fp) != NULL) { while (fgets(buf, 10000, fp) != NULL) {
if (p = index(buf, '\n')) if (p = index(buf, '\n'))
*p = 0; *p = 0;
p = buf; p = buf;
/* Proceed char by char */
while (*p) { 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; start = p;
} else {
p += 2; p += 2;
switch (*p) { switch (*p) {
/* @[. -> Ix */
case '.': case '.':
macro = "Ix"; break; macro = "Ix"; break;
/* @[! -> Ix */
case '!': case '!':
macro = "Id"; break; macro = "Id"; break;
case 0: case 0:
@ -80,45 +90,58 @@ doit(FILE *fp) {
} }
p++; p++;
q = inx; q = inx;
/* On cherche ] */
while (*p != ']') { while (*p != ']') {
if (*p == 0) if (*p == 0)
error("missing ]"); error("missing ]");
/* Si ] est escapé, on l'imprime */
if (*p == '\\' && p[1] == ']') if (*p == '\\' && p[1] == ']')
p++; p++;
*q++ = *p++; *q++ = *p++;
} }
/* inx devient ce qu'il y avait entre [ ] */
if (q == inx) if (q == inx)
error("empty index"); error("empty index");
*q = 0; *q = 0;
/* Vire \f. '' `` \% de l'index et on le met dans arg */
eatfont(inx, arg); eatfont(inx, arg);
/* Si le précédent caractère est un "(", on affiche "\\c" */
if (start > buf && start[-1] == '(') if (start > buf && start[-1] == '(')
printf("\\c"); printf("\\c");
/* Si need_nl == 1, on saute une ligne */
if (need_nl) if (need_nl)
putchar('\n'); putchar('\n');
/* on affiche .Ix ou .Id */
printf(".%s ", macro); printf(".%s ", macro);
/* On bouffe le caractère suivant de l'input */
p++; p++;
/* Si arg commence par '=', on l'affiche entre "" */
if (arg[0] == '=') { if (arg[0] == '=') {
printf("\"%s\"", arg+1); 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) { if (*p) {
putchar('\n'); putchar('\n');
need_nl = 0; need_nl = 0;
if (*p == ' ') if (*p == ' ')
p++; p++;
} }
/* Si arg est du genre "foo|bar", on affiche
"bar, foo"\nfoo bar */
} else if (q = index(arg, '|')) { } else if (q = index(arg, '|')) {
*q = 0; q++; *q = 0; q++;
printf("\"%s, %s\"\n%s %s", q, arg, arg, q); printf("\"%s, %s\"\n%s %s", q, arg, arg, q);
need_nl = 1; need_nl = 1;
} else { } else {
/* Sinon on affiche "arg"\ninx */
printf("\"%s\"\n%s", arg, inx); printf("\"%s\"\n%s", arg, inx);
need_nl = 1; need_nl = 1;
} }
} else {
putchar(*p);
need_nl = 1;
p++;
} }
} }
/* Si on a fini de parser, on saute une ligne */
putchar('\n'); putchar('\n');
need_nl = 0; need_nl = 0;
line++; line++;
@ -127,12 +150,16 @@ doit(FILE *fp) {
eatfont(char *from, char *to) { eatfont(char *from, char *to) {
while (*from) { while (*from) {
/* "\f." -> "" */
if (*from == '\\' && from[1] == 'f' && from[2]) { if (*from == '\\' && from[1] == 'f' && from[2]) {
from += 3; from += 3;
/* "''" -> "" */
} else if (*from == '\'' && from[1] == '\'') { } else if (*from == '\'' && from[1] == '\'') {
from += 2; from += 2;
/* "``" -> "" */
} else if (*from == '`' && from[1] == '`') { } else if (*from == '`' && from[1] == '`') {
from += 2; from += 2;
/* "\%" -> "" */
} else if (*from == '\\' && from[1] == '%') { } else if (*from == '\\' && from[1] == '%') {
from += 2; from += 2;
} else *to++ = *from++; } else *to++ = *from++;