[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.49

1.49    ! bcallah     1: /*     $OpenBSD: funmap.c,v 1.48 2015/03/16 13:47:48 bcallah 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.37      lum       135:        {markbuffer, "mark-whole-buffer",},
1.1       art       136:        {do_meta, "meta-key-mode",},    /* better name, anyone? */
                    137:        {negative_argument, "negative-argument",},
1.48      bcallah   138:        {enewline, "newline",},
1.30      kjell     139:        {lfindent, "newline-and-indent",},
1.1       art       140:        {forwline, "next-line",},
                    141: #ifdef NOTAB
                    142:        {notabmode, "no-tab-mode",},
                    143: #endif /* NOTAB */
                    144:        {notmodified, "not-modified",},
                    145:        {openline, "open-line",},
                    146:        {nextwind, "other-window",},
1.22      kjell     147:        {overwrite_mode, "overwrite-mode",},
1.42      florian   148:        {poptag, "pop-tag-mark",},
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.1       art       156:        {re_queryrepl, "query-replace-regexp",},
                    157: #endif /* REGEX */
                    158:        {quote, "quoted-insert",},
                    159: #ifdef REGEX
                    160:        {re_searchagain, "re-search-again",},
                    161:        {re_backsearch, "re-search-backward",},
                    162:        {re_forwsearch, "re-search-forward",},
                    163: #endif /* REGEX */
                    164:        {reposition, "recenter",},
1.22      kjell     165:        {redraw, "redraw-display",},
1.42      florian   166: #ifdef REGEX
                    167:        {replstr, "replace-string",},
                    168: #endif /* REGEX */
                    169:        {revertbuffer, "revert-buffer",},
1.1       art       170:        {filesave, "save-buffer",},
                    171:        {quit, "save-buffers-kill-emacs",},
                    172:        {savebuffers, "save-some-buffers",},
                    173:        {backpage, "scroll-down",},
                    174:        {back1page, "scroll-one-line-down",},
                    175:        {forw1page, "scroll-one-line-up",},
                    176:        {pagenext, "scroll-other-window",},
                    177:        {forwpage, "scroll-up",},
                    178:        {searchagain, "search-again",},
                    179:        {backsearch, "search-backward",},
                    180:        {forwsearch, "search-forward",},
                    181:        {selfinsert, "self-insert-command",},
                    182: #ifdef REGEX
                    183:        {setcasefold, "set-case-fold-search",},
                    184: #endif /* REGEX */
                    185:        {set_default_mode, "set-default-mode",},
                    186:        {setfillcol, "set-fill-column",},
                    187:        {setmark, "set-mark-command",},
                    188:        {setprefix, "set-prefix-string",},
1.46      lum       189:        {shellcommand, "shell-command",},
1.37      lum       190:        {piperegion, "shell-command-on-region",},
1.1       art       191:        {shrinkwind, "shrink-window",},
                    192: #ifdef NOTAB
                    193:        {space_to_tabstop, "space-to-tabstop",},
                    194: #endif /* NOTAB */
                    195:        {splitwind, "split-window-vertically",},
                    196:        {definemacro, "start-kbd-macro",},
                    197:        {spawncli, "suspend-emacs",},
                    198:        {usebuffer, "switch-to-buffer",},
                    199:        {poptobuffer, "switch-to-buffer-other-window",},
1.8       vincent   200:        {togglereadonly, "toggle-read-only" },
1.1       art       201:        {twiddle, "transpose-chars",},
1.42      florian   202:        {undo, "undo",},
                    203:        {undo_add_boundary, "undo-boundary",},
                    204:        {undo_boundary_enable, "undo-boundary-toggle",},
                    205:        {undo_enable, "undo-enable",},
                    206:        {undo_dump, "undo-list",},
1.1       art       207:        {universal_argument, "universal-argument",},
                    208:        {upperregion, "upcase-region",},
                    209:        {upperword, "upcase-word",},
1.47      lum       210:        {togglevisiblebell, "visible-bell",},
1.42      florian   211:        {tagsvisit, "visit-tags-table",},
1.1       art       212:        {showcpos, "what-cursor-position",},
                    213:        {filewrite, "write-file",},
                    214:        {yank, "yank",},
1.11      db        215:        {NULL, NULL,}
1.1       art       216: };
                    217:
                    218: void
                    219: funmap_init(void)
                    220: {
                    221:        struct funmap *fn;
                    222:
                    223:        for (fn = functnames; fn->fn_name != NULL; fn++) {
                    224:                fn->fn_next = funs;
                    225:                funs = fn;
                    226:        }
                    227: }
                    228:
                    229: int
1.6       vincent   230: funmap_add(PF fun, const char *fname)
1.1       art       231: {
                    232:        struct funmap *fn;
                    233:
                    234:        if ((fn = malloc(sizeof(*fn))) == NULL)
1.11      db        235:                return (FALSE);
1.1       art       236:
                    237:        fn->fn_funct = fun;
                    238:        fn->fn_name = fname;
                    239:        fn->fn_next = funs;
                    240:
                    241:        funs = fn;
1.11      db        242:        return (TRUE);
1.1       art       243: }
                    244:
                    245: /*
                    246:  * Translate from function name to function pointer.
                    247:  */
                    248: PF
1.6       vincent   249: name_function(const char *fname)
1.1       art       250: {
                    251:        struct funmap *fn;
                    252:
                    253:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    254:                if (strcmp(fn->fn_name, fname) == 0)
1.11      db        255:                        return (fn->fn_funct);
1.1       art       256:        }
1.11      db        257:        return (NULL);
1.1       art       258: }
                    259:
1.6       vincent   260: const char *
1.1       art       261: function_name(PF fun)
                    262: {
                    263:        struct funmap *fn;
                    264:
                    265:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    266:                if (fn->fn_funct == fun)
1.11      db        267:                        return (fn->fn_name);
1.1       art       268:        }
1.11      db        269:        return (NULL);
1.1       art       270: }
                    271:
                    272: /*
1.11      db        273:  * List possible function name completions.
1.1       art       274:  */
1.17      deraadt   275: struct list *
1.12      otto      276: complete_function_list(const char *fname)
1.1       art       277: {
1.11      db        278:        struct funmap   *fn;
1.23      kjell     279:        struct list     *head, *el;
1.11      db        280:        int              len;
1.1       art       281:
                    282:        len = strlen(fname);
                    283:        head = NULL;
                    284:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    285:                if (memcmp(fname, fn->fn_name, len) == 0) {
                    286:                        if ((el = malloc(sizeof(*el))) == NULL) {
                    287:                                free_file_list(head);
1.11      db        288:                                return (NULL);
1.1       art       289:                        }
1.23      kjell     290:                        el->l_name = strdup(fn->fn_name);
1.1       art       291:                        el->l_next = head;
                    292:                        head = el;
                    293:                }
                    294:        }
1.11      db        295:        return (head);
1.1       art       296: }