void execute_function(char* arg){ char* flags=split_line(arg); char* pwd_current; char *temp_response[100]; *temp_response='\0'; concatinate(temp_response,get_str(8)); concatinate(temp_response,arg); pwd_current=temp_response; newLine_load(pwd_current); return; }
char* GetValue(const char* confname, const char* name, char* value, size_t len) { assert(value!=NULL && len!=0); FILE* fn = fopen(confname, "r"); if (fn == NULL) return NULL; assert(len < len+CONF_NAME_LEN); len += CONF_NAME_LEN; char* buffer = calloc(1,len); if (buffer == NULL){ fclose(fn); return NULL; } value[0] = '\0'; do { fgets(buffer, len, fn); char *left, *right; if (split_line(buffer, &left, &right, '=') == 0) { if (strcmp(left, name) == 0) { strncpy(value, right, len-CONF_NAME_LEN); value[len-CONF_NAME_LEN-1] = '\0'; break; } } } while (!feof(fn)); free(buffer); fclose(fn); return value[0]=='\0'? NULL:value; }
struct fline_t *read_file(FILE *stream, size_t *len) { struct fline_t *out = NULL; size_t out_len = 0; char *line = NULL; size_t line_len = 0; while (getline(&line, &line_len, stream) != -1){ out_len++; out = realloc(out, sizeof(struct fline_t) * out_len); if (is_code_line(line)){ str_to_lower(line); out[out_len - 1] = split_line(line); } else { out[out_len - 1].len = 0; out[out_len - 1].words = NULL; } } free(line); if (len){ (*len) = out_len; } return out; }
int main (int argc, char** argv) { char* cmdLine; char** command; int status; char cwd[1024]; int isBackground=0; signal(SIGINT, signalhandler); signal(SIGTSTP, signalhandler); while(1) { getcwd(cwd, sizeof(cwd)); printf("e14shell:%s>> ", cwd); cmdLine=read_line(); command=split_line(cmdLine, &isBackground); if(command[0]==NULL) continue; status=execute(command, &isBackground); free(cmdLine); free(command); status=0; memset(cwd, 0, sizeof(cwd)); isBackground=0; } }
void parser(char* command){ int a=1; if(*command=='\0'){ newLine_load(get_str(2)); return; } char* args; args=split_line(command); if(str_cp(command,get_str(3))==1) pwd_function(args); if(str_cp(command,get_str(4))==1) execute_function(args); if(str_cp(command,get_str(5))==1) ls_function(args); if(str_cp(command,get_str(6))==1) cd_function(args); newLine_load(get_str(2)); return; }
RichTextLineList split_richtext_lines (const std::wstring &str, PaletteID id, unsigned wid) { SplitStringLineList split = split_line (wid, str); RichTextLineList ret (split.size ()); std::transform (split.begin (), split.end (), ret.begin (), SplitStringLine2RichTextLine (id)); return ret; }
void do_code_width(void) { LOG_FUNC_ENTRY(); LOG_FMT(LSPLIT, "%s(%d)\n", __func__, __LINE__); for (chunk_t *pc = chunk_get_head(); pc != nullptr; pc = chunk_get_next(pc)) { if ( !chunk_is_newline(pc) && !chunk_is_comment(pc) && pc->type != CT_SPACE && is_past_width(pc)) { if ( pc->type == CT_VBRACE_CLOSE // don't break if a vbrace close && chunk_is_last_on_line(*pc)) // is the last chunk on its line { continue; } bool split_OK = split_line(pc); if (split_OK) { LOG_FMT(LSPLIT, "%s(%d): on orig_line=%zu, orig_col=%zu, for %s\n", __func__, __LINE__, pc->orig_line, pc->orig_col, pc->text()); } else { LOG_FMT(LSPLIT, "%s(%d): Bailed on orig_line=%zu, orig_col=%zu, for %s\n", __func__, __LINE__, pc->orig_line, pc->orig_col, pc->text()); break; } } } }
static void ace_printacl(acl_t *aclp, int cols, int compact) { int slot = 0; char *token; char *acltext; if (compact) { ace_compact_printacl(aclp); return; } acltext = acl_totext(aclp, 0); if (acltext == NULL) return; token = strtok(acltext, ","); if (token == NULL) { free(acltext); return; } do { (void) printf(" %d:", slot++); split_line(token, cols - 5); } while (token = strtok(NULL, ",")); free(acltext); }
/* load_needed -- load files containing needed modules */ static void load_needed() { FILE *fp; int i; char *name; for (i = 0; i < nmodules; i++) { if (!module[i].m_needed) continue; name = module[i].m_file; err_file = name; fp = fopen(name, "r"); if (fp == NULL) { perror(name); exit(2); } while (fgets(line, MAXLINE, fp) != NULL) { nwords = split_line(line, words); if (nwords == 0) continue; put_inst(words[0], &words[1], nwords-1); } fclose(fp); } }
unsigned split_line (SplitStringLine *result, unsigned max_lines, unsigned wid, std::wstring_view s) { unsigned offset = 0; unsigned lines = 0; for (; lines < max_lines && offset < s.length(); ++lines) { offset = split_line(result++, wid, s, offset, 0); } return lines; }
FeatureGroup::FeatureGroup(FeatureGroupInfo& fg_info, const std::string& str) { ft_ = fg_info.feature_type(); std::vector<std::string> values = split_line(str, " "); if (fg_info.feature_type() == DENSE) { // format: 1 2 4 5 6 7 feat_vals.resize(values.size()); if (fg_info.size() == 0) { fg_info.set_length(values.size()); } else { CHECK_EQ(fg_info.size(), values.size()); } std::transform(values.begin(), values.end(), feat_vals.begin(), [](const std::string& str){ return std::stod(str); }); } else if (fg_info.feature_type() == SPARSE_BINARY) { // format: 1 2 4 5 6 7 feat_ids.resize(values.size()); std::transform(values.begin(), values.end(), feat_ids.begin(), [&](const std::string& str){ return fg_info.get_index(str, true); } ); } else { // format, 1:2 2:3 3:4 feat_ids.resize(values.size()); feat_vals.resize(values.size()); size_t idx = 0; for (auto& p : values) { std::vector<std::string> kv_pairs = split_line(p, ":"); CHECK_EQ(kv_pairs.size(), 2); feat_ids[idx] = fg_info.get_index(kv_pairs[0], true); feat_vals[idx] = std::stod(kv_pairs[1]); ++idx; } } }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); FrCommandIso *comm_iso = FR_COMMAND_ISO (comm); char **fields; const char *name_field; g_return_if_fail (line != NULL); if (line[0] == 'd') /* Ignore directories. */ return; if (line[0] == 'D') { g_free (comm_iso->cur_path); comm_iso->cur_path = g_strdup (get_last_field (line, 4)); } else if (line[0] == '-') { /* Is file */ const char *last_field, *first_bracket; fdata = file_data_new (); fields = split_line (line, 8); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6], fields[7]); g_strfreev (fields); /* Full path */ last_field = get_last_field (line, 9); first_bracket = strchr (last_field, ']'); if (first_bracket == NULL) { file_data_free (fdata); return; } name_field = eat_spaces (first_bracket + 1); if ((name_field == NULL) || (strcmp (name_field, ".") == 0) || (strcmp (name_field, "..") == 0)) { file_data_free (fdata); return; } if (comm_iso->cur_path[0] != '/') fdata->full_path = g_strstrip (g_strconcat ("/", comm_iso->cur_path, name_field, NULL)); else fdata->full_path = g_strstrip (g_strconcat (comm_iso->cur_path, name_field, NULL)); fdata->original_path = fdata->full_path; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); fr_command_add_file (comm, fdata); } }
uint16_t BinAsm::get_data(const std::string& line, uint16_t* target, std::string& err) { std::vector<std::string> datas = split_line(line); for (std::vector<std::string>::iterator k=datas.begin(); k!=datas.end(); k++) { std::string p = *k; std::transform(p.begin(), p.end(), p.begin(), ::tolower); if (p == ".dat" || p == "dat") { uint16_t size = 0; for (std::vector<std::string>::iterator i=k+1; i!=datas.end(); i++) { if (i->size() > 0 && (*i)[0] == '"') { for (unsigned int j=0; j < i->size()-1;j++) { if ((*i)[j-1] == '\\') { switch ((*i)[j+1]) { case 'n': target[size] = '\n'; case 't': target[size] = '\t'; case '\\': target[size] = '\\'; case 'r': target[size] = '\r'; default: err = "invalid special symbol value "+(*i); return 0; } } else if ((*i)[j] == '\\') continue; else target[size] = (*i)[j]; size++; } } else { target[size] = get_value(*i, err); size++; } } return size; } } return 0; }
static gboolean parse_file(config_t *cfg, const char *file, const command_t *cmd) { char buf[200]; int line = 0; FILE *fp = fopen(file, "r"); if (!fp) { snprintf(error_msg, sizeof(error_msg), _("%s: fopen(): %s"), file, strerror(errno)); return FALSE; } while (fgets(buf, sizeof(buf), fp)) { const command_t *c = cmd; GPtrArray *args; char **argv; line++; args = split_line(buf); argv = (char **) args->pdata; if (args->len == 0) { g_ptr_array_free(args, TRUE); continue; } while (c->name != NULL && strcasecmp(c->name, argv[0]) != 0) c++; if (c->name == NULL) { snprintf(error_msg, sizeof(error_msg), _("%s:%d: unknown command `%s'"), file, line, argv[0]); g_ptr_array_free(args, TRUE); fclose(fp); return FALSE; } if (!(c->handler(cfg, args->len, argv))) { char *ss = g_strdup(error_msg); snprintf(error_msg, sizeof(error_msg), _("%s:%d: %s"), file, line, ss); g_free(ss); g_ptr_array_free(args, TRUE); fclose(fp); return FALSE; } g_ptr_array_free(args, TRUE); } fclose(fp); return TRUE; }
void print_hello(char *argv){ char chunk[LENGTH]; split_line(chunk,argv,rank); unsigned char result[MD5_DIGEST_LENGTH]; MD5(chunk,strlen(chunk),result); if (cmpmd5(result)==0) { printf("\n[%d.%d] Match found! Answer is %s\n",rank,size,chunk); MPI_Abort(MPI_COMM_WORLD,0); } }
int get_host_port(char **host_ptr, int *port_ptr, char *line) { char *argv[2]; int argc = split_line(argv, NELEM(argv), line, ":", ""); if(argc != 2) return(-1); *host_ptr = argv[0]; *port_ptr = atoi(argv[1]); if(*port_ptr < 1 || *port_ptr > 65535) return(-2); return(0); }
static void process_datafile (char *filename) { register int i, counter = 0; char buffer[2048]; char *line; FILE *input_stream, *output_stream; current_filename = filename; current_line_number = 0; input_stream = fopen (filename, "r"); if (!input_stream) { fprintf (stderr, "Can't open the data input file `%s'.\n", filename); return; } output_stream = fopen (database_filename, "a+"); if (!output_stream) { fprintf (stderr, "Can't open the data output file `%s'.\n", database_filename); fclose (input_stream); return; } while ((line = fgets (buffer, sizeof (buffer) - 1, input_stream)) != (char *)NULL) { char **fields; current_line_number++; /* Okay, clean up the line. */ for (i = strlen (line) - 1; i > -1; i--) { if ((line[i] == '\n') || (line[i] == '\r')) line[i] = '\0'; else break; } fields = split_line (line, FieldSep); counter++; dump_data (fields, output_stream); free_array (fields); } fclose (input_stream); fclose (output_stream); fprintf (stderr, "Dumped %d records to %s\n", counter, database_filename); }
int load_site_config() { FILE *fp; char config_path[255]; char line[255]; int i =0; get_config_path(config_path); fp = fopen(config_path, "r"); if (fp == NULL) { printf("Error ! \n"); return -1; } while (fgets(line, 255, fp) != NULL) { char var[255]; char value[255]; /* avoid comments */ if (line[0] == '#') continue; if (split_line(line, var, value) != 0) continue; strcpy(config_site.var[i].var, var); /* If this variable is empty we use config_site.dest_directory * as default value. This way it is faster to get a first try * of the software without setting/understanding this variable. */ if (strcmp(var, "site_url") == 0) { char path[PATH_MAX+1]; char site_url[PATH_MAX+1]; getcwd(path, PATH_MAX); sprintf(site_url, "%s/%s", path, config_site.dest_directory); strcpy(config_site.var[i].value, site_url); } else { strcpy(config_site.var[i].value, value); } i++; } strcpy(config_site.var[i].var, ""); strcpy(config_site.var[i].value, ""); fclose(fp); return 0; }
int main() { StringPiece pesho = StringPiece("I like pie ||| 123154"); StringPiece kiro = StringPiece("Kiro is a stupid brat ||| 12351"); line_text tmp; tmp = split_line(kiro); std::cout << tmp.text << " " << tmp.value << std::endl; return 0; }
int read_i(t_list **av_list) { char *line; *av_list = NULL; line = NULL; while (line == NULL) { if (get_next_line(0, &line) < 0) return (1); } return (split_line(av_list, line)); }
static void process_line (char *line, gpointer data) { GimvImageInfo *fdata = NULL; FRCommand *comm = FR_COMMAND (data); char **fields; char *name_field; char *filename; struct stat st; g_return_if_fail (line != NULL); fields = split_line (line, 5); memset (&st, 0, sizeof (struct stat)); st.st_size = atol (fields[2]); st.st_mtime = mktime_from_string (fields[3], fields[4]); mkugid_from_string (fields[1], &st.st_uid, &st.st_gid); st.st_mode = mkmode_from_string (fields[0]); g_strfreev (fields); /* Full path */ name_field = get_last_field (line); fields = g_strsplit (name_field, " -> ", 2); if (!fields[1]) { g_strfreev (fields); fields = g_strsplit (name_field, " link to ", 2); } if (*(fields[0]) == '/') { filename = fields[0] + 1; } else { filename = fields[0]; } if (*filename && *comm->filename) { fdata = gimv_image_info_get_with_archive (filename, FR_ARCHIVE (comm->archive), &st); } if (fdata) { if (fields[1]) gimv_image_info_set_link (fdata, fields[1]); comm->file_list = g_list_prepend (comm->file_list, fdata); } g_strfreev (fields); }
static void process_line(t_tokenline *tl) { t_token *tokens; int words[TL_MAX_WORDS], num_words, i; tl->print(tl->user, NL); do { if (!tl->buf_len) break; history_add(tl); if (!split_line(tl, words, &num_words, FALSE)) break; if (!num_words) break; if (!strcmp(tl->buf + words[0], "help")) { if (num_words == 1) { /* * Nothing to tokenize: find the help entry * if any so its help text can be shown. */ tokens = tl->token_levels[tl->token_level]; for (i = 0; tokens[i].token; i++) { if (tokens[i].arg_type == T_ARG_HELP) { tl->parsed.last_token_entry = &tokens[i]; break; } } } else { /* Tokenize with errors turned off. */ tokenize(tl, words + 1, num_words - 1, &tokens, NULL); } show_help(tl, words, num_words); } else if (!strcmp(tl->buf + words[0], "history")) { history_show(tl); } else { if (!tokenize(tl, words, num_words, NULL, NULL)) break; if (tl->callback) tl->callback(tl->user, &tl->parsed); } } while (FALSE); tl->buf[0] = 0; tl->buf_len = 0; tl->escape_len = 0; tl->pos = 0; tl->hist_step = -1; tl->print(tl->user, tl->prompt); }
SplitStringLineList split_line(unsigned wid, std::wstring_view s) { SplitStringLineList ret; if (wid < 2) { // Robustness. Avoid dead loops for (size_t k = 0; k < s.length(); ++k) { ret.push_back({k, 1, ucs_width(s[k])}); } } else { for (unsigned offset = 0; offset < s.length(); ) { SplitStringLine line; offset = split_line(&line, wid, s, offset, 0); ret.push_back(std::move(line)); } } return ret; }
main (int argc, char **argv) #endif { #if defined(_WIN32_WCE) int argc; char cmdline[256], *argv[32]; WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)lpCmdLine, 255, cmdline, 256, NULL, NULL); argc = split_line(argv+1, 32, cmdline)+1; #endif connection_dispatch_loop(argc, argv, mbasc_slave_init, NULL, 0); return 0; }
std::vector<Individual> read_individuals(std::string dose_path) { gz::igzstream dose_file( dose_path.c_str( ) ); std::vector<Individual> individual_list; std::string line; while( std::getline( dose_file, line ) ) { std::vector<std::string> splitted_line = split_line( line ); Individual individual = create_individual( splitted_line ); individual_list.push_back( individual ); } return individual_list; }
void filter_line ( char *line ) { static int ignore_file = 0; if (strncmp (line, "==> ", 4) == 0) { extract_set_component (line); // missed_functions = 0; } else if (strncmp (line, "Creating ", 9) == 0) { line_segments segm; if (ignore_file == 0) { split_line (line, &segm); register_missed_functions (segm[1], missed_functions); } else { ignore_file = 0; } missed_functions = 0; } else if (strstr (line, "/opt/nds/ACE_wrappers")) { /* skip this file */ ignore_file = 1; } else if (strstr (line, "/usr/include/c++")) { /* skip this file */ ignore_file = 1; } else if (strstr (line, "/opt/s2dev")) { /* skip this file */ ignore_file = 1; } else if (strstr (line, "testsuite")) { /* skip this file */ ignore_file = 1; } else if (strstr (line, "source lines executed in file")) { line_segments segm; split_line (line, &segm); create_le_statistics (segm[0], segm[2], segm[8]); } else if (strstr (line, "lines executed in file")) { line_segments segm; split_line (line, &segm); create_le_statistics (segm[0], segm[2], segm[7]); } else if (strstr (line, "branches executed in file")) { line_segments segm; split_line (line, &segm); create_be_statistics (segm[0], segm[2], segm[7]); } else if (strstr (line, "branches taken at least once in file")) { } else if (strstr (line, "calls executed in file")) { line_segments segm; split_line (line, &segm); create_ce_statistics (segm[0], segm[2], segm[7]); } else if (strstr (line, "lines executed in function")) { line_segments segm; split_line (line, &segm); if (strcmp (segm[0], "0.00%") == 0) { missed_functions++; } } }
std::vector<Locus> read_loci(std::string info_path) { gz::igzstream info_file( info_path.c_str( ) ); std::vector<Locus> locus_list; std::string line; std::getline( info_file, line ); // Skip header while( std::getline( info_file, line ) ) { std::vector<std::string> splitted_line = split_line( line ); Locus locus = create_locus( splitted_line ); locus_list.push_back( locus ); } return locus_list; }
std::map<std::string, std::string> LogAudit::populateDenialMap() { std::ifstream bug_file("/system/etc/selinux/selinux_denial_metadata"); std::string line; // allocate a map for the static map pointer in auditParse to keep track of, // this function only runs once std::map<std::string, std::string> denial_to_bug; if (bug_file.good()) { std::string scontext; std::string tcontext; std::string tclass; std::string bug_num; while (std::getline(bug_file, line)) { std::stringstream split_line(line); split_line >> scontext >> tcontext >> tclass >> bug_num; denial_to_bug.emplace(scontext + tcontext + tclass, bug_num); } }
/** * Step forward until a token goes beyond the limit and then call split_line() * to split the line at or before that point. */ void do_code_width(void) { chunk_t *pc; LOG_FMT(LSPLIT, "%s\n", __func__); for (pc = chunk_get_head(); pc != NULL; pc = chunk_get_next(pc)) { if (!chunk_is_newline(pc) && !chunk_is_comment(pc) && (pc->type != CT_SPACE) && is_past_width(pc)) { split_line(pc); } } }
void OPT_ALGO::load_data(std::string data_file, std::string split_tag){ std::ifstream fin(data_file.c_str(), std::ios::in); if(!fin) std::cerr<<"open error get feature number..."<<data_file<<std::endl; int y = 0; while(getline(fin,line)){ feature_index.clear(); key_val.clear(); //return id:value, .e.g 3:1, 4:1 split_line(split_tag, feature_index); y = atof(feature_index[0].c_str()); label.push_back(y); //3:1 as input get_feature_struct(); fea_matrix.push_back(key_val); } fin.close(); }