char * get_config_string (char *section, char *keyword, char *default_value) { char *p = get_config_var (section, keyword); return (p == NULL ? default_value : p); }
char *read_cgminer_conf(char *item) { char *get_iterm; parse_luciconf_file(luci_cgminer_dir); get_iterm=get_config_var(item); return get_iterm; }
char *read_luci_conf(char *item) { char *get_iterm; parse_luciconf_file(luci_conf_directory); get_iterm=get_config_var(item); return get_iterm; }
int get_config_int (char *section, char *keyword, int default_value) { char *p = get_config_var (section, keyword); if (p == NULL) return default_value; return atoi (p); }
void OpenProjectsFromList(COMMAND_T*) { char cPath[256]; GetProjectPath(cPath, 256); char* filename = BrowseForFiles(__LOCALIZE("Select project list","sws_mbox"), cPath, NULL, false, "Reaper Project List (*.RPL)\0*.RPL\0All Files\0*.*\0"); if (filename) { FILE* f = fopenUTF8(filename, "r"); if (f) { // Save "prompt on new project" variable int iNewProjOpts; int sztmp; int* pNewProjOpts = (int*)get_config_var("newprojdo", &sztmp); iNewProjOpts = *pNewProjOpts; *pNewProjOpts = 0; int i = 0; int iProjects = -1; while (EnumProjects(++iProjects, NULL, 0)); // Count projects char cName[10]; EnumProjects(-1, cName, 10); if (iProjects != 1 || cName[0] != 0 || GetNumTracks() != 0) { if (MessageBox(g_hwndParent, __LOCALIZE("Close active tabs first?","sws_mbox"), __LOCALIZE("SWS Project List Open","sws_mbox"), MB_YESNO) == IDYES) Main_OnCommand(40886, 0); else i = 1; } while(fgets(cPath, 256, f)) { char* pC; while((pC = strchr(cPath, '\r'))) *pC = 0; // Strip newlines no matter the format while((pC = strchr(cPath, '\n'))) *pC = 0; if (cPath[0]) { if (i++) Main_OnCommand(41929, 0); // New project tab (ignore default template) Main_openProject(cPath); } } fclose(f); *pNewProjOpts = iNewProjOpts; } else MessageBox(g_hwndParent, __LOCALIZE("Unable to open file.","sws_mbox"), __LOCALIZE("SWS Project List Open","sws_mbox"), MB_OK); free(filename); } }
int main(int argc, char *argv[]) { FILE *file=fopen("test.config", "w"); fwrite(some_data, 1, strlen(some_data), file); fclose(file); parse_config_file("test.config", 0); printf("abc=%s\n", get_config_var("abc")); return 0; }
void* GetConfigVar(const char* cVar) { int sztmp; void* p = NULL; if (int iOffset = projectconfig_var_getoffs(cVar, &sztmp)) { p = projectconfig_var_addr(EnumProjects(-1, NULL, 0), iOffset); } else if ((p = get_config_var(cVar, &sztmp))) { } else { p = get_midi_config_var(cVar, &sztmp); } return p; }
void OpenRelatedProject(COMMAND_T* pCmd) { if ((int)pCmd->user == g_relatedProjects.Get()->GetSize()) // Give the user the chance to add a related project if they selected the first open spot if (MessageBox(g_hwndParent, __LOCALIZE("No related project found. Add one now?","sws_mbox"), __LOCALIZE("SWS Open Related Project","sws_mbox"), MB_YESNO) == IDYES) AddRelatedProject(); if ((int)pCmd->user >= g_relatedProjects.Get()->GetSize()) return; WDL_String* pStr = g_relatedProjects.Get()->Get((int)pCmd->user); ReaProject* pProj; // See if it's already opened char cOpenedProj[256]; int i = 0; while ((pProj = EnumProjects(i++, cOpenedProj, 256))) { if (_stricmp(cOpenedProj, pStr->Get()) == 0) { SelectProjectInstance(pProj); return; } } // Nope, open in new tab // Save "prompt on new project" variable int iNewProjOpts; int sztmp; int* pNewProjOpts = (int*)get_config_var("newprojdo", &sztmp); iNewProjOpts = *pNewProjOpts; *pNewProjOpts = 0; pProj = EnumProjects(-1, NULL, 0); Main_OnCommand(41929, 0); // New project tab (ignore default template) Main_openProject(pStr->Get()); EnumProjects(-1, cOpenedProj, 256); if (_stricmp(pStr->Get(), cOpenedProj)) { Main_OnCommand(40860, 0); // 40860 = Close current project tab SelectProjectInstance(pProj); g_relatedProjects.Get()->Delete((int)pCmd->user, true); } *pNewProjOpts = iNewProjOpts; }
int make_LUH() { FILE *fp_luh,*f_su; struct multi_file_crc files; int k,i,m; int luh_file_length; int luh_fpos; int len,ret; uint64_t len_64; unsigned int su_len; unsigned short length,nu_tar,nu_with,nu_posi,nu_file; unsigned short file_num; unsigned short load_count; unsigned short check_type,check_type_temp; unsigned short crc_type_8,crc_type_16,crc_type_32; unsigned short data_crc_8[10],sup_crc_8[10],multi_crc8; unsigned short data_crc_16[10],sup_crc_16[10]; unsigned short sup_total_crc_16,multi_crc16,header_file_crc; unsigned int data_crc_32[10],sup_crc_32[10]; unsigned int multi_crc32,load_crc; char *ch; char s[15]="load_"; char path_name[50],luh_name[70],data_name[70],sup_name[70]; char target_ID[10][30]= { "luh_target_ID_001","luh_target_ID_002","luh_target_ID_003", "luh_target_ID_004","luh_target_ID_005", "luh_target_ID_006","luh_target_ID_007","luh_target_ID_008", "luh_target_ID_009","luh_target_ID_010" }; char target_with_position[10][40]= { "luh_target_with_position_001","luh_target_with_position_002","luh_target_with_position_003", "luh_target_with_position_004","luh_target_with_position_005", "luh_target_with_position_006","luh_target_with_position_007","luh_target_with_position_008", "luh_target_with_position_009","luh_target_with_position_010" }; char number_target_position[10][40]= { "luh_number_target_position_001","luh_number_target_position_002","luh_number_target_position_003", "luh_number_target_position_004","luh_number_target_position_005", "luh_number_target_position_006","luh_number_target_position_007","luh_number_target_position_008", "luh_number_target_position_009","luh_number_target_position_010" }; char position[10][5][30]= { {"luh_position_001_001","luh_position_001_002","luh_position_001_003","luh_position_001_004","luh_position_001_005"}, {"luh_position_002_001","luh_position_002_002","luh_position_002_003","luh_position_002_004","luh_position_002_005"}, {"luh_position_003_001","luh_position_003_002","luh_position_003_003","luh_position_003_004","luh_position_003_005"}, {"luh_position_004_001","luh_position_004_002","luh_position_004_003","luh_position_004_004","luh_position_004_005"}, {"luh_position_005_001","luh_position_005_002","luh_position_005_003","luh_position_005_004","luh_position_005_005"}, {"luh_position_006_001","luh_position_006_002","luh_position_006_003","luh_position_006_004","luh_position_006_005"}, {"luh_position_007_001","luh_position_007_002","luh_position_007_003","luh_position_007_004","luh_position_007_005"}, {"luh_position_008_001","luh_position_008_002","luh_position_008_003","luh_position_008_004","luh_position_008_005"}, {"luh_position_009_001","luh_position_009_002","luh_position_009_003","luh_position_009_004","luh_position_009_005"}, {"luh_position_010_001","luh_position_010_002","luh_position_010_003","luh_position_010_004","luh_position_010_005"} }; /***************data file*******************/ char data_file_p[10][30]= { "0x0000","0x0000","0x0000", "0x0000","0x0000", "0x0000","0x0000","0x0000", "0x0000","0x0000" }; char data_file_name[10][30]= { "luh_data_file_name_001","luh_data_file_name_002","luh_data_file_name_003", "luh_data_file_name_004","luh_data_file_name_005", "luh_data_file_name_006","luh_data_file_name_007","luh_data_file_name_008", "luh_data_file_name_009","luh_data_file_name_010" }; char data_file_PN[10][30]= { "luh_data_file_PN_001","luh_data_file_PN_002","luh_data_file_PN_003", "luh_data_file_PN_004","luh_data_file_PN_005", "luh_data_file_PN_006","luh_data_file_PN_007","luh_data_file_PN_008", "luh_data_file_PN_009","luh_data_file_PN_010" }; char data_check_value_type[10][40]= { "luh_data_file_check_value_type_001","luh_data_file_check_value_type_002","luh_data_file_check_value_type_003", "luh_data_file_check_value_type_004","luh_data_file_check_value_type_005", "luh_data_file_check_value_type_006","luh_data_file_check_value_type_007","luh_data_file_check_value_type_008", "luh_data_file_check_value_type_009","luh_data_file_check_value_type_010" }; /***************support file*******************/ char support_file_p[10][30]= { "0x0000","0x0000","0x0000", "0x0000","0x0000", "0x0000","0x0000","0x0000", "0x0000","0x0000" }; char support_file_name[10][30]= { "luh_support_file_name_001","luh_support_file_name_002","luh_support_file_name_003", "luh_support_file_name_004","luh_support_file_name_005", "luh_support_file_name_006","luh_support_file_name_007","luh_support_file_name_008", "luh_support_file_name_009","luh_support_file_name_010" }; char support_file_PN[10][30]= { "luh_support_file_PN_001","luh_support_file_PN_002","luh_support_file_PN_003", "luh_support_file_PN_004","luh_support_file_PN_005", "luh_support_file_PN_006","luh_support_file_PN_007","luh_support_file_PN_008", "luh_support_file_PN_009","luh_support_file_PN_010" }; char support_check_value_type[10][40]= { "luh_support_file_check_value_type_001","luh_support_file_check_value_type_002","luh_support_file_check_value_type_003", "luh_support_file_check_value_type_004","luh_support_file_check_value_type_005", "luh_support_file_check_value_type_006","luh_support_file_check_value_type_007","luh_support_file_check_value_type_008", "luh_support_file_check_value_type_009","luh_support_file_check_value_type_010" }; ret=select_section("[media_set]"); if(FAILED==ret) { printf("select_section error\n"); return FAILED; } ch=get_config_var("load_count"); if(ch==NULL) { printf("get load_count error\n"); return FAILED; } load_count=htoi(ch); for(m=1;m<=load_count;m++)//make multi luh files { sprintf(s,"[load_%.3d]",m); //printf("s=%s\n",s); ret=select_section(s); if(FAILED==ret) { printf("select_section error\n"); return FAILED; } strcpy(path_name,"./media665-3"); ch=get_config_var("load_path"); if(ch==NULL) { printf("get load_path error\n"); return FAILED; } change_symbol(ch); strcat(path_name,ch); ch=get_config_var("head_file_name"); if(ch==NULL) { printf("get head_file_name error\n"); return FAILED; } strcpy(luh_name,path_name); strcat(luh_name,ch); fp_luh=fopen(luh_name, "wb+"); if (NULL == fp_luh) { printf("can't open '%s' as config file:%s\n",fp_luh,strerror(errno)); goto EXIT; } /********make LUH**********/ fseek(fp_luh,4,0);//the leading four bytes is file length ch=get_config_var("luh_file_version"); if(ch==NULL) { printf("get luh_file_version error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_part_flags"); if(ch==NULL) { printf("get luh_part_flags error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_PN_length"); if(ch==NULL) { printf("get luh_p_PN_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_target_ID"); if(ch==NULL) { printf("get luh_p_target_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_data_file"); if(ch==NULL) { printf("get luh_p_number_data_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_support_file"); if(ch==NULL) { printf("get luh_p_number_support_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_user_defined_data"); if(ch==NULL) { printf("get luh_p_user_defined_data error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_type_description_length"); if(ch==NULL) { printf("get luh_p_type_description_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_number_target_positions"); if(ch==NULL) { printf("get luh_p_number_target_positions error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_p_check_value_length"); if(ch==NULL) { printf("get luh_p_check_value_length error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_load_PN"); if(ch==NULL) { printf("get luh_load_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write load PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if((strlen(ch)%2)!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } }//if odd ,add 0x00 ch=get_config_var("luh_type_description"); if(ch==NULL) { printf("get luh_type_description error\n"); } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write description length if(ret<0) { printf("fwrite error\n"); } ret=fwrite_chars(ch,fp_luh);//write description if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var("luh_type_ID"); if(ch==NULL) { printf("get luh_type_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var("luh_number_target_ID"); if(ch==NULL) { printf("get luh_number_target_ID error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_tar=htoi(ch); for(k=0;k<nu_tar;k++) //number of target HW ID { ch=get_config_var(target_ID[k]); if(ch==NULL) { printf("get target_ID error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write position length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write target id if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } } ch=get_config_var("luh_number_target_with_position"); if(ch==NULL) { printf("get luh_number_target_with_position error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_with=htoi(ch); for(k=0;k<nu_with;k++) //number of target HW ID with position循环 { ch=get_config_var(target_with_position[k]); if(ch==NULL) { printf("get target_with_position error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write target with position if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(number_target_position[k]); if(ch==NULL) { printf("get number_target_position error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_posi=htoi(ch); for(i=0;i<nu_posi;i++) //number of target HW ID position { ch=get_config_var(position[k][i]); if(ch==NULL) { printf("get position error\n"); return FAILED; } length=htons(strlen(ch)); fwrite(&length,sizeof(short),1,fp_luh);//write length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write position if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } } } crc_type_8=htons(CRC_8_TYPE); crc_type_16=htons(CRC_16_TYPE); crc_type_32=htons(CRC_32_TYPE); /***************data file*******************/ #if 1 ch=get_config_var("luh_number_data_file"); if(ch==NULL) { printf("get luh_number_data_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } file_num=htoi(ch); for(k=0;k<file_num;k++) { ret=fwrite_atohex(data_file_p[k],fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var(data_file_name[k]); if(ch==NULL) { printf("get data_file_name error\n"); return FAILED; } //printf("k=%d\n",k); strcpy(data_name,path_name); strcat(data_name,ch); //printf("data_name=%s\n",data_name); strcpy(files.data_file_name[k],data_name); length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write file name length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write name if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(data_file_PN[k]); if(ch==NULL) { printf("get data_file_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write data PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write data PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } len=calculate_file_length_32(data_name); if(len%2!=0) { len=(len+1)/2; } else { len=len/2; } len=htonl(len); ret=fwrite(&len,sizeof(int),1,fp_luh);//write data file length if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_16[k]=crc_16(data_name); //CRC_16校验 printf("data_crc_16[%d]=0x%x\n",k,data_crc_16[k]); data_crc_16[k]=htons(data_crc_16[k]); ret=fwrite(&data_crc_16[k],sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } len_64=calculate_file_length_64(data_name); //printf("*****data file length_64: %x\n",len); len_64=hton64(len_64);//big end or small end //printf("*****change data file length_64: %llx\n",len); ret=fwrite(&len_64,sizeof(char),8,fp_luh); //write data file length in bytes if(ret<0) { printf("fwrite error\n"); return FAILED; } ch=get_config_var(data_check_value_type[k]); if(ch==NULL) { printf("get data_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("data file check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_8[k]=crc_8(data_name); //printf("data_crc_8[%d]=0x%x\n",k,data_crc_8[k]); data_crc_8[k]=htonl(data_crc_8[k]); ret=fwrite(&data_crc_8[k],sizeof(char),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&data_crc_16[k],sizeof(short),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write data check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write data check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } data_crc_32[k]=crc_32(data_name); //printf("data_crc_32[%d]=0x%x\n",k,data_crc_32[k]); data_crc_32[k]=htonl(data_crc_32[k]); ret=fwrite(&data_crc_32[k],sizeof(int),1,fp_luh);//write data check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } } #endif /*******support file*********/ ch=get_config_var("luh_number_support_file"); if(ch==NULL) { printf("get luh_number_support_file error\n"); return FAILED; } ret=fwrite_atohex(ch,fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } nu_file=htoi(ch); for(k=0;k<nu_file;k++) //number of support files { ret=fwrite_atohex(support_file_p[k],fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } ch=get_config_var(support_file_name[k]); if(ch==NULL) { printf("get support_file_name error\n"); return FAILED; } strcpy(sup_name,path_name); strcat(sup_name,ch); //printf("sup_name=%s\n",sup_name); strcpy(files.su_file_name[k],sup_name); f_su=fopen(sup_name,"r"); if(f_su==NULL) { printf("can`t open support file\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write support file name length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write name if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } ch=get_config_var(support_file_PN[k]); if(ch==NULL) { printf("get support_file_PN error\n"); return FAILED; } length=htons(strlen(ch)); ret=fwrite(&length,sizeof(short),1,fp_luh);//write PN length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh);//write PN if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } if(strlen(ch)%2!=0) { ret=fwrite_atohex("0x00",fp_luh); if(ret<0) { printf("fwrite_atohex error\n"); return FAILED; } } fseek(f_su,0,2);//move to the file end su_len=ftell(f_su); su_len=htonl(su_len); ret=fwrite(&su_len,sizeof(unsigned int),1,fp_luh);//write support file length if(ret<0) { printf("fwrite error\n"); return FAILED; } rewind(f_su);//move to the file start fclose(f_su); sup_crc_16[k]=crc_16(sup_name); sup_crc_16[k]=htons(sup_crc_16[k]); ret=fwrite(&sup_crc_16[k],sizeof(short),1,fp_luh);//write support file crc if(ret<0) { printf("fwrite error\n"); return FAILED; } //printf("sup_crc_16[%d]=0x%x\n",k,sup_crc_16[k]); ch=get_config_var(support_check_value_type[k]); if(ch==NULL) { printf("get support_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("support file check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } sup_crc_8[k]=crc_8(sup_name); //printf("sup_crc_8[%d]=0x%x\n",k,sup_crc_8[k]); sup_crc_8[k]=htonl(sup_crc_8[k]); ret=fwrite(&sup_crc_8[k],sizeof(char),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write support check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write support check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&sup_crc_16[k],sizeof(short),1,fp_luh);//write support check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write support check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write support check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } sup_crc_32[k]=crc_32(sup_name); // printf("sup_crc_32[%d]=0x%x\n",k,sup_crc_32[k]); sup_crc_32[k]=htonl(sup_crc_32[k]); ret=fwrite(&sup_crc_32[k],sizeof(int),1,fp_luh);//write support check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } } ch=get_config_var("luh_user_defined_data"); if(ch==NULL) { printf("get luh_user_defined_data error\n"); return FAILED; } ret=fwrite_chars(ch,fp_luh); if(ret<0) { printf("fwrite_chars error\n"); return FAILED; } luh_fpos=ftell(fp_luh); files.data_file_num=file_num; files.su_file_num=nu_file; strcpy(files.luh_file_name,luh_name); files.luh_length=luh_fpos; ch=get_config_var("luh_load_check_value_type"); if(ch==NULL) { printf("get luh_load_check_value_type error\n"); return FAILED; } check_type=chtoshort_hex(ch); //printf("load check type=0x%x\n",check_type); check_type_temp=htons(check_type); switch(check_type) { case 1: ret=fwrite(&crc_type_8,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc8=multi_crc_8(files); //printf("multi_crc8=0x%x\n",multi_crc8); multi_crc8=htons(multi_crc8); ret=fwrite(&multi_crc8,sizeof(short),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 2: ret=fwrite(&crc_type_16,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc16=multi_crc_16(files); //printf("multi_crc16=0x%x\n",multi_crc16); multi_crc16=htons(multi_crc16); ret=fwrite(&multi_crc16,sizeof(short),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; case 3: ret=fwrite(&crc_type_32,sizeof(short),1,fp_luh);//write load crc check value length if(ret<0) { printf("fwrite error\n"); return FAILED; } ret=fwrite(&check_type_temp,sizeof(short),1,fp_luh);//write load crc check value type if(ret<0) { printf("fwrite error\n"); return FAILED; } multi_crc32=multi_crc_32(files); //printf("multi_crc32=0x%x\n",multi_crc32); multi_crc32=htonl(multi_crc32); ret=fwrite(&multi_crc32,sizeof(int),1,fp_luh);//write load crc check value if(ret<0) { printf("fwrite error\n"); return FAILED; } break; default: ; } luh_fpos=ftell(fp_luh); header_file_crc=crc_file_pos_16(luh_name,luh_fpos); printf("header_file_crc=0x%x\n",header_file_crc); header_file_crc=htons(header_file_crc); ret=fwrite(&header_file_crc,sizeof(short),1,fp_luh);//header file crc if(ret<0) { printf("fwrite error\n"); return FAILED; } luh_fpos=ftell(fp_luh); load_crc=crc_file_pos_32(luh_name,luh_fpos); printf("load_crc=0x%x\n",load_crc); load_crc=htons(load_crc); ret=fwrite(&load_crc,sizeof(int),1,fp_luh);//load crc if(ret<0) { printf("fwrite error\n"); return FAILED; } fseek(fp_luh,0,2);//move to the file end luh_file_length=ftell(fp_luh); luh_file_length=htonl(luh_file_length); rewind(fp_luh);//move to the file start ret=fwrite(&luh_file_length,sizeof(long),1,fp_luh); if(ret<0) { printf("fwrite error\n"); return FAILED; } EXIT: fclose(fp_luh); return FAILED; } return OK; }