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

1.8     ! vincent     1: /*     $OpenBSD: funmap.c,v 1.7 2002/03/16 15:10:11 vincent Exp $      */
1.3       art         2: /*
                      3:  * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>.  All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  *
                     14:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     15:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     16:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     17:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     18:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     19:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     20:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     21:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     22:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     23:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     24:  */
1.1       art        25: #include "def.h"
                     26: #include "kbd.h"
                     27: #include "funmap.h"
                     28:
                     29: /*
                     30:  * If the function is NULL, it must be listed with the
                     31:  * same name in the map_table.
                     32:  */
                     33:
                     34: struct funmap {
1.6       vincent    35:        PF               fn_funct;
                     36:        const            char *fn_name;
1.1       art        37:        struct funmap   *fn_next;
                     38: };
                     39:
                     40: static struct funmap *funs;
                     41:
                     42: static struct funmap functnames[] = {
                     43: #ifndef        NO_HELP
                     44:        {apropos_command, "apropos",},
                     45: #endif /* !NO_HELP */
                     46:        {fillmode, "auto-fill-mode",},
                     47:        {indentmode, "auto-indent-mode",},
                     48:        {backchar, "backward-char",},
                     49:        {delbword, "backward-kill-word",},
                     50:        {gotobop, "backward-paragraph",},
                     51:        {backword, "backward-word",},
                     52:        {gotobob, "beginning-of-buffer",},
                     53:        {gotobol, "beginning-of-line",},
                     54:        {blinkparen, "blink-matching-paren",},
                     55:        {showmatch, "blink-matching-paren-hack",},
                     56: #ifdef BSMAP
                     57:        {bsmap, "bsmap-mode",},
                     58: #endif /* BSMAP */
                     59:        {NULL, "c-x 4 prefix",},
                     60:        {NULL, "c-x prefix",},
                     61: #ifndef NO_MACRO
                     62:        {executemacro, "call-last-kbd-macro",},
                     63: #endif /* !NO_MACRO */
                     64:        {capword, "capitalize-word",},
                     65: #ifndef NO_DIR
                     66:        {changedir, "cd",},
                     67: #endif /* !NO_DIR */
                     68:        {copyregion, "copy-region-as-kill",},
                     69: #ifdef REGEX
                     70:        {cntmatchlines, "count-matches",},
                     71:        {cntnonmatchlines, "count-non-matches",},
                     72: #endif /* REGEX */
                     73:        {define_key, "define-key",},
                     74:        {backdel, "delete-backward-char",},
                     75:        {deblank, "delete-blank-lines",},
                     76:        {forwdel, "delete-char",},
                     77:        {delwhite, "delete-horizontal-space",},
                     78: #ifdef REGEX
                     79:        {delmatchlines, "delete-matching-lines",},
                     80:        {delnonmatchlines, "delete-non-matching-lines",},
                     81: #endif /* REGEX */
                     82:        {onlywind, "delete-other-windows",},
                     83:        {delwind, "delete-window",},
                     84: #ifndef NO_HELP
                     85:        {wallchart, "describe-bindings",},
                     86:        {desckey, "describe-key-briefly",},
                     87: #endif /* !NO_HELP */
                     88:        {digit_argument, "digit-argument",},
                     89: #ifndef NO_DIRED
                     90:        {dired, "dired",},
                     91:        {d_undelbak, "dired-backup-unflag",},
                     92:        {d_copy, "dired-copy-file",},
                     93:        {d_expunge, "dired-do-deletions",},
                     94:        {d_findfile, "dired-find-file",},
                     95:        {d_ffotherwindow, "dired-find-file-other-window",},
                     96:        {d_del, "dired-flag-file-deleted",},
                     97:        {d_otherwindow, "dired-other-window",},
                     98:        {d_rename, "dired-rename-file",},
                     99:        {d_undel, "dired-unflag",},
                    100: #endif /* !NO_DIRED */
                    101:        {lowerregion, "downcase-region",},
                    102:        {lowerword, "downcase-word",},
                    103:        {showversion, "emacs-version",},
                    104: #ifndef NO_MACRO
                    105:        {finishmacro, "end-kbd-macro",},
                    106: #endif /* !NO_MACRO */
                    107:        {gotoeob, "end-of-buffer",},
                    108:        {gotoeol, "end-of-line",},
                    109:        {enlargewind, "enlarge-window",},
                    110:        {NULL, "esc prefix",},
                    111: #ifndef NO_STARTUP
                    112:        {evalbuffer, "eval-current-buffer",},
                    113:        {evalexpr, "eval-expression",},
                    114: #endif /* !NO_STARTUP */
                    115:        {swapmark, "exchange-point-and-mark",},
                    116:        {extend, "execute-extended-command",},
                    117:        {fillpara, "fill-paragraph",},
                    118:        {filevisit, "find-file",},
1.8     ! vincent   119:        {filevisitro, "find-file-read-only",},
1.1       art       120:        {poptofile, "find-file-other-window",},
                    121:        {forwchar, "forward-char",},
                    122:        {gotoeop, "forward-paragraph",},
                    123:        {forwword, "forward-word",},
                    124:        {bindtokey, "global-set-key",},
                    125:        {unbindtokey, "global-unset-key",},
                    126:        {gotoline, "goto-line",},
                    127: #ifndef NO_HELP
                    128:        {NULL, "help",},
                    129:        {help_help, "help-help",},
                    130: #endif /* !NO_HELP */
                    131:        {insert, "insert",},
                    132:        {bufferinsert, "insert-buffer",},
                    133:        {fileinsert, "insert-file",},
                    134:        {fillword, "insert-with-wrap",},
                    135:        {backisearch, "isearch-backward",},
                    136:        {forwisearch, "isearch-forward",},
                    137:        {justone, "just-one-space",},
                    138:        {ctrlg, "keyboard-quit",},
                    139:        {killbuffer, "kill-buffer",},
                    140:        {killline, "kill-line",},
                    141:        {killpara, "kill-paragraph",},
                    142:        {killregion, "kill-region",},
                    143:        {delfword, "kill-word",},
                    144:        {listbuffers, "list-buffers",},
                    145: #ifndef NO_STARTUP
                    146:        {evalfile, "load",},
                    147: #endif /* !NO_STARTUP */
                    148:        {localbind, "local-set-key",},
                    149:        {localunbind, "local-unset-key",},
                    150: #ifndef NO_BACKUP
                    151:        {makebkfile, "make-backup-files",},
                    152: #endif /* !NO_BACKUP */
                    153: #ifdef DO_METAKEY
                    154:        {do_meta, "meta-key-mode",},    /* better name, anyone? */
                    155: #endif /* DO_METAKEY */
                    156:        {negative_argument, "negative-argument",},
                    157:        {newline, "newline",},
                    158:        {indent, "newline-and-indent",},
                    159:        {forwline, "next-line",},
                    160: #ifdef NOTAB
                    161:        {notabmode, "no-tab-mode",},
                    162: #endif /* NOTAB */
                    163:        {notmodified, "not-modified",},
                    164:        {openline, "open-line",},
                    165:        {nextwind, "other-window",},
                    166:        {overwrite, "overwrite-mode",},
                    167: #ifdef PREFIXREGION
                    168:        {prefixregion, "prefix-region",},
                    169: #endif /* PREFIXREGION */
                    170:        {backline, "previous-line",},
                    171:        {prevwind, "previous-window",},
                    172:        {spawncli, "push-shell",},
                    173: #ifndef NO_DIR
                    174:        {showcwdir, "pwd",},
                    175: #endif /* !NO_DIR */
                    176:        {queryrepl, "query-replace",},
                    177: #ifdef REGEX
                    178:        {re_queryrepl, "query-replace-regexp",},
                    179: #endif /* REGEX */
                    180:        {quote, "quoted-insert",},
                    181: #ifdef REGEX
                    182:        {re_searchagain, "re-search-again",},
                    183:        {re_backsearch, "re-search-backward",},
                    184:        {re_forwsearch, "re-search-forward",},
                    185: #endif /* REGEX */
                    186:        {reposition, "recenter",},
                    187:        {refresh, "redraw-display",},
                    188:        {filesave, "save-buffer",},
                    189:        {quit, "save-buffers-kill-emacs",},
                    190:        {savebuffers, "save-some-buffers",},
                    191:        {backpage, "scroll-down",},
                    192:        {back1page, "scroll-one-line-down",},
                    193:        {forw1page, "scroll-one-line-up",},
                    194:        {pagenext, "scroll-other-window",},
                    195:        {forwpage, "scroll-up",},
                    196:        {searchagain, "search-again",},
                    197:        {backsearch, "search-backward",},
                    198:        {forwsearch, "search-forward",},
                    199:        {selfinsert, "self-insert-command",},
                    200: #ifdef REGEX
                    201:        {setcasefold, "set-case-fold-search",},
                    202: #endif /* REGEX */
                    203:        {set_default_mode, "set-default-mode",},
                    204:        {setfillcol, "set-fill-column",},
                    205:        {setmark, "set-mark-command",},
                    206: #ifdef PREFIXREGION
                    207:        {setprefix, "set-prefix-string",},
                    208: #endif /* PREFIXREGION */
                    209:        {shrinkwind, "shrink-window",},
                    210: #ifdef NOTAB
                    211:        {space_to_tabstop, "space-to-tabstop",},
                    212: #endif /* NOTAB */
                    213:        {splitwind, "split-window-vertically",},
                    214: #ifndef NO_MACRO
                    215:        {definemacro, "start-kbd-macro",},
                    216: #endif /* !NO_MACRO */
                    217:        {spawncli, "suspend-emacs",},
                    218:        {usebuffer, "switch-to-buffer",},
                    219:        {poptobuffer, "switch-to-buffer-other-window",},
1.8     ! vincent   220:        {togglereadonly, "toggle-read-only" },
1.1       art       221:        {twiddle, "transpose-chars",},
1.5       vincent   222:        { undo, "undo", },
1.7       vincent   223:        { undo_dump, "undo-list", },
1.1       art       224:        {universal_argument, "universal-argument",},
                    225:        {upperregion, "upcase-region",},
                    226:        {upperword, "upcase-word",},
                    227:        {showcpos, "what-cursor-position",},
                    228:        {filewrite, "write-file",},
                    229:        {yank, "yank",},
                    230:        {NULL, NULL,},
                    231: };
                    232:
                    233: void
                    234: funmap_init(void)
                    235: {
                    236:        struct funmap *fn;
                    237:
                    238:        for (fn = functnames; fn->fn_name != NULL; fn++) {
                    239:                fn->fn_next = funs;
                    240:                funs = fn;
                    241:        }
                    242: }
                    243:
                    244: int
1.6       vincent   245: funmap_add(PF fun, const char *fname)
1.1       art       246: {
                    247:        struct funmap *fn;
                    248:
                    249:        if ((fn = malloc(sizeof(*fn))) == NULL)
                    250:                return FALSE;
                    251:
                    252:        fn->fn_funct = fun;
                    253:        fn->fn_name = fname;
                    254:        fn->fn_next = funs;
                    255:
                    256:        funs = fn;
                    257:        return TRUE;
                    258: }
                    259:
                    260: /*
                    261:  * Translate from function name to function pointer.
                    262:  */
                    263: PF
1.6       vincent   264: name_function(const char *fname)
1.1       art       265: {
                    266:        struct funmap *fn;
                    267:
                    268:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    269:                if (strcmp(fn->fn_name, fname) == 0)
                    270:                        return fn->fn_funct;
                    271:        }
                    272:        return NULL;
                    273: }
                    274:
1.6       vincent   275: const char *
1.1       art       276: function_name(PF fun)
                    277: {
                    278:        struct funmap *fn;
                    279:
                    280:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    281:                if (fn->fn_funct == fun)
                    282:                        return fn->fn_name;
                    283:        }
                    284:        return NULL;
                    285: }
                    286:
                    287: /*
                    288:  * list possible function name completions.
                    289:  */
                    290: LIST *
1.6       vincent   291: complete_function_list(const char *fname, int c)
1.1       art       292: {
                    293:        struct funmap *fn;
                    294:        LIST *head, *el;
                    295:        int len;
                    296:
                    297:        len = strlen(fname);
                    298:        head = NULL;
                    299:        for (fn = funs; fn != NULL; fn = fn->fn_next) {
                    300:                if (memcmp(fname, fn->fn_name, len) == 0) {
                    301:                        if ((el = malloc(sizeof(*el))) == NULL) {
                    302:                                free_file_list(head);
                    303:                                return NULL;
                    304:                        }
                    305:                        el->l_name = fn->fn_name;
                    306:                        el->l_next = head;
                    307:                        head = el;
                    308:                }
                    309:        }
                    310:
                    311:        return head;
                    312: }
                    313:
                    314:
                    315: