10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22132Srobinson
23132Srobinson /*
24*1219Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25132Srobinson * Use is subject to license terms.
26132Srobinson */
27132Srobinson
280Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate
31132Srobinson #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
33*1219Sraf #include "mt.h"
340Sstevel@tonic-gate #include "uucp.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate * generate a vector of pointers (arps) to the
380Sstevel@tonic-gate * substrings in string "s".
390Sstevel@tonic-gate * Each substring is separated by blanks and/or tabs.
400Sstevel@tonic-gate * s -> string to analyze -- s GETS MODIFIED
410Sstevel@tonic-gate * arps -> array of pointers -- count + 1 pointers
420Sstevel@tonic-gate * count -> max number of fields
430Sstevel@tonic-gate * returns:
440Sstevel@tonic-gate * i -> # of subfields
450Sstevel@tonic-gate * arps[i] = NULL
460Sstevel@tonic-gate */
470Sstevel@tonic-gate
48132Srobinson static int
getargs(char * s,char * arps[],int count)49132Srobinson getargs(char *s, char *arps[], int count)
500Sstevel@tonic-gate {
51132Srobinson int i;
520Sstevel@tonic-gate
530Sstevel@tonic-gate for (i = 0; i < count; i++) {
540Sstevel@tonic-gate while (*s == ' ' || *s == '\t')
550Sstevel@tonic-gate *s++ = '\0';
560Sstevel@tonic-gate if (*s == '\n')
570Sstevel@tonic-gate *s = '\0';
580Sstevel@tonic-gate if (*s == '\0')
590Sstevel@tonic-gate break;
600Sstevel@tonic-gate arps[i] = s++;
61132Srobinson while (*s != '\0' && *s != ' ' && *s != '\t' && *s != '\n')
62132Srobinson s++;
630Sstevel@tonic-gate }
640Sstevel@tonic-gate arps[i] = NULL;
650Sstevel@tonic-gate return (i);
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * bsfix(args) - remove backslashes from args
700Sstevel@tonic-gate *
710Sstevel@tonic-gate * \123 style strings are collapsed into a single character
720Sstevel@tonic-gate * \000 gets mapped into \N for further processing downline.
730Sstevel@tonic-gate * \ at end of string is removed
740Sstevel@tonic-gate * \t gets replaced by a tab
750Sstevel@tonic-gate * \n gets replaced by a newline
760Sstevel@tonic-gate * \r gets replaced by a carriage return
770Sstevel@tonic-gate * \b gets replaced by a backspace
78132Srobinson * \s gets replaced by a blank
790Sstevel@tonic-gate * any other unknown \ sequence is left intact for further processing
800Sstevel@tonic-gate * downline.
810Sstevel@tonic-gate */
820Sstevel@tonic-gate
83132Srobinson static void
bsfix(char ** args)84132Srobinson bsfix(char **args)
850Sstevel@tonic-gate {
86132Srobinson char *str, *to, *cp;
87132Srobinson int num;
880Sstevel@tonic-gate
890Sstevel@tonic-gate for (; *args; args++) {
900Sstevel@tonic-gate str = *args;
910Sstevel@tonic-gate for (to = str; *str; str++) {
920Sstevel@tonic-gate if (*str == '\\') {
930Sstevel@tonic-gate if (str[1] == '\0')
940Sstevel@tonic-gate break;
950Sstevel@tonic-gate switch (*++str) {
960Sstevel@tonic-gate case '0':
970Sstevel@tonic-gate case '1':
980Sstevel@tonic-gate case '2':
990Sstevel@tonic-gate case '3':
1000Sstevel@tonic-gate case '4':
1010Sstevel@tonic-gate case '5':
1020Sstevel@tonic-gate case '6':
1030Sstevel@tonic-gate case '7':
104132Srobinson for (num = 0, cp = str;
105132Srobinson cp - str < 3; cp++) {
1060Sstevel@tonic-gate if ('0' <= *cp && *cp <= '7') {
1070Sstevel@tonic-gate num <<= 3;
1080Sstevel@tonic-gate num += *cp - '0';
109132Srobinson } else
1100Sstevel@tonic-gate break;
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate if (num == 0) {
1130Sstevel@tonic-gate *to++ = '\\';
1140Sstevel@tonic-gate *to++ = 'N';
1150Sstevel@tonic-gate } else
116132Srobinson *to++ = (char)num;
1170Sstevel@tonic-gate str = cp-1;
1180Sstevel@tonic-gate break;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate case 't':
1210Sstevel@tonic-gate *to++ = '\t';
1220Sstevel@tonic-gate break;
1230Sstevel@tonic-gate
124132Srobinson case 's':
1250Sstevel@tonic-gate *to++ = ' ';
1260Sstevel@tonic-gate break;
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate case 'n':
1290Sstevel@tonic-gate *to++ = '\n';
1300Sstevel@tonic-gate break;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate case 'r':
1330Sstevel@tonic-gate *to++ = '\r';
1340Sstevel@tonic-gate break;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate case 'b':
1370Sstevel@tonic-gate *to++ = '\b';
1380Sstevel@tonic-gate break;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate default:
1410Sstevel@tonic-gate *to++ = '\\';
1420Sstevel@tonic-gate *to++ = *str;
1430Sstevel@tonic-gate break;
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate else
1470Sstevel@tonic-gate *to++ = *str;
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate *to = '\0';
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate }
152