parse.c revision 56a424cca6b3f91f31bdab72a4626c48c779fe8b
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
* For copyright info, see copyright.h.
*/
#include "ss_internal.h"
#include "copyright.h"
#include <errno.h>
/*
* parse(line_ptr, argc_ptr)
*
* Function:
* Parses line, dividing at whitespace, into tokens, returns
* the "argc" and "argv" values.
* Arguments:
* line_ptr (char *)
* Pointer to text string to be parsed.
* argc_ptr (int *)
* Where to put the "argc" (number of tokens) value.
* Returns:
* argv (char **)
* Series of pointers to parsed tokens.
*/
(unsigned)(n+2)*sizeof(char*))
int sci_idx;
register char *line_ptr;
int *argc_ptr;
{
register int argc;
register enum parse_mode parse_mode;
*argc_ptr = 0;
return(argv);
}
argc = 0;
while (1) {
#ifdef DEBUG
{
}
#endif
while (parse_mode == WHITESPACE) {
if (*line_ptr == '\0')
goto end_of_line;
line_ptr++;
continue;
}
if (*line_ptr == '"') {
/* go to quoted-string mode */
}
else {
/* random-token mode */
parse_mode = TOKEN;
}
}
while (parse_mode == TOKEN) {
if (*line_ptr == '\0') {
*cp++ = '\0';
goto end_of_line;
}
*cp++ = '\0';
line_ptr++;
}
else if (*line_ptr == '"') {
line_ptr++;
}
else {
}
}
while (parse_mode == QUOTED_STRING) {
if (*line_ptr == '\0') {
"Unbalanced quotes in command line");
*argc_ptr = 0;
return NULL;
}
else if (*line_ptr == '"') {
if (*++line_ptr == '"') {
*cp++ = '"';
line_ptr++;
}
else {
parse_mode = TOKEN;
}
}
else {
}
}
}
#ifdef DEBUG
{
int i;
for (i = 0; i <= argc; i++)
printf ("\targv[%2d] = `%s'\n", i,
}
#endif
return(argv);
}