home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
o
/
orbits
/
!orbits
/
c
/
RunImage
< prev
Wrap
Text File
|
1991-11-24
|
7KB
|
263 lines
/*
* Module: RunImage.c
* Creation: 28th July, 1991.
* Last modified: 12th November, 1991.
*
* (c) Copyright Neil Hoggarth, 1991.
*
* This text file is ANSI C source code.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* This program compiles to 'RunImage', which is a multitasking interface
* to the 'orbits' many body orbital mechanics simulation. This program is
* written for computers running the RISC OS operating system.
*
* All external functions which are not part of the standard ANSI library
* come from the RISC OS interface library "RISC_OSlib.o" which should be
* linked in when the program is compiled.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "baricon.h" /* Icon bar stuff from RISC_OSlib */
#include "dbox.h" /* Dialogue box stuff from RISC_OSlib */
#include "event.h" /* WIMP events from RISC_OSlib */
#include "flex.h" /* RISC_OSlib malloc thingy. Needed for txt */
#include "menu.h" /* Menu handling from RISC_OSlib */
#include "res.h" /* Resources from you know where */
#include "resspr.h" /* Something to do with sprites I think */
#include "template.h" /* Template routines from RISC_OSlib */
#include "txt.h" /* Text windows */
#include "vhidelay.h" /* Hourglass functions from RISC_OSlib */
#include "werr.h" /* RISC_OSlib WIMP error box */
#include "win.h" /* WIMP stuff from RISC_OSlib */
#include "wimpt.h" /* ditto */
#include "xferrecv.h" /* File handling by icon drags from RISC_OSlib */
/*
* A suggestion to Acorn for the next compiler release. The above is
* ridiculous! Why can't we just have a "riscos.h" header and be done
* with it? It would save me some typing anyway.
*/
#define STRNG_LEN 81
enum ICON_MENU_ITEMS {IM_INFO=1,IM_INTRO,IM_LICENSE,IM_TRAIL,IM_INPUT,IM_QUIT};
typedef struct {
win_event_handler *handler;
void *handle;
} event_t;
static int finished=FALSE;
static int trail=FALSE;
static txt t;
/*************************** Function Definitions ***********************/
static void read_handler(wimp_eventstr *e, void *handle)
/*
* This function is the event handler for the text window. Actually most
* event handling is done by a handler in the library. This just
* pre-processes the event to catch a few things not provided in the main
* handler.
*/
{
event_t *next;
next=handle;
if (e->e==wimp_ECLOSE)
wimpt_noerr(wimp_close_wind(e->data.o.w));
else if (e->e==wimp_ESCROLL)
txt_movevertical(t,-e->data.scroll.y,1);
else
(*(next->handler))(e,next->handle);
return;
}
static void read_open(char *file,char *title)
/*
* This function opens a text window which displays the contents of file
* 'file' with the text pointed to by 'title' on the title bar.
*/
{
static event_t Handler;
static int active=FALSE;
FILE *stream;
char strng[STRNG_LEN];
int nchar;
if (active)
txt_dispose(&t);
t=txt_new(title);
txt_show(t);
stream=fopen(file,"r");
if (stream==NULL)
werr(FALSE,"Can't find the file\n'%s'\n",file);
while(!feof(stream))
{
nchar=fread(strng,sizeof(char),STRNG_LEN-1,stream);
strng[nchar]=NULL;
txt_insertstring(t,strng);
txt_movedot(t,STRNG_LEN);
}
fclose(stream);
txt_setdot(t,0);
win_read_eventhandler(txt_syshandle(t),Handler.handler,&(Handler.handle));
win_register_event_handler(txt_syshandle(t),read_handler,&Handler);
active=TRUE;
return;
}
static menu MenuMaker(void *handle)
/*
* Builds the icon bar menu.
*/
{
menu temp;
handle=handle; /* Supresses a compiler warning. */
if (trail)
temp=menu_new("Orbits",">Info,Intro,License,!Trail,Input,Quit");
else
temp=menu_new("Orbits",">Info,Intro,License,Trail,Input,Quit");
return(temp);
}
static void MenuProc(void *handle, char *hit)
/*
* Handles choices from the icon bar menu.
*/
{
dbox i;
char cmd[100];
handle=handle; /* Supresses a compiler warning */
switch(hit[0])
{
case IM_INFO:
i=dbox_new("progInfo");
dbox_showstatic(i);
dbox_fillin(i);
dbox_dispose(&i);
break;
case IM_INTRO:
vhsdelay_begin();
read_open("<orbits$dir>.Doc","Introduction to Orbits");
vhsdelay_end();
break;
case IM_LICENSE:
vhsdelay_begin();
read_open("<orbits$dir>.Copying","License Agreement");
vhidelay_end();
break;
case IM_TRAIL:
trail=!trail;
break;
case IM_INPUT:
sprintf(cmd,"Filer_OpenDir %s.input",getenv("orbits$dir"));
wimp_starttask(cmd);
break;
case IM_QUIT:
finished=TRUE;
break;
}
return;
}
static void EventHandler(wimp_eventstr *e,void *handle)
/*
* This is the event handler for the sprite on the icon bar.
*/
{
char *filename;
char cmd[100];
handle=handle; /* This line prevents a compiler warning. */
switch (e->e)
{
case wimp_EREDRAW:
(void)wimpt_checkmode();
break;
case wimp_ESEND:
case wimp_ESENDWANTACK:
if ( e->data.msg.hdr.action==wimp_MDATALOAD )
{
(void)xferrecv_checkinsert(&filename);
sprintf(cmd,"<orbits$dir>.orbits %s %s",trail?"-t":"",filename);
wimp_starttask(cmd);
xferrecv_insertfileok();
}
break;
default:
/*
* It's not an event that we wish to respond to,
* therefore we ignore it.
*/
break;
}
}
static void Init(void)
/*
* Declare the program as a WIMP task and initialise all the RISC_OSlib
* stuff.
*/
{
wimpt_init("orbits");
res_init("orbits");
resspr_init();
template_init();
dbox_init();
vhsdelay_init();
flex_init();
txt_init();
return;
}
/****************************** Main Program ****************************/
int main(void)
{
Init();
baricon("!orbits", (int)resspr_area(), 0);
win_register_event_handler(win_ICONBAR, EventHandler, 0);
event_attachmenumaker(win_ICONBAR, MenuMaker, MenuProc, 0);
win_claim_unknown_events(win_ICONBAR);
event_setmask(wimp_EMPTRENTER | wimp_EMPTRLEAVE | wimp_EKEY);
while(!finished)
event_process();
}