home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / uns < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.0 KB

  1. From decwrl!labrea!rutgers!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery Sun Dec 11 17:12:27 PST 1988
  2. Article 751 of comp.sources.misc:
  3. Path: granite!decwrl!labrea!rutgers!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery
  4. From: segedy@gsg.UUCP (Catherine Segedy)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i076: map unpacker written in C (uns.c)
  7. Keywords: maps, program, unpacker
  8. Message-ID: <285@gsg.UUCP>
  9. Date: 8 Dec 88 00:04:56 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Reply-To: segedy@gsg.UUCP (Catherine Segedy)
  12. Organization: General Systems Group, Inc., Salem, NH
  13. Lines: 119
  14. Approved: allbery@ncoast.UUCP
  15.  
  16. Posting-number: Volume 5, Issue 76
  17. Submitted-by: "Catherine Segedy" <segedy@gsg.UUCP>
  18. Archive-name: uns
  19.  
  20. Due to all the noise recently about the dangers of shell scripts for
  21. unpacking maps, I recently posted to comp.unix.wizards, news.sysadmin,
  22. and news.admin, describing the following program.  I would have just posted
  23. it, but I was delayed a few days for something.  Anyway, here it is.  I hope
  24. this is helpful.
  25.                         cathy segedy, GSG
  26. decvax!gsg!segedy
  27. harvard!gsg!segedy
  28.  
  29. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  30.  
  31. #! /bin/sh
  32. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  33. # Contents:  uns.c
  34. echo extracting 'uns.c'
  35. if test -f 'uns.c' -a -z "$1"; then echo Not overwriting 'uns.c'; else
  36. sed 's/^X//' << \EOF > 'uns.c'
  37. X/* Copyright 1988 by GSG, Salem, NH -- permission is given to copy this and
  38. X    use it as long as it is not sold or used commercially, and as long as
  39. X    this copyright is included with it.
  40. X
  41. X    Author: Cathy Segedy
  42. X            send comments, etc. to:  decvax!gsg!segedy or
  43. X                        harvard!gsg!segedy
  44. X    date: Dec. 7, 1988
  45. Xno guarantees or warranties are made, either implicitly or explicitly about the
  46. Xcorrectness of this program, and it is presented as is, and use at your own
  47. Xrisk.
  48. X
  49. Xto compile this program, (uns.c):
  50. X        cc -o uns uns.c
  51. Xto use this program: (I use it this way)
  52. X    uns mapfilename >> some_output_file
  53. Xthis should produce the mapfile.  The output file should contain
  54. X    a message about the opening of the input file
  55. X    a message about removing end_of_line
  56. X    a message about the open of the mapfile
  57. X    all the lines which come after the SHAR_EOF
  58. X    a message about closing files
  59. Xthis program doesn't get rid of any shell commands which someone might try to
  60. Xslip in, but since it is not a shell script, they shouldn't get executed.
  61. XPlus, the output file will be full of garbage if there was stuff tacked on
  62. Xafter the SHAR_EOF.
  63. XSomeone might wish to shorten MAXLIN  (do map files have a line limit?)
  64. X*/
  65. X
  66. X#include <stdio.h>
  67. X
  68. X#define MAXLIN 256
  69. X
  70. Xmain(argc,argv)
  71. Xint argc;
  72. Xchar *argv[];
  73. X{
  74. X    FILE *fp, *fp2;
  75. X    char buffer[MAXLIN];
  76. X    int at_beginning, at_end;
  77. X    char filename[20], file2[20];
  78. X
  79. X    at_beginning = 0;
  80. X    at_end = 0;
  81. X
  82. X    if(argc != 2){
  83. X        printf("bad arguements\n");
  84. X        exit(1);
  85. X    }
  86. X
  87. X    strcpy(filename,argv[1]);
  88. X
  89. X    printf("opening file {%s}\n",filename);
  90. X    if((fp = fopen(filename, "r")) ==  NULL) {
  91. X        printf("can not open file {%s}\n",filename);
  92. X        exit(1);
  93. X    }
  94. X    else{
  95. X        while( (!at_beginning) && (fgets(buffer,MAXLIN,fp) != NULL) ){
  96. X        if(strncmp(buffer,"cat << 'SHAR_EOF' > ",20) == 0){
  97. X            at_beginning = 1;
  98. X        }
  99. X        }
  100. X        if(!at_beginning){
  101. X        printf("couldn't find beginning, exiting\n");
  102. X        fclose(fp);
  103. X        exit(1);
  104. X        }
  105. X        printf("removing end-of-line while copying\n");
  106. X        strncpy(file2,&buffer[20],(strlen(&buffer[20]) - 1));
  107. X        printf("opening file {%s}\n",file2);
  108. X        if((fp2 = fopen(file2, "w")) ==  NULL) {
  109. X        printf("can not open file {%s}\n",file2);
  110. X        exit(1);
  111. X        }
  112. X
  113. X        while( (!at_end) && (fgets(buffer,MAXLIN,fp) != NULL) ){
  114. X        if(strncmp(buffer,"SHAR_EOF",8) != 0){
  115. X            fprintf(fp2,"%s",buffer);
  116. X        }
  117. X        else{
  118. X            at_end = 1;
  119. X        }
  120. X        }
  121. X    }
  122. X    while( fgets(buffer,MAXLIN,fp) != NULL){
  123. X        printf("%s",buffer);
  124. X    }
  125. X
  126. X    printf("closing files\n");
  127. X    fclose(fp);
  128. X    fclose(fp2);
  129. X}
  130. EOF
  131. chars=`wc -c < 'uns.c'`
  132. if test $chars !=    2579; then echo 'uns.c' is $chars characters, should be    2579 characters!; fi
  133. fi
  134. exit 0
  135.  
  136.  
  137.