💾 Archived View for uscoffings.net › retro-computing › systems › TI994a › assemblers › tiasm › src ›… captured on 2022-06-04 at 01:14:02.

View Raw

More Information

-=-=-=-=-=-=-

#include <stdio.h>
#include "TIasm.h"

int	Debug;

main (argc,argv)
int	argc;
char	*argv[];
{
	char **avec, *arg;
	FILE *isd, *psd;
	int x, filcnt = 0;
	char *tmp, *fpart;
	char c;
	char cbuf[BUFSIZ], swbuf[BUFSIZ], *fvec[BUFSIZ];
	char *rindex();
	FILE *popen();
	flag skippit = FALSE;

	avec = &argv[1];
	while (*avec != NULL)
		if (**avec != '-')
			fvec[filcnt++] = *avec++;
		else {
			arg = *avec++;
			while (*++arg != NULL)

				switch (*arg) {
				    case 'd':		/* Debug */
					strcat (swbuf, "-d ");
					Debug = atoi(*avec);
					strcat (swbuf, *avec++);
					break;
				    default:
					fprintf (stderr, "Unknown switch -%c\n",
					    *arg);
				}
		}

	sprintf (cbuf, "%s %s -o ", PASS1, swbuf);
	fpart = cbuf + strlen(cbuf);

	for (x = 0; x < filcnt; ++x) {
		/* Look for ".a" and replace by ".o" for output part */
		tmp = rindex(fvec[x], '.');
		if (tmp == NULL || *++tmp != 'a') {
			fprintf (stderr,
			    "%s does not end in \".a\", skipping..\n",
			    fvec[x]);
			skippit = TRUE;
		}

		if ((isd = fopen(fvec[x], "r")) == NULL) {
			fprintf (stderr,
			    "Cannot open %s, skipping...\n",
			    fvec[x]);
			skippit = TRUE;
		}

		if (skippit == TRUE)
			skippit = FALSE;
		else {
			*tmp = 'o';

			/* Now to find basename so we leave output here */
			tmp = rindex(fvec[x],'/');
			tmp = tmp != NULL ? tmp + 1: fvec[x];

			*fpart = NULL;
			strcat (fpart, tmp);
			DEBUG (1, "%s\n", cbuf);
			if ((psd = popen(cbuf, "w")) == NULL) {
				fprintf (stderr,
				    "Cannot popen pass1, aborting\n");
				exit (1);
			}
			/* Now give pass1 the file */
			while ((c = fgetc(isd)) != EOF)
				if (fputc(c, psd) == EOF) {
					fprintf (stderr,
					    "I/O error, aborting\n");
					exit (1);
				}
			fclose (isd);
			pclose (psd);
		}
	}
}