Annotation of src/usr.bin/mg/funmap.c, Revision 1.9
1.9 ! vincent 1: /* $OpenBSD: funmap.c,v 1.8 2002/05/29 12:33:36 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 */
1.9 ! vincent 46: { auto_execute, "auto-execute", },
1.1 art 47: {fillmode, "auto-fill-mode",},
48: {indentmode, "auto-indent-mode",},
49: {backchar, "backward-char",},
50: {delbword, "backward-kill-word",},
51: {gotobop, "backward-paragraph",},
52: {backword, "backward-word",},
53: {gotobob, "beginning-of-buffer",},
54: {gotobol, "beginning-of-line",},
55: {blinkparen, "blink-matching-paren",},
56: {showmatch, "blink-matching-paren-hack",},
57: #ifdef BSMAP
58: {bsmap, "bsmap-mode",},
59: #endif /* BSMAP */
60: {NULL, "c-x 4 prefix",},
61: {NULL, "c-x prefix",},
62: #ifndef NO_MACRO
63: {executemacro, "call-last-kbd-macro",},
64: #endif /* !NO_MACRO */
65: {capword, "capitalize-word",},
66: #ifndef NO_DIR
67: {changedir, "cd",},
68: #endif /* !NO_DIR */
69: {copyregion, "copy-region-as-kill",},
70: #ifdef REGEX
71: {cntmatchlines, "count-matches",},
72: {cntnonmatchlines, "count-non-matches",},
73: #endif /* REGEX */
74: {define_key, "define-key",},
75: {backdel, "delete-backward-char",},
76: {deblank, "delete-blank-lines",},
77: {forwdel, "delete-char",},
78: {delwhite, "delete-horizontal-space",},
79: #ifdef REGEX
80: {delmatchlines, "delete-matching-lines",},
81: {delnonmatchlines, "delete-non-matching-lines",},
82: #endif /* REGEX */
83: {onlywind, "delete-other-windows",},
84: {delwind, "delete-window",},
85: #ifndef NO_HELP
86: {wallchart, "describe-bindings",},
87: {desckey, "describe-key-briefly",},
88: #endif /* !NO_HELP */
89: {digit_argument, "digit-argument",},
90: #ifndef NO_DIRED
91: {dired, "dired",},
92: {d_undelbak, "dired-backup-unflag",},
93: {d_copy, "dired-copy-file",},
94: {d_expunge, "dired-do-deletions",},
95: {d_findfile, "dired-find-file",},
96: {d_ffotherwindow, "dired-find-file-other-window",},
97: {d_del, "dired-flag-file-deleted",},
98: {d_otherwindow, "dired-other-window",},
99: {d_rename, "dired-rename-file",},
100: {d_undel, "dired-unflag",},
101: #endif /* !NO_DIRED */
102: {lowerregion, "downcase-region",},
103: {lowerword, "downcase-word",},
104: {showversion, "emacs-version",},
105: #ifndef NO_MACRO
106: {finishmacro, "end-kbd-macro",},
107: #endif /* !NO_MACRO */
108: {gotoeob, "end-of-buffer",},
109: {gotoeol, "end-of-line",},
110: {enlargewind, "enlarge-window",},
111: {NULL, "esc prefix",},
112: #ifndef NO_STARTUP
113: {evalbuffer, "eval-current-buffer",},
114: {evalexpr, "eval-expression",},
115: #endif /* !NO_STARTUP */
116: {swapmark, "exchange-point-and-mark",},
117: {extend, "execute-extended-command",},
118: {fillpara, "fill-paragraph",},
119: {filevisit, "find-file",},
1.8 vincent 120: {filevisitro, "find-file-read-only",},
1.1 art 121: {poptofile, "find-file-other-window",},
122: {forwchar, "forward-char",},
123: {gotoeop, "forward-paragraph",},
124: {forwword, "forward-word",},
125: {bindtokey, "global-set-key",},
126: {unbindtokey, "global-unset-key",},
127: {gotoline, "goto-line",},
128: #ifndef NO_HELP
129: {NULL, "help",},
130: {help_help, "help-help",},
131: #endif /* !NO_HELP */
132: {insert, "insert",},
133: {bufferinsert, "insert-buffer",},
134: {fileinsert, "insert-file",},
135: {fillword, "insert-with-wrap",},
136: {backisearch, "isearch-backward",},
137: {forwisearch, "isearch-forward",},
138: {justone, "just-one-space",},
139: {ctrlg, "keyboard-quit",},
140: {killbuffer, "kill-buffer",},
141: {killline, "kill-line",},
142: {killpara, "kill-paragraph",},
143: {killregion, "kill-region",},
144: {delfword, "kill-word",},
145: {listbuffers, "list-buffers",},
146: #ifndef NO_STARTUP
147: {evalfile, "load",},
148: #endif /* !NO_STARTUP */
149: {localbind, "local-set-key",},
150: {localunbind, "local-unset-key",},
151: #ifndef NO_BACKUP
152: {makebkfile, "make-backup-files",},
153: #endif /* !NO_BACKUP */
154: #ifdef DO_METAKEY
155: {do_meta, "meta-key-mode",}, /* better name, anyone? */
156: #endif /* DO_METAKEY */
157: {negative_argument, "negative-argument",},
158: {newline, "newline",},
159: {indent, "newline-and-indent",},
160: {forwline, "next-line",},
161: #ifdef NOTAB
162: {notabmode, "no-tab-mode",},
163: #endif /* NOTAB */
164: {notmodified, "not-modified",},
165: {openline, "open-line",},
166: {nextwind, "other-window",},
167: {overwrite, "overwrite-mode",},
168: #ifdef PREFIXREGION
169: {prefixregion, "prefix-region",},
170: #endif /* PREFIXREGION */
171: {backline, "previous-line",},
172: {prevwind, "previous-window",},
173: {spawncli, "push-shell",},
174: #ifndef NO_DIR
175: {showcwdir, "pwd",},
176: #endif /* !NO_DIR */
177: {queryrepl, "query-replace",},
178: #ifdef REGEX
179: {re_queryrepl, "query-replace-regexp",},
180: #endif /* REGEX */
181: {quote, "quoted-insert",},
182: #ifdef REGEX
183: {re_searchagain, "re-search-again",},
184: {re_backsearch, "re-search-backward",},
185: {re_forwsearch, "re-search-forward",},
186: #endif /* REGEX */
187: {reposition, "recenter",},
188: {refresh, "redraw-display",},
189: {filesave, "save-buffer",},
190: {quit, "save-buffers-kill-emacs",},
191: {savebuffers, "save-some-buffers",},
192: {backpage, "scroll-down",},
193: {back1page, "scroll-one-line-down",},
194: {forw1page, "scroll-one-line-up",},
195: {pagenext, "scroll-other-window",},
196: {forwpage, "scroll-up",},
197: {searchagain, "search-again",},
198: {backsearch, "search-backward",},
199: {forwsearch, "search-forward",},
200: {selfinsert, "self-insert-command",},
201: #ifdef REGEX
202: {setcasefold, "set-case-fold-search",},
203: #endif /* REGEX */
204: {set_default_mode, "set-default-mode",},
205: {setfillcol, "set-fill-column",},
206: {setmark, "set-mark-command",},
207: #ifdef PREFIXREGION
208: {setprefix, "set-prefix-string",},
209: #endif /* PREFIXREGION */
210: {shrinkwind, "shrink-window",},
211: #ifdef NOTAB
212: {space_to_tabstop, "space-to-tabstop",},
213: #endif /* NOTAB */
214: {splitwind, "split-window-vertically",},
215: #ifndef NO_MACRO
216: {definemacro, "start-kbd-macro",},
217: #endif /* !NO_MACRO */
218: {spawncli, "suspend-emacs",},
219: {usebuffer, "switch-to-buffer",},
220: {poptobuffer, "switch-to-buffer-other-window",},
1.8 vincent 221: {togglereadonly, "toggle-read-only" },
1.1 art 222: {twiddle, "transpose-chars",},
1.5 vincent 223: { undo, "undo", },
1.7 vincent 224: { undo_dump, "undo-list", },
1.1 art 225: {universal_argument, "universal-argument",},
226: {upperregion, "upcase-region",},
227: {upperword, "upcase-word",},
228: {showcpos, "what-cursor-position",},
229: {filewrite, "write-file",},
230: {yank, "yank",},
231: {NULL, NULL,},
232: };
233:
234: void
235: funmap_init(void)
236: {
237: struct funmap *fn;
238:
239: for (fn = functnames; fn->fn_name != NULL; fn++) {
240: fn->fn_next = funs;
241: funs = fn;
242: }
243: }
244:
245: int
1.6 vincent 246: funmap_add(PF fun, const char *fname)
1.1 art 247: {
248: struct funmap *fn;
249:
250: if ((fn = malloc(sizeof(*fn))) == NULL)
251: return FALSE;
252:
253: fn->fn_funct = fun;
254: fn->fn_name = fname;
255: fn->fn_next = funs;
256:
257: funs = fn;
258: return TRUE;
259: }
260:
261: /*
262: * Translate from function name to function pointer.
263: */
264: PF
1.6 vincent 265: name_function(const char *fname)
1.1 art 266: {
267: struct funmap *fn;
268:
269: for (fn = funs; fn != NULL; fn = fn->fn_next) {
270: if (strcmp(fn->fn_name, fname) == 0)
271: return fn->fn_funct;
272: }
273: return NULL;
274: }
275:
1.6 vincent 276: const char *
1.1 art 277: function_name(PF fun)
278: {
279: struct funmap *fn;
280:
281: for (fn = funs; fn != NULL; fn = fn->fn_next) {
282: if (fn->fn_funct == fun)
283: return fn->fn_name;
284: }
285: return NULL;
286: }
287:
288: /*
289: * list possible function name completions.
290: */
291: LIST *
1.6 vincent 292: complete_function_list(const char *fname, int c)
1.1 art 293: {
294: struct funmap *fn;
295: LIST *head, *el;
296: int len;
297:
298: len = strlen(fname);
299: head = NULL;
300: for (fn = funs; fn != NULL; fn = fn->fn_next) {
301: if (memcmp(fname, fn->fn_name, len) == 0) {
302: if ((el = malloc(sizeof(*el))) == NULL) {
303: free_file_list(head);
304: return NULL;
305: }
306: el->l_name = fn->fn_name;
307: el->l_next = head;
308: head = el;
309: }
310: }
311:
312: return head;
313: }
314:
315:
316: