/*  Program: AZMOD
 *   Author: Lawrence W. Esker          Compuserve ID: 76337,2524
 * Compiler: Manx Aztec C, version 3.20a
 *
 * Modification History:
 *      Version 1.0     March 07, 1987    Initial release.
 *
 *
 * Notice: This program is placed in Public Domain. You may use it, abuse it
 * and confuse it to your hearts content. No responsibility will be taken on
 * my part.
 *
 *
 * This program will modify Aztec C version 3.20a compiler, make, debugger,
 * and libraries for use under AmigaDos 1.2.  Almost!  The files will not
 * follow the 1.2 path.  To get around this in "make", either specify full
 * path names, or assign c: to the directory containing "cc", "as", and
 * "make".  For those of us with three drives, this allows us to keep the
 * compiler related files off the workbench disk by including the aztec disk
 * in the "path".
 *
 * The following files from your Aztec C disk will be modified:
 *
 *          cc    make    db    c.lib    c32.lib
 *
 * REMEMBER!  The files fixed by this program WILL NO LONGER WORK under
 * AmigaDos 1.1!  Almost.  The compiler itself works, but it will not be
 * able to automatically invoke the assembler.  This can be bypassed by
 * creating a .c.o rule in "make" similar to:
 *
 *      .c.o:
 *          Aztec:c/cc -A -T -O ram:$*.asm $*.c
 *          Aztec:c/as -O $@ ram:$*.asm
 *
 * If you need to use "make" or "db" under either 1.1 or 1.2, keep an
 * unmodified version in your 1.1 c: directory.  The library fixes effect
 * only the "exec" and "fexec" series functions.  As long as these are not
 * used in your program, it should work under either 1.1 or 1.2.
 *
 * In preparation to execute this program:
 *
 *   1.  Make a copy of the distribution disk.
 *   2.  Copy the 32 bit library, "c32.lib", to the lib directory
 *   3.  Change default to the drive containing the disk to modify.
 *   4.  Run the program.
 *
 * After running the program, you can restructure the disk as your 1.2
 * compiler work disk and compile away.  Be sure to re-link any files which
 * use the "exec" or "fexec" series functions (such as the PD make program,
 * or Matt Dillon's "Shell") using the libraries which this program has
 * modified.
 *
 * Manx and Aztec are Copyrights of Manx Software Systems Inc.
*/
#include <stdio.h>
#include <fcntl.h>

main()
{
    printf("Modifying Manx Aztec C ver 3.20a for Kickstart ver 1.2 {\n");
    fix("c/cc",       0xD51FL,0L);
    fix("c/db",       0x67A9L,0L);
    fix("c/make",     0x1D37L,0x2063L,0L);
    fix("lib/c.lib",  0x2CF0L,0x303EL,0x348AL,0L);
    fix("lib/c32.lib",0x2E38L,0x3176L,0x35BEL,0L);
    printf("}\n\n");
}


fix(file,address)
char *file;
long address;
{
    int fd,i;
    long *addr;

    addr = &address;
    printf("    Fixing %s... ",file);
    fflush(stdout);

    if ((fd=open(file,O_RDWR)) == -1) {
        printf("\x9B1;33;40mERROR, Open failed\x9B0;31;40m\n");
        return();
    }

    for (i=0;addr[i]!=0;i++) {
        lseek(fd,addr[i],0);
        if (write(fd,"\xa8",1) == -1) {
            printf("\x9B1;33;40mERROR, Write failed\x9B0;31;40m\n");
            close(fd);
            return();
        }
    }

    close(fd);
    printf("Done!\n");
}
