home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume28 / ssh / part01 < prev    next >
Encoding:
Text File  |  1992-03-06  |  7.1 KB  |  276 lines

  1. Newsgroups: comp.sources.misc
  2. From: etxerus@james.ericsson.se (Hans Beckerus LG/TH)
  3. Subject:  v28i080:  ssh - Split & Strip appended shell archives, Part01/01
  4. Message-ID: <1992Mar6.031430.5439@sparky.imd.sterling.com>
  5. X-Md4-Signature: cf0a365127771ff87b8e3d93e2b06e78
  6. Date: Fri, 6 Mar 1992 03:14:30 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: etxerus@james.ericsson.se (Hans Beckerus LG/TH)
  10. Posting-number: Volume 28, Issue 80
  11. Archive-name: ssh/part01
  12. Environment: UNIX
  13.  
  14. This small program strips and splits multiple/single part 
  15. shell archives and stores the result in 'partXX' files
  16.  
  17. Hans C. Beckerus
  18. -------------
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then feed it
  21. # into a shell via "sh file" or similar.  To overwrite existing files,
  22. # type "sh file -c".
  23. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  24. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  25. # Contents:  README Makefile ssh.c
  26. # Wrapped by kent@sparky on Thu Mar  5 21:09:21 1992
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. echo If this archive is complete, you will see the following message:
  29. echo '          "shar: End of archive 1 (of 1)."'
  30. if test -f 'README' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'README'\"
  32. else
  33.   echo shar: Extracting \"'README'\" \(356 characters\)
  34.   sed "s/^X//" >'README' <<'END_OF_FILE'
  35. X
  36. X* If you find any faults while using this program please
  37. X  notify me. Read the sourcecode for more information.
  38. X
  39. X* The Makefile is not really needed but I made a simple 
  40. X  one anyway. To compile type 'make install'.
  41. X
  42. X* This program has been tested on the SUN/SPARC and 
  43. X  the HP9000/700 series.
  44. X
  45. X
  46. X  Cheers!
  47. X
  48. X--
  49. XHans C. Beckerus
  50. Xetxerus@james.ericsson.se
  51. X
  52. END_OF_FILE
  53.   if test 356 -ne `wc -c <'README'`; then
  54.     echo shar: \"'README'\" unpacked with wrong size!
  55.   fi
  56.   # end of 'README'
  57. fi
  58. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  59.   echo shar: Will not clobber existing file \"'Makefile'\"
  60. else
  61.   echo shar: Extracting \"'Makefile'\" \(521 characters\)
  62.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  63. X#
  64. X# Simple makefile for ssh 1.10
  65. X#
  66. X
  67. X# Destination directory for binary
  68. XBINDIR= /usr/local/bin
  69. X
  70. XCC= cc
  71. XFLAGS= -O
  72. XPROG= ssh
  73. XSOURCES= ssh.c
  74. XOBJS= ssh.o
  75. X
  76. X# SUN:
  77. X# This should work for all SUN:s using malloc.h
  78. X# together with malloc(3V).
  79. XDEFINES= -DSUN
  80. X# HP:
  81. X# This should work for all HP:s using stdlib.h
  82. X# together with malloc(3C).
  83. X#DEFINES= -DHP
  84. X
  85. XCFLAGS= $(FLAGS) $(DEFINES)
  86. X
  87. X$(PROG): $(OBJS)
  88. X    $(CC) $(CFLAGS) -o $(PROG) $(OBJS) 
  89. X
  90. Xclean:
  91. X    rm -f core $(PROG) $(OBJS)
  92. X
  93. Xinstall: $(PROG)
  94. X    strip $(PROG)
  95. X    mv $(PROG) $(BINDIR)
  96. END_OF_FILE
  97.   if test 521 -ne `wc -c <'Makefile'`; then
  98.     echo shar: \"'Makefile'\" unpacked with wrong size!
  99.   fi
  100.   # end of 'Makefile'
  101. fi
  102. if test -f 'ssh.c' -a "${1}" != "-c" ; then 
  103.   echo shar: Will not clobber existing file \"'ssh.c'\"
  104. else
  105.   echo shar: Extracting \"'ssh.c'\" \(3598 characters\)
  106.   sed "s/^X//" >'ssh.c' <<'END_OF_FILE'
  107. X/* @(#)ssh.c 1.12 92/03/05 (HaB)
  108. X *
  109. X * NAME:
  110. X *    ssh
  111. X *
  112. X * SYNTAX:
  113. X *    ssh < filename
  114. X * 
  115. X * DESCRIPTION:
  116. X *    Splits and strips appended shell archives and
  117. X *    stores the result in 'partXX' files.
  118. X *    
  119. X * NOTES:
  120. X *    The program should work on all archives created
  121. X *    using 'shar' (or equals) provided that they have
  122. X *    not been changed since they were first generated.  
  123. X *
  124. X * DATE:
  125. X *    1992-03-05
  126. X *
  127. X * AUTHOR:
  128. X *    Hans C. Beckerus
  129. X *    etxerus@james.ericsson.se
  130. X *
  131. X * DISCLAIMER:
  132. X *    This program is free to distribute to anyone aslong 
  133. X *    as the code is not changed in anyway without me
  134. X *    knowing about it.  
  135. X *
  136. X *                                            /HaB :-)
  137. X */
  138. X
  139. X#include <stdio.h>
  140. X#include <string.h>
  141. X
  142. X#define SEARCH   0
  143. X#define START    1
  144. X#define INSIDE   2
  145. X#define MSTEP    80     /* Allocation steps       */
  146. X#define SEARCHP  5      /* No. of search patterns */ 
  147. X
  148. X#ifdef HP     /* Can be used for Turbo C/C++ */
  149. X#include <stdlib.h>
  150. Xsize_t msize;
  151. X#endif
  152. X
  153. X#ifdef SUN
  154. X#include <malloc.h>
  155. Xunsigned int msize;
  156. X#endif
  157. X
  158. Xchar sccsid[] = "@(#)ssh.c 1.12  92/03/05 (HaB)  etxerus@james.ericsson.se";
  159. X
  160. Xchar *pattern[] = {                 /* Add more patterns here if needed.   */ 
  161. X    "# This is a shell archive",    /* NOTE! Remember to increase SEARCHP. */ 
  162. X    "# This is part",
  163. X    "#!/bin/sh",
  164. X    "# !/bin/sh",
  165. X    "#! /bin/sh"
  166. X};
  167. X
  168. X/*  ssearchp:
  169. X *
  170. X *  Searches string s for pattern p.
  171. X *  Returns index on success else -1.
  172. X *
  173. X */
  174. X
  175. Xint ssearchp (s, p)
  176. X
  177. Xchar *s;     /* String to search      */
  178. Xchar *p;     /* Pattern to search for */
  179. X
  180. X{
  181. X    register i, j, k;     /* Counters */
  182. X
  183. X    for (i = 0; s[i] != '\0'; i++) {
  184. X    for (j = i, k = 0; p[k] != '\0' && s[j] == p[k]; j++, k++)
  185. X            ;
  186. X    if (k > 0 && p[k] == '\0')     /* Pattern found */
  187. X        return i;
  188. X    }
  189. X    return -1;    /* Pattern not found */
  190. X}
  191. X
  192. Xmain ()
  193. X{
  194. X    FILE     *fr = stdin;         /* Input filepointer  */
  195. X    FILE     *fw;                 /* Output filepointer */
  196. X    int       state = SEARCH;     /* The current state  */
  197. X    int       fc = 0;             /* File part counter  */
  198. X    char     *s;                  /* Read line          */
  199. X    char      fout[7];            /* Output filenames   */
  200. X    register  j = 0;              /* Counter            */
  201. X    register  c;                  /* Read character     */
  202. X
  203. X    msize = MSTEP;
  204. X    s = malloc (msize);     /* Allocate buffer */
  205. X
  206. X    while ((c = getc (fr)) != EOF) {
  207. X    if (c != '\n') {     /* Check for EOL */
  208. X        s[j++] = c;
  209. X            if (j == msize) {
  210. X                msize += MSTEP;
  211. X                if ((s = realloc (s, msize)) == NULL) {
  212. X                    puts ("ssh: Allocation error, cannot continue.");
  213. X                    exit (1);
  214. X                }
  215. X            }
  216. X        }
  217. X    else {
  218. X        s[j] = '\0';     /* One line has been read */
  219. X        switch (state) {
  220. X        case SEARCH:
  221. X            for (j = 0; j < SEARCHP;) {
  222. X            if (ssearchp (s, pattern[j++]) != -1) {
  223. X                state = START;
  224. X                continue;
  225. X            }
  226. X            }
  227. X            if (state != START)
  228. X            break;
  229. X
  230. X        case START:     /* Start writing to file */
  231. X            sprintf (fout, "part%.2d", ++fc);
  232. X            fw = fopen (fout, "w");
  233. X            fprintf (fw, "%s\n", s);
  234. X                    state = INSIDE;
  235. X            break;
  236. X
  237. X                case INSIDE:
  238. X            if (!(strcmp (s, "exit 0"))) {     /* Look for end */
  239. X                        fprintf (fw, "%s\n", s);
  240. X                        fclose (fw);
  241. X                        state = SEARCH;
  242. X                    }
  243. X                    else
  244. X            fprintf (fw, "%s\n", s);
  245. X            break;
  246. X            }
  247. X            j = 0;    /* Reset counter */
  248. X        }
  249. X    }
  250. X}
  251. X
  252. END_OF_FILE
  253.   if test 3598 -ne `wc -c <'ssh.c'`; then
  254.     echo shar: \"'ssh.c'\" unpacked with wrong size!
  255.   fi
  256.   # end of 'ssh.c'
  257. fi
  258. echo shar: End of archive 1 \(of 1\).
  259. cp /dev/null ark1isdone
  260. MISSING=""
  261. for I in 1 ; do
  262.     if test ! -f ark${I}isdone ; then
  263.     MISSING="${MISSING} ${I}"
  264.     fi
  265. done
  266. if test "${MISSING}" = "" ; then
  267.     echo You have the archive.
  268.     rm -f ark[1-9]isdone
  269. else
  270.     echo You still must unpack the following archives:
  271.     echo "        " ${MISSING}
  272. fi
  273. exit 0
  274. exit 0 # Just in case...
  275.