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