Deleted Added
sdiff udiff text old ( 29574 ) new ( 32780 )
full compact
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 $";
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;
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) {
80 switch(ch) {
81 case 'c':
82 cflag = 1; /* multiple uudecode'd files */
83 break;
84 case 'p':
85 pflag = 1; /* print output to stdout */
86 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;
137 register char ch, *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
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
183 else if (!freopen(buf, "w", stdout) ||
184 fchmod(fileno(stdout), mode&0666)) {
185 warn("%s: %s", buf, filename);
186 return(1);
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{
265 (void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n");
266 exit(1);
267}