void decode_format_parameters(const char* format_parameters, unsigned int* maxbandwidth, int* useinbandfec, int* stereo) { if (format_parameters && strlen(format_parameters)<=BLEN){ char buffer2[BLEN+1]; char *buffer = buffer2; strcpy(buffer, format_parameters); while (*buffer) { char *param_value; /* maxplaybackrate */ buffer=read_param(buffer, "maxplaybackrate", ¶m_value); if (param_value) { *maxbandwidth = atoi(param_value); if (!*maxbandwidth) { *maxbandwidth = _OPUS_RATE; DBG("wrong maxbandwidth value '%s'\n", param_value); } continue; } /* stereo */ buffer=read_param(buffer, "stereo", ¶m_value); if (param_value) { if (*param_value == '1') *stereo = 1; else *stereo = 0; continue; } /* useinbandfec */ buffer=read_param(buffer, "useinbandfec", ¶m_value); if (param_value) { if (*param_value == '1') *useinbandfec = 1; else *useinbandfec = 0; continue; } /* Unknown parameter */ if (*buffer) { param_value = buffer; while (*buffer && *buffer!=';') buffer++; if (*buffer) *buffer++ = 0; DBG("OPUS: SDP parameter fmtp: %s ignored in creating encoder.\n", param_value); } } } }
static int read_backend_default_spec(pa_sample_spec *sample_spec) { /* Read spec from backend */ char *out; out = read_param("default-format"); sample_spec->format = pa_parse_sample_format(out); free(out); out = read_param("default-rate"); sample_spec->rate = atoi(out); free(out); out = read_param("default-channels"); sample_spec->channels = atoi(out); free(out); return 0; }
XP_Bool get_16bit_row_bmp (CONVERT_IMGCONTEXT *p_params,CONVERT_IMG_INFO *p_info,CONVERT_IMG_ROW p_outputbuffer) /* This version is for reading 8-bit colormap indexes */ { CONVERT_IMG_ROW outptr = p_outputbuffer; BYTE t_byte; int16 col; uint32 t_redmask=0x00007C00; uint32 t_greenmask=0x000003E0; uint32 t_bluemask=0x0000001F; char t_redshift=10; char t_greenshift=5; char t_blueshift=0; uint16 t_redpad=0; uint16 t_greenpad=0; uint16 t_bluepad=0; if (!p_outputbuffer||!p_params||!p_info) { XP_ASSERT(FALSE); return FALSE; } if (p_info->m_numcolorentries==3) { if (!p_info->m_colormap) { XP_ASSERT(FALSE); return FALSE; } t_redmask=(p_info->m_colormap[0]<<16)+(p_info->m_colormap[1]<<8)+p_info->m_colormap[2]; t_greenmask=(p_info->m_colormap[3]<<16)+(p_info->m_colormap[4]<<8)+p_info->m_colormap[5]; t_bluemask=(p_info->m_colormap[6]<<16)+(p_info->m_colormap[7]<<8)+p_info->m_colormap[8]; process_color_mask(&t_redmask,&t_redshift,&t_redpad); process_color_mask(&t_greenmask,&t_greenshift,&t_greenpad); process_color_mask(&t_bluemask,&t_blueshift,&t_bluepad); } for (col = p_info->m_image_width; col > 0; col--) { uint16 t_pixel;/*16bits*/ uint16 t_temppixel; if (-1==read_param(&p_params->m_stream,&t_pixel,sizeof(t_pixel))) return FALSE; p_info->m_image_size+=sizeof(t_pixel); t_temppixel=(uint16)(t_redmask&t_pixel); if (t_redshift>0) t_temppixel=t_temppixel>>t_redshift; else t_temppixel=t_temppixel<<(-1 *t_redshift); t_temppixel=t_temppixel+t_redpad; outptr[0]=(BYTE)t_temppixel; t_temppixel=(uint16)(t_greenmask&t_pixel); if (t_greenshift>0) t_temppixel=t_temppixel>>t_greenshift; else
/** * Top function to read a HTK parameter file. * * @param filename [in] HTK parameter file name * @param pinfo [in] parameter data (already allocated by new_param()) * * @return TRUE on success, FALSE on failure. */ boolean rdparam(char *filename, HTK_Param *pinfo) { FILE *fp; boolean retflag; if ((fp = fopen_readfile(filename)) == NULL) return(FALSE); retflag = read_param(fp, pinfo); if (fclose_readfile(fp) < 0) return (FALSE); return (retflag); }
void decode_format_parameters(const char* format_parameters, SpeexState* ss) { /* See draft-herlein-avt-rtp-speex-00.txt */ /* TODO: change according to RFC 5574 */ if (format_parameters && strlen(format_parameters)<=BLEN){ char buffer2[BLEN+1]; char *buffer = buffer2; strcpy(buffer, format_parameters); while (*buffer) { char *error=NULL; char *param_value; /* Speex encoding mode */ buffer=read_param(buffer, "mode", ¶m_value); if (param_value) { int mode; if (strcmp(param_value, "any")) { mode = strtol(param_value, &error, 10); if (error!=NULL && error!=param_value && mode>=0 && mode<=10) DBG("Using speex sub mode %d", mode); ss->mode = mode; } continue; } /* Unknown parameter */ if (*buffer) { param_value = buffer; while (*buffer && *buffer!=';') buffer++; if (*buffer) *buffer++ = 0; WARN("SDP parameter fmtp: %s not set in speex.\n", param_value); } } } }
static ssize_t dsm_ctrl_read(struct file *fp, char __user *buf, size_t count, loff_t *pos) { int rc; static u8 param[DSM_PARAM_SZIE]; mutex_lock(&tx_lock); //pr_info("%s enter. (count:%d)\n", __func__, count); read_param(param); rc = copy_to_user(buf, param, count); if (rc != 0) { pr_err("copy_to_user failed. (rc=%d)\n", rc); mutex_unlock(&tx_lock); return 0; } //pr_info("%s out.\n", __func__); mutex_unlock(&tx_lock); return rc; }
int config::load(int argc, char* argv[]) { /* extract program name from path. e.g. /path/to/MArCd -> MArCd */ const char* program_name; const char* separator = strrchr(argv[0], '/'); if ( separator ) { program_name = separator + 1; } else { program_name = argv[0]; } char* filename = NULL; dictionary* config = NULL; /* locate configuration filename. This is done before getopt since getopt has * precedence over conf, so if this is run after getopt it would overwrite * getopt instead of vice-versa. */ for ( int i = 0; i < argc; i++ ) { int a = strcmp(argv[i], "-f") == 0; int b = strcmp(argv[i], "--config") == 0; if ( !(a||b) ) { continue; } if ( i+1 == argc ) { fprintf(stderr, "%s: missing argument to %s.\n", program_name, argv[i]); return 1; } filename = strdup(argv[i+1]); } /* if no configuration file was explicitly required try default paths */ if ( !filename ) { /* try in sysconfdir ($prefix/etc by default) */ char* tmp; int ret = asprintf(&tmp, "%s/%s", SYSCONF_DIR, MARCD_DEFAULT_CONFIG_FILE); if ( ret == -1 ) { fprintf(stderr, "%s: %s\n", program_name, strerror(errno)); exit(1); } if ( access(tmp, R_OK) == 0 ) { filename = tmp; } /* try default filename in pwd (has precedence of sysconfdir) */ if ( access(MARCD_DEFAULT_CONFIG_FILE, R_OK) == 0 ) { free(filename); filename = strdup(MARCD_DEFAULT_CONFIG_FILE); } } /* if we still don't have a filename we ignore it, the user hasn't requested * anything and no default could be located. */ if ( !filename ) { return 0; } /* parse configuration */ config_filename = filename; if ( !(config=iniparser_load(filename)) ) { return 1; } free(filename); /* mysql config */ read_param(db_hostname, sizeof(db_hostname), config, "mysql:hostname"); read_param(db_username, sizeof(db_username), config, "mysql:username"); read_param(db_password, sizeof(db_password), config, "mysql:password"); read_param(db_name, sizeof(db_name), config, "mysql:database"); /* security */ read_param(drop_priv_flag, config, "security:drop"); read_param(set_drop_username, config, "security:user"); read_param(set_drop_group, config, "security:group"); /* general */ read_param(have_relay_daemon, config, "general:relay"); read_param(set_control_ip, config, "general:listen"); read_param(rrdpath, config, "general:datadir"); return 0; }
int main(int argc, char *argv[]){ MPI_Init(&argc, &argv); MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); int i, j, k, n, l, indx, signal; bool flag; double deltat; double time_spend; double begin, end; FILE* energy; FILE* grid; begin = MPI_Wtime(); //read in parameters if(!read_param()){ MPI_Comm_free(&shmcomm); MPI_Finalize(); return 1; } flag = true; dE = 1; el_old = 1; cycle = 0; deltat = (0.1 - dt) / increment; S = 0.25 * (1 + 3 * sqrt(1 - 8 / (3 * U))); // printf("Theoretical value is %lf.\n", third * (1 - third * U) * S * S - 2 * third * third * third * S * S * S * U + U / 9 * S * S * S * S ); if(myid == root){ printf("S is %lf.\n\n", S); //define droplet and boundary, introduce particles, initialize qtensor; if(!initial()){ flag = false; } energy = fopen("energy.out", "w"); fprintf(energy,"cycle\tEnergy_diff\tEnergy_ldg\tEnergy_el\tEnergy_ch\tEnergy_surf\tEnergy_tot\n"); fclose(energy); grid = fopen("grid.bin", "wb"); l = 0; for(l = 0; l < tot; l++){ if(boundary[l] || nboundary[l]) signal = 1; else if(drop[l]) signal = 0; else signal = -1; fwrite(&signal, sizeof(int), 1, grid); } fclose(grid); } //For all infomation initialized in root processor, scatter them to all other processors. if(!scatter()){ flag = false; return 1; } //Evolution while(flag){ //Every 1000 steps calculate energies. if(cycle % 1000 == 0){ free_energy(); if(fabs(dE) < accuracy){ flag = false; } } if(cycle % 10000 == 0){ //Every 10000 steps check the trace of Qtensor if(myid == root){ for(i = 0; i < droplet; i++){ if(!checktr(&q[i * 6])){ flag = false; printf("Error in the trace of q.\n"); } if(flag == false) break; } //print output file output(); } MPI_Bcast(&flag, 1, MPI_BYTE, root, MPI_COMM_WORLD); } //Wait until all the processors are ready and relax the system, first bulk and then boundary. MPI_Barrier(MPI_COMM_WORLD); MPI_Win_fence(0, win); if(flag) relax_bulk(); MPI_Barrier(MPI_COMM_WORLD); MPI_Win_fence(0, win); if(flag) relax_surf(); if(dt < 0.1){ dt += deltat; if(dt >= 0.1) dt = 0.1; } cycle ++; MPI_Barrier(MPI_COMM_WORLD); MPI_Win_fence(0, win); } free_energy(); end = MPI_Wtime(); if(myid == root){ output(); //Calculate time used. time_spend = (double)(end - begin) / 60.0; energy = fopen("energy.out", "a"); if(time_spend < 60){ fprintf(energy, "\nTime used: %lf min.\n", time_spend); printf("\nTime used: %lf min.\n", time_spend); } else{ fprintf(energy, "\nTime used: %lf h.\n", time_spend / 60.0); printf("\nTime used: %lf h.\n", time_spend / 60.0); } fclose(energy); } //deallocate dynamic arrays free_q(); MPI_Win_free(&win); MPI_Comm_free(&shmcomm); MPI_Finalize(); return 0; }
int main (int argc,char *params[]) { int i,result[3]; unsigned char d=0; int a1=0,a2=0; unsigned short c1=0, c2=0; unsigned long int start,mstart=0,lastcall=0; start = time_msec(); /* Load parameters If parameters are valid continue */ if (read_param(argc,params)) { /* Initialise USB system and enable debug mode if ( debug ) usb_set_debug(2); */ /* Search the device */ if ( OpenDevice(ipid)<0 ) { printf("Could not open the k8055 (port:%d)\nPlease ensure that the device is correctly connected.\n",ipid); return (-1); } else { if ( resetcnt1 ) ResetCounter(1); if ( resetcnt2 ) ResetCounter(2); if ( dbt1 != -1 ) SetCounterDebounceTime(1,dbt1); if ( dbt2 != -1 ) SetCounterDebounceTime(2,dbt1); mstart = time_msec(); // Measure start for (i=0; i<numread; i++) { if ( delay ) { // Wait until next measure while ( time_msec()-mstart < i*delay ); } ReadAllAnalog(&a1,&a2); d=ReadAllDigital(); c1=ReadCounter(1); c2=ReadCounter(2); lastcall = time_msec(); printf("%d;%d;%d;%d;%d;%d\n", (int)(lastcall-start),d, (int)a1, (int)a2,c1,c2 ); } if (debug && ((ia1!=-1)||(ia2!=-1)||(id8!=-1))) printf("Set "); if (ia1!=-1){ result[0]=OutputAnalogChannel(1,ia1); if (debug) printf("analog1:%d ",result[0]);} if (ia2!=-1){ result[1]=OutputAnalogChannel(2,ia2); if (debug) printf("analog2:%d ",result[1]);} if (id8!=-1){ result[2]=WriteAllDigital((long)id8); if (debug) printf("digital:%d",result[2]);} if (debug) printf("\n"); CloseDevice(); } } return 0; }
int main(int argc, char *argv[]){ MPI_Init(&argc, &argv); MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); double t_begin; int i, j, k, ii, id, id1; t_begin = MPI_Wtime(); // record the begining CPU time read_param(); lattice_vec(); allocate(); p_allocate(); if (flow_on!=0) { build_stream(); } if (Q_on!=0) { build_neighbor(); } init_surf(); add_patch(); p_init(); p_iden(); init(); if (flow_on!=0) cal_fequ(f); if (Q_on!=0) cal_dQ(); if (Q_on!=0 && flow_on!=0 && newrun_on!=0) { while(qconverge==0) { t_current++; for (ii=0; ii<n_evol_Q; ii++) { cal_dQ(); evol_Q(); } if (t_current%t_print==0) monitor(); } e_tot =-1; k_eng =-1; qconverge = 0; uconverge = 0; t_current =-1; } if (Q_on!=0 && flow_on!=0) { cal_W(); cal_stress(); cal_sigma_p(); } MPI_Barrier(MPI_COMM_WORLD); output1(1,'z',Nx/2,Ny/2); output3(1); if(myid==0) printf("Q initialized\n"); MPI_Barrier(MPI_COMM_WORLD); while (t_current<t_max && uconverge*qconverge==0) { e_toto=e_tot; if (Q_on!=0 && qconverge==0) { if (flow_on!=0 && uconverge==0) cal_W(); for (ii=0; ii<n_evol_Q; ii++) { cal_dQ(); evol_Q(); } } if (flow_on!=0 && uconverge==0) { if (Q_on!=0 && qconverge==0) { cal_stress(); cal_sigma_p(); } evol_f(f,f2); } if (Q_on!=0 && qconverge==0) { if (flow_on!=0 && uconverge==0) cal_W(); for (ii=0; ii<n_evol_Q; ii++) { cal_dQ(); evol_Q(); } } if (flow_on!=0 && uconverge==0) { if (Q_on!=0 && qconverge==0) { cal_stress(); cal_sigma_p(); } evol_f(f2,f); } if (t_current%t_print==0) monitor(); if (t_current%t_write==0) { output1(0,'z',Nx/2,Ny/2); output3(0); fflush(stdout); } t_current++; } output_time(t_begin); output1(0,'z',Nx/2,Ny/2); output3(0); write_restart(); p_deallocate(); deallocate(); return 0; }
void param_set_t::read( const serialization::yaml_node_t& node) { for( int i = 0; i < node.size(); ++i) read_param( node[i]); }
/** Program to sort and format abbreviations used in LaTeX. To be used * with abbrev.sty. * @param Exactly one argument, the file to operate on. May be * specified as file or as file.abb * @name makeabbrev * @author Steve Marple * @version $Revision: 1.8 $ */ int main(int argc, char **argv) { int i; long ell; long line_start; long line_end; char *buffer = NULL; char *infile_name; char *outfile_name; char *cptr; char *abbrev_short; char *abbrev_full; char *key; FILE *infile; FILE *outfile; list_start = NULL; /* massage revision into a suitable version string */ version = malloc(sizeof(char) * (strlen(&revision[11]) + 1)); if(version == NULL) errmess(ERRMESS_NO_MEM); strcpy(version, &revision[11]); version[strlen(version) - 2] = '\0'; /* squish that space */ /* Print out a usage message, GNU say not to use argv[0] as program name. */ if(argc != 2) { printf("makeabbrev:\nusage\tmakeabbrev file\n"); exit(0); } /* create file names */ if(!strcmp(&argv[1][strlen(argv[1])-strlen(INFILE_EXT)], INFILE_EXT)) { /* filename extension given */ infile_name = malloc(sizeof(char) * (strlen(argv[1]) + 1)); outfile_name = malloc(sizeof(char) * (strlen(argv[1]) + strlen(OUTFILE_EXT) + 1)); if(infile_name == NULL || outfile_name == NULL) errmess(ERRMESS_NO_MEM); strcpy(infile_name, argv[1]); strncpy(outfile_name, argv[1], strlen(argv[1])-strlen(INFILE_EXT)); strcpy(&outfile_name[strlen(argv[1])-strlen(INFILE_EXT)], OUTFILE_EXT); } else { infile_name = malloc(sizeof(char) * (strlen(argv[1]) + strlen(INFILE_EXT) + 1)); outfile_name = malloc(sizeof(char) * (strlen(argv[1]) + strlen(OUTFILE_EXT) + 1)); if(infile_name == NULL || outfile_name == NULL) errmess(ERRMESS_NO_MEM); strcpy(infile_name, argv[1]); strcat(infile_name, INFILE_EXT); strcpy(outfile_name, argv[1]); strcat(outfile_name, OUTFILE_EXT); } /* Open files or quit */ if((infile = fopen(infile_name, "r")) == NULL) errmess("Cannot open file"); if((outfile = fopen(outfile_name, "w")) == NULL) errmess("Cannot open output file"); /* Print message */ printf("This is makeabbrev, version %s\n", version); printf("Scanning and sorting input file %s ...", infile_name); fflush(stdout); fprintf(outfile, "\\begin{theabbrev}\n"); /* read every line */ while(!feof(infile)) { line_num++; /* calculate line length - no limit on line lengths :-) */ line_start = ftell(infile); while((i = fgetc(infile)) != EOF && i != '\n') ; line_end = ftell(infile); /* copy line to buffer */ cptr = buffer = malloc(sizeof(char)*(line_end - line_start + 2)); if(buffer == NULL) errmess(ERRMESS_NO_MEM); fseek(infile, line_start, SEEK_SET); for(ell = line_start; ell < line_end -1; ++ell) *cptr++ = fgetc(infile); *cptr = '\0'; fgetc(infile); /* ignore newline */ abbrev_short = read_param(buffer, 1); abbrev_full = read_param(buffer, 2); if(abbrev_full == NULL || abbrev_short == NULL) continue; /* probably a blank line - ignore */ key = read_param(buffer, 3); key_sanity_check(&key, abbrev_short); /* insert_node free()'s abbrev_short & abbrev_full if not inserted into list */ insert_node(abbrev_short, abbrev_full, key); free(buffer); } printf("done\nGenerating output file %s ...", outfile_name); fflush(stdout); print_list(outfile); fprintf(outfile, "\\end{theabbrev}\n"); fclose(infile); fclose(outfile); printf("done\n"); free(buffer); free(infile_name); free(outfile_name); return 0; }
/** * Perform a read, write or just a listing of a parameter * * \param[in] popt list,set,get parameter options * \param[in] pattern search filter for the path of the parameter * \param[in] value value to set the parameter if write operation * \param[in] mode what operation to perform with the parameter * * \retval number of bytes written on success. * \retval -errno on error and prints error message. */ static int param_display(struct param_opts *popt, char *pattern, char *value, enum parameter_operation mode) { int dir_count = 0; char **dir_cache; glob_t paths; char *opname = parameter_opname[mode]; int rc, i; rc = cfs_get_param_paths(&paths, "%s", pattern); if (rc != 0) { rc = -errno; if (!popt->po_recursive) { fprintf(stderr, "error: %s: param_path '%s': %s\n", opname, pattern, strerror(errno)); } return rc; } dir_cache = calloc(paths.gl_pathc, sizeof(char *)); if (dir_cache == NULL) { rc = -ENOMEM; fprintf(stderr, "error: %s: allocating '%s' dir_cache[%zd]: %s\n", opname, pattern, paths.gl_pathc, strerror(-rc)); goto out_param; } for (i = 0; i < paths.gl_pathc; i++) { char *param_name = NULL, *tmp; char pathname[PATH_MAX]; struct stat st; int rc2; if (stat(paths.gl_pathv[i], &st) == -1) { fprintf(stderr, "error: %s: stat '%s': %s\n", opname, paths.gl_pathv[i], strerror(errno)); if (rc == 0) rc = -errno; continue; } if (popt->po_only_dir && !S_ISDIR(st.st_mode)) continue; param_name = display_name(paths.gl_pathv[i], &st, popt); if (param_name == NULL) { fprintf(stderr, "error: %s: generating name for '%s': %s\n", opname, paths.gl_pathv[i], strerror(ENOMEM)); if (rc == 0) rc = -ENOMEM; continue; } /** * For the upstream client the parameter files locations * are split between under both /sys/kernel/debug/lustre * and /sys/fs/lustre. The parameter files containing * small amounts of data, less than a page in size, are * located under /sys/fs/lustre and in the case of large * parameter data files, think stats for example, are * located in the debugfs tree. Since the files are split * across two trees the directories are often duplicated * which means these directories are listed twice which * leads to duplicate output to the user. To avoid scanning * a directory twice we have to cache any directory and * check if a search has been requested twice. */ if (S_ISDIR(st.st_mode)) { int j; for (j = 0; j < dir_count; j++) { if (!strcmp(dir_cache[j], param_name)) break; } if (j != dir_count) { free(param_name); param_name = NULL; continue; } dir_cache[dir_count++] = strdup(param_name); } switch (mode) { case GET_PARAM: /* Read the contents of file to stdout */ if (S_ISREG(st.st_mode)) read_param(paths.gl_pathv[i], param_name, popt); break; case SET_PARAM: if (S_ISREG(st.st_mode)) { rc2 = write_param(paths.gl_pathv[i], param_name, popt, value); if (rc2 < 0 && rc == 0) rc = rc2; } break; case LIST_PARAM: if (popt->po_show_path) printf("%s\n", param_name); break; } /* Only directories are searched recursively if * requested by the user */ if (!S_ISDIR(st.st_mode) || !popt->po_recursive) { free(param_name); param_name = NULL; continue; } /* Turn param_name into file path format */ rc2 = clean_path(popt, param_name); if (rc2 < 0) { fprintf(stderr, "error: %s: cleaning '%s': %s\n", opname, param_name, strerror(-rc2)); free(param_name); param_name = NULL; if (rc == 0) rc = rc2; continue; } /* Use param_name to grab subdirectory tree from full path */ tmp = strstr(paths.gl_pathv[i], param_name); /* cleanup paramname now that we are done with it */ free(param_name); param_name = NULL; /* Shouldn't happen but just in case */ if (tmp == NULL) { if (rc == 0) rc = -EINVAL; continue; } rc2 = snprintf(pathname, sizeof(pathname), "%s/*", tmp); if (rc2 < 0) { /* snprintf() should never an error, and if it does * there isn't much point trying to use fprintf() */ continue; } if (rc2 >= sizeof(pathname)) { fprintf(stderr, "error: %s: overflow processing '%s'\n", opname, pathname); if (rc == 0) rc = -EINVAL; continue; } rc2 = param_display(popt, pathname, value, mode); if (rc2 != 0 && rc2 != -ENOENT) { /* errors will be printed by param_display() */ if (rc == 0) rc = rc2; continue; } } for (i = 0; i < dir_count; i++) free(dir_cache[i]); free(dir_cache); out_param: cfs_free_param_data(&paths); return rc; }
test_config *read_test_config(char *configFile) { FILE *fConfig; test_config *cfg = NULL; char line[255], params[50], lib[100]; char *test=NULL, *p; strcpy(params, ""); cfg = init_fill_test_config(configFile); if (cfg == NULL) check_return(1, "Creating configuration structure.\n"); fConfig = fopen(configFile, "r"); if (!fConfig) return NULL; // Determine how many tests we actually have while (fgets(line, 255, fConfig) != NULL) { if (strchr(line, '[') && strchr(line, ']') && line[0] != '#' && !strncmp(line, "[General]", 9) == 0) cfg->general->test_count++; } cfg->test = (t_test **) MALLOC(sizeof(t_test *)*cfg->general->test_count); int num = -1; FCLOSE(fConfig); // Read all test cases along with the general information fConfig = FOPEN(configFile, "r"); strcpy(lib, ""); while (fgets(line, 255, fConfig) != NULL) { if (strncmp(line, "[General]", 9) == 0) strcpy(params, "general"); if (strcmp(params, "general") == 0) { test = read_param(line); if (strncmp(test, "suite", 5) == 0) strcpy(cfg->general->suite, read_str(line, "suite")); if (strncmp(test, "type", 4) == 0) strcpy(cfg->general->type, read_str(line, "type")); if (strncmp(test, "short configuration file", 24) == 0) cfg->general->short_config = read_int(line, "short configuration file"); if (strncmp(test, "status", 6) == 0) strcpy(cfg->general->status, read_str(line, "status")); } if (strchr(line, '[') && strchr(line, ']') && line[0] != '#' && !strncmp(line, "[General]", 9) == 0) { strcpy(params, "testcase"); num++; cfg->test[num] = newStruct(t_test); cfg->test[num]->test = (char *) MALLOC(sizeof(char)*100); strcpy(cfg->test[num]->test, ""); cfg->test[num]->file = (char *) MALLOC(sizeof(char)*1024); strcpy(cfg->test[num]->file, ""); cfg->test[num]->specs = (char *) MALLOC(sizeof(char)*100); strcpy(cfg->test[num]->specs, ""); cfg->test[num]->status = (char *) MALLOC(sizeof(char)*25); strcpy(cfg->test[num]->status, ""); if (strncmp(cfg->general->type, "library", 7) == 0) { cfg->test[num]->lib = (t_library *) MALLOC(sizeof(t_library)); cfg->test[num]->lib->name = (char *) MALLOC(sizeof(char)*255); } p = strchr(line, ']'); *p = '\0'; strcpy(cfg->test[num]->test, line+1); } if (strcmp(params, "testcase") == 0) { test = read_param(line); if (strncmp(test, "file", 4) == 0) strcpy(cfg->test[num]->file, read_str(line, "file")); if (strncmp(test, "specs", 5) == 0) strcpy(cfg->test[num]->specs, read_str(line, "specs")); if (strncmp(test, "status", 6) == 0) strcpy(cfg->test[num]->status, read_str(line, "status")); if (strncmp(test, "library function", 16) == 0) { strcpy(cfg->test[num]->lib->name, read_str(line, "library function")); if (strncmp(cfg->test[num]->lib->name, "get_cal_dn", 10) == 0) { init_library_function(cfg->test[num]->lib, "get_cal_dn"); strcpy(lib, "get_cal_dn"); } } if (strlen(lib) > 0 && strcmp_case(lib, "get_cal_dn") == 0) { if (strncmp_case(test, "meta file", 9) == 0) strcpy(cfg->test[num]->lib->get_cal_dn->meta_file, read_str(line, "meta file")); if (strncmp_case(test, "incidence angle", 15) == 0) cfg->test[num]->lib->get_cal_dn->incid = read_int(line, "incidence angle"); if (strncmp_case(test, "sample", 6) == 0) cfg->test[num]->lib->get_cal_dn->sample = read_int(line, "sample"); if (strncmp_case(test, "inDn", 4) == 0) cfg->test[num]->lib->get_cal_dn->inDn = read_float(line, "inDn"); if (strncmp_case(test, "bandExt", 7) == 0) strcpy(cfg->test[num]->lib->get_cal_dn->bandExt, read_str(line, "bandExt")); if (strncmp_case(test, "dbFlag", 6) == 0) cfg->test[num]->lib->get_cal_dn->dbFlag = read_int(line, "dbFlag"); if (strncmp(test, "expected value", 14) == 0) cfg->test[num]->lib->get_cal_dn->value = read_double(line, "expected value"); } } } if (test) FREE(test); else asfPrintError("Could not find manual tests in configuration file (%s).\n" "Does the configuration contains unit tests?\n", configFile); FCLOSE(fConfig); return cfg; }
/////////////////////////////////////// //////////READ BMP///////////////////// CONVERT_IMAGERESULT start_input_bmp (CONVERT_IMG_INFO *p_imageinfo, CONVERT_IMGCONTEXT *p_inputparam) { CONVERT_IMAGERESULT t_err; U_CHAR bmpfileheader[14]; U_CHAR bmpinfoheader[64]; #define GET_2B(array,offset) ((uint16) UCH(array[offset]) + \ (((uint16) UCH(array[offset+1])) << 8)) #define GET_4B(array,offset) ((int32) UCH(array[offset]) + \ (((int32) UCH(array[offset+1])) << 8) + \ (((int32) UCH(array[offset+2])) << 16) + \ (((int32) UCH(array[offset+3])) << 24)) int32 bfOffBits; int32 headerSize; int32 biWidth = 0; /* initialize to avoid compiler warning */ int32 biHeight = 0; uint16 biPlanes; int32 biCompression; int32 biXPelsPerMeter,biYPelsPerMeter; int32 biClrUsed = 0; int16 mapentrysize = 0; /* 0 indicates no colormap */ DWORD t_index=0;/*index to stream*/ int32 bPad; uint16 row_width; if (p_inputparam->m_stream.m_type==CONVERT_FILE) { if (!read_param(&p_inputparam->m_stream,bmpfileheader,14)) { /*cant read fileheader*/ return CONVERR_INVALIDFILEHEADER; } p_imageinfo->m_image_size+=14; /* Read and verify the bitmap file header */ if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ return CONVERR_INVALIDFILEHEADER; bfOffBits = (int32) GET_4B(bmpfileheader,10); } if (! read_param(&p_inputparam->m_stream, bmpinfoheader, 4)) return CONVERR_INVALIDIMAGEHEADER;//cant read 4 bytes p_imageinfo->m_image_size+=4; headerSize = (int32) GET_4B(bmpinfoheader,0); if (headerSize < 12 || headerSize > 64) return CONVERR_INVALIDIMAGEHEADER; if (! read_param( &p_inputparam->m_stream, bmpinfoheader+4, (int16)(headerSize-4))) /*casting here is ok beacause of check for >64 above*/ return CONVERR_INVALIDIMAGEHEADER; p_imageinfo->m_image_size+=headerSize-4; switch ((int16) headerSize) { case 12: /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ biWidth = (int32) GET_2B(bmpinfoheader,4); biHeight = (int32) GET_2B(bmpinfoheader,6); biPlanes = GET_2B(bmpinfoheader,8); p_imageinfo->m_bitsperpixel = (int16) GET_2B(bmpinfoheader,10); switch (p_imageinfo->m_bitsperpixel) { case 8: /* colormapped image */ mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ break; case 16: case 24: /* RGB image */ break; default: return CONVERR_INVALIDBITDEPTH; break; } if (biPlanes != 1) return CONVERR_INVALIDBITDEPTH; break; case 40: case 64: /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ /* or OS/2 2.x header, which has additional fields that we ignore */ biWidth = GET_4B(bmpinfoheader,4); biHeight = GET_4B(bmpinfoheader,8); biPlanes = GET_2B(bmpinfoheader,12); p_imageinfo->m_bitsperpixel = (int16) GET_2B(bmpinfoheader,14); biCompression = GET_4B(bmpinfoheader,16); biXPelsPerMeter = GET_4B(bmpinfoheader,24); biYPelsPerMeter = GET_4B(bmpinfoheader,28); biClrUsed = GET_4B(bmpinfoheader,32); /* biSizeImage, biClrImportant fields are ignored */ switch (p_imageinfo->m_bitsperpixel) { case 1: if (!biClrUsed)/* 0 denotes maximum usage of colors*/ biClrUsed=2; case 4: if (!biClrUsed)/* 0 denotes maximum usage of colors*/ biClrUsed=16; case 8: /* colormapped images */ if (!biClrUsed)/* 0 denotes maximum usage of colors*/ biClrUsed=256; mapentrysize = 4; /* Windows uses RGBQUAD colormap */ break; case 24: /* RGB image */ break; case 16: case 32: /* RGB image with masks*/ if (biCompression==3) /*BI_BITFIELDS*/ { biClrUsed=3; /*need to get masks for RGB*/ mapentrysize = 4; /* Windows uses RGBQUAD colormap */ } break; default: return CONVERR_INVALIDBITDEPTH; break; } if (biPlanes != 1) return FALSE; if (biCompression != 0) if (3!=biCompression) return CONVERR_COMPRESSED;//cant handle compressed bitmaps if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { /* Set JFIF density parameters from the BMP data */ p_imageinfo->m_X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ p_imageinfo->m_Y_density = (UINT16) (biYPelsPerMeter/100); p_imageinfo->m_density_unit = 2; /* dots/cm */ } break; default: return CONVERR_INVALIDIMAGEHEADER; break; } /* Compute distance to bitmap data --- will adjust for colormap below */ bPad = bfOffBits - (headerSize + 14); /* Read the colormap, if any */ if (mapentrysize > 0) { if (biClrUsed <= 0) biClrUsed = 256; /* assume it's 256 */ else if (biClrUsed > 256) return CONVERR_INVALIDCOLORMAP; /* Allocate space to store the colormap */ p_imageinfo->m_colormap = (BYTE *)malloc(biClrUsed*3); /* and read it from the file */ t_err=read_colormap_bmp(p_inputparam,p_imageinfo->m_colormap, (int16) biClrUsed, mapentrysize); if (t_err!=CONV_OK) return t_err; p_imageinfo->m_image_size+=biClrUsed*mapentrysize;/*mapentrysize for windows bitmaps*/ /* account for size of colormap */ bPad -= biClrUsed * mapentrysize; } if (CONVERT_FILE==p_inputparam->m_stream.m_type)/* Skip any remaining pad bytes */ { if (bPad < 0) /* incorrect bfOffBits value? */ return CONVERR_INVALIDIMAGEHEADER; while (--bPad >= 0) { (void) read_param_byte(&p_inputparam->m_stream); p_imageinfo->m_image_size++; } } /* Compute row width in file, including padding to 4-byte boundary */ switch (p_imageinfo->m_bitsperpixel) { case 1: row_width = biWidth/8; if (biWidth&7) row_width++; break; case 4: row_width = biWidth/2; if (biWidth&1) row_width++; break; case 8: row_width = (uint16) biWidth; break; case 16: row_width = (uint16) (biWidth * 2); break; case 24: row_width = (uint16) (biWidth * 3); break; case 32: row_width = (uint16) (biWidth * 4); break; default: return CONVERR_INVALIDBITDEPTH; } p_imageinfo->m_stride=row_width; while ((row_width & 3) != 0) row_width++; p_imageinfo->m_row_width = row_width; p_imageinfo->m_stride=p_imageinfo->m_row_width-p_imageinfo->m_stride;//difference /* p_imageinfo->m_in_color_space = JCS_RGB;*/ /* in color space is ignored. was only for JPEG PAL format*/ p_imageinfo->m_input_components = 3; p_imageinfo->m_data_precision = 8; p_imageinfo->m_image_width = (uint16) biWidth; p_imageinfo->m_image_height = (uint16) biHeight; p_imageinfo->m_numcolorentries=(short)biClrUsed; return CONV_OK; }