/************************************************************
  fix.c  By: Stephen Vermeulen

  Copyright (C) 1989 By Stephen Vermeulen

  Use this tool to set the type of an icon.

  It has the following syntax:

      fix file [Detail [Block]]

  when this is typed, fix will load the file called "file.info"
  and if it is a drawer, disk or trashcan type icon will change
  the pen colours used in the borders of the window that workbench
  opens when the disk/drawer/trashcan opens.
************************************************************/

#include <intuition/intuition.h>
#include <workbench/workbench.h>
#include <stdio.h>
#include <functions.h>

#define NO_ICONS       4

extern ULONG IconBase;

/************************************************************
  The following routine just opens the libraries
************************************************************/

short OpenLibs()
{
  short flags; /* any libraries that do not open get recorded here */

  flags = 0;
  IconBase = (ULONG) OpenLibrary("icon.library", 0L);
  if (!IconBase) flags |= NO_ICONS;
  return(flags);
}

void CloseLibs(flags)
short flags;
{
  if (!(flags & NO_ICONS))     CloseLibrary(IconBase);
}

void main(argc, argv)
short argc;
char *argv[];
{
  short lib_flags, icon_type;
  struct DiskObject *dobj, *drawer_obj;
  struct DrawerData *dd_temp;

  if (argc >= 2)
  {
    lib_flags  = OpenLibs();
    if (!lib_flags)
    {
      if (dobj = GetDiskObject(argv[1]))
      {
        if ((dobj->do_Type == 1) || (dobj->do_Type == 2) || (dobj->do_Type == 5))
        {
          /** ok to proceed **/

          if (argc >= 3)
            dobj->do_DrawerData->dd_NewWindow.DetailPen = atoi(argv[2]);
          else
            dobj->do_DrawerData->dd_NewWindow.DetailPen = 2;
          if (argc == 4)
            dobj->do_DrawerData->dd_NewWindow.BlockPen = atoi(argv[3]);
          else
            dobj->do_DrawerData->dd_NewWindow.BlockPen = 3;
          PutDiskObject(argv[1], dobj);
        }
        FreeDiskObject(dobj);
      }
    }
    CloseLibs(lib_flags);
  }
  else
  {
    puts("Syntax is: fix icon [Detail [Block]]");
    puts("  ... don't use the .icon suffix!  Sets the detail and block colours");
    puts("for the borders of WorkBench drawer windows.");
    puts("Written by: Stephen Vermeulen, PO Box 3295, Station B,");
    puts("Calgary, Alberta, CANADA, T2M 4L8.");
  }
}
