int execprg(int f, int n) { #ifndef WINNT int s; char line[NLINE]; #endif /* don't allow this command if restricted */ if (restflag) return resterr(); #if WINNT mlwrite("(unsupported)"); return FALSE; #endif #if VMS if ((s = mlreply("!", line, NLINE)) != TRUE) return s; TTflush(); s = sys(line); /* Run the command. */ mlputs("\r\n\n(End)"); /* Pause. */ TTflush(); tgetc(); sgarbf = TRUE; return s; #endif #if MSDOS if ((s = mlreply("$", line, NLINE)) != TRUE) return s; movecursor(term.t_nrow, 0); TTkclose(); execprog(line); TTkopen(); /* if we are interactive, pause here */ if (clexec == FALSE) { mlputs("\r\n(End)"); tgetc(); } sgarbf = TRUE; return TRUE; #endif #if V7 | USG | BSD if ((s = mlreply("!", line, NLINE)) != TRUE) return s; TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ TTkclose(); system(line); fflush(stdout); /* to be sure P.K. */ TTopen(); mlputs("(End)"); /* Pause. */ TTflush(); while ((s = tgetc()) != '\r' && s != ' '); sgarbf = TRUE; return TRUE; #endif }
execprg(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("!", line, NLINE)) != TRUE) return(s); TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ system(line); TTopen(); mlputs(TEXT188); /* Pause. */ /* "[End]" */ TTflush(); while ((s = tgetc()) != '\r' && s != ' ') ; sgarbf = TRUE; return(TRUE); }
/* * Run a one-liner in a subjob. When the command returns, wait for a single * character to be typed, then mark the screen as garbage so a full repaint is * done. Bound to "C-X !". */ spawn(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("!", line, NLINE)) != TRUE) return(s); TTputc('\n'); /* Already have '\r' */ TTflush(); TTclose(); /* stty to old modes */ system(line); TTopen(); TTflush(); /* if we are interactive, pause here */ if (clexec == FALSE) { mlputs(TEXT6); /* "\r\n\n[End]" */ tgetc(); } sgarbf = TRUE; return(TRUE); }
int Toker::tgetc(){ int c=fgetc(fh),d,e; if( c==EOF ) return c; switch( encoding ){ case UNK: d=fgetc(fh); if( c==0xfe && d==0xff ){ encoding=UTF16BE; }else if( c==0xff && d==0xfe ){ encoding=UTF16LE; }else if( c==0xef && d==0xbb ){ e=fgetc(fh); if( e==0xbf ){ encoding=UTF8; }else{ ungetc( e,fh ); } } if( encoding==UNK ){ encoding=LATIN1; ungetc( d,fh ); ungetc( c,fh ); } return tgetc(); case LATIN1: return c; case UTF8: if( c<128 ){ return c; } d=fgetc(fh); if( c<224 ){ return (c-192)*64+(d-128); } e=fgetc(fh); if( c<240 ){ return (c-224)*4096+(d-128)*64+(e-128); } return 0; case UTF16BE: return ((c&0xff)<<8)|(fgetc(fh)&0xff); case UTF16LE: return ((fgetc(fh)&0xff)<<8)|(c&0xff); } cout<<"Here!"<<endl; return ' '; }
/* KM_GETC - return next command char from kbd macro being executed. ** This is < 0 if not executing kbd macro. Also responsible for ** gathering input for kbd macro. */ km_getc() { register int c; while (km_flag > 0) /* Executing macro? */ { c = sb_getc(((SBBUF *)km_buf)); /* Yes, get char */ if(c != EOF) return(c); /* and return as cmd */ if(--km_exp >= 0) /* Macro done. Repeat? */ ex_go((SBBUF *)km_buf, (chroff)0); /* Yes */ else km_flag = 0; /* No, stop execution */ } c = tgetc(); /* Get char from user (TTY) */ if(km_flag < 0) /* Save it if collecting macro */ { sb_putc(((SBBUF *)km_buf), c); } return(c); }
void Toker::nextLine(){ ++line_num; line.clear(); wline.clear(); tokes.clear(); if( !fh ){ tokes.push_back( Toke(EOF,0,0) ); return; } for(;;){ int c=tgetc(); if( c=='\n' || c==EOF ){ if( c==EOF ) close(); line.push_back( '\n' ); wline.push_back( '\n' ); break; } line.push_back( (c>32 && c<127) ? c : ' ' ); wline.push_back(c); } int p=0; for(;;){ int c=line[p]; if( c=='\'' || c=='\n' ){ if( tokes.size() && tokes.back().toke==T_DOTDOT ){ tokes.pop_back(); break; } tokes.push_back( Toke('\n',p,line.size()) ); break; }else if( isgraph(c) ){ tokes.push_back( nextToke(line,p) ); }else{ ++p; } } }
execprg(f, n) { register int s; char line[NLINE]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if ((s=mlreply("$", line, NLINE)) != TRUE) return(s); movecursor(term.t_nrow - 1, 0); TTkclose(); execprog(line); TTkopen(); /* if we are interactive, pause here */ if (clexec == FALSE) { puts(TEXT6); /* "\r\n\n[End]" */ tgetc(); } sgarbf = TRUE; return (TRUE); }
static int gettoken(struct snmp_toolinfo *tool) { int c; struct enum_type *t; if (saved_token != -1) { c = saved_token; saved_token = -1; return (c); } again: /* * Skip any whitespace before the next token */ while ((c = tgetc()) != EOF) { if (c == '\n') input->lno++; if (!isspace(c)) break; } if (c == EOF) return (TOK_EOF); if (!isascii(c)) { warnx("unexpected character %#2x", (u_int)c); return (TOK_ERR); } /* * Skip comments */ if (c == '#') { while ((c = tgetc()) != EOF) { if (c == '\n') { input->lno++; goto again; } } warnx("unexpected EOF in comment"); return (TOK_ERR); } /* * Single character tokens */ if (strchr("():|", c) != NULL) return (c); if (c == '"' || c == '<') { int end = c; size_t n = 0; val = 1; if (c == '<') { val = 0; end = '>'; } while ((c = tgetc()) != EOF) { if (c == end) break; if (n == sizeof(nexttok) - 1) { nexttok[n++] = '\0'; warnx("filename too long '%s...'", nexttok); return (TOK_ERR); } nexttok[n++] = c; } nexttok[n++] = '\0'; return (TOK_FILENAME); } /* * Sort out numbers */ if (isdigit(c)) { size_t n = 0; nexttok[n++] = c; while ((c = tgetc()) != EOF) { if (!isdigit(c)) { if (tungetc(c) < 0) return (TOK_ERR); break; } if (n == sizeof(nexttok) - 1) { nexttok[n++] = '\0'; warnx("number too long '%s...'", nexttok); return (TOK_ERR); } nexttok[n++] = c; } nexttok[n++] = '\0'; sscanf(nexttok, "%lu", &val); return (TOK_NUM); } /* * So that has to be a string. */ if (isalpha(c) || c == '_' || c == '-') { size_t n = 0; nexttok[n++] = c; while ((c = tgetc()) != EOF) { if (!isalnum(c) && c != '_' && c != '-') { if (tungetc (c) < 0) return (TOK_ERR); break; } if (n == sizeof(nexttok) - 1) { nexttok[n++] = '\0'; warnx("string too long '%s...'", nexttok); return (TOK_ERR); } nexttok[n++] = c; } nexttok[n++] = '\0'; /* * Keywords */ for (c = 0; keywords[c].str != NULL; c++) if (strcmp(keywords[c].str, nexttok) == 0) { val = keywords[c].val; return (keywords[c].tok); } if ((t = snmp_enumtc_lookup(tool, nexttok)) != NULL) { val = t->syntax; return (TOK_DEFTYPE); } return (TOK_STR); } if (isprint(c)) warnx("%u: unexpected character '%c'", input->lno, c); else warnx("%u: unexpected character 0x%02x", input->lno, (u_int)c); return (TOK_ERR); }
void look3(Text *t, uint q0, uint q1, int external) { int n, c, f, expanded; Text *ct; Expand e; Rune *r; uint p; Plumbmsg *m; Runestr dir; char buf[32]; ct = seltext; if(ct == nil) seltext = t; expanded = expand(t, q0, q1, &e); if(!external && t->w!=nil && t->w->nopen[QWevent]>0){ /* send alphanumeric expansion to external client */ if(expanded == FALSE) return; f = 0; if((e.u.at!=nil && t->w!=nil) || (e.nname>0 && lookfile(e.name, e.nname)!=nil)) f = 1; /* acme can do it without loading a file */ if(q0!=e.q0 || q1!=e.q1) f |= 2; /* second (post-expand) message follows */ if(e.nname) f |= 4; /* it's a file name */ c = 'l'; if(t->what == Body) c = 'L'; n = q1-q0; if(n <= EVENTSIZE){ r = runemalloc(n); bufread(&t->file->b, q0, r, n); winevent(t->w, "%c%d %d %d %d %.*S\n", c, q0, q1, f, n, n, r); free(r); }else winevent(t->w, "%c%d %d %d 0 \n", c, q0, q1, f, n); if(q0==e.q0 && q1==e.q1) return; if(e.nname){ n = e.nname; if(e.a1 > e.a0) n += 1+(e.a1-e.a0); r = runemalloc(n); runemove(r, e.name, e.nname); if(e.a1 > e.a0){ r[e.nname] = ':'; bufread(&e.u.at->file->b, e.a0, r+e.nname+1, e.a1-e.a0); } }else{ n = e.q1 - e.q0; r = runemalloc(n); bufread(&t->file->b, e.q0, r, n); } f &= ~2; if(n <= EVENTSIZE) winevent(t->w, "%c%d %d %d %d %.*S\n", c, e.q0, e.q1, f, n, n, r); else winevent(t->w, "%c%d %d %d 0 \n", c, e.q0, e.q1, f, n); free(r); goto Return; } if(plumbsendfid != nil){ /* send whitespace-delimited word to plumber */ m = emalloc(sizeof(Plumbmsg)); m->src = estrdup("acme"); m->dst = nil; dir = dirname(t, nil, 0); if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */ free(dir.r); dir.r = nil; dir.nr = 0; } if(dir.nr == 0) m->wdir = estrdup(wdir); else m->wdir = runetobyte(dir.r, dir.nr); free(dir.r); m->type = estrdup("text"); m->attr = nil; buf[0] = '\0'; if(q1 == q0){ if(t->q1>t->q0 && t->q0<=q0 && q0<=t->q1){ q0 = t->q0; q1 = t->q1; }else{ p = q0; while(q0>0 && (c=tgetc(t, q0-1))!=' ' && c!='\t' && c!='\n') q0--; while(q1<t->file->b.nc && (c=tgetc(t, q1))!=' ' && c!='\t' && c!='\n') q1++; if(q1 == q0){ plumbfree(m); goto Return; } sprint(buf, "click=%d", p-q0); m->attr = plumbunpackattr(buf); } } r = runemalloc(q1-q0); bufread(&t->file->b, q0, r, q1-q0); m->data = runetobyte(r, q1-q0); m->ndata = strlen(m->data); free(r); if(m->ndata<messagesize-1024 && plumbsendtofid(plumbsendfid, m) >= 0){ plumbfree(m); goto Return; } plumbfree(m); /* plumber failed to match; fall through */ } /* interpret alphanumeric string ourselves */ if(expanded == FALSE) return; if(e.name || e.u.at) openfile(t, &e); else{ if(t->w == nil) return; ct = &t->w->body; if(t->w != ct->w) winlock(ct->w, 'M'); if(t == ct) textsetselect(ct, e.q1, e.q1); n = e.q1 - e.q0; r = runemalloc(n); bufread(&t->file->b, e.q0, r, n); if(search(ct, r, n) && e.jump) moveto(mousectl, addpt(frptofchar(&ct->fr, ct->fr.p0), Pt(4, ct->fr.font->height-4))); if(t->w != ct->w) winunlock(ct->w); free(r); } Return: free(e.name); free(e.bname); }
static const struct field * tmain(void) { size_t n; int c, i, j, k; i = j = 0; n = f.v[f.nmemb].lo; for (;;) { tputs(T_RESTORE_CURSOR); if (f.nmemb > 0) { twrite(in.v, f.v[i].so); tputs(T_ENTER_STANDOUT_MODE); twrite(in.v + f.v[i].so, f.v[i].eo - f.v[i].so + 1); tputs(T_EXIT_STANDOUT_MODE); twrite(in.v + f.v[i].eo + 1, n - f.v[i].eo); } else { twrite(in.v, n); } c = tgetc(); switch (c) { case KEY_ENTER: if (f.nmemb > 0) return &f.v[i]; break; case KEY_TERM: return NULL; case KEY_HOME: j = 0; break; case KEY_RIGHT: j = i + 1; break; case KEY_END: j = f.nmemb - 1; break; case KEY_LEFT: j = i - 1; break; case KEY_DOWN: j = i; while (j < (ssize_t)f.nmemb && f.v[i].lo == f.v[j].lo) j++; if (j == (ssize_t)f.nmemb) break; /* FALLTHROUGH */ if (0) { case KEY_UP: k = i; while (k && f.v[i].lo == f.v[k].lo) k--; j = k; while (j && f.v[j - 1].lo == f.v[k].lo) j--; } for (; fcmp(&f.v[i], &f.v[j]) < 0 && f.v[j].lo == f.v[j + 1].lo; j++) /* NOP */; break; } if (j >= 0 && j < (ssize_t)f.nmemb) i = j; } }
/* * Evaluate a function. * * @fname: name of function to evaluate. */ char *gtfun(char *fname) { int fnum; /* index to function to eval */ int status; /* return status */ char *tsp; /* temporary string pointer */ char arg1[NSTRING]; /* value of first argument */ char arg2[NSTRING]; /* value of second argument */ char arg3[NSTRING]; /* value of third argument */ static char result[2 * NSTRING]; /* string result */ /* look the function up in the function table */ fname[3] = 0; /* only first 3 chars significant */ mklower(fname); /* and let it be upper or lower case */ for (fnum = 0; fnum < ARRAY_SIZE(funcs); fnum++) if (strcmp(fname, funcs[fnum].f_name) == 0) break; /* return errorm on a bad reference */ if (fnum == ARRAY_SIZE(funcs)) return errorm; /* if needed, retrieve the first argument */ if (funcs[fnum].f_type >= MONAMIC) { if ((status = macarg(arg1)) != TRUE) return errorm; /* if needed, retrieve the second argument */ if (funcs[fnum].f_type >= DYNAMIC) { if ((status = macarg(arg2)) != TRUE) return errorm; /* if needed, retrieve the third argument */ if (funcs[fnum].f_type >= TRINAMIC) if ((status = macarg(arg3)) != TRUE) return errorm; } } /* and now evaluate it! */ switch (fnum) { case UFADD: return itoa(atoi(arg1) + atoi(arg2)); case UFSUB: return itoa(atoi(arg1) - atoi(arg2)); case UFTIMES: return itoa(atoi(arg1) * atoi(arg2)); case UFDIV: return itoa(atoi(arg1) / atoi(arg2)); case UFMOD: return itoa(atoi(arg1) % atoi(arg2)); case UFNEG: return itoa(-atoi(arg1)); case UFCAT: strcpy(result, arg1); return strcat(result, arg2); case UFLEFT: return strncpy(result, arg1, atoi(arg2)); case UFRIGHT: return (strcpy(result, &arg1[(strlen(arg1) - atoi(arg2))])); case UFMID: return (strncpy(result, &arg1[atoi(arg2) - 1], atoi(arg3))); case UFNOT: return ltos(stol(arg1) == FALSE); case UFEQUAL: return ltos(atoi(arg1) == atoi(arg2)); case UFLESS: return ltos(atoi(arg1) < atoi(arg2)); case UFGREATER: return ltos(atoi(arg1) > atoi(arg2)); case UFSEQUAL: return ltos(strcmp(arg1, arg2) == 0); case UFSLESS: return ltos(strcmp(arg1, arg2) < 0); case UFSGREAT: return ltos(strcmp(arg1, arg2) > 0); case UFIND: return strcpy(result, getval(arg1)); case UFAND: return ltos(stol(arg1) && stol(arg2)); case UFOR: return ltos(stol(arg1) || stol(arg2)); case UFLENGTH: return itoa(strlen(arg1)); case UFUPPER: return mkupper(arg1); case UFLOWER: return mklower(arg1); case UFTRUTH: return ltos(atoi(arg1) == 42); case UFASCII: return itoa((int) arg1[0]); case UFCHR: result[0] = atoi(arg1); result[1] = 0; return result; case UFGTKEY: result[0] = tgetc(); result[1] = 0; return result; case UFRND: return itoa((ernd() % abs(atoi(arg1))) + 1); case UFABS: return itoa(abs(atoi(arg1))); case UFSINDEX: return itoa(sindex(arg1, arg2)); case UFENV: #if ENVFUNC tsp = getenv(arg1); return tsp == NULL ? "" : tsp; #else return ""; #endif case UFBIND: return transbind(arg1); case UFEXIST: return ltos(fexist(arg1)); case UFFIND: tsp = flook(arg1, TRUE); return tsp == NULL ? "" : tsp; case UFBAND: return itoa(atoi(arg1) & atoi(arg2)); case UFBOR: return itoa(atoi(arg1) | atoi(arg2)); case UFBXOR: return itoa(atoi(arg1) ^ atoi(arg2)); case UFBNOT: return itoa(~atoi(arg1)); case UFXLATE: return xlat(arg1, arg2, arg3); } exit(-11); /* never should get here */ }