/* Do what you want with this stuff, it is so much of a crock that I 
 don't care

  Originally created by Steve Hawtin
 */

/* A quick and dirty hack to unpack the compressed NorthC: disk on
  almost any Amiga */

#include <stdio.h>
#include <ctype.h>
#include <string.h>

/* Set up the console if run from workbench */
char *_WBConsole = "con:0/10/640/180/Unpacking NorthC";

char *message[] =
   {"Unpacking NorthC:\n",
    "You must have already created a blank formatted floppy called\n",
    "\"NorthC\" before you can run this program\n",
    "Make sure all other floppies are write protected.\n\n",
    "Do you want to proceed ?",
    NULL
    };

int
y_or_n()
   {/* Get answer y or n */
    char reply[10];
    fgets(reply,9,stdin);
    reply[0] = toupper(reply[0]);
    while(reply[0]!='Y' && reply[0]!='N')
       {puts("Please answer \"y\" or \"n\" ?");
        fgets(reply,9,stdin);
        reply[0] = toupper(reply[0]);
        }
    return(reply[0]=='Y');
    }
    
main(argc,argv)
    int argc;
    char **argv;
   {
    char *str;
    int second_drive = 0;
    int i;
    char TempName[L_tmpnam];
    FILE *TempFile;

    char from_dir[128];
    char from_disk[128];

    char cmnd[256];

    for(i=0;message[i]!=NULL;i++)
        puts(message[i]);
    if(y_or_n()==0)
        exit(EXIT_FAILURE);
    /* So first find out what type of machine we are on, should do this 
      via the operating system, Lock("df1:") could work... */
    puts("Have you got a second floppy drive (df1:) ?");
    second_drive = y_or_n();

    /* Open file with name of current directory, for some reason 
       system("cd");
       doesn't always work! */
    TempFile = fopen("ThisDir","r");
    fgets(from_dir,128,TempFile);
    fclose(TempFile);
    /* From the directory name work out the disk */
    strcpy(from_disk,from_dir);
    str = strrchr(from_disk,':');
    str++;
    *str = '\0';
    from_dir[strlen(from_dir)-1]='\0';

    /* Now make some assignments so that the script files can use the 
      directories */
    strcpy(cmnd,"assign ThisDir: ");
    strcat(cmnd,from_dir);
    system(cmnd);
    strcpy(cmnd,"assign ThisDisk: ");
    strcat(cmnd,from_disk);
    system(cmnd);

    /* Now run the appropriate script file */
    if(second_drive)
        system("execute ThisDir:Dual-Unpack");
      else
        system("execute ThisDir:Single-Unpack");

    puts("All done!!  Press <Return>.\n");
    getchar();
    }
