🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5317

Re: arp.library file requester

#5317
From: Koshy Abraham
Date: Mon, 17 Sep 1990 11:58
313 lines
9856 bytes
In <8240@helios.TAMU.EDU> aaron@stat.tamu.edu (Aaron Hightower) writes:

>In article <4811@jato.Jpl.Nasa.Gov> zupke@mars.UUCP (Brian Zupke) writes:
>>Howdy!  Could anyone tell me how to use the ARP FileRequester function?  
>>Looking at the documentation (an not having an example) this is not very
>>clear.  BTW I have Manx Aztec 5.0.  An example of its use would be
>>perfect.  Thanks in advance.  
>>
>>-Brian

>/* Example of the arp file-requester (Aaron Hightower)
>   aaron@stat.tamu.edu (128.194.28.1) */

[EXAMPLE DELETED]

Here is some code taken from my EPROM programmer project (which will be posted
to Tad very soon - sorry to all who have been waiting). This example shows how
to call the requester the 1.3 way (I think), i.e. by allocating the file requ-
ester structure - useful for future compatiability. There are a couple of
custom gadgets in the requester and the code shows how to handle these as well.

I've only tried this with Aztec C3.6 so you may need to do some extra work to
get it to work with other compilers, and there are some references to external
variables and routines which you will have to sort-out.

I hope this is what you are looking for.

Note : I've had this working on an A1000 under 1.3 & 1.4b? and on A3000 under
WB2.0.

--EXAMPLE STARTS HERE---

/***************************************************************************
 *
 * FileIO.c - file load save for Eprom Programmer.
 *
 * This file is Copyright (C) June 1989, Koshy Abraham.
 *
 *       //
 *      //
 *  \\ //
 *  K\A/b
 ***************************************************************************/

#include "main.h"		/* mainly #include's like intuition.h etc */
#include "events.h"
#include <stdio.h>
#include <libraries/dos.h>

#define STRINFO_P       struct StringInfo *

extern struct Screen    *MyScreen;
extern struct Window    *MyWindow;
extern struct TextAttr  TOPAZ80;
extern UBYTE *DataStart;	/* My data buffer */
extern ULONG DataSize;		/* Size of buffer in bytes*/

static struct Window *FRWind = NULL;

UBYTE Gadget3SIBuff[8] =
	"1fff";
static struct StringInfo Gadget3SInfo = {
	Gadget3SIBuff,	NULL,	0,	8,	0,	0, 0, 0, 0, 0,	0,	0,	NULL
};

static SHORT BorderVectors1[] = {
	0,0,
	57,0,
	57,9,
	0,9,
	0,0
};
static struct Border Border1 = {
	-1,-1, 2, 0, JAM1, 5, BorderVectors1,NULL
};

static struct IntuiText IText1 = {
	2, 0, JAM1,	-28, 1, NULL, (UBYTE *)"End",	NULL
};

static struct Gadget Gadget3 = {
	NULL,	161, 150, 56, 8, GADGHCOMP, RELVERIFY, STRGADGET,	(APTR)&Border1,
	NULL,	&IText1,	NULL,	(APTR)&Gadget3SInfo,	2000,	NULL
};

UBYTE Gadget2SIBuff[8] =
	"000000";
static struct StringInfo Gadget2SInfo = {
	Gadget2SIBuff,	NULL,	0,	8,	0,	0, 0, 0, 0, 0,	0,	0,	NULL
};

static SHORT BorderVectors2[] = {
	0,0,
	57,0,
	57,9,
	0,9,
	0,0
};
static struct Border Border2 = {
	-1, -1, 2, 0, JAM1, 5, BorderVectors2,	NULL
};

static struct IntuiText IText21 = {
	3, 0, JAM1,	0, -10, NULL, (UBYTE *)"Set Save Address Range", NULL
};
static struct IntuiText IText2 = {
	2, 0, JAM1,	-44, 1, NULL, (UBYTE *)"Start", &IText21
};

static struct Gadget Gadget2 = {
	&Gadget3, 60, 150, 56, 8, GADGHCOMP, RELVERIFY, STRGADGET, (APTR)&Border2,
	NULL,	&IText2,	NULL,	(APTR)&Gadget2SInfo,	2001,	NULL
};



/* ProcSaveGads() - Process Save Gadgets.
 * Following function used when saving data. Sets up Start Address and End
 * Address gadgets on file requester.
 */
ProcSaveGads(Mask,Object)
ULONG Mask;
CPTR *Object;
{
   struct Gadget *Gad;

   switch(Mask) {
      case FRF_NewWindFunc:
         ((struct NewWindow *)Object)->LeftEdge = 0;
         ((struct NewWindow *)Object)->Height = 146+20;
         FRWind = NULL;
         break;
      case FRF_AddGadFunc:
         AddGadget(FRWind = (struct Window *)Object, &Gadget2, 0L);
         AddGadget(((struct Window *)Object), &Gadget3, 0L);
         ActivateGadget(&Gadget2, (struct Window *)Object, 0L);
         break;
      case FRF_GEventFunc:
         switch ((ULONG)Object) {
            case 2001:
               if (FRWind)
                  ActivateGadget(&Gadget3, FRWind, 0L);
               break;
            case 2000:
               break;
         }
         return(TRUE);
      case FRF_DoMsgFunc:
         ReplyMsg(Object);
         break;
   }
}



int GetFileName(freq, HailText, FullName, Function, FuncFlags)
struct FileRequester *freq;
char *HailText, FullName[];
void (*Function)();
BYTE FuncFlags;
{
   int RetVal;

   freq->fr_Hail = HailText;
   freq->fr_Window = MyWindow;
   freq->fr_Function = (VOID(*)())Function;
   freq->fr_FuncFlags |= FuncFlags;
   /* FRF_AddGadFunc+FRF_GEventFunc+FRF_NewWindFunc+FRF_DoMsgFunc; */

   RetVal = (ULONG)FileRequest(freq);
   if (RetVal) {
      strcpy(FullName, freq->fr_Dir);
      TackOn(FullName, freq->fr_File);
   }
   return RetVal;
}



#define LoadDirName  LFReq->fr_Dir
#define LoadFileName LFReq->fr_File
struct FileRequester *LFReq = NULL;
int LoadFile(Type)
int Type;
{
   char   FileName[FCHARS+DSIZE+1];
   char s[80];
   int error = FALSE;
   ULONG  ReadSize = 0L;
   struct FileHandle *fh;
   struct FileLock *dlock, *olock;
   FILE *fp;

   /* Allocate file requester, but let CloseLibrary(ArpBase) free it */
   if ((!LFReq) && (LFReq = ArpAllocFreq()))
      return TRUE; /* for now */

   if (GetFileName(LFReq, "Load File", /* LoadDirName, LoadFileName, */ \
      FileName, NULL, 0)) {
      if (dlock = (struct FileLock *)Lock(LoadDirName, SHARED_LOCK))
         olock = (struct FileLock *)CurrentDir((struct FileLock *)dlock);
      if (Type == PLS_SREC) {
         if (fp = fopen(LoadFileName, "r")) {
            ReadSize = LoadSRecord(fp, DataStart, DataSize);
            fclose(fp);
         }
         else
            error = TRUE;
      }
      else if (fh = (struct FileHandle *)Open(LoadFileName, (LONG)MODE_OLDFILE)) {
         switch(Type) {
            case PLS_AMOBJ:        /* AMIGA OBJECT FILE */
               Seek(fh, 16L, (LONG)OFFSET_BEGINNING);
            case PLS_BIN:          /* BINARY */
               ReadSize = Read(fh, DataStart, DataSize);
               break;
         }
         Close(fh);
      }
      else
         error = TRUE;
      if (error)
         GetOkCancel((struct Screen *)MyScreen,(struct Window *)MyWindow,\
            "Load File Error !");
      else {
         sprintf(s, "%ld Bytes Read.", ReadSize);
         GetOkCancel((struct Screen *)MyScreen,(struct Window *)MyWindow, s);
         UpdateScreen();
      }
      CurrentDir((struct FileLock *)olock);
      UnLock((struct FileLock *)dlock);
   }
   return TRUE;
}



/*
      GetOkCancel((struct Screen *)MyScreen,(struct Window *)MyWindow,\
         "File not found")
*/



#define SaveDirName  SFReq->fr_Dir
#define SaveFileName SFReq->fr_File
struct FileRequester *SFReq = NULL;
int SaveFile()
{
   char   FileName[FCHARS+DSIZE+1];
   int error, flag;
   ULONG SStart, SEnd;
   struct FileHandle *sfh;
   struct FileLock *dlock, *flock, *olock;

   /* Allocate file requester, but let CloseLibrary(ArpBase) free it */
   if (!SFReq)
      SFReq = ArpAllocFreq();

   error = 0;
   if (GetFileName(SFReq, "Save Block to File", FileName,\
      (VOID (*) ())ProcSaveGads,\
      (UBYTE)(FRF_AddGadFunc+FRF_GEventFunc+FRF_NewWindFunc+FRF_DoColor))) {
      error = 1;
      if (HexToBin(Gadget2SIBuff, &SStart)) {
         if (HexToBin(Gadget3SIBuff, &SEnd)) {
            if (SStart<=SEnd && SStart<DataSize && SEnd<DataSize) {
               error = 0;
               /* I discovered TackOn() too late to use it here insted of */
               /* Lock()ing directories and files. Anyway this works. */
               if (dlock = (struct FileLock *)Lock(SaveDirName, SHARED_LOCK)) {
                  olock = (struct FileLock *)CurrentDir((struct FileLock *)\
                     dlock);
                  flag = TRUE;
                  if (flock = (struct FileLock *)Lock(SaveFileName,\
                     ACCESS_WRITE)) {
                     flag = GetOkCancel((struct Screen *)MyScreen,\
                        (struct Window *)MyWindow, "Overwrite File ?");
                     UnLock((struct FileLock *)flock);
                  }
                  if (flag) {
                     if ((sfh = (struct FileHandle *)Open(SaveFileName,\
                        MODE_NEWFILE))) {
                        Write((struct FileHandle *)sfh, &DataStart[SStart],\
                           (LONG)(SEnd-SStart+1));
                        Close((struct FileHandle *)sfh);
                     }
                  }
                  CurrentDir((struct FileLock *)olock);
                  UnLock((struct FileLock *)dlock);
               }
            }
         }
      }
   }
   if (error)
      GetOkCancel((struct Screen *)MyScreen, (struct Window *)MyWindow,\
         "ERROR: Address Set wrong.");
    return TRUE;
}

---END OF EXAMPLE---

Regards.

Koshy.

-- 
Koshy Abraham                UUCP: ...!uunet!mcsun!ukc!pyrltd!abekrd!koshy
Abekas Video Systems Ltd.     NET: koshy@abekrd.co.uk       //
12 Portman Rd,   Reading,   PHONE: +44 734 585421          //                   
Berkshire.       RG3 1EA.     FAX: +44 734 597267      \\ //
United Kingdom.             TELEX: 847579              K\A/b
Technical Details
Message-ID: <1379@abekrd.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!pyrltd!abekrd!koshy
References: <4811@jato.Jpl.Nasa.Gov> <8240@helios.TAMU.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!pyrltd!abekrd!koshy
From: koshy@abekrd.UUCP (Koshy Abraham)
Newsgroups: comp.sys.amiga.tech
Subject: Re: arp.library file requester
Message-ID: <1379@abekrd.UUCP>
Date: 17 Sep 90 11:58:22 GMT
References: <4811@jato.Jpl.Nasa.Gov> <8240@helios.TAMU.EDU>
Organization: Abekas Video Systems Ltd, Reading, England
Lines: 313