home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / uns < prev    next >
Text File  |  1989-02-03  |  4KB  |  133 lines

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