//**************************
//
//  Prefs.c
//
//**************************

//**** Header files

#include <workbench/workbench.h>
#include <workbench/startup.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/icon_protos.h>

#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/icon_pragmas.h>

#include <string.h>
#include <stdlib.h>
//#include <stdio.h>

#include "Librarian.h"
#include "Prefs.h"


//**** Local Storage

char *ToolsFileName;
char *ToolsArcName;
char *PrefsProgName;
char *PrefsProgDir;
LONG my_cx_pri=0L;


//**** Function Prototypes


//**** Module Routines

int ReadIcon(int argc, char **argv) {
  struct WBStartup *wbs;
  char **toolArray;
  char *value;
  BPTR oldp;
  struct DiskObject *dobj;

  if (0==argc) { // started from Workbench
    wbs=(struct WBStartup *)argv;

    // move to program dir, and try to get the icon
    oldp=CurrentDir(wbs->sm_ArgList->wa_Lock);
    if (dobj=GetDiskObject(wbs->sm_ArgList->wa_Name)) {
       toolArray=dobj->do_ToolTypes;

       if (value=FindToolType(toolArray,"CX_PRIORITY"))
         StrToLong(value,&my_cx_pri);

       value=FindToolType(toolArray,"TOOLSFILE");
       if (NULL==value) value="ENV:EasyTM.Config";
       ToolsFileName=strcpy(AllocVec(strlen(value)+1,NULL),value);

       value=FindToolType(toolArray,"TOOLSARC");
       if (NULL==value) value="ENVARC:EasyTM.Config";
       ToolsArcName=strcpy(AllocVec(strlen(value)+1,NULL),value);

       value=FindToolType(toolArray,"PREFSPRG");
       if (NULL==value) value="SYS:Prefs/EasyTM-Prefs";
       PrefsProgDir=strcpy(AllocVec(strlen(value)+1,NULL),value);
       PrefsProgName=FilePart(PrefsProgDir);
       value=PathPart(PrefsProgDir);
       *value=0;

       FreeDiskObject(dobj);
    } // if GetDiskObject
    CurrentDir(oldp);
    return 1;
  } else { // started from SHELL
    FPuts( Output(), "This should be started from the workbench\n" );
    return 0;
  } // if 0==argc
} // ReadIcon

//**** End of file
