xref: /Universal-ctags/main/CommonPrelude.c (revision 7decd215b04dd404c7eb4be98d121fb18063323c)
1 const char ctagsCommonPrelude []=
2 "%\n"
3 "% Copyright (c) 2021, Masatake YAMATO\n"
4 "% Copyright (c) 2021, Red Hat, Inc.\n"
5 "%\n"
6 "% This source code is released for free distribution under the terms of the\n"
7 "% GNU General Public License version 2 or (at your option) any later version.\n"
8 "%\n"
9 "\n"
10 "%\n"
11 "% The documentation table\n"
12 "%\n"
13 "\n"
14 "% __PROCDOCS:dict<proc:name, doc:string>\n"
15 "/__procdocs 30 dict def\n"
16 "\n"
17 "% name value __BDEF -\n"
18 "/__bdef { bind def }  bind def\n"
19 "\n"
20 "% doc:string key:name any:val __DOCDEF -\n"
21 "/__bddef {\n"
22 "    1 index exch __bdef\n"
23 "    exch __procdocs 3 1 roll put\n"
24 "} __bdef\n"
25 "\n"
26 "\n"
27 "%\n"
28 "% procedures\n"
29 "%\n"
30 "(any n:int _NDUP any1 ... anyn)\n"
31 "/_ndup { { dup } repeat } __bddef\n"
32 "\n"
33 "(x:any x:any _DEDUP x:any\n"
34 " x:any y:any _DEDUP x:any y:any)\n"
35 "/_dedup {\n"
36 "    count 1 gt {\n"
37 "        2 copy eq {\n"
38 "            pop\n"
39 "        } if\n"
40 "    } if\n"
41 "} __bddef\n"
42 "\n"
43 "(space:int space:int _DEDUP_SPACES space:int\n"
44 " otherthanspace:int space:int _DEDUP_SPACES otherthanspace:int space:int)\n"
45 "/_dedup_spaces {\n"
46 "    count 0 gt {\n"
47 "        dup ?\\_ eq {\n"
48 "            _dedup\n"
49 "        } if\n"
50 "    } if\n"
51 "} __bddef\n"
52 "\n"
53 "% 32 32 _dedup_spaces pstack clear (---) ==\n"
54 "% 32 41 _dedup_spaces pstack clear (---) ==\n"
55 "% 41 32 _dedup_spaces pstack clear (---) ==\n"
56 "% 32 _dedup_spaces pstack clear (---) ==\n"
57 "% 41 _dedup_spaces pstack clear (---) ==\n"
58 "% quit\n"
59 "\n"
60 "/__buildstring {\n"
61 "    {\n"
62 "	    counttomark dup 1 eq {\n"
63 "	        pop exch pop\n"
64 "	        exit\n"
65 "	    } {\n"
66 "	        -1 roll 1 index exch _putlast!\n"
67 "	    } ifelse\n"
68 "    } loop\n"
69 "} __bdef\n"
70 "\n"
71 "(mark char:int|substring:string... _BUILDSTRING string)\n"
72 "/_buildstring {\n"
73 "    0 string __buildstring\n"
74 "} __bddef\n"
75 "\n"
76 "(string char:int|string _PUTLAST! -)\n"
77 "/_putlast!  {\n"
78 "    1 index length exch\n"
79 "    dup type /integertype eq {\n"
80 "	    put\n"
81 "    } {\n"
82 "	    putinterval\n"
83 "    } ifelse\n"
84 "} __bddef\n"
85 "\n"
86 "(target:string fromto:str _TR! -)\n"
87 "/_tr! {\n"
88 "    %\n"
89 "    % () is not allowed.\n"
90 "    % The reason must be be documented.\n"
91 "    %\n"
92 "    0 string\n"
93 "    % str [int<from> int<to>] str'\n"
94 "    2 index {\n"
95 "	% str [int<from> int<to>] str' int<chr>\n"
96 "	    dup 3 index 0 get\n"
97 "	% str [int<from> int<to>] str' int<chr> int<chr> int<from>\n"
98 "	    eq {% str [int<from> int<to>] str' int<chr>\n"
99 "	        pop\n"
100 "	        dup 2 index 1 get _putlast!\n"
101 "	    } {% str [int<from> int<to>] str' int<chr>\n"
102 "	        1 index exch _putlast!\n"
103 "	    } ifelse\n"
104 "    } forall\n"
105 "    % str [int<from> int<to>] str'\n"
106 "    exch pop\n"
107 "    0 exch putinterval\n"
108 "} __bddef\n"
109 "\n"
110 "(string _NORMALIZE_SPACES! -)\n"
111 "/_normalize_spaces! {\n"
112 "    dup\n"
113 "    dup (\\n ) _tr!\n"
114 "    dup (\\t ) _tr!\n"
115 "    dup (\\r ) _tr!\n"
116 "    dup (\\f ) _tr!\n"
117 "    dup (\\v ) _tr!\n"
118 "    mark exch { _dedup_spaces } forall _buildstring\n"
119 "    exch copy pop\n"
120 "} __bddef\n"
121 "\n"
122 "% /x mark 40 (a) 32 32 10 (b) 10 10 9 9 (xyz) 9 9 41 _buildstring def\n"
123 "% x _normalize_spaces! x pstack\n"
124 "\n"
125 "(tag:int _SCOPEREF -)\n"
126 "/_scoperef {\n"
127 "    _scopetop not { 0 } if scope:\n"
128 "} __bddef\n"
129 "\n"
130 "(tag:int _SCOPEPUSH -)\n"
131 "/_scopepush {\n"
132 "    dup _scoperef _scopeset\n"
133 "} __bddef\n"
134 "\n"
135 "(string _ISSTRING string true\n"
136 " any:!string _ISSTRING false)\n"
137 "/_isstring {\n"
138 "    dup type /stringtype eq {\n"
139 "        true\n"
140 "    } {\n"
141 "        pop false\n"
142 "    } ifelse\n"
143 "} __bddef\n"
144 "\n"
145 "(array key _AMEMBER true|fales)\n"
146 "/_amember {\n"
147 "    false 3 1 roll\n"
148 "    % false array key\n"
149 "    exch {\n"
150 "        % false key elt\n"
151 "        1 index\n"
152 "        % false key elt key\n"
153 "        eq {\n"
154 "            % false key\n"
155 "            exch pop true exch\n"
156 "            exit\n"
157 "        } if\n"
158 "        % false key\n"
159 "    } forall\n"
160 "    pop\n"
161 "} __bddef\n"
162 "\n"
163 "(array key _AINDEX nth:int true\n"
164 " array key _AINDEX false)\n"
165 "/_aindex {\n"
166 "    0 3 1 roll\n"
167 "    % idx array key\n"
168 "    exch {\n"
169 "        % idx key elt\n"
170 "        1 index\n"
171 "        eq {\n"
172 "            % idx key\n"
173 "            pop true exit\n"
174 "        } {\n"
175 "            % idx key\n"
176 "            exch 1 add exch\n"
177 "        } ifelse\n"
178 "    } forall\n"
179 "    dup true ne { pop pop false } if\n"
180 "} __bddef\n"
181 ;
182