home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
util
/
appcon-38.73.lha
/
AppCon
/
Src
/
AppCon.c
next >
Wrap
C/C++ Source or Header
|
1994-05-14
|
15KB
|
593 lines
/* AppCon Main Source
**
** Done by Stephan Fuhrmann
**
*/
#define MTYPE_APPWINDOW 7
#define EXEC_MINIMUM 36
#define MY_ID 3111973
/*#define DEBUG_ME*/
#include <AppCon.h>
#include <dos.h>
//#include <stdio.h>
//#include <stdlib.h>
#define FILENAME_MAX 128
#include <string.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <exec/execbase.h>
#include <exec/ports.h>
#include <exec/io.h>
#include <exec/libraries.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <exec/tasks.h>
#include <devices/console.h>
#include <devices/conunit.h>
#include <devices/keymap.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <devices/timer.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#ifdef LATTICE
int CXBRK(void) { return(0); }
int chkabort(void) { return(0); }
#endif
struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase;
struct Library *WorkbenchBase;
struct Library *KeymapBase;
struct DosLibrary *DOSBase;
struct Library *UtilityBase;
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/wb.h>
#include <proto/keymap.h>
#include <proto/utility.h>
long timeout=10; /* in tenths of a second */
const char vt[]=VERSTAG;
struct Process *AppConTask=0L;
struct CommandLineInterface *AppCLI;
struct Window *AppConWindow;
struct MsgPort *timeport=0L;
struct MsgPort *appport=0L;
struct MsgPort *ioreply=0L;
struct IOStdReq *iorequest=0L;
struct timerequest *timerio=0L;
struct AppWindow *AppWindow;
struct AppMessage *AppMessage;
struct InputEvent *InputEvent;
ULONG WaitSignals=SIGBREAKF_CTRL_C;
ULONG ReceivedSignals;
char filename[FILENAME_MAX];
char dirname[FILENAME_MAX];
char pathname[FILENAME_MAX*2];
char AppConName[]="AppCon";
#define TEMPLATE "TimeOut=Time/K/N"
enum templates {OPT_TIMEOUT,OPT_COUNT};
LONG opts[OPT_COUNT];
char HelpPage[]=
"\nAppCon Help\n"\
"-----------\n"\
"© 1994 Stephan Fuhrmann\n\n"\
"Options\n"\
"---------\n"\
"TIMEOUT...timeout between checks of window closing, in tenths of a second\\NUMBER\n"\
"\nExample: AppCon TIMEOUT=10\n";
int breakother (struct Process *MyProc);
struct InputEvent *SendEvents (struct IOStdReq *iorequest,struct InputEvent *SendUs);
void MakeActive (struct Window *ActivateMe);
struct InputEvent *BrewInputevent(char *ASCII);
void FreeIEs (struct InputEvent *firstie);
struct Window *GetConWindow (struct Process *ConProcess,struct MsgPort *MyPort);
long AntiBlocking (struct Window *MyWin);
void MegaAbort (struct IOStdReq *);
void LaunchRequest (long secs,long micros,struct timerequest *mytimerio);
__saveds int main(int argc,char *argv)
{
struct RDArgs *argsptr;
APTR oldname;
SysBase=*(struct ExecBase **)4;
AppConTask=(struct Process *) FindTask(NULL);
oldname=AppConTask->pr_Task.tc_Node.ln_Name;
AppConTask->pr_Task.tc_Node.ln_Name=AppConName;
if (!argc)
return (0);
if (DOSBase=(struct DosLibrary *)OpenLibrary ("dos.library",37))
{
PutStr (VSTRING);
PutStr ("PUBLIC DOMAIN written 1993/94 by Stephan Fuhrmann\n");
if (IntuitionBase=(struct IntuitionBase *)OpenLibrary ("intuition.library",37))
{
if (WorkbenchBase=OpenLibrary ("workbench.library",37))
{
if (KeymapBase=OpenLibrary ("keymap.library",37))
{
if (UtilityBase=OpenLibrary ("utility.library",37))
{
if (breakother (AppConTask))
{
argsptr=AllocDosObject (DOS_RDARGS,0);
if (argsptr)
{
argsptr->RDA_ExtHelp=HelpPage;
if (!ReadArgs (TEMPLATE,opts,argsptr))
{
PrintFault (IoErr(),NULL);
FreeArgs (argsptr);
FreeDosObject (DOS_RDARGS,argsptr);
return (0);
}
if (opts[OPT_TIMEOUT])
timeout=*(LONG *)opts[OPT_TIMEOUT];
if ((ioreply=CreateMsgPort()) && (appport=CreateMsgPort()) && (timeport=CreateMsgPort()))
{
appport->mp_Node.ln_Name=AppConName;
WaitSignals |= 1L << (ioreply->mp_SigBit);
WaitSignals |= 1L << (timeport->mp_SigBit);
WaitSignals |= 1L << (appport->mp_SigBit);
if ((iorequest=CreateIORequest(ioreply,sizeof(struct IOStdReq)))
&& (timerio=CreateIORequest(timeport,sizeof(struct timerequest))))
{
if (!OpenDevice ("timer.device",UNIT_VBLANK,(struct IORequest *)timerio,0))
{
if (!OpenDevice ("input.device",0L,(struct IORequest *)iorequest,0))
{
AppConWindow=GetConWindow (AppConTask,ioreply);
if (AppConWindow)
{
if (AppWindow=AddAppWindowA (MY_ID,NULL,AppConWindow,appport,NULL))
{
ReceivedSignals=0;
LaunchRequest (timeout / 10,(timeout % 10) * 100000,timerio);
while (!(ReceivedSignals & SIGBREAKF_CTRL_C))
{
ReceivedSignals=Wait (WaitSignals);
if (ReceivedSignals & (1L << (timeport->mp_SigBit)))
{
ReceivedSignals &= ~ (1L << (timeport->mp_SigBit));
MegaAbort ((struct IOStdReq *)timerio);
LaunchRequest (timeout / 10,(timeout % 10) * 100000,timerio);
if (AntiBlocking (AppConTask->pr_ConsoleTask) <= 1)
Signal ((struct Task *)AppConTask,SIGBREAKF_CTRL_C);
}
if (ReceivedSignals & (1L << (appport->mp_SigBit)))
{
ReceivedSignals &= ~ (1L << (appport->mp_SigBit));
while (AppMessage = (struct AppMessage *)GetMsg (appport))
{
register long cnt,max;
register struct WBArg *curarg;
struct WBArg *argptr;
if ((AppMessage->am_Type)!=MTYPE_APPWINDOW)
{
#ifdef DEBUG_ME
VPrintf ("Unknown type (%ld)!",&AppMessage->am_Type);
#endif
ReplyMsg((struct Message *)AppMessage);
continue;
}
max=AppMessage->am_NumArgs;
curarg=AppMessage->am_ArgList;
if (!max)
{
#ifdef DEBUG_ME
VPrintf ("Not enough arguments (%ld)!",&max);
#endif
ReplyMsg((struct Message *)AppMessage);
continue;
}
argptr=curarg;
for (cnt=0;cnt<max;cnt++)
{
int hasspace;
int plusend;
if (argptr->wa_Lock)
NameFromLock(argptr->wa_Lock,dirname,FILENAME_MAX);
strcpy (pathname,dirname);
if (argptr->wa_Name)
AddPart(pathname,argptr->wa_Name,FILENAME_MAX*2);
if (cnt)
{
if (InputEvent=BrewInputevent (" "))
{
MakeActive (AppConWindow);
FreeIEs(SendEvents (iorequest,InputEvent));
}
else
DisplayBeep(0);
}
hasspace=(int)strchr(pathname,' ');
plusend=*(pathname+strlen(pathname)-1)=='+';
if (hasspace || plusend)
{
if (InputEvent=BrewInputevent ("\""))
{
MakeActive (AppConWindow);
FreeIEs(SendEvents (iorequest,InputEvent));
}
else
DisplayBeep(0);
}
if (InputEvent=BrewInputevent (pathname))
{
MakeActive (AppConWindow);
FreeIEs (SendEvents (iorequest,InputEvent));
}
else
DisplayBeep (0);
if (hasspace || plusend)
{
if (InputEvent=BrewInputevent ("\""))
{
MakeActive (AppConWindow);
FreeIEs(SendEvents (iorequ