unshar re-revisited (for V7 /bin/sh # causes errors)
Stephen C. Woods
scw at cepu.UUCP
Thu Feb 7 06:18:10 AEST 1985
Here are context diffs from the most recient posting of unshar.c to
allow V7 systems to not have problems with # comment lines.
The V7 Bourne shell doesn't accept '#' as a valid comment, this patch
avoids problems like:
sh: #: not found
or
sh: syntax error in line 34, unexpected '('
when the shell sees a line like
# or contact (213) 824-4448 if you have any problems
------------------cut here-----------------------
*** unshar.c.B Wed Feb 6 09:45:49 1985
--- unshar.c Wed Feb 6 11:30:45 1985
***************
*** 1,7
/****************************************************************
* unshar.c: Unpackage one or more shell archive files
*
! * Usage: unshar [ -d directory ] [ file ] ...
*
* Description: unshar is a filter which removes the front part
* of a file and passes the rest to the 'sh' command.
--- 1,7 -----
/****************************************************************
* unshar.c: Unpackage one or more shell archive files
*
! * Usage: unshar [-c] [-d directory ] [ file ] ...
*
* Description: unshar is a filter which removes the front part
* of a file and passes the rest to the 'sh' command.
***************
*** 10,15
* commands "echo", "cat", and "sed".
*
* HISTORY
* 1-Feb-85 Guido van Rossum (guido at mcvax) at CWI, Amsterdam
* Added missing 'quit' routine;
* added -d flag to change to directory first;
--- 10,18 -----
* commands "echo", "cat", and "sed".
*
* HISTORY
+ * 6-Feb-85 Stephen C. Woods (scw at cepu) Los Angeles CA
+ * fixed '#' for v7 flavor systems (sh dosen't know about # comments)
+ * added -c flag to allow echo of skipped #comments
* 1-Feb-85 Guido van Rossum (guido at mcvax) at CWI, Amsterdam
* Added missing 'quit' routine;
* added -d flag to change to directory first;
***************
*** 25,30
extern char *optarg;
extern int optind;
main (argc, argv)
int argc;
char *argv[];
--- 28,35 -----
extern char *optarg;
extern int optind;
+ int cflag=0;
+
main (argc, argv)
int argc;
char *argv[];
***************
*** 33,39
/* Process options */
! while ((ch = getopt (argc, argv, "d:")) != EOF) {
switch (ch) {
case 'd':
if (chdir (optarg) == -1) {
--- 38,44 -----
/* Process options */
! while ((ch = getopt (argc, argv, "c d:")) != EOF) {
switch (ch) {
case 'd':
if (chdir (optarg) == -1) {
***************
*** 41,46
exit(2);
}
break;
default:
quit (2, "Usage: unshar [-d directory] [file] ...\n");
}
--- 46,54 -----
exit(2);
}
break;
+ case 'c':
+ cflag++;
+ if(cflag == 1)break;
default:
quit (2, "Usage: unshar [-c] [-d directory] [file] ...\n");
}
***************
*** 42,48
}
break;
default:
! quit (2, "Usage: unshar [-d directory] [file] ...\n");
}
}
--- 50,56 -----
cflag++;
if(cflag == 1)break;
default:
! quit (2, "Usage: unshar [-c] [-d directory] [file] ...\n");
}
}
***************
*** 67,72
char *name;
FILE *in;
{ char ch;
FILE *shpr, *popen();
if (position (name, in))
--- 75,81 -----
char *name;
FILE *in;
{ char ch;
+ int inline,comment;
FILE *shpr, *popen();
if (position (name, in))
***************
*** 71,76
if (position (name, in))
{ printf ("%s:\n", name);
if ((shpr = popen ("sh", "w")) == NULL)
quit (1, "unshar: cannot open 'sh' process\n");
--- 80,108 -----
if (position (name, in))
{ printf ("%s:\n", name);
+ #ifdef V7
+ ch=fgetc(in);
+
+ if( (inline=comment= (ch == '#'))){
+ fprintf(stderr," skipping comments\n");
+ if(cflag)fputc(ch,stderr);
+ do{
+ ch=fgetc(in);
+ if(ch == EOF){
+ fprintf(stderr,"file was all comments, nothing extracted\n");
+ return;
+ }
+ if(inline){
+ inline= ch != '\n';
+ }
+ else{
+ inline=comment= (ch == '#');
+ }
+ if(comment && cflag)fputc(ch,stderr);
+ }while(comment);
+ }
+ ungetc(ch,in);
+ #endif V7
if ((shpr = popen ("sh", "w")) == NULL)
quit (1, "unshar: cannot open 'sh' process\n");
--
Stephen C. Woods (VA Wadsworth Med Ctr./UCLA Dept. of Neurology)
uucp: { {ihnp4, uiucdcs}!bradley, hao, trwrb}!cepu!scw
ARPA: cepu!scw at ucla-cs location: N 34 3' 9.1" W 118 27' 4.3"
More information about the Comp.sources.unix
mailing list