summaryrefslogtreecommitdiff
path: root/ipl/progs/shar.icn
blob: 44b02547ba0e956984ceb6fb718a6cdca14a3008 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
############################################################################
#
#	File:     shar.icn
#
#	Subject:  Program to create UNIX shell archive
#
#	Author:   Robert J. Alexander
#
#	Date:     May 6, 1992
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  Program to create Bourne shell archive of text files.
#
#  Usage: shar text_file...
#
############################################################################

procedure main(arg)
   local fn, chars, f, line

   write(
	  "#! /bin/sh_
	 \n# This is a shell archive, meaning:_
	 \n# 1. Remove everything above the #! /bin/sh line._
	 \n# 2. Save the resulting text in a file._
	 \n# 3. Execute the file with /bin/sh (not csh) to create:")
   every write("#\t",!arg)
   write(
	  "# This archive created: ",&dateline,
       "\nexport PATH; PATH=/bin:/usr/bin:$PATH")
   every fn := !arg do {
      chars := 0
      f := open(fn) | stop("Can't open \",fn,"\"")
      write(
	     "if test -f '",fn,"'_
	    \nthen_
	    \n\techo shar: \"will not over-write existing file '",fn,"'\"_
	    \nelse_
	    \ncat << \\SHAR_EOF > '",fn,"'")
      while line := read(f) do {
	 write(line)
	 chars +:= *line + 1
	 }
      write(
	    "SHAR_EOF_
	    \nif test ",chars," -ne \"`wc -c < '",fn,"'`\"_
	    \nthen_
	    \n\techo shar: \"error transmitting '",fn,"'\" '(should have been ",
		  chars," characters)'_
	    \nfi_
	    \nfi")
      close(f)
      }
   write(
	  "exit 0_
	 \n#\tEnd of shell archive")
end