home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
disk
/
misc
/
tracked
/
source.lha
/
sources
/
Menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
5KB
|
223 lines
/* Menu.c menu structures and routines referred to in menus */
#include <libraries/asl.h>
#include <utility/tagitem.h>
#include <dos/dos.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/gadtools.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
extern struct Library *AslBase;
extern struct TextAttr Style;
extern struct Window *Window;
extern struct StringInfo Block_info;
extern int drive;
extern UBYTE *BB, *RB;
/* Menu ID's */
#define m_file 0
#define m_sector 1
#define m_buffer 2
#define m_search 3
struct NewMenu My_NewMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, 0,},
{ NM_ITEM, "About", 0 , 0, 0, 0,},
{ NM_ITEM, "Quit", "Q", 0, 0, 0,},
{ NM_TITLE, "Sector", 0 , 0, 0, 0,},
{ NM_ITEM, "Read again", "R", 0, 0, 0,},
{ NM_ITEM, "Write back", "W", 0, 0, 0,},
{ NM_ITEM, "Load from file", "L", 0, 0, 0,},
{ NM_ITEM, "Save as file", "S", 0, 0, 0,},
{ NM_ITEM, "Calc Checksum", "C", 0, 0, 0,},
{ NM_TITLE, "Buffer", 0 , 0, 0, 0,},
{ NM_ITEM, "Read from buffer", 0 , 0, 0, 0,},
{ NM_ITEM, "Write to buffer", 0 , 0, 0, 0,},
{ NM_TITLE, "Search", 0 , 0, 0, 0,},
{ NM_ITEM, "Search string", 0 , 0, 0, 0,},
{ NM_ITEM, "Search number", 0 , 0, 0, 0,},
{ NM_END, NULL, 0 , 0, 0, 0,},
};
struct TagItem TIA[] =
{
ASL_OKText, NULL, ASL_TopEdge, 40, ASL_LeftEdge, 50, ASL_Height, 140,
ASL_Width, 156, TAG_END, 0
};
int GetName(headertext, string)
char headertext[];
char string[];
{
int i, j;
char *FN, *DN;
struct FileRequester *FR;
int rc;
if ((AslBase = (struct Library *) OpenLibrary(AslName, 0L)))
{
TIA[0].ti_Data = (ULONG) headertext;
FR = (struct FileRequester *) AllocAslRequest(ASL_FileRequest, TIA);
FN = (char *) RequestFile(FR);
DN = FR->rf_Dir;
if (FN)
{
for (i = 0; DN[i] != 0; i++) string[i] = DN[i];
if ((i != 0) && (DN[i-1] != ':')) string[i++] = '/';
for (j = 0; FN[j] != 0; j++) string[i+j] = FN[j];
string[i+j] = 0;
rc = i+j;
}
else rc = 0;
FreeFileRequest(FR);
}
else
{
ShowText2(Window, "asl.library not found.", "Load/Save aborted", NULL);
rc = 0;
}
return(rc);
}
void LoadBlock(buffer)
UBYTE *buffer;
{
char Filename[256];
struct Filehandle *f;
LONG br;
if (GetName("Load", Filename))
{
f = (struct Filehandle *) Open(Filename, MODE_OLDFILE);
if (!f) ShowText2(Window, "Error opening file", "Load aborted", NULL);
else
{
if ((br = Read(f, buffer, 512L)) != 512L)
ShowText2(Window, "Not a full block loaded", NULL, NULL);
Close(f);
UpDateSB();
}
}
}
void SaveBlock(buffer)
UBYTE *buffer;
{
char Filename[256];
struct Filehandle *f;
LONG bw;
if (GetName("Save", Filename))
{
f = (struct Filehandle *) Open(Filename, MODE_NEWFILE);
if (!f) ShowText2(Window, "Error opening file", "Save aborted", NULL);
else
{
if ((bw = Write(f, buffer, 512L)) != 512L)
ShowText2(Window, "Error writing data",
"Check disk and try again", NULL);
else ShowText2(Window, "Block saved.", NULL, NULL);
Close(f);
}
}
}
void CalcCheck(buffer)
LONG *buffer;
{
int i;
LONG L;
buffer[5] = 0;
L = 0;
for (i = 0; i < 128; i++) L += buffer[i];
buffer[5] = -L;
UpDateSB();
}
BOOL DoMenu(menu, item, sub)
UWORD menu, item, sub;
{
int i, td_err;
BOOL rc = TRUE;
switch(menu)
{
case m_file:
switch(item)
{
case 0: /* About */
ShowText2(Window, "TrackEd v1.24 21-may-93",
"by Camiel Rouweler", "Thank you");
break;
case 1: /* Quit */
rc = FALSE;
break;
}
break;
case m_buffer:
switch(item)
{
case 0: /* read from buffer */
for (i = 0; i < 512; i++) BB[i] = RB[i];
UpDateSB();
break;
case 1: /* write to buffer */
for (i = 0; i < 512; i++) RB[i] = BB[i];
break;
}
break;
case m_sector:
switch(item)
{
case 0: /* Re-read */
td_err = ReadBlocks(drive, (WORD) Block_info.LongInt, 1, BB);
if (td_err) ProcessTDError(td_err);
UpDateSB();
break;
case 1: /* Write back */
td_err = WriteBlocks(drive, (WORD) Block_info.LongInt, 1, BB);
if (td_err) ProcessTDError(td_err);
UpDateSB();
break;
case 2: /* Load Block */
LoadBlock(BB);
break;
case 3: /* Save Block */
SaveBlock(BB);
break;
case 4: /* Calculate Checksum */
CalcCheck(BB);
break;
}
break;
case m_search:
switch(item)
{
case 0: /* Search String */
SearchS();
break;
case 1: /* Search Number */
SearchB();
break;
}
break;
}
return(rc);
}