Annotation of src/usr.bin/mg/funmap.c, Revision 1.58
1.58 ! lum 1: /* $OpenBSD: funmap.c,v 1.57 2019/07/02 16:25:39 lum Exp $ */
1.28 kjell 2:
3: /* This file is in the public domain */
4:
1.49 bcallah 5: #include <sys/queue.h>
6: #include <signal.h>
7: #include <stdio.h>
8: #include <stdlib.h>
9: #include <string.h>
10:
1.1 art 11: #include "def.h"
1.49 bcallah 12: #include "funmap.h"
1.1 art 13: #include "kbd.h"
14:
15: /*
16: * If the function is NULL, it must be listed with the
17: * same name in the map_table.
18: */
19:
20: struct funmap {
1.6 vincent 21: PF fn_funct;
22: const char *fn_name;
1.1 art 23: struct funmap *fn_next;
24: };
25:
26: static struct funmap *funs;
27:
28: static struct funmap functnames[] = {
29: {apropos_command, "apropos",},
1.47 lum 30: {toggleaudiblebell, "audible-bell",},
1.42 florian 31: {auto_execute, "auto-execute",},
1.1 art 32: {fillmode, "auto-fill-mode",},
33: {indentmode, "auto-indent-mode",},
1.33 kjell 34: {backtoindent, "back-to-indentation",},
1.40 lum 35: {backuptohomedir, "backup-to-home-directory",},
1.1 art 36: {backchar, "backward-char",},
37: {delbword, "backward-kill-word",},
38: {gotobop, "backward-paragraph",},
39: {backword, "backward-word",},
40: {gotobob, "beginning-of-buffer",},
41: {gotobol, "beginning-of-line",},
1.57 lum 42: {showmatch, "blink-and-insert",},
1.1 art 43: {bsmap, "bsmap-mode",},
44: {NULL, "c-x 4 prefix",},
45: {NULL, "c-x prefix",},
46: {executemacro, "call-last-kbd-macro",},
47: {capword, "capitalize-word",},
48: {changedir, "cd",},
1.29 kjell 49: {clearmark, "clear-mark",},
1.44 florian 50: {colnotoggle, "column-number-mode",},
1.1 art 51: {copyregion, "copy-region-as-kill",},
52: #ifdef REGEX
53: {cntmatchlines, "count-matches",},
54: {cntnonmatchlines, "count-non-matches",},
55: #endif /* REGEX */
1.42 florian 56: {cscreatelist, "cscope-create-list-of-files-to-index",},
57: {csfuncalled, "cscope-find-called-functions",},
58: {csegrep, "cscope-find-egrep-pattern",},
59: {csfindinc, "cscope-find-files-including-file",},
60: {cscallerfuncs, "cscope-find-functions-calling-this-function",},
61: {csdefinition, "cscope-find-global-definition",},
62: {csfindfile, "cscope-find-this-file",},
63: {cssymbol, "cscope-find-this-symbol",},
64: {csfindtext, "cscope-find-this-text-string",},
65: {csnextfile, "cscope-next-file",},
66: {csnextmatch, "cscope-next-symbol",},
67: {csprevfile, "cscope-prev-file",},
68: {csprevmatch, "cscope-prev-symbol",},
1.22 kjell 69: {redefine_key, "define-key",},
1.1 art 70: {backdel, "delete-backward-char",},
71: {deblank, "delete-blank-lines",},
72: {forwdel, "delete-char",},
73: {delwhite, "delete-horizontal-space",},
1.30 kjell 74: {delleadwhite, "delete-leading-space",},
1.1 art 75: #ifdef REGEX
76: {delmatchlines, "delete-matching-lines",},
77: {delnonmatchlines, "delete-non-matching-lines",},
78: #endif /* REGEX */
79: {onlywind, "delete-other-windows",},
1.42 florian 80: {deltrailwhite, "delete-trailing-space",},
1.1 art 81: {delwind, "delete-window",},
82: {wallchart, "describe-bindings",},
83: {desckey, "describe-key-briefly",},
1.45 florian 84: {diffbuffer, "diff-buffer-with-file",},
1.1 art 85: {digit_argument, "digit-argument",},
86: {lowerregion, "downcase-region",},
87: {lowerword, "downcase-word",},
88: {showversion, "emacs-version",},
89: {finishmacro, "end-kbd-macro",},
90: {gotoeob, "end-of-buffer",},
91: {gotoeol, "end-of-line",},
92: {enlargewind, "enlarge-window",},
93: {NULL, "esc prefix",},
94: {evalbuffer, "eval-current-buffer",},
95: {evalexpr, "eval-expression",},
96: {swapmark, "exchange-point-and-mark",},
97: {extend, "execute-extended-command",},
98: {fillpara, "fill-paragraph",},
1.42 florian 99: {filevisitalt, "find-alternate-file",},
1.1 art 100: {filevisit, "find-file",},
1.42 florian 101: {poptofile, "find-file-other-window",},
1.8 vincent 102: {filevisitro, "find-file-read-only",},
1.42 florian 103: {findtag, "find-tag",},
1.1 art 104: {forwchar, "forward-char",},
105: {gotoeop, "forward-paragraph",},
106: {forwword, "forward-word",},
107: {bindtokey, "global-set-key",},
108: {unbindtokey, "global-unset-key",},
1.42 florian 109: {globalwdtoggle, "global-wd-mode",},
1.1 art 110: {gotoline, "goto-line",},
111: {help_help, "help-help",},
1.42 florian 112: {indent, "indent-current-line",},
1.1 art 113: {insert, "insert",},
114: {bufferinsert, "insert-buffer",},
115: {fileinsert, "insert-file",},
116: {fillword, "insert-with-wrap",},
117: {backisearch, "isearch-backward",},
118: {forwisearch, "isearch-forward",},
1.34 kjell 119: {joinline, "join-line",},
1.1 art 120: {justone, "just-one-space",},
121: {ctrlg, "keyboard-quit",},
1.10 jfb 122: {killbuffer_cmd, "kill-buffer",},
1.1 art 123: {killline, "kill-line",},
124: {killpara, "kill-paragraph",},
125: {killregion, "kill-region",},
126: {delfword, "kill-word",},
1.40 lum 127: {toggleleavetmp, "leave-tmpdir-backups",},
1.24 kjell 128: {linenotoggle, "line-number-mode",},
1.1 art 129: {listbuffers, "list-buffers",},
130: {evalfile, "load",},
131: {localbind, "local-set-key",},
132: {localunbind, "local-unset-key",},
133: {makebkfile, "make-backup-files",},
1.43 jasper 134: {makedir, "make-directory",},
1.50 lum 135: {markpara, "mark-paragraph",},
1.37 lum 136: {markbuffer, "mark-whole-buffer",},
1.1 art 137: {do_meta, "meta-key-mode",}, /* better name, anyone? */
138: {negative_argument, "negative-argument",},
1.48 bcallah 139: {enewline, "newline",},
1.30 kjell 140: {lfindent, "newline-and-indent",},
1.1 art 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.42 florian 149: {poptag, "pop-tag-mark",},
1.1 art 150: {prefixregion, "prefix-region",},
151: {backline, "previous-line",},
152: {prevwind, "previous-window",},
153: {spawncli, "push-shell",},
154: {showcwdir, "pwd",},
155: {queryrepl, "query-replace",},
1.15 deraadt 156: #ifdef REGEX
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.42 florian 167: #ifdef REGEX
168: {replstr, "replace-string",},
169: #endif /* REGEX */
170: {revertbuffer, "revert-buffer",},
1.1 art 171: {filesave, "save-buffer",},
172: {quit, "save-buffers-kill-emacs",},
173: {savebuffers, "save-some-buffers",},
174: {backpage, "scroll-down",},
175: {back1page, "scroll-one-line-down",},
176: {forw1page, "scroll-one-line-up",},
177: {pagenext, "scroll-other-window",},
178: {forwpage, "scroll-up",},
179: {searchagain, "search-again",},
180: {backsearch, "search-backward",},
181: {forwsearch, "search-forward",},
1.58 ! lum 182: {ask_selfinsert, "self-insert-char",},
1.1 art 183: {selfinsert, "self-insert-command",},
1.53 lum 184: {sentencespace, "sentence-end-double-space",},
1.1 art 185: #ifdef REGEX
186: {setcasefold, "set-case-fold-search",},
187: #endif /* REGEX */
1.54 reyk 188: {setcasereplace, "set-case-replace",},
1.1 art 189: {set_default_mode, "set-default-mode",},
190: {setfillcol, "set-fill-column",},
191: {setmark, "set-mark-command",},
192: {setprefix, "set-prefix-string",},
1.46 lum 193: {shellcommand, "shell-command",},
1.37 lum 194: {piperegion, "shell-command-on-region",},
1.1 art 195: {shrinkwind, "shrink-window",},
196: #ifdef NOTAB
197: {space_to_tabstop, "space-to-tabstop",},
198: #endif /* NOTAB */
199: {splitwind, "split-window-vertically",},
200: {definemacro, "start-kbd-macro",},
201: {spawncli, "suspend-emacs",},
202: {usebuffer, "switch-to-buffer",},
203: {poptobuffer, "switch-to-buffer-other-window",},
1.8 vincent 204: {togglereadonly, "toggle-read-only" },
1.55 lum 205: {togglereadonlyall, "toggle-read-only-all" },
1.1 art 206: {twiddle, "transpose-chars",},
1.51 lum 207: {transposepara, "transpose-paragraphs",},
1.52 lum 208: {transposeword, "transpose-words",},
1.42 florian 209: {undo, "undo",},
210: {undo_add_boundary, "undo-boundary",},
211: {undo_boundary_enable, "undo-boundary-toggle",},
212: {undo_enable, "undo-enable",},
213: {undo_dump, "undo-list",},
1.1 art 214: {universal_argument, "universal-argument",},
215: {upperregion, "upcase-region",},
216: {upperword, "upcase-word",},
1.47 lum 217: {togglevisiblebell, "visible-bell",},
1.42 florian 218: {tagsvisit, "visit-tags-table",},
1.1 art 219: {showcpos, "what-cursor-position",},
220: {filewrite, "write-file",},
221: {yank, "yank",},
1.11 db 222: {NULL, NULL,}
1.1 art 223: };
224:
225: void
226: funmap_init(void)
227: {
228: struct funmap *fn;
229:
230: for (fn = functnames; fn->fn_name != NULL; fn++) {
231: fn->fn_next = funs;
232: funs = fn;
233: }
234: }
235:
236: int
1.6 vincent 237: funmap_add(PF fun, const char *fname)
1.1 art 238: {
239: struct funmap *fn;
240:
241: if ((fn = malloc(sizeof(*fn))) == NULL)
1.11 db 242: return (FALSE);
1.1 art 243:
244: fn->fn_funct = fun;
245: fn->fn_name = fname;
246: fn->fn_next = funs;
247:
248: funs = fn;
1.11 db 249: return (TRUE);
1.1 art 250: }
251:
252: /*
253: * Translate from function name to function pointer.
254: */
255: PF
1.6 vincent 256: name_function(const char *fname)
1.1 art 257: {
258: struct funmap *fn;
259:
260: for (fn = funs; fn != NULL; fn = fn->fn_next) {
261: if (strcmp(fn->fn_name, fname) == 0)
1.11 db 262: return (fn->fn_funct);
1.1 art 263: }
1.11 db 264: return (NULL);
1.1 art 265: }
266:
1.6 vincent 267: const char *
1.1 art 268: function_name(PF fun)
269: {
270: struct funmap *fn;
271:
272: for (fn = funs; fn != NULL; fn = fn->fn_next) {
273: if (fn->fn_funct == fun)
1.11 db 274: return (fn->fn_name);
1.1 art 275: }
1.11 db 276: return (NULL);
1.1 art 277: }
278:
279: /*
1.11 db 280: * List possible function name completions.
1.1 art 281: */
1.17 deraadt 282: struct list *
1.12 otto 283: complete_function_list(const char *fname)
1.1 art 284: {
1.11 db 285: struct funmap *fn;
1.23 kjell 286: struct list *head, *el;
1.11 db 287: int len;
1.1 art 288:
289: len = strlen(fname);
290: head = NULL;
291: for (fn = funs; fn != NULL; fn = fn->fn_next) {
292: if (memcmp(fname, fn->fn_name, len) == 0) {
293: if ((el = malloc(sizeof(*el))) == NULL) {
294: free_file_list(head);
1.11 db 295: return (NULL);
1.1 art 296: }
1.23 kjell 297: el->l_name = strdup(fn->fn_name);
1.1 art 298: el->l_next = head;
299: head = el;
300: }
301: }
1.11 db 302: return (head);
1.1 art 303: }