joe-3.1jupp31.tgz (die zweite Klappeā€¦)
[alioth/jupp.git] / termidx.c
1 /* $MirOS: contrib/code/jupp/termidx.c,v 1.5 2014/03/04 23:04:12 tg Exp $ */
2 /*
3  *      Program to generate termcap index file
4  *      Copyright
5  *              (C) 1992 Joseph H. Allen
6  *
7  * This file is part of JOE (Joe's Own Editor)
8  */
9 #include "config.h"
10 #include "types.h"
11
12 #include <stdio.h>
13 #include <string.h>
14
15 static void gen(unsigned char *s, FILE *fd)
16 {
17         int c, x;
18         off_t addr = 0, oaddr;
19
20       loop:
21         while (c = getc(fd), c == ' ' || c == '\t' || c == '#')
22                 do {
23                         c = getc(fd);
24                 } while (!(c == -1 || c == '\n'));
25         if (c == -1)
26                 return;
27         if (c == '\n')
28                 goto loop;
29         oaddr = addr;
30 #ifdef HAVE_FSEEKO
31         addr = ftello(fd) - 1;
32 #else
33         /* well, SOL */
34         addr = ftell(fd) - 1;
35 #endif
36         ungetc(c, fd);
37         s[x = 0] = 0;
38         while (1) {
39                 c = getc(fd);
40                 if (c == -1 || c == '\n') {
41                         if (x != 0 && s[x - 1] == '\\')
42                                 --x;
43                         if (x) {
44                                 int y, z, flg;
45
46                                 s[x] = 0;
47                                 z = 0;
48                                 flg = 0;
49                                 do {
50                                         for (y = z; s[y] && s[y] != '|' && s[y] != ':'; ++y) ;
51                                         c = s[y];
52                                         s[y] = 0;
53                                         if (strlen((char *)(s + z)) > 2 && !strchr((char *)(s + z), ' ') && !strchr((char *)(s + z), '\t')) {
54                                                 if(flg)
55                                                         putchar(' ');
56                                                 fputs((char *)(s + z), stdout);
57                                                 flg = 1;
58                                         }
59                                         s[y] = c;
60                                         z = y + 1;
61                                 } while (c && c != ':');
62                                 if (flg)
63                                         printf(" %lX\n",
64                                             (unsigned long)(addr - oaddr));
65                         }
66                         goto loop;
67                 } else if (c == '\r')
68                         /* do nothing */ ;
69                 else
70                         s[x++] = c;
71         }
72 }
73
74 int main(int argc, char *argv[])
75 {
76         unsigned char array[65536];
77
78         gen(array, stdin);
79         return(0);
80 }