home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / nxtarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.6 KB  |  78 lines

  1. /*
  2.  * Copyright (c) 1991 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.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator   or   Software.Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie the rights
  23.  * to redistribute these changes.
  24.  */
  25. /*
  26.  *  nxtarg -- strip off arguments from a string
  27.  *
  28.  *  Usage:  p = nxtarg (&q,brk);
  29.  *    char *p,*q,*brk;
  30.  *    extern char _argbreak;
  31.  *
  32.  *    q is pointer to next argument in string
  33.  *    after call, p points to string containing argument,
  34.  *    q points to remainder of string
  35.  *
  36.  *  Leading blanks and tabs are skipped; the argument ends at the
  37.  *  first occurence of one of the characters in the string "brk".
  38.  *  When such a character is found, it is put into the external
  39.  *  variable "_argbreak", and replaced by a null character; if the
  40.  *  arg string ends before that, then the null character is
  41.  *  placed into _argbreak;
  42.  *  If "brk" is 0, then " " is substituted.
  43.  *
  44.  *  HISTORY
  45.  * 01-Jul-83  Steven Shafer (sas) at Carnegie-Mellon University
  46.  *    Bug fix: added check for "back >= front" in loop to chop trailing
  47.  *    white space.
  48.  *
  49.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  50.  *    Rewritten for VAX.  By popular demand, a table of break characters
  51.  *    has been added (implemented as a string passed into nxtarg).
  52.  *
  53.  *  Originally    from klg (Ken Greer); IUS/SUS UNIX.
  54.  */
  55.  
  56. char _argbreak;
  57. char *skipto();
  58.  
  59. char *nxtarg (q,brk)
  60. char **q,*brk;
  61. {
  62.     register char *front,*back;
  63.     front = *q;            /* start of string */
  64.     /* leading blanks and tabs */
  65.     while (*front && (*front == ' ' || *front == '\t')) front++;
  66.     /* find break character at end */
  67.     if (brk == 0)  brk = " ";
  68.     back = skipto (front,brk);
  69.     _argbreak = *back;
  70.     *q = (*back ? back+1 : back);    /* next arg start loc */
  71.     /* elim trailing blanks and tabs */
  72.     back -= 1;
  73.     while ((back >= front) && (*back == ' ' || *back == '\t')) back--;
  74.     back++;
  75.     if (*back)  *back = '\0';
  76.     return (front);
  77. }
  78.