void CDateTime::setTimeString(char const * str, char const * * end, bool local) { unsigned year; unsigned month; unsigned day; getDate(year, month, day, false); unsigned hour = readDigits(str, 2); checkChar(str, ':'); unsigned minute = readDigits(str, 2); checkChar(str, ':'); unsigned sec = readDigits(str, 2); unsigned nano = 0; if(*str == '.') { unsigned digits; for(digits = 0; digits < 9; digits++) { char c = *++str; if(!isdigit(c)) break; nano = nano * 10 + (c - '0'); } while(digits++<9) nano *= 10; } if(end) *end = str; set(year, month, day, hour, minute, sec, nano, local); }
void CDateTime::setString(char const * str, char const * * end, bool local) { if (!str||!*str) { clear(); return; } unsigned year = readDigits(str, 4); checkChar(str, '-'); unsigned month = readDigits(str, 2); checkChar(str, '-'); unsigned day = readDigits(str, 2); checkChar(str, 'T'); unsigned hour = readDigits(str, 2); checkChar(str, ':'); unsigned minute = readDigits(str, 2); checkChar(str, ':'); unsigned sec = readDigits(str, 2); unsigned nano = 0; if(*str == '.') { unsigned digits; for(digits = 0; digits < 9; digits++) { char c = *++str; if(!isdigit(c)) break; nano = nano * 10 + (c - '0'); } while(digits++<9) nano *= 10; } if(end) *end = str; set(year, month, day, hour, minute, sec, nano, local); }
Square* BoxContainer::createSquare() { int x, y; unsigned int length; char ch; bool ok = true; cout << "\t===Creating New Square===\n"; cout << "\tEnter X Value: "; cin >> x; cout << endl; cout << "\tEnter Y Value: "; cin >> y; cout << endl; cout << "\tEnter Square Length: "; cin >> length; ok = checkLength(length); while (!ok) { cout << "\tWRONG LENGTH VALUE\n"; cout << "\tEnter Square Length: "; cin >> length; ok = checkLength(length); } cout << "\tEnter Square Character: "; cin >> ch; ok = checkChar(ch); while (!ok) { cout << "\tWRONG CHAR VALUE\n"; cout << "\tEnter Square Character: "; cin >> ch; ok = checkChar(ch); } s = new Square(x, y, length, ch); return s; }
void CDateTime::setDateString(char const * str, char const * * end) { unsigned year = readDigits(str, 4); checkChar(str, '-'); unsigned month = readDigits(str, 2); checkChar(str, '-'); unsigned day = readDigits(str, 2); if(end) *end = str; set(year, month, day, 0, 0, 0, 0, false); }
std::string CSeqParser::takeNext( char* &start, char *end ) { while ( !checkChar( *start ) && *start != '/' ) ++start; if ( checkChar( *start ) ) return takeNextWord( start, end ); return takeNextRemake( start, end ); }
int longestValidParentheses(string s) { int len = 0, len_max = 0, count = 0; for (int i = 0 ; i < s.length(); ++ i) { checkChar(len, len_max, count, s[i] == '('); } len = 0, count = 0; for (int i = s.length() - 1; i >= 0; -- i) { checkChar(len, len_max, count, s[i] == ')'); } return len_max; }
void invkey (FILE *inFile) { // Allocate buffers for input / output char *lineIn = malloc(ABC_LEN * sizeof (char)); // 5 seems to be the magic number for the student data function. char *lineOut = malloc(ABC_LEN + 5 * sizeof (char)); // Counter int i; // 5 seems to be the magic number for the student data function. // Read in each line while (fgets(lineIn, ABC_LEN + 5, inFile) != NULL) { // Check to make sure the key is the proper size if (strlen(lineIn) != (ABC_LEN + 1)) { fprintf(stderr, "Invalid key file. Please check the file and try again.\n"); exit(-1); } /** Iterate through 26 characters of lineIn, check the characters to make sure its not an invalid character, then print. **/ for (i = 0; i < ABC_LEN; i++) { // Check input file for proper characters if (checkChar(lineIn[i]) != 1) { // Get inverse lineOut[lineIn[i] - 97] = 97 + i; } } // Finally print the inverse line fprintf(stdout, "%s\n", lineOut); } // Free buffers free(lineIn); free(lineOut); }
void CSVRowInputStream::readPrefix() { /// In this format, we assume, that if first string field contain BOM as value, it will be written in quotes, /// so BOM at beginning of stream cannot be confused with BOM in first string value, and it is safe to skip it. skipBOMIfExists(istr); if (with_names) { if (format_settings.with_names_use_header) { String column_name; do { skipWhitespacesAndTabs(istr); readCSVString(column_name, istr, format_settings.csv); skipWhitespacesAndTabs(istr); addInputColumn(column_name); } while (checkChar(format_settings.csv.delimiter, istr)); skipDelimiter(istr, format_settings.csv.delimiter, true); } else { setupAllColumnsByTableSchema(); skipRow(istr, format_settings.csv, column_indexes_for_input_fields.size()); } } else { setupAllColumnsByTableSchema(); } }
bool CSeqParser::parseClassDeclare( char* &start, char *end, wd::CSeqLog &log, std::list< std::pair< char*, std::string > > &error_info ) { for( char chr = *start; chr != '\0'; chr = *start ) { switch ( chr ) { //类注释 case '/': log.classDescript = takeNextRemake( start, end ); break; //取得下一个可解释字符串 case '\r': case '\n': case ' ': case '\t': gotoNextChar( start, end ); break; case '#': gotoNextLine( start, end ); break; //不应该出现;号 case ';': ++start; pushErrorInfo( error_info, start, "不应该出现的符号 ';'" ); break; case ':': log.classParent = takeNextWord( ++start, end ); if ( log.classParent.empty() ) pushErrorInfo( error_info, start, "类继承缺少父类名称" ); break; case '{': parseClassInfo( ++start, end, log, error_info ); return true; default: if ( !checkChar( chr ) ) { pushErrorInfo( error_info, start, "遇到不可解释的符号, 期望是一个字母、数字和半角下划线" ); return false; } log.className = takeNextWord( start, end ); if ( log.className.empty() ) { pushErrorInfo( error_info, start, "声明类时缺失类名声明" ); return false; } break; } } pushErrorInfo( error_info, start, ( "找不到类 [" + log.className + "] 的 '{' , 类定义失败" ).c_str() ); return false; }
void DataTypeDateTime::deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const { time_t x; if (checkChar('\'', istr)) /// Cases: '2017-08-31 18:36:48' or '1504193808' { readText(x, istr, settings, time_zone, utc_time_zone); assertChar('\'', istr); } else /// Just 1504193808 or 01504193808 { readIntText(x, istr); } static_cast<ColumnUInt32 &>(column).getData().push_back(x); /// It's important to do this at the end - for exception safety. }
void DataTypeDateTime::deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const { time_t x; if (checkChar('"', istr)) { readText(x, istr, settings, time_zone, utc_time_zone); assertChar('"', istr); } else { readIntText(x, istr); } static_cast<ColumnUInt32 &>(column).getData().push_back(x); }
static char checkStrand(std::string const & s) { char const c = checkChar(s); switch ( c ) { case '+': case '-': return c; default: { libmaus2::exception::LibMausException lme; lme.getStream() << "GeneFlatFileEntry: string " << s << " is not valid for the strand column" << std::endl; lme.finish(); throw lme; } } }
std::string CSeqParser::takeNextWord( char* &start, char *end ) { gotoNextChar( start, end ); char *src = start; for ( ; *start != '\0' && start < end; ++start) { if ( checkChar( *start ) ) continue; break; } std::string str( start - src, 0 ); memcpy( &str[0], src, start - src ); return str; }
/* opens the provided txtfile, and compares each letter with a table of letters from the base string. The function keeps track of whether or not the word is formable. Then when a tokenizer is found the word counter updates, and so does the formable word counter, depernding on its status */ void processTokensFromFile(char** base_array, const char** fname_array, const unsigned int num_inputs, const unsigned int* length_array, \ const unsigned int max_length, const unsigned char silence, const unsigned char tare_setup, const size_t buckets) { unsigned int char_count, word_count, formable_count, buff_index; FILE *input_file; char *c_buff=NULL; int c; //character returned from fgetc Table *base_table, *comparison_table; unsigned char is_formable; unsigned int* index; c_buff= calloc(max_length+1, sizeof(char)); //used to build word tokens as read from the provided file if (c_buff==NULL){ printf("Memory allocation failed: char pointer c_buff\n"); exit(0); } base_table=tableCreate(TABLE_SIZE); comparison_table=tableCreate(TABLE_SIZE); fillTable(base_table, base_array[0]); index=generateIndex(base_table); //used to rebuild only the necessary parts of the table copyTableFromIndex(comparison_table, base_table, index); if (!tare_setup) { for(unsigned int i=0; i<num_inputs; ++i) { char_count=0, word_count=0, formable_count=0, buff_index=0; is_formable=1; //assume token is formable until checkChar returns otherwise input_file= fopen(fname_array[i], "r"); if(input_file==NULL) { //Prevents seg fault crash if there is a problem with the provided file printf("Improper file name: %s\n",fname_array[i]); continue; } if(!silence) { displayIntro(i+1,fname_array[i]); } do{ c = fgetc(input_file); //gets next character if(isTokenizer(c) || c==EOF) { if(buff_index != 0){ //non-negative index + reaching a tokenizer means c_buff contains a token ++word_count; char_count += buff_index+1; // +1 to account for the tokenizing character causing termination of token reading if(is_formable) { ++formable_count; if (!silence) {printf("\t%s\n",c_buff);} } //reset params for next loop and next token buff_index=0, is_formable=1; copyTableFromIndex(comparison_table, base_table,index); memset(&c_buff[0],0,(buff_index < max_length) ? buff_index : max_length); } else { ++char_count; // A tokenizer char has been found, but no token is being formed } } else { if(is_formable) { if(checkChar(c,comparison_table)) { c_buff[buff_index]=c; } else { is_formable=0; } } ++buff_index; } } while(c!=EOF); --char_count; //correct for EOF being read for a char fclose(input_file); reportResults(length_array[0],char_count, word_count, formable_count); } } tableDestroy(base_table); tableDestroy(comparison_table); indexDestroy(index); free(c_buff); }
int main (int argc, char **argv) { //variavles for clock double duration; clock_t startClock, finishClock; //variables for getopt int parallelism; char *input = NULL; char *output = NULL; int index; int c; FILE *fpInput; FILE *fpOutput; opterr = 0; //variables for main function before create children int n,i,j,t; char temChar; int flag,found; char **wordsAll; char *temWord; int line, row; struct word *words; struct word temWordStruct; int status; int cProcessN; pid_t pid; int start,end; int separatedWordsRange[cProcessN][2]; int remainder,range; int pfds[2]; pipe(pfds); char *connect1; char connect2[120]; char plusSign[2]; //variables for children processes char frequencyPipe[20]; char contentPipe[100]; //variables for parent process struct word *wordsParent; char content[100]; char *seperatePipe; while ((c = getopt (argc, argv, "p:i:o:")) != -1) switch (c) { case 'p': if(isdigit_all(optarg)==1) { parallelism = atoi(optarg); } else { printf("p option need a number!\n"); return 0; } break; case 'i': input = optarg; if((fpInput=fopen(input,"r"))==NULL) { printf("Cannot read the input file: %s !\n",input); return 0; } break; case 'o': output = optarg; if((fpOutput=fopen(output,"wt"))==NULL) { printf("Cannot create the output file: %s !\n",output); return 0; } break; case '?': if (optopt == 'p') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } else if(optopt == 'i') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } else if(optopt == 'o') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } else if (isprint (optopt)) { fprintf (stderr, "Unknown option `-%c'.\n", optopt); } else { fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt); return 0; } default: abort (); } printf ("parallelism = %d, input = %s, output = %s\n", parallelism, input, output); for (index = optind; index < argc; index++) { printf ("Non-option argument %s\n", argv[index]); } printf("enter the code\n"); //set the number of children process cProcessN = parallelism; //set clock to calculate the run time startClock = clock(); //start read word from file wordsAll = (char**)malloc(10*sizeof(char*)); flag = 1; line= 0; temChar = fgetc(fpInput); while(temChar!=EOF) { if(checkChar(temChar)) { if(flag == 1) { temWord = (char*)malloc(2*sizeof(char)); row = 0; } else { row=row+1; temWord=(char*)realloc(temWord,(row+2)*sizeof(char)); } temWord[row] = temChar; flag = 2; //last word temChar = fgetc(fpInput); if(temChar==EOF) { temWord[row+1]= '\0'; wordsAll = (char**)realloc(wordsAll,(line+10)*sizeof(char*)); wordsAll[line]=temWord; line++; } } else { if(flag == 2) { temWord[row+1]= '\0'; wordsAll = (char**)realloc(wordsAll,(line+1)*sizeof(char*)); wordsAll[line]=temWord; line++; } flag = 1; temChar = fgetc(fpInput); if(temChar==EOF) { break; } } } wordsAll[line] = 0; for(t=0; t<line; t++) { //printf("wordsAll[%d]: %s\n",t,wordsAll[t]); } //printf("line: %d\n",line); //separate the array wordsAll based on cProcess number start = 0; end = 1; range = line/cProcessN; remainder = line%cProcessN; //printf("remainder: %d\n",remainder); //printf("range: %d\n",range); for(i = 0; i<cProcessN; i++ ) { separatedWordsRange[i][start] = i*range; separatedWordsRange[i][end] = ((i+1)*range)-1; } separatedWordsRange[cProcessN-1][end] = line-1; for(i = 0; i<cProcessN; i++ ) { //printf("separatedWordsRange: %d~%d\n",separatedWordsRange[i][start],separatedWordsRange [i][end]); } printf("cProcessN: %d\n",cProcessN); for(i=0; i<cProcessN; i++) { pid = fork(); if(pid==0) { printf( "This is in the %d child process,here read a string from the pipe. pid:%d ppid:%d\n",i,getpid(),getppid() ); //count the words frequency n=0; words = (struct word*)malloc(1*sizeof(struct word)); words[0].content = (char*)malloc(strlen(wordsAll[(separatedWordsRange[i][start])])*sizeof(char)); strcpy(words[0].content,wordsAll[(separatedWordsRange[i][start])]); words[0].number=0; for(t=separatedWordsRange[i][start]; t<(separatedWordsRange[i][end]+1); t++) { found = 0; for(j=0; j<=n; j++) { if(strcmp(wordsAll[t],words[j].content)==0) { found = 1; words[j].number = words[j].number+1; break; } } if(found==0) { n=n+1; words = (struct word*)realloc(words,(n+1)*sizeof(struct word)); words[n].content = (char*)malloc(strlen(wordsAll[t])*sizeof(char)); strcpy(words[n].content,wordsAll[t]); words[n].number=1; } } //sort the word frequency array, the length of the array is n+1 for(t=0; t<=n-1; t++) { for(j=t+1; j<=n; j++) { if(words[j].number>words[t].number) { temWordStruct=words[t]; words[t]=words[j]; words[j]=temWordStruct; } } } for(t=0; t<=n; t++) { //printf("i: %d %s %d\n",i,words[t].content,words[t].number); } //add a flag element for marking the end of the array; words[n+1].content="1"; //strcpy(words[n+1].content,"1"); words[n+1].number=1; //send all data to pipe for(t=0; t<=n+1; t++) { sprintf(frequencyPipe, "%d", words[t].number); strcpy(plusSign,"+"); strcpy(content,words[t].content); connect1 = strcat(content,plusSign); connect1 = strcat(connect1,frequencyPipe); write(pfds[1], connect1, 120); } //free(wordsAll); //free(wordsOrdered); //free(words); exit(3); } else if(pid>0) { //free(wordsAll); printf( "This is in the father process. pid %d\n",getpid() ); //when all children processes have been created. if(i==cProcessN-1) { n = 1; flag=0; //crate array for saving the final sorted data wordsParent = (struct word*)malloc(1*sizeof(struct word)); //add the first word to arrary read(pfds[0], connect2, 120); //separate the result seperatePipe = strtok(connect2,"+"); strcpy(contentPipe,seperatePipe); seperatePipe = strtok(NULL,"+"); strcpy(frequencyPipe,seperatePipe); wordsParent[0].content = (char*)malloc(100*sizeof(char)); strcpy(wordsParent[0].content,contentPipe); wordsParent[0].number = atoi(frequencyPipe); //read all results from pipe free(wordsAll); while(flag<cProcessN) { found = 0; read(pfds[0], connect2, 120); seperatePipe = strtok(connect2,"+"); strcpy(contentPipe,seperatePipe); seperatePipe = strtok(NULL,"+"); strcpy(frequencyPipe,seperatePipe); for(t=0; t<n; t++) { if(strcmp(wordsParent[t].content,contentPipe)==0) { wordsParent[t].number= wordsParent[t].number + atoi(frequencyPipe); found = 1; break; } } if(found == 0) { wordsParent = (struct word*)realloc(wordsParent,(n+1)*sizeof(struct word)); wordsParent[n].content = (char*)malloc(100*sizeof(char)); strcpy(wordsParent[n].content,contentPipe); wordsParent[n].number = atoi(frequencyPipe); n++; } if(strcmp(contentPipe,"1")==0) { flag = flag+1; n=n-1;//ignore flag, do not save it in arrary } } //sort the word frequency array, the length of the array is n+1 for(t=0; t<=n-2; t++) { for(j=t+1; j<=n-1; j++) { if(wordsParent[j].number>wordsParent[t].number) { temWordStruct=wordsParent[t]; wordsParent[t]=wordsParent[j]; wordsParent[j]=temWordStruct; } } } for(t=0; t<n; t++) { //printf("%s %d\n",wordsParent[t].content,wordsParent[t].number); } //write to the file for(t=0; t<n; t++) { fprintf(fpOutput,"%s %d\n",wordsParent[t].content,wordsParent[t].number); } //to make sure all children correctly exit for(t=0; t<cProcessN; t++) { pid=wait(&status); printf("I catched a child process with pid of %d\n",pid); if(WIFEXITED(status)) { printf("the child process %d exit normally.\n",pid); printf("the return code is %d.\n",WEXITSTATUS(status)); } else { printf("the child process %d exit abnormally.\n",pid); printf("the return code is %d.\n",WEXITSTATUS(status)); } } finishClock = clock(); duration = (double)(finishClock - startClock) / CLOCKS_PER_SEC; //printf( "code runs %f seconds\n", duration ); duration = (double)(finishClock - startClock); //printf( "code runs %f seconds\n", duration ); } } else { printf("\n Fork failed, quitting!!!!!!\n"); return 1; } } return 0; }
static int getPtime (char *toptarg, char endTime, time_t sbtime, char flag, time_t *Ptime) { #define MINU 1 #define HOUR 2 #define DAY 4 #define MONTH 8 #define YEAR 16 char *cp, *cp1, *cp2, *cp3; time_t ptimev; struct tm *tmPtr; int ptimef = 0, m, tempInt; if ( ! checkChar (toptarg, &cp)) { lserrno = LSE_BAD_TIME; return -1; } checkThree (toptarg, '/', &cp1, &cp2, &cp3); if ( cp2 != NULL ) { if ( (cp1+1) == cp2 ) { lserrno = LSE_BAD_TIME; return -1; } *cp2 = '0'; checkThree (toptarg, '/', &cp1, &cp, &cp3); *cp2 = '/'; if ( cp3 != NULL ) { lserrno = LSE_BAD_TIME; return -1; } } checkThree (toptarg, ':', &cp1, &cp2, &cp3); if ( cp1 == NULL ) { checkThree (toptarg, '/', &cp1, &cp2, &cp3); if (( cp3 != NULL ) && ( *(cp3+1) != '0' )) { lserrno = LSE_BAD_TIME; return -1; } } checkThree (toptarg, ':', &cp1, &cp2, &cp3); if ( cp2 != NULL ) { lserrno = LSE_BAD_TIME; return -1; } if ( (cp1 != NULL) && ((cp1[-1] == '/') || (cp1[1] == '/'))) { lserrno = LSE_BAD_TIME; return -1; } if (flag == 'w') { tmPtr = malloc (sizeof (struct tm)); tmPtr->tm_year = 70; tmPtr->tm_mon = 0; tmPtr->tm_mday = 1; tmPtr->tm_hour = 0; tmPtr->tm_min = 0; } else { ptimev = time(0); tmPtr = localtime(&ptimev); } tmPtr->tm_sec = 0; tmPtr->tm_isdst = -1; cp = cp1; checkThree (toptarg, '/', &cp1, &cp2, &cp3); if ( (cp == NULL) && (cp1 != NULL) && (cp2 == NULL) && (cp1 > toptarg) ) { *cp1 = '\000'; tempInt = atoi(toptarg); if (tempInt > 12) { ptimef |= YEAR; tmPtr->tm_year = tempInt; if (checkYear(&tmPtr->tm_year) == -1) { *cp1 = '/'; return -1; } if (( *(cp1+1) != '\000')) { ptimef |= MONTH; tmPtr->tm_mon = atoi(cp1+1); if (checkTime(MONTH, tmPtr->tm_mon) == -1) { *cp1 = '/'; return -1; } } else tmPtr->tm_mon = ( endTime ? 12 : 1 ); if (endTime) { m = tmPtr->tm_mon; if ((m==1) || (m==3) || (m==5) || (m==7) || (m==8) || (m==10) || (m==12)) tmPtr->tm_mday = 31; else if (m != 2) tmPtr->tm_mday = 30; else if (tmPtr->tm_year%4 == 0) tmPtr->tm_mday = 29; else tmPtr->tm_mday = 28; } else tmPtr->tm_mday = 1; } else { ptimef |= MONTH; tmPtr->tm_mon = tempInt; if (checkTime(MONTH, tmPtr->tm_mon) == -1) { *cp1 = '/'; return -1; } if ( *(cp1+1) != '\000') { ptimef |= DAY; tmPtr->tm_mday = atoi(cp1+1); if (checkTime(DAY, tmPtr->tm_mday) == -1) { *cp1 = '/'; return -1; } } else if (endTime) { m = tmPtr->tm_mon; if ((m==1) || (m==3) || (m==5) || (m==7) || (m==8) || (m==10) || (m==12)) tmPtr->tm_mday = 31; else if (m != 2) tmPtr->tm_mday = 30; else if (tmPtr->tm_year%4 == 0) tmPtr->tm_mday = 29; else tmPtr->tm_mday = 28; } else tmPtr->tm_mday = 1; } *cp1 = '/'; tmPtr->tm_mon--; tmPtr->tm_hour = ( endTime ? 23 : 0 ); tmPtr->tm_min = ( endTime ? 59 : 0 ); tmPtr->tm_sec = ( endTime ? 59 : 0 ); if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr, ptimef, sbtime); if (*Ptime < 0) return -1; return 0; } if ((cp == NULL) && (cp1 == toptarg) && (cp2 != NULL) ) { *cp2 = '\000'; cp2 = NULL; } if ((cp == NULL) && (cp1 == toptarg) && (cp2 == NULL)) { ptimef |= DAY; toptarg += 1; cp1 = NULL; } if ((cp == NULL) && (cp1 == NULL)) { ptimef |= DAY; tmPtr->tm_mday = atoi(toptarg); if (checkTime(DAY, tmPtr->tm_mday) == -1) return -1; tmPtr->tm_hour = ( endTime ? 23 : 0 ); tmPtr->tm_min = ( endTime ? 59 : 0 ); tmPtr->tm_sec = ( endTime ? 59 : 0 ); if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr, ptimef, sbtime); if (*Ptime < 0) return -1; return 0; } if ( (cp == NULL) && (cp2 != NULL) && (cp1 != toptarg) ) { if ((cp3 != NULL) || (*(cp2+1) != '\000')) { ptimef |= YEAR; ptimef |= MONTH; ptimef |= DAY; *cp1 = '\000'; tmPtr->tm_year = atoi(toptarg); if (checkYear(&tmPtr->tm_year) == -1) { *cp1 = '/'; return -1; } *cp1 = '/'; *cp2 = '\000'; tmPtr->tm_mon = atoi(cp1 + 1); *cp2 = '/'; if (cp3 != NULL) { *cp3 = '\000'; tmPtr->tm_mday = atoi(cp2 + 1); *cp3 = '/'; } else tmPtr->tm_mday = atoi(cp2 + 1); if (checkTime(DAY, tmPtr->tm_mday) == -1) return -1; } else { *cp1 = '\000'; tempInt = atoi(toptarg); if (tempInt > 12) { ptimef |= YEAR; tmPtr->tm_year = tempInt; if (checkYear(&tmPtr->tm_year) == -1) { *cp1 = '/'; return -1; } ptimef |= MONTH; *cp2 = '\000'; tmPtr->tm_mon = atoi(cp1+1); if (endTime) { m = tmPtr->tm_mon; if ((m==1) || (m==3) || (m==5) || (m==7) || (m==8) || (m==10) || (m==12)) tmPtr->tm_mday = 31; else if (m != 2) tmPtr->tm_mday = 30; else if (tmPtr->tm_year%4 == 0) tmPtr->tm_mday = 29; else tmPtr->tm_mday = 28; } else tmPtr->tm_mday = 1; } else { ptimef |= MONTH; tmPtr->tm_mon = tempInt; ptimef |= DAY; *cp2 = '\000'; tmPtr->tm_mday = atoi(cp1+1); } if (checkTime(DAY, tmPtr->tm_mday) == -1) { *cp1 = '/'; *cp2 = '/'; return -1; } } if (checkTime(MONTH, tmPtr->tm_mon) == -1) return -1; tmPtr->tm_mon--; *cp1 = '/'; *cp2 = '/'; tmPtr->tm_hour = ( endTime ? 23 : 0 ); tmPtr->tm_min = ( endTime ? 59 : 0 ); tmPtr->tm_sec = ( endTime ? 59 : 0 ); if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr,ptimef, sbtime); if (*Ptime < 0) return -1; return 0; } if ( (cp !=NULL) && (cp2 != NULL) && (cp3 != NULL) ) { if (cp3 != NULL) { ptimef |= YEAR; ptimef |= MONTH; ptimef |= DAY; *cp1 = '\000'; tmPtr->tm_year = atoi(toptarg); *cp1 = '/'; if (checkYear(&tmPtr->tm_year) == -1) return -1; *cp2 = '\000'; tmPtr->tm_mon = atoi(cp1+1); *cp2 = '/'; if (checkTime(MONTH, tmPtr->tm_mon) == -1) return -1; tmPtr->tm_mon--; *cp3 = '\000'; tmPtr->tm_mday = atoi(cp2+1); *cp3 = '/'; if (checkTime(DAY, tmPtr->tm_mday) == -1) return -1; *cp = '\000'; tmPtr->tm_hour = atoi(cp3+1); *cp = ':'; if (checkTime(HOUR, tmPtr->tm_hour) == -1) return -1; if (*(cp+1) != '\000') { tmPtr->tm_min = atoi(cp+1); if (checkTime(MINU, tmPtr->tm_min) == -1) return -1; } else { tmPtr->tm_min = ( endTime ? 59 : 0 ); tmPtr->tm_sec = ( endTime ? 59 : 0 ); } if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr, ptimef, sbtime); if (*Ptime < 0) return -1; return 0; } } if ( (cp !=NULL) && (cp2 != NULL) && (cp3 == NULL) ) { if ( cp1 > toptarg ) { ptimef |= MONTH; *cp1 = '\000'; tmPtr->tm_mon = atoi(toptarg); *cp1 = '/'; if (checkTime(MONTH, tmPtr->tm_mon) == -1) return -1; tmPtr->tm_mon--; toptarg = cp1; } if ( toptarg[0] == '/' ) { toptarg +=1; } cp1 = cp2; cp2 = NULL; } if ( (cp !=NULL) && (cp1 != NULL) && (cp2 == NULL) ) { if ( (cp1 > toptarg) && (cp1 < cp) ) { ptimef |= DAY; *cp1 = '\000'; tmPtr->tm_mday = atoi(toptarg); *cp1 = '/'; if (checkTime(DAY, tmPtr->tm_mday) == -1) return -1; toptarg = cp1+1; } else if (cp1 > cp) { lserrno = LSE_BAD_TIME; return -1; } } checkThree (toptarg, '/', &cp1, &cp2, &cp3); if ( (cp != NULL) && (cp1 == toptarg) && (cp2 == NULL)) { toptarg +=1; } if ( toptarg[0] == ':' ) { ptimef |= MINU; tmPtr->tm_min = atoi(cp+1); if (checkTime(MINU, tmPtr->tm_min) == -1) return -1; if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr, ptimef, sbtime); if (*Ptime < 0) return -1; return 0; } ptimef |= HOUR; if ( *(cp+1) != '\000') { ptimef |= MINU; tmPtr->tm_min = atoi(cp+1); if (checkTime(MINU, tmPtr->tm_min) == -1) return -1; } else tmPtr->tm_min = ( endTime ? 59 : 0 ); *cp = '\000'; tmPtr->tm_hour = atoi(toptarg); if (checkTime(HOUR, tmPtr->tm_hour) == -1) { *cp = ':'; return -1; } *cp = ':'; if (flag == 'w') { if ((ptimef & YEAR) == YEAR) { lserrno = LSE_BAD_TIME; return -1; } if ((ptimef & MONTH) == MONTH) tmPtr->tm_year--; if ((ptimef & DAY) == DAY) tmPtr->tm_year -= 2; } *Ptime = mkTime (tmPtr, ptimef, sbtime); if (*Ptime < 0) return -1; return 0; }
bool AssemblerY86::checkBool() { int error_row=0; return checkChar(error_row); }