1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27*0Sstevel@tonic-gate /* All Rights Reserved */
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include <unistd.h>
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <stdio.h>
36*0Sstevel@tonic-gate #include <ctype.h>
37*0Sstevel@tonic-gate #include <string.h>
38*0Sstevel@tonic-gate #include <sys/types.h>
39*0Sstevel@tonic-gate #include <sys/stat.h>
40*0Sstevel@tonic-gate #include <termio.h>
41*0Sstevel@tonic-gate #include <sys/stermio.h>
42*0Sstevel@tonic-gate #include <sys/termiox.h>
43*0Sstevel@tonic-gate #include "ttymon.h"
44*0Sstevel@tonic-gate #include "tmstruct.h"
45*0Sstevel@tonic-gate #include "tmextern.h"
46*0Sstevel@tonic-gate #include "stty.h"
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate static void insert_def();
49*0Sstevel@tonic-gate static void zero();
50*0Sstevel@tonic-gate int check_flags();
51*0Sstevel@tonic-gate void mkargv();
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate extern struct Gdef Gdef[];
54*0Sstevel@tonic-gate extern int Ndefs;
55*0Sstevel@tonic-gate char *strsave();
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate /*
58*0Sstevel@tonic-gate * read_ttydefs - read in the /etc/ttydefs and store in Gdef array
59*0Sstevel@tonic-gate * - if id is not NULL, only get entry with that id
60*0Sstevel@tonic-gate * - if check is TRUE, print out the entries
61*0Sstevel@tonic-gate */
62*0Sstevel@tonic-gate void
read_ttydefs(id,check)63*0Sstevel@tonic-gate read_ttydefs(id,check)
64*0Sstevel@tonic-gate char *id;
65*0Sstevel@tonic-gate int check;
66*0Sstevel@tonic-gate {
67*0Sstevel@tonic-gate FILE *fp;
68*0Sstevel@tonic-gate static struct Gdef def;
69*0Sstevel@tonic-gate register struct Gdef *gptr;
70*0Sstevel@tonic-gate static char line[BUFSIZ];
71*0Sstevel@tonic-gate static char dbuf[BUFSIZ];
72*0Sstevel@tonic-gate register char *ptr;
73*0Sstevel@tonic-gate int len;
74*0Sstevel@tonic-gate int input,state,size,rawc,field;
75*0Sstevel@tonic-gate char oldc;
76*0Sstevel@tonic-gate static char d_id[MAXID+1],
77*0Sstevel@tonic-gate d_nextid[MAXID+1],
78*0Sstevel@tonic-gate d_autobaud[MAXID+1],
79*0Sstevel@tonic-gate d_if[BUFSIZ],
80*0Sstevel@tonic-gate d_ff[BUFSIZ];
81*0Sstevel@tonic-gate static char *states[] = {
82*0Sstevel@tonic-gate "","tty label","Initial flags","Final flags","Autobaud","Next label"
83*0Sstevel@tonic-gate };
84*0Sstevel@tonic-gate extern char *getword();
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate if ((fp = fopen(TTYDEFS,"r")) == NULL) {
87*0Sstevel@tonic-gate log("can't open \"%s\".\n", TTYDEFS);
88*0Sstevel@tonic-gate return;
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate if (check) {
92*0Sstevel@tonic-gate for (len = 0; len < (size_t)(BUFSIZ - 1); len++)
93*0Sstevel@tonic-gate dbuf[len] = '-';
94*0Sstevel@tonic-gate dbuf[len] = '\0';
95*0Sstevel@tonic-gate }
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate /* Start searching for the line with the proper "id". */
98*0Sstevel@tonic-gate input = ACTIVE;
99*0Sstevel@tonic-gate do {
100*0Sstevel@tonic-gate line[0] = '\0';
101*0Sstevel@tonic-gate for (ptr= line,oldc = '\0'; ptr < &line[sizeof(line)-1] &&
102*0Sstevel@tonic-gate (rawc=getc(fp))!='\n' && rawc != EOF; ptr++,oldc=(char)rawc){
103*0Sstevel@tonic-gate if ((rawc == '#') && (oldc != '\\'))
104*0Sstevel@tonic-gate break;
105*0Sstevel@tonic-gate *ptr = (char)rawc;
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate *ptr = '\0';
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate /* skip rest of the line */
110*0Sstevel@tonic-gate if (rawc != EOF && rawc != '\n') {
111*0Sstevel@tonic-gate if (check && rawc != '#')
112*0Sstevel@tonic-gate log("Entry too long.");
113*0Sstevel@tonic-gate while ((rawc = getc(fp)) != EOF && rawc != '\n')
114*0Sstevel@tonic-gate ;
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate if (rawc == EOF) {
118*0Sstevel@tonic-gate if (ptr == line) break;
119*0Sstevel@tonic-gate else input = FINISHED;
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate /* if empty line, skip */
123*0Sstevel@tonic-gate for (ptr=line; *ptr != '\0' && isspace(*ptr); ptr++)
124*0Sstevel@tonic-gate ;
125*0Sstevel@tonic-gate if (*ptr == '\0') continue;
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate /* Now we have the complete line */
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate /* Initialize "def" and "gptr". */
130*0Sstevel@tonic-gate gptr = &def;
131*0Sstevel@tonic-gate zero((char *)gptr, sizeof(struct Gdef));
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate ptr = line;
134*0Sstevel@tonic-gate state = T_TTYLABEL;
135*0Sstevel@tonic-gate (void)strncpy(d_id,getword(ptr,&size,0),MAXID);
136*0Sstevel@tonic-gate gptr->g_id = d_id;
137*0Sstevel@tonic-gate ptr += size;
138*0Sstevel@tonic-gate if (*ptr != ':') {
139*0Sstevel@tonic-gate field = state;
140*0Sstevel@tonic-gate state = FAILURE;
141*0Sstevel@tonic-gate } else {
142*0Sstevel@tonic-gate ptr++; /* Skip the ':' */
143*0Sstevel@tonic-gate state++ ;
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate /* If "id" != NULL, and it does not match, go to next entry */
147*0Sstevel@tonic-gate if ((id != NULL) && (strcmp(id,gptr->g_id) != 0))
148*0Sstevel@tonic-gate continue;
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate if (check) {
151*0Sstevel@tonic-gate len = strlen(line);
152*0Sstevel@tonic-gate dbuf[len] = '\0';
153*0Sstevel@tonic-gate log("\n%s", dbuf);
154*0Sstevel@tonic-gate log("%s", line);
155*0Sstevel@tonic-gate log("%s\n", dbuf);
156*0Sstevel@tonic-gate dbuf[len] = '-';
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate for (; state != FAILURE && state != SUCCESS;) {
161*0Sstevel@tonic-gate switch(state) {
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate case T_IFLAGS:
164*0Sstevel@tonic-gate (void)strncpy(d_if,getword(ptr,&size,1),BUFSIZ);
165*0Sstevel@tonic-gate gptr->g_iflags = d_if;
166*0Sstevel@tonic-gate ptr += size;
167*0Sstevel@tonic-gate if ((*ptr != ':') || (check_flags(d_if) != 0)) {
168*0Sstevel@tonic-gate field = state;
169*0Sstevel@tonic-gate state = FAILURE;
170*0Sstevel@tonic-gate } else {
171*0Sstevel@tonic-gate ptr++;
172*0Sstevel@tonic-gate state++ ;
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate break;
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate case T_FFLAGS:
177*0Sstevel@tonic-gate (void)strncpy(d_ff,getword(ptr,&size,1),BUFSIZ);
178*0Sstevel@tonic-gate gptr->g_fflags = d_ff;
179*0Sstevel@tonic-gate ptr += size;
180*0Sstevel@tonic-gate if ((*ptr != ':') || (check_flags(d_ff) != 0)) {
181*0Sstevel@tonic-gate field = state;
182*0Sstevel@tonic-gate state = FAILURE;
183*0Sstevel@tonic-gate } else {
184*0Sstevel@tonic-gate ptr++;
185*0Sstevel@tonic-gate state++ ;
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate break;
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate case T_AUTOBAUD:
190*0Sstevel@tonic-gate (void)strncpy(d_autobaud,getword(ptr,&size,0),MAXID);
191*0Sstevel@tonic-gate if (size > 1) {
192*0Sstevel@tonic-gate ptr += size;
193*0Sstevel@tonic-gate field = state;
194*0Sstevel@tonic-gate state = FAILURE;
195*0Sstevel@tonic-gate break;
196*0Sstevel@tonic-gate }
197*0Sstevel@tonic-gate if (size == 1) {
198*0Sstevel@tonic-gate if (*d_autobaud == 'A')
199*0Sstevel@tonic-gate gptr->g_autobaud |= A_FLAG;
200*0Sstevel@tonic-gate else {
201*0Sstevel@tonic-gate ptr += size;
202*0Sstevel@tonic-gate field = state;
203*0Sstevel@tonic-gate state = FAILURE;
204*0Sstevel@tonic-gate break;
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate ptr += size;
208*0Sstevel@tonic-gate if (*ptr != ':') {
209*0Sstevel@tonic-gate field = state;
210*0Sstevel@tonic-gate state = FAILURE;
211*0Sstevel@tonic-gate } else {
212*0Sstevel@tonic-gate ptr++; /* Skip the ':' */
213*0Sstevel@tonic-gate state++ ;
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate break;
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate case T_NEXTLABEL:
218*0Sstevel@tonic-gate (void)strncpy(d_nextid,getword(ptr,&size,0),MAXID);
219*0Sstevel@tonic-gate gptr->g_nextid = d_nextid;
220*0Sstevel@tonic-gate ptr += size;
221*0Sstevel@tonic-gate if (*ptr != '\0') {
222*0Sstevel@tonic-gate field = state;
223*0Sstevel@tonic-gate state = FAILURE;
224*0Sstevel@tonic-gate } else state = SUCCESS;
225*0Sstevel@tonic-gate break;
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate } /* end switch */
228*0Sstevel@tonic-gate } /* end for loop */
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate if (state == SUCCESS) {
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate if (check) {
233*0Sstevel@tonic-gate log("ttylabel:\t%s", gptr->g_id);
234*0Sstevel@tonic-gate log("initial flags:\t%s", gptr->g_iflags);
235*0Sstevel@tonic-gate log("final flags:\t%s", gptr->g_fflags);
236*0Sstevel@tonic-gate if (gptr->g_autobaud & A_FLAG)
237*0Sstevel@tonic-gate log("autobaud:\tyes");
238*0Sstevel@tonic-gate else
239*0Sstevel@tonic-gate log("autobaud:\tno");
240*0Sstevel@tonic-gate log("nextlabel:\t%s", gptr->g_nextid);
241*0Sstevel@tonic-gate }
242*0Sstevel@tonic-gate if (Ndefs < MAXDEFS)
243*0Sstevel@tonic-gate insert_def(gptr);
244*0Sstevel@tonic-gate else {
245*0Sstevel@tonic-gate log("can't add more entries to ttydefs table, "
246*0Sstevel@tonic-gate " Maximum entries = %d", MAXDEFS);
247*0Sstevel@tonic-gate (void)fclose(fp);
248*0Sstevel@tonic-gate return;
249*0Sstevel@tonic-gate }
250*0Sstevel@tonic-gate if (id != NULL) {
251*0Sstevel@tonic-gate return;
252*0Sstevel@tonic-gate }
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate else {
255*0Sstevel@tonic-gate *++ptr = '\0';
256*0Sstevel@tonic-gate log("Parsing failure in the \"%s\" field\n"
257*0Sstevel@tonic-gate "%s<--error detected here\n", states[field],line);
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate } while (input == ACTIVE);
260*0Sstevel@tonic-gate (void)fclose(fp);
261*0Sstevel@tonic-gate return;
262*0Sstevel@tonic-gate }
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate /*
265*0Sstevel@tonic-gate * zero - zero out the buffer
266*0Sstevel@tonic-gate */
267*0Sstevel@tonic-gate static void
zero(adr,size)268*0Sstevel@tonic-gate zero(adr,size)
269*0Sstevel@tonic-gate register char *adr;
270*0Sstevel@tonic-gate register int size;
271*0Sstevel@tonic-gate {
272*0Sstevel@tonic-gate if (adr != NULL)
273*0Sstevel@tonic-gate while (size--) *adr++ = '\0';
274*0Sstevel@tonic-gate }
275*0Sstevel@tonic-gate
276*0Sstevel@tonic-gate /*
277*0Sstevel@tonic-gate * find_def(ttylabel)
278*0Sstevel@tonic-gate * - scan Gdef table for an entry with requested "ttylabel".
279*0Sstevel@tonic-gate * - return a Gdef ptr if entry with "ttylabel" is found
280*0Sstevel@tonic-gate * - return NULL if no entry with matching "ttylabel"
281*0Sstevel@tonic-gate */
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate struct Gdef *
find_def(ttylabel)284*0Sstevel@tonic-gate find_def(ttylabel)
285*0Sstevel@tonic-gate char *ttylabel;
286*0Sstevel@tonic-gate {
287*0Sstevel@tonic-gate int i;
288*0Sstevel@tonic-gate struct Gdef *tp;
289*0Sstevel@tonic-gate tp = &Gdef[0];
290*0Sstevel@tonic-gate for (i = 0; i < Ndefs; i++,tp++) {
291*0Sstevel@tonic-gate if (strcmp(ttylabel, tp->g_id) == 0) {
292*0Sstevel@tonic-gate return(tp);
293*0Sstevel@tonic-gate }
294*0Sstevel@tonic-gate }
295*0Sstevel@tonic-gate return(NULL);
296*0Sstevel@tonic-gate }
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate /*
299*0Sstevel@tonic-gate * check_flags - check to see if the flags contains options that are
300*0Sstevel@tonic-gate * recognizable by stty
301*0Sstevel@tonic-gate * - return 0 if no error. Otherwise return -1
302*0Sstevel@tonic-gate */
303*0Sstevel@tonic-gate int
check_flags(flags)304*0Sstevel@tonic-gate check_flags(flags)
305*0Sstevel@tonic-gate char *flags;
306*0Sstevel@tonic-gate {
307*0Sstevel@tonic-gate struct termio termio;
308*0Sstevel@tonic-gate struct termios termios;
309*0Sstevel@tonic-gate struct termiox termiox;
310*0Sstevel@tonic-gate struct winsize winsize;
311*0Sstevel@tonic-gate int term;
312*0Sstevel@tonic-gate int cnt = 1;
313*0Sstevel@tonic-gate char *argvp[MAXARGS]; /* stty args */
314*0Sstevel@tonic-gate static char *binstty = "/usr/bin/stty";
315*0Sstevel@tonic-gate static char buf[BUFSIZ];
316*0Sstevel@tonic-gate extern char *sttyparse();
317*0Sstevel@tonic-gate char *s_arg; /* this will point to invalid option */
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate /* put flags into buf, because strtok will break up buffer */
320*0Sstevel@tonic-gate (void)strcpy(buf,flags);
321*0Sstevel@tonic-gate argvp[0] = binstty; /* just a place holder */
322*0Sstevel@tonic-gate mkargv(buf,&argvp[1],&cnt,MAXARGS-1);
323*0Sstevel@tonic-gate argvp[cnt] = (char *)0;
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate /*
326*0Sstevel@tonic-gate * because we don't know what type of terminal we have now,
327*0Sstevel@tonic-gate * just set term = everything, so all possible stty options
328*0Sstevel@tonic-gate * are accepted
329*0Sstevel@tonic-gate */
330*0Sstevel@tonic-gate term = ASYNC|TERMIOS|FLOW;
331*0Sstevel@tonic-gate if ((s_arg = sttyparse(cnt, argvp, term, &termio, &termios,
332*0Sstevel@tonic-gate &termiox, &winsize)) != NULL) {
333*0Sstevel@tonic-gate log("invalid mode: %s", s_arg);
334*0Sstevel@tonic-gate return(-1);
335*0Sstevel@tonic-gate }
336*0Sstevel@tonic-gate return(0);
337*0Sstevel@tonic-gate }
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate /*
340*0Sstevel@tonic-gate * insert_def - insert one entry into Gdef table
341*0Sstevel@tonic-gate */
342*0Sstevel@tonic-gate static void
insert_def(gptr)343*0Sstevel@tonic-gate insert_def(gptr)
344*0Sstevel@tonic-gate struct Gdef *gptr;
345*0Sstevel@tonic-gate {
346*0Sstevel@tonic-gate struct Gdef *tp;
347*0Sstevel@tonic-gate extern struct Gdef *find_def();
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate if (find_def(gptr->g_id) != NULL) {
350*0Sstevel@tonic-gate log("Warning -- duplicate entry <%s>, ignored", gptr->g_id);
351*0Sstevel@tonic-gate return;
352*0Sstevel@tonic-gate }
353*0Sstevel@tonic-gate tp = &Gdef[Ndefs];
354*0Sstevel@tonic-gate tp->g_id = strsave(gptr->g_id);
355*0Sstevel@tonic-gate tp->g_iflags = strsave(gptr->g_iflags);
356*0Sstevel@tonic-gate tp->g_fflags = strsave(gptr->g_fflags);
357*0Sstevel@tonic-gate tp->g_autobaud = gptr->g_autobaud;
358*0Sstevel@tonic-gate tp->g_nextid = strsave(gptr->g_nextid);
359*0Sstevel@tonic-gate Ndefs++;
360*0Sstevel@tonic-gate return;
361*0Sstevel@tonic-gate }
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate /*
364*0Sstevel@tonic-gate * mkargv - parse the string into args, starting from args[cnt]
365*0Sstevel@tonic-gate */
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate void
mkargv(string,args,cnt,maxargs)368*0Sstevel@tonic-gate mkargv(string,args,cnt,maxargs)
369*0Sstevel@tonic-gate char *string, **args;
370*0Sstevel@tonic-gate int *cnt, maxargs;
371*0Sstevel@tonic-gate {
372*0Sstevel@tonic-gate register char *ptrin,*ptrout;
373*0Sstevel@tonic-gate register int i;
374*0Sstevel@tonic-gate int qsize;
375*0Sstevel@tonic-gate extern char quoted();
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gate for (i=0; i < maxargs; i++) args[i] = (char *)NULL;
378*0Sstevel@tonic-gate for (ptrin = ptrout = string,i=0; *ptrin != '\0' && i < maxargs; i++) {
379*0Sstevel@tonic-gate /* Skip excess white spaces between arguments. */
380*0Sstevel@tonic-gate while(*ptrin == ' ' || *ptrin == '\t') {
381*0Sstevel@tonic-gate ptrin++;
382*0Sstevel@tonic-gate ptrout++;
383*0Sstevel@tonic-gate }
384*0Sstevel@tonic-gate /* Save the address of argument if there is something there. */
385*0Sstevel@tonic-gate if (*ptrin == '\0') break;
386*0Sstevel@tonic-gate else args[i] = ptrout;
387*0Sstevel@tonic-gate
388*0Sstevel@tonic-gate /* Span the argument itself. The '\' character causes quoting */
389*0Sstevel@tonic-gate /* of the next character to take place (except for '\0'). */
390*0Sstevel@tonic-gate while (*ptrin != '\0') {
391*0Sstevel@tonic-gate if (*ptrin == '\\') {
392*0Sstevel@tonic-gate *ptrout++ = quoted(ptrin,&qsize);
393*0Sstevel@tonic-gate ptrin += qsize;
394*0Sstevel@tonic-gate
395*0Sstevel@tonic-gate /* Is this the end of the argument? If so quit loop. */
396*0Sstevel@tonic-gate } else if (*ptrin == ' ' || *ptrin == '\t') {
397*0Sstevel@tonic-gate ptrin++;
398*0Sstevel@tonic-gate break;
399*0Sstevel@tonic-gate
400*0Sstevel@tonic-gate /* If this is a normal letter of the argument, save it, advancing */
401*0Sstevel@tonic-gate /* the pointers at the same time. */
402*0Sstevel@tonic-gate } else *ptrout++ = *ptrin++;
403*0Sstevel@tonic-gate }
404*0Sstevel@tonic-gate /* Null terminate the string. */
405*0Sstevel@tonic-gate *ptrout++ = '\0';
406*0Sstevel@tonic-gate }
407*0Sstevel@tonic-gate (*cnt) += i;
408*0Sstevel@tonic-gate }
409*0Sstevel@tonic-gate
410*0Sstevel@tonic-gate #ifdef DEBUG
411*0Sstevel@tonic-gate /*
412*0Sstevel@tonic-gate * dump_ttydefs - dump Gdef table to log file
413*0Sstevel@tonic-gate */
414*0Sstevel@tonic-gate void
dump_ttydefs()415*0Sstevel@tonic-gate dump_ttydefs()
416*0Sstevel@tonic-gate {
417*0Sstevel@tonic-gate int i;
418*0Sstevel@tonic-gate struct Gdef *gptr;
419*0Sstevel@tonic-gate gptr = &Gdef[0];
420*0Sstevel@tonic-gate log("********** dumping ttydefs table **********");
421*0Sstevel@tonic-gate log("Ndefs = %d", Ndefs);
422*0Sstevel@tonic-gate log(" ");
423*0Sstevel@tonic-gate for (i = 0; i < Ndefs; i++,gptr++) {
424*0Sstevel@tonic-gate log("----------------------------------------");
425*0Sstevel@tonic-gate log("ttylabel:\t%s", gptr->g_id);
426*0Sstevel@tonic-gate log("initial flags:\t%s", gptr->g_iflags);
427*0Sstevel@tonic-gate log("final flags:\t%s", gptr->g_fflags);
428*0Sstevel@tonic-gate if (gptr->g_autobaud & A_FLAG)
429*0Sstevel@tonic-gate log("autobaud:\tyes");
430*0Sstevel@tonic-gate else
431*0Sstevel@tonic-gate log("Autobaud:\tno");
432*0Sstevel@tonic-gate log("nextlabel:\t%s", gptr->g_nextid);
433*0Sstevel@tonic-gate log(" ");
434*0Sstevel@tonic-gate }
435*0Sstevel@tonic-gate log("********** end dumping ttydefs table **********");
436*0Sstevel@tonic-gate return;
437*0Sstevel@tonic-gate }
438*0Sstevel@tonic-gate #endif
439*0Sstevel@tonic-gate
440*0Sstevel@tonic-gate
441*0Sstevel@tonic-gate /*
442*0Sstevel@tonic-gate * this is copies from uucp/strsave.c
443*0Sstevel@tonic-gate * and is modified that if malloc fails, it will exit
444*0Sstevel@tonic-gate */
445*0Sstevel@tonic-gate char *
strsave(str)446*0Sstevel@tonic-gate strsave(str)
447*0Sstevel@tonic-gate register char *str;
448*0Sstevel@tonic-gate {
449*0Sstevel@tonic-gate register char *rval;
450*0Sstevel@tonic-gate
451*0Sstevel@tonic-gate if (str == NULL) {
452*0Sstevel@tonic-gate if ((rval = (char *)malloc(1)) == NULL) {
453*0Sstevel@tonic-gate log("strsave: malloc failed");
454*0Sstevel@tonic-gate exit(1);
455*0Sstevel@tonic-gate }
456*0Sstevel@tonic-gate *rval = '\0';
457*0Sstevel@tonic-gate }
458*0Sstevel@tonic-gate else {
459*0Sstevel@tonic-gate if ((rval = (char *)malloc(strlen(str) + 1)) == NULL) {
460*0Sstevel@tonic-gate log("strsave: malloc failed");
461*0Sstevel@tonic-gate exit(1);
462*0Sstevel@tonic-gate }
463*0Sstevel@tonic-gate (void)strcpy(rval, str);
464*0Sstevel@tonic-gate }
465*0Sstevel@tonic-gate return(rval);
466*0Sstevel@tonic-gate }
467