📄 foo.c
字号:
/* This material contains proprietary software of Entropic Research Laboratory, Inc. Any reproduction, distribution, or publication without the prior written permission of Entropic Research Laboratory, Inc. is strictly prohibited. Any public distribution of copies of this work authorized in writing by Entropic Research Laboratory, Inc. must bear the notice: "Copyright (c) 1987, 1988, 1989, 1990, 1991, Entropic Research Laboratory, Inc. All rights reserved." SPS header access routines - Joseph T. Buck Modified for ESPS by Alan Parker Entry points: read_header (stream): reads a header from stream and returns a pointer to it. write_header (h, stream): writes the header *h to stream. new_zfunc (ns,ds,num,den): creates a new zfunc structure. new_header (type) creates a new, zero header. copy_header (h) returns a pointer to a copy of h. add_source_file (oh, name, ih) adds a source file and a source header to the output header. add_comment (h, text): appends a string to the comment field*/#ifndef lintstatic char *sccsid = "@(#)headers.c 1.99 7/17/96 ERL";#endif#include <stdio.h>#include <pwd.h>#include <errno.h>#include <sys/types.h>#include <sys/file.h>#ifdef DEC_ALPHA#undef MIN#undef MAX#endif#ifndef APOLLO_68K#include <unistd.h>#endif#include <sys/stat.h>#include <esps/esps.h>#include <esps/filt.h>#include <esps/unix.h>#include <esps/fea.h>#include <esps/feasd.h>#define ESPS_BYTE 8#define ESPS_SHORT 4#undef BYTE#undef SHORTextern int errno;extern int debug_level; #define MAX_PARAM_LEN 6000/* This is a temp hack to work around a bug whereby a comment could be longer than the maximum size of a variable header item. In the next version of esps change MAX_PARAM_LEN above to 8192, and removed the redefine of MAX_STRING*/#undef MAX_STRING #define MAX_STRING 6000*4#define SIZINT (sizeof (int))#define SIZFLT (sizeof (float))#define SIZSHO (sizeof (short))#define SIZLO (sizeof (long))#define SIZCHAR (sizeof (char))#define SIZZF(z) (z ? (2*SIZSHO + (z->nsiz+z->dsiz)*SIZFLT)/SIZINT : 0)#define BADHEAD(lev,text) { badhead (lev, text); return NULL; }char head_errtxt[100];static int buf[MAX_PARAM_LEN];#define buf2 &buf[MAX_PARAM_LEN/2]/* 2nd half of buf */long long_dummy;char *savestring ();static void badhead (); static void recursive_wh (), put_shorts ();static short *get_shorts (), *copy_shorts ();static float *copy_floats (), *get_floats ();static void write_genhd ();char *add_genhd ();static void hd_error (), put_longs ();static long *copy_longs (), *get_longs ();static void set_ana_type(), set_pit_type(), set_spec_type(), set_ros_type();void set_filt_type(), set_scbk_type();void add_comment();#ifndef DEC_ALPHAstatic long swap_longs();#elsestatic int swap_longs();#endifvoid add_genzfunc();int read_preamble();static void rec_free_hdr(); /* used by free_header */static void free_zfunc(); /* used by free_header */static void free_strlist(); /* used by free_header */static void f_copy(), putnulls(), write_par();static int old_version();double atof();#ifdef DEMO#define NOKEY 1#endif#ifndef NOKEYvoid check_header();#endif#define PRE_DERIVED "1.34" /* last version of header.h without derived fields for feature files */#define PRE_NEWSIZ "1.44" /* last version with ndouble, nfloat, nlong, nshort, nchar, and fixpartsiz as shorts */#define PRE_FIELD_ORDER "1.57" /* last version without ability to read or write feature files in field order */#define PRE_COMPLEX "1.70" /* last version without complex fea fields */#define PRE_ALIGNMENT "1.73" /* last version without alignment pad */#include <esps/mach_codes.h>static int edr_flag=0; /* global EDR flag for reading */static int machine_code; /* global machine_code flag */int EspsDebug = 0; /* debug code enabled in this module */#ifdef DEMOstatic int hash(); /* simple hash function */#endif/* copy zfunc, copies a zfunc from one header to another*/struct zfunc *copy_zfunc (src)struct zfunc *src;{ if (src == NULL) return (NULL); return (new_zfunc (src -> nsiz, src -> dsiz, src -> zeros, src -> poles));}/* new_zfunc creates a new zfunc structure from dynamic memory.*/struct zfunc *new_zfunc (ns, ds, num, den)int ns, ds;float num[], den[];{ struct zfunc *z = (struct zfunc *) malloc ((unsigned) sizeof *z); spsassert(z,"new_zfunc: malloc failed"); if (ns > 0) { z -> zeros = (float *) malloc ((unsigned) (ns * SIZFLT)); spsassert(z->zeros,"new_zfunc: malloc failed"); f_copy (z -> zeros, num, ns); } else z -> zeros = NULL; if (ds > 0) { z -> poles = (float *) malloc ((unsigned) (ds * SIZFLT)); spsassert(z->poles,"new_zfunc: malloc failed"); f_copy (z -> poles, den, ds); } else z -> poles = NULL; z -> nsiz = ns; z -> dsiz = ds; return z;}static struct zfunc *read_zfunc (lev, fd) int lev;FILE * fd; { short ns, ds; if (!miio_get_short (&ns, 1, edr_flag, machine_code, fd) || !miio_get_short (&ds, 1, edr_flag, machine_code, fd)) BADHEAD (lev, "zfunc read error"); if (ns != 0) if (!miio_get_float ((float *)buf, ns, edr_flag, machine_code, fd)) BADHEAD (lev, "zfunc read error"); if (ds != 0) if (!miio_get_float ((float *)buf2, ds, edr_flag, machine_code, fd)) BADHEAD (lev, "zfunc read error"); return new_zfunc (ns, ds, (float *) buf, (float *) buf2);}static voidwrite_zfunc (code, z, fd)short code;struct zfunc *z;FILE * fd;{ short len = SIZZF (z); if (!miio_put_short(&code, 1, edr_flag, fd) || !miio_put_short(&len, 1, edr_flag, fd) || !miio_put_short(&z -> nsiz, 1, edr_flag, fd) || !miio_put_short(&z -> dsiz, 1, edr_flag, fd)) hd_error ("write_zfunc"); if (z -> nsiz != 0) if (!miio_put_float(z -> zeros, z -> nsiz, edr_flag, fd)) hd_error ("write_zfunc"); if (z -> dsiz != 0) if (!miio_put_float(z -> poles, z -> dsiz, edr_flag, fd)) hd_error ("write_zfunc");}static inttypesiz (type)int type;{ switch (type) { case DOUBLE: return sizeof (double); case FLOAT: return sizeof (float); case LONG: return sizeof (long); case ESPS_SHORT: return sizeof (short); case CODED: return sizeof (short); case CHAR: case ESPS_BYTE: case EFILE: case AFILE: return sizeof (char); case DOUBLE_CPLX: return sizeof(double_cplx); case FLOAT_CPLX: return sizeof(float_cplx); case LONG_CPLX: return sizeof(long_cplx); case SHORT_CPLX: return sizeof(short_cplx); case BYTE_CPLX: return sizeof(byte_cplx); } spsassert(NO, "typesiz: unrecognized type code"); return 0; /* not reached, just to keep lint happy */}static voidwrite_genhd (code, np, fp)short code;struct gen_hd *np;FILE * fp;{ short len;/* * do not write out generic for sphere_hd_ptr*/ if (!strcmp(np->name, "sphere_hd_ptr")) return; write_par (code, np -> name, fp); if (!miio_put_int (&np -> size, 1, edr_flag, fp) || !miio_put_short(&np -> type, 1, edr_flag, fp)) hd_error ("write_genhd"); if (np->type == CODED) { char **p = np->codes; while (*p != NULL) { len = strlen(*p)+1; if(!miio_put_short(&len, 1, edr_flag, fp) || !miio_put_char(*p, len, edr_flag, fp)) hd_error ("write_genhd"); p++; } len = 0; if(!miio_put_short(&len, 1, edr_flag, fp)) hd_error ("write_genhd"); } switch (np->type) { case DOUBLE: if (!miio_put_double((double *)np->d_ptr, (int)np->size, edr_flag, fp)) hd_error ("write_genhd"); break; case FLOAT: if (!miio_put_float((float *)np->d_ptr, (int)np->size, edr_flag, fp)) hd_error ("write_genhd"); break; case LONG: if (!miio_put_long((long *)np->d_ptr, (int)np->size, edr_flag, fp)) hd_error ("write_genhd"); break; case ESPS_SHORT: case CODED: if (!miio_put_short((short *)np->d_ptr, (int)np->size, edr_flag, fp)) hd_error ("write_genhd"); break; case CHAR: case ESPS_BYTE: case EFILE: case AFILE: if (!miio_put_char((char *)np->d_ptr, (int)np->size, edr_flag, fp)) hd_error ("write_genhd"); break; } }staticread_genhd (lev, fd, hd, name)int lev;FILE * fd;struct header *hd;char *name;{ unsigned int size; short type, len; char *ptr; char **codes; int data_rep = hd->common.edr; int mach_code = hd->common.machine_code; if (!miio_get_int (&size, 1, data_rep, mach_code, fd) || !miio_get_short (&type, 1, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); if (type != CODED) { ptr = add_genhd (name, type, (int) size, (char *)NULL, (char **)NULL, hd); } else { int i=0; codes = (char **)calloc(1,sizeof(char *)); spsassert(codes != NULL,"read_genhd: calloc failed!"); if (!miio_get_short (&len, 1, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); while (len != 0) { ptr = malloc(SIZCHAR*len); spsassert(ptr != NULL,"read_genhd: malloc failed!"); if (!miio_get_char (ptr, len, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); codes[i++] = ptr; codes = (char **)realloc((char *)codes, sizeof(char *)*(i+1)); spsassert(codes != NULL,"read_genhd: realloc failed!"); codes[i] = NULL; if (!miio_get_short (&len, 1, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); } ptr = add_genhd (name, type, (int) size, (char *)NULL, codes, hd); } switch (type) { case DOUBLE: if (!miio_get_double((double *)ptr, (int)size, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); break; case FLOAT: if (!miio_get_float((float *)ptr, (int)size, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); break; case LONG: if (!miio_get_long((long *)ptr, (int)size, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); break; case ESPS_SHORT: case CODED: if (!miio_get_short((short *)ptr, (int)size, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); break; case CHAR: case ESPS_BYTE: case EFILE: case AFILE: if (!miio_get_char((char *)ptr, (int)size, data_rep, mach_code, fd)) BADHEAD (lev, "read_genhd read error"); break; } return 0;}/* read_header reads in a file header. recursive_rh really does the work.*//* #define NDREC1 *//* define NDREC1 to get beta case of ndrec not being set to -1 for pipes. Remove this to get esps 3.0 code */static long data_offset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -