/* renvoie -1 en cas de pb * si add!=0, on ajoute la commande... */ int Bind_command_new(struct key_entry *key, int command, flrn_char *arg, #ifdef USE_SLANG_LANGUAGE flrn_char *fun_slang, #endif int context, int add ) { int parcours,*toadd=NULL; int mac_num,mac_prec=-1; toadd=get_adrcmd_from_key(context,key,(add==0)); if (add) { if ((toadd==NULL) || (*toadd==FLCMD_UNDEF)) return -1; parcours=*toadd; while ((parcours>-1) && (parcours & FLCMD_MACRO)) { mac_prec=parcours ^ FLCMD_MACRO; parcours=Flcmd_macro[parcours ^ FLCMD_MACRO].next_cmd; } if (parcours>-1) { mac_num = do_macro(parcours, #ifdef USE_SLANG_LANGUAGE NULL, #endif NULL); if (mac_prec==-1) *toadd=mac_num | FLCMD_MACRO; else Flcmd_macro[mac_prec].next_cmd=mac_num | FLCMD_MACRO; toadd = & Flcmd_macro[mac_num].next_cmd; } else { toadd = & Flcmd_macro[mac_prec].next_cmd; } } else { parcours = *toadd; while ((parcours>-1) && (parcours & FLCMD_MACRO)) { /* pour liberer la macro */ mac_prec=parcours ^ FLCMD_MACRO; parcours=Flcmd_macro[parcours ^ FLCMD_MACRO].next_cmd; del_macro(mac_prec); } } if ((arg != NULL) #ifdef USE_SLANG_LANGUAGE || (fun_slang != NULL) #endif ) { mac_num = do_macro(command, #ifdef USE_SLANG_LANGUAGE fun_slang, #endif arg); *toadd = mac_num | FLCMD_MACRO; return 0; } else { *toadd = command; return 0; } }
static el_status_t meta(void) { int c; el_keymap_t *kp; if ((c = tty_get()) == EOF) return CSeof; #ifdef CONFIG_ANSI_ARROWS /* Also include VT-100 arrows. */ if (c == '[' || c == 'O') { switch (tty_get()) { case EOF: return CSeof; case '2': tty_get(); return CSstay; /* Insert */ case '3': tty_get(); return del_char(); /* Delete */ case '5': tty_get(); return CSstay; /* PgUp */ case '6': tty_get(); return CSstay; /* PgDn */ case 'A': return h_prev(); /* Up */ case 'B': return h_next(); /* Down */ case 'C': return fd_char(); /* Left */ case 'D': return bk_char(); /* Right */ case 'F': return end_line(); /* End */ case 'H': return beg_line(); /* Home */ default: /* Fall through */ break; } return el_ring_bell(); } #endif /* CONFIG_ANSI_ARROWS */ if (isdigit(c)) { for (Repeat = c - '0'; (c = tty_get()) != EOF && isdigit(c); ) Repeat = Repeat * 10 + c - '0'; tty_push(c); return CSstay; } if (isupper(c)) return do_macro(c); for (kp = MetaMap; kp->Function; kp++) { if (kp->Key == c) return kp->Function(); } return el_ring_bell(); }
int main(int argc, char **argv) { int c; int skip_if_false = 0; int incomment = 0; char *ip; currfile = &file_ctl[0]; while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) { switch (c) { case 'D': /* define */ for (ip = opts.optarg; *ip; ip++) { if (*ip == '=') *ip = ' '; } snprintf(ibuf, sizeof(ibuf), "#define %s\n", opts.optarg); currfile->fname = "<arg>"; currfile->lineno = opts.optind; directive(); break; case '?': default: opts.errors++; break; } } if (opts.errors || opts.optind < argc - 1) { pmUsageMessage(&opts); exit(1); } currfile->lineno = 0; if (opts.optind == argc) { currfile->fname = "<stdin>"; currfile->fin = stdin; } else { currfile->fname = argv[opts.optind]; currfile->fin = openfile(currfile->fname); if (currfile->fin == NULL) { err((char *)pmErrStr(-oserror())); /*NOTREACHED*/ } } printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname); for ( ; ; ) { if (fgets(ibuf, sizeof(ibuf), currfile->fin) == NULL) { fclose(currfile->fin); if (currfile == &file_ctl[0]) break; free(currfile->fname); currfile--; printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname); continue; } currfile->lineno++; /* strip comments ... */ for (ip = ibuf; *ip ; ip++) { if (incomment) { if (*ip == '*' && ip[1] == '/') { /* end of comment */ incomment = 0; *ip++ = ' '; *ip = ' '; } else *ip = ' '; } else { if (*ip == '/' && ip[1] == '*') { /* start of comment */ incomment = currfile->lineno; *ip++ = ' '; *ip = ' '; } } } ip--; while (ip >= ibuf && isspace((int)*ip)) ip--; *++ip = '\n'; *++ip = '\0'; if (incomment && ibuf[0] == '\n') { printf("\n"); continue; } if (ibuf[0] == '#') { /* cpp control line */ if (strncmp(ibuf, "#include", strlen("#include")) == 0) { char *p; char *pend; char c; FILE *f; static char tmpbuf[MAXPATHLEN]; if (skip_if_false) { printf("\n"); continue; } p = &ibuf[strlen("#include")]; while (*p && isblank((int)*p)) p++; if (*p != '"' && *p != '<') { err("Expected \" or < after #include"); /*NOTREACHED*/ } pend = ++p; while (*pend && *pend != '\n' && ((p[-1] != '"' || *pend != '"') && (p[-1] != '<' || *pend != '>'))) pend++; if (p[-1] == '"' && *pend != '"') { err("Expected \" after file name"); /*NOTREACHED*/ } if (p[-1] == '<' && *pend != '>') { err("Expected > after file name"); /*NOTREACHED*/ } if (currfile == &file_ctl[MAXLEVEL-1]) { err("#include nesting too deep"); /*NOTREACHED*/ } if (pend[1] != '\n' && pend[1] != '\0') { err("Unexpected extra text in #include line"); /*NOTREACHED*/ } c = *pend; *pend = '\0'; f = openfile(p); if (f == NULL && file_ctl[0].fin != stdin) { /* check in directory of file from command line */ static int sep; static char *dir = NULL; if (dir == NULL) { /* * some versions of dirname() clobber the input * argument, some do not ... hence the obscurity * here */ static char *dirbuf; dirbuf = strdup(file_ctl[0].fname); if (dirbuf == NULL) { __pmNoMem("pmcpp: dir name alloc", strlen(file_ctl[0].fname)+1, PM_FATAL_ERR); /*NOTREACHED*/ } dir = dirname(dirbuf); sep = __pmPathSeparator(); } snprintf(tmpbuf, sizeof(tmpbuf), "%s%c%s", dir, sep, p); f = openfile(tmpbuf); if (f != NULL) p = tmpbuf; } if (f == NULL) { /* check in $PCP_VAR_DIR/pmns */ static int sep; static char *var_dir = NULL; if (var_dir == NULL) { var_dir = pmGetConfig("PCP_VAR_DIR"); sep = __pmPathSeparator(); } snprintf(tmpbuf, sizeof(tmpbuf), "%s%cpmns%c%s", var_dir, sep, sep, p); f = openfile(tmpbuf); if (f != NULL) p = tmpbuf; } if (f == NULL) { *pend = c; err("Cannot open file for #include"); /*NOTREACHED*/ } currfile++; currfile->lineno = 0; currfile->fin = f; currfile->fname = strdup(p); *pend = c; if (currfile->fname == NULL) { __pmNoMem("pmcpp: file name alloc", strlen(p)+1, PM_FATAL_ERR); /*NOTREACHED*/ } printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname); } else { /* expect other cpp control ... */ skip_if_false = directive(); printf("\n"); } continue; } if (skip_if_false) printf("\n"); else { if (nmacro > 0) do_macro(); printf("%s", ibuf); } } /* EOF for the top level file */ if (incomment) { char msgbuf[80]; snprintf(msgbuf, sizeof(msgbuf), "Comment at line %d not terminated before end of file", incomment); currfile->lineno = 0; err(msgbuf); exit(1); } exit(0); }