void operations_with_stack(void) { list_stack_t *stack = malloc(sizeof(list_stack_t)); list_stack_init(stack); command_t command; int n; char *res = NULL; char word[WORD_MAX_LEN]; do { command = get_command(); printf("%d\n", command); switch(command) { case EXIT: break; case PUSH: if (read_line(word, WORD_MAX_LEN)) { if (push(stack, word) != CORRECT_WORK) printf("Stack owerflow\n"); printf("HERE\n"); } else printf("Empty input\n"); break; case POP: res = pop(stack); if (res) printf("pop return - %s\n", res); else printf("Stack is empty\n"); break; case PRINT: print_list_stack(stack); break; case ERROR: printf("Invalid input command\n"); break; } printf("\n"); } while (command != EXIT); clean(stack); free(stack); }
/* YY_GETC -- Called by the modified yylex() "input" macro in the lexical * analysis stage of the parser to get the next character from the input * stream. When EOF is reached on the stream, add the "bye" command to * the logfile. */ int yy_getc ( FILE *fp ) { register char ch; while ((ch = *ip_cmdblk++) == EOS) if (get_command (fp) == EOF) { if (currentask->t_flags & T_INTERACTIVE) if (log_commands()) put_logfile ("bye\n"); return (EOF); } return (ch); }
char *parse_request(char *line, struct response *req, int no_tag) { char *rest = line; req->r_cmd = NUM_COMMANDS; req->r_tag = -1; if (no_tag) req->r_tag = get_global_tag(true); else rest = get_rq_tag(rest, req, true, REQUIRES_MORE); if (rest == NULL) return rest; rest = get_command(rest, &req->r_cmd); if (rest == NULL) return rest; switch (req->r_cmd) { case CMD_OPEN: case CMD_CLOSE: case CMD_LOCKW: case CMD_LOCK: case CMD_UNLOCK: case CMD_TEST: case CMD_LIST: case CMD_HOP: case CMD_UNHOP: case CMD_SEEK: case CMD_READ: case CMD_WRITE: case CMD_HELLO: case CMD_COMMENT: case CMD_ALARM: case CMD_QUIT: rest = parse_functions[req->r_cmd] (rest, req); break; case NUM_COMMANDS: break; } return rest; }
static int socket_send_request(int fd, const struct su_context *ctx) { write_token(fd, "version", PROTO_VERSION); write_token(fd, "binary.version", VERSION_CODE); write_token(fd, "pid", ctx->from.pid); write_string_data(fd, "from.name", ctx->from.name); write_string_data(fd, "to.name", ctx->to.name); write_token(fd, "from.uid", ctx->from.uid); write_token(fd, "to.uid", ctx->to.uid); write_string_data(fd, "from.bin", ctx->from.bin); write_string_data(fd, "bind.from", ctx->bind.from); write_string_data(fd, "bind.to", ctx->bind.to); write_string_data(fd, "init", ctx->init); // TODO: Fix issue where not using -c does not result a in a command write_string_data(fd, "command", get_command(&ctx->to)); write_token(fd, "eof", PROTO_VERSION); return 0; }
void set_storage(istorage& Storage) { g_option_storage = &Storage; // Defines the version of the data stored in the options tree ... incrementing it will force user options to be reset const unsigned long current_version = 4; if(detail::version_element().text.empty() || (boost::lexical_cast<unsigned long>(detail::version_element().text) < current_version)) { log() << warning << "Resetting options data to version " << current_version << std::endl; tree().children.clear(); detail::version_element().text = k3d::string_cast(current_version); } // Default external paths if(detail::path_element(path::render_farm()).text.empty()) detail::path_element(path::render_farm()).text = system::get_temp_directory().native_utf8_string().raw(); if(detail::path_element(path::scripts()).text.empty()) detail::path_element(path::scripts()).text = (share_path() / filesystem::generic_path("scripts")).native_utf8_string().raw(); if(detail::path_element(path::documents()).text.empty()) detail::path_element(path::documents()).text = system::get_home_directory().native_utf8_string().raw(); if(detail::path_element(path::bitmaps()).text.empty()) detail::path_element(path::bitmaps()).text = system::get_home_directory().native_utf8_string().raw(); if(detail::path_element(path::tutorials()).text.empty()) detail::path_element(path::tutorials()).text = system::get_home_directory().native_utf8_string().raw(); if(detail::path_element(path::render_frame()).text.empty()) detail::path_element(path::render_frame()).text = system::get_home_directory().native_utf8_string().raw(); if(detail::path_element(path::render_animation()).text.empty()) detail::path_element(path::render_animation()).text = system::get_home_directory().native_utf8_string().raw(); if(detail::path_element(path::displacement_shaders()).text.empty()) detail::path_element(path::displacement_shaders()).text = (share_path() / filesystem::generic_path("shaders/displacement")).native_utf8_string().raw(); if(detail::path_element(path::imager_shaders()).text.empty()) detail::path_element(path::imager_shaders()).text = (share_path() / filesystem::generic_path("shaders/imager")).native_utf8_string().raw(); if(detail::path_element(path::light_shaders()).text.empty()) detail::path_element(path::light_shaders()).text = (share_path() / filesystem::generic_path("shaders/light")).native_utf8_string().raw(); if(detail::path_element(path::surface_shaders()).text.empty()) detail::path_element(path::surface_shaders()).text = (share_path() / filesystem::generic_path("shaders/surface")).native_utf8_string().raw(); if(detail::path_element(path::transformation_shaders()).text.empty()) detail::path_element(path::transformation_shaders()).text = (share_path() / filesystem::generic_path("shaders/transformation")).native_utf8_string().raw(); if(detail::path_element(path::volume_shaders()).text.empty()) detail::path_element(path::volume_shaders()).text = (share_path() / filesystem::generic_path("shaders/volume")).native_utf8_string().raw(); // Default external commands if(get_command(command::bitmap_viewer()).empty()) set_command(command::bitmap_viewer(), DEFAULT_BITMAP_VIEWER); }
int main(int argc, char** argv){ if (argc <= 1){ fprintf(stderr, "usage: %s [run|dump] <program>, where <program> is a sexp-compiled C file\n", argv[0]); exit(1); } char* file = argv[argc-1]; FILE* prog = fopen(file, "r"); if (!prog){ perror("Couldn't open program"); } char progbuf[MAXFILE]; fread(progbuf, MAXFILE, 1, prog); if (!feof(prog)){ fprintf(stderr, "Couldn't read all of %s", file); exit(1); } struct sexp* sexpcode = sexp_parse(progbuf); if (!sexpcode){ fprintf(stderr, "Couldn't parse s-expressions in %s", file); exit(1); } struct program* program = compile(sexpcode); sexp_free(sexpcode); if (!program){ fprintf(stderr, "Couldn't compile\n"); exit(1); } if (argc == 3){ if (!strcmp(argv[1], "run")){ run(program); }else if (!strcmp(argv[1], "dump")){ program_dump(program); } }else{ while(1){ get_command(); if(parse_command(program)){ break; } } } return 0; }
int main( int argc, char *argv[] ) { EVENT command; if( (argc != 1) && (argc != 2) ) { usage( argv[0] ); } if( argc == 2 ) { StarterPid = (pid_t)atoi( argv[1] ); } else { StarterPid = get_starter_pid( argv[0] ); } while( StarterPid ) { check_starter(); command = get_command(); switch( command ) { case SUSPEND: send_sig( SIGUSR1 ); break; case CONTINUE: send_sig( SIGCONT ); break; case VACATE: send_sig( SIGTSTP ); break; case ALARM: send_sig( SIGALRM ); break; case DIE: send_sig( SIGINT ); break; case CKPT_and_VACATE: send_sig( SIGUSR2 ); break; case NO_EVENT: exit( 0 ); default: printf( "Unknown command (%d)\n", command ); } } return 0; }
int main(int argc, char *argv[]) { int command; get_bee_variables(); if (argc < 2) { usage(); return 1; } lock(); if (atexit(unlock)) { perror("bee-dep: atexit"); return 1; } command = get_command(argv[1]); argv++; argc--; switch (command) { case REBUILD: return bee_dep_rebuild(argc, argv); case UPDATE: return bee_dep_update(argc, argv); case REMOVE: return bee_dep_remove(argc, argv); case LIST: return bee_dep_list(argc, argv); case CONFLICTS: return bee_dep_conflicts(argc, argv); default: usage(); return 1; } return 0; }
static void test_parse_maketemp(CuTest *tc) { char cmd[32]; order *ord; struct locale * lang = get_or_create_locale("en"); locale_setstring(lang, keyword(K_MAKE), "MAKE"); locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP"); locale_setstring(lang, "TEMP", "TEMP"); init_locale(lang); ord = parse_order("MAKET herp", lang); CuAssertPtrNotNull(tc, ord); CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd))); CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord)); CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); CuAssertStrEquals(tc, "herp", getstrtoken()); free_order(ord); }
void exec_multi_command(t_mysh *mysh, char *com) { if (com) { mysh->tab_com = get_command(com); if (comp_str(com, "<<") || comp_str(com, ">>") || comp_str(com, "<") || comp_str(com, ">") || comp_str(com, "|")) { my_putstr("Ambiguous output redirect.\n"); clean_mem(mysh); exit(42); } my_builtins(mysh); exec_command(mysh); } else clean_mem(mysh); }
static void row(void* _proc, void* _table) { struct tabl* table; struct ps_proc* proc; struct m_list values; table = _table; proc = _proc; m_list_init(&values); m_list_append(&values, M_LIST_COPY_SHALLOW, get_pid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_command(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_uid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_ruid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_svuid(proc), 1); tabl_add_row(table, &values); }
static int socket_send_request(int fd, const struct su_context *ctx) { #define write_data(fd, data, data_len) \ do { \ size_t __len = htonl(data_len); \ __len = write((fd), &__len, sizeof(__len)); \ LOGE("%d", __len);\ if (__len != sizeof(__len)) { \ PLOGE("write(" #data ")"); \ return -1; \ } \ __len = write((fd), data, data_len); \ if (__len != data_len) { \ PLOGE("write(" #data ")"); \ return -1; \ } \ } while (0) #define write_string(fd, name, data) \ do { \ write_data(fd, name, strlen(name)); \ write_data(fd, data, strlen(data)); \ } while (0) // stringify everything. #define write_token(fd, name, data) \ do { \ char buf[16]; \ snprintf(buf, sizeof(buf), "%d", data); \ write_string(fd, name, buf); \ } while (0) write_token(fd, "version", PROTO_VERSION); write_token(fd, "binary.version", VERSION_CODE); write_token(fd, "pid", ctx->from.pid); write_string(fd, "from.name", ctx->from.name); write_string(fd, "to.name", ctx->to.name); write_token(fd, "from.uid", ctx->from.uid); write_token(fd, "to.uid", ctx->to.uid); write_string(fd, "from.bin", ctx->from.bin); // TODO: Fix issue where not using -c does not result a in a command write_string(fd, "command", get_command(&ctx->to)); write_token(fd, "eof", PROTO_VERSION); return 0; }
void dispatch_console(void) { static char command[MAX_COMMAND_LENGTH] = {0}; static char init = 0; int length = strlen(command); if(init == 0) { printf_P(PSTR("> ")); init = 1; } if(get_command(command+length, MAX_COMMAND_LENGTH-length) == 0) { execute_command(command, mainMenu); memset(command, 0, sizeof(command)); printf_P(PSTR("> ")); } }
void do_update_dpme(partition_map *entry) { int slice = 0; if (!entry) return; dpme_init_flags(entry->data); entry->HFS_name = get_HFS_name(entry, &entry->HFS_kind); if (istrncmp(entry->data->dpme_type, kUnixType, DPISTRLEN) == 0) { printf("Available partition slices for %s:\n",entry->data->dpme_type); printf(" a root partition\n"); printf(" b swap partition\n"); printf(" c do not set any bzb bits\n"); printf(" g user partition\n"); printf("Other lettered values will create user partitions\n"); get_command("Select a slice for default bzb values: ",0,&slice); } bzb_init_slice((BZB *)entry->data->dpme_bzb,slice); entry->the_map->changed = 1; }
static void test_create_order(CuTest *tc) { char cmd[32]; order *ord; struct locale * lang; test_cleanup(); lang = get_or_create_locale("en"); locale_setstring(lang, "keyword::move", "MOVE"); ord = create_order(K_MOVE, lang, "NORTH"); CuAssertPtrNotNull(tc, ord); CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd))); CuAssertIntEquals(tc, K_MOVE, init_order(ord)); CuAssertStrEquals(tc, "NORTH", getstrtoken()); free_order(ord); test_cleanup(); }
void save(int data_available, char buffer[BF], inventory item[ITM]) { //printf("\tIN OBJ: save <---\n"); int i=0; printf("What would you like to save the file as? (.txt will be added)"); get_command(buffer); strcat(buffer,".txt"); FILE *fp = fopen(buffer, "w"); for( i=0;i<data_available; i++) fprintf(fp,"%s %s %0.0lfC %d %d %s\n", item[i].cat, item[i].name, item[i].cost*100 ,item[i].month,item[i].year,item[i].meta); printf("%s created!\n", buffer); fclose(fp); return; }
/* * help_func -- prints help message for specified command */ static int help_func(char *appname, int argc, char *argv[]) { if (argc > 1) { char *cmd_str = argv[1]; struct command *cmdp = get_command(cmd_str); if (cmdp && cmdp->help) { cmdp->help(appname); return 0; } else { outv_err("No help text for '%s' command\n", cmd_str); return -1; } } else { print_help(appname); return -1; } }
static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma) { struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); struct mlx5_ib_dev *dev = to_mdev(ibcontext->device); struct mlx5_uuar_info *uuari = &context->uuari; unsigned long command; unsigned long idx; phys_addr_t pfn; command = get_command(vma->vm_pgoff); switch (command) { case MLX5_IB_MMAP_REGULAR_PAGE: if (vma->vm_end - vma->vm_start != PAGE_SIZE) return -EINVAL; idx = get_index(vma->vm_pgoff); if (idx >= uuari->num_uars) return -EINVAL; pfn = uar_index2pfn(dev, uuari->uars[idx].index); mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx, (unsigned long long)pfn); vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); if (io_remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, vma->vm_page_prot)) return -EAGAIN; mlx5_ib_dbg(dev, "mapped WC at 0x%lx, PA 0x%llx\n", vma->vm_start, (unsigned long long)pfn << PAGE_SHIFT); break; case MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES: return -ENOSYS; default: return -EINVAL; } return 0; }
bool run_main(PFOOBAR2000_API *p_api, GUID *p_guid) { PMAINMENU_COMMANDS *api=0; int index=0, count, i; GUID m_guid; bool ret; SERVICE_CLASS_REF api_class = find_class(p_api, &mainmenu_commands); while(create(p_api, (PSERVICE_API **)&api, api_class, index)) { for(i=0, count = get_command_count(api); i<count; i++) if(IsEqualGUID(p_guid, get_command(api, &m_guid, i))) {execute(api, i, 0), ret=true; goto ex;} index++; } ret=false; ex: __asm mov ecx, api; (*api)->base.service_release(); return ret; }
/* * Runs the shell */ void start_shell(){ const char *path[] = { "./", "/usr/bin/", "/bin/", NULL }; char buff[PATH_BUFFER_SIZE]; char * cwd; cwd = getcwd(buff,PATH_BUFFER_SIZE); bool running = true; struct CommandBuffer cmb = command_buffer_factory(); while(running){ printf("%s > ",cwd); get_command(&cmb,stdin); running = match_command(&cmb,&cwd,path); } delete_command_buffer(&cmb); printf("Exiting shell\n"); }
bool hotkey_base::bindings_equal(hotkey_ptr other) { bool ret; if (other == hotkey_ptr()) { return false; } hk_scopes scopematch = hotkey::get_hotkey_command(get_command()).scope & hotkey::get_hotkey_command(other->get_command()).scope; if (scopematch.none()) { return false; } ret = mod_ == other->mod_ && bindings_equal_helper(other); return ret; }
t_map *parse_lemin() { t_map *map; char *buffer; int step; t_info info; init_map(&map); step = 0; info.command = 0; while ((buffer = get_next_line(0)) != NULL) { info.type = get_line_type(buffer); info.command = parse_type(info, buffer, &step, map); info.command = get_command(info.command, step, map); free(buffer); } is_valid_map(map); return (map); }
static __attribute__ ((noreturn)) void deny(struct su_context *ctx) { char *cmd = get_command(&ctx->to); int send_to_app = 1; // no need to log if called by root if (ctx->from.uid == AID_ROOT) send_to_app = 0; // dumpstate (which logs to logcat/shell) will spam the crap out of the system with su calls if (strcmp("/system/bin/dumpstate", ctx->from.bin) == 0) send_to_app = 0; if (send_to_app) send_result(ctx, DENY); LOGW("request rejected (%u->%u %s)", ctx->from.uid, ctx->to.uid, cmd); fprintf(stderr, "%s\n", strerror(EACCES)); exit(EXIT_FAILURE); }
void js_sentence(FILE *f) { int par1,par2; T_PARAGRAPH pgf; if (!b_closed || open_level) error("Ocekava se '}' (close_block)"); b_closed=0; get_cislo(f,&par1); get_cislo(f,&par2); sub_mode=par2; pgf.num=par1+basic_num; pgf.alt=par1+basic_num; add_pgf(&pgf); sentence=1; last_pgf=par1; get_command(f,&par1); if (par1!=-2) error ("Ocekava se '{' (open_block)"); sentencs++; was_sub=0; }
void js_dialoge(FILE *f) { int parm1; T_PARAGRAPH pgf; if (!b_closed) error("Ocekava se '}' (close_block)"); get_cislo(f,&parm1); abs_num=basic_num=parm1*128; pgf.num=basic_num; pgf.alt=basic_num; last_dialoge=pgf_count; last_pgf=0; add_pgf(&pgf); get_command(f,&parm1); if (parm1!=-2) error ("Ocekava se '{' (open_block)"); sentence=0; b_closed=0; add_short(167); add_short(basic_num); }
static int interpret_cmd(struct interpreter_context *context, struct gsh_command *node, int flags) { char **args = node->c_args; const char *cmd = args[0]; int argc = 0; int i = 0; while(cmd[i++]) argc++; struct builtin_command *c = get_command(cmd); if(c) { c->interpret(args, argc); return 0; } else { char full_path[64]; int ret = 0; if((ret = attempt_exec(cmd, args, argc, flags)) == -1) { printf("gsh: command not found!\n"); return -1; } return ret; } }
int main(int argc, char *argv[]) { GameState *state = allocate_game_state(); get_configuration(state->config); initilize(state); DEBUG("tile size is %li\n", sizeof(Tile)); char msg1[] = "Welcome to Kookoolegit! You are in an infinitely long " "non-orientable space. Good luck!"; add_message(msg1); render_messages(&state->config->message_window); calculate_visible_tiles(state->map, state->map->at_location); state->status_message = get_player_status(); state->need_to_redraw = 1; INFO("entering main loop\n"); while (state->is_running) { /* This blocks, waiting for the next user input */ INFO("******************************\n"); DEBUG("Getting command\n"); enum CommandCode cmd; cmd = get_command(); process_command(state, cmd); DEBUG("state is %d\n", state->state); DEBUG("Redraw flag is %d\n", state->need_to_redraw); if (state->need_to_redraw == 1) { clear(); render_messages(&state->config->message_window); render_map_window(state->map, state->map_graphics_state, &state->config->map_window); render_look_message(state->status_message, &state->config->status_window); state->need_to_redraw = 0; flip(); } } cleanup(state); return 0; }
/* client packet handler */ void cmd_packet_handler(struct conn_server *server, struct connection *conn, struct list_packet *packet) { uint16_t command = get_command(packet); /* check login status */ if (conn->type != LOGIN_OK_CONNECTION && command != CMD_LOGIN) { /* the client not login, ignore this packet */ allocator_free(&server->packet_allocator, packet); return; } switch (command) { case CMD_KEEP_ALIVE: cmd_keep_alive(server, conn, packet); break; case CMD_LOGIN: cmd_login(server, conn, packet); break; case CMD_LOGOUT: cmd_logout(server, conn, packet); break; case CMD_SET_NICK: cmd_user(server, conn, packet); break; case CMD_ADD_CONTACT: case CMD_ADD_CONTACT_REPLY: case CMD_CONTACT_LIST: case CMD_CONTACT_INFO_MULTI: cmd_contact(server, conn, packet); break; case CMD_MESSAGE: case CMD_OFFLINE_MSG: cmd_message(server, conn, packet); break; default: log_err("unkonwn command %#hx\n", command); break; } }
static int process_commands(struct rtpp_ctrl_sock *csock, struct cfg *cf, int controlfd, double dtime, struct rtpp_command_stats *csp, struct rtpp_stats_obj *rsc, struct rtpp_cmd_rcache_obj *rcp) { int i, rval; struct rtpp_command *cmd; int umode; umode = RTPP_CTRL_ISDG(csock); i = 0; do { cmd = get_command(cf, controlfd, &rval, dtime, csp, umode, rcp); if (cmd == NULL && rval == 0) { /* * get_command() failed with error other than I/O error * or something, there might be some good commands in * the queue. */ continue; } if (cmd != NULL) { cmd->laddr = sstosa(&csock->bindaddr); if (cmd->cca.op == GET_STATS) { flush_cstats(rsc, csp); } if (cmd->no_glock == 0) { pthread_mutex_lock(&cf->glock); } i = handle_command(cf, cmd); if (cmd->no_glock == 0) { pthread_mutex_unlock(&cf->glock); } free_command(cmd); } else { i = -1; } } while (i == 0 && umode != 0); return (i); }
int key_unbind(const char *context, const char *key, int force) { int c; const struct key *k; struct binding *b, *prev; struct command *command; c = find_context(context); if (c < 0) return -1; k = find_key(key); if (k == NULL) return -1; prev = NULL; b = key_bindings[c]; while (b) { if (b->key == k) { if (prev) { prev->next = b->next; } else { key_bindings[c] = b->next; } command = get_command(b->cmd); if (command && !--command->bc) help_add_unbound(command); help_remove_bound(b); free(b); return 0; } prev = b; b = b->next; } if (!force) { error_msg("key %s not bound in context %s", key, context); return -1; } return 0; }