void init_cmd(void) { uint16_t i, j, k; for (k = 0; k < 3; k++) { // k for konsole for (i = 0; i < CONS_NUMACTS[k]; i++) { if (!CONS_HASREST[k][i]) cmd_init(i, 0, k); for (j = 1; j < CONS_STATES[k][i]; j++) { cmd_init(i, j, k); } } } uint8_t word_outer = cmd_get(0, 7, 0); uint8_t word_inner = cmd_get(0, 6, 0); // word wheel commands -- go at the end of the command list k = 0; for (i = word_outer; i < word_outer + 6; i++) { for (j = word_inner; j < word_inner + 6; j++) { _CMD wordcmd_tmp; wordcmd_tmp.console = 0; wordcmd_tmp.index = cmds_ptr; wordcmd_tmp.actuator = 0; wordcmd_tmp.group = 10; // special word wheel group wordcmd_tmp.states = 36; wordcmd_tmp.hasrest = 0; wordcmd_tmp.action = k; wordcmd_tmp.desired = (WORD32)(cmds[i].desired.ul | cmds[j].desired.ul); wordcmd_tmp.mask = (WORD32)(cmds[i].mask.ul | cmds[j].mask.ul); strcpy(wordcmd_tmp.command, words_outer[i-word_outer]); strcat(wordcmd_tmp.command, words_inner[j-word_inner]); k++; cmds[cmds_ptr] = wordcmd_tmp; cmds_ptr++; } } cmd_wormhole.console = 6; cmd_wormhole.index = 0; cmd_wormhole.actuator = 0; cmd_wormhole.group = 7; cmd_wormhole.states = 0; cmd_wormhole.hasrest = 0; cmd_wormhole.action = 0; cmd_wormhole.desired = (WORD32)0xFFFFFFFF; cmd_wormhole.mask = (WORD32)0xFFFFFFFF; strcpy(cmd_wormhole.command, worm_str); }
void connection::handle_read_command(const boost::system::error_code& e, std::size_t bytes_transferred) { if (!e) { a::const_buffer b = a::buffer(buffer_); const command *command_type = a::buffer_cast<const command *>(b); if (*command_type == get_msg) { cmd_get(); } else if (*command_type == ack_msg) { a::async_read(socket_, a::buffer(buffer_, sizeof(message_id)), bind(&connection::handle_read_message_id, shared_from_this(), a::placeholders::error, a::placeholders::bytes_transferred)); } else if (*command_type == put_msg) { a::async_read(socket_, a::buffer(buffer_, sizeof(message_len_t)), boost::bind(&connection::handle_read_length, shared_from_this(), a::placeholders::error, a::placeholders::bytes_transferred)); } else { printf("ERROR: unknown message type %d, closing connection\n", *command_type); socket_.shutdown( a::ip::tcp::socket::shutdown_both); } } }
// Exposed to end user int do_function(String args){ // If args is a number then will execute cmd that relates to that number. int cmdid = args.toInt(); if(cmdid != 0){ return execute(cmdid); } // Searches for command with name=args. return execute(cmd_get(args)); }
/* Run the database program interactively. Will repeatedly prompt for a command. */ void run_interactive() { printf("Welcome to FlatDB.\n"); printf("Copyright 2013 Oracle Corporation\n"); printf("\"We synergize your paradigms.\"\n"); printf("\n"); char path[255]; printf("Enter the location of the database file. It does not need to exist; a blank one will be created for you if necessary.\n> "); fgets(path, 255, stdin); char command = 0; do { printf("\n"); printf("Choose a command:\n"); printf(" _a_dd an entry\n"); printf(" _f_ind an ID\n"); printf(" _r_remove an entry\n"); printf(" _p_rint the database\n"); printf(" _q_uit the application\n"); printf("> "); command = fgetc(stdin); getchar(); printf("\n"); switch (command) { case 'a': cmd_add(path); break; case 'f': cmd_get(path); break; case 'r': cmd_remove(path); break; case 'p': cmd_print(path); break; default: break; } } while (command != 'q'); printf("Thank you. Goodbye.\n"); }
int read_cmd(int sock, char *cmd) { if (ft_strequ(cmd, "quit")) return (1); else if (ft_strequ(cmd, "pwd")) cmd_pwd(sock); else if (ft_strnequ(cmd, "ls", 2)) cmd_ls(sock); else if (ft_strnequ(cmd, "cd", 2)) cmd_cd(sock); else if (ft_strnequ(cmd, "get ", 4)) cmd_get(sock, cmd); else if (ft_strnequ(cmd, "put ", 4)) cmd_put(sock, cmd); else cmd_unknow(cmd); return (0); }
int Main(void) { char *cmd[8]; int cmdcnt; char buff[32]; init(); start(); puts(help[0]); init_taglist(0x40000000); while(1) { puts("IMX233# "); cmdcnt = cmdline(cmd); if (cmdcnt == 1 && strcmp(cmd[0], "h") == 0) { int i; for (i = 0; i < 3; i++) { puts("\r\n"); puts(help[i]); } } if (cmdcnt == 2 && strcmp(cmd[0], "get") == 0) { cmd_get(cmd[1]); } if (cmdcnt == 2 && strcmp(cmd[0], "go") == 0) { cmd_go(cmd[1]); } if (cmdcnt == 1 && strcmp(cmd[0], "ddr") == 0) { ddrtest(); } putchr('\n'); putchr('\r'); } return 0; }
// 运行客户端 void run(char* ip, char* pt) { int sockfd = connectToHost(ip, pt); if (getReplyCode(sockfd) != SERVICE_READY) errorReport("Service Connect Error!"); while (userLogin(sockfd) != 0) // 调用登录函数userLogin printf("Please try again.\n"); int isQuit = 0; char buf[BUF_SIZE]; while (!isQuit) { printf("[Client command] "); fgets(buf, sizeof(buf), stdin); switch (cmdToNum(buf)) { case GET: cmd_get(sockfd, buf); break; case PUT: cmd_put(sockfd, buf); break; case PWD: cmd_pwd(sockfd); break; case DIR: cmd_dir(sockfd); break; case CD: cmd_cd(sockfd, buf); break; case HELP: cmd_help(); break; case QUIT: cmd_quit(sockfd); isQuit = 1; break; default: cmd_help(); break; } } close(sockfd); }
void play(void) { Player *player = NULL; StarSystem *sys = NULL; set_seed(); putchar('\n'); player = player_create(); sys = starsys_create(); LINE(80, '-'); player_move_toSystem(player, sys); while (!player->wantToExit) { cmd_get(player); } player_destroy(player); }
stat_t _json_parser_kernal(char *str) { uint8_t status; int8_t depth; cmdObj_t *cmd = cmd_reset_list(); // get a fresh cmdObj list char group[CMD_GROUP_LEN+1] = {""}; // group identifier - starts as NUL int8_t i = CMD_BODY_LEN; ritorno(_normalize_json_string(str, JSON_OUTPUT_STRING_MAX)); // return if error // parse the JSON command into the cmd body do { if (--i == 0) { return (STAT_JSON_TOO_MANY_PAIRS); } // length error if ((status = _get_nv_pair_strict(cmd, &str, &depth)) > STAT_EAGAIN) { // erred out return (status); } // propagate the group from previous NV pair (if relevant) if (group[0] != NUL) { strncpy(cmd->group, group, CMD_GROUP_LEN);// copy the parent's group to this child } // validate the token and get the index if ((cmd->index = cmd_get_index(cmd->group, cmd->token)) == NO_MATCH) { return (STAT_UNRECOGNIZED_COMMAND); } if ((cmd_index_is_group(cmd->index)) && (cmd_group_is_prefixed(cmd->token))) { strncpy(group, cmd->token, CMD_GROUP_LEN);// record the group ID } if ((cmd = cmd->nx) == NULL) return (STAT_JSON_TOO_MANY_PAIRS);// Not supposed to encounter a NULL } while (status != STAT_OK); // breaks when parsing is complete // execute the command cmd = cmd_body; if (cmd->objtype == TYPE_NULL){ // means GET the value ritorno(cmd_get(cmd)); // ritorno returns w/status on any errors } else { ritorno(cmd_set(cmd)); // set value or call a function (e.g. gcode) cmd_persist(cmd); } return (STAT_OK); // only successful commands exit through this point }
/**************************************************************************** * cmd_text_parser() - update a config setting from a text block (text mode) * _text_parser() - helper for above * * Use cases handled: * - $xfr=1200 set a parameter * - $xfr display a parameter * - $x display a group * - ? generate a status report (multiline format) */ uint8_t cmd_text_parser(char *str) { // return (SC_OK); // There is no text parser in this code - just JSON //} cmdObj_t *cmd = cmd_reset_list(); // returns first object in the body uint8_t status = SC_OK; // single-unit parser processing ritorno(_text_parser(str, cmd)); // decode the request or return if error if ((cmd->type == TYPE_PARENT) || (cmd->type == TYPE_NULL)) { if (cmd_get(cmd) == SC_COMPLETE) { // populate value, group values, or run uber-group displays return (SC_OK); // return for uber-group displays so they don't print twice } } else { // process SET and RUN commands status = cmd_set(cmd); // set single value cmd_persist(cmd); } cmd_print_list(status, TEXT_MULTILINE_FORMATTED, JSON_RESPONSE_FORMAT); // print the results return (status); return (SC_OK); }
/* Accepts messages and routes them to their respective registered processes */ void sysproc_command_decoder(void) { msg_envelope_t *msg; int message_target; int source; while (1) { msg = receive_message(&source); switch (msg->header.type) { case CMD_REGISTER_MSG: { cmd_put(msg->data, source); free_message(msg); } break; case CMD_NOTIFY_MSG: { cmd_parse(msg->data); message_target = cmd_get(msg->data); send_message(message_target, msg); } break; } } }
/* * Request a game command from the uI and carry out whatever actions * go along with it. */ void process_command(cmd_context ctx, bool no_request) { int idx; game_command cmd; /* If we've got a command to process, do it. */ if (cmd_get(ctx, &cmd, !no_request) == 0) { idx = cmd_idx(cmd.command); if (idx == -1) return; /* Do some sanity checking on those arguments that might have been declared as "unknown", such as directions and targets. */ switch (cmd.command) { case CMD_WALK: case CMD_RUN: case CMD_JUMP: case CMD_OPEN: case CMD_CLOSE: case CMD_TUNNEL: case CMD_DISARM: case CMD_BASH: case CMD_ALTER: case CMD_JAM: case CMD_MAKE_TRAP: { /* Direction hasn't been specified, so we ask for one. */ if (cmd.args[0].direction == DIR_UNKNOWN) { if (!get_rep_dir(&cmd.args[0].direction)) return; } break; } /* * These take an item number and a "target" as arguments, * though a target isn't always actually needed, so we'll * only prompt for it via callback if the item being used needs it. */ case CMD_USE_WAND: case CMD_USE_ROD: case CMD_QUAFF: case CMD_ACTIVATE: case CMD_READ_SCROLL: case CMD_FIRE: case CMD_THROW: case CMD_STEAL: { bool get_target = FALSE; if (cmd.command == CMD_FIRE || cmd.command == CMD_THROW || obj_needs_aim(object_from_item_idx(cmd.args[0].choice))) { if (cmd.args[1].direction == DIR_UNKNOWN) get_target = TRUE; if (cmd.args[1].direction == DIR_TARGET && !target_okay()) get_target = TRUE; } if (get_target && !get_aim_dir(&cmd.args[1].direction, FALSE)) return; break; } /* This takes a choice and a direction. */ case CMD_CAST: { bool get_target = FALSE; if (spell_needs_aim(cp_ptr->spell_book, cmd.args[0].choice)) { if (cmd.args[1].direction == DIR_UNKNOWN) get_target = TRUE; if (cmd.args[1].direction == DIR_TARGET && !target_okay()) get_target = TRUE; } if (get_target && !get_aim_dir(&cmd.args[1].direction, FALSE)) return; break; } default: { /* I can see the point of the compiler warning, but still... */ break; } } /* Command repetition */ if (game_cmds[idx].repeat_allowed) { /* Auto-repeat */ if (game_cmds[idx].auto_repeat_n > 0 && p_ptr->command_arg == 0 && p_ptr->command_rep == 0) p_ptr->command_arg = game_cmds[idx].auto_repeat_n; allow_repeated_command(); } repeat_prev_allowed = TRUE; if (game_cmds[idx].fn) game_cmds[idx].fn(cmd.command, cmd.args); } }
int main(void) { int isRunning = 1; char buffer[MAX_LINE_LENGTH]; char command[MAX_LINE_LENGTH]; while(isRunning){ //int i; printf("> "); fgets(buffer, MAX_LINE_LENGTH, stdin); /*for( i = 0; i < MAX_LINE_LENGTH; i++ ){ buffer[i] = tolower(buffer[i]); }*/ sscanf(buffer, " %s ", (char*)&command); //Switch for commands if(strcmp(command, "BYE") == 0){ /*BYE*/ deleteAllEntry(entry_head); deleteAllSnapshot(snapshot_head); printf("bye"); isRunning = 0; }else if(strcmp(command, "HELP") == 0){ /*HELP*/ cmd_help(); }else if(strcmp(command, "LIST") == 0){ sscanf(buffer + strlen(command), "%s", (char*)&command); if(strcmp(command, "KEYS") == 0){ /*LIST KEYS*/ cmd_list_keys(); }else if(strcmp(command, "ENTRIES") == 0){ /*LIST ENTRIES*/ cmd_list_entries(); }else if(strcmp(command, "SNAPSHOTS") == 0){ /*LIST SNAPSHOTS*/ cmd_list_snapshots(); } }else if(strcmp(command, "GET") == 0){ /*GET*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_get(key); }else if(strcmp(command, "DEL") == 0){ /*DEL*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_del(key); }else if(strcmp(command, "PURGE") == 0){ /*PURGE*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_purge(key); }else if(strcmp(command, "SET") == 0){ /*SET*/ int i = 0; char key[MAX_KEY_LENGTH]; char *endptr; int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int)); sscanf(buffer + strlen(command), "%s", (char*)&key); endptr = buffer + strlen(command) + strlen(key) + 2; while(1){ values[i] = strtol(endptr, &endptr, 10); if(*endptr == '\n'){ cmd_set(key, values, i+1); break; } i++; } free(values); }else if(strcmp(command, "PUSH") == 0){ /*PUSH*/ int i = 0; char key[MAX_KEY_LENGTH]; char *endptr; int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int)); sscanf(buffer + strlen(command), "%s", (char*)&key); endptr = buffer + strlen(command) + strlen(key) + 2; while(1){ values[i] = strtol(endptr, &endptr, 10); if(*endptr == '\n'){ cmd_push(key, values, i+1); break; } i++; } free(values); }else if(strcmp(command, "APPEND") == 0){ /*APPEND*/ int i = 0; char key[MAX_KEY_LENGTH]; char *endptr; int *values = (int*)malloc(MAX_LINE_LENGTH/2*sizeof(int)); sscanf(buffer + strlen(command), "%s", (char*)&key); endptr = buffer + strlen(command) + strlen(key) + 2; while(1){ values[i] = strtol(endptr, &endptr, 10); if(*endptr == '\n'){ cmd_append(key, values, i+1); break; } i++; } free(values); }else if(strcmp(command, "PICK") == 0){ /*PICK*/ char key[MAX_KEY_LENGTH]; int index; sscanf(buffer + strlen(command)+1, "%s", (char*)&key); index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0); cmd_pick(key, index); }else if(strcmp(command, "PLUCK") == 0){ /*PLUCK*/ char key[MAX_KEY_LENGTH]; int index; sscanf(buffer + strlen(command)+1, "%s", (char*)&key); index = strtol(buffer + strlen(command) + strlen(key)+2, (char**)&command, 0); cmd_pluck(key, index); }else if(strcmp(command, "POP") == 0){ /*POP*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_pop(key); }else if(strcmp(command, "DROP") == 0){ /*DROP*/ int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10); cmd_drop(id); }else if(strcmp(command, "ROLLBACK") == 0){ /*ROLLBACK*/ int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10); cmd_rollback(id); }else if(strcmp(command, "CHECKOUT") == 0){ /*CHECKOUT*/ int id = strtol(buffer + strlen(command) +1 , (char**)&command, 10); cmd_checkout(id); }else if(strcmp(command, "SNAPSHOT") == 0){ /*SNAPSHOT*/ cmd_snapshot(); }else if(strcmp(command, "MIN") == 0){ /*MIN*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_min(key); }else if(strcmp(command, "MAX") == 0){ /*MAX*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_max(key); }else if(strcmp(command, "SUM") == 0){ /*SUM*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_sum(key); }else if(strcmp(command, "LEN") == 0){ /*LEN*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_len(key); }else if(strcmp(command, "REV") == 0){ /*REV*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_rev(key); }else if(strcmp(command, "UNIQ") == 0){ /*UNIQ*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_uniq(key); }else if(strcmp(command, "SORT") == 0){ /*SORT*/ char key[MAX_KEY_LENGTH]; sscanf(buffer + strlen(command), "%s", (char*)&key); cmd_sort(key); }else{ printf("\n"); } } return 0; }
static int main_cmd(int argc, char *argv[]) { if (argc < 1) { return help(); } char *cmd = *argv++; argc--; if (contains(cmd, "key")) { if (argc < 2) { return help(); } uint32_t lockkey = strtoul(argv[0], NULL, 0); hdhomerun_device_tuner_lockkey_use_value(hd, lockkey); cmd = argv[1]; argv+=2; argc-=2; } if (contains(cmd, "get")) { if (argc < 1) { return help(); } return cmd_get(argv[0]); } if (contains(cmd, "set")) { if (argc < 2) { return help(); } return cmd_set(argv[0], argv[1]); } if (contains(cmd, "scan")) { if (argc < 1) { return help(); } if (argc < 2) { return cmd_scan(argv[0], NULL); } else { return cmd_scan(argv[0], argv[1]); } } if (contains(cmd, "save")) { if (argc < 2) { return help(); } return cmd_save(argv[0], argv[1]); } if (contains(cmd, "upgrade")) { if (argc < 1) { return help(); } return cmd_upgrade(argv[0]); } if (contains(cmd, "execute")) { return cmd_execute(); } return help(); }
int main (int argc, char *argv[]) { flux_t h; int ch; char *cmd; log_init ("flux-kvs"); while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'h': /* --help */ usage (); break; default: usage (); break; } } if (optind == argc) usage (); cmd = argv[optind++]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (!strcmp (cmd, "get")) cmd_get (h, argc - optind, argv + optind); else if (!strcmp (cmd, "type")) cmd_type (h, argc - optind, argv + optind); else if (!strcmp (cmd, "put")) cmd_put (h, argc - optind, argv + optind); else if (!strcmp (cmd, "unlink")) cmd_unlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "link")) cmd_link (h, argc - optind, argv + optind); else if (!strcmp (cmd, "readlink")) cmd_readlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "mkdir")) cmd_mkdir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "exists")) cmd_exists (h, argc - optind, argv + optind); else if (!strcmp (cmd, "version")) cmd_version (h, argc - optind, argv + optind); else if (!strcmp (cmd, "wait")) cmd_wait (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch")) cmd_watch (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch-dir")) cmd_watch_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache")) cmd_dropcache (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache-all")) cmd_dropcache_all (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-tokvs")) cmd_copy_tokvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-fromkvs")) cmd_copy_fromkvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dir")) cmd_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dirsize")) cmd_dirsize (h, argc - optind, argv + optind); else usage (); flux_close (h); log_fini (); return 0; }
void _print_str(cmdObj_t *cmd) { cmd_get(cmd); char format[CMD_FORMAT_LEN+1]; fprintf(stderr, _get_format(cmd->index, format), *cmd->stringp); }
void _print_dbl(cmdObj_t *cmd) { cmd_get(cmd); char format[CMD_FORMAT_LEN+1]; fprintf(stderr, _get_format(cmd->index, format), cmd->value); }
int execute(unsigned int uid){ return execute(cmd_get(uid)); }
/* * Hack -- main Angband initialization entry point * * Verify some files, display the "news.txt" file, create * the high score file, initialize all internal arrays, and * load the basic "user pref files". * * Be very careful to keep track of the order in which things * are initialized, in particular, the only thing *known* to * be available when this function is called is the "z-term.c" * package, and that may not be fully initialized until the * end of this function, when the default "user pref files" * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called. * * Note that this function attempts to verify the "news" file, * and the game aborts (cleanly) on failure, since without the * "news" file, it is likely that the "lib" folder has not been * correctly located. Otherwise, the news file is displayed for * the user. * * Note that this function attempts to verify (or create) the * "high score" file, and the game aborts (cleanly) on failure, * since one of the most common "extraction" failures involves * failing to extract all sub-directories (even empty ones), such * as by failing to use the "-d" option of "pkunzip", or failing * to use the "save empty directories" option with "Compact Pro". * This error will often be caught by the "high score" creation * code below, since the "lib/apex" directory, being empty in the * standard distributions, is most likely to be "lost", making it * impossible to create the high score file. * * Note that various things are initialized by this function, * including everything that was once done by "init_some_arrays". * * This initialization involves the parsing of special files * in the "lib/data" and sometimes the "lib/edit" directories. * * Note that the "template" files are initialized first, since they * often contain errors. This means that macros and message recall * and things like that are not available until after they are done. * * We load the default "user pref files" here in case any "color" * changes are needed before character creation. * * Note that the "graf-xxx.prf" file must be loaded separately, * if needed, in the first (?) pass through "TERM_XTRA_REACT". */ bool init_angband(void) { event_signal(EVENT_ENTER_INIT); /* Initialize the menus */ /* This must occur before preference files are read(?) */ init_cmd4_c(); /*** Initialize some arrays ***/ /* Initialize size info */ event_signal_string(EVENT_INITSTATUS, "Initializing array sizes..."); if (init_z_info()) quit("Cannot initialize sizes"); /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (features)"); if (init_f_info()) quit("Cannot initialize features"); /* Initialize object info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (objects)"); if (init_k_info()) quit("Cannot initialize objects"); /* Initialize ego-item info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (ego-items)"); if (init_e_info()) quit("Cannot initialize ego-items"); /* Initialize monster info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (monsters)"); if (init_r_info()) quit("Cannot initialize monsters"); /* Initialize artifact info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (artifacts)"); if (init_a_info()) quit("Cannot initialize artifacts"); /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (vaults)"); if (init_v_info()) quit("Cannot initialize vaults"); /* Initialize history info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (histories)"); if (init_h_info()) quit("Cannot initialize histories"); /* Initialize race info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (races)"); if (init_p_info()) quit("Cannot initialize races"); /* Initialize class info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (classes)"); if (init_c_info()) quit("Cannot initialize classes"); /* Initialize owner info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (owners)"); if (init_b_info()) quit("Cannot initialize owners"); /* Initialize flavor info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (flavors)"); if (init_flavor_info()) quit("Cannot initialize flavors"); /* Initialize spell info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (spells)"); if (init_s_info()) quit("Cannot initialize spells"); /* Initialize spellbook info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (spellbooks)"); init_books(); /* Initialise store stocking data */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (store stocks)"); init_stores(); /* Initialise random name data */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (random names)"); init_names(); /* Initialize some other arrays */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (other)"); if (init_other()) quit("Cannot initialize other stuff"); /* Initialize some other arrays */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (alloc)"); if (init_alloc()) quit("Cannot initialize alloc stuff"); /*** Load default user pref files ***/ /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Loading basic user pref file..."); /* Process that file */ (void)process_pref_file("pref.prf"); /* Done */ event_signal_string(EVENT_INITSTATUS, "Initialization complete"); /* Sneakily init command list */ cmd_init(); /* Ask for a "command" until we get one we like. */ while (1) { game_command command_req; cmd_get(CMD_INIT, &command_req, TRUE); if (command_req.command == CMD_QUIT) { quit(NULL); } else if (command_req.command == CMD_NEWGAME) { event_signal(EVENT_LEAVE_INIT); return TRUE; } else if (command_req.command == CMD_LOADFILE) { event_signal(EVENT_LEAVE_INIT); /* In future we might want to pass back or set the savefile path here. */ return FALSE; } } }
/* * Hack -- main Angband initialization entry point * * Verify some files, display the "news.txt" file, create * the high score file, initialize all internal arrays, and * load the basic "user pref files". * * Be very careful to keep track of the order in which things * are initialized, in particular, the only thing *known* to * be available when this function is called is the "z-term.c" * package, and that may not be fully initialized until the * end of this function, when the default "user pref files" * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called. * * Note that this function attempts to verify the "news" file, * and the game aborts (cleanly) on failure, since without the * "news" file, it is likely that the "lib" folder has not been * correctly located. Otherwise, the news file is displayed for * the user. * * Note that this function attempts to verify (or create) the * "high score" file, and the game aborts (cleanly) on failure, * since one of the most common "extraction" failures involves * failing to extract all sub-directories (even empty ones), such * as by failing to use the "-d" option of "pkunzip", or failing * to use the "save empty directories" option with "Compact Pro". * This error will often be caught by the "high score" creation * code below, since the "lib/apex" directory, being empty in the * standard distributions, is most likely to be "lost", making it * impossible to create the high score file. * * Note that various things are initialized by this function, * including everything that was once done by "init_some_arrays". * * This initialization involves the parsing of special files * in the "lib/data" and sometimes the "lib/edit" directories. * * Note that the "template" files are initialized first, since they * often contain errors. This means that macros and message recall * and things like that are not available until after they are done. * * We load the default "user pref files" here in case any "color" * changes are needed before character creation. * * Note that the "graf-xxx.prf" file must be loaded separately, * if needed, in the first (?) pass through "TERM_XTRA_REACT". */ bool init_angband(void) { /* If we have a savefile, use that for game mode instead */ if (savefile[0]) { load_gamemode(); } /* Which game are we playing? */ if (game_mode == 0) { get_game_mode(); } event_signal(EVENT_ENTER_INIT); /*** Initialize some arrays ***/ /* Initialize size info */ event_signal_string(EVENT_INITSTATUS, "Initializing array sizes..."); if (init_z_info()) quit("Cannot initialize sizes"); /* Prepare some things according to the game being played */ init_game_mode(); /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (features)"); if (init_f_info()) quit("Cannot initialize features"); /* Initialize object info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (objects)"); if (init_k_info()) quit("Cannot initialize objects"); /* Initialize object info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (ghosts)"); if (init_t_info()) quit("Cannot initialize ghosts"); /* Initialize artifact info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (artifacts)"); if (init_a_info()) quit("Cannot initialize artifacts"); /* Initialize ego-item info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (ego-items)"); if (init_e_info()) quit("Cannot initialize ego-items"); /* Initialize monster info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (monsters)"); if (init_r_info()) quit("Cannot initialize monsters"); /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (vaults)"); if (init_v_info()) quit("Cannot initialize vaults"); /* Initialize history info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (histories)"); if (init_h_info()) quit("Cannot initialize histories"); /* Initialize race info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (races)"); if (init_p_info()) quit("Cannot initialize races"); /* Initialize class info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (classes)"); if (init_c_info()) quit("Cannot initialize classes"); /* Initialize owner info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (owners)"); if (init_b_info()) quit("Cannot initialize owners"); /* Initialize flavor info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (flavors)"); if (init_flavor_info()) quit("Cannot initialize flavors"); /* Initialize flavor info */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (quests)"); if (init_q_info()) quit("Cannot initialize quests"); /* Initialize some other arrays */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (other)"); if (init_other()) quit("Cannot initialize other stuff"); /* Initialize some other arrays */ event_signal_string(EVENT_INITSTATUS, "Initializing arrays... (alloc)"); if (init_alloc()) quit("Cannot initialize alloc stuff"); /*** Load default user pref files ***/ /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Loading basic user pref file..."); /* Process that file */ (void)process_pref_file("pref.prf"); /* Initialize feature info */ event_signal_string(EVENT_INITSTATUS, "Initializing Random Artifact Tables...]"); if (init_n_info()) quit("Cannot initialize random name generator list"); /*Build the randart probability tables based on the standard Artifact Set*/ build_randart_tables(); /* Done */ event_signal_string(EVENT_INITSTATUS, "Initialization complete"); /* Sneakily init command list */ cmd_init(); /* Ask for a "command" until we get one we like. */ while (1) { game_command command_req; cmd_get(CMD_INIT, &command_req, TRUE); if (command_req.command == CMD_QUIT) { quit(NULL); } else if (command_req.command == CMD_NEWGAME) { event_signal(EVENT_LEAVE_INIT); return TRUE; } else if (command_req.command == CMD_LOADFILE) { event_signal(EVENT_LEAVE_INIT); /* In future we might want to pass back or set the savefile path here. */ return FALSE; } } }
int main(int argc, char **argv) { uint8_t ret[2]; int i; initialize(); send_cmd(devh,CMD_GET_MODEL,ret); printf("Model:"); switch (ret[0]){ case 1: printf("Basic\n"); break; case 2: printf("digIO\n"); break; case 3: printf("watchdog\n"); break; case 4: printf("smart\n"); break; } send_cmd(devh,CMD_GET_FIRM_VER,ret); printf("Firmware version: %d.%d\n",ret[0],ret[1]); send_cmd(devh,CMD_GET_STATE1,ret); state[1] = ret[0]; send_cmd(devh,CMD_GET_STATE2,ret); state[2] = ret[0]; send_cmd(devh,CMD_GET_STATE3,ret); state[3] = ret[0]; for (i=1;i<4;i++){ printf("Outlet%d:",i); switch(state[i]){ case 0: printf("off\n"); break; case 1: printf("on\n"); break; } } if (argc < 2) { usage(); exit(1); } if (!strcmp(argv[1],"get")) { cmd_get(argc,argv); }else if (!strcmp(argv[1],"set")) { Dprintf("set\n"); cmd_set(argc,argv); }else { usage(); exit(1); } finalize(); exit(0); }
void connection::handle_resume(const boost::system::error_code& e, std::size_t bytes_transferred) { if (!e) cmd_get(); }