int msgqueueCtl4Press(Control *pCtl,int ch,long lParam) { /* 删除队列button的按键消息处理 */ /* Add your self code here: */ if (ch == '\r') { Control *pList = GetCtlByID (msgqueue_handle, 6); if (ListSelNum (pList) == 0) { prtmsg (pCtl, 20, 40, "请在队列列表框中按空格选择队列"); return ch; } if (yorn (pCtl, 20, 40, "WARNING:确实要删除?(y/n)")==0) return ch; for (int i=0; i<g_iMQListCount; i++) { if (ListItemState (pList, i) != SELECTED) continue; MessageQueue mq(g_tMQList[i].iMQID); mq.remove (); } SetMQListData (); CtlShow (pList); CtlAtv (pCtl, pCtl); } return ch; }
int quit(void) { move(20, 0); clrtobot(); addstr("Are you sure you want to quit?"); if (yorn(0)) { if (rfl) { addstr("Would you like to save this game?"); if (yorn(0)) save(0); } cturn = 0; return(1); } return(0); }
/* * dble() * Have the current player double and ask opponent to accept. */ void dble () { register int resp; /* response to y/n */ for (;;) { writel (" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ writel (" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else { /* computer accepts */ writel (" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; if (tflag) gwrite(); return; } } /* ask if player accepts */ writel (" Does "); writel (cturn == 1? color[2]: color[3]); writel (" accept?"); /* get response from yorn, * a "2" means he said "p" * for print board. */ if ((resp = yorn ('R')) == 2) { writel (" Reprint.\n"); buflush(); wrboard(); writel (*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } nexturn (); /* declined */ cturn *= -2; return; } }
int quit(struct move *mm) { if (tflag) { curmove(20, 0); clend(); } else writec('\n'); writel("Are you sure you want to quit?"); if (yorn(0)) { if (rfl) { writel("Would you like to save this game?"); if (yorn(0)) save(mm, 0); } cturn = 0; return (1); } return (0); }
void dble() { int resp; /* response to y/n */ for (;;) { addstr(" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ addstr(" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else {/* computer accepts */ addstr(" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; gwrite(); return; } } /* ask if player accepts */ printw(" Does %s accept?", cturn == 1 ? color[2] : color[3]); /* get response from yorn; a "2" means he said "p" to print board. */ if ((resp = yorn ('r')) == 2) { addstr(" Reprint.\n"); moveplayers(); wrboard(); addstr(*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; gwrite(); return; } nexturn(); /* declined */ cturn *= -2; return; } }
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 */ }
/* * This routine reads the specified file into a database and returns a * pointer to that database. */ ELT * DBRead(register FILE *file) { register int i; register int done; /* flag for input exhausted */ register double nx; /* x holder so x is not set before orienting */ int type; /* element type */ ELT *elist; /* pointer to the file's elements */ POINT *plist; /* pointer for reading in points */ char string[MAXSTRING], *txt; double x, y; /* x and y are read in point coords */ int len, brush, size; int lastpoint; SUNFILE = FALSE; elist = DBInit(); (void) fscanf(file, "%" MAXSTRING_S "s%*[^\n]\n", string); if (strcmp(string, "gremlinfile")) { if (strcmp(string, "sungremlinfile")) { error("`%1' is not a gremlin file", gremlinfile); return (elist); } SUNFILE = TRUE; } (void) fscanf(file, "%d%lf%lf\n", &size, &x, &y); /* ignore orientation and file positioning point */ done = FALSE; while (!done) { /* if (fscanf(file,"%" MAXSTRING_S "s\n", string) == EOF) */ /* I changed the scanf format because the element */ /* can have two words (e.g. CURVE SPLINE) */ if (fscanf(file, "\n%" MAXSTRING_S "[^\n]%*[^\n]\n", string) == EOF) { error("`%1', error in file format", gremlinfile); return (elist); } type = DBGetType(string); /* interpret element type */ if (type < 0) { /* no more data */ done = TRUE; } else { #ifdef UW_FASTSCAN (void) xscanf(file, &x, &y); /* always one point */ #else (void) fscanf(file, "%lf%lf\n", &x, &y); /* always one point */ #endif /* UW_FASTSCAN */ plist = PTInit(); /* NULL point list */ /* * Files created on the SUN have point lists terminated by a line * containing only an asterik ('*'). Files created on the AED have * point lists terminated by the coordinate pair (-1.00 -1.00). */ if (TEXT(type)) { /* read only first point for TEXT elements */ nx = xorn(x, y); y = yorn(x, y); (void) PTMakePoint(nx, y, &plist); savebounds(nx, y); #ifdef UW_FASTSCAN while (xscanf(file, &x, &y)); #else lastpoint = FALSE; do { fgets(string, MAXSTRING, file); if (string[0] == '*') { /* SUN gremlin file */ lastpoint = TRUE; } else { (void) sscanf(string, "%lf%lf", &x, &y); if ((x == -1.00 && y == -1.00) && (!SUNFILE)) lastpoint = TRUE; else { if (compatibility_flag) savebounds(xorn(x, y), yorn(x, y)); } } } while (!lastpoint); #endif /* UW_FASTSCAN */ } else { /* not TEXT element */ #ifdef UW_FASTSCAN do { nx = xorn(x, y); y = yorn(x, y); (void) PTMakePoint(nx, y, &plist); savebounds(nx, y); } while (xscanf(file, &x, &y)); #else lastpoint = FALSE; while (!lastpoint) { nx = xorn(x, y); y = yorn(x, y); (void) PTMakePoint(nx, y, &plist); savebounds(nx, y); fgets(string, MAXSTRING, file); if (string[0] == '*') { /* SUN gremlin file */ lastpoint = TRUE; } else { (void) sscanf(string, "%lf%lf", &x, &y); if ((x == -1.00 && y == -1.00) && (!SUNFILE)) lastpoint = TRUE; } } #endif /* UW_FASTSCAN */ } (void) fscanf(file, "%d%d\n", &brush, &size); (void) fscanf(file, "%d", &len); /* text length */ (void) getc(file); /* eat blank */ txt = (char *) malloc((unsigned) len + 1); for (i = 0; i < len; ++i) { /* read text */ int c = getc(file); if (c == EOF) break; txt[i] = c; } txt[len] = '\0'; (void) DBCreateElt(type, plist, brush, size, txt, &elist); } /* end else */ } /* end while not done */ ; return (elist); } /* end DBRead */
int main( int argc, char **argv) { scmcon *testconp = NULL; scmcon *realconp = NULL; scm *scmp = NULL; FILE *sfile = NULL; char *thedelfile = NULL; char *topdir = NULL; char *thefile = NULL; char *outfile = NULL; char *outfull = NULL; char *outdir = NULL; char *tmpdsn = NULL; char *ne; char *porto = NULL; char errmsg[1024]; char *skifile = NULL; int ians = 0; int do_create = 0; int do_delete = 0; int do_sockopts = 0; int do_fileopts = 0; int use_filelist = 0; int perpetual = 0; int really = 0; int trusted = 0; int force = 0; int allowex = 0; int sta = 0; int s; int c; (void)setbuf(stdout, NULL); if (argc <= 1) { usage(); return (1); } while ((c = getopt(argc, argv, "t:xyhad:f:F:lLwz:pm:c:s")) != EOF) { switch (c) { case 'a': allowex = 1; break; case 't': do_create++; topdir = optarg; break; case 'x': do_delete++; break; case 'y': force++; break; case 'D': trusted++; case 'd': thedelfile = optarg; break; case 'F': trusted++; case 'f': thefile = optarg; break; case 'L': trusted++; case 'l': use_filelist++; break; case 'w': do_sockopts++; break; case 'z': do_fileopts++; porto = optarg; break; case 'p': perpetual++; break; case 'c': skifile = optarg; break; case 'h': usage(); return (0); case 's': strict_profile_checks = 1; // global from myssl.c strict_profile_checks_cms = 1; // global from roa_validate.c break; default: (void)fprintf(stderr, "Invalid option '%c'\n", c); usage(); return (1); } } // if there is anything left in argv, or no operation specified, warn user if (optind < argc) { (void)printf("Extra arguments at the end of the command line.\n"); usage(); return (1); } if ((do_create + do_delete + do_sockopts + do_fileopts) == 0 && thefile == 0 && thedelfile == 0 && skifile == 0 && use_filelist == 0) { (void)printf("You need to specify at least one operation " "(e.g. -f file).\n"); usage(); return (1); } OPEN_LOG("rcli", LOG_USER); if (!my_config_load()) { LOG(LOG_ERR, "can't load configuration"); exit(EXIT_FAILURE); } if (force == 0) { if (do_delete > 0) { ians = yorn("Do you REALLY want to delete all database tables"); if (ians <= 0) { LOG(LOG_NOTICE, "Delete operation cancelled"); return (1); } really++; } if ((do_create > 0) && (really == 0)) { ians = yorn("Do you REALLY want to create all database tables"); if (ians <= 0) { LOG(LOG_NOTICE, "Create operation cancelled"); return (1); } really++; } } scmp = initscm(); if (scmp == NULL) { LOG(LOG_ERR, "Internal error: cannot initialize database schema"); return (-2); } /* * If a create or delete operation is being performed, then a test dsn * will be needed; create it now and defer the creation of the real dsn * until later. Otherwise, create the real dsn. * * A test dsn is needed for operations that operate on the overall * database state as opposed to the rpki tables, namely the create and * delete operations. */ if ((do_create + do_delete) > 0) { /* * Note that in the following line, we do not intend to edit * the database named "information_schema". We are simply * filling in the "database name" parameter with something * that is guaranteed to be valid for MySQL. */ tmpdsn = makedsnscm(scmp->dsnpref, "information_schema", CONFIG_DATABASE_USER_get(), CONFIG_DATABASE_PASSWORD_get()); if (tmpdsn == NULL) { membail(); return (-1); } testconp = connectscm(tmpdsn, errmsg, 1024); memset(tmpdsn, 0, strlen(tmpdsn)); free((void *)tmpdsn); if (testconp == NULL) { LOG(LOG_ERR, "Cannot connect to DSN: %s", errmsg); freescm(scmp); return (-1); } } else { realconp = connectscm(scmp->dsn, errmsg, 1024); if (realconp == NULL) { LOG(LOG_ERR, "Cannot connect to DSN %s: %s", scmp->dsn, errmsg); freescm(scmp); return (-1); } } /* * Process command line options in the following order: delete, create, * dofile, dodir, listener. */ if (do_delete > 0) sta = deleteop(testconp, scmp); if ((do_create > 0) && (sta == 0)) /* first phase of create */ sta = createop(testconp, scmp); /* * Don't need the test connection any more */ if (testconp != NULL) { disconnectscm(testconp); testconp = NULL; } /* * If there has been an error or if we're done because the database was * just deleted and not re-created, bail out. */ if (sta < 0 || (do_delete > 0 && do_create == 0)) { if (realconp != NULL) disconnectscm(realconp); freescm(scmp); if (tdir != NULL) free((void *)tdir); return (sta); } /* * If a connection to the real DSN has not been opened yet, open it now. */ if (realconp == NULL) { realconp = connectscm(scmp->dsn, errmsg, 1024); if (realconp == NULL) { LOG(LOG_ERR, "Cannot connect to DSN %s: %s", scmp->dsn, errmsg); freescm(scmp); if (tdir != NULL) free((void *)tdir); return (-1); } } /* * If a create operation was requested, complete it now. */ if ((do_create > 0) && (sta == 0)) sta = create2op(scmp, realconp, topdir); /* * If the top level repository directory is not set, then retrieve it from * the database. */ if ((tdir == NULL) && (sta == 0)) { tdir = retrieve_tdir(scmp, realconp, &sta); if (tdir == NULL) LOG(LOG_ERR, "Cannot retrieve top level repository info from DB"); } if (sta == 0) { LOG(LOG_INFO, "Top level repository directory is %s", tdir); tdirlen = strlen(tdir); } /* * Setup for actual SSL operations */ OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); LOG(LOG_NOTICE, "Rsync client session started"); if (thefile != NULL && sta == 0) { // Check that the file is in the repository, ask if not and force is // off sta = splitdf(NULL, NULL, thefile, &outdir, &outfile, &outfull); if (sta == 0) { if (strncmp(tdir, outdir, tdirlen) != 0 && force == 0) { ians = yorn("That file is not in the repository. Proceed anyway"); if (ians <= 0) sta = 1; } // if ( strstr(outdir, "TRUST") != NULL ) // trusted++; // if the user has declared it to be trusted // ask for verification unless force is set if (trusted > 0 && force == 0 && sta == 0) { ians = yorn("Really declare this file as trusted"); if (ians <= 0) sta = 1; } if (sta == 1) LOG(LOG_NOTICE, "File operation cancelled"); if (sta == 0) { LOG(LOG_INFO, "Attempting add: %s", outfile); setallowexpired(allowex); sta = add_object(scmp, realconp, outfile, outdir, outfull, trusted); if (sta < 0) { LOG(LOG_ERR, "Add failed: %s: error %s (%d)", thefile, err2string(sta), sta); if (sta == ERR_SCM_SQL) { ne = geterrorscm(realconp); if (ne != NULL && ne != 0) LOG(LOG_ERR, "\t%s", ne); } } else LOG(LOG_INFO, "Add succeeded: %s", outfile); } free((void *)outdir); free((void *)outfile); free((void *)outfull); } else LOG(LOG_ERR, "%s (%d)", err2string(sta), sta); } if (use_filelist > 0 && sta == 0) { char *line = NULL; size_t len = 0; ssize_t read; int status; setallowexpired(allowex); while ((read = getline(&line, &len, stdin)) != -1) { if (read == 0) continue; // Trim newline and skip line if empty if (line[read - 1] == '\n') line[read - 1] = '\0'; if (strlen(line) == 0) continue; // Split directory and file components of path status = splitdf(NULL, NULL, line, &outdir, &outfile, &outfull); if (status != 0) { LOG(LOG_ERR, "%s (%d)", err2string(status), status); continue; } LOG(LOG_INFO, "Attempting add: %s", outfile); // Warn if file not within repository directory if (strncmp(tdir, outdir, tdirlen) != 0) LOG(LOG_WARNING, "%s is not in the repository", line); // Add status = add_object(scmp, realconp, outfile, outdir, outfull, trusted); if (status == 0) { LOG(LOG_INFO, "Add succeeded: %s", outfile); } else { LOG(LOG_ERR, "Add failed: %s: error %s (%d)", line, err2string(status), status); if (status == ERR_SCM_SQL) { ne = geterrorscm(realconp); if (ne != NULL && ne != 0) LOG(LOG_ERR, "\t%s", ne); } } free((void *)outdir); free((void *)outfile); free((void *)outfull); } free(line); } if (thedelfile != NULL && sta == 0) { sta = splitdf(NULL, NULL, thedelfile, &outdir, &outfile, &outfull); if (sta == 0) { sta = delete_object(scmp, realconp, outfile, outdir, outfull, 0); if (sta < 0) { LOG(LOG_ERR, "Could not delete file %s: error %s (%d)", thedelfile, err2string(sta), sta); if (sta == ERR_SCM_SQL) { ne = geterrorscm(realconp); if (ne != NULL && ne != 0) LOG(LOG_ERR, "\t%s", ne); } } else LOG(LOG_INFO, "Delete operation succeeded (%s removed)", thedelfile); free((void *)outdir); free((void *)outfile); free((void *)outfull); } else LOG(LOG_ERR, "Error: %s (%d)", err2string(sta), sta); } if ((do_sockopts + do_fileopts) > 0 && sta == 0) { int protos = (-1); const int max_makesock_attempts = 10; int makesock_failures = 0; do { if (do_sockopts > 0) { uint16_t port = CONFIG_RPKI_PORT_get(); s = makesock(port, &protos); if (s < 0) { makesock_failures++; LOG(LOG_ERR, "Failed to listen on port %" PRIu16 " (failure #%d)", port, makesock_failures); sleep(1); if (makesock_failures >= max_makesock_attempts) { LOG(LOG_ERR, "%d failed attempts to create socket. Aborting.", max_makesock_attempts); sta = -1; break; } } else { makesock_failures = 0; FLUSH_LOG(); sta = sockline(scmp, realconp, s); LOG(LOG_INFO, "Socket connection closed"); FLUSH_LOG(); (void)close(s); } } if (do_fileopts > 0 && porto != NULL) { if (!isatty(0)) { LOG(LOG_DEBUG, "Opening stdin"); sfile = stdin; sta = fileline(scmp, realconp, sfile); } else { LOG(LOG_DEBUG, "Opening a socket cmdfile %s", porto); sfile = fopen(porto, "r"); if (sfile == NULL) LOG(LOG_ERR, "Could not open cmdfile"); else { sta = fileline(scmp, realconp, sfile); LOG(LOG_DEBUG, "Cmdfile closed"); (void)fclose(sfile); } } } if (sta == 0 && skifile) { LOG(LOG_DEBUG, "Starting skifile %s", skifile); sta = read_SKI_blocks(scmp, realconp, skifile); if (sta > 0) sta = 0; if (sta) LOG(LOG_ERR, "Error with skifile: %s (%d)", err2string(sta), sta); } } while (perpetual > 0); if (protos >= 0) (void)close(protos); } if (sta == 0 && skifile) { LOG(LOG_DEBUG, "Starting skifile %s", skifile); sta = read_SKI_blocks(scmp, realconp, skifile); if (sta > 0) sta = 0; if (sta) LOG(LOG_ERR, "Error with skifile: %s (%d)", err2string(sta), sta); } (void)ranlast(scmp, realconp, "RSYNC"); sqcleanup(); if (realconp != NULL) disconnectscm(realconp); freescm(scmp); if (tdir != NULL) free((void *)tdir); LOG(LOG_NOTICE, "Rsync client session ended"); config_unload(); CLOSE_LOG(); return (sta); }