void dump_call(opcode_type opcode,char *text) { unsigned char info,num_parms,parm_type; int i,parm_value,assign_index, name_id; char tempbuf[15]; info = get_byte(); switch(opcode.source1) { case CALL_NO_ASSIGN : /* return value ignored */ { sprintf(text,"Call %s--",name_function(info)); break; } case CALL_ASSIGN_LOCAL_VAR : case CALL_ASSIGN_PROPERTY : { assign_index = get_int(); sprintf(text,"%s %s = Call %s\n : ",name_var_type(opcode.source1), str_constant(assign_index),name_function(info)); break; } default : { sprintf(text,"INVALID"); return; } } num_parms = get_byte(); for (i=0;i<num_parms;i++) { parm_type = get_byte(); parm_value = get_int(); if (i != 0) strcat(text,", "); strcat(text,name_var_type(parm_type)); strcat(text," "); strcat(text,str_constant(parm_value)); } strcat(text,"\n : "); num_parms = get_byte(); for (i=0;i<num_parms;i++) { name_id = get_int(); parm_type = get_byte(); parm_value = get_int(); if (i != 0) strcat(text,", "); strcat(text,"Parm id "); strcat(text,itoa(name_id,tempbuf,10)); strcat(text," "); strcat(text,name_var_type(parm_type)); strcat(text," "); strcat(text,str_constant(parm_value)); } }
/* * Extended command. Call the message line routine to read in the command * name and apply autocompletion to it. When it comes back, look the name * up in the symbol table and run the command if it is found. Print an * error if there is anything wrong. */ int extend(int f, int n) { PF funct; char xname[NXNAME], *bufp; if (!(f & FFARG)) bufp = eread("M-x ", xname, NXNAME, EFNEW | EFFUNC); else bufp = eread("%d M-x ", xname, NXNAME, EFNEW | EFFUNC, n); if (bufp == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); if ((funct = name_function(bufp)) != NULL) { if (macrodef) { struct line *lp = maclcur; macro[macrocount - 1].m_funct = funct; maclcur = lp->l_bp; maclcur->l_fp = lp->l_fp; free(lp); } return ((*funct)(f, n)); } ewprintf("[No match]"); return (FALSE); }
static int bindkey(KEYMAP **mapp, const char *fname, KCHAR *keys, int kcount) { KEYMAP *curmap = *mapp; KEYMAP *pref_map = NULL; PF funct; int c; if (fname == NULL) funct = rescan; else if (((funct = name_function(fname)) == NULL) ? (pref_map = name_map(fname)) == NULL : funct == NULL) { ewprintf("[No match: %s]", fname); return (FALSE); } while (--kcount) { if (doscan(curmap, c = *keys++, &curmap) != NULL) { if (remap(curmap, c, NULL, NULL) != TRUE) return (FALSE); /* * XXX - Bizzarreness. remap creates an empty KEYMAP * that the last key is supposed to point to. */ curmap = ele->k_prefmap; } } (void)doscan(curmap, c = *keys, NULL); return (remap(curmap, c, funct, pref_map)); }
/* ARGSUSED */ int apropos_command(int f, int n) { struct buffer *bp; struct list *fnames, *el; char string[32]; if (eread("apropos: ", string, sizeof(string), EFNUL | EFNEW) == NULL) return (ABORT); /* FALSE means we got a 0 character string, which is fine */ bp = bfind("*help*", TRUE); if (bclear(bp) == FALSE) return (FALSE); fnames = complete_function_list(""); for (el = fnames; el != NULL; el = el->l_next) { char buf[32]; if (strstr(el->l_name, string) == NULL) continue; buf[0] = '\0'; findbind(fundamental_map, name_function(el->l_name), buf, sizeof(buf)); if (addlinef(bp, "%-32s%s", el->l_name, buf) == FALSE) { free_file_list(fnames); return (FALSE); } } free_file_list(fnames); return (popbuftop(bp, WNONE)); }
/* * Do the input for local-set-key, global-set-key and define-key * then call remap to do the work. */ static int dobind(KEYMAP *curmap, const char *p, int unbind) { KEYMAP *pref_map = NULL; PF funct; char bprompt[80], *bufp, *pep; int c, s, n; if (macrodef) { /* * Keystrokes aren't collected. Not hard, but pretty useless. * Would not work for function keys in any case. */ ewprintf("Can't rebind key in macro"); return (FALSE); } if (inmacro) { for (s = 0; s < maclcur->l_used - 1; s++) { if (doscan(curmap, c = CHARMASK(maclcur->l_text[s]), &curmap) != NULL) { if (remap(curmap, c, NULL, NULL) != TRUE) return (FALSE); } } (void)doscan(curmap, c = maclcur->l_text[s], NULL); maclcur = maclcur->l_fp; } else { n = strlcpy(bprompt, p, sizeof(bprompt)); if (n >= sizeof(bprompt)) n = sizeof(bprompt) - 1; pep = bprompt + n; for (;;) { ewprintf("%s", bprompt); pep[-1] = ' '; pep = getkeyname(pep, sizeof(bprompt) - (pep - bprompt), c = getkey(FALSE)); if (doscan(curmap, c, &curmap) != NULL) break; *pep++ = '-'; *pep = '\0'; } } if (unbind) funct = rescan; else { if ((bufp = eread("%s to command: ", bprompt, sizeof(bprompt), EFFUNC | EFNEW, bprompt)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); if (((funct = name_function(bprompt)) == NULL) ? (pref_map = name_map(bprompt)) == NULL : funct == NULL) { ewprintf("[No match]"); return (FALSE); } } return (remap(curmap, c, funct, pref_map)); }
/* returns the name or NULL if not found */ char *Device_Valid_Object_Id( int object_type, uint32_t object_instance) { char *name = NULL; /* return value */ object_name_function name_function = NULL; if (object_type < MAX_BACNET_OBJECT_TYPE) { name_function = Object_Name[object_type]; } if (name_function) { name = name_function(object_instance); } else { if ((object_type == OBJECT_DEVICE) && (object_instance == Object_Instance_Number)) { name = My_Object_Name; } } return name; }
/* * excline - run a line from a load file or eval-expression. If FKEYS is * defined, duplicate functionality of dobind so function key values don't * have to fit in type char. */ int excline(char *line) { PF fp; struct line *lp, *np; int status, c, f, n; char *funcp, *tmp; char *argp = NULL; long nl; #ifdef FKEYS int bind; KEYMAP *curmap; #define BINDARG 0 /* this arg is key to bind (local/global set key) */ #define BINDNO 1 /* not binding or non-quoted BINDARG */ #define BINDNEXT 2 /* next arg " (define-key) */ #define BINDDO 3 /* already found key to bind */ #define BINDEXT 1 /* space for trailing \0 */ #else /* FKEYS */ #define BINDEXT 0 #endif /* FKEYS */ lp = NULL; if (macrodef || inmacro) { ewprintf("Not now!"); return (FALSE); } f = 0; n = 1; funcp = skipwhite(line); if (*funcp == '\0') return (TRUE); /* No error on blank lines */ line = parsetoken(funcp); if (*line != '\0') { *line++ = '\0'; line = skipwhite(line); if (ISDIGIT(*line) || *line == '-') { argp = line; line = parsetoken(line); } } if (argp != NULL) { f = FFARG; nl = strtol(argp, &tmp, 10); if (*tmp != '\0') return (FALSE); if (nl >= INT_MAX || nl <= INT_MIN) return (FALSE); n = (int)nl; } if ((fp = name_function(funcp)) == NULL) { ewprintf("Unknown function: %s", funcp); return (FALSE); } #ifdef FKEYS if (fp == bindtokey || fp == unbindtokey) { bind = BINDARG; curmap = fundamental_map; } else if (fp == localbind || fp == localunbind) { bind = BINDARG; curmap = curbp->b_modes[curbp->b_nmodes]->p_map; } else if (fp == redefine_key) bind = BINDNEXT; else bind = BINDNO; #endif /* FKEYS */ /* Pack away all the args now... */ if ((np = lalloc(0)) == FALSE) return (FALSE); np->l_fp = np->l_bp = maclcur = np; while (*line != '\0') { argp = skipwhite(line); if (*argp == '\0') break; line = parsetoken(argp); if (*argp != '"') { if (*argp == '\'') ++argp; if ((lp = lalloc((int) (line - argp) + BINDEXT)) == NULL) { status = FALSE; goto cleanup; } bcopy(argp, ltext(lp), (int)(line - argp)); #ifdef FKEYS /* don't count BINDEXT */ lp->l_used--; if (bind == BINDARG) bind = BINDNO; #endif /* FKEYS */ } else { /* quoted strings are special */ ++argp; #ifdef FKEYS if (bind != BINDARG) { #endif /* FKEYS */ lp = lalloc((int)(line - argp) + BINDEXT); if (lp == NULL) { status = FALSE; goto cleanup; } lp->l_used = 0; #ifdef FKEYS } else key.k_count = 0; #endif /* FKEYS */ while (*argp != '"' && *argp != '\0') { if (*argp != '\\') c = *argp++; else { switch (*++argp) { case 't': case 'T': c = CCHR('I'); break; case 'n': case 'N': c = CCHR('J'); break; case 'r': case 'R': c = CCHR('M'); break; case 'e': case 'E': c = CCHR('['); break; case '^': /* * split into two statements * due to bug in OSK cpp */ c = CHARMASK(*++argp); c = ISLOWER(c) ? CCHR(TOUPPER(c)) : CCHR(c); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c = *argp - '0'; if (argp[1] <= '7' && argp[1] >= '0') { c <<= 3; c += *++argp - '0'; if (argp[1] <= '7' && argp[1] >= '0') { c <<= 3; c += *++argp - '0'; } } break; #ifdef FKEYS case 'f': case 'F': c = *++argp - '0'; if (ISDIGIT(argp[1])) { c *= 10; c += *++argp - '0'; } c += KFIRST; break; #endif /* FKEYS */ default: c = CHARMASK(*argp); break; } argp++; } #ifdef FKEYS if (bind == BINDARG) key.k_chars[key.k_count++] = c; else #endif /* FKEYS */ lp->l_text[lp->l_used++] = c; } if (*line) line++; } #ifdef FKEYS switch (bind) { case BINDARG: bind = BINDDO; break; case BINDNEXT: lp->l_text[lp->l_used] = '\0'; if ((curmap = name_map(lp->l_text)) == NULL) { ewprintf("No such mode: %s", lp->l_text); status = FALSE; free(lp); goto cleanup; } free(lp); bind = BINDARG; break; default: #endif /* FKEYS */ lp->l_fp = np->l_fp; lp->l_bp = np; np->l_fp = lp; np = lp; #ifdef FKEYS } #endif /* FKEYS */ } #ifdef FKEYS switch (bind) { default: ewprintf("Bad args to set key"); status = FALSE; break; case BINDDO: if (fp != unbindtokey && fp != localunbind) { lp->l_text[lp->l_used] = '\0'; status = bindkey(&curmap, lp->l_text, key.k_chars, key.k_count); } else status = bindkey(&curmap, NULL, key.k_chars, key.k_count); break; case BINDNO: #endif /* FKEYS */ inmacro = TRUE; maclcur = maclcur->l_fp; status = (*fp)(f, n); inmacro = FALSE; #ifdef FKEYS } #endif /* FKEYS */ cleanup: lp = maclcur->l_fp; while (lp != maclcur) { np = lp->l_fp; free(lp); lp = np; } free(lp); return (status); }
int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; int nobackups = 0; struct buffer *bp = NULL; #ifdef MRUBY mrb_mg_init(); int noinitfile = 0; #endif /* MRUBY */ while ((o = getopt(argc, argv, "nf:q")) != -1) switch (o) { case 'n': nobackups = 1; break; case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; case 'q': noinitfile = 1; break; default: usage(); } argc -= optind; argv += optind; maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ /* * This is where we initialize standalone extensions that should * be loaded dynamically sometime in the future. */ { extern void grep_init(void); extern void theo_init(void); extern void cmode_init(void); extern void dired_init(void); dired_init(); grep_init(); theo_init(); cmode_init(); #ifdef UTF8 utf8_init(); #endif /* UTF8 */ } if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ ttykeymapinit(); /* Symbols, bindings. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(); /* user startup file */ #ifdef MRUBY if (noinitfile == 0 && (cp = startupfile(NULL)) != NULL) mrb_mg_load(cp); #else if ((cp = startupfile(NULL)) != NULL) (void)load(cp); #endif /* MRUBY */ /* * Now ensure any default buffer modes from the startup file are * given to any files opened when parsing the startup file. * Note *scratch* will also be updated. */ for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { bp->b_flag = defb_flag; for (i = 0; i <= defb_nmodes; i++) { bp->b_modes[i] = defb_modes[i]; } } /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); if (nobackups) makebkfile(FFARG, 0); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long long lval; const char *errstr; lval = strtonum(&argv[i][1], INT_MIN, INT_MAX, &errstr); if (argv[i][1] == '\0' || errstr != NULL) goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: ttbeep(); macrodef = FALSE; } } }
void run_command_bind(char *args) /* {{{ */ { /** * create a new keybind * syntax - mode key function [funcarg] */ int key, ret = 0; char *function = NULL, *arg = NULL, *keystr = NULL, *modestr = NULL, *keyname = NULL; void (*func)(); funcmap *fmap; prog_mode mode; /* parse command */ if (args != NULL) ret = sscanf(args, "%ms %ms %ms %m[^\n]", &modestr, &keystr, &function, &arg); if (ret < 3) { statusbar_message(cfg.statusbar_timeout, "syntax: bind <mode> <key> <function> <args>"); tnc_fprintf(logfp, LOG_ERROR, "syntax: bind <mode> <key> <function> <args> [%d](%s)", ret, args); goto cleanup; } /* parse mode string */ if (str_eq(modestr, "tasklist")) mode = MODE_TASKLIST; else if (str_eq(modestr, "pager")) mode = MODE_PAGER; else { tnc_fprintf(logfp, LOG_ERROR, "bind: invalid mode (%s)", modestr); goto cleanup; } /* parse key */ key = parse_key(keystr); /* map function to function call */ fmap = find_function(function, mode); if (fmap==NULL) { tnc_fprintf(logfp, LOG_ERROR, "bind: invalid function specified (%s)", args); goto cleanup; } func = fmap->function; /* error out if there is no argument specified when required */ if (fmap->argn>0 && arg==NULL) { statusbar_message(cfg.statusbar_timeout, "bind: argument required for function %s", function); goto cleanup; } /* add keybind */ add_keybind(key, func, arg, mode); keyname = name_key(key); statusbar_message(cfg.statusbar_timeout, "key %s (%d) bound to %s - %s", keyname, key, modestr, name_function(func)); goto cleanup; cleanup: free(function); free(arg); free(keystr); free(modestr); free(keyname); return; } /* }}} */
int main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; struct buffer *bp = NULL; while ((o = getopt(argc, argv, "f:")) != -1) switch (o) { case 'f': if (init_fcn_name != NULL) errx(1, "cannot specify more than one " "initial function"); init_fcn_name = optarg; break; default: usage(); } argc -= optind; argv += optind; setlocale(LC_CTYPE, ""); maps_init(); /* Keymaps and modes. */ funmap_init(); /* Functions. */ if (init_fcn_name && (init_fcn = name_function(init_fcn_name)) == NULL) errx(1, "Unknown function `%s'", init_fcn_name); vtinit(); /* Virtual terminal. */ dirinit(); /* Get current directory. */ edinit(bp); /* Buffers, windows. */ bellinit(); /* Audible and visible bell. */ /* * doing update() before reading files causes the error messages from * the file I/O show up on the screen. (and also an extra display of * the mode line if there are files specified on the command line.) */ update(CMODE); /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */ if (init_fcn) init_fcn(FFOTHARG, 1); for (nfiles = 0, i = 0; i < argc; i++) { if (argv[i][0] == '+' && strlen(argv[i]) >= 2) { long lval; char *end; lval = strtol(&argv[i][1], &end, 0); if (argv[i][1] == '\0' || *end != '\0') goto notnum; startrow = lval; } else { notnum: cp = adjustname(argv[i], FALSE); if (cp != NULL) { if (nfiles == 1) splitwind(0, 1); if ((curbp = findbuffer(cp)) == NULL) { vttidy(); errx(1, "Can't find current buffer!"); } (void)showbuffer(curbp, curwp, 0); if (readin(cp) != TRUE) killbuffer(curbp); else { /* Ensure enabled, not just toggled */ if (init_fcn_name) init_fcn(FFOTHARG, 1); nfiles++; } } } } if (nfiles > 2) listbuffers(0, 1); /* fake last flags */ thisflag = 0; for (;;) { if (epresf == KCLEAR) eerase(); if (epresf == TRUE) epresf = KCLEAR; if (winch_flag) { do_redraw(0, 0, TRUE); winch_flag = 0; } update(CMODE); lastflag = thisflag; thisflag = 0; switch (doin()) { case TRUE: break; case ABORT: ewprintf("Quit"); /* FALLTHRU */ case FALSE: default: macrodef = FALSE; } } }