00001 /* $Id: argvize.c,v 1.1.1.1 2006/01/05 05:41:16 root Exp $ */ 00002 00003 /* 00004 * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by Opsycon AB. 00017 * 4. The name of the author may not be used to endorse or promote products 00018 * derived from this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00021 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00024 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00026 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00027 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00028 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00029 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 */ 00033 00034 00035 #define MAX_AC 100 00036 00037 /* 00038 * Take the string pointed by 's', break it up in words and 00039 * make a pointer list in 'av'. Return number of 'args'. 00040 */ 00041 int 00042 argvize(char *av[], char *s) 00043 { 00044 char **pav = av, c; 00045 int ac; 00046 00047 for (ac = 0; ac < MAX_AC; ac++) { 00048 /* step over cntrls and spaces */ 00049 while (*s && *s <= ' ') 00050 s++; 00051 00052 if (!*s) 00053 break; 00054 00055 c = *s; 00056 /* if it's a quote skip forward */ 00057 if (c == '\'' || c == '"') { 00058 if (pav) 00059 *pav++ = ++s; 00060 while (*s && *s != c) 00061 s++; 00062 if (*s) 00063 *s++ = 0; 00064 } else { /* find end of word */ 00065 if (pav) 00066 *pav++ = s; 00067 while (' ' < *s) 00068 s++; 00069 } 00070 00071 if (*s) 00072 *s++ = 0; 00073 } 00074 return (ac); 00075 }
1.5.6