⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
	   if(buffhd->common.tag)		buffhd->common.tag = NO;	   set_seg_lab(buffhd, names);	   tags_to_seg = YES;	   buffhd->variable.refer = NULL;	   message("Creating output file as segment labeled.\n");	}	(void) clear_buffer();	ofile = savestring(s);	outhd = copy_header(buffhd);	outhd->common.ndrec = 0;	set_header(outhd);	write_header(outhd,ostrm);	return 1;}char	buffile[20] = "selbufXXXXXX";char	tempfile[20] = "seltmpXXXXXX";/* open the buffer file.  First time through, create the buffer and temp   file*/voidopen_buff(){	extern char	*mktemp();	static first = 1;	spsassert(buffhd, "buffhd botch");	if (first) {		(void)mktemp(buffile);		(void)mktemp(tempfile);		first = 0;	}	buffd = fopen(buffile, "w+");	spsassert(buffd, "Trouble opening temporary file");	tstrm = fopen(tempfile, "w+");	spsassert(tstrm, "Trouble opening temporary file");	write_header(buffhd, buffd);	(void)fflush(buffd);	changes = 0;	out_count = 0;	bufrec = allo_fea_rec(buffhd);	assert(bufrec != NULL);	}/* run psps on the buffer file*/intshow_buffer(){	if (debug_level) 		Fprintf(stderr, "show_buffer: called.\n");	if (out_count == 0) 		message("Nothing in buffer.\n");	else		run_psps("-H", buffile);	if (undone_count) { 		message1(		  "%ld extra records shown at the end have been undone,\n",undone_count);		message(		  "these records will not be output by the write command.\n");	}	return 1;}	/* clear the buffer*/intclear_buffer(){	if (debug_level) 		Fprintf(stderr, "clear_buffer: called.\n");	if (buffhd == NULL) {	/* no buffer setup yet */		message("There is no buffer setup yet.\n");		return 1;	}	if (changes)		if (!confirm(			"Buffer has changed since last write - clear it?"))			return 0;	if(bufrec != NULL) {		free((char *)bufrec);		bufrec = NULL;	}	if (buffd != NULL) {		(void)fclose(buffd);		(void)unlink(buffile);	}	if (tstrm != NULL) {		(void)fclose(tstrm);		(void)unlink(tempfile);	}	open_buff();	return 1;}/* get another record from the input file set.   */intget_rec(rec_ptr, hd_ptr, name_ptr)struct fea_data **rec_ptr;struct header **hd_ptr;char **name_ptr;{	int	i;	long total=0;	if (debug_level) 		Fprintf(stderr, "get_rec called.\n");	assert(name_ptr && rec_ptr && hd_ptr);	if (n_ifiles == 0) {		errmsg("No input files open.\n");		return EOF;	}	if (data_ptr < ihd[0]->common.ndrec) { /* special case */		data_ptr++;		*hd_ptr = ihd[0];		*rec_ptr = irec[0];		*name_ptr = ifile[0];		return get_fea_rec(irec[0], ihd[0], istrm[0]);	}	for (i = 1; i < n_ifiles; i++) {		total += ihd[i-1]->common.ndrec;		if (data_ptr < ihd[i]->common.ndrec+total) {			data_ptr++;			*hd_ptr = ihd[i];			*rec_ptr = irec[i];			*name_ptr = ifile[i];			return get_fea_rec(irec[i], ihd[i], istrm[i]);		}	}	errmsg1("data_ptr got fouled up: %d, seek help\n", data_ptr);	return EOF;}extern long sel_count;/* print the current record in the buffer record */intshow_last(){	if (debug_level)		Fprintf(stderr,"show_last called.\n");	if (out_count == 0) 		message("Nothing in buffer.\n");	else if (sel_count == 0)		message("Cannot show last record after undo.\n");	else		print_fea_rec(bufrec, buffhd, stdout);	return 1;}void zero_fea_rec();	/* put a record to the buffer*/intput_rec(rec, hd)struct fea_data *rec;struct header *hd;{	if (debug_level) 		Fprintf(stderr, "put_rec called.\n");	assert(rec && hd);	if (bufrec == NULL) {		errmsg("No output file setup.\n");		return 0;	}	zero_fea_rec(bufrec, buffhd);	copy_fea_rec(rec, hd, bufrec, buffhd, buffhd->hd.fea->names, 			(short **)NULL);/* handle tags to segment_labeled   if called for*/	if (hd->common.tag && tags_to_seg) {		*(long *)get_fea_ptr(bufrec,"segment_start",buffhd) = rec->tag;		*(short *)get_fea_ptr(bufrec,"source_file",buffhd) =		  fea_encode(hd->variable.refer,"source_file",buffhd);	}	out_count++;	changes++;	undone_count = 0;	put_fea_rec(bufrec, buffhd, buffd);	return 1;}/* flush the buffer.  This updates the header also*/voidflush_buffer(){	buffhd->common.ndrec = out_count;	(void)fflush(buffd);	rewind(buffd);	write_header(buffhd, buffd);	if (fseek(buffd,0L,2) != 0) {	  Fprintf(stderr,"fseek failed!");	  exit (1);	}	(void)fflush(buffd);}/* ask the user for confirmation of something*/intconfirm(s)char	*s;{#define CLINSIZ 5	char	buf[CLINSIZ];	if (com_file_depth != 0 || !in_tty) 		return 1;	while (1) {		message1		    ("%s\n [y then return to confirm, n then return to abort] ", s);		(void) fgets(buf, CLINSIZ, stdin);		if (strlen(buf) == 2 && buf[0] == 'y') 			return 1;		if (strlen(buf) == 2 && buf[0] == 'n') 			return 0;	}}/* show number of output records in buffer*/intshow_size(){	message1("%ld records in output buffer.\n",out_count);	return 1;}/* write the buffer to the output files*/intwrite_buffer(){	long i;	if (debug_level)		Fprintf(stderr,"write_buffer called.\n");		if(changes == 0) {		errmsg("No changes to write.\n");		return 1;	}	if (out_count == 0) {		errmsg("Nothing in buffer.\n");		return 1;	}	if (ofile == NULL) {		errmsg("No output file specified.\n");		return 0;	}	rewind(tstrm);	rewind(buffd);	(void)read_header(buffd);	if(!nflag) {		rewind(ostrm);		(void)read_header(ostrm);		while (get_fea_rec(bufrec,buffhd,ostrm) != EOF)			put_fea_rec(bufrec,buffhd,tstrm);		rewind(ostrm);		outhd->common.ndrec += out_count;		write_header(outhd, ostrm);		rewind(tstrm);		while (get_fea_rec(bufrec,buffhd,tstrm) != EOF)			put_fea_rec(bufrec,buffhd,ostrm);	}	i = out_count;	while (i-- && (get_fea_rec(bufrec,buffhd,buffd) != EOF))		put_fea_rec(bufrec,buffhd,ostrm);	if(nflag) {		rewind(ostrm);		outhd->common.ndrec += out_count;		write_header(outhd, ostrm);		if (fseek(buffd,0L,2) != 0) {	  	  Fprintf(stderr,"fseek failed!");	  	  exit (1);		}	}	(void)fflush(ostrm);	changes=0;	(void) clear_buffer();	return 1;		}/* close the output file*/intclose_outfile(){	if(ofile == NULL)		return 1;	(void) fclose(ostrm);	ofile = NULL;	return 1;}extern char *progversion, *progdate;extern int Argc;extern char **Argv;/* set the version, program  name, and program date    in the output header.  It also adds source files.   If the -n flag is set, then don't add source files.*/voidset_header(hd)struct header *hd;{	int i;	char *get_cmd_line();	(void)strcpy(hd->common.prog,PROG);	(void)strcpy(hd->common.vers,progversion);	(void)strcpy(hd->common.progdate,progdate);	if(!nflag) {		for(i=0; i<n_ifiles; i++) 			add_source_file(hd, ifile[i], ihd[i]);		add_comment(hd, get_cmd_line(Argc, Argv));	}}/* quit   If changes haven't been written out, confirm from the   user*/intterminate(){	if (debug_level) 		Fprintf(stderr, "terminate: called.\n");	if (changes)		if (!confirm(			"Buffer has changed since last write - quit?"))			return 0;	(void) unlink(buffile);	(void) unlink(tempfile);	exit (0);	return 1; 	/* lint */}		intundo(){	if(sel_count != 0) {	  buffhd->common.ndrec -= sel_count;	  out_count -= sel_count;	  (void)fflush(buffd);	  rewind(buffd);	  write_header(buffhd, buffd);	  fea_skiprec(buffd,buffhd->common.ndrec,buffhd);	  message1("%ld records removed from end of buffer.\n",sel_count);	  undone_count = sel_count;	  sel_count = 0;	  if (out_count == 0) changes = 0;	}	else	  message("Nothing to undo.\n");	return 1;}intcheck_names(a,b)struct header *a, *b;{	char **afields, **bfields;	int k;		assert(a); assert(b);	assert(a->common.type == FT_FEA);	assert(b->common.type == FT_FEA);	afields = a->hd.fea->names;	bfields = b->hd.fea->names;		for (k=0; bfields[k] != NULL; k++) 		if(lin_search2(afields, bfields[k]) != -1) return 1;	return 0;}voidzero_fea_rec(rec,hd)struct fea_data *rec;struct header *hd;{	int i;	spsassert(hd && rec,"hd or rec is NULL");	for(i=0; i<hd->common.ndouble; i++)		rec->d_data[i] = 0;	for(i=0; i<hd->common.nfloat; i++)		rec->f_data[i] = 0;	for(i=0; i<hd->common.nlong; i++)		rec->l_data[i] = 0;	for(i=0; i<hd->common.nshort; i++)		rec->s_data[i] = 0;	for(i=0; i<hd->common.nchar; i++)		rec->b_data[i] = 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -