tm 7.80.
[elisp/tm.git] / ol2.c
1 /*
2  *   This program `ol2' is a converter
3  * from a text for outline-mode of GNU Emacs to normal text.
4  *   This is a filter. So, input is `stdin', output is `stdout'.
5  *
6  * Copyright 1992, Timtia Software.
7  *
8  * This program is Copyfree.
9  */
10
11 #include <stdio.h>
12
13 main()
14 {
15     unsigned char  depth=0, offset=1;
16     
17     for(;;){
18         char str[256], *cp;
19         unsigned short  section[255];
20         unsigned char   d;
21         unsigned short  i;
22         unsigned short  code;
23
24         if(gets(str)==NULL) break;
25         
26         for(d=0, cp=str; ;d++){
27             if(*cp++!='*') break;
28         }
29         if(*--cp==' ') cp++;
30         if(d==0){
31             puts(str);
32         }
33         else if(d==1){
34             if(d>depth){
35                 depth=d;
36                 section[0]=0;
37             }
38             else if(d==depth){
39                 section[0]++;
40             }
41             else{
42                 depth=d;
43                 section[0]++;
44             }
45             code=0xa3b0+section[0]+offset;
46             printf("%c%c %s\n", code>>8,code&0xff, cp);
47         }
48         else if(d==depth){
49             section[depth-1]++;
50             for(i=0; i<depth-1; i++){
51                 printf("%d.", section[i]+offset);
52             }
53             printf("%d %s\n", section[i]+offset, cp);
54         }
55         else if(d>depth){
56             for(i=0; i<depth; i++){
57                 printf("%d.", section[i]+offset);
58             }
59             for(; i<d-1; i++){
60                 section[i]=0;
61                 printf("%d.", section[i]+offset);
62             }
63             section[i]=0;
64             printf("%d %s\n", section[i]+offset, cp);
65             depth=d;
66         }
67         else{
68             depth=d;
69             section[depth-1]++;
70             for(i=0; i<depth-1; i++){
71                 printf("%d.", section[i]+offset);
72             }
73             printf("%d %s\n", section[i]+offset, cp);
74         }   
75     }
76 }