Added SILC Thread Queue API
[silc.git] / util / robodoc / Source / folds.c
1 #include <stddef.h>
2 #include <string.h>
3 #include "robodoc.h"
4 #include "folds.h"
5
6
7 /****v* ROBODoc/fold_start_markers 
8  * NAME
9  *   fold_start_markers
10  * FUNCTION
11  *   Strings for fold start.
12  * SOURCE
13  */
14 fold_mark_t     fold_start_markers[] =
15 {
16   {"/*{{{", "*/"},     /* C, C++ */
17   {"--{{{", "\n"},     /* Occam, line ends with newline */
18   {"#{{{", "\n"},      /* Various scripts, line ends with newline */
19   {NULL, NULL}
20 };
21
22 /****/
23
24
25 /****v* ROBODoc/fold_end_markers 
26  * NAME
27  *   fold_start_end
28  * FUNCTION
29  *   Strings for fold end.
30  * SOURCE
31  */
32 fold_mark_t fold_end_markers[] =
33 {
34   {"/*}}}", "*/"},
35   {"--}}}", "\n"},
36   {"#}}}", "\n"},
37   {NULL, NULL}
38 };
39
40 /****/
41
42 int extra_flags = 0;
43
44 /****v* ROBODoc/fold 
45 * NAME
46 *   fold
47 * FUNCTION
48 *   Fold counter - true global. 
49 * SOURCE
50 */
51
52 int fold = 0;
53
54 /****/
55
56
57
58 /****f* ROBODoc/RB_Check_Fold_End [3.0h]
59 * NAME
60 *  RB_Check_Fold_End
61 * AUTHOR
62 *  PetteriK
63 * FUNCTION
64 *  See if a fold end is found.
65 * RETURN VALUE
66 *   1 if end mark is found
67 * SOURCE
68 */
69
70 char
71 RB_Check_Fold_End (char *cur_char)
72 {
73   fold_mark_t *t = fold_end_markers;
74   char found = 0;
75
76   while (found == 0 && t->start != NULL)
77     {
78       if (strncmp (t->start, cur_char, strlen (t->start)) == 0)
79         {
80           found = 1;
81           break;
82         }
83       t++;                      /* try the next fold mark string */
84     }
85   return found;
86 }
87
88 /*******/
89
90 /****f* ROBODoc/RB_Check_Fold_Start 
91  * NAME
92  *   RB_Check_Fold_Start
93  * AUTHOR
94  *   PetteriK
95  * FUNCTION
96  *   Check if a fold start is found.
97  * RETURN VALUE
98  *   Pointer to the item body, fold mark and name skipped.
99  * SIDE EFFECTS
100  *   *found = 1 if fold mark is found. Fold name is copied to *foldname.
101  *******
102  */
103
104 char *
105 RB_Check_Fold_Start (char *cur_char, char *foldname, char *found)
106 {
107   int n = 0;
108   fold_mark_t *t = fold_start_markers;
109
110   *found = 0;
111   while (*found == 0 && t->start != NULL)
112     {
113       if (strncmp (t->start, cur_char, strlen (t->start)) == 0)
114         {
115           *found = 1;
116           break;
117         }
118       t++;                      /* try the next fold mark string */
119     }
120   if (*found == 0)
121     {
122       return cur_char;          /* not found, get out of here */
123     }
124   cur_char += strlen (t->start);        /* skip fold mark */
125   /* get the fold name */
126   while (strncmp (t->end, cur_char, strlen (t->end)) != 0)
127     {
128       foldname[n++] = *cur_char++;
129     }
130   /* if fold mark does not end with newline, skip chars... */
131   if (t->end[0] != '\n')
132     {
133       cur_char += strlen (t->end);
134     }
135   foldname[n] = '\0';
136   while (*cur_char != '\n')
137     {
138       cur_char++;               /* not so sure about this */
139     }
140   return cur_char;
141 }