home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / ISPSRC.ZIP / makeshar < prev    next >
Text File  |  1991-06-18  |  2KB  |  116 lines

  1. : Use /bin/sh
  2. #
  3. # $Header: /usr0/ghk/free/ispell/RCS/makeshar,v 1.2 89/07/11 00:24:58 geoff Exp $
  4. #
  5. # $Log:    makeshar,v $
  6. # Revision 1.2  89/07/11  00:24:58  geoff
  7. # Don't forget to remove the temp file at the end.
  8. # Revision 1.1  89/06/23  00:26:07  geoff
  9. # Initial revision
  10. #
  11. # Make a shar file, keeping file sizes below a maximum, but as large as
  12. # possible.  The output files are put in file01.shar through filenn.shar,
  13. # where "file" is the output base name (default "prog").
  14. #
  15. # If one of the output files is named "README", it is placed first in the
  16. # first shar file.
  17. #
  18. # Usage:
  19. #
  20. #    makeshar [-n] [-m max-size] [-o output-base ] [shar-switches] file-list
  21. #
  22. SHAR_SW=
  23. MAXSIZE=60000
  24. OUTPUT_BASE=prog
  25. NUM_SHARS=no
  26. TMP=${TMPDIR:-/tmp}/ms$$
  27.  
  28. while [ $# -gt 0 ]
  29. do
  30.     case "$1" in
  31.     -m)
  32.         MAXSIZE=$2
  33.         shift; shift
  34.         ;;
  35.     -n)
  36.         NUM_SHARS=yes
  37.         shift
  38.         ;;
  39.     -o)
  40.         OUTPUT_BASE="$2"
  41.         shift; shift
  42.         ;;
  43.     -*)
  44.         SHAR_SW="$SHAR_SW $1"
  45.         shift
  46.         ;;
  47.     *)
  48.         break
  49.         ;;
  50.     esac
  51. done
  52. trap "/bin/rm -f ${TMP}; exit 1" 1 2 15
  53. trap "/bin/rm -f ${TMP}; exit 0" 13
  54. sed -e "s;OUTPUT_BASE;$OUTPUT_BASE;" -e "s;SHAR_SW;$SHAR_SW;" \
  55.   -e "s;MAXSIZE;$MAXSIZE;" > ${TMP} << 'EOF_AWK_SCRIPT'
  56.     BEGIN { nfiles = 0 }
  57.     {
  58.     if ($3 == "total")
  59.         next
  60.     # Shar adds one extra character per line
  61.     size[nfiles] = $1 + $2
  62.     files[nfiles] = $3
  63.     nfiles++
  64.     }
  65.     END \
  66.     {
  67.     outbase = "OUTPUT_BASE"
  68.     sharcount = 1
  69.     for (filesdone = 0;  filesdone < nfiles;  sharcount++)
  70.         {
  71.         printf ("%s", "sharSHAR_SW")
  72.         totsize = 0
  73.         for (i = 0;  filesdone == 0  &&  i < nfiles;  i++)
  74.         {
  75.         if (files[i] == "README")
  76.             {
  77.             filesdone++
  78.             totsize += size[i]
  79.             printf (" %s", files[i])
  80.             files[i] = ""
  81.             size[i] = 0
  82.             }
  83.         }
  84.         for (i = 0;  totsize < MAXSIZE  &&  i < nfiles;  i++)
  85.         {
  86.         if (files[i] != "" \
  87.           &&  (totsize == 0  ||  size[i] < MAXSIZE - totsize))
  88.             {
  89.             filesdone++
  90.             totsize += size[i]
  91.             printf (" %s", files[i])
  92.             files[i] = ""
  93.             size[i] = 0
  94.             }
  95.         }
  96.         printf (" > %s%2.2d.shar\n", outbase, sharcount)
  97.         }
  98.     print "echo", sharcount - 1
  99.     }
  100. EOF_AWK_SCRIPT
  101. nshars=`wc -lc "$@" \
  102.   | sort -rn \
  103.   | awk -F ${TMP} \
  104.   | sh`
  105. if [ $NUM_SHARS = yes ]
  106. then
  107.     echo $nshars
  108. else
  109.     echo $nshars shar files:
  110.     ls -l "$OUTPUT_BASE"??.shar
  111. fi
  112.  
  113. /bin/rm -f ${TMP}
  114.