home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / libcs / nxtarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-11  |  3.0 KB  |  85 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. /*
  29.  *  nxtarg -- strip off arguments from a string
  30.  *
  31.  *  Usage:  p = nxtarg (&q,brk);
  32.  *    char *p,*q,*brk;
  33.  *    extern char _argbreak;
  34.  *
  35.  *    q is pointer to next argument in string
  36.  *    after call, p points to string containing argument,
  37.  *    q points to remainder of string
  38.  *
  39.  *  Leading blanks and tabs are skipped; the argument ends at the
  40.  *  first occurence of one of the characters in the string "brk".
  41.  *  When such a character is found, it is put into the external
  42.  *  variable "_argbreak", and replaced by a null character; if the
  43.  *  arg string ends before that, then the null character is
  44.  *  placed into _argbreak;
  45.  *  If "brk" is 0, then " " is substituted.
  46.  *
  47.  *  HISTORY
  48.  * $Log:    nxtarg.c,v $
  49.  * Revision 1.2  90/12/11  17:57:10  mja
  50.  *     Add copyright/disclaimer for distribution.
  51.  * 
  52.  * 01-Jul-83  Steven Shafer (sas) at Carnegie-Mellon University
  53.  *    Bug fix: added check for "back >= front" in loop to chop trailing
  54.  *    white space.
  55.  *
  56.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  57.  *    Rewritten for VAX.  By popular demand, a table of break characters
  58.  *    has been added (implemented as a string passed into nxtarg).
  59.  *
  60.  *  Originally    from klg (Ken Greer); IUS/SUS UNIX.
  61.  */
  62.  
  63. char _argbreak;
  64. char *skipto();
  65.  
  66. char *nxtarg (q,brk)
  67. char **q,*brk;
  68. {
  69.     register char *front,*back;
  70.     front = *q;            /* start of string */
  71.     /* leading blanks and tabs */
  72.     while (*front && (*front == ' ' || *front == '\t')) front++;
  73.     /* find break character at end */
  74.     if (brk == 0)  brk = " ";
  75.     back = skipto (front,brk);
  76.     _argbreak = *back;
  77.     *q = (*back ? back+1 : back);    /* next arg start loc */
  78.     /* elim trailing blanks and tabs */
  79.     back -= 1;
  80.     while ((back >= front) && (*back == ' ' || *back == '\t')) back--;
  81.     back++;
  82.     if (*back)  *back = '\0';
  83.     return (front);
  84. }
  85.