Annotation of src/usr.bin/mg/funmap.c, Revision 1.6
1.6 ! vincent 1: /* $OpenBSD: funmap.c,v 1.5 2002/02/20 22:30:54 vincent Exp $ */
1.3 art 2: /*
3: * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: *
14: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24: */
1.1 art 25: #include "def.h"
26: #include "kbd.h"
27: #include "funmap.h"
28:
29: /*
30: * If the function is NULL, it must be listed with the
31: * same name in the map_table.
32: */
33:
34: struct funmap {
1.6 ! vincent 35: PF fn_funct;
! 36: const char *fn_name;
1.1 art 37: struct funmap *fn_next;
38: };
39:
40: static struct funmap *funs;
41:
42: static struct funmap functnames[] = {
43: #ifndef NO_HELP
44: {apropos_command, "apropos",},
45: #endif /* !NO_HELP */
46: {fillmode, "auto-fill-mode",},
47: {indentmode, "auto-indent-mode",},
48: {backchar, "backward-char",},
49: {delbword, "backward-kill-word",},
50: {gotobop, "backward-paragraph",},
51: {backword, "backward-word",},
52: {gotobob, "beginning-of-buffer",},
53: {gotobol, "beginning-of-line",},
54: {blinkparen, "blink-matching-paren",},
55: {showmatch, "blink-matching-paren-hack",},
56: #ifdef BSMAP
57: {bsmap, "bsmap-mode",},
58: #endif /* BSMAP */
59: {NULL, "c-x 4 prefix",},
60: {NULL, "c-x prefix",},
61: #ifndef NO_MACRO
62: {executemacro, "call-last-kbd-macro",},
63: #endif /* !NO_MACRO */
64: {capword, "capitalize-word",},
65: #ifndef NO_DIR
66: {changedir, "cd",},
67: #endif /* !NO_DIR */
68: {copyregion, "copy-region-as-kill",},
69: #ifdef REGEX
70: {cntmatchlines, "count-matches",},
71: {cntnonmatchlines, "count-non-matches",},
72: #endif /* REGEX */
73: {define_key, "define-key",},
74: {backdel, "delete-backward-char",},
75: {deblank, "delete-blank-lines",},
76: {forwdel, "delete-char",},
77: {delwhite, "delete-horizontal-space",},
78: #ifdef REGEX
79: {delmatchlines, "delete-matching-lines",},
80: {delnonmatchlines, "delete-non-matching-lines",},
81: #endif /* REGEX */
82: {onlywind, "delete-other-windows",},
83: {delwind, "delete-window",},
84: #ifndef NO_HELP
85: {wallchart, "describe-bindings",},
86: {desckey, "describe-key-briefly",},
87: #endif /* !NO_HELP */
88: {digit_argument, "digit-argument",},
89: #ifndef NO_DIRED
90: {dired, "dired",},
91: {d_undelbak, "dired-backup-unflag",},
92: {d_copy, "dired-copy-file",},
93: {d_expunge, "dired-do-deletions",},
94: {d_findfile, "dired-find-file",},
95: {d_ffotherwindow, "dired-find-file-other-window",},
96: {d_del, "dired-flag-file-deleted",},
97: {d_otherwindow, "dired-other-window",},
98: {d_rename, "dired-rename-file",},
99: {d_undel, "dired-unflag",},
100: #endif /* !NO_DIRED */
101: {lowerregion, "downcase-region",},
102: {lowerword, "downcase-word",},
103: {showversion, "emacs-version",},
104: #ifndef NO_MACRO
105: {finishmacro, "end-kbd-macro",},
106: #endif /* !NO_MACRO */
107: {gotoeob, "end-of-buffer",},
108: {gotoeol, "end-of-line",},
109: {enlargewind, "enlarge-window",},
110: {NULL, "esc prefix",},
111: #ifndef NO_STARTUP
112: {evalbuffer, "eval-current-buffer",},
113: {evalexpr, "eval-expression",},
114: #endif /* !NO_STARTUP */
115: {swapmark, "exchange-point-and-mark",},
116: {extend, "execute-extended-command",},
117: {fillpara, "fill-paragraph",},
118: {filevisit, "find-file",},
119: {poptofile, "find-file-other-window",},
120: {forwchar, "forward-char",},
121: {gotoeop, "forward-paragraph",},
122: {forwword, "forward-word",},
123: {bindtokey, "global-set-key",},
124: {unbindtokey, "global-unset-key",},
125: {gotoline, "goto-line",},
126: #ifndef NO_HELP
127: {NULL, "help",},
128: {help_help, "help-help",},
129: #endif /* !NO_HELP */
130: {insert, "insert",},
131: {bufferinsert, "insert-buffer",},
132: {fileinsert, "insert-file",},
133: {fillword, "insert-with-wrap",},
134: {backisearch, "isearch-backward",},
135: {forwisearch, "isearch-forward",},
136: {justone, "just-one-space",},
137: {ctrlg, "keyboard-quit",},
138: {killbuffer, "kill-buffer",},
139: {killline, "kill-line",},
140: {killpara, "kill-paragraph",},
141: {killregion, "kill-region",},
142: {delfword, "kill-word",},
143: {listbuffers, "list-buffers",},
144: #ifndef NO_STARTUP
145: {evalfile, "load",},
146: #endif /* !NO_STARTUP */
147: {localbind, "local-set-key",},
148: {localunbind, "local-unset-key",},
149: #ifndef NO_BACKUP
150: {makebkfile, "make-backup-files",},
151: #endif /* !NO_BACKUP */
152: #ifdef DO_METAKEY
153: {do_meta, "meta-key-mode",}, /* better name, anyone? */
154: #endif /* DO_METAKEY */
155: {negative_argument, "negative-argument",},
156: {newline, "newline",},
157: {indent, "newline-and-indent",},
158: {forwline, "next-line",},
159: #ifdef NOTAB
160: {notabmode, "no-tab-mode",},
161: #endif /* NOTAB */
162: {notmodified, "not-modified",},
163: {openline, "open-line",},
164: {nextwind, "other-window",},
165: {overwrite, "overwrite-mode",},
166: #ifdef PREFIXREGION
167: {prefixregion, "prefix-region",},
168: #endif /* PREFIXREGION */
169: {backline, "previous-line",},
170: {prevwind, "previous-window",},
171: {spawncli, "push-shell",},
172: #ifndef NO_DIR
173: {showcwdir, "pwd",},
174: #endif /* !NO_DIR */
175: {queryrepl, "query-replace",},
176: #ifdef REGEX
177: {re_queryrepl, "query-replace-regexp",},
178: #endif /* REGEX */
179: {quote, "quoted-insert",},
180: #ifdef REGEX
181: {re_searchagain, "re-search-again",},
182: {re_backsearch, "re-search-backward",},
183: {re_forwsearch, "re-search-forward",},
184: #endif /* REGEX */
185: {reposition, "recenter",},
186: {refresh, "redraw-display",},
187: {filesave, "save-buffer",},
188: {quit, "save-buffers-kill-emacs",},
189: {savebuffers, "save-some-buffers",},
190: {backpage, "scroll-down",},
191: {back1page, "scroll-one-line-down",},
192: {forw1page, "scroll-one-line-up",},
193: {pagenext, "scroll-other-window",},
194: {forwpage, "scroll-up",},
195: {searchagain, "search-again",},
196: {backsearch, "search-backward",},
197: {forwsearch, "search-forward",},
198: {selfinsert, "self-insert-command",},
199: #ifdef REGEX
200: {setcasefold, "set-case-fold-search",},
201: #endif /* REGEX */
202: {set_default_mode, "set-default-mode",},
203: {setfillcol, "set-fill-column",},
204: {setmark, "set-mark-command",},
205: #ifdef PREFIXREGION
206: {setprefix, "set-prefix-string",},
207: #endif /* PREFIXREGION */
208: {shrinkwind, "shrink-window",},
209: #ifdef NOTAB
210: {space_to_tabstop, "space-to-tabstop",},
211: #endif /* NOTAB */
212: {splitwind, "split-window-vertically",},
213: #ifndef NO_MACRO
214: {definemacro, "start-kbd-macro",},
215: #endif /* !NO_MACRO */
216: {spawncli, "suspend-emacs",},
217: {usebuffer, "switch-to-buffer",},
218: {poptobuffer, "switch-to-buffer-other-window",},
219: {twiddle, "transpose-chars",},
1.5 vincent 220: { undo, "undo", },
1.1 art 221: {universal_argument, "universal-argument",},
222: {upperregion, "upcase-region",},
223: {upperword, "upcase-word",},
224: {showcpos, "what-cursor-position",},
225: {filewrite, "write-file",},
226: {yank, "yank",},
227: {NULL, NULL,},
228: };
229:
230: void
231: funmap_init(void)
232: {
233: struct funmap *fn;
234:
235: for (fn = functnames; fn->fn_name != NULL; fn++) {
236: fn->fn_next = funs;
237: funs = fn;
238: }
239: }
240:
241: int
1.6 ! vincent 242: funmap_add(PF fun, const char *fname)
1.1 art 243: {
244: struct funmap *fn;
245:
246: if ((fn = malloc(sizeof(*fn))) == NULL)
247: return FALSE;
248:
249: fn->fn_funct = fun;
250: fn->fn_name = fname;
251: fn->fn_next = funs;
252:
253: funs = fn;
254: return TRUE;
255: }
256:
257: /*
258: * Translate from function name to function pointer.
259: */
260: PF
1.6 ! vincent 261: name_function(const char *fname)
1.1 art 262: {
263: struct funmap *fn;
264:
265: for (fn = funs; fn != NULL; fn = fn->fn_next) {
266: if (strcmp(fn->fn_name, fname) == 0)
267: return fn->fn_funct;
268: }
269: return NULL;
270: }
271:
1.6 ! vincent 272: const char *
1.1 art 273: function_name(PF fun)
274: {
275: struct funmap *fn;
276:
277: for (fn = funs; fn != NULL; fn = fn->fn_next) {
278: if (fn->fn_funct == fun)
279: return fn->fn_name;
280: }
281: return NULL;
282: }
283:
284: /*
285: * list possible function name completions.
286: */
287: LIST *
1.6 ! vincent 288: complete_function_list(const char *fname, int c)
1.1 art 289: {
290: struct funmap *fn;
291: LIST *head, *el;
292: int len;
293:
294: len = strlen(fname);
295: head = NULL;
296: for (fn = funs; fn != NULL; fn = fn->fn_next) {
297: if (memcmp(fname, fn->fn_name, len) == 0) {
298: if ((el = malloc(sizeof(*el))) == NULL) {
299: free_file_list(head);
300: return NULL;
301: }
302: el->l_name = fn->fn_name;
303: el->l_next = head;
304: head = el;
305: }
306: }
307:
308: return head;
309: }
310:
311:
312: