#include <proto/dos.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <dialog/resman.h>
#include <proto/dlg.h>

extern struct Library *DLGBase;

BOOL DeBug(char *string)
{
  int fp;
  char datestr[22];

  BorrowArea(200,"DB","Debugging",64,MSGLOCK|WRITELOCK);
  if((fp=open("DLGCONFIG:MISC/Debug.log",O_RDWR + O_CREAT))==EOF) {
    FreeArea(200,"DB",MSGLOCK|WRITELOCK);
    return(-1);
  }

  lseek(fp,0L,2);
  MDate(datestr);
  write(fp,datestr,strlen(datestr));
  write(fp,": ",2);
  write(fp,string,strlen(string));
  write(fp,"\n",1);
  close(fp);
  FreeArea(200,"DB",MSGLOCK|WRITELOCK);

  return(0);
}

BOOL SDB(char *string)

{char datestr[22],dbstr[80],Ext[4];
 BPTR ofh;

 Delay(20);
 BorrowArea(200,"DB","Debugging",64,MSGLOCK|WRITELOCK);

 if (!(ofh=(BPTR)Open("SER:",MODE_NEWFILE)))
    {FreeArea(200,"DB",MSGLOCK|WRITELOCK);
     return(FALSE);
    }

 MDate(datestr);
 GetDevName(Ext);

 ASPrintf(NULL, dbstr,"%s: %s: %s\n",Ext,datestr,string);
 Write(ofh,dbstr,(long)strlen(dbstr));

 Delay(20);
 Close(ofh);
 FreeArea(200,"DB",MSGLOCK|WRITELOCK);

 return(0);
}


BOOL PDB(char *string)

{char datestr[22],dbstr[80],Ext[4];
 BPTR ofh;

 BorrowArea(200,"DB","Debugging",64,MSGLOCK|WRITELOCK);

 if (!(ofh=(BPTR)Open("PAR:",MODE_NEWFILE)))
    {FreeArea(200,"DB",MSGLOCK|WRITELOCK);
     return(FALSE);
    }

 MDate(datestr);
 GetDevName(Ext);

 ASPrintf(NULL, dbstr,"%s: %s: %s\n",Ext,datestr,string);
 Write(ofh,dbstr,(long)strlen(dbstr));

 Close(ofh);
 FreeArea(200,"DB",MSGLOCK|WRITELOCK);

 return(0);
}


void Oldb(char *string)

{AFPrintf(NULL, Output(), "%s\n",string);
 getchar();
}
