|
1 /* |
|
2 * comp.h - header file for completion |
|
3 * |
|
4 * This file is part of zsh, the Z shell. |
|
5 * |
|
6 * Copyright (c) 1992-1997 Paul Falstad |
|
7 * All rights reserved. |
|
8 * |
|
9 * Permission is hereby granted, without written agreement and without |
|
10 * license or royalty fees, to use, copy, modify, and distribute this |
|
11 * software and to distribute modified versions of this software for any |
|
12 * purpose, provided that the above copyright notice and the following |
|
13 * two paragraphs appear in all copies of this software. |
|
14 * |
|
15 * In no event shall Paul Falstad or the Zsh Development Group be liable |
|
16 * to any party for direct, indirect, special, incidental, or consequential |
|
17 * damages arising out of the use of this software and its documentation, |
|
18 * even if Paul Falstad and the Zsh Development Group have been advised of |
|
19 * the possibility of such damage. |
|
20 * |
|
21 * Paul Falstad and the Zsh Development Group specifically disclaim any |
|
22 * warranties, including, but not limited to, the implied warranties of |
|
23 * merchantability and fitness for a particular purpose. The software |
|
24 * provided hereunder is on an "as is" basis, and Paul Falstad and the |
|
25 * Zsh Development Group have no obligation to provide maintenance, |
|
26 * support, updates, enhancements, or modifications. |
|
27 * |
|
28 */ |
|
29 |
|
30 typedef struct cmatcher *Cmatcher; |
|
31 typedef struct cmlist *Cmlist; |
|
32 typedef struct cpattern *Cpattern; |
|
33 typedef struct menuinfo *Menuinfo; |
|
34 typedef struct cexpl *Cexpl; |
|
35 typedef struct cmgroup *Cmgroup; |
|
36 typedef struct cmatch *Cmatch; |
|
37 |
|
38 /* This is for explantion strings. */ |
|
39 |
|
40 struct cexpl { |
|
41 int always; /* display even without matches */ |
|
42 char *str; /* the string */ |
|
43 int count; /* the number of matches */ |
|
44 int fcount; /* number of matches with fignore ignored */ |
|
45 }; |
|
46 |
|
47 /* This describes a group of matches. */ |
|
48 |
|
49 struct cmgroup { |
|
50 char *name; /* the name of this group */ |
|
51 Cmgroup prev; /* previous on the list */ |
|
52 Cmgroup next; /* next one in list */ |
|
53 int flags; /* see CGF_* below */ |
|
54 int mcount; /* number of matches */ |
|
55 Cmatch *matches; /* the matches */ |
|
56 int lcount; /* number of things to list here */ |
|
57 int llcount; /* number of line-displays */ |
|
58 char **ylist; /* things to list */ |
|
59 int ecount; /* number of explanation string */ |
|
60 Cexpl *expls; /* explanation strings */ |
|
61 int ccount; /* number of compctls used */ |
|
62 LinkList lexpls; /* list of explanation string while building */ |
|
63 LinkList lmatches; /* list of matches */ |
|
64 LinkList lfmatches; /* list of matches without fignore */ |
|
65 LinkList lallccs; /* list of used compctls */ |
|
66 int num; /* number of this group */ |
|
67 int nbrbeg; /* number of opened braces */ |
|
68 int nbrend; /* number of closed braces */ |
|
69 int new; /* new matches since last permalloc() */ |
|
70 /* The following is collected/used during listing. */ |
|
71 int dcount; /* number of matches to list in columns */ |
|
72 int cols; /* number of columns */ |
|
73 int lins; /* number of lines */ |
|
74 int width; /* column width */ |
|
75 int *widths; /* column widths for listpacked */ |
|
76 int totl; /* total length */ |
|
77 int shortest; /* length of shortest match */ |
|
78 Cmgroup perm; /* perm. alloced version of this group */ |
|
79 }; |
|
80 |
|
81 |
|
82 #define CGF_NOSORT 1 /* don't sort this group */ |
|
83 #define CGF_LINES 2 /* these are to be printed on different lines */ |
|
84 #define CGF_HASDL 4 /* has display strings printed on separate lines */ |
|
85 #define CGF_UNIQALL 8 /* remove all duplicates */ |
|
86 #define CGF_UNIQCON 16 /* remove consecutive duplicates */ |
|
87 #define CGF_PACKED 32 /* LIST_PACKED for this group */ |
|
88 #define CGF_ROWS 64 /* LIST_ROWS_FIRST for this group */ |
|
89 #define CGF_FILES 128 /* contains file names */ |
|
90 |
|
91 /* This is the struct used to hold matches. */ |
|
92 |
|
93 struct cmatch { |
|
94 char *str; /* the match itself */ |
|
95 char *orig; /* the match string unquoted */ |
|
96 char *ipre; /* ignored prefix, has to be re-inserted */ |
|
97 char *ripre; /* ignored prefix, unquoted */ |
|
98 char *isuf; /* ignored suffix */ |
|
99 char *ppre; /* the path prefix */ |
|
100 char *psuf; /* the path suffix */ |
|
101 char *prpre; /* path prefix for opendir */ |
|
102 char *pre; /* prefix string from -P */ |
|
103 char *suf; /* suffix string from -S */ |
|
104 char *disp; /* string to display (compadd -d) */ |
|
105 char *autoq; /* closing quote to add automatically */ |
|
106 int flags; /* see CMF_* below */ |
|
107 int *brpl; /* places where to put the brace prefixes */ |
|
108 int *brsl; /* ...and the suffixes */ |
|
109 char *rems; /* when to remove the suffix */ |
|
110 char *remf; /* shell function to call for suffix-removal */ |
|
111 int qipl; /* length of quote-prefix */ |
|
112 int qisl; /* length of quote-suffix */ |
|
113 int rnum; /* group relative number */ |
|
114 int gnum; /* global number */ |
|
115 mode_t mode; /* mode field of a stat */ |
|
116 char modec; /* LIST_TYPE-character for mode or nul */ |
|
117 }; |
|
118 |
|
119 #define CMF_FILE (1<< 0) /* this is a file */ |
|
120 #define CMF_REMOVE (1<< 1) /* remove the suffix */ |
|
121 #define CMF_ISPAR (1<< 2) /* is paramter expansion */ |
|
122 #define CMF_PARBR (1<< 3) /* paramter expansion with a brace */ |
|
123 #define CMF_PARNEST (1<< 4) /* nested paramter expansion */ |
|
124 #define CMF_NOLIST (1<< 5) /* should not be listed */ |
|
125 #define CMF_DISPLINE (1<< 6) /* display strings one per line */ |
|
126 #define CMF_HIDE (1<< 7) /* temporarily hide this one */ |
|
127 #define CMF_NOSPACE (1<< 8) /* don't add a space */ |
|
128 #define CMF_PACKED (1<< 9) /* prefer LIST_PACKED */ |
|
129 #define CMF_ROWS (1<<10) /* prefer LIST_ROWS_FIRST */ |
|
130 #define CMF_MULT (1<<11) /* string appears more than once */ |
|
131 #define CMF_FMULT (1<<12) /* first of multiple equal strings */ |
|
132 #define CMF_ALL (1<<13) /* a match representing all other matches */ |
|
133 #define CMF_DUMMY (1<<14) /* unselectable dummy match */ |
|
134 |
|
135 /* Stuff for completion matcher control. */ |
|
136 |
|
137 struct cmlist { |
|
138 Cmlist next; /* next one in the list of global matchers */ |
|
139 Cmatcher matcher; /* the matcher definition */ |
|
140 char *str; /* the string for it */ |
|
141 }; |
|
142 |
|
143 struct cmatcher { |
|
144 int refc; /* reference counter */ |
|
145 Cmatcher next; /* next matcher */ |
|
146 int flags; /* see CMF_* below */ |
|
147 Cpattern line; /* what matches on the line */ |
|
148 int llen; /* length of line pattern */ |
|
149 Cpattern word; /* what matches in the word */ |
|
150 int wlen; /* length of word pattern */ |
|
151 Cpattern left; /* left anchor */ |
|
152 int lalen; /* length of left anchor */ |
|
153 Cpattern right; /* right anchor */ |
|
154 int ralen; /* length of right anchor */ |
|
155 }; |
|
156 |
|
157 #define CMF_LINE 1 |
|
158 #define CMF_LEFT 2 |
|
159 #define CMF_RIGHT 4 |
|
160 #define CMF_INTER 8 |
|
161 |
|
162 struct cpattern { |
|
163 Cpattern next; /* next sub-pattern */ |
|
164 unsigned char tab[256]; /* table of matched characters */ |
|
165 int equiv; /* if this is a {...} class */ |
|
166 }; |
|
167 |
|
168 /* This is a special return value for parse_cmatcher(), * |
|
169 * signalling an error. */ |
|
170 |
|
171 #define pcm_err ((Cmatcher) 1) |
|
172 |
|
173 /* Information about what to put on the line as the unambiguous string. |
|
174 * The code always keeps lists of these structs up to date while |
|
175 * matches are added (in the aminfo structs below). |
|
176 * The lists have two levels: in the first one we have one struct per |
|
177 * word-part, where parts are separated by the anchors of `*' patterns. |
|
178 * These structs have pointers (in the prefix and suffix fields) to |
|
179 * lists of cline structs describing the strings before or after the |
|
180 * the anchor. */ |
|
181 |
|
182 typedef struct cline *Cline; |
|
183 typedef struct clsub Clsub; |
|
184 |
|
185 struct cline { |
|
186 Cline next; |
|
187 int flags; |
|
188 char *line; |
|
189 int llen; |
|
190 char *word; |
|
191 int wlen; |
|
192 char *orig; |
|
193 int olen; |
|
194 int slen; |
|
195 Cline prefix, suffix; |
|
196 int min, max; |
|
197 }; |
|
198 |
|
199 #define CLF_MISS 1 |
|
200 #define CLF_DIFF 2 |
|
201 #define CLF_SUF 4 |
|
202 #define CLF_MID 8 |
|
203 #define CLF_NEW 16 |
|
204 #define CLF_LINE 32 |
|
205 #define CLF_JOIN 64 |
|
206 #define CLF_MATCHED 128 |
|
207 #define CLF_SKIP 256 |
|
208 |
|
209 /* Information for ambiguous completions. One for fignore ignored and * |
|
210 * one for normal completion. */ |
|
211 |
|
212 typedef struct aminfo *Aminfo; |
|
213 |
|
214 struct aminfo { |
|
215 Cmatch firstm; /* the first match */ |
|
216 int exact; /* if there was an exact match */ |
|
217 Cmatch exactm; /* the exact match (if any) */ |
|
218 int count; /* number of matches */ |
|
219 Cline line; /* unambiguous line string */ |
|
220 }; |
|
221 |
|
222 /* Information about menucompletion stuff. */ |
|
223 |
|
224 struct menuinfo { |
|
225 Cmgroup group; /* position in the group list */ |
|
226 Cmatch *cur; /* match currently inserted */ |
|
227 int pos; /* begin on line */ |
|
228 int len; /* length of inserted string */ |
|
229 int end; /* end on the line */ |
|
230 int we; /* non-zero if the cursor was at the end */ |
|
231 int insc; /* length of suffix inserted */ |
|
232 int asked; /* we asked if the list should be shown */ |
|
233 char *prebr; /* prefix before a brace, if any */ |
|
234 char *postbr; /* suffix after a brace */ |
|
235 }; |
|
236 |
|
237 /* Flags for compadd and addmatches(). */ |
|
238 |
|
239 #define CAF_QUOTE 1 |
|
240 #define CAF_NOSORT 2 |
|
241 #define CAF_MATCH 4 |
|
242 #define CAF_UNIQCON 8 |
|
243 #define CAF_UNIQALL 16 |
|
244 #define CAF_ARRAYS 32 |
|
245 #define CAF_KEYS 64 |
|
246 #define CAF_ALL 128 |
|
247 |
|
248 /* Data for compadd and addmatches() */ |
|
249 |
|
250 typedef struct cadata *Cadata; |
|
251 |
|
252 struct cadata { |
|
253 char *ipre; /* ignored prefix (-i) */ |
|
254 char *isuf; /* ignored suffix (-I) */ |
|
255 char *ppre; /* `path' prefix (-p) */ |
|
256 char *psuf; /* `path' suffix (-s) */ |
|
257 char *prpre; /* expanded `path' prefix (-W) */ |
|
258 char *pre; /* prefix to insert (-P) */ |
|
259 char *suf; /* suffix to insert (-S) */ |
|
260 char *group; /* name of the group (-[JV]) */ |
|
261 char *rems; /* remove suffix on chars... (-r) */ |
|
262 char *remf; /* function to remove suffix (-R) */ |
|
263 char *ign; /* ignored suffixes (-F) */ |
|
264 int flags; /* CMF_* flags (-[fqn]) */ |
|
265 int aflags; /* CAF_* flags (-[QUa]) */ |
|
266 Cmatcher match; /* match spec (parsed from -M) */ |
|
267 char *exp; /* explanation (-X) */ |
|
268 char *apar; /* array to store matches in (-A) */ |
|
269 char *opar; /* array to store originals in (-O) */ |
|
270 char *dpar; /* array to delete non-matches in (-D) */ |
|
271 char *disp; /* array with display lists (-d) */ |
|
272 char *mesg; /* message to show unconditionally (-x) */ |
|
273 int dummies; /* add that many dummy matches */ |
|
274 }; |
|
275 |
|
276 /* List data. */ |
|
277 |
|
278 typedef struct cldata *Cldata; |
|
279 |
|
280 struct cldata { |
|
281 int columns; /* screen width */ |
|
282 int lines; /* screen height */ |
|
283 int menuacc; /* value of global menuacc */ |
|
284 int valid; /* no need to calculate anew */ |
|
285 int nlist; /* number of matches to list */ |
|
286 int nlines; /* number of lines needed */ |
|
287 int hidden; /* != 0 if there are hidden matches */ |
|
288 int onlyexpl; /* != 0 if only explanations to print */ |
|
289 int showall; /* != 0 if hidden matches should be shown */ |
|
290 }; |
|
291 |
|
292 typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int); |
|
293 |
|
294 /* Flags for fromcomp. */ |
|
295 |
|
296 #define FC_LINE 1 |
|
297 #define FC_INWORD 2 |
|
298 |
|
299 /* Flags for special parameters. */ |
|
300 |
|
301 #define CPN_WORDS 0 |
|
302 #define CP_WORDS (1 << CPN_WORDS) |
|
303 #define CPN_REDIRS 1 |
|
304 #define CP_REDIRS (1 << CPN_REDIRS) |
|
305 #define CPN_CURRENT 2 |
|
306 #define CP_CURRENT (1 << CPN_CURRENT) |
|
307 #define CPN_PREFIX 3 |
|
308 #define CP_PREFIX (1 << CPN_PREFIX) |
|
309 #define CPN_SUFFIX 4 |
|
310 #define CP_SUFFIX (1 << CPN_SUFFIX) |
|
311 #define CPN_IPREFIX 5 |
|
312 #define CP_IPREFIX (1 << CPN_IPREFIX) |
|
313 #define CPN_ISUFFIX 6 |
|
314 #define CP_ISUFFIX (1 << CPN_ISUFFIX) |
|
315 #define CPN_QIPREFIX 7 |
|
316 #define CP_QIPREFIX (1 << CPN_QIPREFIX) |
|
317 #define CPN_QISUFFIX 8 |
|
318 #define CP_QISUFFIX (1 << CPN_QISUFFIX) |
|
319 #define CPN_COMPSTATE 9 |
|
320 #define CP_COMPSTATE (1 << CPN_COMPSTATE) |
|
321 |
|
322 #define CP_REALPARAMS 10 |
|
323 #define CP_ALLREALS ((unsigned int) 0x3ff) |
|
324 |
|
325 |
|
326 #define CPN_NMATCHES 0 |
|
327 #define CP_NMATCHES (1 << CPN_NMATCHES) |
|
328 #define CPN_CONTEXT 1 |
|
329 #define CP_CONTEXT (1 << CPN_CONTEXT) |
|
330 #define CPN_PARAMETER 2 |
|
331 #define CP_PARAMETER (1 << CPN_PARAMETER) |
|
332 #define CPN_REDIRECT 3 |
|
333 #define CP_REDIRECT (1 << CPN_REDIRECT) |
|
334 #define CPN_QUOTE 4 |
|
335 #define CP_QUOTE (1 << CPN_QUOTE) |
|
336 #define CPN_QUOTING 5 |
|
337 #define CP_QUOTING (1 << CPN_QUOTING) |
|
338 #define CPN_RESTORE 6 |
|
339 #define CP_RESTORE (1 << CPN_RESTORE) |
|
340 #define CPN_LIST 7 |
|
341 #define CP_LIST (1 << CPN_LIST) |
|
342 #define CPN_INSERT 8 |
|
343 #define CP_INSERT (1 << CPN_INSERT) |
|
344 #define CPN_EXACT 9 |
|
345 #define CP_EXACT (1 << CPN_EXACT) |
|
346 #define CPN_EXACTSTR 10 |
|
347 #define CP_EXACTSTR (1 << CPN_EXACTSTR) |
|
348 #define CPN_PATMATCH 11 |
|
349 #define CP_PATMATCH (1 << CPN_PATMATCH) |
|
350 #define CPN_PATINSERT 12 |
|
351 #define CP_PATINSERT (1 << CPN_PATINSERT) |
|
352 #define CPN_UNAMBIG 13 |
|
353 #define CP_UNAMBIG (1 << CPN_UNAMBIG) |
|
354 #define CPN_UNAMBIGC 14 |
|
355 #define CP_UNAMBIGC (1 << CPN_UNAMBIGC) |
|
356 #define CPN_UNAMBIGP 15 |
|
357 #define CP_UNAMBIGP (1 << CPN_UNAMBIGP) |
|
358 #define CPN_INSERTP 16 |
|
359 #define CP_INSERTP (1 << CPN_INSERTP) |
|
360 #define CPN_LISTMAX 17 |
|
361 #define CP_LISTMAX (1 << CPN_LISTMAX) |
|
362 #define CPN_LASTPROMPT 18 |
|
363 #define CP_LASTPROMPT (1 << CPN_LASTPROMPT) |
|
364 #define CPN_TOEND 19 |
|
365 #define CP_TOEND (1 << CPN_TOEND) |
|
366 #define CPN_OLDLIST 20 |
|
367 #define CP_OLDLIST (1 << CPN_OLDLIST) |
|
368 #define CPN_OLDINS 21 |
|
369 #define CP_OLDINS (1 << CPN_OLDINS) |
|
370 #define CPN_VARED 22 |
|
371 #define CP_VARED (1 << CPN_VARED) |
|
372 #define CPN_LISTLINES 23 |
|
373 #define CP_LISTLINES (1 << CPN_LISTLINES) |
|
374 #define CPN_QUOTES 24 |
|
375 #define CP_QUOTES (1 << CPN_QUOTES) |
|
376 #define CPN_IGNORED 25 |
|
377 #define CP_IGNORED (1 << CPN_IGNORED) |
|
378 |
|
379 #define CP_KEYPARAMS 26 |
|
380 #define CP_ALLKEYS ((unsigned int) 0x3ffffff) |
|
381 |
|
382 /* Hooks. */ |
|
383 |
|
384 #define INSERTMATCHHOOK (comphooks + 0) |
|
385 #define MENUSTARTHOOK (comphooks + 1) |
|
386 #define COMPCTLMAKEHOOK (comphooks + 2) |
|
387 #define COMPCTLCLEANUPHOOK (comphooks + 3) |
|
388 #define COMPLISTMATCHESHOOK (comphooks + 4) |
|
389 |
|
390 /* compctl hook data struct */ |
|
391 |
|
392 struct ccmakedat { |
|
393 char *str; |
|
394 int incmd; |
|
395 int lst; |
|
396 }; |
|
397 |
|
398 /* Data given to offered hooks. */ |
|
399 |
|
400 typedef struct chdata *Chdata; |
|
401 |
|
402 struct chdata { |
|
403 Cmgroup matches; /* the matches generated */ |
|
404 int num; /* the number of matches */ |
|
405 int nmesg; /* the number of messages */ |
|
406 Cmatch cur; /* current match or NULL */ |
|
407 }; |
|
408 |