📄 foo.c
字号:
version field of the outmost header*/voidwrite_header (p, fd)FILE * fd;struct header *p;{#define PWD_SIZE 200#ifdef DEC_ALPHA time_t tloc;#else long tloc; #endif#ifndef DEC_ALPHA long time ();#endif#if !defined(hpux) && !defined(OS5) char *getwd(); #endif char *ctime (), *user, *getlogin(); struct passwd *pass, *getpwnam(), *getpwuid(); int i, userid; char *pwd, *pwd2; struct preamble *pre = (struct preamble *)calloc(1, sizeof(*pre)); struct header *ref_hold_hd[MAX_SOURCES]; char *ref_hold_src[MAX_SOURCES]; int ref_nnames, ref_nheads; int foreign_hd_length;#ifndef NOKEY check_header(MACH_CODE);#endif edr_flag = p->common.edr; if(getenv("ESPSDEBUG")) EspsDebug=1; if(EspsDebug) Fprintf(stderr,"write_header: edr: %d\n",edr_flag); if(update_date) { tloc = time (0); (void) strcpy (p -> common.date, ctime (&tloc)); p -> common.date[24] = ' '; } else update_date = 1; if (!(user = getlogin()) && (userid = getuid()) ) { pass = getpwuid(userid); if(pass) user = pass->pw_name; } if(user) (void)strncpy(p->common.user,user,USERSIZ); p->common.user[USERSIZ-1] = '\0'; pwd = malloc((unsigned)PWD_SIZE); /* buffer for gethostname */ spsassert(pwd,"write_header: malloc failed!"); (void)gethostname(pwd,PWD_SIZE); (void)strcat(pwd,":"); pwd2 = malloc((unsigned)PWD_SIZE); /* buffer for getwd */ spsassert(pwd2,"write_header: malloc failed!");#if !defined(hpux) && !defined(OS5) if(getwd(pwd2) == NULL)#else if(getcwd(pwd2,PWD_SIZE) == NULL)#endif (void)strcpy(pwd2,"Couldn't get directory name"); (void)strcat(pwd,pwd2); p->variable.current_path = savestring(pwd); free(pwd); free(pwd2); if (p->variable.refhd) { struct header *h = p->variable.refhd;/* For a reference header, hold all the embedded source headers. We don't want to write them out, but we can't just zap them here, because it alters the header in memory.*/ /* zap all the source files and headers */ for (i = 0; i < MAX_SOURCES; i++) { ref_hold_hd[i] = h->variable.srchead[i]; ref_hold_src[i] = h->variable.source[i]; h -> variable.source[i] = NULL; h -> variable.srchead[i] = NULL; } ref_nnames = h->variable.nnames; ref_nheads = h->variable.nheads; h -> variable.nnames = h -> variable.nheads = 0; }#ifndef NOPAD/* see if we should write feature files in "field_order", instead of by data type as is normal. If the env variable FIELD_ORDER is defined, but not equal to "off", then do this.*/ if(p->common.type == FT_FEA) { char *ptr = getenv("FIELD_ORDER"); if(ptr && strcmp(ptr,"off") != 0) { p->hd.fea->field_order = YES; Fprintf(stderr, "write_header: FIELD_ORDER environment variable is set\n"); } }#endif/* call function to fix up the type fields in the header. Note that we don't do this for Feature Files. See add_fea_fld*/#ifdef ESI if (p -> common.type == FT_ANA) (void) set_ana_type (p); if (p -> common.type == FT_PIT) (void) set_pit_type (p); if (p -> common.type == FT_ROS) (void) set_ros_type (p);#endif ESI if (p -> common.type == FT_SPEC) (void) set_spec_type (p); if (p -> common.type == FT_FILT) (void) set_filt_type (p); if (p -> common.type == FT_SCBK) (void) set_scbk_type (p);/* write out the preamble the first time, without knowing the data offset*/ pre->machine_code = MACH_CODE; p->common.machine_code = pre->machine_code; pre->check_code = 3000; pre->record_size = size_rec2(p); pre->check = HD_CHECK_VAL; pre->edr = p->common.edr; pre->data_offset = 0;#ifndef DEC_ALPHA if (!miio_put_long(&pre->machine_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->check_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->data_offset, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->record_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->check, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->edr, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->align_pad_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->foreign_hd, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1");#else if (!miio_put_int(&pre->machine_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->check_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->data_offset, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->record_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->check, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->edr, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->align_pad_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->foreign_hd, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1");#endif/* write out all headers */ recursive_wh (p, fd);/* if there is a foreign header, then write it out here */ if((foreign_hd_length = get_genhd_val("foreign_hd_length", p, 0.0)) > 0) {/* the above is supposed to be = not == *//* there is a foreign header (generic defined and non-zero), if the generic foreign_hd_ptr is defined and non-null, then write out that data after the esps header. We are using a long generic too hold a char * here.*/ long *foreign_hd_ptr; pre->foreign_hd = -1; if((foreign_hd_ptr=get_genhd_l("foreign_hd_ptr",p)) && *foreign_hd_ptr){ pre->foreign_hd = ftell(fd); if (!fwrite ((char *)(*foreign_hd_ptr), 1, foreign_hd_length, fd)) hd_error ("write_header - foreign header"); } else { fprintf(stderr, "write_header: Warning, foreign_hd_length is non-zero (%d), but\n", foreign_hd_length); fprintf(stderr, "write_header: foreign_hd_ptr is undefined or NULL\n"); } } pre->data_offset = ftell(fd); /* get the data offset *//* if possible, rewind the output and update the preamble*/ if (fseek(fd, 0L, 0) == 0) { /* its not a pipe */#if defined(SUN3) || defined(SUN4) || defined(SUN386i) if (EspsDebug) Fprintf(stderr,"write_header: data_offset: %x\n", pre->data_offset); if ( getenv("ESPS_ALIGN") && ((pre->data_offset & 0xf) != 0)) { char *pad;/* means that the start of data is not double word aligned*/ (void)fseek(fd, pre->data_offset, 0); pre->align_pad_size = 0x10 - (pre->data_offset & 0xf); pad = malloc((unsigned)pre->align_pad_size); miio_put_char(pad,pre->align_pad_size,pre->edr,fd); pre->data_offset = pre->data_offset + pre->align_pad_size; free(pad); assert(pre->data_offset == ftell(fd)); (void)fseek(fd, 0L, 0); if (EspsDebug) { Fprintf(stderr, "write_header: align check: required pad size is 0x%x\n", pre->align_pad_size); Fprintf(stderr, "write_header: new data offset is 0x%x\n", pre->data_offset); } } else#endif { if(EspsDebug) Fprintf(stderr,"write_header: no pad needed\n"); } /* (void)fprintf(stderr,"write_header: just rewound output file\n"); (void)fprintf(stderr,"write_header: data offset is %ld\n",pre->data_offset);*/#ifndef DEC_ALPHA if (!miio_put_long(&pre->machine_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->check_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->data_offset, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->record_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->check, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->edr, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->align_pad_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_long(&pre->foreign_hd, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1");#else if (!miio_put_int(&pre->machine_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->check_code, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->data_offset, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->record_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->check, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->edr, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->align_pad_size, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1"); if (!miio_put_int(&pre->foreign_hd, 1, (int)pre->edr, fd)) hd_error("error writing preamble 1");#endif (void)fseek(fd, pre->data_offset, 0); }/* restore the subheaders to the reference header*/ if (p->variable.refhd) { struct header *h = p->variable.refhd; /* zap all the source files and headers */ for (i = 0; i < MAX_SOURCES; i++) { h->variable.srchead[i] = ref_hold_hd[i]; h->variable.source[i] = ref_hold_src[i]; } h->variable.nnames = ref_nnames; h->variable.nheads = ref_nheads; } free(pre); }/* rec_write_header writes out a header. It calls fix_header to repair some fields.*/static voidrecursive_wh (p, fd)FILE * fd;struct header *p;{ int i; short code, len; char I[4]; long dummy=0; fix_header (p); I[0] = '\0'; /* dirty trick to keep sccs from */ (void)strcpy(I,"%"); /* killing the % I % , symbol */ (void)strcat(I,"I%");/* if the header version define (from header.h) is equal to percentIpercent then that means that header.h is an sccs edit version. Substitute a large sccs version instead of putting the sccs keyword into the header*/ if(strcmp(I,HD_VERSION) != 0) (void) strcpy (p -> common.hdvers, HD_VERSION); else (void) strcpy (p -> common.hdvers, "999"); if (EspsDebug) fprintf(stderr,"write header: header version: %s\n",p->common.hdvers); if ((p -> common.type == FT_SD) && (get_sd_type (p) == NONE)) (void) fprintf (stderr, "write_header: Warning - type fields for SD file not set."); if (p->common.type == FT_SPEC && p -> hd.spec -> freq_format == ARB_FIXED) { (void ) fprintf (stderr, "ARB_FIXED type not implemented yet -- seek help.\n"); exit (1); } if (miio_put_short(&p->common.type, 1, edr_flag, fd) == 0) hd_error ("write_header");#ifndef NOPAD if (miio_put_short(&p->common.pad1, 1, edr_flag, fd) == 0) hd_error ("write_header");#endif if (miio_put_long(&p->common.check, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.date, DATESIZE, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.hdvers, VERSIONSIZE, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.prog, PROGSIZE, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.vers, VERSIONSIZE, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.progdate, DATESIZE, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.ndrec, 1, edr_flag,fd) == 0) hd_error ("write_header"); if (miio_put_short(&p->common.tag, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_short(&p->common.nd1, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.ndouble, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.nfloat, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.nlong, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.nshort, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.nchar, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.fixpartsiz, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_long(&p->common.hsize, 1, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_char(p->common.user, USERSIZ, edr_flag, fd) == 0) hd_error ("write_header"); if (miio_put_short(p->common.spares, NSPARES, edr_flag, fd) == 0) hd_error ("write_header"); switch (p -> common.type) {#ifdef ESI case FT_ANA: if (fwrite ((char *) p -> hd.ana, ANA_SIZE, 1, fd) == 0) hd_error ("write_header"); break; case FT_PIT: if (fwrite ((char *) p -> hd.pit, PIT_SIZE, 1, fd) == 0) hd_error ("write_header"); break; case FT_ROS: { struct ros_header *ros; if (fwrite ((char *) p -> hd.ros, ROS_SIZE, 1, fd) == 0) hd_error ("write_header"); ros = p -> hd.ros; (void) put_shorts (fd, ros -> type_bits, ros -> maxtype); (void) put_shorts (fd, ros -> rc_ubits, ros -> order_unvcd); (void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -