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