int eof_text_is_section_marker(const char *text) { if(text) { if((ustrstr(text, "[section") == text) || (ustrstr(text, "section") == text) || (ustrstr(text, "[prc_") == text)) return 1; //If the input string begins with any of these substrings, consider this a section event } return 0; }
char eof_song_contains_event_beginning_with(EOF_SONG *sp, const char *text, unsigned long track) { unsigned long i; if(sp && text) { for(i = 0; i < sp->text_events; i++) { if(track && (sp->text_event[i]->track != track)) { //If searching for events in a specific track, and this event isn't in that track continue; //Skip this event } if(ustrstr(sp->text_event[i]->text, text) == sp->text_event[i]->text) { //If a substring search returns the beginning of an existing text event as a match return 1; //Return match found } } } return 0; //Return no match found }
//***************************************************************************** // // Read the next chunck of data from the file. Return the count of data // that was read. Return 0 if no data is currently available. Return // a -1 if at the end of file. // //***************************************************************************** int fs_read(struct fs_file *file, char *buffer, int count) { int iAvailable; // // Check to see if an audio update was requested (pextension = 1). // if(file->pextension) { const struct fsdata_file *ptTree; // // Check to see if this is a file we know something about. // ptTree = file->pextension; if(strncmp((char *)ptTree->name, "/ptpclock", 9) == 0) { char *ptr, cTemp; extern volatile unsigned long g_ulSystemTimeSeconds; tTime sLocalTime; // // Check to see if the buffer size is large enough for the entire // file. If not, return EOF. // if(ptTree->len > count) { return(-1); } // // Copy the file into the buffer. // memcpy(buffer, ptTree->data, ptTree->len); // // Find the "div" marker for the PTP time. // ptr = ustrstr((const char *)buffer, "Www Mmm Dd, Yyyy Hh:Mm:Ss"); if(ptr == NULL) { return(-1); } // // Save the character after the date string. // cTemp = *(ptr + 26); // // Get the local time from the current second counter. // ulocaltime(g_ulSystemTimeSeconds, &sLocalTime); // // Print the the local time into the page buffer. // usprintf(ptr, "%3s %3s %2d, %4d %02d:%02d:%02d", g_ppcDay[sLocalTime.ucWday], g_ppcMonth[sLocalTime.ucMon], sLocalTime.ucMday, sLocalTime.usYear, sLocalTime.ucHour, sLocalTime.ucMin, sLocalTime.ucSec); *(ptr + 26) = cTemp; // // Clear the extension data and return the count. // file->pextension = NULL; return(ptTree->len); } // // Here, return EOF ... we don't now how to process this file. // else { return(-1); } } // // Check to see if more data is available. // if(file->len == file->index) { // // There is no remaining data. Return a -1 for EOF indication. // return(-1); } // // Determine how much data we can copy. The minimum of the 'count' // parameter or the available data in the file system buffer. // iAvailable = file->len - file->index; if(iAvailable > count) { iAvailable = count; } // // Copy the data. // memcpy(buffer, file->data + file->index, iAvailable); file->index += iAvailable; // // Return the count of data that we copied. // return(iAvailable); }
int usubstitute_env(char *line, int max_len) { char *tmp_line; char *env_cpy; char *dollar_bracket; char *closing_bracket; char *pre_str; char *env_str; char *env_val; char *post_str; int pre_len, env_len, post_len, tot_len; tmp_line = (char *) umalloc(max_len); env_cpy = (char *) umalloc(max_len); memset(env_cpy, 0, max_len); /* * look for opening '$(' sequence */ while ((dollar_bracket = ustrstr(line, "$(")) != NULL) { pre_str = line; env_str = dollar_bracket + 2; if ((closing_bracket = strchr(env_str, ')')) == NULL) { /* * no closing bracket */ fprintf(stderr, "WARNING - uparams_read:substitute_env\n"); fprintf(stderr, "No closing bracket for env variable\n"); fprintf(stderr, "Reading '%s'", line); ufree(tmp_line); ufree(env_cpy); return (-1); } /* if ((closing_bracket = ... */ post_str = closing_bracket + 1; /* * load up env string and null terminate */ env_len = (int) (closing_bracket - env_str); strncpy(env_cpy, env_str, env_len ); env_cpy[env_len] = '\0'; /* * get env val */ if ((env_val = getenv(env_cpy)) == NULL) { /* * no env variable set */ fprintf(stderr, "WARNING - uparams_read:substitute_env\n"); fprintf(stderr, "Env variable '%s' not set\n", env_cpy); ufree(tmp_line); ufree(env_cpy); return (-1); } /* * compute total length after substitution */ pre_len = (int) (dollar_bracket - pre_str); env_len = strlen(env_val); post_len = strlen(post_str); tot_len = pre_len + env_len + post_len + 1; if (tot_len > max_len) { /* * substituted string too long */ fprintf(stderr, "WARNING - uparams_read:substitute_env\n"); fprintf(stderr, "Env str too long.\n"); fprintf(stderr, "Reading '%s'", line); ufree(tmp_line); ufree(env_cpy); return (-1); } /* if (tot_len > max_len) */ /* * set tmp line and copy over */ *dollar_bracket = '\0'; sprintf(tmp_line, "%s%s%s", pre_str, env_val, post_str); ustrncpy(line, tmp_line, max_len); } /* while */ ufree(tmp_line); ufree(env_cpy); return (0); }
/********************************************************************** functionName:FRESULT report_search_subsn(uint8_t type,char *subsn,uint16_t offset,TEST_INFO_TypeDef *test,uint32_t *fnumb) description:通过试验编号查找结果,在指定试验类型中试验编号只要包含“subsn”中的字符,都搜索出来 type:试验种类 subsn:搜索文件名中包含“subsn”字符串 offset 偏移量,一次只能搜索10个文件名,搜索后面的试验,需要使用此变量,提过前面的文件 test:最多返回偏移后的10组试验信息,test定时的时候必须是11个数组,最后一个数组文件名全部为0表示结束。 fnumb:返回查找到的文件数量 **********************************************************************/ FRESULT report_search_sn(uint8_t type,char *subsn,uint16_t offset,TEST_INFO_TypeDef *test,uint32_t *fnumb) { DIR dir_object; FILINFO file_info; FRESULT fresult; uint8_t i=0; uint8_t j=0; uint8_t long_file_name = 0; //长文件名标志 uint8_t dot_num = 0; #if _USE_LFN file_info.lfname = Lfname; file_info.lfsize = sizeof(Lfname); #endif *fnumb=0; if((type>KZTY)||(!type)) return FR_NO_FILE; else { fresult = f_opendir(&dir_object,test_path[type].path); if(fresult != FR_OK) return fresult; for(;;) { fresult = f_readdir(&dir_object, &file_info); if(fresult != FR_OK) return fresult; if(!file_info.fname[0]) //如果文件名是空的,跳过文件 break; long_file_name = (file_info.lfname[0] == 0) ? 0 : 1; //判断是否是长文件名 if(file_info.fattrib&AM_ARC) //如果是一个文件 { if ( !long_file_name ) { if(ustrstr(file_info.fname,subsn)!=NULL) { *fnumb+=1; if(offset) { offset--; } else if(j<10) { dot_num = GetDotNum(file_info.fname); for(i=0;i<8;i++) { if (file_info.fname[i] == '.') { if (dot_num == 1) { break; } else { dot_num--; } } test->fname[i]=file_info.fname[i]; } test->fname[i]=0; fstime2tTime((tTime *)&(test->time),file_info.fdate,file_info.ftime); test++; j++; } } } else { if(ustrstr(file_info.lfname,subsn)!=NULL) { *fnumb+=1; if(offset) { offset--; } else if(j<10) { dot_num = GetDotNum(file_info.lfname); for(i=0;i<16;i++) { if (file_info.lfname[i] == '.') { if (dot_num == 1) { break; } else { dot_num--; } } test->fname[i]=file_info.lfname[i]; } test->fname[i]=0; fstime2tTime((tTime *)&(test->time),file_info.fdate,file_info.ftime); test++; j++; } } } } } for(i=0;i<16;i++) test->fname[i]=0; } return FR_OK; }