home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3349 / fields.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  1.2 KB  |  70 lines

  1. /*
  2.  * Copyright 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <ctype.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. #ifndef    lint
  14. static    char    sccsid[] = "@(#)fields.c    3.2    08:26:23    11/26/90";
  15. #endif
  16.  
  17. extern    char    *Progname;
  18.  
  19. /*
  20.  * valid_field - insure that a field contains all legal characters
  21.  *
  22.  * The supplied field is scanned for non-printing and other illegal
  23.  * characters.  If any illegal characters are found, valid_field
  24.  * returns -1.  Zero is returned for success.
  25.  */
  26.  
  27. int
  28. valid_field (field, illegal)
  29. char    *field;
  30. char    *illegal;
  31. {
  32.     char    *cp;
  33.  
  34.     for (cp = field;*cp && isprint (*cp) && ! strchr (illegal, *cp);cp++)
  35.         ;
  36.  
  37.     if (*cp)
  38.         return -1;
  39.     else
  40.         return 0;
  41. }
  42.  
  43. /*
  44.  * change_field - change a single field if a new value is given.
  45.  *
  46.  * prompt the user with the name of the field being changed and the
  47.  * current value.
  48.  */
  49.  
  50. void
  51. change_field (buf, prompt)
  52. char    *buf;
  53. char    *prompt;
  54. {
  55.     char    new[BUFSIZ];
  56.     char    *cp;
  57.  
  58.     printf ("\t%s [%s]: ", prompt, buf);
  59.     if (fgets (new, BUFSIZ, stdin) != new)
  60.         return;
  61.  
  62.     if (cp = strchr (new, '\n'))
  63.         *cp = '\0';
  64.     else
  65.         return;
  66.  
  67.     if (new[0])
  68.         strcpy (buf, new);
  69. }
  70.