void errexit(const char *s) { write(2, "\n", 1); perror(s); getout(0); }
int readc(void) { char c; if (tflag) { cline(); newpos(); } buflush(); if (read(0, &c, 1) != 1) errexit("readc"); #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE if (c == '\177') getout(0); #endif if (c == '\033' || c == '\015') return ('\n'); if (cflag) return (c); if (c == '\014') return ('R'); if (c >= 'a' && c <= 'z') return (c & 0137); return (c); }
// Exit because of an input read error. static void read_error_exit(void) { if (silent_mode) /* Normal way to exit for "ex -s" */ getout(0); STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); preserve_exit(); }
/* * check_char() * * Handle processing of the input * * Precondition: Parameter is not void * Postcondition: The input is processed * * @param char* input The input */ void check_char(char* input) { int count; if(input != NULL) { if(!my_strcmp(input, KU)) { moveup(); } else if(!my_strcmp(input, KD)) { movedown(); } else if(!my_strcmp(input, KL)) { moveleft(); } else if(!my_strcmp(input, KR)) { moveright(); } else if(!my_strcmp(input, " ")) { doselect(); } else { getout(input); } } }
void errexit(const char *s) { write(STDERR_FILENO, "\n", 1); perror(s); getout(0); }
void check_char(char *c) { if(!my_strcmp(c, (char *) SPACE)) doselect(); else if(!my_strcmp(c, gl_env.left)) moveleft(); else if(!my_strcmp(c, gl_env.right)) moveright(); else if(!my_strcmp(c, gl_env.up)) moveup(); else if(!my_strcmp(c, gl_env.down)) movedown(); else if(!my_strcmp(c, gl_env.esc) || !my_strcmp(c, (char *)ESC)) { restore_terminal(); getout(0); exit(1); } else if(!my_strcmp(c, (char *) ENTER)) { restore_terminal(); getout(1); } }
int main(int argc,char *argv[]) { printf("SRCSWAP - Source code mark/replace utility Version 1.0000 %s",__DATE__); markchar='~'; ovrwrit = 0; disp=0; nomark=0; noquote=0; xargc=argc; for (i=0;i<argc;i++) { xargv[i] = argv[i]; } if (argc < 4) format(); i = 4; while (i < argc) { getopt(i); i++; } getinp(); getout(); top=NULL; cur=NULL; get_xl(); srt_xl(); done=0; printf("\nProcessing..."); while (!(done)) { getline(); process(); } fclose(outf); return(0); }
char check_char(char* input){ if(input != NULL){ if(my_strcmp(input, KU) == 0){ moveup(); }else if(my_strcmp(input, KD) == 0){ movedown(); }else if(my_strcmp(input, KL) == 0){ moveleft(); }else if(my_strcmp(input, KR) == 0){ moveright(); }else if(my_strcmp(input, " ") == 0){ doselect(); }else{ getout(input); } } return *input; }
int readc(void) { int c; clrtoeol(); refresh(); c = getch(); if (c == '\004' || c == ERR) /* ^D or failure */ getout(0); if (c == '\033' || c == '\015') return('\n'); if (cflag) return(c); if (c == '\014') return('R'); if (c >= 'a' && c <= 'z') return(c & 0137); /* upper case */ return(c); }
main() { char line1[1024],line2[1024],line3[1024]; int popbcs,i; setvbuf(stdin,NULL,_IOFBF,24*1024); setvbuf(stdout,NULL,_IOFBF,24*1024); fprintf(stderr,"miniopt0... "); while(NULL!=gets(line1)) { TOP: if(!strcmp(line1,"ex\tde,hl")) { if(NULL==gets(line2)) { puts(line1); getout(); } else if(strncmp(line2,"ld\thl,",6)) { puts(line1); puts(line2); } else if(NULL==gets(line3)) { puts(line1); puts(line2); getout(); } else if(/* strcmp(line3,"add\thl,de") && */ strcmp(line3,"call\twrelop")) { puts(line1); puts(line2); strcpy(line1,line3); goto TOP; } else { /* if(!strcmp(line3,"call\twrelop")) */ printf("global wrelop_ex\n" "ld\tde,%s\n" "call\twrelop_ex\n", line2+6); /* else printf("ld\tde,%s\n" "add\thl,de ;; *miniopt0*\n",line2+6); */ opts++; } } else if(!strcmp(line1,"pop\tbc")) { popbcs=0; do { popbcs++; if(NULL==gets(line1)) { for(i=0;i<popbcs;i++) puts("pop\tbc"); getout(); } } while(!strcmp(line1,"pop\tbc")); if(strcmp(line1,"jp\tcret")) { for(i=0;i<popbcs;i++) puts("pop\tbc"); goto TOP; } puts("jp\tcret"); opts++; } else puts(line1); } getout(); return 0; }
void getarg(struct move *mm, char ***arg) { char **s; /* process arguments here. dashes are ignored, nbrw are ignored if * the game is being recovered */ s = *arg; while (*s && s[0][0] == '-') { switch (s[0][1]) { /* don't ask if rules or instructions needed */ case 'n': if (rflag) break; aflag = 0; args[acnt++] = 'n'; break; /* player is both red and white */ case 'b': if (rflag) break; pnum = 0; aflag = 0; args[acnt++] = 'b'; break; /* player is red */ case 'r': if (rflag) break; pnum = -1; aflag = 0; args[acnt++] = 'r'; break; /* player is white */ case 'w': if (rflag) break; pnum = 1; aflag = 0; args[acnt++] = 'w'; break; /* print board after move according to following * character */ case 'p': if (s[0][2] != 'r' && s[0][2] != 'w' && s[0][2] != 'b') break; args[acnt++] = 'p'; args[acnt++] = s[0][2]; if (s[0][2] == 'r') bflag = 1; if (s[0][2] == 'w') bflag = -1; if (s[0][2] == 'b') bflag = 0; break; case 't': if (s[0][2] == '\0') { /* get terminal caps */ s++; tflag = getcaps(*s); } else tflag = getcaps(&s[0][2]); break; case 's': s++; /* recover file */ if (s[0] == NULL) { writel("No save file named\n"); getout(0); } else recover(mm, s[0]); break; } s++; } if (s[0] != 0) recover(mm, s[0]); }
int main (int argc, char **argv) { int i,l; /* non-descript indices */ char c; /* non-descript character storage */ if (pledge("stdio rpath wpath cpath tty exec", NULL) == -1) err(1, "pledge"); signal(SIGINT, getout); /* trap interrupts */ /* use whole screen for text */ begscr = 0; getarg(argc, argv); initcurses(); /* check if restored game and save flag for later */ if ((rfl = rflag)) { if (pledge("stdio rpath wpath cpath tty", NULL) == -1) err(1, "pledge"); wrboard(); /* print board */ /* if new game, pretend to be a non-restored game */ if (cturn == 0) rflag = 0; } else { rscore = wscore = 0; /* zero score */ if (aflag) { /* print rules */ addstr(rules); if (yorn(0)) { endwin(); execl(TEACH, "teachgammon", (char *)NULL); err(1, "%s", noteach); } else {/* if not rules, then instructions */ addstr(need); if (yorn(0)) { /* print instructions */ clear(); text(instruct); } } } if (pledge("stdio rpath wpath cpath tty", NULL) == -1) err(1, "pledge"); init(); /* initialize board */ if (pnum == 2) {/* ask for color(s) */ printw("\n%s", askcol); while (pnum == 2) { c = readc(); switch (c) { case 'R': /* red */ pnum = -1; break; case 'W': /* white */ pnum = 1; break; case 'B': /* both */ pnum = 0; break; case 'P': /* Control the dice */ iroll = 1; addstr("\nDice controlled!\n"); addstr(askcol); break; default: /* error */ beep(); } } } wrboard(); /* print board */ move(18, 0); } /* limit text to bottom of screen */ begscr = 17; for (;;) { /* begin game! */ /* initial roll if needed */ if ((!rflag) || raflag) roll(); /* perform ritual of first roll */ if (!rflag) { move(17, 0); while (D0 == D1) /* no doubles */ roll(); /* print rolls */ printw("%s%d%s%d", rollr, D0, rollw, D1); /* winner goes first */ if (D0 > D1) { addstr(rstart); cturn = 1; } else { addstr(wstart); cturn = -1; } } /* initialize variables according to whose turn it is */ if (cturn == 1) { /* red */ home = 25; bar = 0; inptr = &in[1]; inopp = &in[0]; offptr = &off[1]; offopp = &off[0]; Colorptr = &color[1]; colorptr = &color[3]; colen = 3; } else { /* white */ home = 0; bar = 25; inptr = &in[0]; inopp = &in[1]; offptr = &off[0]; offopp = &off[1]; Colorptr = &color[0]; colorptr = &color[2]; colen = 5; } /* do first move (special case) */ if (!(rflag && raflag)) { if (cturn == pnum) /* computer's move */ domove(0); else { /* player's move */ mvlim = movallow(); /* reprint roll */ move(cturn == -1 ? 18 : 19, 0); proll(); getmove(); /* get player's move */ } } move(17, 0); clrtoeol(); begscr = 18; /* no longer any difference between normal and recovered game. */ rflag = 0; /* move as long as it's someone's turn */ while (cturn == 1 || cturn == -1) { /* board maintainence */ moveplayers(); /* fix board */ /* do computer's move */ if (cturn == pnum) { domove(1); /* see if double refused */ if (cturn == -2 || cturn == 2) break; /* check for winning move */ if (*offopp == 15) { cturn *= -2; break; } continue; } /* (player's move) */ /* clean screen if safe */ if (hflag) { move(20, 0); clrtobot(); hflag = 1; } /* if allowed, give him a chance to double */ if (dflag && dlast != cturn && gvalue < 64) { move(cturn == -1 ? 18: 19, 0); addstr(*Colorptr); c = readc(); /* character cases */ switch (c) { case 'R': /* reprint board */ wrboard(); break; case 'S': /* save game */ raflag = 1; save(1); break; case 'Q': /* quit */ quit(); break; case 'D': /* double */ dble(); break; case ' ': /* roll */ case '\n': roll(); printw(" rolls %d %d. ", D0, D1); /* see if he can move */ if ((mvlim = movallow()) == 0) { /* can't move */ printw("%s%s%s", toobad1, *colorptr, unable); if (pnum) { moveplayers(); sleep(MVPAUSE); } nexturn(); break; } getmove(); /* okay to clean screen */ hflag = 1; break; default: /* invalid character */ /* print help message */ move(20, 0); text(helpm); move(cturn == -1 ? 18 : 19, 0); /* don't erase */ hflag = 0; } } else {/* couldn't double */ /* print roll */ roll(); move(cturn == -1 ? 18: 19, 0); proll(); /* can he move? */ if ((mvlim = movallow()) == 0) { /* he can't */ printw("%s%s%s", toobad2, *colorptr, cantmv); moveplayers(); sleep(MVPAUSE); nexturn(); continue; } getmove(); } } /* don't worry about who won if quit */ if (cturn == 0) break; /* fix cturn = winner */ cturn /= -2; /* final board pos. */ moveplayers(); /* backgammon? */ mflag = 0; l = bar + 7 * cturn; for (i = bar; i != l; i += cturn) if (board[i] * cturn) mflag++; /* compute game value */ move(20, 0); if (*offopp == 15) { if (mflag) { addstr(bgammon); gvalue *= 3; } else if (*offptr <= 0) { addstr(gammon); gvalue *= 2; } } /* report situation */ if (cturn == -1) { addstr("Red wins "); rscore += gvalue; } else { addstr("White wins "); wscore += gvalue; } printw("%d point%s.\n", gvalue, (gvalue > 1) ? "s":""); /* write score */ wrscore(); /* see if he wants another game */ addstr(again); if ((i = yorn('S')) == 0) break; init(); if (i == 2) { addstr(" Save.\n"); cturn = 0; save(0); } /* yes, reset game */ wrboard(); } /* give him a chance to save if game was recovered */ if (rfl && cturn) { addstr(svpromt); if (yorn(0)) { /* re-initialize for recovery */ init(); cturn = 0; save(0); } } /* leave peacefully */ getout(0); /* NOT REACHED */ }
/*********************************************************************** * MAIN ***********************************************************************/ int main(int ac, char **av) { int term_stat; /* child return status */ int sig; /* current signal */ int lc; char *msg; /*************************************************************** * parse standard options, and exit if there is an error ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child, "dd", &CHILDSWRITEFD, &CHILDSREADFD); #endif /*************************************************************** * perform global setup for test ***************************************************************/ setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; signals_received[0] = '\0'; /* * fork off a child process */ if ((pid = FORK_OR_VFORK()) < 0) { tst_brkm(TBROK|TERRNO, cleanup, "fork() failed"); } else if (pid > 0) { /* PARENT PROCESS - first set up for unexpected signals */ tst_sig(FORK, DEF_HANDLER, getout); /* wait for "ready" message from child */ if (read_pipe(PARENTSREADFD) != 0) { /* read_pipe() failed. */ tst_brkm(TBROK, getout, "%s", p_p.mesg); } if (STD_TIMING_ON) { /* * Insure a running total for multiple loop iterations */ tblock.tb_total += p_p.rtimes.tb_total; if (p_p.rtimes.tb_min < tblock.tb_min) tblock.tb_min = p_p.rtimes.tb_min; if (p_p.rtimes.tb_max > tblock.tb_max) tblock.tb_max = p_p.rtimes.tb_max; tblock.tb_count += p_p.rtimes.tb_count; } /* check for ready message */ if (p_p.result != TPASS) { /* child setup did not go well */ tst_brkm(p_p.result, getout, "%s", p_p.mesg); } else if (STD_FUNCTIONAL_TEST) { tst_resm(p_p.result, "%s", p_p.mesg); } else { /* no pass results being issued */ Tst_count++; } /* * send signals to child and see if it holds them */ for (sig = 1; sig < NUMSIGS; sig++) { if ((sig == 41) && !CRAYT3E && !SGI) { sig = 42; /* skip over SIGPEFAILURE for non-CRAYT3E systems */ } if ((sig != SIGCLD) && (sig != SIGKILL) && (sig != SIGALRM) && (sig != SIGSTOP) && (sig != SIGCANCEL) && (sig != SIGTIMER) #ifdef SIGRECOVERY && (sig != SIGRECOVERY) #endif #ifdef SIGRESTART && (sig != SIGRESTART) #endif #ifdef SIGNOBDM && (sig != SIGNOBDM) #endif #ifdef SIGPTINTR && (sig != SIGPTINTR) #endif ) { if (kill(pid, sig) < 0) { tst_brkm(TBROK|TERRNO, NULL, "kill(%d, %d) failed", pid, sig); getout(); } } } /* * Tell child that all signals were sent. */ p_p.result = TPASS; strcpy(p_p.mesg, "All signals were sent"); write_pipe(PARENTSWRITEFD); /* * Get childs reply about received signals. */ if (read_pipe(PARENTSREADFD) < 0) { tst_brkm(TBROK, getout, "%s", p_p.mesg); } if (STD_FUNCTIONAL_TEST) tst_resm(p_p.result, "%s", p_p.mesg); else if (p_p.result != TPASS) tst_resm(p_p.result, "%s", p_p.mesg); else Tst_count++; /* * wait for child */ if (wait(&term_stat) < 0) { tst_brkm(TBROK, getout, "wait() failed"); } } else { /* * CHILD PROCESS - set up to catch signals. */ #ifdef UCLINUX if (self_exec(av[0], "dd", CHILDSWRITEFD, CHILDSREADFD) < 0) { tst_brkm(TBROK|TERRNO, cleanup, "self_exec() failed"); } #else do_child(); #endif } } cleanup(); tst_exit(); }
int OnlineSession::run(istream &in, bool interactive) { map<string, int> commands; _prepareCommands(commands); int res = 0; int count = 0; int cmd; string command; string sarg1, sarg2; int iarg1, iarg2, iarg3, iarg4, iarg5, iarg6, iarg7, iarg8; SeriesDistanceMetric *metric; double darg1; GroupableTimeSeriesSet *t; clock_t time; res = 0; while (!in.eof()) { if (res != 0) getout() << "Command returned with status " << res << "." << endl; if (interactive) { int width = getout().width(); getout() << "["; getout().width(3); getout() << count; getout().width(width); getout() << "] > "; getout().flush(); } in >> command; if (command.size() > 0 && !in.eof()) { cmd = commands[command]; } else { cmd = _EXIT; getout() << endl; } time = clock(); try { res = 0; switch (cmd) { case 0: getout() << "Unknown command '" << command << "'. Type 'help' for help." << endl; res = 1; break; case _EXIT: getout() << "Quitting..." << endl; return 0; case _HELP: _print_help(getout()); break; case _DEBUG: in >> iarg1; getout() << "Setting verbosity to " << iarg1 << "." << endl; verbosity = iarg1; break; case _LOAD_TSS: in >> sarg1; getout() << "Loading Time Series Set from file '" << sarg1 << "'." << endl; res = loaddb(sarg1.c_str()); if (res == 0) { getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl; } else { getout() << "Failed to load dataset." << endl; } break; case _SAVE_TSS: in >> iarg1; in >> sarg2; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Saving Time Series Set " << iarg1 << ":" << t->getName() << " to file '" << sarg2 << "'." << endl; res = savedb(iarg1, sarg2.c_str()); if (res == 0) getout() << "Dataset successfully saved." << endl; else getout() << "Failed to save dataset." << endl; break; case _OLOAD_TSS: in >> sarg1; in >> iarg1 >> iarg2 >> iarg3; getout() << "Loading Time Series Set from file '" << sarg1 << "' with N=" << iarg1 << ", L=" << iarg2 << ", and D=" << iarg3 << "." << endl; res = loadolddb(sarg1.c_str(), iarg1, iarg2, iarg3); if (res == 0) { getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl; } else { getout() << "Failed to load dataset." << endl; } break; case _OSAVE_TSS: in >> iarg1; in >> sarg2; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Saving Time Series Set " << iarg1 << ":" << t->getName() << " to file '" << sarg2 << "'." << endl; res = saveolddb(iarg1, sarg2.c_str()); if (res == 0) getout() << "Dataset successfully saved." << endl; else getout() << "Failed to save dataset." << endl; break; case _DROP_TSS: in >> iarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Dropping Time Series Set " << iarg1 << ":" << t->getName() << "." << endl; killdb(iarg1); break; case _RAND_TSS: in >> iarg1 >> iarg2 >> iarg3; getout() << "Generating random Time Series Set with N=" << iarg1 << ", L=" << iarg2 << ", and range=" << iarg3 << "." << endl; res = randdb(iarg3, iarg1, iarg2); if (res == 0) getout() << "Dataset successfully loaded. Index: " << datasets.size()-1 << endl; else getout() << "Failed to load dataset." << endl; break; case _LIST_TSS: res = printdbs(); break; case _NORM_TSS: in >> iarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Normalizing Time Series Set " << iarg1 << ":" << t->getName() << "." << endl; t->normalize(); break; case _KSIM_TSS: in >> iarg1 >> iarg2 >> iarg3 >> iarg4 >> iarg5 >> iarg6; checkIndex(iarg1); checkIndex(iarg2); t = datasets[iarg1]; getout() << "Searching similar sequences for Time Series Set " << iarg1 << ":" << t->getName(); t = datasets[iarg2]; getout() << ", query string at " << iarg3 << " in dataset " << iarg2 << ":" << t->getName(); getout() << " in interval [" << iarg4 << "," << iarg5 << "] with strategy=" << iarg6 << "." << endl; similar(iarg1, iarg2, iarg3, TimeInterval(iarg4, iarg5), iarg6); break; case _OUTLIER_TSS: in >> iarg1 >> iarg2; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Searching for outlier group in dataset " << iarg1 << ":" << t->getName() << " for length=" << iarg2 << "." << endl; outlier(iarg1, iarg2); break; case _TSS_DIST: in >> iarg1 >> iarg2 >> iarg3 >> iarg4; in >> iarg5 >> iarg6 >> iarg7 >> iarg8; in >> sarg1; checkIndex(iarg1); checkIndex(iarg5); metric = getDistMetric(sarg1.c_str()); if (metric == NULL) { getout() << "Unknown method: " << sarg1.c_str() << endl; res = -1; break; } getout() << "Using distance metric " << metric->name << " to find distance:" << endl; getout() << "A: DB:" << iarg1 << ", " << iarg2 << "@[" << iarg3 << "," << iarg4 << "]." << endl; getout() << "B: DB:" << iarg5 << ", " << iarg6 << "@[" << iarg7 << "," << iarg8 << "]." << endl; getout() << "Distance: " << printdist(iarg1, iarg5, iarg2, iarg6, TimeInterval(iarg3, iarg4), TimeInterval(iarg7, iarg8), metric) << endl; break; case _LS_DIST: printDistMetrics(); break; case _GROUP_TSS: in >> iarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Generating new grouping for Time Series Set " << iarg1 << ":" << t->getName() << " with ST " << defaultST << "." << endl; res = initdbgroups(iarg1, defaultST); break; case _GROUP_ST_TSS: in >> iarg1; in >> darg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Generating new grouping for Time Series Set " << iarg1 << ":" << t->getName() << " with ST " << darg1 << "." << endl; res = initdbgroups(iarg1, darg1); break; case _LOAD_GROUP_TSS: in >> iarg1; in >> sarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Loading grouping data for Time Series Set " << iarg1 << ":" << t->getName() << " at " << sarg1 << "." << endl; res = loaddbgroups(iarg1, sarg1.c_str()); break; case _SAVE_GROUP_TSS: in >> iarg1; in >> sarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Saving grouping data for Time Series Set " << iarg1 << ":" << t->getName() << " to " << sarg1 << "." << endl; res = savedbgroups(iarg1, sarg1.c_str()); break; case _DROP_GROUP_TSS: in >> iarg1; checkIndex(iarg1); t = datasets[iarg1]; getout() << "Dropping grouping data for Time Series Set " << iarg1 << ":" << t->getName() << "." << endl; res = killdbgroups(iarg1); break; case _DESC_TSS: in >> iarg1; checkIndex(iarg1); res = descdb(iarg1); break; case _PRINT_TSS: in >> iarg1; checkIndex(iarg1); res = printdb(iarg1); break; case _PRINT_INTERVAL: in >> iarg1 >> iarg2 >> iarg3 >> iarg4; checkIndex(iarg1); res = printint(iarg1, iarg2, TimeInterval(iarg3, iarg4)); break; case _SET_DEF_ST: in >> darg1; getout() << "Setting default ST to " << darg1 << "." << endl; res = setST(darg1); break; case _GET_DEF_ST: getout() << "default ST = " << getST() << "." << endl; break; case _SET_DEF_R: in >> iarg1; getout() << "Setting default R constraint to " << iarg1 << "." << endl; res = setR(iarg1); break; case _GET_DEF_R: getout() << "default R = " << getR() << "." << endl; break; } } catch (exception &e) { getout() << "Caught exception attempting operation:" << endl; getout() << e.what() << endl; } time = clock() - time; getout() << "Command used " << ((float)time/CLOCKS_PER_SEC) << " seconds." << endl << endl; count++; } return 0; }