📄 eopen.3
字号:
.\" Copyright (c) 1987 Entropic Speech, Inc.; All rights reserved.\" @(#)eopen.3 1.6 06 May 1997 ESI.TH EOPEN 3\-ESPSu 06 May 1997.ds ]W "\fI\s+4\ze\h'0.05'e\s-4\v'-0.4m'\fP\(*p\v'0.4m'\ Entropic Speech, Inc..SH NAMEeopen \- open ESPS file, read header, and check type.SH SYNOPSIS.nf.ft B#include <esps/header.h>#include <esps/ftypes.h>#include <esps/fea.h>#include <stdio.h>char *eopen(prog_name, file_name, mode, type, subtype, header, stream)char *prog_name, *file_name, *mode;int type, subtype;struct header **header;FILE **stream;eopen2(prog_name, file_name, mode, type, subtype, header, stream)char *prog_name, *file_name, *mode;int type, subtype;struct header **header;FILE **stream;.fi.ft.SH DESCRIPTION.PPThe following are input parameters:.TP.I prog_namethe name of the calling program or other string to be put at thebeginning of error messages..TP.I file_namethe name of the file to be opened or "\-" for standard input oroutput..TP.I modethe string "r" for.I read,"w" for.I write,or any other string acceptable as the second argument of.IR fopen (3S)..TP.I typeone of the file-type codes, such as FT_SD and FT_SPEC, defined in.I <esps/ftypes.h>,or NONE..TP.I subtypeone of the feature-file subtype codes, such as \fIFEA_ANA\fP(5-ESPS) and \fIFEA_STAT\fP(5-ESPS),defined in.I <esps/fea.h>,or NONE; ignored unless.I typeis FT_FEA..PPThe following are output parameters..TP.I headerpoints to a variable in which a pointer to the file header is stored..TP.I streampoints to a variable in which a file pointer for the opened file isstored..PPThe function value returned by.I eopenis ordinarily just.I file_name;but if.I file_nameis "\-", the returned value is "<stdin>" or "<stdout>"..PPIf the first letter of.I modeis 'r',.I eopenopens the file for reading.The function is most useful in that case,as it takes care of reading the header and checking the ESPS file type.However,.I eopencan also open a file for writing or appending,and that simpler case is described first..PPIf.I modebegins with any letter but 'r', and.I file_nameis "\-", \fIeopen\fP just assigns the value.I stdoutto.RI * streamand returns the string "<stdout>"..PPIf.I modebegins with a letter other than 'r', and.I file_nameis an ordinary file name,\fIeopen\fP attempts to open the file by executing.IR fopen ( file_name ", " mode ).Upon success, it assigns the resulting value to.RI * streamand returns.I file_name;upon failure, \fIeopen\fP exits with an error message..PPIf.I modebegins with 'r', and.I file_nameis "\-", \fIeopen\fP assigns the value.I stdinto.RI * streamand attempts to read the header and (if required) check the file type,as described below.Upon successful completion,\fIeopen\fP returns the string "<stdin>"..PPIf.I modebegins with 'r', and.I file_nameis an ordinary file name,\fIeopen\fP attempts to open the file by executing.IR fopen ( file_name ", " mode ).Upon failure, the program exits with an error message;upon success, \fIeopen\fP assigns the resulting value to.RI * streamand attempts to read the header and (if required) check the file type,as described below.Upon successful completion,\fIeopen\fP returns.I file-name..PP\fIEopen\fP uses \fIread_header\fP(3-ESPS) to attempt to read the file header. If it fails, the program exits with a message;otherwise \fIeopen\fP assigns the resulting value of.I read_headerto.RI * header..PPThen, if.I typeis NONE,type checking is skipped, and \fIeopen\fP returns.Otherwise, if.I common.typein the header has a different value from.I type,the program exits with a message, except for the case where\fIcommon.type\fR == FT_SD, \fItype\fR == FT_FEA, and \fIsubtype\fR ==FEA_SD.If the type is correct and is not FT_FEA,there is no further checking to be done, and \fIeopen\fP returns.Also, if.I subtypeis NONE, further checking is skipped.However, if.I typeis FT_FEA and.I subtypeis not NONE, the value of .IR hd.fea \-> fea_typeis checked; if the value of.I subtypeis different, the program exits with a message.Otherwise \fIeopen\fP returns..PPIf the file to be opened is an old format SD file (FT_SD), and\fIeopen\fR is called with \fItype\fR == FT_FEA and \fIsubtype\fR ==FEA_SD, then the SD header is converted to a FEA_SD header andreturned. This is to allow a program designed to handle FEA_SD filesto read old SD files also..PPThe alternate function \fIeopen2\fP is identical to \fIeopen\fP exceptthat \fIeopen2\fP does not exit after detecting a problem. Instead,after detecting a problem, it sets *header to NULL, outputs an errormessage, and returns the appropriate file name (\fIfile_name\fP,"<stdout>", or "<stdin>"). It is the responsibility of the caller tocheck the \fIheader\fP after \fIeopen2\fP returns..SH EXAMPLE.PPA program that reads a sampled-data file and a statistics feature fileand writes one output file might contain the following code. Assume thatat this point in the program the value of the variable.I optindis one greater than the index of the last optional argument in the program'sargument vector..sp.nfif (optind < argc) input_sd = eopen(ProgName, argv[optind++], "r", FT_FEA, FEA_SD, &sd_ihd, &inputsd_strm);else{ Fprintf(stderr, "%s: no input SD file specified.\\n", ProgName); SYNTAX;}if (optind < argc) input_stat = eopen(ProgName, argv[optind++], "r", FT_FEA, FEA_STAT, &stat_ihd, &inputstat_strm);else{ Fprintf(stderr, "%s: no input FEA_STAT file specified.\\n", ProgName); SYNTAX;}if (inputsd_strm == stdin && inputstat_strm == stdin){ Fprintf(stderr, "%s: input files can't both be <stdin>.\\n", ProgName); exit(1);}if (optind < argc) out_fea = eopen(ProgName, argv[optind++], "w", NONE, NONE, (struct header **) NULL, &outfea_strm);else{ Fprintf(stderr, "%s: no output file specified.\\n", ProgName); SYNTAX;}if (optind < argc){ Fprintf(stderr, "%s: too many files specified.\\n", ProgName); SYNTAX;}.fi.sp.SH DIAGNOSTICS.PPThe invocation of.IR read_header (3\-ESPSu)may produce various diagnostic messages.The following are generated directly by.I eopen..nf.PP\fIprog_name\fP: can't open \fIfile_name\fP: \fIreason\fP\fIprog_name\fP: \fIfilename\fP is not an ESPS file\fIprog_name\fP: \fIfilename\fP is not an ESPS \fIfiletype\fP file.fi.SH WARNING.PPTo prevent.I streamfrom becoming.I stdinor.I stdout,the program should either check that.IR strcmp ( file_name,"\-") != 0 before.I eopenis called or check that.I stream!=.I stdinor.I stream!=.I stdoutafter.I eopenis called..SH BUGSNone known..SH "SEE ALSO".PPfopen(3S), read_header(3\-ESPSu), ESPS(5\-ESPS), FEA(5\-ESPS).SH AUTHORRodney Johnson
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -