[net.sources] Ratfor in C changes..

oz@yetti.UUCP (Ozan Yigit) (06/25/85)

Ian Darwin (darwin!ian) has improved the front-end of the ratfor
program recently posted to net.sources. It now uses getopt(), and
accepts a parameter (-l n) to set the ratfor-generated label number.
Here is a normal diff of this version, to feed into patch 1.3.

Oz

Ps: case stmt handling on its way..

------------------- CUT (obviously) -------------------------
2,6c2,4
<  * ratfor
<  *
<  * A ratfor pre-processor in C. It is almost a direct
<  * translation of a pre-processor distributed by the
<  * University of Arizona. It closely corresponds to the
---
>  * ratfor - A ratfor pre-processor in C. 
>  * Almost a direct translation of a pre-processor distributed by the
>  * University of Arizona. Closely corresponds to the
8,9d5
<  * It lacks the "case" construct available in the UNIX
<  * version of ratfor.
11c7,9
<  * By:	Oz
---
>  * Lacks the "case" construct available in the UNIX version of ratfor.
>  *
>  * By:	Ozan Yigit, York University, Toronto, Canada
14a13
> 
93,96c92,96
< 
< /* ------------------------------ */
< /* M A I N   L I N E  &  I N I T  */
< /* ------------------------------ */
---
> char *progname;
>  
> /* 
>  * M A I N   L I N E  &  I N I T
>  */
102,103c102,104
< 	int i;
< 	char *p;
---
> 	int c, errflg = 0;
> 	extern int optind;
> 	extern char *optarg;
105,108c106,132
< 	if (argc == 1)
< 		usage();
< 	if ((infile[0] = fopen(argv[1], "r")) == NULL) {
< 		fprintf(stderr,"%s: cannot open.\n",argv[1]);
---
> 	progname = argv[0];
> 
> 	while ((c=getopt(argc, argv, "Chn:o:6:")) != EOF)
> 	switch (c) {
> 		case 'C':
> 			/* not written yet */
> 			break;
> 		case 'h':
> 			/* not written yet */
> 			break;
> 		case 'l':
> 			startlab = atoi(optarg);
> 			break;
> 		case 'o':
> 			if ((freopen(optarg, "w", stdout)) == NULL)
> 				error("can't write %s\n", optarg);
> 			break;
> 		case '6':
> 			/* not written yet */
> 			break;
> 		default:
> 			++errflg;
> 	}
> 	
> 	if (errflg) {
> 		fprintf(stderr,
> 			"usage: %s [-C][-hx][-l n][-o file][-6x] [file...]\n");
111,115d134
< 	if (p = argv[2])
< 		if ((freopen(p, "w", stdout)) == NULL) {
< 			fprintf(stderr,"%s: cannot create.\n",p);
< 			exit(1);
< 	}
116a136,150
> 	/*
> 	 * present version can only process one file, sadly.
> 	 */
> 	if (optind >= argc)
> 		infile[0] = stdin;
> 	else if ((infile[0] = fopen(argv[optind], "r")) == NULL)
> 		error("cannot read %s", argv[optind]);
> 
> 	initvars();
> 
> 	parse();		/* call parser.. */
> 
> 	exit(1);
> }
> 
118,119c152
<  * initialise our stuff..
<  *
---
>  * initialise 
120a154,157
> initvars()
> {
> 	int i;
> 
133,136c170
< 	label = 23000;		/* next generated label */
< 
< 	parse();		/* call parser.. */
< 	exit(1);
---
> 	label = startlab;	/* next generated label */
139,142c173,175
< 
< /* ------------------------------ */
< /* P A R S E R 			  */
< /* ------------------------------ */
---
> /*
>  * P A R S E R
>  */
204,207c237,239
< 
< /* ------------------------------ */
< /* L E X I C A L  A N A L Y S E R */
< /* ------------------------------ */
---
> /*
>  * L E X I C A L  A N A L Y S E R
>  */
787,790c819,821
< 
< /* ------------------------------ */
< /* C O D E  G E N E R A T I O N   */
< /* ------------------------------ */
---
> /*
>  * C O D E  G E N E R A T I O N 
>  */
794d824
<  *
1018c1048
< 		if (lexstr[0] == DIG2 && lexstr[1] == DIG3)
---
> 		if (atoi(lexstr) >= startlab)
1358,1361c1388,1390
< 
< /* ------------------------------ */
< /* E R R O R  M E S S A G E S     */
< /* ------------------------------ */
---
> /*
>  * E R R O R  M E S S A G E S 
>  */
1365d1393
<  *
1377d1404
<  *
1380c1407
< char msg[];
---
> char *msg;
1400a1428
> 
1402,1403c1430
<  * usage
<  *
---
>  * U T I L I T Y  R O U T I N E S
1405,1409d1431
< usage()
< {
< 	fprintf(stderr,"usage: ratfor <input file> [output file]\n");
< 	exit(1);
< }
1411,1415d1432
< 
< /* ------------------------------ */
< /* U T I L I T Y  R O U T I N E S */
< /* ------------------------------ */
< 
1418d1434
<  *
1471c1487
< 		if (str1[i] == EOS) {
---
> 		if (str1[i] == EOS)
1473d1488
< 		}
1512c1527
< 	strcpy(defn,p->def);
---
> 	(void) strcpy(defn,p->def);
1518d1532
<  *
1526d1539
< 
1542d1554
< 	 *