[net.micro.6809] Trivial But Useful Hack for OS-9

jejones@ea.UUCP (11/01/84)

Attached please find source (Microware C) for a program that will run
a specified program at a specified priority. Alas, it's sufficiently
stupid that it won't look up the right interpreter, so you have to say

	RunAt <priority> "RunB WhatIReallyWant"

and the like. (The quotes are necessary, by the way.) Also alas, the
Microware Shell is sufficiently woofish about recognizing redirection,
memory specifications, etc. that they can't go inside the quotes. (What
do you want for 1300 bytes?)

						James Jones
------------------------------TARE HEAR------------------------------
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# ModuleType.h RunAt.c

echo x - ModuleType.h
sed 's/^	//' > "ModuleType.h" << '//E*O*F ModuleType.h//'
	/*
	 * ModuleType.h -- type/language byte values
	 *    (gee, this really ought to be in module.h...)
	 */
	
	#define MTProg		 1	/* program module		*/
	#define MTSub		 2	/* subroutine module		*/
	#define MTMulti		 3	/* multi-module			*/
	#define MTData		 4	/* data module			*/
	#define MTSys		12	/* OS-9 system module		*/
	#define MTFMan		13	/* OS-9 file manager		*/
	#define MTDriver	14	/* OS-9 device driver		*/
	#define MTDescr		15	/* OS-9 device descriptor	*/
	
	#define LData		0	/* data				*/
	#define LMLang		1	/* 6809 machine language	*/
	#define LICode		2	/* BASIC09 I-code		*/
	#define LPCode		3	/* Pascal P-code		*/
	#define LCOBOL		4	/* COBOL I-code			*/
//E*O*F ModuleType.h//

echo x - RunAt.c
sed 's/^	//' > "RunAt.c" << '//E*O*F RunAt.c//'
	/*
	 * RunAt -- do something at a specified priority
	 *
	 * usage: RunAt <priority> "command"
	 * note: the command cannot be a shell script
	 * (for that matter, it has to be a machine language program...)
	 */
	
	#include <stdio.h>
	#include <ctype.h>
	#include <ModuleType.h>
	
	#define MAXPARMS	256
	
	main(argc, argv)
	int	argc;
	char	*argv[];
	{
		int	child, prio;
		char	*ParmScan;
		char	ParmString[MAXPARMS];
	
		if (argc != 3) {
			fprintf(stderr, "usage: RunAt <priority> \"command\"\n");
			exit(1);
		}
	
		prio = atoi(argv[1]);
		if (prio < 1 || prio > 255) {
			fprintf(stderr, "RunAt: priority %d out of range\n", prio);
			exit(1);
		}
	
		for (ParmScan = argv[2]; !isspace(*ParmScan); )
			ParmScan++;
	
		*ParmScan = '\0';
		while (isspace(*++ParmScan))
			;
		strcpy(ParmString, ParmScan);
		strcat(ParmString, "\n");
	
		setpr(getpid(), prio);
	
		chain(argv[2], strlen(ParmString), ParmString,
			MTProg, LMLang, 0);
	
		fprintf(stderr, "RunAt: can't fork\n");
		exit(1);
	
	}
//E*O*F RunAt.c//

exit 0