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