1
0
Files
irix-657m-src/eoe/cmd/ppp/getargs.c
2022-09-29 17:59:04 +03:00

133 lines
2.4 KiB
C

/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
#ident "$Revision: 1.5 $"
#include "uucp.h"
/*
* generate a vector of pointers (arps) to the
* substrings in string "s".
* Each substring is separated by blanks and/or tabs.
* s -> string to analyze -- s GETS MODIFIED
* arps -> array of pointers -- count + 1 pointers
* count -> max number of fields
* returns:
* i -> # of subfields
* arps[i] = NULL
*/
int
getargs(char *s, char *arps[], int count)
{
register int i;
bzero(arps, sizeof(arps[0])*(count+1));
for (i = 0; i < count; i++) {
while (*s == ' ' || *s == '\t')
*s++ = '\0';
if (*s == '\n')
*s = '\0';
if (*s == '\0')
break;
arps[i] = s++;
while (*s != '\0' && *s != ' '
&& *s != '\t' && *s != '\n')
s++;
}
return(i);
}
/***
* bsfix(args) - remove backslashes from args
*
* \123 style strings are collapsed into a single character
* \000 gets mapped into \N for further processing downline.
* \ at end of string is removed
* \t gets replaced by a tab
* \n gets replaced by a newline
* \r gets replaced by a carriage return
* \b gets replaced by a backspace
* \s gets replaced by a blank
* any other unknown \ sequence is left intact for further processing
* downline.
*/
void
bsfix(char **args)
{
register char *str, *to, *cp;
register int num;
for (; *args; args++) {
str = *args;
for (to = str; *str; str++) {
if (*str == '\\') {
if (str[1] == '\0')
break;
switch (*++str) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
for ( num = 0, cp = str
; cp - str < 3
; cp++
) {
if ('0' <= *cp && *cp <= '7') {
num <<= 3;
num += *cp - '0';
}
else
break;
}
if (num == 0) {
*to++ = '\\';
*to++ = 'N';
} else
*to++ = num;
str = cp-1;
break;
case 't':
*to++ = '\t';
break;
case 's':
*to++ = ' ';
break;
case 'n':
*to++ = '\n';
break;
case 'r':
*to++ = '\r';
break;
case 'b':
*to++ = '\b';
break;
default:
*to++ = '\\';
*to++ = *str;
break;
}
}
else
*to++ = *str;
}
*to = '\0';
}
}