void patches(void){ //Change version string for(int i = 0; i < 0x600000; i+=4){ if(strcomp((void*)0x27B00000 - i, (void*)L"Ver.", 4)){ if(strcomp((void*)0x27B00000 - i + 0x28, (void*)"T_ver_00", 4)) strcopy((void*)0x27B00000 - i, (void*)L"\uE024Rei", 4); } } }
void patches(void){ //Change version string for(int i = 0; i < 0x600000; i+=4){ if(strcomp((void*)0x27B00000 - i, (void*)L"Ver.", 4)){ if(strcomp((void*)0x27B00000 - i + 0x0A, (void*)L"%d.%d.%d-%d", 11)) strcopy((void*)0x27B00000 - i, (void*)L"\uE024Rei", 4); } } }
int getIfaceFilePolluts() // // Input: none // Output: returns an error code // Purpose: reads names of pollutants saved on the inflows interface file. // { int i, j; char line[MAXLINE+1]; // line from inflows interface file char s1[MAXLINE+1]; // general string variable char s2[MAXLINE+1]; // --- read number of pollutants (minus FLOW) fgets(line, MAXLINE, Finflows.file); sscanf(line, "%d", &NumIfacePolluts); NumIfacePolluts--; if ( NumIfacePolluts < 0 ) return ERR_ROUTING_FILE_FORMAT; // --- read flow units fgets(line, MAXLINE, Finflows.file); sscanf(line, "%s %s", s1, s2); if ( !strcomp(s1, "FLOW") ) return ERR_ROUTING_FILE_FORMAT; IfaceFlowUnits = findmatch(s2, FlowUnitWords); if ( IfaceFlowUnits < 0 ) return ERR_ROUTING_FILE_FORMAT; //// This section was moved out of the if (...) statement below it //// //(5.0.017 - LR) //// so that not all pollutants have to be in the interface file. //// //(5.0.017 - LR) // --- allocate memory for pollutant index array if ( Nobjects[POLLUT] > 0 ) { IfacePolluts = (int *) calloc(Nobjects[POLLUT], sizeof(int)); if ( !IfacePolluts ) return ERR_MEMORY; for (i=0; i<Nobjects[POLLUT]; i++) IfacePolluts[i] = -1; } // --- read pollutant names & units if ( NumIfacePolluts > 0 ) { // --- check each pollutant name on file with project's pollutants for (i=0; i<NumIfacePolluts; i++) { if ( feof(Finflows.file) ) return ERR_ROUTING_FILE_FORMAT; fgets(line, MAXLINE, Finflows.file); sscanf(line, "%s %s", s1, s2); if ( Nobjects[POLLUT] > 0 ) { j = project_findObject(POLLUT, s1); if ( j < 0 ) continue; if ( !strcomp(s2, QualUnitsWords[Pollut[j].units]) ) return ERR_ROUTING_FILE_NOMATCH; IfacePolluts[j] = i; } } } return 0; }
int main() { char *str = "string"; char *wrd = "word"; char src[] = "source"; char dest[] = "destination"; char concat[ strlength(dest) + strlength(src) ]; char empty[100]; char a[] = "abc"; char b[] = "ab"; int i = 1; printf( "Testing strlength with string: %s\n", str ); printf( "String length: %d \n", strlength( str ) ); printf( "Testing strlength with string: %s\n", wrd ); printf( "String length: %d\n", strlength( wrd ) ); printf( "\n" ); printf( "Testing strcopy with string: %s\n", src ); printf( "Testing strcopy with string: %s\n", empty ); strcopy( empty, src ); printf("Empty string is now: %s\n", empty ); printf( "\n" ); printf( "Testing strconcat with string: %s\n", src ); printf( "Testing strconcat with string: %s\n", dest ); printf( "Appends the first: %d character(s) \n", i ); strconcatn( concat, dest, src, i ); printf( "Concatenated string: %s\n", concat ); printf( "\n" ); printf( "Testing strcomp with string: abc and ab \n" ); printf( "%d\n", strcomp( a, b ) ); printf( "Testing strcomp with string: abc and abc \n" ); printf( "%d\n", strcomp( a, a ) ); printf( "This answer is wrong! Still working on it." ); printf( "\n" ); printf( "Testing strchar with string: %s. Return place if found -1 if not found\n", src ); printf( "Looking for s \n" ); printf( "%d\n", strchar( src, 's' ) ); printf( "Looking for 1 \n" ); printf( "%d\n", strchar( src, '1' ) ); printf( "Looking for e \n" ); printf( "%d\n", strchar( src, 'e' ) ); printf( "\n" ); printf( "Testing strstring with strings %s and %s. Return 1 if found -1 if not found \n", a, b ); printf( "%d This answer is wrong! I used my strcomp (broken method for now) in this method which is why it churned out the wrong answer. \n", strstring( a, b ) ); return 0; }
void iface_openRoutingFiles() // // Input: none // Output: none // Purpose: opens routing interface files. // { // --- initialize shared variables NumIfacePolluts = 0; IfacePolluts = NULL; NumIfaceNodes = 0; IfaceNodes = NULL; OldIfaceValues = NULL; NewIfaceValues = NULL; // --- check that inflows & outflows files are not the same if ( Foutflows.mode != NO_FILE && Finflows.mode != NO_FILE ) { if ( strcomp(Foutflows.name, Finflows.name) ) { report_writeErrorMsg(ERR_ROUTING_FILE_NAMES, ""); return; } } // --- open the file for reading or writing if ( Foutflows.mode == SAVE_FILE ) openFileForOutput(); if ( Finflows.mode == USE_FILE ) openFileForInput(); }
// main com operacoes uteis para testar funcionamento das rotinas implementadas int main(void) { Lista* l1 = criaLista(), * l2 = criaLista(), * x; char* str = (char*) calloc(20, sizeof(char)); int resultado; insereLetra(l1, 's'); // insere sempre no inicio da lista insereLetra(l1, 'a'); insereLetra(l2, 'c'); insereLetra(l2, 'u'); insereLetra(l2, 'l'); //concatena x = strconcat(l2, l1); // converte para string listconvertstr(x, str); //imprime string printf("Normal: %s\n", str); //inverte lista x=strconvertlist(str); x = strinvert(x); //converte para string listconvertstr(x, str); //imprime string printf("Invertida: %s\n", str); //compara x com sua inversa resultado=strcomp(x,strinvert(x)); //imprime resultado if(resultado==0) printf(" -> Iguais\n"); else printf(" -> Diferentes\n"); getchar(); getchar(); return 0; }
int parseStdLine(char *line, int *year, int *month, int *day, int *hour, int *minute, float *value) // // Input: line = line of data from a standard rainfall data file // Output: *year = year when rainfall occurs // *month = month of year when rainfall occurs // *day = day of month when rainfall occurs // *hour = hour of day when rainfall occurs // *minute = minute of hour when rainfall occurs // *value = rainfall value (user units); // returns 0 if data line could not be parsed successfully or // 1 if line parsed successfully // Purpose: parses a line of data from a standard rainfall data file. // { char seps[] = " ,\t\n"; // token separator characters char *token; // string token *year = 1; *month = 1; *day = 1; *hour = 0; *minute = 0; *value = 0.0; ////////////////////////////////////////////////// //// Modified to check station ID. (LR - 7/5/06 ) ////////////////////////////////////////////////// // --- get and check station ID token = strtok(line, seps); if ( token == NULL ) return 0; if ( StationID != NULL && !strcomp(token, StationID) ) return 0; // --- parse year, month, and day token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getInt(token, year) ) return 0; token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getInt(token, month) ) return 0; token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getInt(token, day) ) return 0; // --- parse hour and minute token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getInt(token, hour) ) return 0; token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getInt(token, minute) ) return 0; // --- parse rainfall value token = strtok(NULL, seps); if ( token == NULL ) return 0; if ( !getFloat(token, value) ) return 0; return 1; }
main () { int cand_1, cand_2, cand_3, cand_4, branco, nulo, num_voto, total; char cont[1]; cand_1 = 0; cand_2 = 0; cand_3 = 0; cand_4 = 0; branco = 0; nulo = 0; total = 0; cont = 's'; while (strcomp(cons,'s')) { total++; printf("Digite o número de seu candidato:\n"); printf("1-Tiririca\n"); printf("2-Batoré\n"); printf("3-Vovó da Fiel\n"); printf("4-Mulher Pêra\n"); printf("5-Branco\n"); printf("\n"); scanf("%i",&num_voto); switch (num_voto) { case 1: cand_1 ++; break; case 2: cand_2 ++; break; case 3: cand_3 ++; break; case 4: cand_4 ++; break; case 5: branco ++; break; else: nulo++; } printf("Mais algum eleitor para votar?\n[s/n]"); scanf("%s",&cont); }
void openFiles(char *f1, char *f2, char *f3) // // Input: f1 = name of input file // f2 = name of report file // f3 = name of binary output file // Output: none // Purpose: opens a project's input and report files. // { // --- initialize file pointers to NULL Finp.file = NULL; Frpt.file = NULL; Fout.file = NULL; // --- save file names sstrncpy(Finp.name, f1, MAXFNAME); sstrncpy(Frpt.name, f2, MAXFNAME); sstrncpy(Fout.name, f3, MAXFNAME); // --- check that file names are not identical if (strcomp(f1, f2) || strcomp(f1, f3) || strcomp(f2, f3)) { writecon(FMT11); ErrorCode = ERR_FILE_NAME; return; } // --- open input and report files if ((Finp.file = fopen(f1,"rt")) == NULL) { writecon(FMT12); writecon(f1); ErrorCode = ERR_INP_FILE; return; } if ((Frpt.file = fopen(f2,"wt")) == NULL) { writecon(FMT13); ErrorCode = ERR_RPT_FILE; return; } }
void insertInStart(const char str[]){ int i,len=strlen(str); if(len<count) return; if(len>count) count=len; for(i=0;i<row;i++){ if(strcomp(str,&start[i][0])==0) return; else if(strcomp(str,&start[i][0])==1) continue; else{ slideDD(i); strcpy(&start[i][0],str); return; } } strcpy(&(start[row][0]),str); row=row+1; }
unsigned char get_filetype_postdel(GLOBAL *g, char *ext) { if (!(*ext)) return 255; if (strcomp(audio_types, ext)) { g->v.misc.release_type = RTYPE_AUDIO; } if (!strcasecmp(ext, "sfv")) return 1; if (!clear_file(g->l.race, g->v.file.name)) return 4; if (!strcasecmp(ext, "zip")) return 0; if (!strcasecmp(ext, "nfo")) return 2; if (!strcomp(ignored_types, ext) || !strcomp(allowed_types, ext)) return 3; return 255; }
int rainFileConflict(Project* project, int i) // // Input: i = rain gage index // Output: returns 1 if file conflict found, 0 if not // Purpose: checks if a rain gage's station ID matches another gage's // station ID but the two use different rain data files. // { int j; char* staID = project->Gage[i].staID; char* fname = project->Gage[i].fname; for (j = 1; j < i; j++) { if ( strcomp(project->Gage[j].staID, staID) && !strcomp(project->Gage[j].fname, fname) ) { report_writeErrorMsg(project,ERR_RAIN_FILE_CONFLICT, project->Gage[i].ID); return 1; } } return 0; }
int main() try { // test new duplicate function char a[] = "test"; char* a_dpl = strdupl(a,5); print_str(a_dpl); cout << "\n"; char b[] = { 't','e','s','t' }; char* b_dpl = strdupl(b,4); print_str(b_dpl); cout << "\n"; delete[] b_dpl; delete[] a_dpl; // test new find substring function char s[] = "xxxtestxxx"; char x[] = "test"; char* sub = findx(s,x); print_str(sub); cout << "\n"; char s2[] = { 'x','x','t','e','s','t','x','x' }; char x2[] = { 't','e','s','t' }; char* sub2 = findx(s2,x2,8,4); print_str(sub2,6); cout << "\n"; // test new comparison function char str1[] = "atest"; char str2[] = "btest"; cout << str1 << " to " << str2 << " is " << strcomp(str1,str2) << "\n"; char str3[] = { 't','e','s','t','1' }; char str4[] = { 't','e','s','t','1', 'a' }; cout << str3 << " to " << str4 << " is " << strcomp(str3,str4,5,6) << "\n"; } catch (exception& e) { cerr << "exception: " << e.what() << endl; } catch (...) { cerr << "exception\n"; }
int comp(struct node * current, EleType n){ if(current ==0) return 0; if (strcmp(current->value,n)==0){ return 1; if (strcomp(n,current-> value)<=0){ return comp(current->left, n); } else{ return comp(current->right, n); } } }
tree* treefind(tree* t, char *s){ tree* tmp = t; if(tmp!=NULL){ //printf("%s %s %d\n",tmp->s,s,strcomp(tmp->s,s)); if(strcomp(tmp->s,s)==0){ //printf("here!\n"); result = tmp; } else{ for(tmp=tmp->child;tmp!=NULL;tmp=tmp->sibling) treefind(tmp,s); } } return result; }
int strstring( char a[], char b[] ) { int i; int j; for (i = 0; i < strlength( a ); i++ ) { j = 0; char c[100]; while ( j < strlength( b ) ) { c[j] = b[j]; j++; } if ( strcomp( c, b ) == 1 ) return 1; } return -1; }
int findExactMatch(char *s, char *keyword[]) // // Input: s = character string // keyword = array of keyword strings // Output: returns index of keyword which matches s or -1 if no match found // Purpose: finds exact match between string and array of keyword strings. // { int i = 0; while (keyword[i] != NULL) { if ( strcomp(s, keyword[i]) ) return(i); i++; } return(-1); }
/*Main program*/ int main() { char *str1; char *str2; char *str3; int opt; printf("Enter the option: \ 1.Copy \ 2.Compare \ 3.Concate \ 4.Reverse \ 5.Length \n"); scanf("%d",&opt); str1=(char *)malloc(sizeof(char)); printf("Enter String 1\n"); scanf("%s",str1); str2=(char *)malloc(sizeof(char)); printf("Enter String2\n"); scanf("%s",str2); str3=(char *)malloc(sizeof(char)); switch(opt) { case 1:strcopy(str3,str2); break; case 2:strcomp(str1,str2); break; case 3:strconcat(str1,str2); break; case 4:strrever(str1,str3); break; case 5:strlength(str1); break; default:printf("Wrong input selection \n"); break; } }
main() { char temp[1000]; int i = 0; char Strings[NUM][LEN]; printf("Please enter %d strings, one per line:\n", NUM); for(i; i<25; i++){ fgets(&Strings[i][0], LEN,stdin); } i=0; puts("\nHere are the strings in the order you entered:"); for (i; i<25; i++){ printf("%s\n",Strings[i]); } int j=1,k=0,l=0,m=0, sorted=1; // line 26 i=1; for(k=0;k<25;k++){ for(i=1;i<25;i++){ if(strcomp(Strings[i],Strings[i-1])>0){ strcpy(temp,Strings[i-1]); strcpy(Strings[i-1],Strings[i]); strcpy(Strings[i],temp); }}} puts("\nIn alphabetical order, the strings are:"); for(i=0;i<NUM;i++){ printf("%s",Strings[i]); } return 0; }
static int diff_print_one_compact( const git_diff_delta *delta, float progress, void *data) { diff_print_info *pi = data; git_buf *out = pi->buf; char old_suffix, new_suffix, code = git_diff_status_char(delta->status); int (*strcomp)(const char *, const char *) = pi->diff ? pi->diff->strcomp : git__strcmp; GIT_UNUSED(progress); if (code == ' ') return 0; old_suffix = diff_pick_suffix(delta->old_file.mode); new_suffix = diff_pick_suffix(delta->new_file.mode); git_buf_clear(out); if (delta->old_file.path != delta->new_file.path && strcomp(delta->old_file.path,delta->new_file.path) != 0) git_buf_printf(out, "%c\t%s%c -> %s%c\n", code, delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); else if (delta->old_file.mode != delta->new_file.mode && delta->old_file.mode != 0 && delta->new_file.mode != 0) git_buf_printf(out, "%c\t%s%c (%o -> %o)\n", code, delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode); else if (old_suffix != ' ') git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix); else git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path); if (git_buf_oom(out)) return -1; if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(out), git_buf_len(out), pi->payload)) return callback_error(); return 0; }
void minmax_c(uchar *a[], int n, uchar **min, uchar **max) { int i, c; if(n == 1) { *min = *max = a[0]; return; } c = strcomp(a[0], a[1]); if(c == 0) *min = *max = a[0]; else if(c < 0) { *min = a[0]; *max = a[1]; } else { *min = a[1]; *max = a[0]; } for(i = n - 1; i > 2; i -= 2) { if(strcomp(a[i], a[i - 1]) >= 0) { if(strcomp(*max, a[i])) *max = a[i]; if(strcomp(*min, a[i - 1])) *min = a[i - 1]; } else { if(strcomp(*max, a[i - 1])) *max = a[i - 1]; if(strcomp(*min, a[i])) *min = a[i]; } } if(n % 2) if(strcomp(*max, a[2])) *max = a[2]; if(strcomp(*min, a[2])) *min = a[2]; }
static void comparison (lua_Type ttype_less, lua_Type ttype_equal, lua_Type ttype_great, IMS op) { struct Stack *S = &L->stack; TObject *l = S->top-2; TObject *r = S->top-1; int32 result; if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) result = (int32)strcomp(svalue(l), tsvalue(l)->u.s.len, svalue(r), tsvalue(r)->u.s.len); else { call_binTM(op, "unexpected type in comparison"); return; } S->top--; nvalue(S->top-1) = 1; ttype(S->top-1) = (result < 0) ? ttype_less : (result == 0) ? ttype_equal : ttype_great; }
static int diff_print_one_name_status( const git_diff_delta *delta, float progress, void *data) { diff_print_info *pi = data; git_buf *out = pi->buf; char old_suffix, new_suffix, code = git_diff_status_char(delta->status); int (*strcomp)(const char *, const char *) = pi->diff ? pi->diff->strcomp : git__strcmp; GIT_UNUSED(progress); if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ') return 0; old_suffix = diff_pick_suffix(delta->old_file.mode); new_suffix = diff_pick_suffix(delta->new_file.mode); git_buf_clear(out); if (delta->old_file.path != delta->new_file.path && strcomp(delta->old_file.path,delta->new_file.path) != 0) git_buf_printf(out, "%c\t%s%c %s%c\n", code, delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); else if (delta->old_file.mode != delta->new_file.mode && delta->old_file.mode != 0 && delta->new_file.mode != 0) git_buf_printf(out, "%c\t%s%c %s%c\n", code, delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); else if (old_suffix != ' ') git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix); else git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path); if (git_buf_oom(out)) return -1; pi->line.origin = GIT_DIFF_LINE_FILE_HDR; pi->line.content = git_buf_cstr(out); pi->line.content_len = git_buf_len(out); return pi->print_cb(delta, NULL, &pi->line, pi->payload); }
int parseStdLine(Project* project, char *line, int *year, int *month, int *day, int *hour, int *minute, float *value) // // Input: line = line of data from a standard rainfall data file // Output: *year = year when rainfall occurs // *month = month of year when rainfall occurs // *day = day of month when rainfall occurs // *hour = hour of day when rainfall occurs // *minute = minute of hour when rainfall occurs // *value = rainfall value (user units); // returns 0 if data line could not be parsed successfully or // 1 if line parsed successfully // Purpose: parses a line of data from a standard rainfall data file. // { int n; char token[MAXLINE]; n = sscanf(line, "%s %d %d %d %d %d %f", token, year, month, day, hour, minute, value); if ( n < 7 ) return 0; if ( project->StationID != NULL && !strcomp(token, project->StationID) ) return 0; return 1; }
int project_readOption(char* s1, char* s2) // // Input: s1 = option keyword // s2 = string representation of option's value // Output: returns error code // Purpose: reads a project option from a pair of string tokens. // // NOTE: all project options have default values assigned in setDefaults(). // { int k, m, h, s; double tStep; char strDate[25]; DateTime aTime; DateTime aDate; // --- determine which option is being read k = findmatch(s1, OptionWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, s1); switch ( k ) { // --- choice of flow units case FLOW_UNITS: m = findmatch(s2, FlowUnitWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); FlowUnits = m; if ( FlowUnits <= MGD ) UnitSystem = US; else UnitSystem = SI; break; // --- choice of infiltration modeling method case INFIL_MODEL: m = findmatch(s2, InfilModelWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); InfilModel = m; break; // --- choice of flow routing method case ROUTE_MODEL: m = findmatch(s2, RouteModelWords); if ( m < 0 ) m = findmatch(s2, OldRouteModelWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); if ( m == NO_ROUTING ) IgnoreRouting = TRUE; else RouteModel = m; if ( RouteModel == EKW ) RouteModel = KW; break; // --- simulation start date case START_DATE: if ( !datetime_strToDate(s2, &StartDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation start time of day case START_TIME: if ( !datetime_strToTime(s2, &StartTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation ending date case END_DATE: if ( !datetime_strToDate(s2, &EndDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- simulation ending time of day case END_TIME: if ( !datetime_strToTime(s2, &EndTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- reporting start date case REPORT_START_DATE: if ( !datetime_strToDate(s2, &ReportStartDate) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- reporting start time of day case REPORT_START_TIME: if ( !datetime_strToTime(s2, &ReportStartTime) ) { return error_setInpError(ERR_DATETIME, s2); } break; // --- day of year when street sweeping begins or when it ends // (year is arbitrarily set to 1947 so that the dayOfYear // function can be applied) case SWEEP_START: case SWEEP_END: strcpy(strDate, s2); strcat(strDate, "/1947"); if ( !datetime_strToDate(strDate, &aDate) ) { return error_setInpError(ERR_DATETIME, s2); } m = datetime_dayOfYear(aDate); if ( k == SWEEP_START ) SweepStart = m; else SweepEnd = m; break; // --- number of antecedent dry days case START_DRY_DAYS: StartDryDays = atof(s2); if ( StartDryDays < 0.0 ) { return error_setInpError(ERR_NUMBER, s2); } break; // --- runoff or reporting time steps // (input is in hrs:min:sec format, time step saved as seconds) case WET_STEP: case DRY_STEP: case REPORT_STEP: if ( !datetime_strToTime(s2, &aTime) ) { return error_setInpError(ERR_DATETIME, s2); } datetime_decodeTime(aTime, &h, &m, &s); h += 24*(int)aTime; s = s + 60*m + 3600*h; if ( s <= 0 ) return error_setInpError(ERR_NUMBER, s2); switch ( k ) { case WET_STEP: WetStep = s; break; case DRY_STEP: DryStep = s; break; case REPORT_STEP: ReportStep = s; break; } break; // --- type of damping applied to inertial terms of dynamic wave routing case INERT_DAMPING: m = findmatch(s2, InertDampingWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); else InertDamping = m; break; // --- Yes/No options (NO = 0, YES = 1) case ALLOW_PONDING: case SLOPE_WEIGHTING: case SKIP_STEADY_STATE: case IGNORE_RAINFALL: case IGNORE_SNOWMELT: case IGNORE_GWATER: case IGNORE_ROUTING: case IGNORE_QUALITY: case IGNORE_RDII: //(5.1.004) m = findmatch(s2, NoYesWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); switch ( k ) { case ALLOW_PONDING: AllowPonding = m; break; case SLOPE_WEIGHTING: SlopeWeighting = m; break; case SKIP_STEADY_STATE: SkipSteadyState = m; break; case IGNORE_RAINFALL: IgnoreRainfall = m; break; case IGNORE_SNOWMELT: IgnoreSnowmelt = m; break; case IGNORE_GWATER: IgnoreGwater = m; break; case IGNORE_ROUTING: IgnoreRouting = m; break; case IGNORE_QUALITY: IgnoreQuality = m; break; case IGNORE_RDII: IgnoreRDII = m; break; //(5.1.004) } break; case NORMAL_FLOW_LTD: m = findmatch(s2, NormalFlowWords); if ( m < 0 ) m = findmatch(s2, NoYesWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); NormalFlowLtd = m; break; case FORCE_MAIN_EQN: m = findmatch(s2, ForceMainEqnWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); ForceMainEqn = m; break; case LINK_OFFSETS: m = findmatch(s2, LinkOffsetWords); if ( m < 0 ) return error_setInpError(ERR_KEYWORD, s2); LinkOffsets = m; break; // --- compatibility option for selecting solution method for // dynamic wave flow routing (NOT CURRENTLY USED) case COMPATIBILITY: if ( strcomp(s2, "3") ) Compatibility = SWMM3; else if ( strcomp(s2, "4") ) Compatibility = SWMM4; else if ( strcomp(s2, "5") ) Compatibility = SWMM5; else return error_setInpError(ERR_KEYWORD, s2); break; // --- routing or lengthening time step (in decimal seconds) // (lengthening time step is used in Courant stability formula // to artificially lengthen conduits for dynamic wave flow routing // (a value of 0 means that no lengthening is used)) case ROUTE_STEP: case LENGTHENING_STEP: if ( !getDouble(s2, &tStep) ) { if ( !datetime_strToTime(s2, &aTime) ) { return error_setInpError(ERR_NUMBER, s2); } else { datetime_decodeTime(aTime, &h, &m, &s); h += 24*(int)aTime; s = s + 60*m + 3600*h; tStep = s; } } if ( k == ROUTE_STEP ) { if ( tStep <= 0.0 ) return error_setInpError(ERR_NUMBER, s2); RouteStep = tStep; } else LengtheningStep = MAX(0.0, tStep); break; // --- safety factor applied to variable time step estimates under // dynamic wave flow routing (value of 0 indicates that variable // time step option not used) case VARIABLE_STEP: if ( !getDouble(s2, &CourantFactor) ) return error_setInpError(ERR_NUMBER, s2); if ( CourantFactor < 0.0 || CourantFactor > 2.0 ) return error_setInpError(ERR_NUMBER, s2); break; // --- minimum surface area (ft2 or sq. meters) associated with nodes // under dynamic wave flow routing case MIN_SURFAREA: MinSurfArea = atof(s2); break; // --- minimum conduit slope (%) case MIN_SLOPE: if ( !getDouble(s2, &MinSlope) ) return error_setInpError(ERR_NUMBER, s2); if ( MinSlope < 0.0 || MinSlope >= 100 ) return error_setInpError(ERR_NUMBER, s2); MinSlope /= 100.0; break; // --- maximum trials / time step for dynamic wave routing case MAX_TRIALS: m = atoi(s2); if ( m < 0 ) return error_setInpError(ERR_NUMBER, s2); MaxTrials = m; break; // --- head convergence tolerance for dynamic wave routing case HEAD_TOL: if ( !getDouble(s2, &HeadTol) ) { return error_setInpError(ERR_NUMBER, s2); } break; // --- steady state tolerance on system inflow - outflow case SYS_FLOW_TOL: if ( !getDouble(s2, &SysFlowTol) ) { return error_setInpError(ERR_NUMBER, s2); } SysFlowTol /= 100.0; break; // --- steady state tolerance on nodal lateral inflow case LAT_FLOW_TOL: if ( !getDouble(s2, &LatFlowTol) ) { return error_setInpError(ERR_NUMBER, s2); } LatFlowTol /= 100.0; break; case TEMPDIR: // Temporary Directory sstrncpy(TempDir, s2, MAXFNAME); break; } return 0; }
int writereport() /* **------------------------------------------------------ ** Input: none ** Output: returns error code ** Purpose: writes formatted output report to file ** ** Calls strcomp() from the EPANET.C module. **------------------------------------------------------ */ { char tflag; FILE *tfile; int errcode = 0; /* If no secondary report file specified then */ /* write formatted output to primary report file. */ Fprinterr = FALSE; if (Rptflag && strlen(Rpt2Fname) == 0 && RptFile != NULL) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* A secondary report file was specified */ else if (strlen(Rpt2Fname) > 0) { /* If secondary report file has same name as either input */ /* or primary report file then use primary report file. */ if (strcomp(Rpt2Fname,InpFname) || strcomp(Rpt2Fname,Rpt1Fname)) { writecon(FMT17); writecon(Rpt1Fname); if (Energyflag) writeenergy(); errcode = writeresults(); } /* Otherwise write report to secondary report file. */ else { /* Try to open file */ tfile = RptFile; tflag = Rptflag; if ((RptFile = fopen(Rpt2Fname,"wt")) == NULL) { RptFile = tfile; Rptflag = tflag; errcode = 303; } /* Write full formatted report to file */ else { Rptflag = 1; writecon(FMT17); writecon(Rpt2Fname); writelogo(); if (Summaryflag) writesummary(); if (Energyflag) writeenergy(); errcode = writeresults(); fclose(RptFile); RptFile = tfile; Rptflag = tflag; } } } /* Special error handler for write-to-file error */ if (Fprinterr) errmsg(309); return(errcode); } /* End of writereport */
int optionGlobales(char const *option[], int nbArgs, Plateau *p){ int i; for(i = 1; i<nbArgs; i++){ if(strcomp(option[i],"-N")){ if((i+1) == nbArgs){ printf("Argument obligatoire : N\n"); return 1; } if (strcomp("IA",option[i+1])||strcomp("ia",option[i+1])||strcomp("robot",option[i+1])){ p->typeNoir = 1; } else if(strcomp("human",option[i+1])||strcomp("h",option[i+1])||strcomp("H",option[i+1])|| strcomp("Humain",option[i+1])){ p->typeNoir = 2; } else { printf("erreur N : \n"); return 1; } } else if(strcomp(option[i],"-B")){ if((i+1) == nbArgs){ printf("Argument obligatoire : B\n"); return 1; } if (strcomp("IA",option[i+1])||strcomp("ia",option[i+1])||strcomp("robot",option[i+1])){ p->typeBlanc = 1; } else if(strcomp("human",option[i+1])||strcomp("h",option[i+1])||strcomp("H",option[i+1])|| strcomp("Humain",option[i+1])){ p->typeBlanc = 2; } else { printf("erreur B : \n"); return 1; } } else if(strcomp(option[i],"-c")){ if((i+1) == nbArgs){ printf("Argument obligatoire : C\n"); return 1; } else { if(fichierConfig(option[i+1], p) != 0) { printf("ERREUR fichier config option.c\n"); exit(-1); } } } else if (strcomp(option[i],"-t")){ if( nbArgs != 2){ printf("l'Option -t ne prend ni argument ni autre option\n"); return 1; } else{ return 2; } } } return 0; }
void audioSort(struct audio *info, char *link_source, char *link_target) { #if (audio_genre_sort == TRUE) || (audio_artist_sort == TRUE) || (audio_year_sort == TRUE) || (audio_group_sort == TRUE) || (audio_language_sort == TRUE) int n = 0; #if (audio_artist_sort == TRUE) || (audio_group_sort == TRUE) || (audio_language_sort == TRUE) char *temp_p = NULL; #if (audio_language_sort == TRUE) char language[3]; #endif #if (audio_group_sort == TRUE) char *temp_q = NULL; char temp_nam[16]; #endif #endif #else d_log("audioSort: No audio_*_sort is set to TRUE - skipping sorting of audio\n"); (void)info; (void)link_source; (void)link_target; #endif if (subcomp(link_target, NULL)) { int i, pos = 0; char sourceDir[PATH_MAX]; for (i = strlen(link_source); i > 0; i--) { if (link_source[i] == '/') { pos = i; break; } } strcpy(sourceDir, link_source); strlcpy(link_source, sourceDir, pos + 1); extractDirname(link_target, link_source); } #if ( audio_genre_sort == TRUE ) d_log("audioSort: Sorting audio by genre (%s)\n", info->id3_genre); createlink(audio_genre_path, info->id3_genre, link_source, link_target); #endif #if ( audio_artist_sort == TRUE ) d_log("audioSort: Sorting audio by artist\n"); if (*info->id3_artist) { d_log("audioSort: - artist: %s\n", info->id3_artist); if (!strncasecmp(link_target, "VA", 2) && (link_target[2] == '-' || link_target[2] == '_')) { #if ( audio_artist_sort_various_only == TRUE ) memcpy(info->id3_artist, "VA", 3); #endif createlink(audio_artist_path, "VA", link_source, link_target); } if (memcmp(info->id3_artist, "VA", 3)) { #if ( audio_artist_nosub == FALSE ) temp_p = ng_realloc(temp_p, 2, 1, 0, NULL, 1); #if ( audio_artist_noid3 == FALSE ) snprintf(temp_p, 2, "%c", toupper(*info->id3_artist)); #else snprintf(temp_p, 2, "%c", toupper(*link_target)); #endif #else temp_p = ng_realloc(temp_p, strlen(info->id3_artist)+1, 1, 0, NULL, 1); snprintf(temp_p, strlen(info->id3_artist)+1, "%s", info->id3_artist); temp_p = check_nocase_linkname(audio_artist_path, temp_p); space_to_dot(temp_p); #endif createlink(audio_artist_path, temp_p, link_source, link_target); ng_free(temp_p); } } #endif #if ( audio_year_sort == TRUE ) d_log("audioSort: Sorting audio by year (%s)\n", info->id3_year); if (*info->id3_year != 0) createlink(audio_year_path, info->id3_year, link_source, link_target); #endif #if ( audio_group_sort == TRUE ) d_log("audioSort: Sorting audio by group\n"); temp_p = remove_pattern(link_target, "*-", RP_LONG_LEFT); temp_p = remove_pattern(temp_p, "_", RP_SHORT_LEFT); n = (int)strlen(temp_p); if (n > 0 && n < 15) { strncpy(temp_nam, temp_p, sizeof(temp_nam)); if (n > 4) { temp_q = temp_nam + n - 4; if (!strncasecmp(temp_q, "_INT", 4)) { d_log("audioSort: - Internal release detected\n"); *temp_q = '\0'; } } d_log("audioSort: - Valid groupname found: %s (%i) - checking for exisiting sort-dir.\n", temp_nam, n); temp_p = check_nocase_linkname(audio_group_path, temp_p); d_log("audioSort: - Valid groupname found: %s (%i) - using this.\n", temp_p, n); createlink(audio_group_path, temp_p, link_source, link_target); } #endif #if ( audio_language_sort == TRUE ) d_log("audioSort: Sorting audio by language\n"); language[0] = '\0'; n = (int)strlen(link_target); while ( n > 3) { if (link_target[n] == '-') { if ((unsigned char)link_target[n-3] == '-' && (unsigned char)link_target[n-2] >= 'A' && (unsigned char)link_target[n-2] <= 'Z' && (unsigned char)link_target[n-1] >= 'A' && (unsigned char)link_target[n-1] <= 'Z') { language[0] = link_target[n-2]; language[1] = link_target[n-1]; language[2] = '\0'; temp_p = language; break; } } n--; } if (language[0] != '\0' && !strcomp(audio_ignored_languages, language)) { d_log("audioSort: - Valid language found: %s\n", language); createlink(audio_language_path, temp_p, link_source, link_target); } else d_log("audioSort: - No valid language found - skipping.\n"); #endif }
int climate_readParams(char* tok[], int ntoks) // // Input: tok[] = array of string tokens // ntoks = number of tokens // Output: returns error code // Purpose: reads climate/temperature parameters from input line of data // // Format of data can be // TIMESERIES name // FILE name // WINDSPEED MONTHLY v1 v2 ... v12 // WINDSPEED FILE // SNOWMELT v1 v2 ... v6 // ADC IMPERV/PERV v1 v2 ... v10 // { int i, j, k; double x[6], y; DateTime aDate; // --- identify keyword k = findmatch(tok[0], TempKeyWords); if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[0]); switch (k) { case 0: // Time series name // --- check that time series name exists if ( ntoks < 2 ) return error_setInpError(ERR_ITEMS, ""); i = project_findObject(TSERIES, tok[1]); if ( i < 0 ) return error_setInpError(ERR_NAME, tok[1]); // --- record the time series as being the data source for temperature Temp.dataSource = TSERIES_TEMP; Temp.tSeries = i; break; case 1: // Climate file // --- record file as being source of temperature data if ( ntoks < 2 ) return error_setInpError(ERR_ITEMS, ""); Temp.dataSource = FILE_TEMP; // --- save name and usage mode of external climate file Fclimate.mode = USE_FILE; sstrncpy(Fclimate.name, tok[1], MAXFNAME); // --- save starting date to read from file if one is provided Temp.fileStartDate = NO_DATE; if ( ntoks > 2 ) { if ( *tok[2] != '*') { if ( !datetime_strToDate(tok[2], &aDate) ) return error_setInpError(ERR_DATETIME, tok[2]); Temp.fileStartDate = aDate; } } break; case 2: // Wind speeds // --- check if wind speeds will be supplied from climate file if ( strcomp(tok[1], w_FILE) ) { Wind.type = FILE_WIND; } // --- otherwise read 12 monthly avg. wind speed values else { if ( ntoks < 14 ) return error_setInpError(ERR_ITEMS, ""); Wind.type = MONTHLY_WIND; for (i=0; i<12; i++) { if ( !getDouble(tok[i+2], &y) ) return error_setInpError(ERR_NUMBER, tok[i+2]); Wind.aws[i] = y; } } break; case 3: // Snowmelt params if ( ntoks < 7 ) return error_setInpError(ERR_ITEMS, ""); for (i=1; i<7; i++) { if ( !getDouble(tok[i], &x[i-1]) ) return error_setInpError(ERR_NUMBER, tok[i]); } // --- convert deg. C to deg. F for snowfall temperature if ( UnitSystem == SI ) x[0] = 9./5.*x[0] + 32.0; Snow.snotmp = x[0]; Snow.tipm = x[1]; Snow.rnm = x[2]; Temp.elev = x[3] / UCF(LENGTH); Temp.anglat = x[4]; Temp.dtlong = x[5] / 60.0; break; case 4: // Areal Depletion Curve data // --- check if data is for impervious or pervious areas if ( ntoks < 12 ) return error_setInpError(ERR_ITEMS, ""); if ( match(tok[1], w_IMPERV) ) i = 0; else if ( match(tok[1], w_PERV) ) i = 1; else return error_setInpError(ERR_KEYWORD, tok[1]); // --- read 10 fractional values for (j=0; j<10; j++) { if ( !getDouble(tok[j+2], &y) || y < 0.0 || y > 1.0 ) return error_setInpError(ERR_NUMBER, tok[j+2]); Snow.adc[i][j] = y; } break; } return 0; }
static int checkout_action( checkout_data *data, git_diff_delta *delta, git_iterator *workdir, const git_index_entry **wditem_ptr, git_vector *pathspec) { const git_index_entry *wd = *wditem_ptr; int cmp = -1, act; int (*strcomp)(const char *, const char *) = data->diff->strcomp; int (*pfxcomp)(const char *str, const char *pfx) = data->diff->pfxcomp; int error; /* move workdir iterator to follow along with deltas */ while (1) { if (!wd) return checkout_action_no_wd(data, delta); cmp = strcomp(wd->path, delta->old_file.path); /* 1. wd before delta ("a/a" before "a/b") * 2. wd prefixes delta & should expand ("a/" before "a/b") * 3. wd prefixes delta & cannot expand ("a/b" before "a/b/c") * 4. wd equals delta ("a/b" and "a/b") * 5. wd after delta & delta prefixes wd ("a/b/c" after "a/b/" or "a/b") * 6. wd after delta ("a/c" after "a/b") */ if (cmp < 0) { cmp = pfxcomp(delta->old_file.path, wd->path); if (cmp == 0) { if (wd->mode == GIT_FILEMODE_TREE) { /* case 2 - entry prefixed by workdir tree */ error = git_iterator_advance_into_or_over(&wd, workdir); if (error && error != GIT_ITEROVER) goto fail; *wditem_ptr = wd; continue; } /* case 3 maybe - wd contains non-dir where dir expected */ if (delta->old_file.path[strlen(wd->path)] == '/') { act = checkout_action_with_wd_blocker(data, delta, wd); *wditem_ptr = git_iterator_advance(&wd, workdir) ? NULL : wd; return act; } } /* case 1 - handle wd item (if it matches pathspec) */ if (checkout_action_wd_only(data, workdir, wd, pathspec) < 0) goto fail; if ((error = git_iterator_advance(&wd, workdir)) < 0 && error != GIT_ITEROVER) goto fail; *wditem_ptr = wd; continue; } if (cmp == 0) { /* case 4 */ act = checkout_action_with_wd(data, delta, wd); *wditem_ptr = git_iterator_advance(&wd, workdir) ? NULL : wd; return act; } cmp = pfxcomp(wd->path, delta->old_file.path); if (cmp == 0) { /* case 5 */ if (wd->path[strlen(delta->old_file.path)] != '/') return checkout_action_no_wd(data, delta); if (delta->status == GIT_DELTA_TYPECHANGE) { if (delta->old_file.mode == GIT_FILEMODE_TREE) { act = checkout_action_with_wd(data, delta, wd); if ((error = git_iterator_advance_into(&wd, workdir)) < 0 && error != GIT_ENOTFOUND) goto fail; *wditem_ptr = wd; return act; } if (delta->new_file.mode == GIT_FILEMODE_TREE || delta->new_file.mode == GIT_FILEMODE_COMMIT || delta->old_file.mode == GIT_FILEMODE_COMMIT) { act = checkout_action_with_wd(data, delta, wd); if ((error = git_iterator_advance(&wd, workdir)) < 0 && error != GIT_ITEROVER) goto fail; *wditem_ptr = wd; return act; } } return checkout_action_with_wd_dir(data, delta, wd); } /* case 6 - wd is after delta */ return checkout_action_no_wd(data, delta); } fail: *wditem_ptr = NULL; return -1; }