home *** CD-ROM | disk | FTP | other *** search
- From decwrl!labrea!rutgers!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery Sun Dec 11 17:12:27 PST 1988
- Article 751 of comp.sources.misc:
- Path: granite!decwrl!labrea!rutgers!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery
- From: segedy@gsg.UUCP (Catherine Segedy)
- Newsgroups: comp.sources.misc
- Subject: v05i076: map unpacker written in C (uns.c)
- Keywords: maps, program, unpacker
- Message-ID: <285@gsg.UUCP>
- Date: 8 Dec 88 00:04:56 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: segedy@gsg.UUCP (Catherine Segedy)
- Organization: General Systems Group, Inc., Salem, NH
- Lines: 119
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 5, Issue 76
- Submitted-by: "Catherine Segedy" <segedy@gsg.UUCP>
- Archive-name: uns
-
- Due to all the noise recently about the dangers of shell scripts for
- unpacking maps, I recently posted to comp.unix.wizards, news.sysadmin,
- and news.admin, describing the following program. I would have just posted
- it, but I was delayed a few days for something. Anyway, here it is. I hope
- this is helpful.
- cathy segedy, GSG
- decvax!gsg!segedy
- harvard!gsg!segedy
-
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
- #! /bin/sh
- # This file was wrapped with "dummyshar". "sh" this file to extract.
- # Contents: uns.c
- echo extracting 'uns.c'
- if test -f 'uns.c' -a -z "$1"; then echo Not overwriting 'uns.c'; else
- sed 's/^X//' << \EOF > 'uns.c'
- X/* Copyright 1988 by GSG, Salem, NH -- permission is given to copy this and
- X use it as long as it is not sold or used commercially, and as long as
- X this copyright is included with it.
- X
- X Author: Cathy Segedy
- X send comments, etc. to: decvax!gsg!segedy or
- X harvard!gsg!segedy
- X date: Dec. 7, 1988
- Xno guarantees or warranties are made, either implicitly or explicitly about the
- Xcorrectness of this program, and it is presented as is, and use at your own
- Xrisk.
- X
- Xto compile this program, (uns.c):
- X cc -o uns uns.c
- Xto use this program: (I use it this way)
- X uns mapfilename >> some_output_file
- Xthis should produce the mapfile. The output file should contain
- X a message about the opening of the input file
- X a message about removing end_of_line
- X a message about the open of the mapfile
- X all the lines which come after the SHAR_EOF
- X a message about closing files
- Xthis program doesn't get rid of any shell commands which someone might try to
- Xslip in, but since it is not a shell script, they shouldn't get executed.
- XPlus, the output file will be full of garbage if there was stuff tacked on
- Xafter the SHAR_EOF.
- XSomeone might wish to shorten MAXLIN (do map files have a line limit?)
- X*/
- X
- X#include <stdio.h>
- X
- X#define MAXLIN 256
- X
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X FILE *fp, *fp2;
- X char buffer[MAXLIN];
- X int at_beginning, at_end;
- X char filename[20], file2[20];
- X
- X at_beginning = 0;
- X at_end = 0;
- X
- X if(argc != 2){
- X printf("bad arguements\n");
- X exit(1);
- X }
- X
- X strcpy(filename,argv[1]);
- X
- X printf("opening file {%s}\n",filename);
- X if((fp = fopen(filename, "r")) == NULL) {
- X printf("can not open file {%s}\n",filename);
- X exit(1);
- X }
- X else{
- X while( (!at_beginning) && (fgets(buffer,MAXLIN,fp) != NULL) ){
- X if(strncmp(buffer,"cat << 'SHAR_EOF' > ",20) == 0){
- X at_beginning = 1;
- X }
- X }
- X if(!at_beginning){
- X printf("couldn't find beginning, exiting\n");
- X fclose(fp);
- X exit(1);
- X }
- X printf("removing end-of-line while copying\n");
- X strncpy(file2,&buffer[20],(strlen(&buffer[20]) - 1));
- X printf("opening file {%s}\n",file2);
- X if((fp2 = fopen(file2, "w")) == NULL) {
- X printf("can not open file {%s}\n",file2);
- X exit(1);
- X }
- X
- X while( (!at_end) && (fgets(buffer,MAXLIN,fp) != NULL) ){
- X if(strncmp(buffer,"SHAR_EOF",8) != 0){
- X fprintf(fp2,"%s",buffer);
- X }
- X else{
- X at_end = 1;
- X }
- X }
- X }
- X while( fgets(buffer,MAXLIN,fp) != NULL){
- X printf("%s",buffer);
- X }
- X
- X printf("closing files\n");
- X fclose(fp);
- X fclose(fp2);
- X}
- EOF
- chars=`wc -c < 'uns.c'`
- if test $chars != 2579; then echo 'uns.c' is $chars characters, should be 2579 characters!; fi
- fi
- exit 0
-
-
-