📄 psps.c
字号:
/* psps - prints ESPS data files * * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing by * Entropic Speech, Inc. must bear the notice * * "Copyright (c) 1987 Entropic Speech, Inc.; All rights reserved" * * psps - prints an ESPS data file on standard output. This verison by * Alan Parker, based on the SDS version by Joe Buck. * - Revised and checked for ESPS 3.0 by John Shore */#include <stdio.h>#include <esps/esps.h>#include <esps/sd.h>#include <esps/spec.h>#include <esps/fea.h>#include <esps/filt.h>#include <esps/scbk.h>#include <esps/unix.h>#include <esps/feaspec.h>#include <esps/feasd.h>#include <esps/feafilt.h>#ifdef ESI#include <esps/ana.h>#include <esps/pitch.h>#include <esps/ros.h>#endif ESI#define HUGE 2000000000#ifndef lint static char *sccs_id = "@(#)psps.c 3.16 8/31/95 ESI";#endif#define SYNTAX USAGE("psps [-aDghHlvx] [-r range] [-t range] [-f field_name] file")#define ERROR_EXIT(text) {(void) fprintf(stderr, "psps: %s - exiting\n", text); exit(1);}int getopt();char *myrealloc();int size_rec();char *file_typeX();short get_rec_len();void lrange_switch();void pr_full_header();void pr_history();void pr_sd_data();void pr_feasd_data();#ifdef ESIvoid print_ana();void print_pitch();void print_ros();#endifvoid print_common();void print_fea();void print_filt(); void print_generic();void print_scbk();void print_sd();void print_spec();void print_txtcomment();void tab();int vflag = 0; /* global needed in prnt_hdr.c (print_fea)*/int full = 0; /* if true, print full header(s) */extern char *optarg;extern int optind; /* array of strings containing FEA fields */char **field_name = NULL;int fflag = 0; /* FEA field name given if fflag set */int nfield = 0; /* number of field names given */int eflag = 0; /* causes EFILE and AFILE links to be followed */int Recursive = 0; /* if true, recursively print all headers */int debug_level = 0;main (argc, argv)int argc;char **argv;{ int c; long i; int history = 0; /* if true, print a history */ int nohead = 0; /* if true, don't print header ' */ int nodata = 0; /* -D given? */ int isfile = 0; /* non-zero if input is not a pipe*/ char *range = NULL; /* -r argument */ char *trange = NULL; /* -t argument */ char *inp_file; /* input file name */ FILE *istrm = stdin; struct header *h; struct spec_data *spec_rec; struct filt_data *filt_rec; struct scbk_data *scbk_rec; struct fea_data *fea_rec; struct feaspec *feaspec_rec; struct feasd *feasd_rec; struct feafilt *feafilt_rec;#ifdef ESI struct ana_data *ana_rec; struct pitch *pit_rec; struct ros_data *ros_rec;#endif ESI long srec = 1; /* first record to print */ long erec = HUGE; /* last record to print */ long stag = 0; /* tag start */ long etag = LONG_MAX; double *data; long tag; long rec_size; int k = 0; int tflag = 0; int oflag = 0; int gflag = 0; /* print any ESPS file in generic format */ short type; /* ESPS filt type */ /* * process command line options */ while ((c = getopt (argc, argv, "hlHaxDr:t:vgf:e")) != EOF) { switch (c) { case 'h': history++; break; case 'a': Recursive++; /* fall through to case 'f' intentional */ case 'l': full++; break; case 'H': nohead++; break; case 'x': debug_level++; break; case 'D': nodata++; break; case 'r': range = optarg; oflag++; break; case 't': trange = optarg; tflag++; break; case 'v': vflag++; full++; break; case 'g': gflag++; break; case 'f': nfield++; field_name = (char **) myrealloc ((char *) field_name, (nfield+1) * sizeof (char *)); assert (field_name); field_name[nfield-1] = optarg; field_name[nfield] = NULL; assert (field_name[nfield-1]); fflag++; break; case 'e': eflag++; full++; break; default: SYNTAX; } }/* check for conflicting switches */ if (nodata && range || nohead && full || history && full) ERROR_EXIT("conflicting switches"); if (tflag && oflag) ERROR_EXIT("conflicting switches: -t and -r options"); if (optind == argc) SYNTAX; /* * open input file */ inp_file = argv[optind]; if(strcmp(inp_file,"-") != 0) { if ((istrm = fopen (inp_file, "r")) == NULL) CANTOPEN ("psps", inp_file); } else inp_file = "<stdin>"; if ((h = read_header (istrm)) == NULL) NOTSPS ("psps", inp_file); if (tflag && (h->common.tag == NO)) ERROR_EXIT("Data is not tagged, cannot use -t option"); if (fflag && (h->common.type != FT_FEA)) ERROR_EXIT("Use the -f option with ESPS Feature files only"); if (!fflag) nfield = 1; /* * check for file or pipe and process range */ if (h->common.ndrec != -1) isfile++; srec = 1; erec = (isfile ? h->common.ndrec : LONG_MAX); lrange_switch (range, &srec, &erec, 1);/* Process the t option arguments (range of tags)*/ if (tflag) lrange_switch (trange, &stag, &etag, 1); if (stag > etag) ERROR_EXIT("starting tag > ending tag with -t option"); if (debug_level) { Fprintf(stderr, "psps: srec = %ld, erec = %ld\n", srec, erec); Fprintf(stderr, "psps: input is %s pipe\n", (isfile ? "not" : "")); } if (srec == 0) Fprintf(stderr, "psps: records start at 1, using range %ld:%ld\n",++srec,++erec); if(isfile && (srec > h->common.ndrec)) Fprintf(stderr,"psps: WARNING - starting point > than h->ndrec\n"); if(isfile && (erec > h->common.ndrec)) Fprintf(stderr,"psps: WARNING - not enough records in file\n"); /* * print header */ if (full) /* * full header for -v, -l, and -a options */ pr_full_header (inp_file, h, Recursive, 0); else if (history) /* * -h option prints common portion of all subheaders */ pr_history (inp_file, h, 0); else if (!nohead) { /* * -H suppresses header (except for common portion) */ (void) printf("File: %s\n",inp_file); print_common(0,h); } /* * exit if only the header is wanted */ if (nodata) exit(0); fea_skiprec(istrm, srec - 1, h); /* * now print data records */ if (gflag) type = -1; else type = h->common.type; switch (type) { case FT_SD: pr_sd_data (istrm, srec, erec, h); break;#ifdef ESI case FT_ANA: ana_rec = allo_ana_rec(h); i = srec; while (i++ <= erec && (get_ana_rec(ana_rec,h,istrm) != EOF)) { if (!tflag || (tflag && ana_rec->tag >= stag && ana_rec->tag <= etag)) { (void) printf("Record %d: ",i-1); (void) print_ana_rec(ana_rec,h,stdout); } } break; case FT_PIT: pit_rec = allo_pitch_rec(); i = srec; while (i++ <= erec && (get_pitch_rec(pit_rec,istrm) != EOF)) { if (!tflag || (tflag && pit_rec->tag >= stag && pit_rec->tag <= etag)) { (void) printf("Record %d: ",i-1); (void) print_pitch_rec(pit_rec,stdout); } } break;#endif ESI case FT_SPEC: spec_rec = allo_spec_rec(h); i = srec; while (i++ <= erec && (get_spec_rec(spec_rec,h,istrm) != EOF)) { if (!tflag || (tflag && spec_rec->tag >= stag && spec_rec->tag <= etag)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -