[comp.sys.atari.st] A fix to the "outdated ranlib" problem

minow@decvax.UUCP (Martin Minow) (12/16/86)

The enclosed program changes the date of all .a files in the \lib
directory, so they will be earlier than the "ranlib" update date.
Note that the description of Fdatime() in the Mark Williams C
manual and GSDTOF in the Abacus "Internals" book is incorrect.

Martin Minow
decvax!minow

----- Cut here -----

/*
 * This program hacks the date of all lib\*.a files so that the
 * Mark Williams linker doesn't get "outdated ranlib" errors.
 * It is used after the shell has initialized the ramdisk on boot.
 * The relevant parts of my profile file are as follows:
 *	set sysdrive=a:
 *	set usrdrive=b:
 *	set tmpdrive=d:				<-- ramdisk
 *	mkdir $tmpdrive\bin			<-- create ramdisk bin
 *	mkdir $tmpdrive\lib			<-- and ramdisk lib
 *	cp $sysdrive\lib\libc.a $tmpdrive\lib	<-- copy C library
 *	... other copies ...
 *	setenv ...
 *	cd $tmpdrive				<-- now on ramdisk
 *	fixranlib				<-- fix libc.a
 *
 * Copyright (c) 1986, Martin Minow, Arlington MA.  This program may be
 * freely used, copied, and redistributed so long as this copyright notice
 * is left intact and the program is not sold for direct personal gain.
 */

#if 0 && MAKEFILE
fixranlib:
	cc fixranlib.c -o fixranlib.prg
#endif

#include <osbind.h>

typedef struct {
    unsigned char dma_reserved[21];	/* Reserved for TOS		*/
    unsigned char dma_type;		/* File type flags		*/
    unsigned short dma_time;		/* Creation time		*/
    unsigned short dma_date;		/* Creation date		*/
    unsigned long dma_size;		/* File size in bytes		*/
    unsigned char dma_name[14];		/* File name			*/
} DMA_buffer;

#define FT_NORM	(0x00)			/* Normal file access		*/
#define FT_PROT (0x01)			/* Write protected		*/
#define FT_HIDE (0x02)			/* Hidden files			*/
#define FT_SYS	(0x04)			/* System files			*/
#define	FT_VOL	(0x08)			/* Volume-label files		*/
#define FT_SUB	(0x10)			/* Subdirectory			*/
#define FT_WRTC	(0x20)			/* Written to and closed	*/

#define E_OK	(0L)			/* All ok, no errors		*/
#define E_FILNF	(-33)			/* File not found		*/
#define E_PTHNF	(-34)			/* Path not found		*/
#define	E_NMFIL	(-49)			/* No more files		*/

/*
 * Warning, date_time is modified by Fdatime().
 */
/*			   year-1980    month   date			*/
int	model_date[2] = { 0, (0 << 9) + (1 << 5) + 1 };
int	date_time[2];

main()
{
	DMA_buffer	dma_block;
	register int	status;
	register int	handle;
	char		work[32];

	Fsetdta(&dma_block);		/* Setup the DMA buffer area	*/
	if ((status = Fsfirst("lib\\*.a", FT_NORM)) != E_OK)
	    fatal(status, "lib\\*.a", "getting first file");
	else {
	    do {
		strcpy(work, "LIB\\");
		strcat(work, dma_block.dma_name);
		Cconws(work);
		Cconws("\r\n");
		if ((handle = Fopen(work, 0)) < 0)
		    errorprint(handle, work, "opening file");
		else {
		    date_time[0] = model_date[0];
		    date_time[1] = model_date[1];
		    /*
		     * The book says 0 sets and 1 gets.
		     * The book is wrong.
		     */
		    Fdatime(date_time, handle, 1);
		    if ((status = Fclose(handle)) != E_OK)
			fatal(status, work, "closing file");
		}
	    } while ((status = Fsnext()) == E_OK);
	    if (status != E_NMFIL)
		fatal(status, "lib\\*.a", "getting next file");
	}
	exit(0);
}

fatal(status, what, where)
int		status;
char		*what, *where;
{
	errorprint(status, what, where);
	exit(1);
}

errorprint(status, what, where)
register int		status;
char			*what, *where;
{
	char		work[6];
	register char	*wp;
	register int	negflag;

	Cconws(what);
	Cconws(": ");
	if (status == E_FILNF)
	    Cconws("File not found");
	else if (status == E_PTHNF)
	    Cconws("Directory not found");
	else {
	    wp = work + sizeof work;
	    *--wp = '\0';
	    if ((negflag = (status < 0)))
		status = -status;
	    do {
		*--wp = (status % 10) + '0';
		status /= 10;
	    } while (wp > work && status != 0);
	    Cconws("Unexpected error: ");
	    if (negflag)
		Cconout('-');
	    Cconws(wp);
	}
	Cconws(" when ");
	Cconws(where);
	Cconws(".\r\n");
}