home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / libcs / strarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-11  |  2.4 KB  |  66 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*  strarg  --  parse a string
  29.  *
  30.  *  Usage:  p = strarg (ptr, brk, prompt, defalt, buf);
  31.  *    char *p, **ptr, *brk, *prompt, *defalt, *buf;
  32.  *
  33.  *  Strarg will parse an argument from the string pointed to by "ptr",
  34.  *  bumping ptr to point to the next argument in the string.
  35.  *  The argument parsed will be copied into "buf".  If there is no
  36.  *  argument, then getstr() will be called, and the value placed into
  37.  *  buf.  In any event, the address of buf is returned as a value.
  38.  *  "Brk" is the list of characters which terminate an argument;
  39.  *  if 0, then " " is used.
  40.  *
  41.  *  HISTORY
  42.  * $Log:    strarg.c,v $
  43.  * Revision 1.2  90/12/11  17:59:59  mja
  44.  *     Add copyright/disclaimer for distribution.
  45.  * 
  46.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  47.  *    Rewritten for VAX.
  48.  *
  49.  */
  50.  
  51. #include <libc.h>
  52.  
  53. char *strarg (ptr, brk, prompt, defalt, buf)
  54. char **ptr, *brk, *prompt, *defalt, *buf;
  55. {
  56.     register char *arg;
  57.  
  58.     arg = nxtarg (ptr,brk);        /* parse an argument */
  59.     fflush (stdout);
  60.  
  61.     if (*arg && strcmp (arg,"?")!=0)  strcpy (buf,arg);
  62.     else getstr (prompt,defalt,buf);
  63.  
  64.     return (buf);
  65. }
  66.