📄 foo.c
字号:
static long align_pad_size;#ifdef DEMOstatic long check_code;#endifextern int sphere_to_sd_ctrl; /* defined in sphere.c */struct header *read_header (fd)FILE * fd;{ static struct header *recursive_rh (); struct header *sphere_to_feasd(); long nrec(), k; struct header *p; long foreign_hd_length; if (getenv("ESPSDEBUG")) EspsDebug = 1;#ifndef NOKEY if((sphere_to_sd_ctrl != 123)) check_header(MACH_CODE);#endif p = recursive_rh(fd, 0); if(p == NULL) { if (EspsDebug) Fprintf(stderr,"read_header: recursive_rh == NULL\n");/* check and see if it is a NIST sphere header */ if (fseek(fd, 0L, 0) == 0) { /* its not a pipe */ if (EspsDebug) Fprintf(stderr,"not a pipe\n"); if((p = sphere_to_feasd(fd)) == NULL) { /* not a NIST either */ char *def_header; FILE *header_fd; if (EspsDebug) Fprintf(stderr,"not a NIST, rewinding\n"); (void)fseek(fd, 0L, 0); /* rewind *//* if the file is a SIG header file, then just return NULL, so that the code in waves does the right thing*/ if (EspsDebug) Fprintf(stderr,"read_header: see if its SIG\n"); if (is_SIG_file(fd)) { if (EspsDebug) Fprintf(stderr,"read_header: it is SIG\n"); return NULL; }/* In this case its not an ESPS, NIST or SIG file, so if DEF_HEADER is defined, then try and add a default ESPS header to it*/ def_header = getenv("DEF_HEADER"); if(EspsDebug) Fprintf(stderr,"read_header: not a Sphere\n"); if (def_header && (header_fd = fopen(def_header,"r"))) { if(EspsDebug) Fprintf(stderr,"read_header: def_header: %s\n",def_header); p = recursive_rh(header_fd, 0); (void)fclose(header_fd); if (p == NULL) { fprintf(stderr,"DEF_HEADER not ESPS\n"); return NULL; } (void)fseek(fd, 0L, 0); } else { if(EspsDebug) Fprintf(stderr,"read_header: no default header\n"); return NULL; } } } else { if(EspsDebug) Fprintf(stderr,"read_header: cannot rewind\n"); return NULL; } } if (!getenv("ESPS_NOALIGN")) { if(EspsDebug) Fprintf(stderr,"read_header: NOALIGN not set\n"); if (!old_version(p->common.hdvers,PRE_ALIGNMENT)){ if(EspsDebug && (align_pad_size != 0)) Fprintf(stderr,"read_header: skipping alignment pad\n"); if(EspsDebug) { Fprintf(stderr,"offset: %x\n",data_offset); Fprintf(stderr,"align pad size: %x\n",align_pad_size); } if(align_pad_size != 0) { char *align_pad = malloc((unsigned)align_pad_size); spsassert(align_pad,"read_header: failed to alloc align pad"); if (!miio_get_byte(align_pad, align_pad_size, YES, NONE, fd)) BADHEAD (0, "error reading alignment pad"); free(align_pad); } } else if(EspsDebug) Fprintf(stderr,"read_header: old_version or alignpad_size == 0\n"); } foreign_hd_length = (long)get_genhd_val("foreign_hd_length",p,0.0); if(EspsDebug) Fprintf(stderr, "read_header: foreign_hd_length: %ld\n",foreign_hd_length); if (foreign_hd_length > 0) { char * foreign_hd_ptr = malloc((unsigned)foreign_hd_length); spsassert(foreign_hd_ptr,"read_header: failed to alloc foreign hd\n"); if (!fread(foreign_hd_ptr, 1, foreign_hd_length, fd)) BADHEAD (0, "error reading foreign header"); *add_genhd_l("foreign_hd_ptr",(long *)NULL,1,p)=(long)foreign_hd_ptr; } #ifdef DEC_ALPHA if (edr_default(p->common.machine_code)) /* default edr */ p->common.edr = 1;#endif k = nrec(p, fd);#ifdef NDREC1 if(k != -1) #endif p->common.ndrec = k;#define ALTERNATE1#ifdef ALTERNATE1/* if the header has the encoding generic and is FEA_SD then set the data type to SHORT*/ if (p->common.type == FT_FEA && p->hd.fea->fea_type == FEA_SD && get_genhd_val("encoding",p,(double)0,0)) { int i; for(i=0;i<p->hd.fea->field_count;i++) { if (strcmp("samples",p->hd.fea->names[i]) == 0) { p->hd.fea->types[i] = ESPS_SHORT; p->hd.fea->nshort += p->hd.fea->sizes[i]; p->hd.fea->nbyte -= p->hd.fea->sizes[i]; p->common.nshort += p->hd.fea->sizes[i]; p->common.nchar -= p->hd.fea->sizes[i]; } } }#endif return p;}static struct header *recursive_rh (fd, lev)FILE * fd;int lev;{ struct header *p = new_header (0); /* new_header makes an all zero header */ short code, len; int nh = 0, ns = 0;/* some debug code*/ if (EspsDebug) Fprintf(stderr,"recursive_rh, lev: %d\n",lev);/* see if this file has a preamble (older esps files might not) only the outer most header has a preamble */ if (lev == 0) { struct preamble *pre = (struct preamble *) calloc(1, sizeof(*pre));#ifndef DEC_ALPHA if (!miio_get_long(&pre->machine_code, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->check_code, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->data_offset, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->record_size, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->check, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->edr, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->align_pad_size, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_long(&pre->foreign_hd, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble");#else if (!miio_get_int(&pre->machine_code, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->check_code, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->data_offset, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->record_size, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->check, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->edr, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->align_pad_size, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble"); if (!miio_get_int(&pre->foreign_hd, 1, YES, NONE, fd)) BADHEAD (lev, "error reading preamble");#endif if (pre->check != HD_CHECK_VAL) { if (EspsDebug) Fprintf(stderr,"trying byte swapping.."); pre->check = swap_longs(pre->check); pre->machine_code = swap_longs(pre->machine_code); pre->check_code = swap_longs(pre->check_code); pre->data_offset = swap_longs(pre->data_offset); pre->record_size = swap_longs(pre->record_size); pre->edr = NO; pre->align_pad_size = swap_longs(pre->align_pad_size); pre->foreign_hd = swap_longs(pre->foreign_hd); } data_offset = pre->data_offset; align_pad_size = pre->align_pad_size;#ifdef DEMO check_code = pre->check_code;#endif if (pre->check != HD_CHECK_VAL) { if (EspsDebug) Fprintf(stderr,"no preamble here.\n");/* if the preamble is not valid, we must copy the stuff we read back to a standard common header structure and then read the rest of it */ (void)bcopy((char *)pre, (char *)p, sizeof (*pre)); if (fread(((char *)p)+sizeof(*pre),1,FIXPART_LEN-sizeof(*pre), fd)==0) BADHEAD (lev, "error reading rest of common, after preamble");/* if this is an older type file, then it is not EDR_ESPS */ edr_flag = NO; p->common.edr = NO; data_offset = -1; align_pad_size = 0;#ifdef DEMO check_code = 3000;#endif } else { /* this is a valid preamble */#ifdef MACH_CHECK_STUFF if(pre->machine_code == MACH_CODE) { Fprintf(stderr,"This ESPS file was created on machine %s\n", machine_codes[pre->machine_code]); Fprintf(stderr, "and is not compatible with this machine (%s).\n", machine_codes[MACH_CODE]); return NULL; /* return NULL, which means error */ }#endif if (EspsDebug) Fprintf(stderr,"found preamble\n"); p->common.edr = pre->edr; edr_flag = pre->edr; p->common.machine_code = pre->machine_code; machine_code = pre->machine_code; if(EspsDebug) Fprintf(stderr,"read_header: edr_flag: %d, machine: %s\n", edr_flag, machine_codes[machine_code]); if (miio_get_short(&p->common.type, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header");#ifndef NOPAD if (miio_get_short(&p->common.pad1, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header");#endif if (miio_get_long(&p->common.check, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.date, DATESIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.hdvers, VERSIONSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.prog, PROGSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.vers, VERSIONSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.progdate, DATESIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.ndrec, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(&p->common.tag, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(&p->common.nd1, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.ndouble, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nfloat, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nlong, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nshort, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nchar, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.fixpartsiz, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.hsize, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.user, USERSIZ, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(p->common.spares, NSPARES, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (EspsDebug) fprintf(stderr,"read_header: header version: %s\n", p->common.hdvers); }#ifdef DEMO if (pre->check_code != (3000 + hash(p->common.date))) return NULL;#endif free((char *)pre); /* we don't need this anymore */ } else { p->common.machine_code = machine_code; p->common.edr = edr_flag; if (miio_get_short(&p->common.type, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header");#ifndef NOPAD if (miio_get_short(&p->common.pad1, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header");#endif if (miio_get_long(&p->common.check, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.date, DATESIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.hdvers, VERSIONSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.prog, PROGSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.vers, VERSIONSIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.progdate, DATESIZE, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.ndrec, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(&p->common.tag, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(&p->common.nd1, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.ndouble, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nfloat, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nlong, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nshort, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.nchar, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.fixpartsiz, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_long(&p->common.hsize, 1, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_char(p->common.user, USERSIZ, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (miio_get_short(p->common.spares, NSPARES, edr_flag, machine_code, fd) == 0) BADHEAD (lev, "error reading common part of header"); if (EspsDebug) fprintf(stderr,"read_header: header version: %s\n", p->common.hdvers); }/* validate the header */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -