subr.c (22989) | subr.c (25709) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 19 unchanged lines hidden (view full) --- 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 19 unchanged lines hidden (view full) --- 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ |
36static char rcsid[] = "$Id$"; | 36static char rcsid[] = "$Id: subr.c,v 1.9 1997/02/22 14:21:40 peter Exp $"; |
37#endif /* not lint */ 38 39/* 40 * Melbourne getty. 41 */ 42#define COMPAT_43 43#include <stdlib.h> 44#include <unistd.h> 45#include <string.h> 46#include <termios.h> 47#include <sys/ioctl.h> 48#include <sys/param.h> | 37#endif /* not lint */ 38 39/* 40 * Melbourne getty. 41 */ 42#define COMPAT_43 43#include <stdlib.h> 44#include <unistd.h> 45#include <string.h> 46#include <termios.h> 47#include <sys/ioctl.h> 48#include <sys/param.h> |
49#include <syslog.h> |
|
49#ifdef DEBUG 50#include <stdio.h> 51#endif 52 53#include "gettytab.h" 54#include "pathnames.h" 55#include "extern.h" 56 --- 9 unchanged lines hidden (view full) --- 66gettable(name, buf) 67 const char *name; 68 char *buf; 69{ 70 register struct gettystrs *sp; 71 register struct gettynums *np; 72 register struct gettyflags *fp; 73 long n; | 50#ifdef DEBUG 51#include <stdio.h> 52#endif 53 54#include "gettytab.h" 55#include "pathnames.h" 56#include "extern.h" 57 --- 9 unchanged lines hidden (view full) --- 67gettable(name, buf) 68 const char *name; 69 char *buf; 70{ 71 register struct gettystrs *sp; 72 register struct gettynums *np; 73 register struct gettyflags *fp; 74 long n; |
75 int l; 76 char *p; 77 char *msg = NULL; |
|
74 const char *dba[2]; | 78 const char *dba[2]; |
79 80 static int firsttime = 1; 81 |
|
75 dba[0] = _PATH_GETTYTAB; 76 dba[1] = 0; 77 | 82 dba[0] = _PATH_GETTYTAB; 83 dba[1] = 0; 84 |
78 if (cgetent(&buf, dba, name) != 0) | 85 if (firsttime) { 86 /* 87 * we need to strdup() anything in the strings array 88 * initially in order to simplify things later 89 */ 90 for (sp = gettystrs; sp->field; sp++) 91 if (sp->value != NULL) { 92 /* handle these ones more carefully */ 93 if (sp >= &gettystrs[4] && sp <= &gettystrs[6]) 94 l = 2; 95 else 96 l = strlen(sp->value) + 1; 97 if ((p = malloc(l)) != NULL) { 98 strncpy(p, sp->value, l); 99 p[l-1] = '\0'; 100 } 101 /* 102 * replace, even if NULL, else we'll 103 * have problems with free()ing static mem 104 */ 105 sp->value = p; 106 } 107 firsttime = 0; 108 } 109 110 switch (cgetent(&buf, (char **)dba, (char *)name)) { 111 case 1: 112 msg = "%s: couldn't resolve 'tc=' in gettytab '%s'"; 113 case 0: 114 break; 115 case -1: 116 msg = "%s: unknown gettytab entry '%s'"; 117 break; 118 case -2: 119 msg = "%s: retrieving gettytab entry '%s': %m"; 120 break; 121 case -3: 122 msg = "%s: recursive 'tc=' reference gettytab entry '%s'"; 123 break; 124 default: 125 msg = "%s: unexpected cgetent() error for entry '%s'"; 126 break; 127 } 128 129 if (msg != NULL) { 130 syslog(LOG_ERR, msg, "getty", name); |
79 return; | 131 return; |
132 } |
|
80 | 133 |
81 for (sp = gettystrs; sp->field; sp++) 82 cgetstr(buf, sp->field, &sp->value); | 134 for (sp = gettystrs; sp->field; sp++) { 135 if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) { 136 if (sp->value) { 137 /* prefer existing value */ 138 if (strcmp(p, sp->value) != 0) 139 free(sp->value); 140 else { 141 free(p); 142 p = sp->value; 143 } 144 } 145 sp->value = p; 146 } else if (l == -1) { 147 free(sp->value); 148 sp->value = NULL; 149 } 150 } 151 |
83 for (np = gettynums; np->field; np++) { | 152 for (np = gettynums; np->field; np++) { |
84 if (cgetnum(buf, np->field, &n) == -1) | 153 if (cgetnum(buf, (char*)np->field, &n) == -1) |
85 np->set = 0; 86 else { 87 np->set = 1; 88 np->value = n; 89 } 90 } | 154 np->set = 0; 155 else { 156 np->set = 1; 157 np->value = n; 158 } 159 } |
160 |
|
91 for (fp = gettyflags; fp->field; fp++) { | 161 for (fp = gettyflags; fp->field; fp++) { |
92 if (cgetcap(buf, fp->field, ':') == NULL) | 162 if (cgetcap(buf, (char *)fp->field, ':') == NULL) |
93 fp->set = 0; 94 else { 95 fp->set = 1; 96 fp->value = 1 ^ fp->invrt; 97 } 98 } | 163 fp->set = 0; 164 else { 165 fp->set = 1; 166 fp->value = 1 ^ fp->invrt; 167 } 168 } |
169 |
|
99#ifdef DEBUG 100 printf("name=\"%s\", buf=\"%s\"\r\n", name, buf); 101 for (sp = gettystrs; sp->field; sp++) 102 printf("cgetstr: %s=%s\r\n", sp->field, sp->value); 103 for (np = gettynums; np->field; np++) 104 printf("cgetnum: %s=%d\r\n", np->field, np->value); 105 for (fp = gettyflags; fp->field; fp++) 106 printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, --- 5 unchanged lines hidden (view full) --- 112gendefaults() 113{ 114 register struct gettystrs *sp; 115 register struct gettynums *np; 116 register struct gettyflags *fp; 117 118 for (sp = gettystrs; sp->field; sp++) 119 if (sp->value) | 170#ifdef DEBUG 171 printf("name=\"%s\", buf=\"%s\"\r\n", name, buf); 172 for (sp = gettystrs; sp->field; sp++) 173 printf("cgetstr: %s=%s\r\n", sp->field, sp->value); 174 for (np = gettynums; np->field; np++) 175 printf("cgetnum: %s=%d\r\n", np->field, np->value); 176 for (fp = gettyflags; fp->field; fp++) 177 printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, --- 5 unchanged lines hidden (view full) --- 183gendefaults() 184{ 185 register struct gettystrs *sp; 186 register struct gettynums *np; 187 register struct gettyflags *fp; 188 189 for (sp = gettystrs; sp->field; sp++) 190 if (sp->value) |
120 sp->defalt = sp->value; | 191 sp->defalt = strdup(sp->value); |
121 for (np = gettynums; np->field; np++) 122 if (np->set) 123 np->defalt = np->value; 124 for (fp = gettyflags; fp->field; fp++) 125 if (fp->set) 126 fp->defalt = fp->value; 127 else 128 fp->defalt = fp->invrt; 129} 130 131void 132setdefaults() 133{ 134 register struct gettystrs *sp; 135 register struct gettynums *np; 136 register struct gettyflags *fp; 137 138 for (sp = gettystrs; sp->field; sp++) 139 if (!sp->value) | 192 for (np = gettynums; np->field; np++) 193 if (np->set) 194 np->defalt = np->value; 195 for (fp = gettyflags; fp->field; fp++) 196 if (fp->set) 197 fp->defalt = fp->value; 198 else 199 fp->defalt = fp->invrt; 200} 201 202void 203setdefaults() 204{ 205 register struct gettystrs *sp; 206 register struct gettynums *np; 207 register struct gettyflags *fp; 208 209 for (sp = gettystrs; sp->field; sp++) 210 if (!sp->value) |
140 sp->value = sp->defalt; | 211 sp->value = !sp->defalt ? sp->defalt 212 : strdup(sp->defalt); |
141 for (np = gettynums; np->field; np++) 142 if (!np->set) 143 np->value = np->defalt; 144 for (fp = gettyflags; fp->field; fp++) 145 if (!fp->set) 146 fp->value = fp->defalt; 147} 148 --- 633 unchanged lines hidden --- | 213 for (np = gettynums; np->field; np++) 214 if (!np->set) 215 np->value = np->defalt; 216 for (fp = gettyflags; fp->field; fp++) 217 if (!fp->set) 218 fp->value = fp->defalt; 219} 220 --- 633 unchanged lines hidden --- |