home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0913.lha
/
PickStartup
/
pickstartup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-03
|
17KB
|
535 lines
/* INCLUDES for Intuition ******************************************** */
///
#include "exec/types.h"
#include "exec/libraries.h"
#include "exec/memory.h"
#include "libraries/asl.h"
#include "proto/exec.h"
#include "clib/intuition_protos.h"
#include "clib/dos_protos.h"
#include "clib/exec_protos.h"
#include "clib/asl_protos.h"
#include "clib/alib_protos.h"
#include "devices/keyboard.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "dos/dos.h"
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "intuition/screens.h"
UBYTE *vers = "$VER: PickStartup V1.3";
///
/* Window defines */
///
#define MY_WIN_LEFT 0
#define MY_WIN_TOP 0
#define MY_WIN_WIDTH 356
#define MY_WIN_HEIGHT 69
#define MAXPATH 512 /* path/file buffer max size */
#define MATRIX_SIZE 16L /* 2.04 Keyboard Matrix Size */
///
/*************************************************************************
* Var Stuff *
*************************************************************************/
///
struct EasyStruct MyHelp =
{
sizeof(struct EasyStruct),
0,
"CommanLine Options are:",
"PickStartup2 [?] [RMB=] [DIR=] [FILTER=] [DELAY=] [KEY=] [F1=] [NOWIN]\n\n"
"DeFaults are:\n"
"? NONE unless you ask.\n"
"KEY=0x63 or commonly known as the Ctrl key.\n"
"RMB=none\n"
"F1=none\n"
"DIR=S:special-startups\n"
"DELAY=5\n"
"FILTER=Start-#?\n"
"NOWIN\n"
"Example....... \n"
"Pickstartup RMB=S:test F1=S:Test2 DELAY=7 DIR=S: FILTER=s#?\n"
"This will execute the s:test if you press the RMB or s:test2 if F1 pressed\n"
"Or open ASL Req to Dir s: and display all filenames starting with s.\n"
"If no button pressed the window will remain open for a delay of 7\n"
"unless NOWIN option used. Then close and continue with your \n"
"current Startup-sequence.\n"
"This DELAY time will vary depending on your system\n" ,
"Thanks|Show some KeyCodes",
};
struct EasyStruct SomeKeyCodesHelp =
{
sizeof(struct EasyStruct),
0,
" Here are some common KeyCodes ",
"63 CTRL Key (default) \n"
"60 Left Shift Key \n"
"64 Left Alt Key \n"
"61 Right Shift Key \n"
"65 Right Alt Key \n"
"50-59 F1-F10\n"
"Don't use 50 if you are using the F1= option\n",
"Thanks",
};
struct IntuiText IText1 =
{
1, 0, JAM2, /* front and back text pens, drawmode and fill byte */
32, 32, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
" Click For Startup List ", /* pointer to text */
NULL /* next IntuiText structure */
};
struct TagItem win_tags[] = /* Window Tags */
{
WA_Left, MY_WIN_LEFT,
WA_Top, MY_WIN_TOP,
WA_Width, MY_WIN_WIDTH,
WA_Height, MY_WIN_HEIGHT,
/* WA_DragBar, TRUE,*/
WA_RMBTrap, TRUE,
/* WA_CloseGadget, TRUE,*/
WA_Title, (ULONG) " PickStartup by Bill Pierpont 1993",
WA_Activate, TRUE,
WA_IDCMP, IDCMP_MOUSEBUTTONS | IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_RAWKEY,
TAG_DONE, NULL,
};
///
/* Protos */
///
void ExecuteFileName(VOID);
void ExecuteF1_FileName(VOID);
void GetStringArg(int, int, TEXT *arg[]);
VOID GetOptions (int argc, TEXT *argv[]);
APTR AllocAslRequest (ULONG, struct TagItem *);
VOID FreeAslRequest (APTR request);
int CloseUpDevice (VOID);
VOID PrintHelp(VOID);
VOID GetFileName (VOID);
VOID Handle_Events (struct Window *);
BOOL AddPart (UBYTE * dirname, UBYTE * filename, unsigned long size);
BOOL IsKeyDn (LONG);
///
/***********************************************************************
* Globals *
************************************************************************/
///
LONG KeyToCk = 0x63;
LONG F1_Key = 0x50;
LONG oslibversion = 37;
ULONG LoopCount = 50000;
USHORT code = NULL;
BOOL NoWin = FALSE;
BOOL Continue = TRUE;
BOOL Cancelled = FALSE;
BOOL Check_F1 = FALSE;
TEXT Default_Buffer[MAXPATH] = "";
TEXT WorkBuf[MAXPATH] = "";
TEXT F1_Buffer[MAXPATH] = "";
TEXT FilePath[MAXPATH] = "s:special-startups"; /* Buffer For File request pathname */
TEXT FilePattern[MAXPATH] = "start-#?";
extern struct Library *IntuitionBase;
extern struct Library *AslBase;
int count = 0;
///
/***********************************************************************
* main *
***********************************************************************/
int
main(int argc, TEXT *argv[])
{
///
struct Window *win; /// get options if any
if (argc > 0)
{GetOptions (argc, argv);}
if (!Continue) /// if we found the help option quit here
{ return (0); }
else
{ Continue = FALSE; } /// reset switch
if (IsKeyDn(KeyToCk))
{
GetFileName ();
if (Cancelled==TRUE) /// User Selected cancel duuh
{ return(0);}
else
{ return(10); } /// User selected File exit and kill Cli
}
if (Check_F1) // If F1 Option used do this
{
KeyToCk = 0x50; // 50 hex is Key Code for F1_Key
if (IsKeyDn(KeyToCk))
{ ExecuteF1_FileName(); /// yep its down
if (Cancelled) /// Close if Cancelled Selected
{ return (0);} /// and quit but don't Kill current Startup
else
{ return (10);}
}
}
if(NoWin)
{ return(0);}
else
{
win = OpenWindowTagList (NULL, win_tags); /// open the window and print
if (win == NULL) /// and print some text
{ printf ("Window Failed to Open"); }
else
{ PrintIText (win->RPort, &IText1, 0, 0);
Handle_Events (win);
CloseWindow (win); /// you can close that window now
}
/// After calling Handle_Events the
///Continue = code MENUDOWN or MOUSEBUTTONS
if (code) /// If window clicked code is set
{ ExecuteFileName(); /// If not set window timed out
if (Cancelled) /// Close if Cancelled Selected
{ return (0);} /// and quit but don't Kill current Startup
else
{ return (10);} /// job done quit and kill startup-sequence
}
}
return (0);
///
}
/***************************************************************************
GetFileName()
Calls ASLreq.
Get the users input.
Then execute the selected script.
****************************************************************************/
void
GetFileName ()
{
///
struct FileRequester *fr;
TEXT buffer[MAXPATH];
if (AslBase = OpenLibrary ("asl.library", 37L))
{
if (fr = (struct FileRequester *) AllocAslRequestTags (ASL_FileRequest,
ASL_Hail, (ULONG) "Pick Startup File",
ASL_Height, 200,
ASL_Width, 220,
ASL_LeftEdge, 0,
ASL_TopEdge, 0,
ASL_OKText, (ULONG) "OK",
ASL_CancelText, (ULONG) "Cancel",
ASL_Pattern, (TEXT *) &FilePattern,
ASL_FuncFlags, FILF_PATGAD,
ASL_Dir, (TEXT *) &FilePath,
TAG_DONE))
{
if (AslRequest (fr, NULL)) /* This Call Opens the Requester*/
{
strcpy (buffer, "execute "); /* Build PathName */
strcat (buffer, fr->rf_Dir);
AddPart (buffer, fr->rf_File, sizeof (buffer)
- strlen (buffer));
if(strncmp(fr->rf_File, "",1)) /*if not a null string execute it */
{Execute ((STRPTR) &buffer, NULL, NULL);}
}
else
{
Cancelled = TRUE;
}
} /* end if */
FreeAslRequest (fr);
CloseLibrary (AslBase);
}
else
{
printf ("You Need WorkBench Version 2.04 to run this Program");
}
///
}
/***********************************************************************
Handle_Events()
Does what its name implies
until LoopCount == 0 or user hits a mouse botton
LoopCount can be changed by command line option.
I know busyloop ......badboy but becaues of the nature of the program
since it isn't multitasking at this point it dosn't make any difference.
Someday I hope to learn how to use Timer Device.
************************************************************************/
void
Handle_Events (struct Window *win)
{
///
ULONG class;
BOOL Done = FALSE;
struct IntuiMessage *message;
register long windowsig = 0L;
register struct MsgPort *Iport = NULL;
Iport = win->UserPort;
windowsig = 1L << Iport->mp_SigBit;
while (!Done)
{
count++;
if (count > LoopCount)
Done = TRUE;
while ((!Done) &&
(message = (struct IntuiMessage *) GetMsg (win->UserPort)))
{
class = message->Class;
code = message->Code;
ReplyMsg ((struct Message *) message);
if (class == IDCMP_MOUSEBUTTONS)
{
Done = TRUE;
Continue = TRUE;
}
else
{
code = NULL; /// clear code so main() does not
///open ASL when we return
}
}
}
}
/****************************************************************************
GetOptions()
Sets up options recieved from the command line
Loop thought the argv array looking for strings that match KeyWords.
If one is found then get and seperate the KeyWord from the rest of the
string to get parameter the user entered.
*****************************************************************************/
VOID
GetOptions (int argc, TEXT *argv[])
{
///
int length;
int count;
int temphexa;
for (count = 1; count < argc; count++)
{ length=stclen(argv[count]);
if(!strncmp(argv[count], "?",1))
{
PrintHelp();
Continue = FALSE;
}
if(!strncmp(argv[count], "NOWIN",5))
{
NoWin = TRUE;
/// Continue = FALSE;
}
if(!strncmp(argv[count],"FILTER=",7))
{
GetStringArg(8,length,&argv[count]);
strcpy (FilePattern, WorkBuf);
}
if(!strnicmp(argv[count], "KEY=",4))
{
GetStringArg(5,length,&argv[count]);
stch_i(WorkBuf,&temphexa); /* Grrr, why isn't it like atoi?! */
KeyToCk = temphexa ? (UWORD)temphexa : 0x63;
}
if(!strncmp(argv[count],"RMB=",4))
{
GetStringArg(5,length,&argv[count]);
if(length >4) /* if 4 we have a string */
{
strcpy (Default_Buffer, "execute "); /* set up command else we use the default */
strcat (Default_Buffer, WorkBuf);
}
}
if(!strncmp(argv[count],"F1=",3))
{
GetStringArg(4,length,&argv[count]);
if(length >3) // if 3 we have a string */
{
strcpy (F1_Buffer, "execute "); // set up command else we use the default */
strcat (F1_Buffer, WorkBuf);
Check_F1 = TRUE;
}
}
if(!strncmp(argv[count], "DELAY=",6))
{
GetStringArg(7,length,&argv[count]);
if((LoopCount = strtoul(WorkBuf,NULL,10)*10000) == 0)
{LoopCount = 5000;}
}
if(!strncmp(argv[count],"DIR=",4))
{
GetStringArg(5,length,&argv[count]);
if(length > 4)
{
strcpy (FilePath, WorkBuf);
}
}
}
///
}
/****************************************************************
* get the substring of the argument *
* I really just wrote this routine to practice passing arguments*
* call GetStringArg(p,l,argv)
* p = int = to the length of the keyword+1 e.g "DIR=" is 5
* l = length of argv string (already calced.
* argv = address of argv[count] string
*****************************************************************/
void GetStringArg(int ParameterLength,int length,TEXT *argv[])
{
///
struct EasyStruct CommandErrorHelp =
{
sizeof(struct EasyStruct),
0,
"HELLO, You Need Help with PickStartup2",
"You have an Error in your command line Option for \n"
"%s\n"
"Do Not put a space between the Keyword and your option.\n\n"
"I will use the default value for now. ",
"OK|Show Me How",
};
if(ParameterLength-1 == length)
{
if(!EasyRequestArgs(NULL,&CommandErrorHelp,NULL,argv)) /* if show me how selected printHelp */
{PrintHelp();}
}
else
{ strmid(*argv,WorkBuf,ParameterLength,length);} /* Gets the SUbstring and puts it in WorkBuf */
///
}
/**************************************************************************
PrintHelp()
Calls EasyRequest to display some help.
Like you couldn't tell this.
***************************************************************************/
void PrintHelp()
{
if(!EasyRequest(NULL,&MyHelp,NULL,"(var)",2))
EasyRequest(NULL,&SomeKeyCodesHelp,NULL,"(var)",2);
}
///
/*************************************************************************
IsKeyDn()
/* This Section of code supplied by J.Luk. */
Keyboard.device checking if a certain key is down
ARGS: UWORD KeyToCk -- Raw Key Matrix code, see RKM:Libs p707(1.3),828(2.04)
RESULT: BOOL of whether or not the key is down! (sheesh)
**************************************************************************/
BOOL IsKeyDn(KeyToCk)
LONG KeyToCk;
{
struct IOStdReq *keyRequest;
struct MsgPort *keyPort;
UBYTE *keyMatrix;
BOOL RetFlg = FALSE;
if (keyPort=CreatePort(NULL,NULL) )
{
if (keyRequest=(struct IOStdReq *)CreateExtIO (keyPort, sizeof (struct IOStdReq)))
{
if (!OpenDevice("keyboard.device",NULL,(struct IORequest *) keyRequest, NULL) )
{
if (keyMatrix=AllocMem(MATRIX_SIZE, MEMF_PUBLIC | MEMF_CLEAR) )
{
keyRequest->io_Command=KBD_READMATRIX;
keyRequest->io_Data=(APTR)keyMatrix;
keyRequest->io_Length=13;
DoIO ( (struct IORequest *) keyRequest);
/* Why couldn't the RKM just say this?!!!! */
/* No Shit ! */
if (keyMatrix[KeyToCk/8] & (1L<<(KeyToCk%8))) RetFlg = TRUE;
/* Access the byte of the key matrix, and test to see if */
/* bit KeyToCk%8 (the remainder) is set */
FreeMem (keyMatrix, MATRIX_SIZE);
}
CloseDevice ( (struct IORequest *) keyRequest);
}
DeleteExtIO ( (struct IORequest *) keyRequest);
} DeletePort (keyPort);
}
return (RetFlg);
}
void ExecuteFileName()
{
if(code == MENUDOWN) /// if RMB do the default command line file only option
{
if(strcmp(Default_Buffer,"")) /// setup up the file name from the commandline to execute
{ Execute ((STRPTR) &Default_Buffer, NULL, NULL); }
else
{ GetFileName ();}/* RMB file name entered wrong, call ASL and get one */
}
else
{
GetFileName(); }
}
void ExecuteF1_FileName()
{
if(Check_F1) /// if RMB do the default command line file only option
{
if(strcmp(F1_Buffer,"")) /// setup up the file name from the commandline to execute
{ Execute ((STRPTR) &F1_Buffer, NULL, NULL); }
else
{ GetFileName ();}/* F1 file name entered wrong, call ASL and get one */
}
else
{ GetFileName(); }
}