home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / groff-1.09-src.lha / src / amiga / groff-1.09 / pic / make-dos-dist < prev    next >
Text File  |  1994-02-21  |  6KB  |  300 lines

  1. #! /bin/sh
  2.  
  3. # This creates a compressed (14 bits) tar file that can be copied to a DOS
  4. # machine, unpacked and compiled with Borland C++ 2.0.
  5.  
  6. # This is for groff version 1.04.  It will probably need work for
  7. # other versions.
  8.  
  9. # The grammar is yacced here, because I don't have a yacc on my DOS
  10. # machine.  The resulting .tab.c file is split up; I found the
  11. # compiler ran out of memory otherwise.  The sed command that does the
  12. # splitting assumes you're using the SunOS 4.1.1 yacc.
  13. # (Bison-generated parsers need alloca() which Borland C++ does not
  14. # have.) You'll need to tweak it for other yaccs: in particular you'll
  15. # need to change the `tabs' variable, so that it matches the names of
  16. # the external arrays of ints generated by your version yacc: it is
  17. # these that are split off into another file.  You may also need to
  18. # change tabtype to `short' if the tables are arrays of shorts.
  19.  
  20. picdir=`pwd`
  21. tarfile=pic_tar
  22. tabs="yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef"
  23. tabtype=int
  24. file1=pic_tab1.c
  25. file2=pic_tab2.c
  26.  
  27. rm -fr temp
  28. mkdir temp
  29. cd temp
  30.  
  31.  
  32. yacc -d $picdir/pic.y
  33.  
  34. for tab in $tabs; do echo "/$tabtype $tab\\[]/i\\
  35. extern $tabtype $tab[];
  36. /$tabtype $tab\\[]/,/;/{
  37. w $file2
  38. d
  39. }"; done >split.sed
  40.  
  41. sed -f split.sed y.tab.c >$file1
  42.  
  43. rm -f split.sed y.tab.c
  44.  
  45. mv y.tab.h pic_tab.h
  46.  
  47. libfiles="change_lf.c cset.c cset.h errarg.c errarg.h error.c error.h \
  48. fatal.c filename.c version.c lf.c lib.h lineno.c new.c string.c \
  49. stringclass.h progname.c strerror.c strsave.c ptable.c ptable.h"
  50.  
  51. picfiles="common.c common.h lex.c main.c object.c object.h output.h \
  52. pic.h position.h tex.c text.h troff.c"
  53.  
  54. for file in $picfiles
  55. do
  56.     sed -e '/^#include/s/pic\.tab\.h/pic_tab.h/' $picdir/$file >$file
  57. done
  58.  
  59. for file in $libfiles; do cp $picdir/../lib/$file $file; done
  60.  
  61. mv stringclass.h stringcl.h
  62. mv change_lf.c changelf.c
  63.  
  64. cat >makefile <<'EOF'
  65. # Makefile for pic with Borland C++ 2.0.
  66. CC=bcc -P -V
  67. OLDCC=bcc -V
  68. MODEL=l
  69. WARN=
  70. DEBUG=
  71. MAP=-M
  72. CFLAGS=-m$(MODEL) $(WARN) $(DEBUG) -I. -DSWITCHAR
  73. LDFLAGS=-m$(MODEL) $(DEBUG) $(MAP)
  74.  
  75. OBJS=changelf.obj \
  76. common.obj \
  77. cset.obj \
  78. errarg.obj \
  79. error.obj \
  80. fatal.obj \
  81. filename.obj \
  82. lex.obj \
  83. lf.obj \
  84. lineno.obj \
  85. main.obj \
  86. new.obj \
  87. object.obj \
  88. pic_tab1.obj \
  89. pic_tab2.obj \
  90. progname.obj \
  91. ptable.obj \
  92. string.obj \
  93. strsave.obj \
  94. tex.obj \
  95. troff.obj \
  96. version.obj \
  97. getopt.obj \
  98. strerror.obj
  99.  
  100. PROG=pic
  101.  
  102. .c.obj:
  103.     $(CC) -c $(CFLAGS) {$< }
  104.  
  105. $(PROG).exe: $(OBJS)
  106.     $(CC) $(LDFLAGS) -e$(PROG) @&&!
  107. $(OBJS)
  108. !
  109.  
  110. strerror.obj: strerror.c
  111.     $(OLDCC) -c $(CFLAGS) strerror.c
  112.  
  113. getopt.obj: getopt.c
  114.     $(OLDCC) -c $(CFLAGS) getopt.c
  115.  
  116. # Enable auto-dependency checking.
  117. .autodepend
  118. EOF
  119.  
  120. cat >osfcn.h <<'EOF'
  121. #include <io.h>
  122.  
  123. extern "C" {
  124.      int getopt(int, char **, const char *);
  125.      extern int optind;
  126.      extern int opterr;
  127. }
  128. EOF
  129.  
  130. cat >getopt.c <<'EOF'
  131. /* getopt() for those systems that don't have it. */
  132. /* Derived from comp.sources.unix/volume3/att_getopt. */
  133.  
  134. #include <stdio.h>
  135. #include </gnu/include/string.h>
  136. #include <ctype.h>
  137.  
  138. #ifdef SWITCHAR
  139. #include <dos.h>
  140. #endif
  141.  
  142. int    opterr = 1;
  143. int    optind = 1;
  144. int    optopt;
  145. char *optarg;
  146.  
  147. #ifndef OPTION_CHAR
  148. #define OPTION_CHAR '-'
  149. #endif
  150.  
  151. #ifdef isascii
  152. #define ISASCII(c) isascii(c)
  153. #else
  154. #define ISASCII(c) (1)
  155. #endif
  156.  
  157. int getopt(argc, argv, opts)
  158. int argc;
  159. char **argv;
  160. char *opts;
  161. {
  162. #ifdef SWITCHAR
  163.     union REGS regs;
  164.     static char switchar = '\0';
  165. #endif
  166.     static int sp = 1;
  167.     register int c;
  168.     register char *cp;
  169.     char *message;
  170. #ifdef SWITCHAR
  171.     if (switchar == '\0') {
  172.         regs.x.ax = 0x3700;
  173.         intdos(®s, ®s);
  174.         if (!regs.x.cflag)
  175.             switchar = regs.h.dl;
  176.         else
  177.             switchar = '/';
  178.     }
  179. #endif
  180.     if (sp == 1) {
  181.         if (optind >= argc)
  182.             return EOF;
  183.         if ((
  184. #ifdef SWITCHAR
  185.             argv[optind][0] != switchar &&
  186. #endif
  187.             argv[optind][0] != OPTION_CHAR) || argv[optind][1] == '\0') {
  188. #ifdef REORDER_ARGS
  189.             int i;
  190.             for (i = optind; i < argc; i++)
  191.                 if ((
  192. #ifdef SWITCHAR
  193.                      argv[i][0] == switchar ||
  194. #endif
  195.                      argv[i][0] == OPTION_CHAR) && argv[i][1] != '\0')
  196.                     break;
  197.             if (i < argc) {
  198.                 c = argv[i][1];
  199. #ifdef CASE_INSENSITIVE_OPTIONS
  200.                 if (isupper(c))
  201.                     c = tolower(c);
  202. #endif
  203.                 if (c != ':' && c != OPTION_CHAR && (cp = strchr(opts, c)) != NULL
  204.                     && cp[1] == ':' && argv[i][2] == 0 && i < argc - 1) {
  205.                     int j;
  206.                     char *temp1 = argv[i];
  207.                     char *temp2 = argv[i+1];
  208.                     for (j = i - 1; j >= optind; j--)
  209.                         argv[j+2] = argv[j];
  210.                     argv[optind] = temp1;
  211.                     argv[optind+1] = temp2;
  212.                 }
  213.                 else {
  214.                     int j;
  215.                     char *temp = argv[i];
  216.                     for (j = i - 1; j >= optind; j--)
  217.                         argv[j+1] = argv[j];
  218.                     argv[optind] = temp;
  219.                 }
  220.             }
  221.             else
  222. #endif
  223.                 return EOF;
  224.         }
  225.         if ((argv[optind][0] == OPTION_CHAR && argv[optind][1] == OPTION_CHAR
  226.                   && argv[optind][2] == '\0')
  227. #ifdef SWITCHAR
  228.             || (argv[optind][0] == switchar && argv[optind][1] == switchar
  229.                 && argv[optind][2] == '\0')
  230. #endif
  231.             ) {
  232.             optind++;
  233.             return(EOF);
  234.         }
  235.     }
  236.     optopt = c = (unsigned char)argv[optind][sp];
  237. #ifdef CASE_INSENSITIVE_OPTIONS
  238.     if (ISASCII(c) && isupper(c))
  239.         optopt = c = tolower(c);
  240. #endif
  241.     if (c == ':' || (cp = strchr(opts, c)) == NULL) {
  242.         if (argv[optind][++sp] == '\0') {
  243.             optind++;
  244.             sp = 1;
  245.         }
  246.         message = ": illegal option -- ";
  247.         goto bad;
  248.     }
  249.     if (*++cp == ':') {
  250.         if (argv[optind][sp+1] != '\0')
  251.             optarg = &argv[optind++][sp+1];
  252.         else if (++optind >= argc) {
  253.             sp = 1;
  254.             message = ": option requires an argument -- ";
  255.             goto bad;
  256.         }
  257.         else
  258.             optarg = argv[optind++];
  259.         sp = 1;
  260.     } 
  261.     else {
  262.         if (argv[optind][++sp] == '\0') {
  263.             sp = 1;
  264.             optind++;
  265.         }
  266.         optarg = NULL;
  267.     }
  268.     return c;
  269. bad:
  270.     if (opterr) {
  271.         fputs(argv[0], stderr);
  272.         fputs(message, stderr);
  273.         fputc(optopt, stderr);
  274.         fputc('\n', stderr);
  275.     }
  276.     return '?';
  277. }
  278.  
  279. /*
  280. Local Variables:
  281. c-indent-level: 4
  282. c-continued-statement-offset: 4
  283. c-brace-offset: 4
  284. c-argdecl-indent: 4
  285. c-label-offset: -4
  286. tab-width: 4
  287. End:
  288. */
  289. EOF
  290.  
  291. for file in *; do sed -e 's/$//' $file >temp; mv temp $file; done
  292.  
  293. tar cf ../$tarfile *
  294. cd ..
  295. compress -b14 $tarfile
  296. rm -fr temp
  297.  
  298. echo Now move $tarfile.Z to a MSDOS machine with Borland C++ 2.0,
  299. echo unpack and compile with make -S.
  300.