📄 fea_edit.c
字号:
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 (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, size, tstrm, '#'); break; case LONG: lptr = (long *) get_fea_ptr (fea_rec, name, oh); flag = fill_longs (lptr, size, tstrm, '#'); break; case FLOAT: fptr = (float *) get_fea_ptr (fea_rec, name, oh); flag = fill_floats (fptr, size, tstrm, '#'); break; case DOUBLE: dptr = (double *) get_fea_ptr (fea_rec, name, oh); flag = fill_doubles (dptr, size, tstrm, '#'); break; case CHAR: cptr = get_fea_ptr (fea_rec, name, oh); flag = fill_chars (cptr, size, tstrm, '#'); break; case CODED: sptr = (short *) get_fea_ptr (fea_rec, name, oh); flag = fill_coded (sptr, 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 (template); exit (0);trouble: Fprintf (stderr, "fea_edit: Trouble reading temp file back.\n"); Fprintf (stderr, "fea_edit: Temp file saved in %s\n", template); Fprintf (stderr, "fea_edit: Want to edit text again? [yn] "); if (getchar() != 'n') 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; 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; 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] == 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, "%lg ", *d_ptr++); if (fea -> types[i] == FLOAT) Fprintf (file, "%g ", *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] == 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; 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 (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_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 (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 (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 (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; count = 0; s = NULL; *cptr = '\0'; while (1) { if ((ptr = strtok (s, " \n")) == NULL) { if (fgets (buf, BUFSIZE, strm) == NULL) return 0; if (*buf == symbol || *buf == '\n') return 1; s = buf; } else { s = NULL; if (size != 1 && count += strlen (ptr) + 1 > size) { Fprintf (stderr, "fea_edit: fill_chars: Too many values, extra ignored\n"); len = strlen (ptr) - count + 1; (void) strncat (cptr, ptr, len); } else if (size == 1 && count += strlen (ptr) > size) { Fprintf (stderr, "fea_edit: fill_chars: Too many values, extra ignored\n"); (void) strncat (cptr, ptr, 1); } else { (void) strcat (cptr, ptr);/* (void) strcat (cptr, "\n"); */ } } }}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 (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 (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 > 5) Fprintf (stderr, "lin_search2(codes, %s) = %d\n", ptr, lin_search2(codes, ptr)); } } }}intfill_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 = 0; char *ptr, *s; count = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (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++] = 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 count; long index = 0; char *ptr, *s; count = 0; *gen_fields = 0; s = NULL; while (1) { if ((ptr = strtok (s, " \t\n")) == NULL) { if (fgets (buf, BUFSIZE, strm) == NULL) return (code_ptr); if (*buf == symbol || *buf == '\n') return (code_ptr); s = buf; } else { s = NULL; if (debug > 5) Fprintf (stderr, "ptr = %s\n", ptr); if (strchr (ptr, ']') != NULL) /* ']' exists in string */ return (code_ptr); if (strchr (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 > 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -