int remove_test() { int ret = 0; printf("remove_test: Start\n"); /* * Remove existing file */ printf("\tbegin: Remove existing file(%s)\n", NEW_FILE_PATH_2); if((ret = do_remove(NEW_FILE_PATH_2)) != 0){ goto out; } printf("\tend: Success\n"); /* * Remove non-existing file */ printf("\tbegin: Remove non-existing file(%s)\n", DUMMY_FILE_PATH_1); if((ret = do_remove(DUMMY_FILE_PATH_1)) == 0){ printf("\tNon-existing file was removed without error...\n"); ret = 1; goto out; } ret = 0; printf("\tend: Success\n"); /* * Remove directory */ printf("\tbegin: Remove directory (%s) using unlink\n", NEW_DIR_PATH_1); ret = do_remove(NEW_DIR_PATH_1); switch(ret){ case 0: printf("\tdirectory was removed!!\n"); ret = 1; goto out; case EISDIR: break; default: printf("\terror is not EISDIR, but \"%s\"\n", strerror(ret)); } ret = 0; printf("\tend: Success\n"); out: if (ret) { printf("\tend: Failed\n"); } printf("remove_test: Finish\n"); return ret; }
value_type remove(const key_type & key) { node_type * n = do_find(m_root, key); assert(n != NULL); value_type v = n->value(); m_root = do_remove(m_root, key); return v; }
void recv_request(int newfd) { char buf[2048]; int ret; while(1) { bzero(buf,sizeof(buf)); ret=recv(newfd,buf,sizeof(buf),0); if(ret==0) { break; } if(strncmp("cd",buf,2)==0) { do_cd(newfd,buf); }else if(strncmp("ls",buf,2)==0) { do_ls(newfd,buf); }else if(strncmp("puts",buf,4)==0) { do_puts(newfd); }else if(strncmp("gets",buf,4)==0) { do_gets(newfd,buf); }else if(strncmp("remove",buf,6)==0) { do_remove(newfd,buf); }else if(strncmp("pwd",buf,3)==0) { do_pwd(newfd,buf); }else{ continue; } } }
int main (int argc, char **argv) { if (argc < 2) { g_print (_("Insufficient number of command line arguments.\n")); usage (argc, argv); return 1; } setlocale (LC_ALL, ""); g_type_init (); if (strcmp (argv[1], "dump") == 0) { return do_dump (argc, argv); } if (strcmp (argv[1], "add") == 0) { return do_add (argc, argv); } if (strcmp (argv[1], "list") == 0) { return do_list (argc, argv); } if (strcmp (argv[1], "remove") == 0) { return do_remove (argc, argv); } g_print (_("Unknown command '%s'\n"), argv[1]); usage (argc, argv); return 1; }
static void *centerMain(void *arg) { int cnt; processlist = NULL; // processlist = empty cnt = 99999; // cnt = expired do_reload(0); // reload speadsheat while(1) { if(toCenter.poll() == rlFifo::DATA_AVAILABLE) { toCenter.read(interpreter.line,rl_PRINTF_LENGTH-1); if (interpreter.isCommand("sigterm(")) do_sigterm(); else if(interpreter.isCommand("sigkill(")) do_sigkill(); else if(interpreter.isCommand("reload(")) do_reload(1); else if(interpreter.isCommand("remove(")) do_remove(); else if(interpreter.isCommand("save(")) do_save(); if(processes_have_been_modified) do_save(); } else if(cnt++ >= WATCHDOG_CYCLE_TIME) { cnt = 0; watchdog(); if(processes_have_been_modified) do_save(); } else { rlsleep(1000); // 1 second } if(arg == NULL) return NULL; // just to fool the compiler } }
void HTMLButcherListEditDialog::OnRemove(wxCommandEvent& event) { wxListBox *lb = (wxListBox*) FindWindow(ID_ITEMS); if (lb->GetSelection() != wxNOT_FOUND) { do_remove(static_cast<ButcherListIdClientData*>(lb->GetClientObject(lb->GetSelection()))->GetId()); } }
int main(object me, string arg) { object ob, *inv; int i; if( !arg ) return notify_fail("你要脱掉什麽?\n"); if(arg=="all") { inv = all_inventory(me); for(i=0; i<sizeof(inv); i++) do_remove(me, inv[i]); write("Ok.\n"); return 1; } if( !objectp(ob = present(arg, me)) ) return notify_fail("你身上没有这样东西。\n"); return do_remove(me, ob); }
/** * Remove element. * * Removes the first element in the vector that compares equal to val. * All iterators may become invalidated if this method returns true. * * @param val Value to be compared. * * @return true if an element was removed, false otherwise. */ bool remove(const value_type& val) { iterator it = std::find(collection_.begin(), collection_.end(), val); if (it != collection_.end()) { do_remove(it); return true; } return false; }
bool remove_if(UnaryPredicate pred) { iterator it = std::find_if(collection_.begin(), collection_.end(), pred); if (it != collection_.end()) { do_remove(it); return true; } return false; }
/* Remove text nodes from @first up to, and including @last. */ void remove_text_list(struct dynstr *first, struct dynstr *last) { struct dynstr *nullstr = newdynstr(NULL, 0); insert_text_list(first, nullstr, nullstr); do_remove(first, last, nullstr, nullstr); if (list_empty(&nullstr->node_first) && list_empty(&nullstr->node_last)) dynstr_del(nullstr); }
int main(object me, string arg) { object ob, *inv; int i; if( !arg ) return notify_fail("你要脱掉什么?\n"); if ( time() - me->query_temp("last_time/wear") < 5 ) return notify_fail("急什么?慢慢来。\n"); if(arg=="all") { inv = all_inventory(me); for(i=0; i<sizeof(inv); i++) do_remove(me, inv[i]); write("Ok.\n"); return 1; } if( !objectp(ob = present(arg, me)) ) return notify_fail("你身上没有这样东西。\n"); return do_remove(me, ob); }
int main(int argc, char const* argv[]) { char line[MAX_LENGTH]; int start, n; while (n = read_line(line, MAX_LENGTH)) { if (do_remove(line) > 0) { printf("%s", line); } } return 0; }
items::items(editor_resource_ptr res, QWidget* parent) : QFrame(parent) , resource_(res) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QGridLayout* l = new QGridLayout(this); l->setContentsMargins(0, 0, 0, 0); // Tablewidget data_ = new QTableWidget(this); data_->setColumnCount(3); data_->setHorizontalHeaderLabels(QStringList() << "Filename" << "Type" << "?"); data_->setColumnWidth(0, 100); data_->setColumnWidth(1, 75); data_->setColumnWidth(2, 20); data_->verticalHeader()->setVisible(false); data_->setEditTriggers(QTableWidget::NoEditTriggers); data_->setSelectionMode(QTableWidget::SingleSelection); data_->setSelectionBehavior(QTableWidget::SelectRows); data_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); l->addWidget(data_, 0, 0, 1, 2); // Buttons QPushButton* btn_edit = new QPushButton("Edit", this); btn_edit->setMaximumWidth(80); l->addWidget(btn_edit, 2, 0, Qt::AlignCenter); connect(btn_edit, SIGNAL(clicked()), SLOT(do_edit())); QPushButton* btn_add = new QPushButton("Add", this); btn_add->setMaximumWidth(80); l->addWidget(btn_add, 1, 0, Qt::AlignCenter); connect(btn_add, SIGNAL(clicked()), SLOT(do_add())); QPushButton* btn_remove = new QPushButton("Remove", this); btn_remove->setMaximumWidth(80); l->addWidget(btn_remove, 1, 1, Qt::AlignCenter); connect(btn_remove, SIGNAL(clicked()), SLOT(do_remove())); QPushButton* btn_generate = new QPushButton("Generate", this); btn_generate->setMaximumWidth(80); l->addWidget(btn_generate, 2, 1, Qt::AlignCenter); connect(btn_generate, SIGNAL(clicked()), SLOT(do_generate())); connect(resource_.data(), SIGNAL(sig_resource_updated()), SLOT(do_update())); do_update(); }
int main (int argc, char *argv[]) { if (argc < 2) { print_doc(argv[0]); return EINVAL; } if (strncmp(argv[1],"put",3) == 0) { if (argc < 4) { print_doc(argv[0]); return EINVAL; } const char *key = argv[2]; const char *src = argv[3]; return do_put(key, src); } else if (strncmp(argv[1], "get", 3) == 0) { if (argc < 4) { print_doc(argv[0]); return EINVAL; } const char *key = argv[2]; const char *outpath = argv[3]; return do_get(key, outpath); } else if (strncmp(argv[1], "remove", 6) == 0) { if (argc < 3) { print_doc(argv[0]); return EINVAL; } const char *key = argv[2]; return do_remove(key); } else if (strncmp(argv[1], "search", 6) == 0) { if (argc < 4) { print_doc(argv[0]); return EINVAL; } const char *key = argv[2]; const char *outpath = argv[3]; return do_search(key, outpath); } else if (strncmp(argv[1], "stat", 4) == 0) { if (argc < 3) { print_doc(argv[0]); return EINVAL; } const char *key = argv[2]; return do_stat(key); } else { print_doc(argv[0]); return EINVAL; } return 0; }
node_type * do_remove( node_type * r, const key_type & k) { if(r == NULL) { return NULL; } else if(k < r->key()) { r->left() = do_remove(r->left(), k); return r; } else if(k > r->key()) { r->right() = do_remove(r->right(), k); return r; } // k == r->key() --> remove this node // First check for simple cases where at most // one of the children is non-NULL if(r->left() == NULL) { node_type * tmp = r->right(); delete r; --m_size; return tmp; } else if(r->right() == NULL) { node_type * tmp = r->left(); delete r; --m_size; return tmp; } // Both children are non-NULL node_type * n = do_get_min(r->right()); r->value() = n->value(); r->key() = n->key(); r->right() = do_delete_min(r->right()); delete n; --m_size; return r; }
static void job_proc(void) { struct ipc_struct ipc; struct pack *p; struct ProcChild *sender; char *t, *s; int cmd; size_t size; p = pack_new(256); while (1) { if (1 == proc_listen(&sender, &cmd, &size, 1)) break; } proc_get(sender, &ipc, p, size); bk_channel = ipc.source; switch (cmd) { case CMD_REGISTER: pack_get(p, &t, NULL); pack_get(p, &s, NULL); do_register(ipc.node, t, s); break; case CMD_REMOVE: pack_get(p, &t, NULL); do_remove(t); break; case CMD_CALL: do_call(ipc.node, p); break; case CMD_CALL_PACKAGE: pack_get(p, &t, NULL); do_call_package(ipc.node, t, p); break; case CMD_GETLIST: do_getlist(ipc.node); break; case CMD_DUMP_PROFILE: do_dump_profile(); break; case CMD_EVENT: pack_get(p, &t, NULL); pack_get(p, &s, NULL); do_event(t, ipc.node, s, p); break; } }
void client_handle(psession_t ps) { socket_t fd_client = ps -> sess_sfd ; int cmd_len = 0 ; int recv_ret ; while(1 ) { bzero(ps -> sess_buf, BUF_SIZE); recv_ret = recv(fd_client, &cmd_len, sizeof(int),0); if(cmd_len == 0 || recv_ret == 0) { printf("client exit !\n"); close(ps ->sess_sfd); free(ps); exit(1); } recvn(fd_client, ps->sess_buf, cmd_len); if(strncmp("cd", ps ->sess_buf, 2) == 0) { do_cd(ps); }else if(strncmp("ls", ps ->sess_buf, 2) == 0) { do_ls(ps); }else if( strncmp("puts", ps ->sess_buf, 4)== 0) { do_puts(ps); }else if( strncmp("gets", ps ->sess_buf, 4)== 0) { do_gets(ps); }else if( strncmp("remove", ps ->sess_buf, 6)== 0) { do_remove(ps); }else if(strncmp("pwd", ps ->sess_buf, 3) == 0) { do_pwd(ps); }else { continue ; } } }
ListNode *do_remove(ListNode *head, int n, int& i) { if (head == nullptr) { i = 0; return head; } head->next = do_remove(head->next, n, i); ++i; if (i == n) { ListNode *tmp = head->next; free(head); return tmp; } return head; }
static void job_proc(void) { struct ProcChild *sender; char *t, *s; int cmd; size_t size; while (1) { if (1 == proc_listen(&sender, &cmd, &size, 1)) break; } ipc_recv(sender, size); chan = ipc_get_data(); chan_id = ipc_get_id(); switch (cmd) { case CMD_REGISTER: ipc_get_arg(&t, NULL); ipc_get_arg(&s, NULL); do_register(ipc_get_node(), t, s); break; case CMD_REMOVE: ipc_get_arg(&t, NULL); do_remove(t); break; case CMD_CALL: do_call(ipc_get_node()); break; case CMD_CALL_PACKAGE: ipc_get_arg(&t, NULL); do_call_package(ipc_get_node(), t); break; case CMD_GETLIST: do_getlist(ipc_get_node()); break; case CMD_DUMP_PROFILE: do_dump_profile(); break; } }
int drslot_chrp_pci(struct options *opts) { int rc; struct dr_node *all_nodes; all_nodes = get_hp_nodes(); if (all_nodes == NULL) { say(ERROR, "There are no PCI hot plug slots on this system.\n"); return -1; } #ifdef DBG_HOT_PLUG print_slots_list(all_nodes); #endif if (!opts->usr_drc_name) opts->usr_drc_name = find_drc_name(opts->usr_drc_index, all_nodes); switch (opts->action) { case ADD: rc = do_add(opts, all_nodes); break; case REMOVE: rc = do_remove(opts, all_nodes); break; case REPLACE: rc = do_replace(opts, all_nodes); break; case IDENTIFY: rc = do_identify(opts, all_nodes); break; default: say(ERROR, "Invalid operation specified!\n"); rc = -1; break; } free_node(all_nodes); return rc; }
void replace_text_list(struct dynstr *oldfirst, struct dynstr *oldlast, struct dynstr *newfirst, struct dynstr *newlast) { struct dynstr *ds, *next; if (oldfirst->cpp_cond != oldlast->cpp_cond) { fputs("Replacing CPP conditionals not supported\n", stderr); exit(1); } next = next_dynstr(newlast); ds = newfirst; do { ds->cpp_cond = oldfirst->cpp_cond; ds = next_dynstr(ds); } while (ds != next); insert_text_list(oldfirst, newfirst, newlast); do_remove(oldfirst, oldlast, newfirst, newlast); }
int main(int argc, char** argv) { string_map* parameters = parse_parameters(argc, argv); opkg_conf *conf = load_conf((char*)get_string_map_element(parameters, "config")); char* run_type = get_string_map_element(parameters, "run-type"); int force_overwrite_other_files = get_string_map_element(parameters, "force-overwrite") != NULL ? 1 : 0; int force_overwrite_configs = get_string_map_element(parameters, "force-overwrite-configs") != NULL ? 1 : 0; int force_depends = get_string_map_element(parameters, "force-depends") != NULL ? 1 : 0; int force_reinstall = get_string_map_element(parameters, "force-reinstall") != NULL ? 1 : 0; int remove_orphaned_depends = get_string_map_element(parameters, "autoremove") != NULL ? REMOVE_ALL_ORPHANED_DEPENDENCIES : REMOVE_NO_ORPHANED_DEPENDENCIES; remove_orphaned_depends = get_string_map_element(parameters, "autoremove-same-destination") != NULL ? REMOVE_ORPHANED_DEPENDENCIES_IN_SAME_DEST : remove_orphaned_depends; char* install_root = get_string_map_element(parameters, "install-destination"); install_root = install_root == NULL ? strdup("root") : install_root; char* link_root = get_string_map_element(parameters, "link-destination"); char* tmp_root = get_string_map_element(parameters, "tmp_dir"); tmp_root = tmp_root == NULL ? strdup("/tmp") : tmp_root; string_map* pkgs = get_string_map_element(parameters, "package-list"); char* format_str = get_string_map_element(parameters, "output-format"); int format = OUTPUT_HUMAN_READABLE; if(format_str != NULL) { format = strcmp(format_str, "json") == 0 ? OUTPUT_JSON : format; format = strcmp(format_str, "js") == 0 || strcmp(format_str, "javascript") == 0 ? OUTPUT_JAVASCRIPT : format; } if(strcmp(run_type, "install") == 0) { do_install(conf, pkgs, install_root, link_root, 0, force_overwrite_configs, force_overwrite_other_files, force_reinstall, tmp_root); } else if(strcmp(run_type, "remove") == 0) { do_remove(conf, pkgs, !force_overwrite_configs, remove_orphaned_depends, force_depends, 1); } else if(strcmp(run_type, "upgrade") == 0) { do_upgrade(conf, pkgs, !force_overwrite_configs, install_root, link_root); } else if(strcmp(run_type, "update") == 0) { update(conf); } else if((strcmp(run_type, "list") == 0) || strcmp(run_type, "list-installed") == 0 || strcmp(run_type, "list_installed") == 0) { do_list(conf, parameters, format); } else if(strcmp(run_type, "dest-info") == 0 || strcmp(run_type, "dest_info") == 0) { do_print_dest_info(conf, format); } else if(strcmp(run_type, "info") == 0) { do_print_info(conf, parameters, install_root, format); } return(0); }
void do_guild (CHAR_DATA * ch, char *argy) { int i; CHAR_DATA *mob; char buf[STD_LENGTH]; char arg1[SML_LENGTH]; DEFINE_COMMAND ("guild", do_guild, POSITION_STANDING, 0, LOG_NORMAL, "This command allows you to perform guild options at a guild house.") if (IS_MOB (ch)) return; argy = one_argy(argy, arg1); if (!str_cmp (arg1, "info") || !str_cmp(arg1, "cost") || !str_cmp(arg1, "costs")) { show_guild_costs(ch, ""); return; } for (mob = ch->in_room->more->people; mob != NULL; mob = mob->next_in_room) { if (IS_MOB (mob) && ( IS_SET (mob->pIndexData->act3, ACT3_TINKER) || IS_SET (mob->pIndexData->act3, ACT3_WARRIOR) || IS_SET (mob->pIndexData->act3, ACT3_HEALER) || IS_SET (mob->pIndexData->act3, ACT3_WIZARD) || IS_SET (mob->pIndexData->act3, ACT3_THIEFG) || IS_SET (mob->pIndexData->act3, ACT3_RANGER) || IS_SET (mob->pIndexData->act3, ACT3_ROGUE) || IS_SET (mob->pIndexData->act3, ACT3_MYSTIC) || IS_SET (mob->pIndexData->act3, ACT3_CONJURER) || IS_SET (mob->pIndexData->act3, ACT3_BATTLEMASTER) || IS_SET (mob->pIndexData->act3, ACT3_NECROMANCER) || IS_SET (mob->pIndexData->act3, ACT3_MONK) ) ) break; } if (mob == NULL) { send_to_char ("There is no guildmaster present here!\n\r", ch); return; } if (arg1[0] == '\0') { send_to_char ("\n\rOptions:\n\r---> Guild leave\n\r---> Guild info\n\r---> Guild join\n\r---> Guild status\n\r", ch); return; } /*end of GUILD INFO */ if (!str_cmp (arg1, "status")) { if (!IS_SET (ch->pcdata->guilds, (mob->pIndexData->act3))) { send_to_char ("You are not a member of our guild!\n\r", ch); return; } send_to_char ("You are an highly respected member of the guild.\n\r", ch); return; } /*end of GUILD STATUS */ if (!str_cmp (arg1, "leave")) { if (!is_member (ch, (mob->pIndexData->act3))) { send_to_char ("You aren't even a member!!\n\r", ch); return; } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]--; REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); send_to_char("You are no longer a member of the guild.", ch); player_preset(ch, "Zlughlkheyn"); do_remove(ch, "all"); break; } } } /*end of GUILD LEAVE */ if (!str_cmp(arg1, "replace")) { char arg2[STD_LENGTH]; char arg3[STD_LENGTH]; int oldnum = -1; int newnum = -1; argy = one_argy(argy, arg2); argy = one_argy(argy, arg3); if (arg2[0] == '\0' || arg3[0] == '\0') { send_to_char("Syntax: Guild Replace <old_guild> <new_guild>\n\r", ch); return; } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (!str_cmp(guild_data[i].what_you_type, arg2)) { oldnum = guild_data[i].mob_guildmaster_bit; break; } } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (!str_cmp(guild_data[i].what_you_type, arg3)) { newnum = guild_data[i].mob_guildmaster_bit; break; } } if (oldnum == -1 || newnum == -1) { send_to_char("You need to check those names again. I don't know which guilds you are talking about.\n\r", ch); return; } if (!IS_SET(ch->pcdata->guilds, oldnum)) { send_to_char("You don't have that guild so how do you expect to replace it?\n\r", ch); return; } if (newnum == oldnum) { send_to_char("You are not changing anything!! Get a clue.\n\r", ch); return; } if (!IS_SET(mob->pIndexData->act3, newnum)) { send_to_char("This guildmaster cannot add you. You must find the proper guildmaster for the guild you wish to join.\n\r", ch); return; } if (is_member(ch, newnum)) { send_to_char("You are already a member of that guild!\n\r", ch); return; } if (ch->pcdata->bank < 60000) { send_to_char("You need 60000 coins in the bank for this to be done.\n\r", ch); return; } if(ch->pcdata->warpoints < 100) { send_to_char("You need 100 warpoints for this to be done.\n\r", ch); return; } ch->pcdata->bank -= 60000; ch->pcdata->warpoints -= 100; for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(oldnum, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]--; REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(newnum, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]++; SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see); send_to_char(buf, ch); sprintf (buf, "Welcome to our guild, %s!", NAME (ch)); do_say (mob, buf); player_preset(ch, "Zlughlkheyn"); fix_char(ch); send_to_char("Ok, the guilds have been switched.\n\r", ch); return; } if (!str_cmp (arg1, "join")) { int num = get_num_guilds(ch); int remorts = pow.guild_info[num][0]; int lvl = pow.guild_info[num][1]; int cst = (pow.guild_info[num][2] * 100); int wps = pow.guild_info[num][3]; int kps = pow.guild_info[num][4]; bool can_join = TRUE; if (IS_SET (ch->pcdata->guilds, mob->pIndexData->act3 )) { send_to_char ("You are already a member of our guild!\n\r", ch); return; } if (ch->pcdata->remort_times < remorts) { sprintf (buf, "You need to have at least %d remorts to join this guild!\n\r", remorts); send_to_char (buf, ch); can_join = FALSE; } // Commented out because i replaced it with the code below. /* if (LEVEL (ch) < lvl) { sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl); send_to_char (buf, ch); can_join = FALSE; }*/ //Added so if the player has a remort that they can join even if they don't meet the level req. //Sabelis 1-18-2006 if ((LEVEL (ch) >lvl) || (ch->pcdata->remort_times>0)) { can_join = TRUE; } else if (LEVEL (ch) < lvl) { sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl); send_to_char (buf, ch); can_join = FALSE; } if (tally_coins (ch) < cst) { sprintf (buf, "We need a payment of %d coins before we can let you join.\n\r", cst); send_to_char (buf, ch); can_join = FALSE; } if (ch->pcdata->warpoints < wps) { sprintf (buf, "You need to have at least %d warpoints to join this guild!\n\r", wps); send_to_char (buf, ch); can_join = FALSE; } if (ch->pcdata->killpoints < kps) { sprintf (buf, "You need to have at least %d killpoints to join this guild!\n\r", kps); send_to_char (buf, ch); can_join = FALSE; } if (!can_join) return; ch->pcdata->warpoints -= wps; ch->pcdata->killpoints -= kps; sub_coins (cst, ch); for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++) { if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit)) { ch->pcdata->stat[guild_data[i].stat_modified]++; SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit); break; } } sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see); send_to_char(buf, ch); sprintf (buf, "Welcome to our guild, %s!", NAME (ch)); do_say (mob, buf); } return; }
PHP_COUCHBASE_LOCAL void php_couchbase_remove_impl(INTERNAL_FUNCTION_PARAMETERS, int oo) { char *key; char *cas = NULL; long klen = 0; long cas_len = 0; long replicate_to = 0; long persist_to = 0; lcb_cas_t cas_v = 0; php_couchbase_res *couchbase_res; lcb_error_t retval; php_couchbase_ctx *ctx; char errmsg[256]; int arg = (oo) ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL; PHP_COUCHBASE_GET_PARAMS(couchbase_res, arg, "s|sll", &key, &klen, &cas, &cas_len, &persist_to, &replicate_to); if (klen == 0) { couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_illegal_key_exception, "No key specified: Empty key"); return ; } if (validate_simple_observe_clause(couchbase_res->handle, persist_to, replicate_to TSRMLS_CC) == -1) { /* Exception already thrown */ return; } if (cas_len > 0) { char *e; cas_v = (lcb_cas_t)strtoull(cas, &e, 10); if (*e != '\0') { couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_illegal_key_exception, "Invalid CAS specified"); return; } } retval = do_remove(couchbase_res->handle, key, klen, &cas_v); couchbase_res->rc = retval; switch (retval) { case LCB_SUCCESS: Z_TYPE_P(return_value) = IS_STRING; Z_STRLEN_P(return_value) = spprintf(&(Z_STRVAL_P(return_value)), 0, "%llu", cas_v); break; case LCB_KEY_ENOENT: RETURN_FALSE; /* NOTREACHED */ case LCB_KEY_EEXISTS: if (oo) { couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_key_mutated_exception, "Failed to remove the value from the server: %s", lcb_strerror(couchbase_res->handle, retval)); return ; } else { RETURN_FALSE; } default: couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_lcb_exception, "Failed to remove the value from the server: %s", lcb_strerror(couchbase_res->handle, retval)); return ; } if (retval == LCB_SUCCESS && (persist_to > 0 || replicate_to > 0)) { /* * If we have a durability spec, after the commands have been * issued (and callbacks returned), try to fulfill that spec by * using polling observe internal (please note that this is * only possible from OO) */ struct observe_entry entry; memset(&entry, 0, sizeof(entry)); entry.key = key; entry.nkey = klen; entry.cas = cas_v; retval = simple_observe(couchbase_res->handle, &entry, 1, persist_to, replicate_to); couchbase_res->rc = retval; if (retval != LCB_SUCCESS) { if (retval == LCB_ETIMEDOUT) { zend_throw_exception(cb_timeout_exception, "Timed out waiting for the objects to persist", 0 TSRMLS_CC); } else { snprintf(errmsg, sizeof(errmsg), "observe failed for: %s", klen, key, lcb_strerror(couchbase_res->handle, retval)); zend_throw_exception(cb_lcb_exception, errmsg, 0 TSRMLS_CC); } } else { /* @todo checkfor timeout!!! */ if (entry.mutated) { zend_throw_exception(cb_key_mutated_exception, "The document was mutated", 0 TSRMLS_CC); } } } }
// clang-format off Expected<Unit, json_patch::patch_application_error> // clang-format on json_patch::apply(dynamic& obj) { using op_code = patch_operation_code; using error_code = patch_application_error_code; using error = patch_application_error; for (auto&& it : enumerate(ops_)) { auto const index = it.index; auto const& op = *it; auto resolved_path = obj.try_get_ptr(op.path); switch (op.op_code) { case op_code::test: if (!resolved_path.hasValue()) { return folly::makeUnexpected( error{error_code::path_not_found, index}); } if (*resolved_path->value != *op.value) { return folly::makeUnexpected(error{error_code::test_failed, index}); } break; case op_code::remove: { auto ret = do_remove(resolved_path); if (ret.hasError()) { return makeUnexpected(error{ret.error(), index}); } break; } case op_code::add: { DCHECK(op.value.hasValue()); auto ret = do_add(resolved_path, *op.value, op.path.tokens().back()); if (ret.hasError()) { return makeUnexpected(error{ret.error(), index}); } break; } case op_code::replace: { if (resolved_path.hasValue()) { *resolved_path->value = *op.value; } else { return folly::makeUnexpected( error{error_code::path_not_found, index}); } break; } case op_code::move: { DCHECK(op.from.hasValue()); auto resolved_from = obj.try_get_ptr(*op.from); if (!resolved_from.hasValue()) { return makeUnexpected(error{error_code::from_not_found, index}); } { auto ret = do_add( resolved_path, *resolved_from->value, op.path.tokens().back()); if (ret.hasError()) { return makeUnexpected(error{ret.error(), index}); } } { auto ret = do_remove(resolved_from); if (ret.hasError()) { return makeUnexpected(error{ret.error(), index}); } } break; } case op_code::copy: { DCHECK(op.from.hasValue()); auto const resolved_from = obj.try_get_ptr(*op.from); if (!resolved_from.hasValue()) { return makeUnexpected(error{error_code::from_not_found, index}); } { DCHECK(!op.path.tokens().empty()); auto ret = do_add( resolved_path, *resolved_from->value, op.path.tokens().back()); if (ret.hasError()) { return makeUnexpected(error{ret.error(), index}); } } break; } case op_code::invalid: { DCHECK(false); return makeUnexpected(error{error_code::other, index}); } } } return unit; }
/** * Creates a veh_interact window based on the given parameters. * @param v The vehicle the player is interacting with. * @param x The x-coordinate of the square the player is 'e'xamining. * @param y The y-coordinate of the square the player is 'e'xamining. */ void veh_interact::exec (game *gm, vehicle *v, int x, int y) { g = gm; veh = v; // x1 x2 // y1 ----+------+-- // | | // y2 ----+------+ // | // | winw1 = 12; winw2 = 35; winh1 = 3; winh2 = 12; winw12 = winw1 + winw2 + 1; winw3 = FULL_SCREEN_WIDTH - winw1 - winw2 - 2; winh3 = FULL_SCREEN_HEIGHT - winh1 - winh2 - 2; winh23 = winh2 + winh3 + 1; winx1 = winw1; winx2 = winw1 + winw2 + 1; winy1 = winh1; winy2 = winh1 + winh2 + 1; // changed FALSE value to 1, to keep w_border from starting at a negative x,y const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 1; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 1; page_size = winh23; // h w y x WINDOW *w_border= newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, -1 + iOffsetY, -1 + iOffsetX); w_grid = newwin(FULL_SCREEN_HEIGHT -2, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX); w_mode = newwin(1, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX); w_msg = newwin(winh1 - 1, FULL_SCREEN_WIDTH-2, 1 + iOffsetY, iOffsetX); w_disp = newwin(winh2-1, winw1, winy1 + 1 + iOffsetY, iOffsetX); w_parts = newwin(winh2-1, winw2, winy1 + 1 + iOffsetY, winx1 + 1 + iOffsetX); w_stats = newwin(winh3-1, winw12, winy2 + iOffsetY, iOffsetX); w_list = newwin(winh23, winw3, winy1 + 1 + iOffsetY, winx2 + 1 + iOffsetX); wborder(w_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwputch(w_border, 16, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, 4, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, 4, FULL_SCREEN_WIDTH-1, c_ltgray, LINE_XOXX); // -| mvwputch(w_border, 24, 49, c_ltgray, LINE_XXOX); wrefresh(w_border); for (int i = 0; i < FULL_SCREEN_HEIGHT; i++) { mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2-1? LINE_XOXX : LINE_XOXO); if (i >= winy1 && i < winy2) { mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } } for (int i = 0; i < FULL_SCREEN_WIDTH; i++) { mvwputch(w_grid, winy1, i, c_ltgray, i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX)); if (i < winx2) { mvwputch(w_grid, winy2-1, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX); } } wrefresh(w_grid); crafting_inv = gm->crafting_inventory(&gm->u); int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use; int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("welder_crude", 1) && crafting_inv.has_charges("welder_crude", charges_crude)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/20)); has_jack = crafting_inv.has_amount("jack", 1); has_siphon = crafting_inv.has_amount("hose", 1); has_wheel = crafting_inv.has_amount( "wheel", 1 ) || crafting_inv.has_amount( "wheel_wide", 1 ) || crafting_inv.has_amount( "wheel_bicycle", 1 ) || crafting_inv.has_amount( "wheel_motorbike", 1 ) || crafting_inv.has_amount( "wheel_small", 1 ); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (dx, dy, ch); if (ch == KEY_ESCAPE || ch == 'q' ) { finish = true; } else { if (dx != -2 && (dx || dy) && cursor_x + dx >= -6 && cursor_x + dx < 6 && cursor_y + dy >= -6 && cursor_y + dy < 6) { move_cursor(dx, dy); } else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; case 's': do_siphon(mval); break; case 'c': do_tirechange(mval); break; case 'd': do_drain(mval); break; } if (sel_cmd != ' ') { finish = true; } display_mode (' '); } } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }
inline bool remove(node_type node, const queue_id_t new_state LOCKING_STAT_FLAG) { MUTEX_LOCK_GUARD_FLAG(mtx, normal_lock, coord_normal_lock); return do_remove(node, new_state); }
//void do_install(opkg_conf* conf, char* pkg_name, char* install_root_name, char* link_root_name, char** version_criteria) void do_install(opkg_conf* conf, string_map* pkgs, char* install_root_name, char* link_root_name, int is_upgrade, int overwrite_config, int overwrite_other_package_files, int force_reinstall, char* tmp_root) { string_map* package_data = initialize_string_map(1); string_map* matching_packages = initialize_string_map(1); string_map* pkgs_from_file = initialize_string_map(1); unsigned long num_destroyed; char* install_root_path = (char*)get_string_map_element(conf->dest_names, install_root_name); char* overlay_path = NULL; // no special treatment of overlay, can be reenabled by setting this variable here if we ever need it char* test_dir = dynamic_strcat(2, (overlay_path != NULL ? overlay_path : install_root_path), "/usr/lib/opkg/info"); if(!create_dir_and_test_writable(test_dir)) { fprintf(stderr, "ERROR: Specified install destination is not writable, exiting\n"); exit(1); } free(test_dir); if(install_root_path == NULL) { printf("ERROR: No destination %s found, cannot install\n\n", install_root_name); exit(1); } char* tmp_dir = (char*)malloc(1024); if(create_tmp_dir(tmp_root == NULL ? "/tmp" : tmp_root, &tmp_dir) != 0) { fprintf(stderr, "ERROR: Could not create tmp dir, exiting\n"); exit(1); } /* Determine all packages to install by first loading all package names, status & dependencies (and no other variables) */ load_all_package_data(conf, package_data, matching_packages, NULL, LOAD_MINIMAL_PKG_VARIABLES_FOR_ALL, install_root_name, 1, NULL ); destroy_string_map(matching_packages, DESTROY_MODE_FREE_VALUES, &num_destroyed); /* determine list of all packiages we are about to install, including dependencies */ string_map* install_pkgs_map = initialize_string_map(1); char** install_pkg_list = NULL; unsigned long install_pkg_list_len = 0; char* unsatisfied_dep_err = NULL; /* new string map var with all pkgs to install = pkgs, keys = version */ unsigned long num_pkg_names; char** pkg_names = get_string_map_keys(pkgs, &num_pkg_names); int pkg_name_index; /* * Load data for any packages being installed via ipk and * determine if any packages we are about to install * provide anything, and if so set package we are installing to preferred */ string_map* preferred_provides = initialize_string_map(1); for(pkg_name_index=0;pkg_name_index < num_pkg_names; pkg_name_index++) { char* pkg_name = pkg_names[pkg_name_index]; char** version_criteria = get_string_map_element(pkgs, pkg_name); char* install_pkg_version = NULL; int install_pkg_is_current; /* deal with case where we're installing from file */ if(path_exists(pkg_name)) { //installing from file char* pkg_file = pkg_name; //extract control files int err = 0; char* tmp_control = dynamic_strcat(2, tmp_dir, "/tmp_ctrl"); char* tmp_control_prefix = dynamic_strcat(2, tmp_control, "/tmp."); char* tmp_control_name = dynamic_strcat(2, tmp_control_prefix, "control"); mkdir_p(tmp_control, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); deb_extract( pkg_file, stderr, extract_control_tar_gz | extract_all_to_fs| extract_preserve_date | extract_unconditional, tmp_control_prefix, NULL, &err); if(err != 0) { fprintf(stderr, "ERROR: %s is not a valid package file, cannot install\n", pkg_file); rm_r(tmp_dir); exit(1); } string_map* tmp_control_pkg_data = initialize_string_map(1); matching_packages = initialize_string_map(1); load_package_data(tmp_control_name, 0, tmp_control_pkg_data, matching_packages, NULL, LOAD_ALL_PKG_VARIABLES, NULL, NULL); unsigned long num_ctrl_names; char** ctrl_name_list = get_string_map_keys(tmp_control_pkg_data, &num_ctrl_names); destroy_string_map(matching_packages, DESTROY_MODE_FREE_VALUES, &num_destroyed); err = 1; //set back to 0 when data successfully loaded if(num_ctrl_names > 0) { int ctrl_name_index; for(ctrl_name_index=0; ctrl_name_list[ctrl_name_index] != NULL; ctrl_name_index++) { if( strcmp(ctrl_name_list[ctrl_name_index], PROVIDES_STRING) != 0) { pkg_name = strdup(ctrl_name_list[ctrl_name_index]); } } char* version = NULL; int is_current; string_map* pkg_info = get_package_current_or_latest(tmp_control_pkg_data, pkg_name, &is_current, &version); if(pkg_info != NULL) { err = 0; set_string_map_element(pkg_info, "Install-File-Location", strdup(pkg_file)); set_string_map_element(pkg_info, "Version", version); //we need to save this, since we are going to set a special version to make sure data doesn't get over-written later, also no need to free version now char* special_version = dynamic_strcat(2, version, "@@_FILE_INSTALL_VERSION_@@"); char** new_version_criteria = malloc(3*sizeof(char*)); new_version_criteria[0] = strdup("="); new_version_criteria[1] = special_version; new_version_criteria[2] = NULL; version_criteria = new_version_criteria; string_map* all_current_versions = get_string_map_element(package_data, pkg_name); if(all_current_versions == NULL) { all_current_versions=initialize_string_map(1); set_string_map_element(package_data, pkg_name, all_current_versions); } set_string_map_element(all_current_versions, special_version, pkg_info); set_string_map_element(all_current_versions, LATEST_VERSION_STRING, special_version); free(pkg_names[pkg_name_index]); pkg_names[pkg_name_index] = strdup(pkg_name); set_string_map_element(pkgs, pkg_name, copy_null_terminated_string_array(new_version_criteria)); set_string_map_element(pkgs_from_file, pkg_name, strdup("D")); } } free_null_terminated_string_array(ctrl_name_list); if(err != 0) { fprintf(stderr, "ERROR: %s is not a valid package file, cannot install\n", pkg_file); rm_r(tmp_dir); exit(1); } free_if_not_null(tmp_control); free_if_not_null(tmp_control_prefix); free_if_not_null(tmp_control_name); rm_r(tmp_control); } /* determine if package provides anything, and set this package to preferred if so*/ string_map* install_pkg_data = get_package_current_or_latest_matching(package_data, pkg_name, version_criteria, &install_pkg_is_current, &install_pkg_version); if(install_pkg_data != NULL) { char* provides_str = get_string_map_element(install_pkg_data, "Provides"); if(provides_str != NULL) { if(strlen(provides_str) > 0) { unsigned long num_provides; char package_separators[] = {' ', ',', ':', ';', '\'', '\"', '\t', '\r', '\n'}; char** provides_list = split_on_separators(provides_str, package_separators, 9, -1, 0, &num_provides); int provides_index; char* provides_unique_key = dynamic_strcat(3, pkg_name, "@", install_pkg_version); for(provides_index=0; provides_index < num_provides; provides_index++) { char* provides_name = strdup(provides_list[provides_index]); char* eq = strchr(provides_name, '='); if(eq != NULL) { *eq = '\0' ; } if(strlen(provides_name) > 0) { set_string_map_element(preferred_provides, provides_name, strdup(provides_unique_key)); } } } } } } /* reload with new preferred_provides */ free_recursive_package_vars(package_data); matching_packages = initialize_string_map(1); load_all_package_data(conf, package_data, matching_packages, NULL, LOAD_MINIMAL_PKG_VARIABLES_FOR_ALL, install_root_name, 1, preferred_provides ); destroy_string_map(matching_packages, DESTROY_MODE_FREE_VALUES, &num_destroyed); /* load data and do sanity checks for packages we are about to install */ for(pkg_name_index=0;pkg_name_index < num_pkg_names; pkg_name_index++) { char* pkg_name = pkg_names[pkg_name_index]; char** version_criteria = get_string_map_element(pkgs, pkg_name); char* install_pkg_version = NULL; int install_pkg_is_current; load_recursive_package_data_variables(package_data, pkg_name, 1, 0, 0); // load required-depends for package of interest only string_map* install_pkg_data = get_package_current_or_latest_matching(package_data, pkg_name, version_criteria, &install_pkg_is_current, &install_pkg_version); char* install_status = install_pkg_data == NULL ? NULL : get_string_map_element(install_pkg_data, "Status"); if(install_status != NULL) { char** old_el = set_string_map_element(install_pkgs_map, pkg_name, copy_null_terminated_string_array(version_criteria) ); if(old_el != NULL){ free_null_terminated_string_array(old_el); } string_map* install_pkg_depend_map = get_string_map_element(install_pkg_data, "Required-Depends"); if(install_pkg_depend_map != NULL) { unsigned long num_keys; char** load_detail_pkgs = get_string_map_keys(install_pkg_depend_map, &num_keys); int ldp_index; for(ldp_index=0;ldp_index < num_keys && unsatisfied_dep_err == NULL; ldp_index++) { char* dep_name = load_detail_pkgs[ldp_index]; char** dep_def= get_string_map_element(install_pkg_depend_map, dep_name); if(get_string_map_element(install_pkgs_map, dep_name) != NULL) { /* * We really should check here whether old dependency def can be reconciled with the new one, and report an error if it can't * Right now we just use the heuristic that top-level (user specified, not dependency) package defs get preference, followed * by first dependency encountered. * * Since right now versioning features aren't really being used very much other than kernel dependencies in Gargoyle/OpenWrt * I'm just leaving this comment here as a reminder that this should be addressed at some point rather than messing with it now * */ dep_def = get_string_map_element(install_pkgs_map, dep_name); } else { set_string_map_element(install_pkgs_map, dep_name, copy_null_terminated_string_array(dep_def)); } //error checking, check that dependency definition exists char* latest_version = NULL; int latest_is_current = 0; string_map* dep_info = get_package_current_or_latest_matching(package_data, dep_name, dep_def, &latest_is_current, &latest_version); //check if we have a version installed different than what is required int have_current; char* current_version = NULL; string_map* cur_info = get_package_current_or_latest(package_data, dep_name, &have_current, ¤t_version); if(have_current && (latest_is_current == 0 || dep_info == NULL)) { //should only get here if dep_def[1] is not null (version mismatch doesn't make sense if no version is specified) char* cur_status = get_string_map_element(cur_info, "Status"); if(strstr(cur_status, " hold ") != NULL) { unsatisfied_dep_err = dynamic_strcat(11, "ERROR: Dependency ", dep_name, " (", dep_def[0], " ", dep_def[1], ") of package ", pkg_name, " is installed,\n\t\tbut has incompatible version ", current_version, " and is marked as 'hold'"); } else { unsatisfied_dep_err = dynamic_strcat(10, "ERROR: Dependency ", dep_name, " (", dep_def[0], " ", dep_def[1], ") of package ", pkg_name, " is installed,\n\t\tbut has incompatible version ", current_version); } } free_if_not_null(current_version); free_if_not_null(latest_version); // check that dependency definition exists if(unsatisfied_dep_err == NULL && dep_info == NULL) { if(dep_def[1] != NULL) { unsatisfied_dep_err = dynamic_strcat(9, "ERROR: Dependency ", dep_name, " (", dep_def[0], " ", dep_def[1], ") of package ", pkg_name, " cannot be found, try updating your package lists"); } else { unsatisfied_dep_err = dynamic_strcat(5, "ERROR: Dependency ", dep_name, " of package ", pkg_name, " cannot be found, try updating your package lists"); } } } free_null_terminated_string_array(load_detail_pkgs); } } install_status = install_pkg_data == NULL ? NULL : get_string_map_element(install_pkg_data, "Status"); /* error checking before we start install */ if(install_pkg_data == NULL || install_status == NULL) { fprintf(stderr, "ERROR: No package named %s found, try updating your package lists\n\n", pkg_name); rm_r(tmp_dir); exit(1); } if(strstr(install_status, " installed") != NULL) { if(force_reinstall) { fprintf(stderr, "WARNING: Package %s is already installed, forcing removal and reinstallation\n\n", pkg_name); free_package_data(package_data); string_map* rm_pkg = initialize_string_map(1); set_string_map_element(rm_pkg, pkg_name, alloc_depend_def(NULL)); do_remove(conf, rm_pkg, (overwrite_config ? 0 : 1), 0, 1, 0, tmp_root); //restart install return do_install(conf, pkgs, install_root_name, link_root_name, is_upgrade, overwrite_config, overwrite_other_package_files, force_reinstall, tmp_root); } else { fprintf(stderr, "WARNING: Package %s is already installed, ignoring\n", pkg_name); fprintf(stderr, " Use --force-reinstall to force reinstallation\n\n"); char** old_el = remove_string_map_element(install_pkgs_map, pkg_name); if(old_el != NULL){ free_null_terminated_string_array(old_el); }; } } if(unsatisfied_dep_err != NULL) { fprintf(stderr, "%s\n", unsatisfied_dep_err); rm_r(tmp_dir); exit(1); } } /* load more detailed data on packages we are about to install */ free_recursive_package_vars(package_data); /* note: whacks install_pkg_depend_map */ string_map* parameters = initialize_string_map(1); matching_packages = initialize_string_map(1); set_string_map_element(parameters, "package-list", install_pkgs_map); load_all_package_data(conf, package_data, matching_packages, parameters, LOAD_MINIMAL_FOR_ALL_PKGS_ALL_FOR_MATCHING, install_root_name, 0, preferred_provides); unsigned long from_file_pkg_list_len; char** from_file_pkg_list = get_string_map_keys(pkgs_from_file, &from_file_pkg_list_len); int from_file_index; for(from_file_index=0; from_file_index < from_file_pkg_list_len; from_file_index++) { char* old = set_string_map_element(matching_packages, from_file_pkg_list[from_file_index], strdup("D")); free_if_not_null(old); } free_null_terminated_string_array(from_file_pkg_list); install_pkg_list = get_string_map_keys(matching_packages, &install_pkg_list_len); destroy_string_map(matching_packages, DESTROY_MODE_FREE_VALUES, &num_destroyed); destroy_string_map(parameters, DESTROY_MODE_IGNORE_VALUES, &num_destroyed); char* all_pkg_list_str = join_strs(", ", install_pkg_list, install_pkg_list_len, 0, 0); uint64_t combined_size = 0; int pkg_index; for(pkg_index=0; pkg_index < install_pkg_list_len; pkg_index++) { char** match_criteria = get_string_map_element(install_pkgs_map, install_pkg_list[pkg_index]); string_map* pkg = get_package_current_or_latest_matching(package_data, install_pkg_list[pkg_index], match_criteria, NULL, NULL); char* next_size_str = get_string_map_element(pkg, "Installed-Size"); uint64_t next_size = 0; if(sscanf(next_size_str, SCANFU64, &next_size) > 0) { combined_size = combined_size + next_size; } } uint64_t root_size = destination_bytes_free(conf, install_root_name); if(combined_size >= root_size ) { fprintf(stderr, "ERROR: Not enough space in destination %s to install specified packages:\n\t%s\n\n", install_root_name, all_pkg_list_str); rm_r(tmp_dir); exit(1); } if(all_pkg_list_str != NULL) { printf("Preparing to install the following packages, which will require " SCANFU64 " bytes:\n\t%s\n\n", combined_size, all_pkg_list_str); } else { fprintf(stderr, "No packages to install.\n\n"); } /* Set status of new required packages to half-installed, set user-installed on requested package, installed time on all */ char* install_root_status_path = dynamic_strcat(2, install_root_path, "/usr/lib/opkg/status"); string_map* install_root_status = initialize_string_map(1); matching_packages = initialize_string_map(1); if(path_exists(install_root_status_path)) { load_package_data(install_root_status_path, 0, install_root_status, matching_packages, NULL, LOAD_ALL_PKG_VARIABLES, install_root_name, preferred_provides); } destroy_string_map(matching_packages, DESTROY_MODE_FREE_VALUES, &num_destroyed); time_t now = time(NULL); char install_time[20]; sprintf(install_time, "%lu", now); for(pkg_index=0; pkg_index < install_pkg_list_len; pkg_index++) { int is_installed; char* install_version = NULL; char** match_criteria = get_string_map_element(install_pkgs_map, install_pkg_list[pkg_index]); string_map* pkg = get_package_current_or_latest_matching(package_data, install_pkg_list[pkg_index], match_criteria, &is_installed, &install_version); if(is_installed == 0) /* should never be true, but check anyway */ { char* old_status = remove_string_map_element(pkg, "Status"); free(old_status); char* status_parts[3] = { "install", "ok", "half-installed" }; status_parts[1] = get_string_map_element(pkgs, install_pkg_list[pkg_index]) != NULL ? "user" : status_parts[1]; char* new_status = dynamic_strcat(5, status_parts[0], " ", status_parts[1], " ", status_parts[2]); set_string_map_element(pkg, "Status", new_status); set_string_map_element(pkg, "Installed-Time", strdup(install_time)); set_string_map_element(pkg, "Install-Destination", strdup(install_root_name)); if(link_root_name != NULL) { set_string_map_element(pkg, "Link-Destination", strdup(link_root_name)); } add_package_data(install_root_status, &pkg, install_pkg_list[pkg_index], install_version, NULL); /* Note: we just added pkg data structure from package_data to install_root_status, Be careful on cleanup! */ } } save_package_data_as_status_file(install_root_status, install_root_status_path); string_map* install_called_pkgs = initialize_string_map(1); int err = 0; for(pkg_name_index=0;pkg_name_index < num_pkg_names; pkg_name_index++) { char* pkg_name = pkg_names[pkg_name_index]; if(get_string_map_element(install_pkgs_map, pkg_name) != NULL && get_string_map_element(install_called_pkgs, pkg_name) == NULL) { int install_pkg_is_current; char* install_pkg_version = NULL; char** version_criteria = get_string_map_element(pkgs, pkg_name); get_package_current_or_latest_matching(package_data, pkg_name, version_criteria, &install_pkg_is_current, &install_pkg_version); err = recursively_install(pkg_name, install_pkg_version, install_root_name, link_root_name, overlay_path, is_upgrade, overwrite_config, overwrite_other_package_files, tmp_dir, conf, package_data, install_called_pkgs); free_if_not_null(install_pkg_version); } } if(err) { fprintf(stderr, "An error occurred during Installation, removing partially installed packages.\n"); unsigned long num_install_called_pkgs; char** install_called_pkg_list = get_string_map_keys(install_called_pkgs, &num_install_called_pkgs); int pkg_index; for(pkg_index=0; pkg_index < num_install_called_pkgs; pkg_index++) { remove_individual_package(install_called_pkg_list[pkg_index], conf, package_data, tmp_dir, 0, 0); } free_null_terminated_string_array(install_called_pkg_list); //call remove function to do cleanup of partial install //DO NOT EXIT HERE, fixup status file below } //remove tmp dir -- need to do this whether or not there is an error rm_r(tmp_dir); free(tmp_dir); //set status of new packages to installed on success, and remove on failure for(pkg_index=0; pkg_index < install_pkg_list_len; pkg_index++) { /* no need to check version, should only be one installed version at a time... */ string_map* pkg = get_package_current_or_latest(install_root_status, install_pkg_list[pkg_index], NULL, NULL); if(pkg != NULL) { if(!err) { char* status = get_string_map_element(pkg, "Status"); if(strstr(status, " half-installed") != NULL) { char* status_parts[3] = { "install", "ok", "installed" }; status_parts[1] = get_string_map_element(pkgs, install_pkg_list[pkg_index]) != NULL ? "user" : status_parts[1]; char* new_status = dynamic_strcat(5, status_parts[0], " ", status_parts[1], " ", status_parts[2]); char* old_status = set_string_map_element(pkg, "Status", new_status); free_if_not_null(old_status); } } else { string_map* all_pkg_versions = remove_string_map_element(install_root_status, install_pkg_list[pkg_index]); free_all_package_versions(all_pkg_versions); } } } save_package_data_as_status_file(install_root_status, install_root_status_path); if(!err) { if(all_pkg_list_str != NULL) { printf("Installation of packages successful.\n\n"); } } else { printf("Finished removing partially installed packages.\n\n"); } }
void veh_interact::exec (game *gm, vehicle *v, int x, int y) { g = gm; veh = v; ex = x; ey = y; // x1 x2 // y1 ----+------+-- // | | // y2 ----+------+ // | // | winw1 = 12; winw2 = 35; winh1 = 3; winh2 = 12; winw12 = winw1 + winw2 + 1; winw3 = 80 - winw1 - winw2 - 2; winh3 = 25 - winh1 - winh2 - 2; winh23 = winh2 + winh3 + 1; winx1 = winw1; winx2 = winw1 + winw2 + 1; winy1 = winh1; winy2 = winh1 + winh2 + 1; page_size = winh23; // h w y x w_grid = newwin(25, 80, 0, 0); w_mode = newwin(1, 80, 0, 0); w_msg = newwin(winh1 - 1, 80, 1, 0); w_disp = newwin(winh2, winw1, winy1 + 1, 0); w_parts = newwin(winh2, winw2, winy1 + 1, winx1 + 1); w_stats = newwin(winh3, winw12, winy2 + 1, 0); w_list = newwin(winh23, winw3, winy1 + 1, winx2 + 1); for (int i = 0; i < 25; i++) { mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2? LINE_XOXX : LINE_XOXO); if (i >= winy1 && i < winy2) mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } for (int i = 0; i < 80; i++) { mvwputch(w_grid, winy1, i, c_ltgray, i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX)); if (i < winx2) mvwputch(w_grid, winy2, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX); } wrefresh(w_grid); crafting_inv = gm->crafting_inventory(); int charges = ((it_tool *) g->itypes["welder"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/5)); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (gm, dx, dy, ch); if (ch == KEY_ESCAPE) finish = true; else if (dx != -2 && (dx || dy) && cx + dx >= -6 && cx + dx < 6 && cy + dy >= -6 && cy + dy < 6) move_cursor(dx, dy); else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; default:; } if (sel_cmd != ' ') finish = true; display_mode (' '); } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }
/** * Creates a veh_interact window based on the given parameters. * @param v The vehicle the player is interacting with. * @param x The x-coordinate of the square the player is 'e'xamining. * @param y The y-coordinate of the square the player is 'e'xamining. */ void veh_interact::exec (game *gm, vehicle *v, int x, int y) { veh = v; // winw1 winw2 winw3 // winh1 | | // ------+-------+------ // winh2 | | // ------+-------+------ // winh3 | | // // +-------------------------+ // | w_mode | // | w_msg | // +-------+---------+-------+ // |w_disp | w_parts | w_list| // +-------+---------+-------+ // | w_stats | // +-------------------------+ int winw1 = 12; int winw2 = 35; int winh1 = 3; int winh2 = 13; int winw3 = FULL_SCREEN_WIDTH - winw1 - winw2 - 4; int winh3 = FULL_SCREEN_HEIGHT - winh1 - winh2 - 2; int winx1 = winw1; int winx2 = winw1 + winw2 + 1; int winy1 = winh1; int winy2 = winh1 + winh2 + 1; mode_h = 1; mode_w = FULL_SCREEN_WIDTH - 2; msg_h = winh1 - 1; msg_w = FULL_SCREEN_WIDTH - 2; disp_h = winh2 - 1; disp_w = winw1; parts_h = winh2 - 1; parts_w = winw2; stats_h = winh3 - 1; stats_w = FULL_SCREEN_WIDTH - 2; list_h = winh2 - 1; list_w = winw3; const int iOffsetX = 1 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); const int iOffsetY = 1 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0); page_size = list_h; // h w y x WINDOW *w_border = newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, -1 + iOffsetY, -1 + iOffsetX ); w_grid = newwin( FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, iOffsetY, iOffsetX ); w_mode = newwin( mode_h, mode_w, iOffsetY, iOffsetX ); w_msg = newwin( msg_h, msg_w, mode_h + iOffsetY, iOffsetX ); w_disp = newwin( disp_h, disp_w, mode_h + msg_h + 1 + iOffsetY, iOffsetX ); w_parts = newwin( parts_h, parts_w, mode_h + msg_h + 1 + iOffsetY, disp_w + 1 + iOffsetX ); w_list = newwin( list_h, list_w, mode_h + msg_h + 1 + iOffsetY, disp_w + 1 + parts_w + 1 + iOffsetX ); w_stats = newwin( stats_h, stats_w, mode_h + msg_h + 1 + disp_h + 1 + iOffsetY, iOffsetX ); wborder(w_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwputch(w_border, mode_h + msg_h + 1 + disp_h + 1, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, mode_h + msg_h + 1, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_border, mode_h + msg_h + 1 + disp_h + 1, FULL_SCREEN_WIDTH - 1, c_ltgray, LINE_XOXX); mvwputch(w_border, mode_h + msg_h + 1, FULL_SCREEN_WIDTH - 1, c_ltgray, LINE_XOXX); wrefresh(w_border); // Two lines dividing the three middle sections. for (int i = winy1; i < winy2; i++) { mvwputch(w_grid, i, winx2, c_ltgray, LINE_XOXO); mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO); } // Two lines dividing the vertical menu sections. for (int i = 0; i < FULL_SCREEN_WIDTH; i++) { mvwputch( w_grid, winy1, i, c_ltgray, LINE_OXOX ); mvwputch( w_grid, winy2-1, i, c_ltgray, LINE_OXOX ); } // Fix up the line intersections. mvwputch( w_grid, winy1, winx1, c_ltgray, LINE_OXXX ); mvwputch( w_grid, winy1, winx2, c_ltgray, LINE_OXXX ); mvwputch( w_grid, winy2 - 1, winx1, c_ltgray, LINE_XXOX ); mvwputch( w_grid, winy2 - 1, winx2, c_ltgray, LINE_XXOX ); wrefresh(w_grid); crafting_inv = g->crafting_inventory(&g->u); int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use; int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use; has_wrench = crafting_inv.has_amount("wrench", 1) || crafting_inv.has_amount("toolset", 1); has_hacksaw = crafting_inv.has_amount("hacksaw", 1) || crafting_inv.has_amount("toolset", 1); has_welder = (crafting_inv.has_amount("welder", 1) && crafting_inv.has_charges("welder", charges)) || (crafting_inv.has_amount("welder_crude", 1) && crafting_inv.has_charges("welder_crude", charges_crude)) || (crafting_inv.has_amount("toolset", 1) && crafting_inv.has_charges("toolset", charges/20)); has_jack = crafting_inv.has_amount("jack", 1); has_siphon = crafting_inv.has_amount("hose", 1); has_wheel = crafting_inv.has_amount( "wheel", 1 ) || crafting_inv.has_amount( "wheel_wide", 1 ) || crafting_inv.has_amount( "wheel_bicycle", 1 ) || crafting_inv.has_amount( "wheel_motorbike", 1 ) || crafting_inv.has_amount( "wheel_small", 1 ); display_stats (); display_veh (); move_cursor (0, 0); bool finish = false; while (!finish) { char ch = input(); // See keypress.h int dx, dy; get_direction (dx, dy, ch); if (ch == KEY_ESCAPE || ch == 'q' ) { finish = true; } else { if (dx != -2 && (dx || dy) && cursor_x + dx >= -6 && cursor_x + dx < 6 && cursor_y + dy >= -6 && cursor_y + dy < 6) { move_cursor(dx, dy); } else { int mval = cant_do(ch); display_mode (ch); switch (ch) { case 'i': do_install(mval); break; case 'r': do_repair(mval); break; case 'f': do_refill(mval); break; case 'o': do_remove(mval); break; case 'e': do_rename(mval); break; case 's': do_siphon(mval); break; case 'c': do_tirechange(mval); break; case 'd': do_drain(mval); break; } if (sel_cmd != ' ') { finish = true; } display_mode (' '); } } } werase(w_grid); werase(w_mode); werase(w_msg); werase(w_disp); werase(w_parts); werase(w_stats); werase(w_list); delwin(w_grid); delwin(w_mode); delwin(w_msg); delwin(w_disp); delwin(w_parts); delwin(w_stats); delwin(w_list); erase(); }