Files
2017-04-17 00:10:12 +02:00

173 lines
4.7 KiB
C

/* File parseIO.c */
/*
These are system dependent functions called by the parser
to read input lines and notify the user of errors.
*/
/****************************************************************
Topograph - A function browser
Copyright (C) 1996 Marc Culler
culler@math.uic.edu
Department of Mathematics (M/C 249)
University of Illinois at Chicago
851 S. Morgan St.
Chicago, IL 60607-7045
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 2 of the License, 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.
******************************************************************/
#include "Topograph.h"
#include "graph.h"
#include "eval/evaluator.h"
#include <string.h>
/* Defined in this module. */
BOOL getFunction(char *message);
void freeFunction(void);
unsigned char *getLine(char buffer[], int size);
void syntaxError(char lineBuffer[], int position);
void unmatchedParens(void);
void unknownSymbol(char *);
void putPrompt(void);
void putMessage(char *message);
void closeIOConsole(void);
/* Defined in eval.c */
extern INSWORD *createEvaluator(void);
extern freeEvaluator(INSWORD *code);
/* Defined in CP.c */
extern struct CPMessage CPmsg;
/* Defined in UI.c */
extern void bailOut(char *);
extern void stackScreens(void);
extern char titleString[];
extern char inputWindowString[];
extern struct Screen *CPScreen;
extern struct Screen *graphScreen;
extern struct Window *CPWindow;
extern struct Gadget *CPGadgets[];
int IOBusyFlag;
BPTR IOConsole;
BOOL getFunction(char *message){
INSWORD *newFunction;
char saveTitle[256];
ScreenToFront(CPScreen);
strcpy(saveTitle,titleString);
titleString[0] = '\0';
IOConsole = Open(inputWindowString, MODE_READWRITE);
if (IOConsole == NULL) bailOut("Could not open input window.\n");
if (message != NULL) putMessage(message);
putPrompt();
newFunction = createEvaluator();
if (newFunction == NULL){
strcpy(titleString,saveTitle);
SetWindowTitles(CPWindow, titleString, NULL);
closeIOConsole();
return FALSE;
}
else{
SetRast(&(graphScreen->RastPort),UNDERCOLOR);
freeEvaluator((INSWORD *)CPmsg.evaluate);
CPmsg.evaluate = (double(* __asm)(register __fp5 double x,register __fp6 double y))
newFunction;
CPmsg.computeNewValues = YES;
SetWindowTitles(CPWindow, titleString, NULL);
FPuts(IOConsole,
"\nSelect the initial domain and range, then click on Draw to begin.\n");
OffGadget(CPGadgets[RESCALE],CPWindow,NULL);
ActivateWindow(CPWindow);
return TRUE;
}
}
void freeFunction(void){
freeEvaluator((INSWORD *) CPmsg.evaluate);
}
void syntaxError(char lineBuffer[], int position){
int i;
FPuts(IOConsole, "\n\rSyntax error.\n\r\r");
for (i=0;i<position;i++) FPutC(IOConsole,lineBuffer[i]);
FPuts(IOConsole, "\n\r");
for (i=0;i<position;i++) FPutC(IOConsole,' ');
for (;lineBuffer[i] != '\0';i++) FPutC(IOConsole,lineBuffer[i]);
FPuts(IOConsole, "\n\rPlease try again.\n\n\r");
titleString[0] = '\0';
putPrompt();
}
void unmatchedParens(){
FPuts(IOConsole, "\n\rUnmatched parentheses\n\r");
FPuts(IOConsole, "\n\rPlease try again.\n\n\r");
titleString[0] = '\0';
putPrompt();
}
void unknownSymbol(char *symbol){
FPuts(IOConsole, "\n\rUnknown symbol: ");
FPuts(IOConsole, symbol);
FPuts(IOConsole, "\n\n\rPlease try again.\n\n\r");
titleString[0] = '\0';
putPrompt();
}
unsigned char *getLine(char buffer[], int size){
unsigned char *value;
int i;
/*In case we need to quit while we are reading the input stream.*/
IOBusyFlag = TRUE;
value = FGets(IOConsole, buffer, size);
IOBusyFlag = FALSE;
if (titleString[0] == '\0'){
for(i=0;i<128;i++){
if (buffer[i] == ';' || buffer[i] == '\n' || buffer[i] == '\0') break;
else titleString[i] = buffer[i];
}
titleString[i] = '\0';
}
return(value);
}
void putPrompt(void){
FPuts(IOConsole, "z(x,y) = ");
}
void closeIOConsole(void){
if (IOConsole == NULL) return;
else {
Close(IOConsole);
stackScreens();
IOConsole = NULL;
}
}
void putMessage(char *message){
FPuts(IOConsole,message);
}