original files of m241
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/parse.c,v 1.2 2001/11/08 15:56:24 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: parse.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:24 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.7 2001/01/19 22:23:48 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.6 2000/03/17 00:12:42 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.5 1999/04/26 19:05:01 sra
|
||||
* Fix a few minor warnings, fix a few Solaris-specific problems in the
|
||||
* demo code.
|
||||
*
|
||||
* Revision 2.4 1998/02/25 04:57:29 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.3 1997/03/20 06:53:02 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.2 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1993/07/29 04:28:22 sra
|
||||
* Add copyright notice.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This is a hacked up version of Bridgham's parse_line() function.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/demo/parse.h>
|
||||
|
||||
/*
|
||||
* Backslash handling. Generates one character, shuffles
|
||||
* remaining string down appropriately to close up.
|
||||
*/
|
||||
|
||||
static void backslash(register char *p1)
|
||||
{
|
||||
register char *p2 = p1 + 1;
|
||||
if (*p2 >= '0' && *p2 <= '9') { /* octal digits */
|
||||
*p1 = (char) (*p2++ - '0');
|
||||
while (p2 <= p1 + 3 && *p2 >= '0' && *p2 <= '9')
|
||||
*p1 = (char) ((*p1 * 8) + (*p2++ - '0'));
|
||||
p1++;
|
||||
} else switch (*p2) {
|
||||
case 'a': *p2 = '\007'; break; /* bell */
|
||||
case 'b': *p2 = '\010'; break; /* backspace */
|
||||
case 'e': *p2 = '\033'; break; /* escape */
|
||||
case 'f': *p2 = '\014'; break; /* formfeed */
|
||||
case 'n': *p2 = '\012'; break; /* linefeed */
|
||||
case 'r': *p2 = '\015'; break; /* carriage return */
|
||||
case 't': *p2 = '\011'; break; /* tab */
|
||||
}
|
||||
while ((*p1++ = *p2++) != '\0'); /* and copy the line down */
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a line into argc and argv, returns argc.
|
||||
* Doublequote and backslash do the obvious quoting things.
|
||||
*/
|
||||
|
||||
int parse_line(char *line, char *argv[], int max_args)
|
||||
{
|
||||
int argc = 0, quoting = 0;
|
||||
for (;;) {
|
||||
while (isspace((int) *line))
|
||||
line++;
|
||||
switch (*line) {
|
||||
case '\0': return argc;
|
||||
case '\"': quoting = 1; line++; break;
|
||||
}
|
||||
if (argc >= max_args)
|
||||
return -1;
|
||||
argv[argc++] = line;
|
||||
while (quoting || !isspace((int) *line))
|
||||
switch (*line) {
|
||||
case '\0': return (quoting ? -1 : argc);
|
||||
case '\"': quoting = 0; *line = ' '; continue;
|
||||
case '\\': backslash(line); line++; continue;
|
||||
default: line++; continue;
|
||||
}
|
||||
*line++ = '\0';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user