[BACK]Return to funmap.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/funmap.c, Revision 1.55

1.55    ! lum         1: /*     $OpenBSD: funmap.c,v 1.54 2018/08/29 07:50:16 reyk 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.31      kjell      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",},
                    182:        {selfinsert, "self-insert-command",},
1.53      lum       183:        {sentencespace, "sentence-end-double-space",},
1.1       art       184: #ifdef REGEX
                    185:        {setcasefold, "set-case-fold-search",},
                    186: #endif /* REGEX */
1.54      reyk      187:        {setcasereplace, "set-case-replace",},
1.1       art       188:        {set_default_mode, "set-default-mode",},
                    189:        {setfillcol, "set-fill-column",},
                    190:        {setmark, "set-mark-command",},
                    191:        {setprefix, "set-prefix-string",},
1.46      lum       192:        {shellcommand, "shell-command",},
1.37      lum       193:        {piperegion, "shell-command-on-region",},
1.1       art       194:        {shrinkwind, "shrink-window",},
                    195: #ifdef NOTAB
                    196:        {space_to_tabstop, "space-to-tabstop",},
                    197: #endif /* NOTAB */
                    198:        {splitwind, "split-window-vertically",},
                    199:        {definemacro, "start-kbd-macro",},
                    200:        {spawncli, "suspend-emacs",},
                    201:        {usebuffer, "switch-to-buffer",},
                    202:        {poptobuffer, "switch-to-buffer-other-window",},
1.8       vincent   203:        {togglereadonly, "toggle-read-only" },
1.55    ! lum       204:        {togglereadonlyall, "toggle-read-only-all" },
1.1       art       205:        {twiddle, "transpose-chars",},
1.51      lum       206:        {transposepara, "transpose-paragraphs",},
1.52      lum       207:        {transposeword, "transpose-words",},
1.42      florian   208:        {undo, "undo",},
                    209:        {undo_add_boundary, "undo-boundary",},
                    210:        {undo_boundary_enable, "undo-boundary-toggle",},
                    211:        {undo_enable, "undo-enable",},
                    212:        {undo_dump, "undo-list",},
1.1       art       213:        {universal_argument, "universal-argument",},
                    214:        {upperregion, "upcase-region",},
                    215:        {upperword, "upcase-word",},
1.47      lum       216:        {togglevisiblebell, "visible-bell",},
1.42      florian   217:        {tagsvisit, "visit-tags-table",},
1.1       art       218:        {showcpos, "what-cursor-position",},
                    219:        {filewrite, "write-file",},
                    220:        {yank, "yank",},
1.11      db        221:        {NULL, NULL,}
1.1       art       222: };
                    223:
                    224: void
                    225: funmap_init(void)
                    226: {
                    227:        struct funmap *fn;
                    228:
                    229:        for (fn = functnames; fn->fn_name != NULL; fn++) {
                    230:                fn->fn_next = funs;
                    231:                funs = fn;
                    232:        }
                    233: }
                    234:
                    235: int
1.6       vincent   236: funmap_add(PF fun, const char *fname)
1.1       art       237: {
                    238:        struct funmap *fn;
                    239:
                    240:        if ((fn = malloc(sizeof(*fn))) == NULL)
1.11      db        241:                return (FALSE);
1.1       art       242:
                    243:        fn->fn_funct = fun;
                    244:        fn->fn_name = fname;
                    245:        fn->fn_next = funs;
                    246:
                    247:        funs = fn;
1.11      db        248:        return (TRUE);
1.1       art       249: }
                    250:
                    251: /*
                    252:  * Translate from function name to function pointer.
                    253:  */
                    254: PF
1.6       vincent   255: name_function(const char *fname)
1.1       art       256: {
                    257:        struct funmap *fn;
                    258:
                    259:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    260:                if (strcmp(fn->fn_name, fname) == 0)
1.11      db        261:                        return (fn->fn_funct);
1.1       art       262:        }
1.11      db        263:        return (NULL);
1.1       art       264: }
                    265:
1.6       vincent   266: const char *
1.1       art       267: function_name(PF fun)
                    268: {
                    269:        struct funmap *fn;
                    270:
                    271:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    272:                if (fn->fn_funct == fun)
1.11      db        273:                        return (fn->fn_name);
1.1       art       274:        }
1.11      db        275:        return (NULL);
1.1       art       276: }
                    277:
                    278: /*
1.11      db        279:  * List possible function name completions.
1.1       art       280:  */
1.17      deraadt   281: struct list *
1.12      otto      282: complete_function_list(const char *fname)
1.1       art       283: {
1.11      db        284:        struct funmap   *fn;
1.23      kjell     285:        struct list     *head, *el;
1.11      db        286:        int              len;
1.1       art       287:
                    288:        len = strlen(fname);
                    289:        head = NULL;
                    290:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    291:                if (memcmp(fname, fn->fn_name, len) == 0) {
                    292:                        if ((el = malloc(sizeof(*el))) == NULL) {
                    293:                                free_file_list(head);
1.11      db        294:                                return (NULL);
1.1       art       295:                        }
1.23      kjell     296:                        el->l_name = strdup(fn->fn_name);
1.1       art       297:                        el->l_next = head;
                    298:                        head = el;
                    299:                }
                    300:        }
1.11      db        301:        return (head);
1.1       art       302: }