[net.micro.atari16] MAKE part 3 of 3

bammi@cwruecmp.UUCP (08/05/86)

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	readme
#	rules.c
#	ststuff.c
#	touch.c
# This archive created: Tue Aug  5 02:46:38 1986
# By:	Jwahar R. Bammi ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'readme'" '(5969 characters)'
if test -f 'readme'
then
	echo shar: over-writing existing file "'readme'"
fi
sed 's/^X//' << \SHAR_EOF > 'readme'
X
X	A full featured Public Domain Make for the Atari Sts. Adapted 
Xfrom origonal posting by Neil Russell.
X
X	After unsharing the 3 parts of this posting you should end up
Xwith the following files:
X
XSources:
X
X	astat.h		h.h		main.c		rules.c
X	check.c		input.c		make.c		ststuff.c
X	decl.h		macro.c		reader.c	touch.c
X
XAlcyon C compile scripts (you only need these the first time around!):
X	compile.sh
X	link.sh
X	lnk
X
XMegamax C compiler scripts (you only need these the first time around!):
X	mmcomp.sh
X	mmlink.sh
X
XMakefiles for make:
X	makefile  - Alcyon C flavor
X	makefile.mmc - Megamax C flavor
X
XTouch:
X	compiling & linking touch.c will reult in a touch program. touch
X	updates the mod. time of a file to present.
X	Usage: touch file file ......
X
X	#define the symbol MEGAMAX at the top of touch.c is you are
Xgoing to compile touch using the Megamax C compiler.
X
XDocs: (well sort of)
X	readme
X	read.mee
X
X
X	Atari ST specific Information:
X
X    ATARI SPECIAL MACROS:
X
X	Since the Atari St does not have any standard shell, I have built in
Xthree macros that are useful:
X
X	$(RM)	- removes one or more files, Wild Cards Allowed
X	$(CP)   - copies one file to another. NO directories allowed,
X		  will only accept two arguments, both of which
X		  must be files. If the destination file exists, it
X	          will be overwritten.
X	$(ECHO) - echo's its arguements.
X
X	All atari special commands internally begin with the character '%'
X	and are handled by routines in ststuff.c. It should be trivial to
X	add other Atari Special commands if you so desire. All other 
X	commands are executed using the Pexec gemdos command, so complete
X	path names must be used.
X
X    CONTINUATION LINES:
X
X	The line continuation character is '\'. Back slashes may appear in
Xpathname, but NOT at the end of a line, as it will be taken as a continuation
Xbackslash, and not as a part of the pathname. This should not create any big
Xproblem as far as i can see.
X
X
X    DEFAULT RULES:
X
X	See the file RULES.C. I have built in default rules for '.c.o'
Xfor both Alcyon C and Megamax C. But since both use the same '.o' suffix,
Xonly one may be built into the version of make that you compile. Which
Xversion gets built into make depends on the Pre Processor symbol
X'MEGRULES'. If this symbol is defined (see H.H) then Megamax rules get
Xbuilt in. If it is not, then Alcyon rules get built in. All the rules
Xare based on values of macros defined in RULES.C. These macros may be
Xredefined in a makefile, and when the default rule is expanded by make
Xat runtime, the new redefined values will be used instead. Note that the default
Xrule may not be redefined in a makefile. Make will give an error. The only
Xway to redefine the default rule is to edit RULES.C and recompile and link.
XThe values i have used in RULES.C are relevant for our setup. You will
Xprobably want to edit them for your setup. The default rules in RULES.C are
Xas follows:
X
X	.SUFFIXES: .prg .68k .o .bin .s .c .pas
X
X	Alcyon C defult rules (if MEGRULES is not defined):
X	/* Alcyon C and AS68 rules */
X
X	/* Path to the Alcyon C executables */
X	setmacro("CPATH","c:\\bin");
X
X	/* C preprocessor	   */
X	setmacro("CP68", "cp68.prg");
X	/* C preprocessor flags    */
X	setmacro("CPFLAGS", "-i c:\\include\\");
X
X	/* Pass 1 of the C compiler */
X	setmacro("C068", "c068.prg");
X	/* Pass 1 flags		   */
X	setmacro("C0FLAGS", "-f"); /* change to "" if you want to use IEEE
X				    * floating point and libm instead of libf
X				    * by Default. Otherwise simply redefine
X				    * C0FLAGS in your makefile to get the
X				    * IEEE floating option.
X				    */
X
X	/* Pass 2 of the C compiler */
X	setmacro("C168","c168.prg");
X	/* Pass 2  flags	    */
X	/* setmacro("C1FLAGS", ""); */	/* Save ourselves some space */
X
X	/* Assembler		    */
X	setmacro("AS","as68.prg");
X	/* Assembler flags	    */
X	setmacro("ASFLAGS","-l -u -s c:\\bin\\");
X
X	.c.o:
X		$(CPATH)\$(CP68) $(CPFLAGS) $< $*.i
X		$(CPATH)\$(C068) $*.i $*.1 $*.2 $*.3 $(C0FLAGS)
X		$(RM) $*.i
X		$(CPATH)\$(C168) $*.1 $*.2 $*.s $(C1FLAGS)
X		$(RM) $*.1 $*.2
X		$(CPATH)\$(AS) $(ASFLAGS) $*.s
X		$(RM) $*.s
X
X	.s.o:
X		$(CPATH)\$(AS) $(ASFLAGS) $<
X
X	/* Linker of choice */
X	setmacro("LINKER", "c:\\bin\\link68.prg");
X
X	/* Relmod */
X	setmacro("RELMOD", "c:\\bin\\relmod.prg");
X
X
X     Megamax C default rules (if MEGRULES is defined):
X
X	/* Megamax C Rules default */
X
X	/* Path to the Megamax C executables */
X	setmacro("CPATH","c:\\bin");
X
X	/* C Compiler	   */
X	setmacro("MMCC", "mmcc.ttp");
X
X	/* Code Optimizer	    */
X	setmacro("MMIMP","mmimp.ttp");
X
X	.c.o:
X		$(CPATH)\$(MMCC) $<
X		$(CPATH)\$(MMIMP) $*.o
X
X	/* Linker of choice */
X	setmacro("LINKER", "$(CPATH)\\mmlink.ttp");
X
X	I have not defined any default '.pas.bin' rule for Oss Pascal, but
Xthat should be easy to add.
X
X
X    How to Compile Make:
X
X	Edit the file H.H. If you want to use the Megamax C compiler 
Xuncomment the line /* #define MEGAMAX */ to define the symbol 'MEGAMAX'. If
Xyou are using the Alcyon C compiler, leave the line commented out. Edit the 
Xfile RULES.C and the symbol 'MEGRULES' in H.H for your taste. If you have
Xthe beckmeyer C shell and my version of CC (posted to the net long ago) then
Xyou may use the shell scripts
X	compile.sh and link.sh - for Alcyon C
Xor
X	mmcomp.sh and mmlink.sh - for Megamax C
X
XIf you don't have CC or microCshell, then you will have to use these scripts
Xas guideline.
X
X    Once make.prg is made, you can safely throw away all the shell scripts!!
XIf you intend to use make from the desktop, rename it to make.ttp.
X
X	
X	This program is fully in the Public Domain, and you are encouraged
Xto distribute copies of the program. Your comments/criticisms/fixes etc.
Xwill be very much appreciated. I am however  not responsible for any bugs
Xand/or correctness of behavior of the program. No part of this distribution may
Xbe used for commercial gains.
X
X				Send your comments to:
X
X					Jwahar R. Bammi
X			       Usenet:  .....!decvax!cwruecmp!bammi
X			        CSnet:  bammi@case
X				 Arpa:  bammi%case@csnet-relay
X			   CompuServe:  71515,155
X
SHAR_EOF
if test 5969 -ne "`wc -c 'readme'`"
then
	echo shar: error transmitting "'readme'" '(should have been 5969 characters)'
fi
echo shar: extracting "'rules.c'" '(6877 characters)'
if test -f 'rules.c'
then
	echo shar: over-writing existing file "'rules.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'rules.c'
X#define ATARIST
X
X	/*******************************************************\
X	*							*
X	*	A full featured MAKE Clone			*
X	*							*
X	*	Origional Author: (Thank You)			*
X	*	    Neil Russell				*
X	*	    ACSnet:  caret@tictoc.oz			*
X	*	    UUCP:  ...!seismo!munnari!tictoc.oz!caret	*
X	*	    ARPA:  caret%tictoc.oz@seismo.arpa		*
X	*							*
X	*	Atari St Port & C code cleanup:			*
X	*	    Jwahar R. Bammi				*
X	*	    UUCP:  .....!decvax!cwruecmp!bammi		*
X	*	   CSNET:  bammi@case				*
X	*	    ARPA:  bammi%case@csnet-relay		*
X	*     CompuServe:  71515,155				*
X	*							*
X	\*******************************************************/
X		    
X
X/*
X *	Control of the implicit suffix rules
X */
X#include <stdio.h>
X#include "h.h"
X
X/* 
X * These definitions were added to get the types RIGHT - JRB
X *	Please people - don't assume sizeof(pointer) == sizeof(int)
X */
X
X#define Newline(X,Y,Z) newline((struct name *)X, (struct depend *)Y,\
X			       (struct cmd *)Z)
X
X#define Newcmd(X,Y)    newcmd((char *)X, (struct cmd *)Y)
X
X#define Newdep(X,Y)    newdep((struct name *)X, (struct depend *)Y)
X
X	/* When, Oh when will people stop abusing C ! */
X
X
X/*
X *	Return a pointer to the suffix of a name
X */
Xchar *
Xsuffix(name)
Xchar *			name;
X{
X	extern char *rindex();
X
X	return rindex(name, '.');
X}
X
X
X/*
X *	Dynamic dependency.  This routine applies the suffis rules
X *	to try and find a source and a set of rules for a missing
X *	target.  If found, np is made into a target with the implicit
X *	source name, and rules.  Returns TRUE if np was made into
X *	a target.
X */
Xbool
Xdyndep(np)
Xstruct name *		np;
X{
X	register char *		p;
X	register char *		q;
X	register char *		suff;		/*  Old suffix  */
X	register char *		basename;	/*  Name without suffix  */
X	struct name *		op;		/*  New dependent  */
X	struct name *		sp;		/*  Suffix  */
X	struct line *		lp;
X	struct depend *		dp;
X	char *			newsuff;
X
X
X	p = str1;
X	q = np->n_name;
X	if((suff = suffix(q)) == (char *)NULL)
X		return FALSE;	/* File does'nt have a suffix */
X	while (q < suff)
X		*p++ = *q++;
X	*p = '\0';
X	basename = ((struct macro *)(setmacro("*", str1)))->m_val;
X
X	if (!(((sp = newname(".SUFFIXES"))->n_flag) & N_TARG))
X		return FALSE;
X
X	for (lp = sp->n_line; lp; lp = lp->l_next)
X		for (dp = lp->l_dep; dp; dp = dp->d_next)
X		{
X			newsuff = dp->d_name->n_name;
X			if (strlen(suff)+strlen(newsuff)+1 >= LZ)
X				fatal("Suffix rule too long");
X			p = str1;
X			q = newsuff;
X			while (*p++ = *q++)
X				;
X			p--;
X			q = suff;
X			while (*p++ = *q++)
X				;
X			sp = newname(str1);
X			if (sp->n_flag & N_TARG)
X			{
X				p = str1;
X				q = basename;
X				if (strlen(basename) + strlen(newsuff)+1 >= LZ)
X					fatal("Implicit name too long");
X				while (*p++ = *q++)
X					;
X				p--;
X				q = newsuff;
X				while (*p++ = *q++)
X					;
X				op = newname(str1);
X				if (!op->n_time)
X					modtime(op);
X				if (op->n_time)
X				{
X					dp = Newdep(op, 0);
X					Newline(np, dp, sp->n_line->l_cmd);
X					setmacro("<", op->n_name);
X					return TRUE;
X				}
X			}
X		}
X	return FALSE;
X}
X
X#ifdef ATARIST
X/* Default rules for Atari St
X *
X * These rules have been tuned for the setup @ Case Western Reserve U.
X * you will probably have to change it for your installation.
X *
X */
X
Xvoid
Xmakerules()
X{
X	struct cmd *		cp;
X	struct name *		np;
X	struct depend *		dp;
X
X	/* Atari special internal (to make) commands */
X	setmacro("RM","%r");	/* Remove, any number of args, Wildcards OK */
X	setmacro("CP","%c");	/* Copy file to file only     */
X	setmacro("ECHO","%e");	/* Echo Arguement	      */
X
X#ifndef MEGRULES
X	/* Alcyon C and AS68 rules */
X
X	/* Path to the Alcyon C executables */
X	setmacro("CPATH","c:\\bin");
X
X
X	/* C preprocessor	   */
X	setmacro("CP68", "cp68.prg");
X	/* C preprocessor flags    */
X	setmacro("CPFLAGS", "-i c:\\include\\");
X
X	/* Pass 1 of the C compiler */
X	setmacro("C068", "c068.prg");
X	/* Pass 1 flags		   */
X	setmacro("C0FLAGS", "-f"); /* change to "" if you want to use IEEE
X				    * floating point and libm instead of libf
X				    * by Default. Otherwise simply redefine
X				    * C0FLAGS in your makefile to get the
X				    * IEEE floating option.
X				    */
X
X	/* Pass 2 of the C compiler */
X	setmacro("C168","c168.prg");
X	/* Pass 2  flags	    */
X	/* setmacro("C1FLAGS", ""); */	/* Save ourselves some space */
X
X	/* Assembler		    */
X	setmacro("AS","as68.prg");
X	/* Assembler flags	    */
X	setmacro("ASFLAGS","-l -u -s c:\\bin\\");
X
X	/* Now make up the command lines */
X	cp = Newcmd("$(CPATH)\\$(CP68) $(CPFLAGS) $< $*.i", NULL);
X	cp = Newcmd("$(CPATH)\\$(C068) $*.i $*.1 $*.2 $*.3 $(C0FLAGS)", cp);
X	cp = Newcmd("$(RM) $*.i", cp);
X	cp = Newcmd("$(CPATH)\\$(C168) $*.1 $*.2 $*.s $(C1FLAGS)", cp);
X	cp = Newcmd("$(RM) $*.1 $*.2",cp);
X	cp = Newcmd("$(CPATH)\\$(AS) $(ASFLAGS) $*.s", cp);
X	cp = Newcmd("$(RM) $*.s", cp);
X	np = newname(".c.o");
X	Newline(np, 0, cp);
X
X	/* Rules for Alcyon Assembler */
X	cp = Newcmd("$(CPATH)\\$(AS) $(ASFLAGS) $<", NULL);
X	np = newname(".s.o");
X	Newline(np, 0, cp);
X
X	/* Linker of choice */
X	setmacro("LINKER", "c:\\bin\\link68.prg");
X
X	/* Relmod */
X	setmacro("RELMOD", "c:\\bin\\relmod.prg");
X
X#else
X	/* Megamax C Rules default */
X
X	/* Path to the Megamax C executables */
X	setmacro("CPATH","c:\\bin");
X
X
X	/* C Compiler	   */
X	setmacro("MMCC", "mmcc.ttp");
X
X	/* Code Optimizer	    */
X	setmacro("MMIMP","mmimp.ttp");
X
X	/* Now make up the command lines */
X	cp = Newcmd("$(CPATH)\\$(MMCC) $<", NULL);
X	cp = Newcmd("$(CPATH)\\$(MMIMP) $*.o", cp);
X	np = newname(".c.o");
X	Newline(np, 0, cp);
X
X	/* Linker of choice */
X	setmacro("LINKER", "$(CPATH)\\mmlink.ttp");
X
X#endif /* MEGRULES */
X
X	/* Predefined suffixes */
X	np = newname(".prg");
X	dp = Newdep(np, NULL);
X	np = newname(".68k");
X	dp = Newdep(np, dp);
X	np = newname(".o");
X	dp = Newdep(np, dp);
X	np = newname(".bin");
X	dp = Newdep(np, dp);
X	np = newname(".s");
X	dp = Newdep(np, dp);
X	np = newname(".c");
X	dp = Newdep(np, dp);
X	np = newname(".pas");
X	dp = Newdep(np, dp);
X	np = newname(".SUFFIXES");
X	Newline(np, dp, 0);
X
X
X}
X
X#else	
Xvoid
Xmakerules()
X{
X	struct cmd *		cp;
X	struct name *		np;
X	struct depend *		dp;
X
X
X	setmacro("BDSCC", "asm");
X	/*	setmacro("BDSCFLAGS", "");	*/
X	cp = Newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", 0);
X	np = newname(".c.o");
X	Newline(np, 0, cp);
X
X	setmacro("CC", "c");
X	setmacro("CFLAGS", "-O");
X	cp = Newcmd("$(CC) $(CFLAGS) -c $<", 0);
X	np = newname(".c.obj");
X	Newline(np, 0, cp);
X
X	setmacro("M80", "asm -n");
X	/*	setmacro("M80FLAGS", "");	*/
X	cp = Newcmd("$(M80) $(M80FLAGS) $<", 0);
X	np = newname(".mac.o");
X	Newline(np, 0, cp);
X
X	setmacro("AS", "zas");
X	/*	setmacro("ASFLAGS", "");	*/
X	cp = Newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", 0);
X	np = newname(".as.obj");
X	Newline(np, 0, cp);
X
X	np = newname(".as");
X	dp = Newdep(np, 0);
X	np = newname(".obj");
X	dp = Newdep(np, dp);
X	np = newname(".c");
X	dp = Newdep(np, dp);
X	np = newname(".o");
X	dp = Newdep(np, dp);
X	np = newname(".mac");
X	dp = Newdep(np, dp);
X	np = newname(".SUFFIXES");
X	Newline(np, dp, 0);
X}
X#endif /* Atari ST */
SHAR_EOF
if test 6877 -ne "`wc -c 'rules.c'`"
then
	echo shar: error transmitting "'rules.c'" '(should have been 6877 characters)'
fi
echo shar: extracting "'ststuff.c'" '(6282 characters)'
if test -f 'ststuff.c'
then
	echo shar: over-writing existing file "'ststuff.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'ststuff.c'
X#define ATARIST
X
X	/*******************************************************\
X	*							*
X	*	A full featured MAKE Clone			*
X	*							*
X	*	Origional Author: (Thank You)			*
X	*	    Neil Russell				*
X	*	    ACSnet:  caret@tictoc.oz			*
X	*	    UUCP:  ...!seismo!munnari!tictoc.oz!caret	*
X	*	    ARPA:  caret%tictoc.oz@seismo.arpa		*
X	*							*
X	*	Atari St Port & C code cleanup:			*
X	*	    Jwahar R. Bammi				*
X	*	    UUCP:  .....!decvax!cwruecmp!bammi		*
X	*	   CSNET:  bammi@case				*
X	*	    ARPA:  bammi%case@csnet-relay		*
X	*     CompuServe:  71515,155				*
X	*							*
X	\*******************************************************/
X		    
X
X/*
X *
X * ststuff.c - Retrofit routines
X *             for the Atari St's
X *
X */
X
X#ifdef ATARIST
X#include <stdio.h>
X#include <ctype.h>
X#include "h.h"
X#include "astat.h"
X
X/*
X * Get file statistics - sort of like stat(2)
X */
X
Xint getstat(fname, buf)
Xregister char *fname;
Xregister struct stat *buf;
X{
X	register struct stat *save_dta;
X	register int status;
X
X	/* Save old DTA */
X	save_dta = (struct stat *)Fgetdta();
X
X	/* set the new DTA */
X	Fsetdta(buf);
X
X	/* Find file stat */
X	status = Fsfirst(fname, 0);
X
X	/* reset dta */
X	Fsetdta(save_dta);
X	
X	/* return status */
X	return (status == 0) ? 0 : -1;
X	
X}
X
X
X/*
X * system
X *	execute a command and return status
X */
Xint system(cmd)
Xregister char *cmd;
X{
X	char command[128], tail[130];
X	register char *p, *save;
X	register int n;
X
X	if(*cmd == '%')
X		/* Atari special internal command */
X		return st_special(cmd);
X
X	/* Break up command into command and command tail */
X	for(p = save = command; !isspace(*cmd); *p++ = *cmd++) /* copy */;
X	*p = '\0';
X
X	while(isspace(*cmd)) cmd++; /* skip blanks */
X	if((n = strlen(cmd)) > 128)
X	{
X		fprintf(stderr,"Command '%s' too long\n",save);
X		return -1;
X	}
X
X	tail[0] = (char) n;
X	strcpy(&tail[1],cmd);
X
X	return (int)Pexec(0,command, tail, (char *)NULL);
X}
X
X/*
X * Atari St special commands
X *
X */
Xint st_special(cmd)
Xregister char *cmd;
X{
X	extern int rm(), cp();
X
X	switch(cmd[1])
X	{
X	    case 'r':
X	    case 'R': /* remove */
X		return rm(&cmd[2]);
X		
X	    case 'c':
X	    case 'C': /* copy */
X		return cp(&cmd[2]);
X
X	    case 'e':
X	    case 'E':
X		return echo(&cmd[2]);
X		
X	    default:
X		fprintf(stderr,"Warning: '%s' - Unknown Atari Special Command\n",
X			cmd);
X	}
X	return 0;
X}
X
X/*
X * remove file(s)
X *
X */
Xint rm(list)
Xregister char *list;
X{
X	char name[128];
X	register char *p;
X
X	while((!isspace(*list)) && (*list != '\0')) list++;
X	while(*list != '\0')
X	{
X		while(isspace(*list)) list++;
X
X		for(p = name; !isspace(*list) && (*list != '\0');
X		    *p++ = *list++) /* copy */;
X		*p = '\0';
X
X		if(p != name)
X			remove(name);	 /* never mind the return value
X					  * we are doing 'rm -f'
X					  */
X	}
X	return 0;
X}
X
X
X#define iswild(F) ((index(F,'*') != (char *)NULL) || (index(F,'?') != (char *)NULL))
X
X/*
X * this routine actually removes the files, dealing with wildcards
X *
X */
Xremove(filename)
Xregister char *filename;
X{
X	register struct stat *save_dta;
X	struct stat buf;
X	char fbuf[128];
X	char pbuf[128];
X	register char *path, *p;
X	extern char *strcpy(), *strcat(), *index(), *rindex();
X
X	if(!iswild(filename))
X	{
X		/* not a wild card */
X		unlink(filename);
X		return;
X	}
X
X	/* Wild Card */
X	if((p = rindex(filename,'\\')) != (char *)NULL)
X	{
X		register char *q;
X
X		/* Pick up path */
X		p++;
X		for(path = pbuf, q= filename; q != p; *path++ = *q++) /* Copy */;
X		*path = '\0';
X		path = pbuf;
X	}
X	else
X		/* No path */
X		path = (char *)NULL;
X
X	/* Save old DTA */
X	save_dta = (struct stat *)Fgetdta();
X
X	/* set the new DTA */
X	Fsetdta(&buf);
X
X	/* Unlink the first match for wild card */
X	if(Fsfirst(filename, (0x01 | 0x010 | 0x020)) != 0)
X		/* No such file(s), simply return */
X			return;
X
X	unlink ( (path == (char *)NULL) ? buf.st_sp2
X		  : strcat(strcpy(fbuf, path), buf.st_sp2) );
X
X	/* Unlink any other match(s) for wild card */
X	while(Fsnext() == 0)
X		/* rest of them */
X		unlink ( (path == (char *)NULL) ? buf.st_sp2
X			  : strcat(strcpy(fbuf, path), buf.st_sp2) );
X
X	/* reset dta */
X	Fsetdta(save_dta);
X}	
X
X/*
X * copy files
X *
X */
Xint cp(list)
Xregister char *list;
X{
X	char source[128], dest[128];
X	char buf[512];
X	register char *p;
X	register int fsource, fdest;
X	register long count;
X
X	while((!isspace(*list)) && (*list != '\0')) list++;
X	while(isspace(*list)) list++;
X	if(*list == '\0')
X	{
X		/* no source specified */
X		fprintf(stderr,"Usage: ${CP} <source file> <destination file>\n");
X		return 1;
X	}
X
X	for(p = source; !isspace(*list) && (*list != '\0'); *p++ = *list++) /* copy */;
X	*p = '\0';
X
X	while(isspace(*list)) list++;
X	if(*list == '\0')
X	{
X		/* no destination specified */
X		fprintf(stderr,"Usage: ${CP} <source file> <destination file>\n");
X		return 2;
X	}
X
X	for(p = dest; !isspace(*list) && (*list != '\0'); *p++ = *list++) /* copy */;
X	*p = '\0';
X
X	if(*list != 0)
X	{
X		fprintf(stderr,"Only 2 parameters allowed\nUsage: $(CP) <source file> <destination file>\n");
X		return 6;
X	}
X	
X
X	if((fsource = Fopen(source, 0)) < 0)
X	{
X		fprintf(stderr,"%s: no such file\n", source);
X		return 3;
X	}
X
X	if((fdest = Fcreate(dest, 0)) < 0)
X	{
X		/* May already exist */
X		if((fdest = Fopen(dest, 1)) < 0)
X		{
X			fprintf(stderr,"%s: cannot open for write\n", dest);
X			Fclose(fsource);
X			return 4;
X		}
X	}
X
X	while((count = Fread(fsource, 512L, buf)) > 0)
X	{
X		if(Fwrite(fdest, count, buf) != count)
X		{
X			fprintf(stderr,"Error writing %s\n", dest);
X			Fclose(fsource);
X			Fclose(fdest);
X			return 5;
X		}
X	}
X
X	Fclose(fsource);
X	Fclose(fdest);
X	
X	return 0;
X}
X
X/*
X * Echo arguements
X *
X */
Xint echo(list)
Xregister char *list;
X{
X	while((!isspace(*list)) && (*list != '\0')) list++;
X
X	if(*list != '\0')
X	{
X		while(isspace(*list)) list++;
X		printf("%s\n",list);
X	}
X	
X	return 0;
X}
X
X	
X/*
X * rtime - stuff current time & date into long (ptr passed)
X *
X */
Xrtime(t)
Xlong *t;
X{
X
X	*t = Gettime();	/* Ikbd's time */
X}
X
X/*
X * Flips Word of a long, used to get the date into the Higher order bits,
X * and time into the lower order bits of a long, so that comparisons can
X * later be done using a simple C relational operator.
X *
X */
Xvoid
XFlipWords(i)
X#ifdef MEGAMAX
Xunsigned i[];
X#else
Xunsigned int i[];
X#endif /* MEGAMAX */
X{
X#ifdef MEGAMAX
X	register unsigned  temp;
X#else
X	register unsigned int temp;
X#endif /* MEGAMAX */
X	
X	temp = i[0];
X	i[0] = i[1];
X	i[1] = temp;
X}
X	
X#endif /* ATARIST */
SHAR_EOF
if test 6282 -ne "`wc -c 'ststuff.c'`"
then
	echo shar: error transmitting "'ststuff.c'" '(should have been 6282 characters)'
fi
echo shar: extracting "'touch.c'" '(1194 characters)'
if test -f 'touch.c'
then
	echo shar: over-writing existing file "'touch.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'touch.c'
X/* #define MEGAMAX */	/* Define if using Megamax C */
X
X			/*******************************\
X		        *	Touch.c		        *
X			*			        *
X		        *	 Change last mod time   *
X			*        of args. to present.   *
X			*			        *
X			*	Jwahar R. Bammi	        *
X			*			        *
X			\*******************************/
X
X#include <osbind.h>
X
X#ifdef MEGAMAX
X#undef Fdatime		/* Megamax has it incorrectly defined */
X#define	Fdatime(a,b,c)	gemdos(0x57,a,b,c)
X#endif /* MEGAMAX */
X
X
Xmain(argc, argv)
Xregister int argc;
Xregister char **argv;
X{
X	while(--argc)
X		touch(*++argv);
X}
X
Xtouch(file)
Xregister char *file;
X{
X	register int	fd;
X
X	if ((fd = Fopen(file, 0)) < 0)
X	{
X		Cconws("Touch: '");
X		Cconws(file);
X		Cconws("' not touched - non-existant\r\n");
X	}
X	else
X	{
X		long tim;
X
X		Fseek(0L, fd, 2); /* Seek to EOF */
X		tim = Gettime();
X		FlipWords(&tim);
X		Fdatime( &tim, fd,  1); /* This time the Hitch Hikers
X					 * guide is wrong
X				         */
X		Fclose(fd);
X
X	}
X}
X
XFlipWords(i)
X#ifdef MEGAMAX
Xunsigned i[];
X#else
Xunsigned int i[];
X#endif /* MEGAMAX */
X{
X#ifdef MEGAMAX
X	register unsigned  temp;
X#else
X	register unsigned int temp;
X#endif /* MEGAMAX */
X	
X	temp = i[0];
X	i[0] = i[1];
X	i[1] = temp;
X}
SHAR_EOF
if test 1194 -ne "`wc -c 'touch.c'`"
then
	echo shar: error transmitting "'touch.c'" '(should have been 1194 characters)'
fi
#	End of shell archive
exit 0
-- 
					Jwahar R. Bammi
 		        Usenet:  .....!decvax!cwruecmp!bammi
		        CSnet:  bammi@case         Arpa:  bammi%case@csnet-relay
			CompuServe:  71515,155