putsym.c

来自「speech signal process tools」· C语言 代码 · 共 806 行 · 第 1/2 页

C
806
字号
#endif	(void)sprintf (text, "string %s = %c%s%c;\n", symbol, DQUOTE, value, DQUOTE);	(void) fprintf (tmp_fp, "%s", text);	found = TRUE;     } /* end while */     if ( !found ) {	/* Looks like the symbol didn't exist in the ESPS Common file	 * so let's append it to the end of the file. */#ifdef DEBUG	(void) fprintf (stderr, "fputsym_s: new symbol (%s)\n", name);#endif	(void)sprintf (text, "string %s = %c%s%c;\n", symbol, DQUOTE, value, DQUOTE);	(void) fprintf (tmp_fp, "%s", text);     }/* * Now copy contents of TMP_FILE to ESPS Common file, * but rewind both files first * */    (void) rewind (tmp_fp);    (void) fclose (com_fp);    if ((com_fp = fopen (filename, "w")) == NULL) {	(void) fprintf (stderr,	"fputsym_s: could not open file %s for writing.\n",	filename);	return -1;    }    while (fgets(line, LINE_SIZE, tmp_fp) != NULL) {	(void)fprintf (com_fp, "%s", line);#ifdef DEBUG	(void)fprintf (stderr, "%s", line);#endif    }    (void) fclose (tmp_fp);    (void) fclose (com_fp);    (void) unlink (template);    return 0;} /* end fputsym_s() */intputsym_s (symbol, value)char	*symbol;char	*value;{char	buffer[LINE_SIZE];	/* buffer to hold output text */char	*text = buffer;		/* pointer to buffer */char	*name = buffer;		/* string for holding name of symbol */char	line[LINE_SIZE];char	*type;char	*val;int	found = FALSE;int     ret;char	DQUOTE = '"';    spsassert(symbol != NULL, "putsym_s: symbol is NULL");    if((ret = setup_common(NULL)) != 1) return ret;/* * we've opened the file, now update it. * But first check if symbol already exists in the ESPS Common file. * */#ifdef DEBUG    (void) fprintf (stderr,    "\nputsym_s: ESPS Common file %s has been opened for updating.\n",    filename);#endif     while (fgets(line, LINE_SIZE, com_fp) != NULL) {	(void) strcpy (buffer, line); 	if ( strcmp("string", (type = strtok(buffer, " \t"))) != 0 ) { #ifdef DEBUG   (void) fprintf (stderr, "putsym_s: skipping (%s) type\n", type);#endif	   (void)fprintf (tmp_fp, "%s", line);	   continue;	}	name = strtok(NULL, "\t ="); 	val = strtok(NULL, "\t ;");#ifdef DEBUG	(void) fprintf (stderr, "putsym_s: type: %s\n", type);	(void) fprintf (stderr,	"          name: %s\n", name);	(void) fprintf (stderr,	"         value: %s\n", val);#endif	if ( strcmp(name, symbol) != 0) {#ifdef DEBUG	   (void) fprintf (stderr, "putsym_s: skipping (%s) symbol\n", name);#endif	   (void) fprintf (tmp_fp, "%s", line);	   continue;	}#ifdef DEBUG	(void) fprintf (stderr, "putsym_s: updating (%s) symbol\n", name);#endif	(void)sprintf (text, "string %s = %c%s%c;\n", symbol, DQUOTE, value, DQUOTE);	(void) fprintf (tmp_fp, "%s", text);	found = TRUE;     } /* end while */     if ( !found ) {	/* Looks like the symbol didn't exist in the ESPS Common file	 * so let's append it to the end of the file. */#ifdef DEBUG	(void) fprintf (stderr, "putsym_s: new symbol (%s)\n", name);#endif	(void)sprintf (text, "string %s = %c%s%c;\n", symbol, DQUOTE, value, DQUOTE);	(void) fprintf (tmp_fp, "%s", text);     }/* * Now copy contents of TMP_FILE to ESPS Common file, * but rewind both files first * */    (void) rewind (tmp_fp);    (void) fclose (com_fp);    if ((com_fp = fopen (filename, "w")) == NULL) {	(void) fprintf (stderr,	"putsym_s: could not open ESPS Common file %s for writing.\n",	filename);	return -1;    }    while (fgets(line, LINE_SIZE, tmp_fp) != NULL) {	(void)fprintf (com_fp, "%s", line);#ifdef DEBUG	(void)fprintf (stderr, "%s", line);#endif    }    (void) fclose (tmp_fp);    (void) fclose (com_fp);    (void) unlink (template);    return 0;} /* end putsym_s() */intputsym_f (symbol, value)char	*symbol;float	value;{char	buffer[LINE_SIZE];	/* buffer to hold output text */char	*text = buffer;		/* pointer to buffer */char	*name = buffer;		/* string for holding name of symbol */char	line[LINE_SIZE];char	*type;char	*val;int	found = FALSE;int     ret;    spsassert(symbol != NULL, "putsym_f: symbol is NULL");    if((ret = setup_common(NULL)) != 1) return ret;/* * we've opened the file, now update it. * But first check if symbol already exists in the ESPS Common file. * */#ifdef DEBUG   (void) fprintf(stderr,"putsym_f: value: %f, symbol: %s\n",value,symbol);#endif     while (fgets(line, LINE_SIZE, com_fp) != NULL) {	(void) strcpy (buffer, line); 	if ( strcmp("float", (type = strtok(buffer, " \t"))) != 0 ) { #ifdef DEBUG   (void) fprintf (stderr, "putsym_f: skipping (%s) type\n", type);#endif	   (void) fputs (line,tmp_fp);	   continue;	}	name = strtok(NULL, "\t ="); 	val = strtok(NULL, "\t ;");#ifdef DEBUG	(void) fprintf (stderr, "putsym_f: val (string): %s\n",val);	(void) fprintf (stderr, "putsym_f: type: %s\n", type);	(void) fprintf (stderr,	"          name: %s\n", name);	(void) fprintf (stderr,	"         value: %f\n", (float)atof(val));#endif	if (strcmp(name, symbol) != 0) {#ifdef DEBUG	   (void) fprintf (stderr, "putsym_f: skipping (%s) symbol\n", name);#endif	   (void) fputs (line,tmp_fp);	   continue;	}#ifdef DEBUG	(void) fprintf (stderr, "putsym_f: updating (%s) symbol\n", name);#endif	(void)sprintf (text, "float %s = %f;\n", symbol, value);	(void) fputs (text,tmp_fp);#ifdef DEBUG        (void) fprintf(stderr,"text: %s\n",text);#endif	found = TRUE;     } /* end while */     if ( !found ) {	/* Looks like the symbol didn't exist in the ESPS Common file	 * so let's append it to the end of the file. */#ifdef DEBUG	(void) fprintf (stderr, "putsym_f: new symbol (%s)\n", name);#endif	(void)sprintf (text, "float %s = %f;\n", symbol, value);	(void) fputs (text,tmp_fp);     }/* * Now copy contents of TMP_FILE to ESPS Common file, * but rewind both files first * */    (void) rewind (tmp_fp);    (void) fclose (com_fp);    if ((com_fp = fopen (filename, "w")) == NULL) {	(void) fprintf (stderr,	"putsym_f: could not open ESPS Common file %s for writing.\n",	filename);	return -1;    }    while (fgets(line, LINE_SIZE, tmp_fp) != NULL) {	(void)fprintf (com_fp, "%s", line);#ifdef DEBUG	(void)fprintf (stderr, "%s", line);#endif    }    (void) fclose (tmp_fp);    (void) fclose (com_fp);    (void) unlink (template);    return 0;} /* end putsym_f() */intfputsym_f (symbol, value, file)char	*symbol;float	value;char	*file;{char	buffer[LINE_SIZE];	/* buffer to hold output text */char	*text = buffer;		/* pointer to buffer */char	*name = buffer;		/* string for holding name of symbol */char	line[LINE_SIZE];char	*type;char	*val;int	found = FALSE;int     ret;    spsassert(symbol != NULL, "fputsym_f: symbol is NULL");    spsassert(file, "fputsym_f: filename is NULL");    if((ret = setup_common(file)) != 1) return ret;/* * we've opened the file, now update it. * But first check if symbol already exists in the ESPS Common file. * */#ifdef DEBUG   (void) fprintf(stderr,"fputsym_f: value: %f, symbol: %s\n",value,symbol);#endif     while (fgets(line, LINE_SIZE, com_fp) != NULL) {	(void) strcpy (buffer, line); 	if ( strcmp("float", (type = strtok(buffer, " \t"))) != 0 ) { #ifdef DEBUG   (void) fprintf (stderr, "putsym_f: skipping (%s) type\n", type);#endif	   (void) fputs (line,tmp_fp);	   continue;	}	name = strtok(NULL, "\t ="); 	val = strtok(NULL, "\t ;");#ifdef DEBUG	(void) fprintf (stderr, "val (string): %s\n", val);	(void) fprintf (stderr, "putsym_f: type: %s\n", type);	(void) fprintf (stderr,	"          name: %s\n", name);	(void) fprintf (stderr,	"         value: %f\n", (float)atof(val));#endif	if (strcmp(name, symbol) != 0) {#ifdef DEBUG	   (void) fprintf (stderr, "fputsym_f: skipping (%s) symbol\n", name);#endif	   (void) fputs (line,tmp_fp);	   continue;	}#ifdef DEBUG	(void) fprintf (stderr, "putsym_f: updating (%s) symbol\n", name);#endif	(void)sprintf (text, "float %s = %f;\n", symbol, value);#ifdef DEBUG        (void) fprintf(stderr,"text: %s\n",text);#endif	(void) fputs (text,tmp_fp);	found = TRUE;     } /* end while */     if ( !found ) {	/* Looks like the symbol didn't exist in the ESPS Common file	 * so let's append it to the end of the file. */#ifdef DEBUG	(void) fprintf (stderr, "putsym_f: new symbol (%s)\n", name);#endif	(void)sprintf (text, "float %s = %f;\n", symbol, value);	(void) fputs (text,tmp_fp);     }/* * Now copy contents of TMP_FILE to ESPS Common file, * but rewind both files first * */    (void) rewind (tmp_fp);    (void) fclose (com_fp);    if ((com_fp = fopen (filename, "w")) == NULL) {	(void) fprintf (stderr,	"putsym_f: could not open ESPS Common file %s for writing.\n",	filename);	return -1;    }    while (fgets(line, LINE_SIZE, tmp_fp) != NULL) {	(void)fprintf (com_fp, "%s", line);#ifdef DEBUG	(void)fprintf (stderr, "%s", line);#endif    }    (void) fclose (tmp_fp);    (void) fclose (com_fp);    (void) unlink (template);    return 0;} /* end putsym_f() */

⌨️ 快捷键说明

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