fea_edit.c
来自「speech signal process tools」· C语言 代码 · 共 1,172 行 · 第 1/2 页
C
1,172 行
while (1) { if (flag == 0 || *buf == '\n') { put_fea_rec (fea_rec, oh, out); clear_fea_rec (fea_rec, oh); rec_count++; if (local_fgets (buf, BUFSIZE, tstrm) == NULL) break; } else if (*buf == '#') { if (debug_level > 0) Fprintf (stderr, "fea_edit: %s", buf); if ((name = strtok (buf, " \t")) == NULL) goto trouble; if (strcmp (name + 1, "Tag") == 0) { if ((cptr = strtok (0, " \t\n")) == NULL) { Fprintf (stderr, "fea_edit: Missing Tag value.\n"); goto trouble; } fea_rec -> tag = atol (cptr); if (local_fgets (buf, BUFSIZE, tstrm) == NULL) goto trouble; } else { name = savestring (name); name++; size = get_fea_siz (name, oh, NULL, NULL); if (size == 0) { Fprintf (stderr, "fea_edit: name: %s not a valid field.\n", name); goto trouble; } type = get_fea_type (name, oh); switch (type) { case SHORT: sptr = (short *) get_fea_ptr (fea_rec, name, oh); flag = fill_shorts (sptr, (long)size, tstrm, '#'); break; case LONG: lptr = (long *) get_fea_ptr (fea_rec, name, oh); flag = fill_longs (lptr, (long)size, tstrm, '#'); break; case FLOAT: fptr = (float *) get_fea_ptr (fea_rec, name, oh); flag = fill_floats (fptr, (long)size, tstrm, '#'); break; case DOUBLE: dptr = (double *) get_fea_ptr (fea_rec, name, oh); flag = fill_doubles (dptr, (long)size, tstrm, '#'); break; case CHAR: cptr = get_fea_ptr (fea_rec, name, oh); flag = fill_chars (cptr, (long)size, tstrm, '#'); break; case BYTE: bptr = get_fea_ptr (fea_rec, name, oh); flag = fill_bytes (bptr, (long)size, tstrm, '#'); break; case CODED: sptr = (short *) get_fea_ptr (fea_rec, name, oh); flag = fill_coded (sptr, (long)size, name, oh, tstrm, '#'); break; } } } } rewind (out); oh -> common.ndrec = rec_count; write_header (oh, out); (void) fclose (out); (void) fclose (tstrm); } else { /* other part of the if abort */ Fprintf (stderr,"fea_edit: Aborting without making changes.\n"); } (void) unlink (tempfile); exit (0);trouble: Fprintf (stderr, "fea_edit: Trouble reading temp file back.\n"); Fprintf (stderr, "fea_edit: Temp file saved in %s\n", tempfile); Fprintf (stderr, "fea_edit: Want to edit text again? [yn] "); if (strcmp(gets(buf),"n") != 0) goto again; exit (1);}shorttype_str (s)char *s;{ if (strcmp (s, "SHORT") == 0) return SHORT; if (strcmp (s, "LONG") == 0) return LONG; if (strcmp (s, "FLOAT") == 0) return FLOAT; if (strcmp (s, "DOUBLE") == 0) return DOUBLE; if (strcmp (s, "CHAR") == 0) return CHAR; if (strcmp (s, "CODED") == 0) return CODED; if (strcmp (s, "BYTE") == 0) return BYTE; Fprintf (stderr, "fea_edit: bad type code: %s \n", s); return 0;}voidprint_rec (rec, hd, file)struct fea_data *rec;struct header *hd;FILE * file;{ int i, count = 0; long psize, *l_ptr; short *s_ptr; double *d_ptr; float *f_ptr; char *c_ptr, *b_ptr; struct fea_header *fea = hd -> hd.fea; if (hd -> common.type != FT_FEA) { Fprintf (stderr, "fea_edit: print_fea_rec: called with non fea hd\n"); exit (1); } if (hd -> common.tag) Fprintf (file, "#Tag %ld\n", rec -> tag); for (i = 0; i < fea -> field_count; i++) { Fprintf (file, "#%s\t", fea -> names[i]); if (fea -> types[i] == DOUBLE) d_ptr = (double *) get_fea_ptr (rec, fea -> names[i], hd); if (fea -> types[i] == FLOAT) f_ptr = (float *) get_fea_ptr (rec, fea -> names[i], hd); if (fea -> types[i] == LONG) l_ptr = (long *) get_fea_ptr (rec, fea -> names[i], hd); if (fea -> types[i] == BYTE) b_ptr = get_fea_ptr (rec, fea -> names[i], hd); if (fea -> types[i] == SHORT || fea -> types[i] == CODED) s_ptr = (short *) get_fea_ptr (rec, fea -> names[i], hd); if (fea -> types[i] == CHAR) c_ptr = get_fea_ptr (rec, fea -> names[i], hd); count = 0; psize = fea -> sizes[i]; while (psize--) { count++; if (fea -> types[i] == DOUBLE) Fprintf (file, "%.8lg ", *d_ptr++); if (fea -> types[i] == FLOAT) Fprintf (file, "%.8g ", *f_ptr++); if (fea -> types[i] == LONG) Fprintf (file, "%ld ", *l_ptr++); if (fea -> types[i] == SHORT) Fprintf (file, "%d ", *s_ptr++); if (fea -> types[i] == BYTE) Fprintf (file, "%d ", (int)*b_ptr++); if (fea -> types[i] == CHAR) if (isprint (*c_ptr)) Fprintf (file, "%c", *c_ptr++); if (fea -> types[i] == CODED) { if (idx_ok (*s_ptr, fea -> enums[i])) Fprintf (file, "%s ", fea -> enums[i][*s_ptr++]); else Fprintf (file, "bad-code:%d ", *s_ptr++); count++; } if ((fea -> types[i] != CHAR && count > 7) || (fea -> types[i] == CHAR && count > 50)) { count = 0; if (psize) /* more data remains to be printed */ Fprintf (file, "\n\t"); } } Fprintf (file, "\n"); }}intfill_shorts (sptr, size, strm, symbol)short *sptr;long size;FILE * strm;char symbol;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_shorts: Too many values, extra ignored\n"); else *sptr++ = atoi (ptr); } }}intfill_bytes (bptr, size, strm, symbol)char *bptr;long size;FILE * strm;char symbol;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_bytes: Too many values, extra ignored\n"); else *bptr++ = atoi (ptr); } }}intfill_longs (lptr, size, strm, symbol)long *lptr;long size;FILE * strm;char symbol;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_longs: Too many values, extra ignored\n"); else *lptr++ = atol (ptr); } }}intfill_floats (fptr, size, strm, symbol)float *fptr;long size;FILE * strm;char symbol;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_floats: Too many values, extra ignored\n"); else *fptr++ = atof (ptr); } }}intfill_doubles (dptr, size, strm, symbol)double *dptr;long size;FILE * strm;char symbol;{ static long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_doubles: Too many values, extra ignored\n"); else *dptr++ = atof (ptr); } }}intfill_chars (cptr, size, strm, symbol)char *cptr;long size;FILE * strm;char symbol;{ static long count; char *ptr, *s; int len; char tokenstring[3]; sprintf(tokenstring,"\n%c",symbol); count = 0; s = NULL; *cptr = '\0'; while (1) { if ((ptr = strtok (s, tokenstring)) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if ( ((count += strlen (ptr) + 1) > size) && strcmp(&ptr[strlen(ptr)-1]," ")!=0) Fprintf (stderr, "fea_edit: fill_chars: Too many values, extra ignored\n"); len = size; (void) strncat (cptr, ptr, len); } } }intfill_coded (sptr, size, name, hd, strm, symbol)short *sptr;long size;char *name;struct header *hd;FILE * strm;char symbol;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_coded: Too many values, extra ignored\n"); else *sptr++ = fea_encode (ptr, name, hd); } }}intfill_gencoded (sptr, size, name, hd, strm, symbol, codes)short *sptr;long size;char *name;struct header *hd;FILE * strm;char symbol;char **codes;{ long count; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (count++ > size) Fprintf (stderr, "fea_edit: fill_gencoded: Too many values, extra ignored\n"); else { /* *sptr++ = fea_encode (ptr, name, hd); */ *sptr++ = lin_search2(codes, ptr); if (debug_level > 5) Fprintf (stderr, "lin_search2(codes, %s) = %d\n", ptr, lin_search2(codes, ptr)); } } }}/* * This funtion is not used in this program anymore: * * int * fill_codes (code_ptr, size, name, hd, strm, symbol) * char **code_ptr; * long size; * char *name; * struct header *hd; * FILE *strm; * char symbol; * { * long count; * long index_val = 0; * char *ptr, *s; * * count = 0; * s = NULL; * while (1) { * if ((ptr = strtok (s, " \t\n")) == NULL) { * if (local_fgets (buf, BUFSIZE, strm) == NULL) * return 0; * if (*buf == symbol || *buf == '\n') * return 1; * s = buf; * } * else { * s = NULL; * if (count++ > size) * Fprintf (stderr, * "fea_edit: fill_codes: Too many values, extra ignored\n"); * else * code_ptr[index_val++] = savestring (ptr); * } * } * } * */char **fill_codes1 (code_ptr, size, name, hd, strm, symbol, gen_fields)char **code_ptr;long size;char *name;struct header *hd;FILE *strm;char symbol;int *gen_fields;{ long index_val = 0; char *ptr, *s; *gen_fields = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (local_fgets (buf, BUFSIZE, strm) == NULL) return (code_ptr); if (*buf == symbol || *buf == '\n') return (code_ptr); s = buf; } else { s = NULL; if (debug_level > 5) Fprintf (stderr, "ptr = %s\n", ptr); if (index (ptr, ']') != NULL) /* ']' exists in string */ return (code_ptr); if (index (ptr, '[') == NULL) { /* '[' does not exist in string */ code_ptr[*gen_fields] = savestring (ptr); *gen_fields += 1; code_ptr = (char **) realloc ((char *) code_ptr, (*gen_fields + 1) * sizeof (char *)); code_ptr[*gen_fields] = NULL; if (debug_level > 5) { Fprintf (stderr, "fill_codes1: code_ptr[*gen_fields = %d] = %s\n", *gen_fields - 1, code_ptr[*gen_fields - 1]); (void) fflush (stderr); } } } }}voidclear_fea_rec (rec, hd)struct fea_data *rec;struct header *hd;{ double *dptr; float *fptr; short *sptr; long *lptr; char *cptr; int k; k = hd -> common.ndouble; dptr = rec -> d_data; while (k--) *dptr++ = 0; k = hd -> common.nfloat; fptr = rec -> f_data; while (k--) *fptr++ = 0; k = hd -> common.nlong; lptr = rec -> l_data; while (k--) *lptr++ = 0; k = hd -> common.nshort; sptr = rec -> s_data; while (k--) *sptr++ = 0; k = hd -> common.nchar; cptr = rec -> b_data; while (k--) *cptr++ = 0;}char *local_fgets(buf, n, stream)char *buf;int n;FILE *stream;{ if(fgets(buf,n,stream) == NULL) return NULL; while(*buf == '*') if(fgets(buf,n,stream) == NULL) return NULL; return buf;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?