bool spellchecker(std::string &word, std::unordered_set<std::string> &dictionary) { enum STRING_CASE word_case = test_string_case(word); std::string word_temp(word); std::unordered_set<std::string> possible_words; switch(word_case) { case STRING_CASE_All_Upper: possible_words.insert(word); string_to_lower(word_temp, 1); case STRING_CASE_First_Upper: possible_words.insert(word_temp); string_to_lower(word_temp); case STRING_CASE_Lower: possible_words.insert(word_temp); break; case STRING_CASE_Mixed: default: possible_words.insert(word); } for(auto test : possible_words) { if(dictionary.find(test) != dictionary.end()) return true; } return false; }
node_t* ns_search(namespace_t* ns, const char* name, int state, int type){ node_t* temp_node; int i, match; char *name_lower; if (!(name_lower = string_to_lower(name))){ printf("memory error\n"); return 0; } i = 0; for (temp_node=*(ns->members); temp_node; temp_node=temp_node->next){ char *node_name_lower; if (!(node_name_lower = string_to_lower(ns->cb(temp_node)))){ printf("memory error\n"); free(name_lower); return 0; } match = 0; switch (type){ case SEARCH_EXACT: if (!(strcmp(name_lower, node_name_lower))) match = 1; break; case SEARCH_SUBSTRING: if (!(strstr(node_name_lower, name_lower))) match = 1; break; case SEARCH_INITIAL_SUBSTRING: if ((node_name_lower) == (strstr(node_name_lower, name_lower))) match = 1; break; default: break; } free(node_name_lower); if ((match)&&(i++ >= state)){ free(name_lower); return temp_node; } } free(name_lower); return 0; }
bool Utilities::compare(string input_1, string input_2) { if (string_to_lower(input_1) == string_to_lower(input_2)) return true; else return false; }
bool HttpMessage :: has_header_field( std::string key ){ std::string lkey = string_to_lower( key ); // String case independent compare for( std::map<std::string, std::string>::iterator it = header.begin(); it != header.end() ; it++ ){ if( string_to_lower(it->first) == lkey ){ return true; } } return false; }
std::string HttpMessage :: get_header_field( std::string key ){ std::string lkey = string_to_lower( key ); // String case independent compare for( std::map<std::string, std::string>::iterator it = header.begin(); it != header.end() ; it++ ){ if( string_to_lower(it->first) == lkey ){ return it->second; } } return std::string(); }
/* returns the matching main category array index or -1 of not found */ int valid_main_category(char * category) { int i; char str0[BLOCK_SIZE], str1[BLOCK_SIZE]; string_to_lower(category,str1); for (i = 0; i < no_of_main_categories; i++) { string_to_lower(category_main[i], str0); if (strcmp(str0,str1) == 0) { return i; } } return -1; }
bool OpeningBook::set_first_and_last(string last_move_string, unsigned depth) { bool entry_found = false; if (first > last) { cerr << "You should have never seen this message. Something must "; cerr << "have gone terribly wrong in the book." << endl; } last_move_string = string_to_lower(last_move_string); for (unsigned int index = first; index <= last; index++) { if (book[index].size() > depth) { if (book[index][depth].compare(last_move_string) == 0) { first = index; entry_found = true; break; } } } if (!entry_found) { book_open = false; return false; } for (unsigned int index = first; index <= last; index++) { if (book[index].size() > depth) { if (book[index][depth].compare(last_move_string) != 0) { last = index - 1; break; } } } return true; }
ImageFormat::Type ImageFormat::determine_type_from_extension(const std::string &file_name) { const std::string extension = string_to_lower(std::experimental::filesystem::path(file_name).extension()); auto extension_is_any_of = [&](const std::vector<std::string> &strs) { return std::find(strs.begin(), strs.end(), extension) != strs.end(); }; if (extension_is_any_of({".exr"})) return Type::EXR; if (extension_is_any_of({".jpg", ".jpeg", ".jpe"})) return Type::JPEG; if (extension_is_any_of({".png"})) return Type::PNG; if (extension_is_any_of({".icb", ".targa", ".tga", ".tpic", ".vda", ".vst"})) return Type::TGA; if (extension_is_any_of({".webp"})) return Type::WEBP; return Type::UNDETERMINED; }
void read_file_word_by_word(char *filename, list_t *list) { check(filename != NULL, "Given filename was null."); check(list != NULL, "list was NULL."); FILE *fp1 = NULL; char string[500]; char c; fp1 = fopen(filename, "r"); check(fp1 != NULL, "Could not open file: %s.", filename); do { c = fscanf(fp1, "%s", string); if(c != EOF) { string_to_lower(string); if(validate_word(string) != 0) { char *temp_word = string; check(dl_insert(list, temp_word) == 1, "Did not insert '%s' properly,", temp_word); } } } while(c != EOF); fclose(fp1); return; error: if(list != NULL) { dl_clear_destroy(list); } exit(1); }
static void test_string_to_lower() { char *string = string_duplicate("Hello World"); string_to_lower(string); CU_ASSERT_STRING_EQUAL(string, "hello world"); free(string); }
/** * @NAME: string_capitalized * @DESC: Capitaliza un string */ void string_capitalized(char *text) { if (!string_is_empty(text)) { _string_upper_element(text); if (strlen(text) >= 2){ string_to_lower(&text[1]); } } }
enum rarch_content_type path_is_media_type(const char *path) { char ext_lower[128]; ext_lower[0] = '\0'; strlcpy(ext_lower, path_get_extension(path), sizeof(ext_lower)); string_to_lower(ext_lower); switch (msg_hash_to_file_type(msg_hash_calculate(ext_lower))) { #ifdef HAVE_FFMPEG case FILE_TYPE_OGM: case FILE_TYPE_MKV: case FILE_TYPE_AVI: case FILE_TYPE_MP4: case FILE_TYPE_FLV: case FILE_TYPE_WEBM: case FILE_TYPE_3GP: case FILE_TYPE_3G2: case FILE_TYPE_F4F: case FILE_TYPE_F4V: case FILE_TYPE_MOV: case FILE_TYPE_WMV: case FILE_TYPE_MPG: case FILE_TYPE_MPEG: case FILE_TYPE_VOB: case FILE_TYPE_ASF: case FILE_TYPE_DIVX: case FILE_TYPE_M2P: case FILE_TYPE_M2TS: case FILE_TYPE_PS: case FILE_TYPE_TS: case FILE_TYPE_MXF: return RARCH_CONTENT_MOVIE; case FILE_TYPE_WMA: case FILE_TYPE_OGG: case FILE_TYPE_MP3: case FILE_TYPE_M4A: case FILE_TYPE_FLAC: case FILE_TYPE_WAV: return RARCH_CONTENT_MUSIC; #endif #ifdef HAVE_IMAGEVIEWER case FILE_TYPE_JPEG: case FILE_TYPE_PNG: case FILE_TYPE_TGA: case FILE_TYPE_BMP: return RARCH_CONTENT_IMAGE; #endif case FILE_TYPE_NONE: default: break; } return RARCH_CONTENT_NONE; }
bool read_file_word_by_word(FILE *fp, list_t *list, int actual_offset, int child_read_size, int size){ check(list != NULL, "list was NULL."); check(fp != NULL, "file was NULL"); int offset = fseek(fp, actual_offset, SEEK_SET); check_debug(offset == 0, "fseek returned non-zero."); if(actual_offset != 0){ offset = fseek(fp, -1, SEEK_CUR); int cur_character; do { cur_character = fgetc(fp); if(isspace(cur_character) != 0){ break; } else { offset = fseek(fp, -2, SEEK_CUR); } } while(isspace(cur_character) == 0 && cur_character != EOF && offset == 0); actual_offset = ftell(fp); if((size - (actual_offset + child_read_size)) < child_read_size){ child_read_size = size - actual_offset; } } int byte_count = 0; char string[512]; int c; do { c = fscanf(fp, "%s", string); byte_count = ftell(fp) - actual_offset; if(byte_count < child_read_size || (actual_offset + byte_count) == size){ if(c != EOF){ string_to_lower(string); if(validate_word(string) != 0){ char *temp_word = string; check(dl_insert(list, temp_word) == 1, "Did not insert '%s' properly,", temp_word); } } } else { } } while(c != EOF && byte_count < child_read_size); return 1; error: return 0; }
String StringUtil::ToLower(CStrRef input, ToLowerType type /*= ToLowerAll */) { if (input.empty()) return input; int len = input.size(); char *ret = nullptr; switch (type) { case ToLowerAll: ret = string_to_lower(input.data(), len); break; case ToLowerFirst: ret = string_to_lower_first(input.data(), len); break; case ToLowerWords: ret = string_to_lower_words(input.data(), len); break; default: assert(false); break; } return String(ret, len, AttachString); }
int parse_rc_line(const char *line, struct Rc *rc) { assert(line); assert(rc); if (has_key(line, "hostname")) { rc->hostname = strdup(has_key(line, "hostname")); if (!rc->hostname) return EXIT_FAILURE; } if (has_key(line, "macaddr")) { rc->macaddr = strdup(has_key(line, "macaddr")); if (!rc->macaddr) return EXIT_FAILURE; string_to_lower(rc->macaddr); } if (has_key(line, "uuidcmd")) { rc->uuidcmd = strdup(has_key(line, "uuidcmd")); if (!rc->uuidcmd) return EXIT_FAILURE; } return EXIT_SUCCESS; }
int process_dirblk(CIFBLK *cif, int noext, DSXTENT extent[], BYTE *dirblk, char* dsname, char *pdsmember, unsigned long optflags) { int rc; int dirrem; char memname[9]; static const BYTE endofdir[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; /* Load number of bytes in directory block */ dirrem = (dirblk[0] << 8) | dirblk[1]; if (dirrem < 2 || dirrem > 256) { // "Directory block byte count is invalid" FWRMSG( stderr, HHC02400, "E" ); return -1; } /* Point to first directory entry */ dirblk += 2; dirrem -= 2; while (dirrem > 0) { PDSDIR *dirent = (PDSDIR*)dirblk; int k, size; /* Check for end of directory */ if (memcmp( endofdir, dirent->pds2name, 8 ) == 0) return +1; /* (logical EOF) */ /* Extract this member's name */ make_asciiz(memname, sizeof(memname), dirent->pds2name, 8); if (optflags & OPT_PDS_LISTONLY) { char memname_lc[9]; /* List just the member names in this PDS */ memcpy(memname_lc, memname, sizeof(memname)); string_to_lower(memname_lc); puts(memname_lc); } else { /* Are we interested in this specific member? */ if (0 || (optflags & OPT_PDS_WILDCARD) || strcmp( pdsmember, memname ) == 0 ) { if (optflags & OPT_PDS_WILDCARD && !(optflags & OPT_MEMINFO_ONLY)) printf("> Member %s\n", memname); else if (1 && !(optflags & OPT_MEMINFO_ONLY) && !isatty( fileno( stdout )) ) { /* Delete any existing o/p file contents */ rewind( stdout ); ftruncate( fileno( stdout ), 0 ); } rc = process_member(cif, noext, extent, dirent->pds2ttrp, optflags, dsname, memname); if (rc < 0) return -1; /* If not ALL members then we're done */ if (!(optflags & OPT_PDS_WILDCARD)) { found = 1; return +1; /* (logical EOF) */ } } } /* Load the user data halfword count */ k = dirent->pds2indc & PDS2INDC_LUSR; /* Point to next directory entry */ size = 12 + k*2; dirblk += size; dirrem -= size; } return 0; }
int read_pexoII_info(NemSpread<T,INT> &spreader, const char *filename) /* * This function reads the ASCII parallel-exodus command file. * * Input * ----- * filename - The name of the command file. */ { /* local declarations */ static const char *yo = "read_pexoII_info"; FILE *file_cmd; char inp_line[MAX_INPUT_STR_LN + 1]; char inp_copy[MAX_INPUT_STR_LN + 1]; char *cptr, *cptr2, *cptr3; int i, icnt, tlist_alloc; /***************************** BEGIN EXECUTION ******************************/ /* Open the file */ if((file_cmd=fopen(filename, "r")) == NULL) return -1; /* Begin parsing the input file */ while(fgets(inp_line, MAX_INPUT_STR_LN, file_cmd)) { /* skip any line that is a comment */ if((inp_line[0] != '#') && (inp_line[0] != '\n')) { strcpy(inp_copy, inp_line); clean_string(inp_line, " \t"); cptr = strtok(inp_line, "\t="); /****** The input ExodusII file name ******/ if (token_compare(cptr, "input fem file")) { if(strlen(ExoFile) == 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); strcpy(ExoFile, cptr); } } /****** The input NemesisI load balance file name ******/ else if (token_compare(cptr, "lb file")) { if(strlen(Exo_LB_File) == 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); strcpy(Exo_LB_File, cptr); } } /****** The scalar results ExodusII file name ******/ else if (token_compare(cptr, "scalar results fem file")) { if(strlen(Exo_Res_File) == 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); strcpy(Exo_Res_File, cptr); } } /****** The parallel results ExodusII file name ******/ else if (token_compare(cptr, "parallel results file base name")) { if (strlen(Output_File_Base_Name) == 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); strcpy(Output_File_Base_Name, cptr); } } /****** The Number of Processors ******/ else if (token_compare(cptr, "number of processors")) { if (spreader.Proc_Info[0] < 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); if(sscanf(cptr, "%d", &(spreader.Proc_Info[0])) != 1) { fprintf(stderr, "%s: ERROR, can\'t interpret int for number of" " Processors.\n", yo); exit(1); } } } /****** The File extension to use for spread files ******/ else if (token_compare(cptr, "file extension for spread files")) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); strcpy(PIO_Info.Exo_Extension, cptr); } /****** Is There a Scalar Mesh File to Use ******/ else if (token_compare(cptr, "use scalar mesh file")) { if (Gen_Flag < 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); if (Gen_Flag < 0) { if (token_compare(cptr, "yes")) Gen_Flag = 1; else Gen_Flag = 0; } } } /****** The Debug reporting level ******/ else if (token_compare(cptr, "debug")) { if (Debug_Flag < 0) { cptr = strtok(NULL, "\t="); strip_string(cptr, " \t\n"); if(sscanf(cptr, "%d", &Debug_Flag) != 1) { fprintf(stderr, "%s: ERROR, can\'t interpret int for Debug_Flag\n", yo); exit(1); } } } /****** Restart Time List ******/ else if (token_compare(cptr, "restart info")) { cptr = strchr(cptr, '\0'); cptr++; /* * If there is a list, then need to change the comma's in * the list to blank spaces so that the strtok below works * correctly. So, search for commas between the beginning * delimiter, "{", and the end delimiter, "}", and change * them to blank spaces. */ cptr2 = strchr(cptr, '{'); if (cptr2 != NULL) { icnt = strlen(cptr2); for (i = 0; i < icnt; i++) { if (*cptr2 == '}') break; if (*cptr2 == ',') *cptr2 = ' '; cptr2++; } } strip_string(cptr," \t\n="); cptr = strtok(cptr, ","); /* Loop until all the suboptions have been specified */ while(cptr != NULL) { strip_string(cptr, " \t\n"); string_to_lower(cptr, '\0'); /* check if the user wants to specifically turn this off */ if (strcmp(cptr, "off") == 0) { if (spreader.Restart_Info.Flag < 0) { spreader.Restart_Info.Flag = 0; spreader.Restart_Info.Num_Times = 0; } } /* check if the user wants all of the time steps */ else if (strcmp(cptr, "all") == 0) { if (spreader.Restart_Info.Flag < 0) { spreader.Restart_Info.Flag = 1; spreader.Restart_Info.Num_Times = -1; /* -1 designates read all times */ } } /* IGNORED check if the user wants move variable in blocks IGNORED */ else if (strstr(cptr, "block")) { cptr2 = strchr(cptr, '='); if(cptr2 == NULL) { fprintf(stderr, "fatal: must specify a value with \"block\""); exit(1); } cptr2++; } /* check if the user has a list of time indices to get */ else if (strstr(cptr, "list")) { /* "{" defines the beginning of the group designator */ cptr2 = strchr(cptr, '{'); if (cptr2== NULL) { fprintf(stderr, "fatal: list start designator \"{\" not found"); exit(1); } cptr2++; cptr3 = strchr(cptr, '}'); if (cptr3== NULL) { fprintf(stderr, "fatal: list end designator \"}\" not found"); exit(1); } *cptr3 = '\0'; /* Allocate the time list */ spreader.Restart_Info.Time_Idx.resize(TLIST_CNT); tlist_alloc = TLIST_CNT; spreader.Restart_Info.Num_Times = 0; while (cptr2) { /* first check to see if they want to get the last time index */ if (strncmp(cptr2, "last", 4) == 0) { icnt = 0; spreader.Restart_Info.Time_Idx[spreader.Restart_Info.Num_Times] = 0; } else { icnt = sscanf(cptr2, "%d", &(spreader.Restart_Info.Time_Idx[spreader.Restart_Info.Num_Times])); } if(icnt >= 0) (spreader.Restart_Info.Num_Times)++; if (spreader.Restart_Info.Num_Times >= tlist_alloc) { tlist_alloc += TLIST_CNT; spreader.Restart_Info.Time_Idx.resize(tlist_alloc); } /* move to the next blank space */ cptr3 = strchr(cptr2, ' '); if (cptr3) { /* find the next non-blank space */ while (*cptr3 == ' ') cptr3++; } cptr2 = cptr3; } } else { fprintf(stderr, "warning: unknown restart info suboption %s", cptr); exit(1); } cptr = strtok(NULL, ","); } } /* End "if (token_compare(cptr, "restart time list"))" */ /****** Reserved Space for Variables ******/ else if (token_compare(cptr, "reserve space")) { cptr = strchr(cptr, '\0'); cptr++; strip_string(cptr," \t\n="); cptr = strtok(cptr, ","); while (cptr != NULL) { strip_string(cptr, " \t\n"); string_to_lower(cptr, '='); if (strstr(cptr, "nodal")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &Num_Nod_Var); if ((icnt <= 0) || (Num_Nod_Var < 0)) { fprintf(stderr, "Error: Invalid value for nodal variable\n"); return 0; } } else if (strstr(cptr, "elemental")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &Num_Elem_Var); if ((icnt <= 0) || (Num_Elem_Var < 0)) { fprintf(stderr, "Error: Invalid value for elemental variable\n"); return 0; } } else if (strstr(cptr, "global")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &Num_Glob_Var); if ((icnt <= 0) || (Num_Glob_Var < 0)) { fprintf(stderr, "Error: Invalid value for global variable\n"); return 0; } } else if (strstr(cptr, "nodeset")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &Num_Nset_Var); if ((icnt <= 0) || (Num_Nset_Var < 0)) { fprintf(stderr, "Error: Invalid value for nodeset variable\n"); return 0; } } else if (strstr(cptr, "sideset")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &Num_Sset_Var); if ((icnt <= 0) || (Num_Sset_Var < 0)) { fprintf(stderr, "Error: Invalid value for sideset variable\n"); return 0; } } cptr = strtok(NULL, ","); } /* End "while (cptr != NULL)" */ } /* End "else if (token_compare(cptr, "reserve space"))" */ /****** Parallel Disk Information ******/ else if (token_compare(cptr, "parallel disk info")) { cptr = strchr(cptr, '\0'); cptr++; strip_string(cptr," \t\n="); cptr = strtok(cptr, ","); strip_string(cptr, " \t\n"); string_to_lower(cptr, '='); /* the first sub-option must be "number" */ if (!strstr(cptr, "number")) { fprintf(stderr, "Error: First sup-option for disk info must be " "\"number\"\n"); return 0; } else { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: integer value must be specified for" " reserve space.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &(PIO_Info.Num_Dsk_Ctrlrs)); if ((icnt <= 0) || (PIO_Info.Num_Dsk_Ctrlrs <= 0)) { fprintf(stderr, "Error: Invalid value for # of raid controllers\n"); return 0; } } cptr = strtok(NULL, ","); while (cptr != NULL) { strip_string(cptr, " \t\n"); string_to_lower(cptr, '='); if (strstr(cptr, "list")) { /* * So, "number" references the length of the list, and * I need to do some shuffling to make the new form * work with the old code. */ PIO_Info.Dsk_List_Cnt = PIO_Info.Num_Dsk_Ctrlrs; PIO_Info.Num_Dsk_Ctrlrs = 0; /* "{" defines the beginning of the list */ cptr = strchr(cptr, '{'); if (cptr == NULL) { fprintf(stderr, "Error: disk list must be specified\n"); return 0; } cptr++; /* allocate memory for to hold the values */ PIO_Info.Dsk_List = (int *) array_alloc(__FILE__, __LINE__, 1, PIO_Info.Dsk_List_Cnt, sizeof(int)); for (i = 0; i < (PIO_Info.Dsk_List_Cnt - 1); i++) { sscanf(cptr, "%d", &(PIO_Info.Dsk_List[i])); cptr = strtok(NULL, ", \t;"); } /* last one is a special case */ sscanf(cptr, "%d}", &(PIO_Info.Dsk_List[i])); } else if (strstr(cptr, "offset")) { cptr2 = strchr(cptr, '='); if (cptr2 == NULL) { fprintf(stderr, "Error: value must be specified with the " "\"offset\" option.\n"); return 0; } cptr2++; icnt = sscanf(cptr2, "%d", &(PIO_Info.PDsk_Add_Fact)); if ((icnt <= 0) || (PIO_Info.PDsk_Add_Fact < 0)) { fprintf(stderr, "Error: Invalid value for offset\n"); return 0; } } else if (strstr(cptr, "zeros")) { PIO_Info.Zeros = 1; } else if (strstr(cptr, "nosubdirectory")) { PIO_Info.NoSubdirectory = 1; } else if (strstr(cptr, "stage_off")) { strcpy(PIO_Info.Staged_Writes, "no"); } else if (strstr(cptr, "stage_on")) { strcpy(PIO_Info.Staged_Writes, "yes"); } cptr = strtok(NULL, ","); } } /* End "else if (token_compare(cptr, "parallel disk info"))" */ else if (token_compare(cptr, "parallel file location")) { cptr = strchr(cptr, '\0'); cptr++; strip_string(cptr," \t\n="); cptr = strtok(cptr, ","); while (cptr != NULL) { strip_string(cptr, " \t\n"); string_to_lower(cptr, '='); if (strstr(cptr, "root")) { cptr2 = strchr(cptr, '='); if(cptr2 == NULL) { fprintf(stderr, "fatal: must specify a path with \"root\""); return 0; } cptr2++; if(strlen(cptr2) == 0) { fprintf(stderr, "fatal: invalid path name specified with" " \"root\""); return 0; } strcpy(PIO_Info.Par_Dsk_Root, cptr2); } if (strstr(cptr, "subdir")) { cptr2 = strchr(cptr, '='); if(cptr2 == NULL) { fprintf(stderr, "fatal: must specify a path with \"subdir\""); return 0; } cptr2++; if(strlen(cptr2) == 0) { fprintf(stderr, "fatal: invalid path name specified with" " \"subdir\""); return 0; } strcpy(PIO_Info.Par_Dsk_SubDirec, cptr2); if (PIO_Info.Par_Dsk_SubDirec[strlen(PIO_Info.Par_Dsk_SubDirec)-1] != '/') strcat(PIO_Info.Par_Dsk_SubDirec, "/"); } cptr = strtok(NULL, ","); } } } /* End "if(inp_line[0] != '#')" */ } /* End "while(fgets(inp_line, MAX_INPUT_STR_LN, file_cmd))" */ if (strlen(Output_File_Base_Name) == 0 && strlen(Exo_LB_File) != 0) { // User did not specify a base name. Use the basenmae of the // Exo_LB_File instead. strcpy(Output_File_Base_Name, Exo_LB_File); // If there is an extension, strip it off... char *cPtr = strrchr(Output_File_Base_Name, '.'); if (cPtr != NULL) { *cPtr = '\0'; } } /* Close the command file */ fclose(file_cmd); return 0; }
int main(int argc, char *argv[]){ int pid = 0; int i = 0; int child = 0; int status; char *first_param = "2"; int num_children = atoi(first_param); int children[num_children]; struct stat st; char *file_name = "./dllist.c"; int size = 0; stat(file_name, &st); size = st.st_size; printf("file_name: %s, file_size: %d\n", file_name, size); FILE *fp = fopen(file_name, "r"); int child_read_size = size / num_children; int child_segment_size = 0; for(i = 0; i < NUM_ELEMS(children); i++){ child_segment_size += child_read_size; pid = fork(); if(pid != 0){ children[i] = pid; printf("child_pid: %d\n", pid); waitpid(children[i], &status, 0); } else { child = 1; break; } } if(child == 0){ printf("parent process, pid: %d\n", getpid()); } else { printf("child process, pid: %d, ppid: %d\n", pid, getppid()); printf("\tchild_start: %d, child_end: %d\n", child_segment_size - child_read_size, child_segment_size); int actual_offset = child_segment_size - child_read_size; int offset = fseek(fp, actual_offset, SEEK_SET); printf("\toffset: %d\n", offset); int ch = 0; int byte_count = 0; char string_buffer[512]; if(actual_offset != 0){ int cur_character; do{ cur_character = fgetc(fp); if(isspace(cur_character) == 0){ offset = fseek(fp, -2, SEEK_CUR); } else { offset = fseek(fp, -1, SEEK_CUR); } } while(isspace(cur_character) == 0 && (cur_character != EOF && offset == 0)); printf("\t\tftell(fp): %lu\n", ftell(fp)); } int word_count = 0; list_t *list = NULL; list = dl_init(); do { ch = fscanf(fp, "%s", string_buffer); if(actual_offset != 0 && byte_count == 0){ printf("\t\tfirst_word: %s\n", string_buffer); } byte_count = ftell(fp) - (actual_offset); if(string_buffer[0] == '\0'){ printf("\t\twhitespace_at_bytecount: %d\n", byte_count); } if(byte_count < child_read_size || (actual_offset + byte_count) == size){ if(ch != EOF){ string_to_lower(string_buffer); if(validate_word(string_buffer) != 0){ char *temp_word = string_buffer; check(dl_insert(list, temp_word) == 1, "Did not insert '%s' properly.", temp_word); word_count++; } } else { printf("\t\tlast_word_file: %s\n", string_buffer); } } else { printf("\t\tlast_word: %s\n", string_buffer); } } while( ch != EOF && byte_count < child_read_size); dl_clear_destroy(list); printf("\tbyte_count: %d, word_count: %d\n", byte_count, word_count); fclose(fp); exit(0); } rewind(fp); int temp; char temp_buffer[512]; int true_wordcount = 0; do{ temp = fscanf(fp, "%s", temp_buffer); if(temp != EOF){ true_wordcount++; } } while(temp != EOF); fclose(fp); printf("true_wordcount: %d\n", true_wordcount); return 0; error: return 1; }
static PRESULT usbupg_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2) { UINT8 bID; UINT16 sel,block_idx,*Uni_str; UINT32 block_len; char str_buf[20] = {0}; char str_extend[4] = {0}; char str_filter[4] = {0}; PRESULT ret = PROC_PASS; USBUPG_FILENODE filenode; MULTISEL *pMsel; bID = OSD_GetObjID(pObj); switch(event) { case EVN_REQUEST_STRING: sel = param1; Uni_str= (UINT16*)param2; // NOTICE: Uni_str size is 32 (#define MAX_STR_LEN 32) in obj_multisel.c if(bID == UPG_MODE_ID) { ComUniStrCopyChar(Uni_str,OSD_GetUnicodeString(usb_upgrade_type_name[sel])); //memcpy(str_buf, usb_upgrade_type_name[sel], STRLEN(usb_upgrade_type_name[sel])); //ComAscStr2Uni(str_buf, Uni_str); } else if(bID == UPG_FILE_ID) { if(usbupg_files_cnt == 0) { pMsel = &usbupg_sel_upgrade_type; usbupg_get_file_filter(OSD_GetMultiselSel(pMsel), str_extend, str_filter); string_to_lower(str_extend); #ifdef USBUPG_UPGFILE_FILTER string_to_lower(str_filter); #else str_filter[0] = 0; #endif { UINT16 *pStr=NULL; UINT16 uni_string[50]={0}; UINT16 uni_string2[50]={0}; pStr = OSD_GetUnicodeString(RS_NO_FILE); ComUniStrCopyChar(&uni_string,(UINT16 *)pStr); sprintf(str_buf, "(%s*.%s)", str_filter, str_extend); ComAscStr2Uni(str_buf, uni_string2); ComUniStrCat(&uni_string,uni_string2); ComUniStrCopyChar(Uni_str,uni_string); //sprintf(str_buf, "No File(%s*.%s)", str_filter, str_extend); //ComAscStr2Uni(str_buf, Uni_str); } } else { usbupg_get_filenode(&filenode,sel); filenode.upg_file_name[31] = 0; ComAscStr2Uni(filenode.upg_file_name, Uni_str); } } else { ComAscStr2Uni("", Uni_str); } break; case EVN_POST_CHANGE: if(bID == 1) { sel = param1; usbupg_create_filelist(sel,&usbupg_files_cnt); pMsel = &usbupg_filelist_sel; OSD_SetMultiselSel(pMsel, 0); OSD_SetMultiselCount(pMsel, (usbupg_files_cnt)); OSD_DrawObject((POBJECT_HEAD)pMsel,C_UPDATE_ALL); } break; default: break; } return ret; }
static PRESULT sys_backup_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2) { UINT8 bID,back_saved; UINT16 block_idx,file_idx,popup_strid; INT32 vscr_idx,length,fileread_ret; char str_buff[20]; void *pBuff; BOOL burnflash_ret; VACTION unact; PRESULT ret; PMULTISEL pMsel; lpVSCR apVscr; win_popup_choice_t choice; UINT8 tmp[4]; UINT8 block_name[20]; UINT8 file_extention[4]; UINT8 file_name[24]; UINT32 chunk_offset; USB_BACKUP_MODE_TYPE_E usb_backup_mode; ret = PROC_PASS; bID = OSD_GetObjID(pObj); switch(event) { case EVN_UNKNOWN_ACTION: unact = (VACTION)(param1>>16); if(unact == VACT_ENTER && bID == START_ID) { // start_backup =1; win_sys_backup_msg_clear(); win_sys_backup_process_update(0); vscr_idx = osal_task_get_current_id(); apVscr = OSD_GetTaskVscr(vscr_idx); popup_strid = RS_SYS_BACKUP_ALERT_NOPLUG; win_compopup_init(WIN_POPUP_TYPE_SMSG); win_compopup_set_msg(NULL,NULL, popup_strid); win_compopup_open_ext(&back_saved); osal_task_sleep(2000); win_compopup_smsg_restoreback(); OSD_SetAttr(&sys_backup_item_con1, C_ATTR_INACTIVE); OSD_SetAttr(&sys_backup_item_con2, C_ATTR_INACTIVE); OSD_DrawObject( (POBJECT_HEAD)&sys_backup_item_con1, C_UPDATE_ALL); OSD_DrawObject( (POBJECT_HEAD)&sys_backup_item_con2, C_UPDATE_ALL); pMsel = &sys_backup_sel_upgrade_type; usb_backup_mode = OSD_GetMultiselSel(pMsel); switch(usb_backup_mode) { case EM_BACKUP_MODE_TOTAL_FLASH: block_idx = 0; break; case EM_BACKUP_MODE_USER_DATA: block_idx = usbupg_get_block_index(USBUPG_USERDB); break; #ifdef EANBLE_BAKUP_CCCAM_NEWCAMD_DATA case EM_BACKUP_MODE_CCCAM_NEWCAMD: block_idx = usbupg_get_block_index(USBUPG_CCCAM_NEWCAMD); break; #endif #ifdef ENABLE_SOFT_CAM_KEY case EM_BACKUP_MODE_SOFTCAM: block_idx = usbupg_get_block_index(USBUPG_SOFTCAM); break; #endif default: // start_backup =0; ASSERT(0); return; } usbupg_get_blockinfo(block_idx, block_name, &chunk_offset); usb_backup_get_file_filter(usb_backup_mode, file_extention, tmp); sprintf(file_name, "%s.%s", block_name, file_extention); string_to_lower(file_name); //libc_printf("[sys_backup_item_callback]block_idx = %d, block_name = %s, file_extention = %s, file_name = %s", block_idx, block_name, file_extention, file_name); #ifdef EANBLE_BAKUP_CCCAM_NEWCAMD_DATA if(EM_BACKUP_MODE_CCCAM_NEWCAMD == usb_backup_mode) { //save the cccam data and newcamd data(first 16 group data) ret = usbupg_dump_flash2(CccamNewcamdBackup,(64*1024),file_name, win_sys_backup_process_update); } else #endif #ifdef ENABLE_SOFT_CAM_KEY if(EM_BACKUP_MODE_SOFTCAM == usb_backup_mode) { //save the softcam data ret = usbupg_dump_flash2(softcam_backup, 64*1024,file_name, win_sys_backup_process_update); } else #endif { #if 1//def WANGYANG ret = usbupg_dump_flash3(block_idx, file_name, win_sys_backup_process_update,win_progress_bar_draw_bmp); #else ret = usbupg_dump_flash(block_idx, file_name, win_sys_backup_process_update); #endif } if (ret ==RET_SUCCESS) { popup_strid = RS_MSG_BACKUP_SUCCESS; } else { popup_strid = RS_OTA_UPGRADE_FAIL; } ERROR_HANDLER: OSD_SetAttr(&sys_backup_item_con1, C_ATTR_ACTIVE); OSD_SetAttr(&sys_backup_item_con2, C_ATTR_ACTIVE); OSD_DrawObject( (POBJECT_HEAD)&sys_backup_item_con1, C_UPDATE_ALL); OSD_TrackObject( (POBJECT_HEAD)&sys_backup_item_con2, C_UPDATE_ALL); OSD_UpdateVscr(apVscr); // start_backup =0; if(popup_strid != 0) { win_sys_backup_msg_update(popup_strid); win_compopup_init(WIN_POPUP_TYPE_SMSG); win_compopup_set_msg(NULL,NULL, popup_strid); win_compopup_open_ext(&back_saved); osal_task_sleep(2000); win_compopup_smsg_restoreback(); } return ret; } break; } return ret; }
/*-------------------------------------------------------------------*/ static int process_member (CIFBLK *cif, int noext, DSXTENT extent[], char *memname, BYTE *ttr) { int rc; /* Return code */ U16 len; /* Record length */ u_int trk; /* Relative track number */ U32 cyl; /* Cylinder number */ U8 head; /* Head number */ U8 rec; /* Record number */ BYTE *buf; /* -> Data block */ FILE *ofp; /* Output file pointer */ char ofname[256]; /* Output file name */ int offset; /* Offset of record in buffer*/ char card[81]; /* Logical record (ASCIIZ) */ char pathname[MAX_PATH]; /* ofname in host format */ /* Build the output file name */ memset (ofname, 0, sizeof(ofname)); strncpy (ofname, memname, 8); string_to_lower (ofname); strlcat (ofname, ".mac", sizeof(ofname)); /* Open the output file */ hostpath(pathname, ofname, sizeof(pathname)); ofp = fopen (pathname, (asciiflag? "w" : "wb")); if (ofp == NULL) { FWRMSG( stderr, HHC02468, "E", ofname, "fopen", strerror( errno )); return -1; } /* Point to the start of the member */ trk = (ttr[0] << 8) | ttr[1]; rec = ttr[2]; WRMSG( HHC02469, "I", memname, trk, rec ); /* Read the member */ while (1) { /* Convert relative track to cylinder and head */ rc = convert_tt (trk, noext, extent, cif->heads, &cyl, &head); if (rc < 0) return -1; // fprintf (stderr, // "CCHHR=%4.4X%4.4X%2.2X\n", // cyl, head, rec); /* Read a data block */ rc = read_block (cif, cyl, head, rec, NULL, NULL, &buf, &len); if (rc < 0) return -1; /* Move to next track if record not found */ if (rc > 0) { trk++; rec = 1; continue; } /* Exit at end of member */ if (len == 0) break; /* Check length of data block */ if (len % 80 != 0) { FWRMSG( stderr, HHC02470, "E", len, cyl, head, rec ); return -1; } /* Process each record in the data block */ for (offset = 0; offset < len; offset += 80) { if (asciiflag) { make_asciiz (card, sizeof(card), buf + offset, 72); fprintf (ofp, "%s\n", card); } else { fwrite (buf+offset, 80, 1, ofp); } if (ferror(ofp)) { FWRMSG( stderr, HHC02468, "E", ofname, "fwrite", strerror( errno )); return -1; } } /* end for(offset) */ /* Point to the next data block */ rec++; } /* end while */ /* Close the output file and exit */ fclose (ofp); return 0; } /* end function process_member */
String StringUtil::ToLower(CStrRef input) { if (input.empty()) return input; int len = input.size(); char *ret = string_to_lower(input.data(), len); return String(ret, len, AttachString); }
lista_t* operacao_inclui(lista_t *operacoes, lista_t *agencias, lista_t *contas) { operacao_t *operacao = NULL; agencia_t *agencia; conta_t *conta; bool done = false; bool operacao_tipo_ok = false; bool operacao_ok = false; bool agencia_ok = false; bool conta_ok = false; bool confirmar = false; char *str = NULL; operacao = (operacao_t*)malloc(sizeof(operacao_t)); operacao->montante = 0.0; operacao->conta_destino_numero = 0; agencia = (agencia_t*)malloc(sizeof(agencia_t)); conta = (conta_t*)malloc(sizeof(conta_t)); printf("--- Realizando nova tranzacao ---\n"); while (!done) { if (!operacao_ok) { printf("Codigo: "); str = string_get(OPERACAO_CODIGO_MAX_LEN); if (check_cancelar(str)) { free(str); return operacoes; } operacao->codigo = (unsigned int)atoi(str);; free(str); str = NULL; if (lista_busca(operacoes, operacao, compara_operacao)) { printf("A operacao de codigo %d ja existe. Use um numero diferente.\n", operacao->codigo); continue; } operacao_ok = true; } if (!agencia_ok) { printf("Agencia codigo: "); str = string_get(AGENCIA_CODIGO_MAX_LEN); if (check_cancelar(str)) { free(str); return operacoes; } agencia->codigo = (unsigned int)atoi(str); free(str); str = NULL; if (!lista_busca(agencias, agencia, compara_agencia)) { printf("A agencia de codigo %d nao existe.\n", agencia->codigo); continue; } agencia_ok = true; } if (!conta_ok) { printf("Numero da conta: "); str = string_get(CONTA_NUMERO_MAX_LEN); if (check_cancelar(str)) { free(str); return operacoes; } conta->numero = (unsigned int)atoi(str); free(str); str = NULL; if (!lista_busca(contas, conta, compara_conta)) { printf("A conta de numero %d nao existe.\n", conta->numero); continue; } conta_ok = true; operacao->agencia_codigo = agencia->codigo; } if (!operacao_tipo_ok) { printf("Tipo de operacao (saldo, pagamento, saque, transferencia): "); str = string_get(OPERACAO_TIPO_MAX_LEN); if (check_cancelar(str)) { free(str); return operacoes; } string_to_lower(str); if (compara_string("saldo", str)) operacao->tipo = Saldo; else if (compara_string("pagamento", str)) operacao->tipo = Pagamento; else if (compara_string("saque", str)) operacao->tipo = Saque; else if (compara_string("transferencia", str)) operacao->tipo = Transferencia; else { printf("Operacao desconhecida: %s. Tente novamente.\n", str); free(str); str = NULL; continue; } operacao_tipo_ok = true; operacao->conta_numero = conta->numero; } if ((operacao_tipo_ok) && (operacao->tipo == Transferencia)) { printf("Numero da conta de destino da transferencia: "); str = string_get(CONTA_NUMERO_MAX_LEN); if (check_cancelar(str)) { free(str); return operacoes; } conta->numero = (unsigned int)atoi(str); free(str); str = NULL; if (!lista_busca(contas, conta, compara_conta)) { printf("A conta de numero %d nao existe.\n", conta->numero); continue; } conta_ok = true; operacao->conta_destino_numero = conta->numero; } operacao->data = get_time(); printf("---\nDados fornecidos:\n"); operacao_imprime(operacao); if (true == confirmar_opcao()) { done = true; } else { done = false; operacao_ok = false; agencia_ok = false; conta_ok = false; operacao_tipo_ok = false; } } confirmar = false; if (operacao->tipo == Saldo) { operacao_saldo(operacao, contas); confirmar = true; } else if (operacao->tipo == Pagamento) { if (operacao_pagamento(operacoes, operacao, contas)) confirmar = true; } else if (operacao->tipo == Saque) { if (operacao_saque(operacoes, operacao, contas)) confirmar = true; } else if (operacao->tipo == Transferencia) { if (operacao_transferencia(operacoes, operacao, contas)) confirmar = true; } if (confirmar == true) return lista_insere(operacoes, operacao); else return operacoes; }
/** * This function shows the main menu * * @v info_s * @return none * @date 2014-04-14 * @author PL Team **/ void show_menu() { int menu_choose; int control; // to verify if it is not a char! char player1nameAux[MAX_PLAYERNAME_LENGTH]=""; char player2nameAux[MAX_PLAYERNAME_LENGTH]=""; do { clearscr(); printf("Triplets Game\n\n"); printf("1. Play : Player vs Computer (PvC)\n"); printf("2. Play : Player vs Player (PvP)\n"); printf("3. Game rules\n"); printf("4. High scores\n"); printf("5. Replay game\n"); printf("6. Credits\n\n"); printf("7. Exit Game.\n\n"); printf("(Choose an option and press enter): "); control=scanf("%d",&menu_choose); clean_buffer_keyboard(); } while (menu_choose<1 || menu_choose>7 || control == 0); switch(menu_choose) { case 1: G_current_game.game_mode=pvc; G_current_game.pvp_mode = notpvp; show_difficulty(); choose_interface(); clearscr(); printf("Triplets - Player vs Computer \n\n"); do { printf("Enter your name: "); fgets(G_players[0].name, MAX_PLAYERNAME_LENGTH, stdin); terminate_string_at_first_slash_n(G_players[0].name); strcpy(player1nameAux,G_players[0].name); string_to_lower(player1nameAux); if (!strcmp(player1nameAux,"cpu")) { printf("Invalid name.\n"); } } while (!strcmp(player1nameAux,"cpu")); strcpy(G_players[1].name, "CPU");// G_players[1] is cpu player choose_board(); show_who_first(); break; case 2: G_current_game.game_mode=pvp; G_current_game.cpu_mode = none; clearscr(); printf("Triplets - Player vs Player\n"); do { printf("Enter the name of player 1: "); fgets(G_players[0].name, MAX_PLAYERNAME_LENGTH, stdin); terminate_string_at_first_slash_n(G_players[0].name); strcpy(player1nameAux,G_players[0].name); string_to_lower(player1nameAux); if (!(strcmp(player1nameAux,"cpu"))) { printf("Invalid name.\n"); } } while (!(strcmp(player1nameAux,"cpu"))); do { printf("\nEnter the name of player 2: "); fgets(G_players[1].name, MAX_PLAYERNAME_LENGTH, stdin); terminate_string_at_first_slash_n(G_players[1].name); strcpy(player2nameAux,G_players[1].name); string_to_lower(player2nameAux); if (!(strcmp(player2nameAux,"cpu")) || !(strcmp(player2nameAux,player1nameAux))) { printf("Invalid name.\n"); } } while (!(strcmp(player2nameAux,"cpu")) || !(strcmp(player2nameAux,player1nameAux))); show_pvp_mode(); if (G_current_game.pvp_mode == normal) { choose_interface(); } else { G_current_game.interface_mode = console; } choose_board(); show_who_first(); break; case 3: show_game_rules(); show_menu(); break; case 4: //show High scores// show_highscores(); show_menu(); break; case 5: replay_menu(); // this is in PT_save_read_moves.c show_menu(); break; case 6: show_credits(); show_menu(); break; case 7: exit(0); break; default: clearscr(); show_menu(); break; } }