/* generate CSV unique visitors stats */ static void print_csv_visitors (FILE * fp, GHolder * h) { char *data, buf[DATE_LEN]; float percent; int hits, bw, i, process = g_hash_table_size (ht_unique_visitors); /* make compiler happy */ memset (buf, 0, sizeof (buf)); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bw = h->items[i].bw; convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); fprintf (fp, "\"%d\",", i); /* idx */ fprintf (fp, ","); /* parent idx */ fprintf (fp, "\"%s\",", VISIT_ID); fprintf (fp, "\"%d\",", hits); fprintf (fp, "\"%4.2f%%\",", percent); fprintf (fp, "\"%s\",", buf); fprintf (fp, "\"%d\"\r\n", bw); } }
static void print_json_sub_items (FILE * fp, GSubList * sub_list, int process) { char *data; float percent; GSubItem *iter; int hits, i = 0; fprintf (fp, ",\n\t\t\t\"items\": [\n"); for (iter = sub_list->head; iter; iter = iter->next) { hits = iter->hits; data = (char *) iter->data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; fprintf (fp, "\t\t\t\t{\n"); fprintf (fp, "\t\t\t\t\t\"hits\": \"%d\",\n", hits); fprintf (fp, "\t\t\t\t\t\"percent\": \"%4.2f%%\",\n", percent); fprintf (fp, "\t\t\t\t\t\"data\": \""); escape_json_output (fp, data); fprintf (fp, "\"\n"); fprintf (fp, "\t\t\t\t}"); if (i != sub_list->size - 1) fprintf (fp, ",\n"); else fprintf (fp, "\n"); i++; } fprintf (fp, "\t\t\t]"); }
/* generate JSON unique visitors stats */ static void print_json_visitors (FILE * fp, GHolder * h) { char *data, buf[DATE_LEN]; float percent; int hits, bw, i, process = get_ht_size (ht_unique_visitors); /* make compiler happy */ memset (buf, 0, sizeof (buf)); fprintf (fp, "\t\"%s\": [\n", VISIT_ID); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bw = h->items[i].bw; convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); fprintf (fp, "\t\t{\n\t\t\t\"hits\": \"%d\",\n", hits); fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); fprintf (fp, "\t\t\t\"date\": \"%s\",\n", buf); fprintf (fp, "\t\t\t\"bytes\": \"%d\"\n", bw); fprintf (fp, "\t\t}"); if (i != h->idx - 1) fprintf (fp, ",\n"); else fprintf (fp, "\n"); } fprintf (fp, "\t]"); }
//Vaporize a character's homun. If flag, HP needs to be 80% or above. int merc_hom_vaporize(struct map_session_data *sd, int flag) { struct homun_data *hd; nullpo_ret(sd); hd = sd->hd; if (!hd || hd->homunculus.vaporize) return 0; if (status_isdead(&hd->bl)) return 0; //Can't vaporize a dead homun. if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) return 0; hd->regen.state.block = 3; //Block regen while vaporized. //Delete timers when vaporized. merc_hom_hungry_timer_delete(hd); hd->homunculus.vaporize = 1; if(battle_config.hom_setting&0x40) memset(hd->blockskill, 0, sizeof(hd->blockskill)); clif_hominfo(sd, sd->hd, 0); merc_save(hd); return unit_remove_map(&hd->bl, CLR_OUTSIGHT); }
static void print_csv_sub_items (FILE * fp, GSubList * sub_list, int process, const char *id, int *idx) { char *data; float percent; GSubItem *iter; int hits, i = 0; for (iter = sub_list->head; iter; iter = iter->next) { hits = iter->hits; data = (char *) iter->data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; fprintf (fp, "\"%d\",", i); /* idx */ fprintf (fp, "\"%d\",", (*idx)); /* parent idx */ fprintf (fp, "\"%s\",", id); fprintf (fp, "\"%d\",", hits); fprintf (fp, "\"%4.2f%%\",", percent); fprintf (fp, "\""); escape_cvs_output (fp, data); fprintf (fp, "\","); fprintf (fp, "\r\n"); /* parent idx */ i++; } }
/** * Generate CSV on complete fields for the following modules: * REQUESTS, REQUESTS_STATIC, NOT_FOUND, HOSTS */ static void print_csv_complete (FILE * fp, GHolder * holder, int process) { char *data, *method = NULL, *protocol = NULL; const char *id = NULL; float percent; GHolder *h; int i, j, hits; unsigned long long bw, usecs; for (i = 0; i < 4; i++) { switch (i) { case 0: h = holder + REQUESTS; id = REQUE_ID; break; case 1: h = holder + REQUESTS_STATIC; id = STATI_ID; break; case 2: h = holder + NOT_FOUND; id = FOUND_ID; break; case 3: h = holder + HOSTS; id = HOSTS_ID; break; } for (j = 0; j < h->idx; j++) { hits = h->items[j].hits; data = h->items[j].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bw = h->items[j].bw; usecs = h->items[j].usecs; method = h->items[j].method; protocol = h->items[j].protocol; fprintf (fp, "\"%d\",", j); /* idx */ fprintf (fp, ","); /* parent idx */ fprintf (fp, "\"%s\",", id); fprintf (fp, "\"%d\",", hits); fprintf (fp, "\"%4.2f%%\",", percent); fprintf (fp, "\""); escape_cvs_output (fp, data); fprintf (fp, "\","); fprintf (fp, "\"%lld\"", bw); if (conf.serve_usecs) fprintf (fp, ",\"%lld\"", usecs); if (conf.append_protocol && protocol) fprintf (fp, ",\"%s\"", protocol); if (conf.append_method && method) fprintf (fp, ",\"%s\"", method); fprintf (fp, "\r\n"); } } }
/* Clause 4.3.3.1 */ void gen_items() { FILE *output; int i; char a_string[128]; int j; char filename[1024] = "\0"; srand(0); printf("Generating item table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, ITEM_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", ITEM_DATA); return; } for (i = 0; i < items; i++) { /* i_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* i_im_id */ FPRINTF(output, "%d", get_random(9999) + 1); METAPRINTF((output, "%c", delimiter)); /* i_name */ get_a_string(a_string, 14, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* i_price */ FPRINTF(output, "%0.2f", ((double) get_random(9900) + 100.0) / 100.0); METAPRINTF((output, "%c", delimiter)); /* i_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { j = get_random(strlen(a_string) - 8); strncpy(a_string + j, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } fclose(output); printf("Finished item table data...\n"); return; }
/** * Generate JSON on partial fields for the following modules: * OS, BROWSERS, REFERRERS, REFERRING_SITES, KEYPHRASES, STATUS_CODES */ static void print_json_generic (FILE * fp, const GHolder * h, int process) { char *data; const char *id = NULL; float percent; int i, hits; if (h->module == BROWSERS) id = BROWS_ID; else if (h->module == OS) id = OPERA_ID; else if (h->module == REFERRERS) id = REFER_ID; else if (h->module == REFERRING_SITES) id = SITES_ID; else if (h->module == KEYPHRASES) id = KEYPH_ID; else if (h->module == STATUS_CODES) id = CODES_ID; #ifdef HAVE_LIBGEOIP else if (h->module == GEO_LOCATION) id = GEOLO_ID; #endif fprintf (fp, "\t\"%s\": [\n", id); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; fprintf (fp, "\t\t{\n"); fprintf (fp, "\t\t\t\"hits\": \"%d\",\n", hits); fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); fprintf (fp, "\t\t\t\"data\": \""); escape_json_output (fp, data); fprintf (fp, "\""); if (h->module == OS || h->module == BROWSERS || h->module == STATUS_CODES #ifdef HAVE_LIBGEOIP || h->module == GEO_LOCATION #endif ) print_json_sub_items (fp, h->items[i].sub_list, process); fprintf (fp, "\n\t\t}"); if (i != h->idx - 1) fprintf (fp, ",\n"); else fprintf (fp, "\n"); } fprintf (fp, "\n\t]"); }
/* set item's percent in GDashData */ static float set_percent_data (GDashData * data, int n, int process) { float max = 0.0; int i; for (i = 0; i < n; i++) { data[i].metrics->percent = get_percentage (process, data[i].metrics->hits); if (data[i].metrics->percent > max) max = data[i].metrics->percent; } return max; }
static void sharpsl_battery_thread(struct work_struct *private_) { int voltage, percent, apm_status, i; if (!sharpsl_pm.machinfo) return; sharpsl_pm.battstat.ac_status = (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN) ? APM_AC_ONLINE : APM_AC_OFFLINE); /* Corgi cannot confirm when battery fully charged so periodically kick! */ if (!sharpsl_pm.machinfo->batfull_irq && (sharpsl_pm.charge_mode == CHRG_ON) && time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_ON_TIME_INTERVAL)) schedule_delayed_work(&toggle_charger, 0); for (i = 0; i < 5; i++) { voltage = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); if (voltage > 0) break; } if (voltage <= 0) { voltage = sharpsl_pm.machinfo->bat_levels_noac[0].voltage; dev_warn(sharpsl_pm.dev, "Warning: Cannot read main battery!\n"); } voltage = sharpsl_average_value(voltage); apm_status = get_apm_status(voltage); percent = get_percentage(voltage); /* At low battery voltages, the voltage has a tendency to start creeping back up so we try to avoid this here */ if ((sharpsl_pm.battstat.ac_status == APM_AC_ONLINE) || (apm_status == APM_BATTERY_STATUS_HIGH) || percent <= sharpsl_pm.battstat.mainbat_percent) { sharpsl_pm.battstat.mainbat_voltage = voltage; sharpsl_pm.battstat.mainbat_status = apm_status; sharpsl_pm.battstat.mainbat_percent = percent; } dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage, sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies); /* Suspend if critical battery level */ if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL) && !(sharpsl_pm.flags & SHARPSL_APM_QUEUED)) { sharpsl_pm.flags |= SHARPSL_APM_QUEUED; dev_err(sharpsl_pm.dev, "Fatal Off\n"); apm_queue_event(APM_CRITICAL_SUSPEND); } schedule_delayed_work(&sharpsl_bat, SHARPSL_BATCHK_TIME); }
int BC_Pot::draw(int flush) { int x1, y1, x2, y2; draw_top_background(parent_window, 0, 0, get_w(), get_h()); draw_pixmap(images[status]); set_color(get_resources()->pot_needle_color); angle_to_coords(x1, y1, x2, y2, percentage_to_angle(get_percentage())); draw_line(x1, y1, x2, y2); flash(flush); return 0; }
/** * Generate CSV on partial fields for the following modules: * OS, BROWSERS, REFERRERS, REFERRING_SITES, KEYPHRASES, STATUS_CODES */ static void print_csv_generic (FILE * fp, const GHolder * h, int process) { char *data; const char *id = NULL; float percent; int i, idx, hits; if (h->module == BROWSERS) id = BROWS_ID; else if (h->module == OS) id = OPERA_ID; else if (h->module == REFERRERS) id = REFER_ID; else if (h->module == REFERRING_SITES) id = SITES_ID; else if (h->module == KEYPHRASES) id = KEYPH_ID; else if (h->module == STATUS_CODES) id = CODES_ID; #ifdef HAVE_LIBGEOIP else if (h->module == GEO_LOCATION) id = GEOLO_ID; #endif for (i = 0, idx = 0; i < h->idx; i++, idx++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; fprintf (fp, "\"%d\",", idx); /* idx */ fprintf (fp, ","); /* parent idx */ fprintf (fp, "\"%s\",", id); fprintf (fp, "\"%d\",", hits); fprintf (fp, "\"%4.2f%%\",", percent); fprintf (fp, "\""); escape_cvs_output (fp, data); fprintf (fp, "\","); fprintf (fp, "\r\n"); /* parent idx */ if (h->module == OS || h->module == BROWSERS || h->module == STATUS_CODES #ifdef HAVE_LIBGEOIP || h->module == GEO_LOCATION #endif ) print_csv_sub_items (fp, h->items[i].sub_list, process, id, &idx); } }
/*! * @brief This function will be called by the Scheduler. It takes the battery number as input, and returns a binary message as output. * @param battery_number the battery number * @return a binary message that contains the battery level, from 0x0 to 0xE */ unsigned char get_battery_level(int battery_number) { /* get the percentage from the battery*/ uint16_t percentage = get_percentage(battery_number); if (battery_number == FIRST_BATTERY) { /* send the percentage to the alarm */ setup_alarm(percentage); /* send the percentage to the leds*/ display_percentage(percentage); } /* the new bin msg protocol needs to be negotiated with Scheduler*/ // uint8_t binMsg = make_msg(batteryNumber, percentage); unsigned char bin_msg = translate_level(percentage); return bin_msg; }
static void print_html_geolocation (FILE * fp, GHolder * h, int process) { char *data; float percent; int hits; int i; GSubList *sub_list; if (h->idx == 0) return; print_html_h2 (fp, GEOLO_HEAD, GEOLO_ID); print_p (fp, GEOLO_DESC); print_html_begin_table (fp); print_html_begin_thead (fp); fprintf (fp, "<tr>"); fprintf (fp, "<th>Visitors</th>"); fprintf (fp, "<th>%%</th>"); fprintf (fp, "<th>"); fprintf (fp, "Location"); fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>"); fprintf (fp, "</th>"); fprintf (fp, "</tr>"); print_html_end_thead (fp); print_html_begin_tbody (fp); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; print_html_begin_tr (fp, 0); fprintf (fp, "<td>%d</td>", hits); fprintf (fp, "<td>%4.2f%%</td>", percent); fprintf (fp, "<td>%s</td>", data); print_html_end_tr (fp); sub_list = h->items[i].sub_list; print_html_sub_geolocation (fp, sub_list, process); } print_html_end_tbody (fp); print_html_end_table (fp); }
/* Output a sublist (double linked-list) items for a particular parent node. * * On error, it exits early. * On success, outputs item value. */ static void print_csv_sub_items (FILE * fp, GHolder * h, int idx, int valid) { GSubList *sub_list = h->items[idx].sub_list; GSubItem *iter; float percent; int i = 0; if (sub_list == NULL) return; for (iter = sub_list->head; iter; iter = iter->next, i++) { percent = get_percentage (valid, iter->metrics->hits); percent = percent < 0 ? 0 : percent; fprintf (fp, "\"%d\",", i); /* idx */ fprintf (fp, "\"%d\",", idx); /* parent idx */ fprintf (fp, "\"%s\",", module_to_id (h->module)); fprintf (fp, "\"%d\",", iter->metrics->hits); fprintf (fp, "\"%d\",", iter->metrics->visitors); fprintf (fp, "\"%4.2f%%\",", percent); if (conf.bandwidth) fprintf (fp, "\"%lld\",", (long long) iter->metrics->bw.nbw); if (conf.serve_usecs) { fprintf (fp, "\"%lld\",", (long long) iter->metrics->avgts.nts); fprintf (fp, "\"%lld\",", (long long) iter->metrics->cumts.nts); fprintf (fp, "\"%lld\",", (long long) iter->metrics->maxts.nts); } if (conf.append_method && iter->metrics->method) fprintf (fp, "\"%s\"", iter->metrics->method); fprintf (fp, ","); if (conf.append_protocol && iter->metrics->protocol) fprintf (fp, "\"%s\"", iter->metrics->protocol); fprintf (fp, ","); fprintf (fp, "\""); escape_cvs_output (fp, iter->metrics->data); fprintf (fp, "\","); fprintf (fp, "\r\n"); /* parent idx */ } }
int BC_Pot::button_press_event() { if(!tooltip_on) top_level->hide_tooltip(); if(top_level->event_win == win && enabled) { if(status == POT_HIGH || status == POT_UP) { if(get_buttonpress() == 4) { increase_value(); show_value_tooltip(); draw(1); handle_event(); } else if(get_buttonpress() == 5) { decrease_value(); show_value_tooltip(); draw(1); handle_event(); } else { status = POT_DN; start_cursor_angle = coords_to_angle(get_cursor_x(), get_cursor_y()); start_needle_angle = percentage_to_angle(get_percentage()); angle_offset = start_cursor_angle - start_needle_angle; prev_angle = start_cursor_angle; angle_correction = 0; draw(1); top_level->deactivate(); top_level->active_subwindow = this; show_value_tooltip(); } return 1; } } return 0; }
void metadata_browse(void *db, const char *url, prop_t *nodes, prop_t *model, library_query_t type, int (*checkstop)(void *opaque), void *opaque) { prop_t *status = prop_create_r(model, "status"); bmdb_t b = {0}; b.b_query = strdup(url); b.b_type = type; b.b_nodes = nodes; b.b_metadata = prop_create_r(model, "metadata"); while(!checkstop(opaque)) { int p = get_percentage(url); if(p != 100) { prop_set(model, "percentage", PROP_SET_INT, p); prop_set(model, "progressmeter", PROP_SET_INT, 1); prop_link(_p("Indexing"), status); } else { prop_set(model, "progressmeter", PROP_SET_INT, 0); prop_unlink(status); } // int64_t ts = showtime_get_ts(); bmdb_query_exec(db, &b); // printf("Query took %lld\n", showtime_get_ts() - ts); prop_set(model, "loading", PROP_SET_INT, 0); sleep(1); } prop_set(model, "progressmeter", PROP_SET_INT, 0); prop_unlink(status); free(b.b_query); prop_ref_dec(status); prop_ref_dec(b.b_metadata); }
void AgentSelectorRenderer::scanCoordsForIPA(int x, int y, SelectorEvent & evt) { IPAStim::IPAType types[] = {IPAStim::Adrenaline, IPAStim::Perception, IPAStim::Intelligence}; // For each agent for(size_t a = 0; a < 4; a++) { int barLeft = getIpaBarLeftForAgent(a); if(x >= barLeft && x <= barLeft + kIpaBarWidth) { // For each type of IPA for (int i=0; i<3; i++) { int barTop = getIpaBarTop(a, types[i]); if( y>= barTop && y <= barTop + kIpaBarHeight) { evt.eventType = SelectorEvent::kSelectIpa; evt.agentSlot = a; evt.IpaType = types[i]; evt.percentage = get_percentage(a, x); return; } } } } }
/* Clause 4.3.3.1 */ void gen_stock() { FILE *output; int i, j, k; char a_string[128]; char filename[1024] = "\0"; srand(0); printf("Generating stock table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, STOCK_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", STOCK_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY stock FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < items; j++) { /* s_i_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* s_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* s_quantity */ FPRINTF(output, "%d", get_random(90) + 10); METAPRINTF((output, "%c", delimiter)); /* s_dist_01 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_02 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_03 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_04 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_05 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_06 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_07 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_08 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_09 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_10 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_ytd */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_order_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_remote_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { k = get_random(strlen(a_string) - 8); strncpy(a_string + k, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished stock table data...\n"); return; }
void ask_questions(Questiondata *questions) { questions->not_asked = malloc(questions->numquestions * sizeof(char)); /* Questions haven't been asked yet - set to true*/ int i; for(i=0; i<questions->numquestions; i++) { questions->not_asked[i] = 1; } int question_no, answer, question_count = 0; int question_correct = 0; question_no = get_random(0, questions->numquestions); //printf("%d %d", question_no, question_not_asked(question_no, questions)); while(question_count < questions->numquestions) { while( ! question_not_asked(question_no, questions) ) question_no = get_random(0, questions->numquestions); printf("Question %d: %s\n", question_count + 1, questions->question_text[question_no]); #if DEBUG > 0 printf("Answer: %d\n", questions->question_answers[question_no]); #endif fscanf(stdin, "%d", &answer); if( questions->question_answers[question_no] == answer ) { printf("Correct!\n"); question_correct++; } else printf("Wrong answer.\n"); questions->not_asked[question_no] = 0; question_count++; } printf("You scored %d out of %d: %.1f%%\n", question_correct, questions->numquestions, get_percentage(question_correct, questions->numquestions)); }
/* Clause 4.3.3.1 */ void gen_stock() { FILE* output; int i, j, k; char a_string[128]; char filename[1024] = "\0"; srand(0); printf("Generating stock table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, STOCK_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", STOCK_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "stock"); } for (i = 0; i < warehouses; i++) { for (j = 0; j < items; j++) { /* s_i_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* s_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* s_quantity */ FPRINTF(output, "%d", get_random(90) + 10); METAPRINTF((output, "%c", delimiter)); /* s_dist_01 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_02 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_03 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_04 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_05 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_06 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_07 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_08 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_09 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_10 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_ytd */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_order_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_remote_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { k = get_random(strlen(a_string) - 8); strncpy(a_string + k, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } fclose(output); printf("Finished stock table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_customers() { FILE* output; int i, j, k; char a_string[1024]; struct tm* tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating customer table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, CUSTOMER_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", CUSTOMER_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "customer"); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* c_first */ get_a_string(a_string, 8, 16); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_middle */ FPRINTF2(output, "OE"); METAPRINTF((output, "%c", delimiter)); /* c_last Clause 4.3.2.7 */ if (k < 1000) { get_c_last(a_string, k); } else { get_c_last(a_string, get_nurand(255, 0, 999)); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* c_phone */ get_n_string(a_string, 16, 16); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_since */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* c_credit */ if (get_percentage() < .10) { FPRINTF2(output, "BC"); } else { FPRINTF2(output, "GC"); } METAPRINTF((output, "%c", delimiter)); /* c_credit_lim */ FPRINTF2(output, "50000.00"); METAPRINTF((output, "%c", delimiter)); /* c_discount */ FPRINTF(output, "0.%04d", get_random(5000)); METAPRINTF((output, "%c", delimiter)); /* c_balance */ FPRINTF2(output, "-10.00"); METAPRINTF((output, "%c", delimiter)); /* c_ytd_payment */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* c_payment_cnt */ FPRINTF2(output, "1"); METAPRINTF((output, "%c", delimiter)); /* c_delivery_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* c_data */ get_a_string(a_string, 300, 500); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } fclose(output); printf("Finished customer table data...\n"); return; }
/* * Clause 5.2.5.4 * Calculate and return a think time using a negative exponential function. * think_time = -ln(r) * m * return: think time, in milliseconds * r: random number, where 0 < r <= 1 * mean_think_time = mean think time, in milliseconds */ int get_think_time(int mean_think_time) { return (-1.0 * log(get_percentage() + 0.000001) * mean_think_time); }
const char* BC_PercentagePot::get_caption() { sprintf(caption, "%d%%", (int)(get_percentage() * 100 + 0.5)); return caption; }
void *terminal_worker(void *data) { #ifndef STANDALONE int length; int sockfd; #endif /* NOT STANDALONE */ struct terminal_context_t *tc; struct client_transaction_t client_data; double threshold; int keying_time; struct timespec thinking_time, rem; int mean_think_time; /* In milliseconds. */ struct timeval rt0, rt1; double response_time; extern int errno; int rc; int local_seed; #ifdef STANDALONE struct db_context_t dbc; struct transaction_queue_node_t *node = (struct transaction_queue_node_t *) malloc(sizeof(struct transaction_queue_node_t)); extern char sname[32]; extern int exiting; #ifdef LIBPQ extern char postmaster_port[32]; #endif /* LIBPQ */ #ifdef LIBMYSQL extern char dbt2_mysql_port[32]; #endif /* LIBMYSQL */ #endif /* STANDALONE */ tc = (struct terminal_context_t *) data; /* Each thread needs to seed in Linux. */ if (seed == -1) { struct timeval tv; unsigned long junk; /* Purposely used uninitialized */ gettimeofday(&tv, NULL); local_seed = getpid() ^ (int) pthread_self() ^ tv.tv_sec ^ tv.tv_usec ^ junk; } else { local_seed = seed; } printf("seed: %u\n", local_seed); fflush(stdout); srand(local_seed); #ifdef STANDALONE #ifdef ODBC db_init(sname, DB_USER, DB_PASS); #endif /* ODBC */ #ifdef LIBPQ db_init(DB_NAME, sname, postmaster_port); #endif /* LIBPQ */ #ifdef LIBMYSQL printf("CONNECTED TO DB |%s| |%s| |%s|\n", DB_NAME, sname, dbt2_mysql_port); db_init(sname, "", dbt2_mysql_port); #endif /* LIBMYSQL */ if (!exiting && connect_to_db(&dbc) != OK) { LOG_ERROR_MESSAGE("db_connect() error, terminating program"); printf("cannot connect to database, exiting...\n"); exit(1); } #else /* Connect to the client program. */ sockfd = connect_to_client(hostname, client_port); if (sockfd < 1) { LOG_ERROR_MESSAGE( "connect_to_client() failed, thread exiting..."); printf("connect_to_client() failed, thread exiting..."); pthread_exit(NULL); } #endif /* STANDALONE */ do { if (mode_altered == 1) { /* * Determine w_id and d_id for the client per * transaction. */ tc->w_id = w_id_min + get_random(w_id_max - w_id_min + 1); tc->d_id = get_random(table_cardinality.districts) + 1; } /* * Determine which transaction to execute, minimum keying time, * and mean think time. */ threshold = get_percentage(); if (threshold < transaction_mix.new_order_threshold) { client_data.transaction = NEW_ORDER; keying_time = key_time.new_order; mean_think_time = think_time.new_order; } else if (transaction_mix.payment_actual != 0 && threshold < transaction_mix.payment_threshold) { client_data.transaction = PAYMENT; keying_time = key_time.payment; mean_think_time = think_time.payment; } else if (transaction_mix.order_status_actual != 0 && threshold < transaction_mix.order_status_threshold) { client_data.transaction = ORDER_STATUS; keying_time = key_time.order_status; mean_think_time = think_time.order_status; } else if (transaction_mix.delivery_actual != 0 && threshold < transaction_mix.delivery_threshold) { client_data.transaction = DELIVERY; keying_time = key_time.delivery; mean_think_time = think_time.delivery; } else { client_data.transaction = STOCK_LEVEL; keying_time = key_time.stock_level; mean_think_time = think_time.stock_level; } #ifdef DEBUG printf("executing transaction %c\n", transaction_short_name[client_data.transaction]); fflush(stdout); LOG_ERROR_MESSAGE("executing transaction %c", transaction_short_name[client_data.transaction]); #endif /* DEBUG */ /* Generate the input data for the transaction. */ if (client_data.transaction != STOCK_LEVEL) { generate_input_data(client_data.transaction, &client_data.transaction_data, tc->w_id); } else { generate_input_data2(client_data.transaction, &client_data.transaction_data, tc->w_id, tc->d_id); } /* Keying time... */ pthread_mutex_lock( &mutex_terminal_state[KEYING][client_data.transaction]); ++terminal_state[KEYING][client_data.transaction]; pthread_mutex_unlock( &mutex_terminal_state[KEYING][client_data.transaction]); if (time(NULL) < stop_time) { sleep(keying_time); } else { break; } pthread_mutex_lock( &mutex_terminal_state[KEYING][client_data.transaction]); --terminal_state[KEYING][client_data.transaction]; pthread_mutex_unlock( &mutex_terminal_state[KEYING][client_data.transaction]); /* Note this thread is executing a transation. */ pthread_mutex_lock( &mutex_terminal_state[EXECUTING][client_data.transaction]); ++terminal_state[EXECUTING][client_data.transaction]; pthread_mutex_unlock( &mutex_terminal_state[EXECUTING][client_data.transaction]); /* Execute transaction and record the response time. */ if (gettimeofday(&rt0, NULL) == -1) { perror("gettimeofday"); } #ifdef STANDALONE memcpy(&node->client_data, &client_data, sizeof(client_data)); /* enqueue_transaction(node); node = get_node(); if (node == NULL) { LOG_ERROR_MESSAGE("Cannot get a transaction node.\n"); } */ rc = process_transaction(node->client_data.transaction, &dbc, &node->client_data.transaction_data); if (rc == ERROR) { LOG_ERROR_MESSAGE("process_transaction() error on %s", transaction_name[node->client_data.transaction]); } #else /* STANDALONE */ length = send_transaction_data(sockfd, &client_data); length = receive_transaction_data(sockfd, &client_data); rc = client_data.status; #endif /* STANDALONE */ if (gettimeofday(&rt1, NULL) == -1) { perror("gettimeofday"); } response_time = difftimeval(rt1, rt0); pthread_mutex_lock(&mutex_mix_log); if (rc == OK) { fprintf(log_mix, "%d,%c,%f,%d\n", (int) time(NULL), transaction_short_name[client_data.transaction], response_time, (int) pthread_self()); } else if (rc == STATUS_ROLLBACK) { fprintf(log_mix, "%d,%c,%f,%d\n", (int) time(NULL), toupper(transaction_short_name[client_data.transaction]), response_time, (int) pthread_self()); } else if (rc == ERROR) { fprintf(log_mix, "%d,%c,%f,%d\n", (int) time(NULL), 'E', response_time, (int) pthread_self()); } fflush(log_mix); pthread_mutex_unlock(&mutex_mix_log); pthread_mutex_lock(&mutex_terminal_state[EXECUTING][client_data.transaction]); --terminal_state[EXECUTING][client_data.transaction]; pthread_mutex_unlock(&mutex_terminal_state[EXECUTING][client_data.transaction]); /* Thinking time... */ pthread_mutex_lock(&mutex_terminal_state[THINKING][client_data.transaction]); ++terminal_state[THINKING][client_data.transaction]; pthread_mutex_unlock(&mutex_terminal_state[THINKING][client_data.transaction]); if (time(NULL) < stop_time) { thinking_time.tv_nsec = (long) get_think_time(mean_think_time); thinking_time.tv_sec = (time_t) (thinking_time.tv_nsec / 1000); thinking_time.tv_nsec = (thinking_time.tv_nsec % 1000) * 1000000; while (nanosleep(&thinking_time, &rem) == -1) { if (errno == EINTR) { memcpy(&thinking_time, &rem, sizeof(struct timespec)); } else { LOG_ERROR_MESSAGE( "sleep time invalid %d s %ls ns", thinking_time.tv_sec, thinking_time.tv_nsec); break; } } } pthread_mutex_lock(&mutex_terminal_state[THINKING][client_data.transaction]); --terminal_state[THINKING][client_data.transaction]; pthread_mutex_unlock(&mutex_terminal_state[THINKING][client_data.transaction]); } while (time(NULL) < stop_time); #ifdef STANDALONE /*recycle_node(node);*/ #endif /* STANDALONE */ /* Note when each thread has exited. */ pthread_mutex_lock(&mutex_mix_log); fprintf(log_mix, "%d,TERMINATED,%d\n", (int) time(NULL), (int) pthread_self()); fflush(log_mix); pthread_mutex_unlock(&mutex_mix_log); return NULL; /* keep the compiler quiet */ }
/* Clause 4.3.3.1 */ void gen_items() { FILE *output; int i; char a_string[128]; int j; char filename[1024] = "\0"; srand(0); printf("Generating item table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, ITEM_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", ITEM_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY item FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < items; i++) { /* i_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* i_im_id */ FPRINTF(output, "%d", get_random(9999) + 1); METAPRINTF((output, "%c", delimiter)); /* i_name */ get_a_string(a_string, 14, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* i_price */ FPRINTF(output, "%0.2f", ((double) get_random(9900) + 100.0) / 100.0); METAPRINTF((output, "%c", delimiter)); /* i_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { j = get_random(strlen(a_string) - 8); strncpy(a_string + j, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished item table data...\n"); return; }
static void sharpsl_battery_thread(struct work_struct *private_) { int voltage, percent, apm_status, i = 0; if (!sharpsl_pm.machinfo) return; sharpsl_pm.battstat.ac_status = (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN) ? APM_AC_ONLINE : APM_AC_OFFLINE); if (!sharpsl_pm.machinfo->batfull_irq && (sharpsl_pm.charge_mode == CHRG_ON) && time_after(jiffies, sharpsl_pm.charge_start_time + SHARPSL_CHARGE_ON_TIME_INTERVAL)) schedule_delayed_work(&toggle_charger, 0); while(1) { voltage = sharpsl_pm.machinfo->read_devdata(SHARPSL_BATT_VOLT); if (voltage > 0) break; if (i++ > 5) { voltage = sharpsl_pm.machinfo->bat_levels_noac[0].voltage; dev_warn(sharpsl_pm.dev, "Warning: Cannot read main battery!\n"); break; } } voltage = sharpsl_average_value(voltage); apm_status = get_apm_status(voltage); percent = get_percentage(voltage); if ((sharpsl_pm.battstat.ac_status == APM_AC_ONLINE) || (apm_status == APM_BATTERY_STATUS_HIGH) || percent <= sharpsl_pm.battstat.mainbat_percent) { sharpsl_pm.battstat.mainbat_voltage = voltage; sharpsl_pm.battstat.mainbat_status = apm_status; sharpsl_pm.battstat.mainbat_percent = percent; } dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage, sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies); #ifdef CONFIG_BACKLIGHT_CORGI if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) && ((sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_LOW) || (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL))) { if (!(sharpsl_pm.flags & SHARPSL_BL_LIMIT)) { sharpsl_pm.machinfo->backlight_limit(1); sharpsl_pm.flags |= SHARPSL_BL_LIMIT; } } else if (sharpsl_pm.flags & SHARPSL_BL_LIMIT) { sharpsl_pm.machinfo->backlight_limit(0); sharpsl_pm.flags &= ~SHARPSL_BL_LIMIT; } #endif if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL) && !(sharpsl_pm.flags & SHARPSL_APM_QUEUED)) { sharpsl_pm.flags |= SHARPSL_APM_QUEUED; dev_err(sharpsl_pm.dev, "Fatal Off\n"); apm_queue_event(APM_CRITICAL_SUSPEND); } schedule_delayed_work(&sharpsl_bat, SHARPSL_BATCHK_TIME); }
int main(void) { uint16_t menu_choice = 0; int percentage = 0, kill = 0, shutdown_delay = 0, tmp; char str[20]; clock_setup(); gpio_setup(); usart_setup(); adc_setup(); while(1) { menu_choice = usart_recv_blocking(USART2); switch(menu_choice) { case 's': { percentage = get_percentage(); kill = get_kill_status(); sprintf(str, "%i %i\n\r", percentage, kill); for(int i = 0; i < 20; ++i) { if(str[i] == 0) break; usart_send_blocking(USART2, (uint16_t)str[i]); } break; } case 'k': { tmp = usart_recv_blocking(USART2); for(int i = 0; tmp != '^';) { shutdown_delay *= 10; shutdown_delay += (tmp - 48); tmp = usart_recv_blocking(USART2); } sprintf(str, "Kill in %ims\n\r", shutdown_delay); for(int i = 0; i < 20; ++i) { if(str[i] == 0) break; usart_send_blocking(USART2, (uint16_t)str[i]); } delay_ms(shutdown_delay); sprintf(str, "Killing.\n\r"); for(int i = 0; i < 20; ++i) { if(str[i] == 0) break; usart_send_blocking(USART2, (uint16_t)str[i]); } shutdown_delay = 0; break; } default: break; } //sprintf(str, "%i\n\r", adc_dat); //for(int i = 0; i < 20; ++i) { // if(str[i] == 0) break; // usart_send_blocking(USART2, (uint16_t)str[i]); //} //delay_ms(10); } // while(1) return 0; }
int pet_catch_process2(struct map_session_data *sd, int target_id) { struct mob_data *md; int i = 0, pet_catch_rate = 0; nullpo_retr(1, sd); md = (struct mob_data *)map_id2bl(target_id); if(!md || md->bl.type != BL_MOB || md->bl.prev == NULL) { //Invalid inputs/state, abort capture. clif_pet_roulette(sd,0); sd->catch_target_class = -1; sd->itemid = sd->itemindex = -1; return 1; } //FIXME: delete taming item here, if this was an item-invoked capture and the item was flagged as delay-consume [ultramage] i = search_petDB_index(md->mob_id,PET_CLASS); //Catch_target_class == 0 is used for universal lures (except bosses for now). [Skotlex] if(sd->catch_target_class == 0 && !(md->status.mode&MD_BOSS)) sd->catch_target_class = md->mob_id; if(i < 0 || sd->catch_target_class != md->mob_id) { clif_emotion(&md->bl,E_AG); //Mob will do /ag if wrong lure is used on them. clif_pet_roulette(sd,0); sd->catch_target_class = -1; return 1; } pet_catch_rate = (pet_db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100; if(pet_catch_rate < 1) pet_catch_rate = 1; if(battle_config.pet_catch_rate != 100) pet_catch_rate = (pet_catch_rate*battle_config.pet_catch_rate)/100; if(rnd()%10000 < pet_catch_rate) { unit_remove_map(&md->bl,CLR_OUTSIGHT); status_kill(&md->bl); clif_pet_roulette(sd,1); intif_create_pet(sd->status.account_id,sd->status.char_id,pet_db[i].class_,mob_db(pet_db[i].class_)->lv, pet_db[i].EggID,0,pet_db[i].intimate,100,0,1,pet_db[i].jname); } else { clif_pet_roulette(sd,0); sd->catch_target_class = -1; } return 0; }
/* Clause 4.3.3.1 */ void gen_customers() { FILE *output; int i, j, k; char a_string[1024]; struct tm *tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating customer table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, CUSTOMER_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", CUSTOMER_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY customer FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* c_first */ get_a_string(a_string, 8, 16); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_middle */ FPRINTF2(output, "OE"); METAPRINTF((output, "%c", delimiter)); /* c_last Clause 4.3.2.7 */ if (k < 1000) { get_c_last(a_string, k); } else { get_c_last(a_string, get_nurand(255, 0, 999)); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* c_phone */ get_n_string(a_string, 16, 16); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_since */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* c_credit */ if (get_percentage() < .10) { FPRINTF2(output, "BC"); } else { FPRINTF2(output, "GC"); } METAPRINTF((output, "%c", delimiter)); /* c_credit_lim */ FPRINTF2(output, "50000.00"); METAPRINTF((output, "%c", delimiter)); /* c_discount */ FPRINTF(output, "0.%04d", get_random(5000)); METAPRINTF((output, "%c", delimiter)); /* c_balance */ FPRINTF2(output, "-10.00"); METAPRINTF((output, "%c", delimiter)); /* c_ytd_payment */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* c_payment_cnt */ FPRINTF2(output, "1"); METAPRINTF((output, "%c", delimiter)); /* c_delivery_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* c_data */ get_a_string(a_string, 300, 500); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished customer table data...\n"); return; }