Deleted Added
full compact
uudecode.c (29574) uudecode.c (32780)
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

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
43#endif
44static const char rcsid[] =
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

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
43#endif
44static const char rcsid[] =
45 "$Id: uudecode.c,v 1.9 1997/08/22 06:51:43 charnier Exp $";
45 "$Id: uudecode.c,v 1.10 1997/09/18 14:07:26 phk Exp $";
46#endif /* not lint */
47
48/*
49 * uudecode [file ...]
50 *
51 * create the specified file, decoding as you go.
52 * used with uuencode.
53 */

--- 4 unchanged lines hidden (view full) ---

58#include <fnmatch.h>
59#include <pwd.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65char *filename;
46#endif /* not lint */
47
48/*
49 * uudecode [file ...]
50 *
51 * create the specified file, decoding as you go.
52 * used with uuencode.
53 */

--- 4 unchanged lines hidden (view full) ---

58#include <fnmatch.h>
59#include <pwd.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65char *filename;
66int cflag, pflag;
66int cflag, iflag, pflag, sflag;
67
68static void usage __P((void));
69int decode __P((void));
70int decode2 __P((int));
71
72int
73main(argc, argv)
74 int argc;
75 char *argv[];
76{
77 int rval, ch;
78
67
68static void usage __P((void));
69int decode __P((void));
70int decode2 __P((int));
71
72int
73main(argc, argv)
74 int argc;
75 char *argv[];
76{
77 int rval, ch;
78
79 while ((ch = getopt(argc, argv, "cp")) != -1) {
79 while ((ch = getopt(argc, argv, "cips")) != -1) {
80 switch(ch) {
81 case 'c':
82 cflag = 1; /* multiple uudecode'd files */
83 break;
80 switch(ch) {
81 case 'c':
82 cflag = 1; /* multiple uudecode'd files */
83 break;
84 case 'i':
85 iflag = 1; /* ask before override files */
86 break;
84 case 'p':
85 pflag = 1; /* print output to stdout */
86 break;
87 case 'p':
88 pflag = 1; /* print output to stdout */
89 break;
90 case 's':
91 sflag = 1; /* do not strip pathnames for output */
92 break;
87 default:
88 usage();
89 }
90 }
91 argc -= optind;
92 argv += optind;
93
94

--- 34 unchanged lines hidden (view full) ---

129}
130
131int
132decode2(flag)
133 int flag;
134{
135 struct passwd *pw;
136 register int n;
93 default:
94 usage();
95 }
96 }
97 argc -= optind;
98 argv += optind;
99
100

--- 34 unchanged lines hidden (view full) ---

135}
136
137int
138decode2(flag)
139 int flag;
140{
141 struct passwd *pw;
142 register int n;
137 register char ch, *p;
143 register char ch, first, *p;
138 int mode, n1;
139 char buf[MAXPATHLEN];
140 char buffn[MAXPATHLEN]; /* file name buffer */
141
142
143 /* search for header line */
144 do {
145 if (!fgets(buf, sizeof(buf), stdin)) {
146 if (flag) /* no error */
147 return(0);
148
149 warnx("%s: no \"begin\" line", filename);
150 return(1);
151 }
152 } while (strncmp(buf, "begin ", 6) ||
153 fnmatch("begin [0-7]* *", buf, 0));
154
155 (void)sscanf(buf, "begin %o %s", &mode, buf);
156
144 int mode, n1;
145 char buf[MAXPATHLEN];
146 char buffn[MAXPATHLEN]; /* file name buffer */
147
148
149 /* search for header line */
150 do {
151 if (!fgets(buf, sizeof(buf), stdin)) {
152 if (flag) /* no error */
153 return(0);
154
155 warnx("%s: no \"begin\" line", filename);
156 return(1);
157 }
158 } while (strncmp(buf, "begin ", 6) ||
159 fnmatch("begin [0-7]* *", buf, 0));
160
161 (void)sscanf(buf, "begin %o %s", &mode, buf);
162
163 if (!sflag && !pflag) {
164 strncpy(buffn, buf, sizeof(buffn));
165 if (strrchr(buffn, '/') != NULL)
166 strncpy(buf, strrchr(buffn, '/') + 1, sizeof(buf));
167 if (buf[0] == '\0') {
168 warnx("%s: illegal filename", buffn);
169 return(1);
170 }
171 }
172
157 /* handle ~user/file format */
158 if (buf[0] == '~') {
159 if (!(p = index(buf, '/'))) {
160 warnx("%s: illegal ~user", filename);
161 return(1);
162 }
163 *p++ = '\0';
164 if (!(pw = getpwnam(buf + 1))) {

--- 10 unchanged lines hidden (view full) ---

175 bcopy(pw->pw_dir, buf, n);
176 buf[n] = '/';
177 }
178
179 /* create output file, set mode */
180 if (pflag)
181 ; /* print to stdout */
182
173 /* handle ~user/file format */
174 if (buf[0] == '~') {
175 if (!(p = index(buf, '/'))) {
176 warnx("%s: illegal ~user", filename);
177 return(1);
178 }
179 *p++ = '\0';
180 if (!(pw = getpwnam(buf + 1))) {

--- 10 unchanged lines hidden (view full) ---

191 bcopy(pw->pw_dir, buf, n);
192 buf[n] = '/';
193 }
194
195 /* create output file, set mode */
196 if (pflag)
197 ; /* print to stdout */
198
183 else if (!freopen(buf, "w", stdout) ||
184 fchmod(fileno(stdout), mode&0666)) {
185 warn("%s: %s", buf, filename);
186 return(1);
199 else {
200 if (iflag && !access(buf, F_OK))
201 (void)fprintf(stderr, "not overwritten: %s\n", buf);
202 if (!freopen(buf, "w", stdout) ||
203 fchmod(fileno(stdout), mode&0666)) {
204 warn("%s: %s", buf, filename);
205 return(1);
206 }
187 }
188 strcpy(buffn, buf); /* store file name from header line */
189
190 /* for each input line */
191 for (;;) {
192 if (!fgets(p = buf, sizeof(buf), stdin)) {
193 warnx("%s: short file", filename);
194 return(1);

--- 62 unchanged lines hidden (view full) ---

257 return(1);
258 }
259 return(0);
260}
261
262static void
263usage()
264{
207 }
208 strcpy(buffn, buf); /* store file name from header line */
209
210 /* for each input line */
211 for (;;) {
212 if (!fgets(p = buf, sizeof(buf), stdin)) {
213 warnx("%s: short file", filename);
214 return(1);

--- 62 unchanged lines hidden (view full) ---

277 return(1);
278 }
279 return(0);
280}
281
282static void
283usage()
284{
265 (void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n");
285 (void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
266 exit(1);
267}
286 exit(1);
287}