#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *skip_spc (char *s);
char *skip_nspc (char *s, char **dp);
char *copy_nspc (char *s, char **dp);
char *handle_options (s, port, xfile, ifile, ofile, client, dir, user, appendp)
char *s;
char *port, *xfile, *client, *dir, *user, *ofile, *ifile;
int *appendp;
{
int ch;
char *s1, *d;
*port = *xfile = *ifile = *client = *dir = *user = *ofile = 0;
*appendp = 0;
s = skip_spc (s);
while (*s == '-') {
s1 = s;
++s;
ch = *s++;
s = skip_spc (s);
switch (ch) {
case 'p':
d = port;
s = copy_nspc (s, &d);
break;
case 'x':
d = xfile;
s = copy_nspc (s, &d);
break;
case 'i':
d = ifile;
s = copy_nspc (s, &d);
break;
case 'c':
d = client;
s = copy_nspc (s, &d);
break;
case 'd':
d = dir;
s = copy_nspc (s, &d);
break;
case 'u':
d = user;
s = copy_nspc (s, &d);
break;
case 'o':
d = ofile;
s = copy_nspc (s, &d);
break;
case 's':
s = copy_nspc (s, &d);
break;
case 'a':
d = ofile;
s = copy_nspc (s, &d);
*appendp = 1;
break;
default:
return (s1);
}
s = skip_spc (s);
}
return (s);
}
char *skip_spc (s)
char *s;
{
for (; ((*s == ' ') || (*s == '\t') || (*s == '\n')); ++s);
return (s);
}
char *copy_nspc (s, dp)
char *s, **dp;
{
char *d;
d = *dp;
for (; ((*s != ' ') && (*s != '\t') && (*s != '\n') && (*s != 0));
++s) *d++ = *s;
*d = 0;
*dp = d;
return (s);
}
int split_quote_args (s, argv, dp)
char *s;
char **argv;
char **dp;
{
int i, ch;
char *d, *s1, *d1;
d = *dp;
for (i = 0;; ++i) {
for (; ((*s == ' ') || (*s == '\t') || (*s == '\n')); ++s);
if (*s == 0) {
break;
}
*argv++ = d;
for (; ((*s != ' ') && (*s != '\t') && (*s != '\n') &&
(*s != 0)); ++s) {
if ((*s == '\'') || (*s == '`') || (*s == '\"')) {
d1 = d;
s1 = s;
ch = *s;
++s;
for (; ((*s != ch) && (*s != 0)); ++s) *d++ = *s;
if (*s == 0) {
/* no matching quote -- do not treat as quote */
d = d1;
s = s1;
*d++ = *s;
}
} else {
*d++ = *s;
}
}
*d++ = 0;
}
*argv = 0;
*dp = d;
return (i);
}