int strtoularray(unsigned long *array, char *string, const char *delim) { /* split a <delim> delimited string into a long array */ int idx=0; char *t1; for (idx=0;idx<MAX_VALUE_LIST;idx++) array[idx]=0; idx=0; for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) { if (is_numeric(t1) && idx<MAX_VALUE_LIST) { array[idx]=strtoul(t1,NULL,10); idx++; } else return FALSE; } return TRUE; }
/* SYNTAX: KNOCKOUT [<seconds>] <nick> <reason> */ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, IRC_CHANNEL_REC *channel) { KNOCKOUT_REC *rec; char *nick, *reason, *timeoutstr, *str; void *free_arg; int timeleft; g_return_if_fail(data != NULL); if (!IS_IRC_SERVER(server) || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED); if (!IS_IRC_CHANNEL(channel)) cmd_return_error(CMDERR_NOT_JOINED); if (is_numeric(data, ' ')) { /* first argument is the timeout */ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nick, &reason)) return; timeleft = atoi(timeoutstr); } else { timeleft = 0; if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nick, &reason)) return; } if (timeleft == 0) timeleft = settings_get_int("knockout_time"); if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); signal_emit("command ban", 3, nick, server, channel); str = g_strdup_printf("%s %s", nick, reason); signal_emit("command kick", 3, str, server, channel); g_free(str); /* create knockout record */ rec = g_new(KNOCKOUT_REC, 1); rec->timeleft = timeleft; rec->channel = channel; rec->ban = ban_get_mask(channel, nick); server->knockoutlist = g_slist_append(server->knockoutlist, rec); cmd_params_free(free_arg); }
static int TRANS(TLIINETConnect)(XtransConnInfo ciptr, char *host, char *port) { char portbuf[PORTBUFSIZE]; struct t_call *sndcall; long tmpport; prmsg(2, "TLIINETConnect(%s,%s)\n", host, port); #ifdef X11_t /* * X has a well known port, that is transport dependant. It is easier * to handle it here, than try and come up with a transport independent * representation that can be passed in and resolved the usual way. * * The port that is passed here is really a string containing the idisplay * from ConnectDisplay(). */ if (is_numeric (port)) { tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10); sprintf(portbuf,"%u", tmpport ); port = portbuf; } #endif if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL ) { prmsg(1, "TLIINETConnect() failed to allocate a t_call\n"); return TRANS_CONNECT_FAILED; } if( TRANS(TLIAddrToNetbuf)(ciptr->index, host, port, &(sndcall->addr) ) < 0 ) { prmsg(1, "TLIINETConnect() unable to resolve name:%s.%s\n", host, port); t_free((char *)sndcall,T_CALL); return TRANS_CONNECT_FAILED; } return TRANS(TLIConnect)(ciptr, sndcall ); }
static void command_set_ban(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item, int set) { IRC_CHANNEL_REC *chanrec; char *channel, *nicks; void *free_arg; g_return_if_fail(data != NULL); if (server == NULL || !server->connected || !IS_IRC_SERVER(server)) cmd_return_error(CMDERR_NOT_CONNECTED); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST, item, &channel, &nicks)) return; if (!ischannel(*channel)) cmd_param_error(CMDERR_NOT_JOINED); if (*nicks == '\0') { if (strcmp(data, "*") != 0) cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); /* /BAN * or /UNBAN * - ban/unban everyone */ nicks = (char *) data; } chanrec = irc_channel_find(server, channel); if (chanrec == NULL) cmd_param_error(CMDERR_CHAN_NOT_FOUND); if (!chanrec->wholist) cmd_param_error(CMDERR_CHAN_NOT_SYNCED); if (set) ban_set(chanrec, nicks); else { if (is_numeric(nicks, '\0')) { /* unban with ban number */ BAN_REC *ban = g_slist_nth_data(chanrec->banlist, atoi(nicks)-1); if (ban != NULL) nicks = ban->ban; } ban_remove(chanrec, nicks); } cmd_params_free(free_arg); }
void parser_base::identifier(const char*& p, size_t& len, const char* extra) { p = mp_char; len = 1; for (next(); has_char(); next(), ++len) { char c = cur_char(); if (is_alpha(c) || is_name_char(c) || is_numeric(c)) continue; if (extra) { // See if the character is one of the extra allowed characters. if (is_in(c, extra)) continue; } return; } }
/* SYNTAX: WINDOW SHOW <number>|<name> */ static void cmd_window_show(const char *data) { WINDOW_REC *window; if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); window = is_numeric(data, 0) ? window_find_refnum(atoi(data)) : window_find_item(active_win, data); if (window == NULL) return; if (is_window_visible(window)) return; WINDOW_GUI(window)->parent = mainwindow_create(); WINDOW_GUI(window)->parent->active = window; active_mainwin = NULL; window_set_active(window); }
/* SYNTAX: WINDOW GOTO active|<number>|<name> */ static void cmd_window_goto(const char *data) { WINDOW_REC *window; g_return_if_fail(data != NULL); if (is_numeric(data, 0)) { cmd_window_refnum(data); return; } if (g_strcasecmp(data, "active") == 0) window = window_highest_activity(active_win); else window = window_find_item(active_win, data); if (window != NULL) window_set_active(window); }
static void init(int argc, char* argv[]) { int i = 1; config.packets = 10; /* Disable stdout buffering to avoid long lags in the callback */ setbuf(stdout, NULL); while(i < argc) { if (strcmp("-c", argv[i]) == 0) { if (argv[i+1] == NULL || ((config.packets = atoi(argv[i+1])) == 0) || !is_numeric(argv[i+1])) usage(); config.packets = atoi(argv[i+1]); i++; } else if (strcmp("-o", argv[i]) == 0) { if (argv[i+1] == NULL) usage(); DEBUG(printf("Reading from save file: %s\n", argv[i+1])); config.read_from_save_file = TRUE; config.save_file_name = malloc(strlen(argv[i+1]) * sizeof(char)); strcpy(config.save_file_name, argv[i+1]); DEBUG(printf("Captured filename: %s\n", config.save_file_name)); i++; } else { printf("Aborting.. %d\n", i); usage(); } i++; } packets_captured.head = NULL; packets_captured.len = 0; }
static int type_str(unsigned long value, void *arg) { unsigned long types; types = *((unsigned long *)arg); if ((types & B_ASN1_NUMERICSTRING) && !is_numeric(value)) types &= ~B_ASN1_NUMERICSTRING; if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) types &= ~B_ASN1_PRINTABLESTRING; if ((types & B_ASN1_IA5STRING) && (value > 127)) types &= ~B_ASN1_IA5STRING; if ((types & B_ASN1_T61STRING) && (value > 0xff)) types &= ~B_ASN1_T61STRING; if ((types & B_ASN1_BMPSTRING) && (value > 0xffff)) types &= ~B_ASN1_BMPSTRING; if (!types) return -1; *((unsigned long *)arg) = types; return 1; }
string pdf_version (url image) { string buf; bool ok= !load_string (image, buf, false); int n= N(buf); if (!ok || n < 5 || buf(0,5) != "%PDF-") { std_error << "Cannot determine PDF version of \"" << image << "\"." << LF; return default_pdf_version (); } int pos= 5; while (n > pos && is_numeric (buf[pos])) pos++; string v= buf(5,pos); if (!is_double(v)) { std_error << "Cannot determine PDF version of \"" << image << "\"." << LF; return default_pdf_version ();; } //cout << "PDF version found for \"" << image << "\": " << v << LF; return v; }
int do_show(jokedb_struct *jokedb) { // define buffer to store user provided int joke_id_buf_sz = 11; char joke_id_buf[joke_id_buf_sz]; uint32_t joke_id; char joke_str[MAX_JOKE_STRING_LEN] = { 0 }; int id_type; // send SHOWWHICHID msg send(SHOWWHICHID, cgc_strlen(SHOWWHICHID)); provide_joke_id: // send LISTPROMPT and handle user input cgc_memset(joke_id_buf, '\0', joke_id_buf_sz); prompt_user(SHOWPROMPT, joke_id_buf, joke_id_buf_sz); // is joke_id_buf a number? id_type = is_numeric(joke_id_buf); // numeric and >= 0 if (id_type == 0) { joke_id = str2uint32(joke_id_buf); if (joke_id == 1337) { send(EASTEREGG, cgc_strlen(EASTEREGG)); } else if (joke_id < joke_count(jokedb)) { send_joke(&jokedb->jokes[joke_id]); } else { send(BADIDERROR, cgc_strlen(BADIDERROR)); goto provide_joke_id; } // not numeric } else if (id_type == -1 && streq(joke_id_buf, "RANDOM") == 0) { send_random_joke(jokedb); // either numeric < 0, or not numeric that is not "RANDOM" } else { send(BADIDERROR, cgc_strlen(BADIDERROR)); goto provide_joke_id; } return 0; }
int number(char **argv) { int tail; if (is_numeric(argv[2]) == 1) { tail = ft_atoi(argv[2]); if (tail < 0) return (-tail); else return (tail); } else { ft_putstr("tail: illegal offset -- "); ft_putstr(argv[2]); ft_putstr("\n"); return (-1); } }
bool parse_number() { char buf[256]; // Should be enough for any number char* buf_ptr = buf; // Copy all sign characters while(buf_ptr < buf+255 && *m_path == '-' || *m_path == '+') { *buf_ptr++ = *m_path++; } // Copy all numeric characters while(buf_ptr < buf+255 && is_numeric(*m_path)) { *buf_ptr++ = *m_path++; } *buf_ptr = 0; m_last_number = atof(buf); return true; }
/* `optlist' should contain only one unknown key - the server tag. returns NULL if there was unknown -option */ static int cmd_options_get_signal(const char *cmd, GHashTable *optlist) { GSList *list, *tmp, *next; char *signame; int signum; /* get all the options, then remove the known ones. there should be only one left - the signal */ list = hashtable_get_keys(optlist); if (cmd != NULL) { for (tmp = list; tmp != NULL; tmp = next) { char *option = tmp->data; next = tmp->next; if (command_have_option(cmd, option)) list = g_slist_remove(list, option); } } if (list == NULL) return -1; signame = list->data; signum = -1; signum = is_numeric(signame, 0) ? atol(signame) : signal_name_to_id(signame); if (signum == -1 || list->next != NULL) { /* unknown option (not a signal) */ signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), signum == -1 ? list->data : list->next->data); signal_stop(); return -2; } g_slist_free(list); return signum; }
/* SYNTAX: UNIGNORE <id>|<mask> */ static void cmd_unignore(const char *data) { IGNORE_REC *rec; GSList *tmp; char *mask; void *free_arg; if (!cmd_get_params(data, &free_arg, 1, &mask)) return; if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); if (is_numeric(mask, ' ')) { /* with index number */ tmp = g_slist_nth(ignores, atoi(mask)-1); rec = tmp == NULL ? NULL : tmp->data; } else { /* with mask */ const char *chans[2] = { "*", NULL }; if (active_win->active_server != NULL && server_ischannel(active_win->active_server, mask)) { chans[0] = mask; mask = NULL; } rec = ignore_find_noact("*", mask, (char **) chans, 0); if (rec == NULL) { rec = ignore_find_noact("*", mask, (char **) chans, 1); } } if (rec != NULL) { rec->level = 0; ignore_update_rec(rec); } else { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_IGNORE_NOT_FOUND, mask); } cmd_params_free(free_arg); }
//------------------------------------------------------------------------------ // Name: enumerate_processes // Desc: //------------------------------------------------------------------------------ QMap<edb::pid_t, IProcess::pointer> DebuggerCore::enumerate_processes() const { QMap<edb::pid_t, IProcess::pointer> ret; QDir proc_directory("/proc/"); QFileInfoList entries = proc_directory.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for(const QFileInfo &info: entries) { const QString filename = info.fileName(); if(is_numeric(filename)) { const edb::pid_t pid = filename.toULong(); // NOTE(eteran): the const_cast is reasonable here. // While we don't want THIS function to mutate the DebuggerCore object // we do want the associated PlatformProcess to be able to trigger // non-const operations in the future, at least hypothetically. ret.insert(pid, std::make_shared<PlatformProcess>(const_cast<DebuggerCore*>(this), pid)); } } return ret; }
/* SYNTAX: WINDOW STICK [<ref#>] [ON|OFF] */ static void cmd_window_stick(const char *data) { MAIN_WINDOW_REC *mainwin; WINDOW_REC *win; mainwin = active_mainwin; win = active_mainwin->active; if (is_numeric(data, ' ')) { /* ref# specified */ win = window_find_refnum(atoi(data)); if (win == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, data); return; } while (*data != ' ' && *data != '\0') data++; while (*data == ' ') data++; } if (g_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') { /* unset sticky */ if (!WINDOW_GUI(win)->sticky) { printformat_window(win, MSGLEVEL_CLIENTERROR, TXT_WINDOW_NOT_STICKY); } else { gui_window_set_unsticky(win); printformat_window(win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_UNSET_STICKY); } } else { /* set sticky */ window_reparent(win, mainwin); gui_window_set_sticky(win); printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_SET_STICKY); } }
array_list_t* coverage_filter(array_list_t* input_records, array_list_t *failed, variant_stats_t **input_stats, char *filter_name, void* f_args) { assert(input_records); assert(failed); array_list_t *passed = array_list_new(input_records->size + 1, 1, COLLECTION_MODE_ASYNCHRONIZED); size_t filter_name_len = strlen(filter_name); int min_coverage = ((coverage_filter_args*)f_args)->min_coverage; LOG_DEBUG_F("coverage_filter (min coverage = %d) over %zu records\n", min_coverage, input_records->size); char *aux_buffer = (char*) calloc (128, sizeof(char)); vcf_record_t *record; for (int i = 0; i < input_records->size; i++) { record = input_records->items[i]; if (record->info_len > strlen(aux_buffer)) { aux_buffer = realloc (aux_buffer, record->info_len+1); memset(aux_buffer, 0, (record->info_len+1) * sizeof(char)); } strncpy(aux_buffer, record->info, record->info_len); char *record_coverage = get_field_value_in_info("DP", aux_buffer); if (record_coverage != NULL && is_numeric(record_coverage)) { if (atoi(record_coverage) >= min_coverage) { array_list_insert(record, passed); } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } free(aux_buffer); return passed; }
string _db_create_field_sql(string name, map<string, string> spec) { string sql; _db_process_field( spec ); sql = "`" + name + "` " + spec["mysql_type"]; if ( (spec["type"] == "varchar" || spec["type"] == "char" || spec["type"] == "text") && isset(spec["length"]) ) { sql += "(" + spec["length"] + ")"; } else if (isset(spec["precision"]) && isset(spec["scale"])) { sql += "(" + spec["precision"] + ", " + spec["scale"] + ")"; } if (!spec["unsigned"].empty()) { sql += " unsigned"; } if (spec["not null"] == _TRUE) { sql += " NOT NULL"; } if (!spec["auto_increment"].empty()) { sql += " auto_increment"; } if (inarray( spec, "default")) { if ( !is_numeric(spec["default"]) ) { spec["default"] = "\"" + spec["default"] + "\""; } sql += " DEFAULT " + spec["default"]; } if (spec["not null"].empty() && !isset(spec["default"])) { sql += " DEFAULT NULL"; } return sql; }
/* SYNTAX: DEHILIGHT <id>|<mask> */ static void cmd_dehilight(const char *data) { HILIGHT_REC *rec; GSList *tmp; if (is_numeric(data, ' ')) { /* with index number */ tmp = g_slist_nth(hilights, atoi(data)-1); rec = tmp == NULL ? NULL : tmp->data; } else { /* with mask */ char *chans[2] = { "*", NULL }; rec = hilight_find(data, chans); } if (rec == NULL) printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_HILIGHT_NOT_FOUND, data); else { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_HILIGHT_REMOVED, rec->text); hilight_remove(rec); } }
/** * @brief * Change the negative [on/off] of the led display. * @param arg The new negative value for the negative option, could be: * - LED_NEGATIVE_OFF or 0 * - LED_NEGATIVE_ON or 1 * @param cheeky_device A file descriptor to the led device. * @return 0 on success, -1 on error. */ static int set_negative(char* arg, int cheeky_device) { if (is_numeric(arg)) ioctl(cheeky_device, IOCTL_CMD_NEGATIVE, atoi(arg)); else if (strcmp(arg, "LED_NEGATIVE_ON") == 0) ioctl(cheeky_device, IOCTL_CMD_NEGATIVE, LED_NEGATIVE_ON); else if (strcmp(arg, "LED_NEGATIVE_OFF") == 0) ioctl(cheeky_device, IOCTL_CMD_NEGATIVE, LED_NEGATIVE_OFF); else { printf("cheeky_display: Wrong argument to --negative!\n"); usage(); return (-1); } return (0); }
void json_parser<_Handler>::value() { char c = cur_char(); if (is_numeric(c)) { number(); return; } switch (c) { case '-': number(); break; case '[': array(); break; case '{': object(); break; case 't': parse_true(); m_handler.boolean_true(); break; case 'f': parse_false(); m_handler.boolean_false(); break; case 'n': parse_null(); m_handler.null(); break; case '"': string(); break; default: json::parse_error::throw_with("value: failed to parse '", cur_char(), "'.", offset()); } }
/** * @brief * Change the flash [on/off] of the led display. * @param arg The new value for the flash option, could be: * - LED_NO_FLASH or 0 * - LED_FLASHING or 1 * @param cheeky_device A file descriptor to te led device. * @return 0 on success, -1 on error. */ static int set_flashing(char* arg, int cheeky_device) { if (is_numeric(arg)) ioctl(cheeky_device, IOCTL_CMD_FLASH, atoi(arg)); else if (strcmp(arg, "LED_FLASHING") == 0) ioctl(cheeky_device, IOCTL_CMD_FLASH, LED_FLASHING); else if (strcmp(arg, "LED_NO_FLASH") == 0) ioctl(cheeky_device, IOCTL_CMD_FLASH, LED_NO_FLASH); else { printf("cheeky_display: Wrong argument to --flash!\n"); usage(); return (-1); } return (0); }
/* SYNTAX: WINDOW HIDE [<number>|<name>] */ static void cmd_window_hide(const char *data) { WINDOW_REC *window; if (mainwindows->next == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_CANT_HIDE_LAST); return; } if (*data == '\0') window = active_win; else if (is_numeric(data, 0)) { window = window_find_refnum(atoi(data)); if (window == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, data); } } else { window = window_find_item(active_win->active_server, data); } if (window == NULL || !is_window_visible(window)) return; if (WINDOW_MAIN(window)->sticky_windows) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_CANT_HIDE_STICKY_WINDOWS); return; } mainwindow_destroy(WINDOW_MAIN(window)); if (active_mainwin == NULL) { active_mainwin = WINDOW_MAIN(active_win); window_set_active(active_mainwin->active); } }
void Menu::parse() { std::string str; std::string delim = ";"; std::string token; std::size_t pos = 0; for(size_t i = 0; i < fileCP.size(); i++) { str = fileCP[i]; while ((pos = str.find(delim)) != std::string::npos) { token = str.substr(0, pos); if (is_numeric(token.c_str()) != 0) _Score.push_back(token); else _Name.push_back(token); str.erase(0, pos + delim.length()); } _Game.push_back(str); } }
static PROCESS_REC *process_find(const char *name, int verbose) { GSList *tmp; g_return_val_if_fail(name != NULL, NULL); if (*name == '%' && is_numeric(name+1, 0)) return process_find_id(atoi(name+1), verbose); for (tmp = processes; tmp != NULL; tmp = tmp->next) { PROCESS_REC *rec = tmp->data; if (rec->name != NULL && strcmp(rec->name, name) == 0) return rec; } if (verbose) { printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown process name: %s", name); } return NULL; }
/* SYNTAX: SCROLLBACK GOTO <+|-linecount>|<linenum>|<timestamp> */ static void cmd_scrollback_goto(const char *data) { char *datearg, *timearg; void *free_arg; int lines; if (!cmd_get_params(data, &free_arg, 2, &datearg, &timearg)) return; if (*timearg == '\0' && (*datearg == '-' || *datearg == '+')) { /* go forward/backward n lines */ lines = atoi(datearg + (*datearg == '-' ? 0 : 1)); gui_window_scroll(active_win, lines); } else if (*timearg == '\0' && is_numeric(datearg, '\0')) { /* go to n'th line. */ scrollback_goto_line(atoi(datearg)); } else { /* should be timestamp */ scrollback_goto_time(datearg, timearg); } cmd_params_free(free_arg); }
/* SYNTAX: WINDOW ITEM GOTO <number>|<name> */ static void cmd_window_item_goto(const char *data, SERVER_REC *server) { WI_ITEM_REC *item; GSList *tmp; void *free_arg; char *target; if (!cmd_get_params(data, &free_arg, 1, &target)) return; if (is_numeric(target, '\0')) { /* change to specified number */ tmp = g_slist_nth(active_win->items, atoi(target)-1); item = tmp == NULL ? NULL : tmp->data; } else { item = window_item_find_window(active_win, server, target); } if (item != NULL) window_item_set_active(active_win, item); cmd_params_free(free_arg); }
/* SYNTAX: WINDOW ITEM MOVE <number>|<name> */ static void cmd_window_item_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { WINDOW_REC *window; void *free_arg; char *target; if (!cmd_get_params(data, &free_arg, 1, &target)) return; if (is_numeric(target, '\0')) { /* move current window item to specified window */ window = window_find_refnum(atoi(target)); } else { /* move specified window item to current window */ item = window_item_find(server, target); window = active_win; } if (window != NULL && item != NULL) window_item_set_active(window, item); cmd_params_free(free_arg); }
void urlencode(unsigned char *src, int src_len, unsigned char *dest, int dest_len) { unsigned char ch; int len = 0; while (len < (dest_len - 4) && *src) { ch = (unsigned char)*src; if (*src == ' ') { *dest++ = '+'; } else if (is_numeric(ch) || strchr("-_.!~*'()", ch)) { *dest++ = *src; } else { *dest++ = '%'; *dest++ = char2hex( (unsigned char)(ch >> 4) ); *dest++ = char2hex( (unsigned char)(ch % 16) ); } ++src; ++len; } *dest = 0; return ; }