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