/** * Evaluate the expression */ int eval_str_expr (char *str_expr) { char *before, *after; if (str_split (str_expr, '+', &before, &after)) { return (eval_str_expr (before) + eval_str_expr (after)); } else if (str_split (str_expr, '-', &before, &after)) { return (eval_str_expr (before) - eval_str_expr (after)); } else if (str_split (str_expr, '*', &before, &after)) { return (eval_str_expr (before) * eval_str_expr (after)); } else if (str_split (str_expr, '/', &before, &after)) { return (eval_str_expr (before) / eval_str_expr (after)); } else { return atoi(str_expr); } }
/* Read substitution scores from specified file and return as a kind of pseudo substitution matrix. All nonspecified elements in matrix will be equal to NEGINFTY, which is to be interpretted as "NA" */ Matrix* read_subst_scores(TreeModel *mod, FILE *F) { Matrix *retval = mat_new(mod->rate_matrix->size, mod->rate_matrix->size); String *line = str_new(STR_MED_LEN), *tuple1, *tuple2; List *l = lst_new_ptr(3); int alph_size = (int)strlen(mod->rate_matrix->states); int *inv_alph = mod->rate_matrix->inv_states; double val; mat_set_all(retval, NEGINFTY); while (str_readline(line, F) != EOF) { str_double_trim(line); if (str_starts_with_charstr(line, "#") || line->length == 0) continue; str_split(line, NULL, l); if (lst_size(l) < 3) { die("ERROR: wrong number of columns in subst. score file.\n"); } tuple1 = lst_get_ptr(l, 0); tuple2 = lst_get_ptr(l, 1); if (str_as_dbl(lst_get_ptr(l, 2), &val) != 0) { die("ERROR: bad value in subst. score file.\n"); } mat_set(retval, tuple_index(tuple1->chars, inv_alph, alph_size), tuple_index(tuple2->chars, inv_alph, alph_size), val); str_free(tuple1); str_free(tuple2); str_free(lst_get_ptr(l, 2)); } lst_free(l); str_free(line); return retval; }
int irc_server_cmd_privmsg(t_srv *server, t_usr *user, char **cmd) { char **dest; char *msg; int i; if (user->n == NULL) return (server_send(user->s, ERR_NOLOGIN)); if (cmd[1] == NULL) return (server_send(user->s, ERR_NORECIPIENT)); if (cmd[2] == NULL) return (server_send(user->s, ERR_NOTEXTTOSEND)); if (!(dest = str_split(cmd[1], ",")) || !(msg = concat_message(&(cmd[2])))) return (handle_error("malloc failed")); i = -1; while (dest[++i]) { if (strcmp(dest[i], "$*") == 0) send_global_message(user, msg); else if (dest[i][0] == '&' || dest[i][0] == '#') send_channel_message(user, dest[i], msg); else send_user_message(server, user, dest[i], msg); } free(msg); free_tab(dest); return (EXIT_SUCCESS); }
int main() { char *s="Gg22AAAA876543"; str_split(s); print_split_str(); return 0; }
const char * fs_mimetype_get_file_extension_from_filename(const char *filename) { int err; unsigned int i, cnt, len; char buff[1024], **tab = NULL; if (filename == NULL || strlen(filename) == 0 || strlen(filename) > 1024) return (ERR_PARAM); if ((err = str_strip(filename, " \t\n\r", (char *)&buff)) != ERR_OK) return (err); if ((err = str_split(filename, ".", &cnt, &tab)) != ERR_OK) return (err); if (cnt > 1) { len = strlen(tab[cnt -1]); strncpy(&buff, (const char *)tab[cnt -1], len + 1); buff[len] = '\0'; } else *buff = '\0'; strs_free(tab); return ((const char *)buff); }
int command_process(netcon_client_t *netcon_client, const char *command) { char *tokens[MAX_TOKENS]; char str[1024]; int num_tokens; syslog(LOG_DEBUG, "Command: %s", command); // Make a copy of the command since we modify it strncpy(str, command, sizeof(str)); num_tokens = str_split(str, tokens, MAX_TOKENS, ' '); if (num_tokens == 0) { return 0; } if (strcmp(tokens[0], "get") == 0) { command_get(netcon_client, tokens, num_tokens); } else if (strcmp(tokens[0], "toggle") == 0) { command_toggle(netcon_client, tokens, num_tokens); } else if (strcmp(tokens[0], "exit") == 0) { command_exit(netcon_client, tokens, num_tokens); } else { syslog(LOG_WARNING, "Invalid command: %s", command); } return 0; }
int thom_load_paths() { char *line; FILE* fp; char file_name[MAX_PATH+1]; int len = 100; int read; char **options; snprintf(file_name, MAX_PATH, "%s/global.conf", THOM.thom_home_dir); fp = fopen(file_name, "r"); if (fp == (FILE *)0 ) return 0; line = malloc(MAX_PATH*2); while ((read = getline(&line, &len, fp)) != -1) { options = str_split(line, '='); if(options){ if(strcmp(options[0], DEFAULT_DISK_PATH) == 0){ strcpy(THOM.thom_disk_dir, options[1]); }else if(strcmp(options[0], DEFAULT_K7_PATH) == 0){ strcpy(THOM.thom_k7_dir, options[1]); } } } if(line){ free(line); } return 0; }
void handle_ftpcmd(session_t *sess) { char buf[MAXCMD] = {0}; sprintf(buf, "Welcome to zftp!\r\n%d", FTP_READY); ftp_cmdio_write_m(sess->ctrl_fd, FTP_READY, buf); while (1) { start_signal_alarm_ctrl(); _reset_session_cmd(sess); int ret = ftp_cmdio_get_cmd_args(sess->ctrl_fd, sess->ftp_cmd_line, MAXCMD); if (ret == -1) { if (errno == EINTR) continue; ERROR_EXIT("ftp_cmdio_get_cmd_args"); } else if (ret == 0) exit(0); str_trim_crlf(sess->ftp_cmd_line); str_split(sess->ftp_cmd_line, sess->ftp_cmd_op, sess->ftp_cmd_arg, ' '); str_toupper(sess->ftp_cmd_op); _handle_map(sess); } }
void cmd_teleport(std::wostringstream &os, ServerCommandContext *ctx) { if((ctx->privs & PRIV_TELEPORT) ==0) { os<<L"-!- You don't have permission to do that"; return; } if(ctx->parms.size() != 2) { os<<L"-!- Missing parameter"; return; } std::vector<std::wstring> coords = str_split(ctx->parms[1], L','); if(coords.size() != 3) { os<<L"-!- You can only specify coordinates currently"; return; } v3f dest(stoi(coords[0])*10, stoi(coords[1])*10, stoi(coords[2])*10); ctx->player->setPosition(dest); ctx->server->SendMovePlayer(ctx->player); os<< L"-!- Teleported."; }
KLF_EXPORT QString klfSearchPath(const QString& programName, const QString& extra_path) { static const QString PATH = getenv("PATH"); static const QString pathsep = QString("")+KLF_PATH_SEP; QString path = PATH; if (!extra_path.isEmpty()) path = extra_path + pathsep + path; const QStringList paths = str_split(path, pathsep, true); QString test; int k, j; for (k = 0; k < (int)paths.size(); ++k) { klfDbg("searching in "+paths[k]) ; QStringList hits = klfSearchFind(paths[k]+"/"+programName); klfDbg("\t...resulting in hits = "+hits.join(" ;; ")) ; for (j = 0; j < (int)hits.size(); ++j) { if ( QFileInfo(hits[j]).isExecutable() ) { klfDbg("\tFound definitive (executable) hit at "+hits[j]) ; return hits[j]; } } } return QString::null; }
int fstorage_uri(const char *filename, const char *fkey, const char *akey, char *urip) { int err, n; unsigned int cnt; char **tab; str_split(fkey, "::", &cnt, &tab); err = ( cnt != 2 || fkey == NULL || fkey[0] == '\0' || filename == NULL || filename[0] =='\0' || (akey != NULL && akey[0] == '\0') || false) ? ERR_PARAM : ERR_OK; if (err == ERR_OK) { if (akey != NULL) n = sprintf(urip, "/%s?fkey=%s&akey=%s", filename, (const char *)tab[1], akey); else n = sprintf(urip, "/%s?fkey=%s", filename, (const char *)tab[1]); } free(tab); return (err); }
int main(int argc, const char **argv) { ArgState *state = arg_command_line(args,argv); if (! interactive) { if (array_len(incdirs) > 0) { printf("the include paths\n"); FOR_ARR (str_t,P,incdirs) printf("'%s'\n",*P); } if (array_len(string_args) > 0) { printf("the string args\n"); FOR_ARR (str_t,P,string_args) printf("'%s'\n",*P); } printf("flag a is %d\n",a); } else { char *line; printf("> "); while ((line = file_getline(stdin)) != NULL) { char **parts = str_split(line," "); // args_process assumes args start at second element, hence -1 here PValue v = arg_process(state,(const char**)parts-1); if (v != NULL) { printf("%s\n",value_tostring(v)); unref(v); } dispose(parts,line); printf("> "); arg_reset_used(state); } } return 0; }
void do_site_chmod(session_t *sess, char *args) { if (strlen(args) == 0) { ftp_reply(sess, FTP_BADCMD, "SITE CHMOD needs 2 arguments."); return; } char perm[100] = {0}; char file[100] = {0}; str_split(args , perm, file, ' '); if (strlen(file) == 0) { ftp_reply(sess, FTP_BADCMD, "SITE CHMOD needs 2 arguments."); return; } unsigned int mode = str_octal_to_uint(perm); if (chmod(file, mode) < 0) { ftp_reply(sess, FTP_CHMODOK, "SITE CHMOD command failed."); } else { ftp_reply(sess, FTP_CHMODOK, "SITE CHMOD command ok."); } }
result_t handle_system_event(const char *request, size_t req_len) { // tokenize request message size_t num_tokens = 0; char **tokens = str_split(request, ": ", &num_tokens); if(num_tokens < 2) { fprintf(stderr, "Could not find correct number of tokens in rpc system request."); return FAILURE; } if(strncmp(tokens[1], ACTION_VOLUME_MUTE, sizeof(ACTION_VOLUME_MUTE)-1) == 0) { audio_output_mute(!audio_input_is_muted()); } else if(strncmp(tokens[1], ACTION_VOLUME_LEVEL, sizeof(ACTION_VOLUME_LEVEL)-1) == 0) { if(num_tokens < 3) { fprintf(stderr, "Could not find correct number of tokens for rpc system request's action volume level"); return FAILURE; } float volume_level = atoi(tokens[2])/100.0; volume_level = (volume_level < 0.0f) ? 0.0f : (volume_level > 1.0f) ? 1.0f : volume_level; audio_output_set_volume(volume_level); } else if(strncmp(tokens[1], ACTION_SHUT_DOWN, sizeof(ACTION_SHUT_DOWN)-1) == 0) { system_shutdown(); } else if(strncmp(tokens[1], ACTION_RESTART, sizeof(ACTION_RESTART)-1) == 0) { system_restart(); } else if(strncmp(tokens[1], ACTION_SLEEP, sizeof(ACTION_SLEEP)-1) == 0) { system_sleep(); } else if(strncmp(tokens[1], ACTION_LOG_OUT, sizeof(ACTION_LOG_OUT)-1) == 0) { system_logout(); } // free tokens free_tokens(tokens, num_tokens); }
// read file data, calculates amount of measurements and mean bool parse_inputFile(std::string& filename) { // used to calculate mean int totalValueSum = 0; // initialize statistic counters statistics.totalMeasurements = 0.0; std::ifstream file(filename); std::string line; // read file line by line, split each line by comma // convert each comma separated value to integer while(std::getline(file, line)) { std::vector<std::string> data = str_split(line, ','); std::string::size_type sz; Measurement measurement; measurement.index = std::stoi(data.at(0), &sz); measurement.value = std::stoi(data.at(1), &sz); statistics.totalMeasurements += 1.0; totalValueSum += measurement.value; all_data.push_back(measurement); } // calculate mean statistics.mean = totalValueSum / statistics.totalMeasurements; return true; }
int main(void) { char s[] = "a+b/c++d"; char b[] = "+/"; puts(str_split(s,b)); return 0; }
void parseconf_load_setting(const char *setting){ while(isspace(*setting)) setting++; char key[128] = {0}, value[128] = {0}; str_split(setting, key, value, '='); if(strlen(value) == 0){ fprintf(stderr, "missing value in config file for : %s\n", key); exit(EXIT_FAILURE); } { const struct parseconf_str_setting *p_str_setting = parseconf_str_array; while(p_str_setting->p_setting_name != NULL){ if(strcmp(p_str_setting->p_setting_name, key) == 0){ const char **p_cur_setting = p_str_setting->p_variable; if(*p_cur_setting) free((char*)*p_cur_setting); *p_cur_setting = strdup(value); return; } p_str_setting++; } } { const struct parseconf_bool_setting *p_bool_setting = parseconf_bool_array; while(p_bool_setting->p_setting_name != NULL){ if(strcmp(p_bool_setting->p_setting_name, key) == 0){ str_upper(value); if(strcmp(value, "YES") == 0 || strcmp(value, "TRUE") == 0 || strcmp(value, "1") == 0) *(p_bool_setting->p_variable) = 1; else if(strcmp(value, "NO") == 0 || strcmp(value, "FALSE") == 0 || strcmp(value, "0") == 0) *(p_bool_setting->p_variable) = 0; else{ fprintf(stderr, "Wrong bool value in config file for : %s\n", key); exit(EXIT_FAILURE); } return; } p_bool_setting++; } } { const struct parseconf_uint_setting *p_uint_setting = parseconf_uint_array; while(p_uint_setting->p_setting_name != NULL){ if(strcmp(p_uint_setting->p_setting_name, key) == 0){ if(value[0] == '0'){ *(p_uint_setting->p_variable) = str_octal_to_uint(value); } else{ *(p_uint_setting->p_variable) = atoi(value); } return; } p_uint_setting++; } } }
rta * login_1_svc(proy_in *in, struct svc_req *rqstp) { char buffer[1000]; FILE *fp; fp=fopen ("users.txt","r"); fscanf(fp,"%s",buffer); char **tokens; char **user; int desicion=0; tokens= str_split(buffer,','); if(tokens) { int i; for(i=0;*(tokens+i);i++) { user=str_split(*(tokens+i),'-'); if(strcmp(in->usuario,user[0])==0) { if(strcmp(in->pass,user[1])==0) { desicion=1; } } } } static rta result; if(desicion==1) { result.rta=rand()%1000+1; } else { result.rta=0; } fclose(fp); if(result.rta!=0) { char buffer[sizeof(result.rta)]; snprintf(buffer,sizeof(buffer),"%d",result.rta); FILE *fp; fp=fopen(in->usuario,"w"); fputs(buffer,fp); fclose(fp); } return &result; }
int set_splitter( const char *line, const char *keyword, VArray &splitter ) { VRegexp re("^[ \011]*([a-zA-Z0-9]+)[ \011]*=[ \011]*(.+)"); if ( ! re.m( line ) ) return 0; if ( str_low( re[1] ) != keyword ) return 0; splitter = str_split( PATH_DELIMITER, re[2] ); return 1; }
void processExtensions() { char * extVar = getenv("EXT_TO_BROWSE"); //printf("%s\n", extVar); if (extVar && *extVar) { exts = str_split(extVar); } }
void CNodeDefManager::applyTextureOverrides(const std::string &override_filepath) { infostream << "CNodeDefManager::applyTextureOverrides(): Applying " "overrides to textures from " << override_filepath << std::endl; std::ifstream infile(override_filepath.c_str()); std::string line; int line_c = 0; while (std::getline(infile, line)) { line_c++; if (trim(line) == "") continue; std::vector<std::string> splitted = str_split(line, ' '); if (splitted.size() != 3) { errorstream << override_filepath << ":" << line_c << " Could not apply texture override \"" << line << "\": Syntax error" << std::endl; continue; } content_t id; if (!getId(splitted[0], id)) { errorstream << override_filepath << ":" << line_c << " Could not apply texture override \"" << line << "\": Unknown node \"" << splitted[0] << "\"" << std::endl; continue; } ContentFeatures &nodedef = m_content_features[id]; if (splitted[1] == "top") nodedef.tiledef[0].name = splitted[2]; else if (splitted[1] == "bottom") nodedef.tiledef[1].name = splitted[2]; else if (splitted[1] == "right") nodedef.tiledef[2].name = splitted[2]; else if (splitted[1] == "left") nodedef.tiledef[3].name = splitted[2]; else if (splitted[1] == "back") nodedef.tiledef[4].name = splitted[2]; else if (splitted[1] == "front") nodedef.tiledef[5].name = splitted[2]; else if (splitted[1] == "all" || splitted[1] == "*") for (int i = 0; i < 6; i++) nodedef.tiledef[i].name = splitted[2]; else if (splitted[1] == "sides") for (int i = 2; i < 6; i++) nodedef.tiledef[i].name = splitted[2]; else { errorstream << override_filepath << ":" << line_c << " Could not apply texture override \"" << line << "\": Unknown node side \"" << splitted[1] << "\"" << std::endl; continue; } } }
int dash_eval(char *line, char *std_input, char *origin) { if (line == NULL) return 1; int num_tokens; char **tokens = str_split(line, " ", &num_tokens); char *token; int i; int remote_pipe_pos = -1; for (i = 0; i < num_tokens; i++) { if (strcmp(tokens[i], REMOTE_PIPE) == 0) { remote_pipe_pos = i; break; } } if (remote_pipe_pos == -1) // No remote pipes { char *msg_data = dash_exec_scmd(tokens, remote_pipe_pos + 1, num_tokens, std_input); if (std_input == NULL) { printf("%s", msg_data); return 1; } else { // Send to origin char *fio_msg = dashp_fio(msg_data); send_to_host(fio_msg, origin); return 1; } } else // Remote pipe at remote_pipe_pos { char *subcommand = join_strings(tokens, " ", remote_pipe_pos+1, num_tokens); char *remotehost = extract_host(subcommand); char *maincommand = join_strings(tokens, " ", 0, remote_pipe_pos); char *msg_data = dash_exec_scmd(tokens, 0, remote_pipe_pos, std_input); char *send_msg; if (std_input == NULL) { // TODO: MAKE IP ADDRESS FUNCTION WORK! char *fin_remote_host = (char *) malloc (strlen(remotehost) + 1); strcat(fin_remote_host, remotehost); strcat(fin_remote_host, ":"); remove_substring(subcommand, fin_remote_host); free (fin_remote_host); subcommand[strlen(subcommand)-1] = '\0'; send_msg = dashp_pip(msg_data, "127.0.0.1", subcommand); } else { send_msg = dashp_pip(msg_data, origin, subcommand); } send_to_host(send_msg, remotehost); printf("Sent"); return 2; } }
void handle_child(session_t *pses) { if(pses == NULL) handle_error_str("do_cmd_user: pses is NULL."); ftp_reply(pses->ctrl_fd, FTP_GREET, "(Mftp 0.1)"); //220 int iret; while(true) { memset(pses->cmdline, 0, MAX_COMMAND_LINE); memset(pses->cmd, 0, MAX_COMMAND); memset(pses->arg, 0, MAX_ARG); iret = recvline(pses->ctrl_fd, pses->cmdline, MAX_COMMAND_LINE);//接收命令行 if(iret == -1) handle_error("recvline"); else if(iret == 0) handle_error("recvline"); //去掉\r\n str_trim_crlf(pses->cmdline); //分割命令和参数 str_split(pses->cmdline, pses->cmd, pses->arg, ' '); //将命令转换成大写 str_upper(pses->cmd); #ifdef _DEBUG_ printf("cmd = [%s] arg = [%s]\n", pses->cmd,pses->arg); #endif //处理ftp命令 int len = ARRAYLEN(ctrl_cmds); int i = 0; for(i = 0; i < len; i++) { if(strcmp(ctrl_cmds[i].cmd, pses->cmd) == 0) { if(ctrl_cmds[i].cmd_handler != NULL) { (*ctrl_cmds[i].cmd_handler)(pses); //等价于ctrl_cmds[i].cmd_handler(pses); } else { ftp_reply(pses->ctrl_fd, FTP_COMMANDNOTIMPL, "Unimplement command."); //502 } break; } } if(i >= len) { //没找到命令 ftp_reply(pses->ctrl_fd, FTP_BADCMD, "Unknown command."); } } }
void PatchTableParams::set_from_switches(string s) { vector<string> L = str_split(s, ' '); vector<const char *> argv; for (int i = 0; i < (int) L.size(); i++) { if (L[i].size() && !(L[i].size() == 1 && L[i][0] == ' ')) { argv.push_back(L[i].c_str()); } } set_from_switches(argv.size(), &argv[0]); }
result_t handle_slide_show_event(const char *request, size_t req_len) { // tokenize request message size_t num_tokens = 0; char **tokens = str_split(request, ": ", &num_tokens); if(num_tokens < 2) { fprintf(stderr, "Could not find correct number of tokens in rpc slide show event request."); return FAILURE; } if( strncmp(tokens[1], ACTION_START, sizeof(ACTION_START)-1) == 0 ){ slide_show_start_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_END, sizeof(ACTION_END)-1) == 0) { slide_show_end_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_PREVIOUS, sizeof(ACTION_PREVIOUS)-1) == 0) { if(num_tokens == 3 && ( strncmp(tokens[2], "yes", 3) == 0) ) { slide_show_previous_hot_keys_event(); } else { slide_show_previous_no_animation_hot_keys_event(); } } else if( strncmp(tokens[1], ACTION_NEXT, sizeof(ACTION_NEXT)-1) == 0) { if(num_tokens == 3 && (strncmp(tokens[2], "yes", 3) == 0) ) { slide_show_next_hot_keys_event(); } else { slide_show_next_no_animation_hot_keys_event(); } } else if( strncmp(tokens[1], ACTION_POINTER, sizeof(ACTION_POINTER)-1) == 0) { if(num_tokens < 3) { fprintf(stderr, "Could not find correct number of tokens for rpc slide show request's action pointer"); return FAILURE; } if( strncmp(tokens[2], "arrow", 5) == 0 ) { slide_show_arrow_pointer_hot_keys_event(); } else if( strncmp(tokens[2], "pen", 3) == 0) { slide_show_pen_pointer_hot_keys_event(); } } else if( strncmp(tokens[1], ACTION_BLANK_SLIDE, sizeof(ACTION_BLANK_SLIDE)-1) == 0) { if(num_tokens < 3) { fprintf(stderr, "Could not find correct number of tokens for rpc slide show request's action blank slide"); return FAILURE; } if( strncmp(tokens[2], "black", 5) == 0 ) { slide_show_blank_slide_black_hot_keys_event(); } else if( strncmp(tokens[2], "pen", 3) == 0) { slide_show_blank_slide_white_hot_keys_event(); } } else if( strncmp(tokens[1], ACTION_FIRST_SLIDE, sizeof(ACTION_FIRST_SLIDE)-1) == 0) { slide_show_first_slide_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_LAST_SLIDE, sizeof(ACTION_LAST_SLIDE)-1) == 0) { slide_show_last_slide_hot_keys_event(); } }
void devfs_conf_handle(char *buffer) { char *line; char **rule; int i = 0; char *dev = NULL; char *target = NULL; if (buffer != NULL) { if (strlen(buffer) == 0) return; if (buffer[0] == '#') return; if (strncmp(buffer, "link ", 5) == 0) { //ln -sf strncpy(line, buffer+5, strlen(buffer) - 5); rule = str_split(line, ' '); while(*rule) { if (i == 0) dev = *rule; else target = *rule; i++; rule++; } } else if (strncmp(buffer, "own ", 4) == 0) { //chown uid:gid strncpy(line, buffer+4, strlen(buffer) - 4); rule = str_split(line, ' '); while(*rule) { if (i == 0) dev = *rule; else target = *rule; i++; rule++; } if (dev != NULL && target != NULL) { char **id = str_split(target, ':'); get } }
//cocklebur constructor Cocklebur::Cocklebur(map<string,string> & map_conf){ d_conf = map_conf; if( map_conf.count("cocklebur.data.dir") > 0 ) d_conf_data_dir = map_conf["cocklebur.data.dir"]; if( d_conf_data_dir == "" ) d_conf_data_dir = "cocklebur_data"; if( map_conf.count("cocklebur.host.list") > 0 ) { string host_list = map_conf["cocklebur.host.list"]; vector< string > vec_host_list; str_split(vec_host_list, host_list,',',true); vector< string >::iterator it = vec_host_list.begin(); for( ; it != vec_host_list.end() ; it++ ) { vector< string > vec_port; str_split( vec_port, *it, ':' ); d_conf_map_host_port[vec_port[0]] = atoi( vec_port[1].c_str() ); } } if( map_conf.count("cocklebur.server.address") >0 ) { vector< string > tmp; str_split( tmp, map_conf["cocklebur.server.address"], ':' ); d_conf_my_ip = tmp[0]; d_conf_my_port = atoi( tmp[1].c_str() ); } if( access( d_conf_data_dir.c_str(), 0 ) != 0 ) { // we got nothing from data_dir mkdir(d_conf_data_dir.c_str(), 0775); initial_in_memory(); } else { // we got the snapshots from data_dir initial_in_memory(); //initial_in_file(); } // initial locks pthread_rwlock_init( &m_host_stat, NULL ); pthread_rwlock_init( &m_cur_node_mode, NULL ); pthread_rwlock_init( &m_ack_lock, NULL ); }
result_t handle_shortcut_event(const char *request, size_t req_len) { // tokenize request message size_t num_tokens = 0; char **tokens = str_split(request, ": ", &num_tokens); if(num_tokens < 2) { fprintf(stderr, "Could not find correct number of tokens in rpc shortcut request."); return FAILURE; } if(strncmp(tokens[1], ACTION_SELECT_ALL, sizeof(ACTION_SELECT_ALL)-1) == 0) { system_hot_keys_event(kSelectAllHotKeys); } else if(strncmp(tokens[1], ACTION_CUT, sizeof(ACTION_CUT)-1) == 0) { system_hot_keys_event(kCutHotKeys); } else if(strncmp(tokens[1], ACTION_COPY, sizeof(ACTION_COPY)-1) == 0) { system_hot_keys_event(kCopyHotKeys); } else if(strncmp(tokens[1], ACTION_PASTE, sizeof(ACTION_PASTE)-1) == 0) { system_hot_keys_event(kPasteHotKeys); } else if(strncmp(tokens[1], ACTION_OPEN_FILE, sizeof(ACTION_OPEN_FILE)-1) == 0) { system_hot_keys_event(kOpenFileHotKeys); } else if(strncmp(tokens[1], ACTION_SAVE, sizeof(ACTION_SAVE)-1) == 0) { system_hot_keys_event(kSaveHotKeys); } else if(strncmp(tokens[1], ACTION_FIND, sizeof(ACTION_FIND)-1) == 0) { system_hot_keys_event(kFindHotKeys); } else if(strncmp(tokens[1], ACTION_PRINT, sizeof(ACTION_PRINT)-1) == 0) { system_hot_keys_event(kPrintHotKeys); } else if(strncmp(tokens[1], ACTION_NEW_WINDOW, sizeof(ACTION_NEW_WINDOW)-1) == 0) { system_hot_keys_event(kOpenNewWindowHotKeys); } else if(strncmp(tokens[1], ACTION_MINIMIZE_WINDOW, sizeof(ACTION_MINIMIZE_WINDOW)-1) == 0) { system_hot_keys_event(kMinimizeFrontWindowHotKeys); } else if(strncmp(tokens[1], ACTION_CLOSE_WINDOW, sizeof(ACTION_CLOSE_WINDOW)-1) == 0) { system_hot_keys_event(kCloseFrontWindowHotKeys); } else if(strncmp(tokens[1], ACTION_SWITCH_APPS, sizeof(ACTION_SWITCH_APPS)-1) == 0) { system_hot_keys_event(kSwitchAppsHotKeys); } else if(strncmp(tokens[1], ACTION_UNDO, sizeof(ACTION_UNDO)-1) == 0) { system_hot_keys_event(kUndoHotKeys); } else if(strncmp(tokens[1], ACTION_REDO, sizeof(ACTION_REDO)-1) == 0) { system_hot_keys_event(kRedoHotKeys); } else if(strncmp(tokens[1], ACTION_SYSTEM_SEARCH, sizeof(ACTION_SYSTEM_SEARCH)-1) == 0) { system_hot_keys_event(kSpotlightHotKeys); } else if(strncmp(tokens[1], ACTION_FORCE_QUIT, sizeof(ACTION_FORCE_QUIT)-1) == 0) { system_hot_keys_event(kForceQuitHotKeys); } else if(strncmp(tokens[1], ACTION_SHOW_DESKTOP, sizeof(ACTION_SHOW_DESKTOP)-1) == 0) { system_hot_keys_event(kShowDesktopHotKeys); } else if(strncmp(tokens[1], ACTION_LEFT_DESKTOP, sizeof(ACTION_LEFT_DESKTOP)-1) == 0) { system_hot_keys_event(kLeftDesktopHotKeys); } else if(strncmp(tokens[1], ACTION_RIGHT_DESKTOP, sizeof(ACTION_RIGHT_DESKTOP)-1) == 0) { system_hot_keys_event(kRightDesktopHotKeys); } // free tokens free_tokens(tokens, num_tokens); }
result_t handle_browser_event(const char *request, size_t req_len) { // tokenize request message size_t num_tokens = 0; char **tokens = str_split(request, ": ", &num_tokens); if(num_tokens < 2) { fprintf(stderr, "Could not find correct number of tokens in rpc browser event request."); return FAILURE; } if( strncmp(tokens[1], ACTION_NEW_TAB, sizeof(ACTION_NEW_TAB)-1) == 0 ){ browser_new_tab_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_PREVIOUS_TAB, sizeof(ACTION_PREVIOUS_TAB)-1) == 0) { browser_prev_tab_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_NEXT_TAB, sizeof(ACTION_NEXT_TAB)-1) == 0) { browser_next_tab_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_CLOSE_TAB, sizeof(ACTION_CLOSE_TAB)-1) == 0) { browser_close_tab_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_OPEN_FILE, sizeof(ACTION_OPEN_FILE)-1) == 0) { browser_open_file_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_NEW_PRIVATE_WINDOW, sizeof(ACTION_NEW_PRIVATE_WINDOW)-1) == 0) { browser_new_private_window_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_REOPEN_CLOSED_TAB, sizeof(ACTION_REOPEN_CLOSED_TAB)-1) == 0) { browser_reopen_closed_tab_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_CLOSE_WINDOW, sizeof(ACTION_CLOSE_WINDOW)-1) == 0) { browser_close_window_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_SHOW_DOWNLOADS, sizeof(ACTION_SHOW_DOWNLOADS)-1) == 0) { browser_show_downloads_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_SHOW_HISTORY, sizeof(ACTION_SHOW_HISTORY)-1) == 0) { browser_show_history_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_SHOW_SIDEBAR, sizeof(ACTION_SHOW_SIDEBAR)-1) == 0) { browser_show_sidebar_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_SHOW_PAGE_SOURCE, sizeof(ACTION_SHOW_PAGE_SOURCE)-1) == 0) { browser_show_page_source_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_HOME_PAGE, sizeof(ACTION_HOME_PAGE)-1) == 0) { browser_home_page_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_RELOAD_PAGE, sizeof(ACTION_RELOAD_PAGE)-1) == 0) { browser_reload_page_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_BOOKMARK_PAGE, sizeof(ACTION_BOOKMARK_PAGE)-1) == 0) { browser_add_bookmark_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_ENTER_FULL_SCREEN, sizeof(ACTION_ENTER_FULL_SCREEN)-1) == 0) { enter_full_screen_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_ZOOM_OUT, sizeof(ACTION_ZOOM_OUT)-1) == 0) { zoom_hot_keys_event(kZoomOut); } else if( strncmp(tokens[1], ACTION_ZOOM_ACTUAL_SIZE, sizeof(ACTION_ZOOM_ACTUAL_SIZE)-1) == 0) { zoom_actual_size_hot_keys_event(); } else if( strncmp(tokens[1], ACTION_ZOOM_IN, sizeof(ACTION_ZOOM_IN)-1) == 0) { zoom_hot_keys_event(kZoomIn); } else if( strncmp(tokens[1], ACTION_ENTER_LOCATION, sizeof(ACTION_ENTER_LOCATION)-1) == 0) { browser_open_location_hot_keys_event(); } }
int main(){ int len, i; char *p[3] = { "Ene", "Mene", "Miste" }, *s, **r; s = str_join(p, 3, ", "); printf("%s\n", s); r = str_split(s, ",", &len); printf("\n"); for(i=0; i<len; i++){ printf("%s\n", r[i]); } return 0; }