
/*  This provides the outermost framework of LOGO, calling the parser to
 *	begin with, and then thereafter whenever an interrupt or error occurs.
 *	Copyright (C) 1979, The Children's Museum, Boston, Mass.
 *	Written by Douglas B. Klunder.
 */
/* 
                                  NXLogo
       Copyright  1992, CSM Software, Inc.  All Rights Reserved.
    You may freely copy, distribute and reuse the code in this program. CSM
Software disclaims any warranty of any kind, expressed or implied as to its
fitness for any particular use. (Code last moditied Date June 25, 1992)

  Last Modified by :
          Gary F. Desrochers (garyd@slate.mines.colorado.edu)
          Sean Kerstiens     (skerstie@slate.mines.colorado.edu)

  Modified For:
          Colorado School of Mines.

  Last edited: 
          June 25,1992

*/
/*
     The new code and any changes in these logo files has been to try to
     keep the code the same so that this code can still be used on other
     machines.  This means any of the changes or additions are inside ifndef
     and ifdef statements.
     If you want to know the changes needed to make this run on the NeXT 
     look in these files for the NEXT definition.
*/
     
#include "logo.h"
#include <stdlib.h>
#ifdef NEXT
#import <appkit/Application.h>
#import <defaults.h>
#import <streams/streams.h>
#import <objc/Object.h>
#include <time.h>
extern void srandom();
extern int getpid();
extern void unlink();
NXStream *aStream;
const char *homeval, *syslibdir, *helpdir;
id controler;
id blankid;
/* As of right now the logo functions
   readlist,rl
   request
   edit,ed
   readchar,rc
   are removed and may be put in later.
   Also [] cannot go more then one line. ( of course one line is 1000 chars )
   the to command does not work.  All you have to do is make a .lg file from
   any editor.
*/
#endif

char editfile[30];
extern char *getbpt;
#ifndef NOTURTLE
extern int turtdes;
extern struct display *mydpy;
#endif  NOTURTLE
#ifdef  SETCURSOR
#include <sgtty.h>
struct sgttyb tty;
#endif  SETCURSOR

#ifdef NEXT
void main(int argc, char *argv[])
{
        void nextMain();
	union timeUnion{
         long li[2];
         int  i[2];
              }tu;

	time(&tu.li[0]);
	time(&tu.li[1]);
	SRAND(tu.i[1]+tu.i[0]);

        nextMain(argc,argv);
        /* Later on maybe this can include the option to include the
           file that was clicked on. */
#else  /* NOT NEXT */
main(argc,argv)
int argc
char *argv[]
{
	int i[2];

	char tbuff[BUFSIZ];
	setbuf(stdout,tbuff);
	time(i);
	SRAND(i[1]+i[0]);
	sprintf(editfile,"/tmp/logo%u",(short)getpid());

#ifdef SETCURSOR
	gtty(1,&tty);
#endif
	if (argc>1)
		getbpt = argv[1];
	else
		printf("\nWelcome to Children's Museum/LSRHS LOGO\n?");
	fflush(stdout);
		fprintf(stderr,"I don't belong here!/n");
	while (enter()==1) {
		yyprompt(1);
	}
	cboff();
#ifdef SETCURSOR
	stty(1,&tty);
#endif
#ifndef NOTURTLE
#ifdef FLOOR
	if (turtdes>0)
		printf("Please\007 unplug the turtle\007 and put it\007 away.\n");
#endif FLOOR
	if (turtdes<0) {
		printf(mydpy->finish);
		(*mydpy->outfn)();
	}
#endif  NOTURTLE
	unlink(editfile);
#endif  NEXT
        exit(0);
}
#ifdef NEXT
void nextMain(int argc, char *argv[]){
char *getenv();
    homeval = NXGetDefaultValue("NXLogo", "NXLogoLib");
    syslibdir = NXGetDefaultValue("NXLogo", "NXLogoSysLib");
    helpdir = NXGetDefaultValue("NXLogo", "NXLogoHelp");
    NXApp = [Application new];
    [NXApp loadNibSection:"NXLogo.nib" owner:NXApp];
    [NXApp run];
    [NXApp free];
    exit(0);
}
extern int enter();
int actOnString(NXStream *dStream, id thisRoutine){
        int retint = 0;
        aStream = dStream;
        controler = thisRoutine;
        NXSeek(aStream,0,NX_FROMSTART);
	if ((retint = enter())==3) {
                return(1);
	}
        return(0);
}
#endif NEXT
