|
/*ScianScripts.c
Stuff for scripts in scian
Eric Pepke
*/
#include "Scian.h"
#include "ScianTypes.h"
#include "ScianArrays.h"
#include "ScianIDs.h"
#include "ScianEvents.h"
#include "ScianRecorders.h"
#include "ScianWindows.h"
#include "ScianObjWindows.h"
#include "ScianVisWindows.h"
#include "ScianScripts.h"
#include "ScianSliders.h"
#include "ScianTimers.h"
#include "ScianMethods.h"
#include "ScianLists.h"
#include "ScianErrors.h"
#include "ScianGarbageMan.h"
#include "ScianSpaces.h"
#include "ScianIcons.h"
Bool runningScript = false; /*True iff running script*/
WinInfoPtr scriptWindow = 0; /*The current window of the script*/
extern ObjPtr perspecControlClass; /*Class of perspecive controls*/
FILE *logFile = 0; /*File that we're logging to*/
Bool logging = false; /*True iff logging*/
long framesLeft = 0; /*Frames left to record*/
Bool abortScript = false; /*Abort script*/
/*IDs for running tasks*/
#define RT_NONE 0 /*No running task*/
#define RT_RECORDING 1 /*Recording some time*/
int runningTask = RT_NONE; /*Current running task*/
#define MAXSTACKDEPTH 100 /*Maximum depth of block stack*/
#define ERROBJ ((ObjPtr) -1) /*Evil Satanic test value*/
typedef struct
{
int command;
} Block;
Block commandStack[MAXSTACKDEPTH]; /*Stack of commands*/
int nextStackElement = 0; /*Next element on the stack*/
#define KWBEGIN 0 /*Begin a block*/
#define KWEND 1 /*End current modal command*/
#define KWRECORDER 2 /*(set) recorder*/
#define KWDESELECT 3 /*Deselect an icon*/
#define KWSELECT 4 /*Select an icon*/
#define KWVISUALIZE 5 /*Do the visualize menu item*/
#define KWALIGNMENT 6 /*(Set) alignment*/
#define KWLOCATION 7 /*(Set) location*/
#define KWVIDEOSCREEN 8 /*Resize current window to video screen*/
#define KWFULLSCREEN 9 /*Resize current window to full screen*/
#define KWROTATE 10 /*Rotate space*/
#define KWSHOW 11 /*Show something*/
#define KWPANEL 12 /*(Show/Hide) the panel of icons*/
#define KWRECORDING 13 /*Begin recording*/
#define KWSNAP 14 /*Snap a single frame*/
#define KWWINDOW 15 /*Select a new window*/
#define KWSET 16 /*Set something*/
#define KWCONTROLS 17 /*(Show) controls for a vis object*/
#define KWPUSHWINDOW 18 /*Push a window behind all others*/
#define KWQUIT 19 /*Quit*/
#define KWSHEAR 20 /*Shear the matrix*/
#define KWFPS 21 /*(Set) fps*/
#define KWEYEPOSN 22 /*Eye position*/
#define KWROLL 23 /*Roll of eyeball*/
#define KWPITCH 24 /*Pitch of eyeball*/
#define KWYAW 25 /*Yaw of eyeball*/
#define KWCLONE 26 /*Clone an icon*/
#define KWHIDE 27 /*Hide the frame of a window*/
#define KWEXIT 28 /*Exit on next loop*/
#define KWVALUE 29 /*(Set) value of a something*/
#define KWFONT 30 /*(Set) the font of something*/
#define KWSIZE 31 /*(Set) the size of something's font*/
#define KWCLOSE 32 /*Closes a window*/
#define KWDRAG 33 /*Drags something*/
#define KWDROP 34 /*Drops whatever is in the drag buffer*/
#define KWBOUNDS 35 /*(Set) the bounds of an object*/
#define KWTILE 36 /*Tile to a certain width and height*/
#define KWANNOTATION 37 /*Add annotation*/
#define KWFRAME 38 /*(Show/Hide) the frame of a window*/
#define KWLOCATE 39 /*Locate a window*/
#define KWDELETE 40 /*Delete stuff*/
#define KWSCRSAVE 41 /*Save the screen*/
#define KWRECORD 42 /*Record some number of seconds*/
#define KWSCREEN 43 /*(Set) screen*/
#define KWCOLOR 44 /*(Set) color*/
#define KWPREFERENCES 45 /*(Show) preferences*/
#define KWDUPLICATE 46 /*Duplicate an icon, just like clone*/
#define KWOFF 47 /*(Turn) off*/
#define KWTURN 48 /*Turn (on/off)*/
#define KWON 49 /*(Turn) on*/
#define KWVISOBJECTSAS 50 /*Visualize objects as*/
#define KWFUNCTIONBOX 51 /*(Set) Function box*/
#define KWFILESWINDOW 52 /*(Show) FilesWindow*/
#define KWSELECTALL 53 /*Selectall*/
#define KWDESELECTALL 54 /*Deselectall*/
#define KWHELP 55 /*(Show) help*/
#define KWFILEREADERS 56 /*(Show) fileReaders*/
#define KWDATASETS 57 /*(Show) datasets*/
#define KWROTATION 58 /*(Set) rotation*/
#define KWLOCALCOPY 59 /*Make a local copy*/
#define KWFRONT 60 /*(Show) front (panel controls)*/
#define KWBACK 61 /*(Show) back (panel controls)*/
#define NKEYWORDS 62 /*Number of keywords*/
char *keywords[NKEYWORDS] =
{
"begin",
"end",
"recorder",
"deselect",
"select",
"visualize",
"alignment",
"location",
"videoscreen",
"fullscreen",
"rotate",
"show",
"panel",
"recording",
"snap",
"window",
"set",
"controls",
"pushwindow",
"quit",
"shear",
"fps",
"eyeposn",
"roll",
"pitch",
"yaw",
"clone",
"hide",
"exit",
"value",
"font",
"size",
"close",
"drag",
"drop",
"bounds",
"tile",
"annotation",
"frame",
"locate",
"delete",
"scrsave",
"record",
"screen",
"color",
"preferences",
"duplicate",
"off",
"turn",
"on",
"visobjectsas",
"functionbox",
"fileswindow",
"selectall",
"deselectall",
"help",
"filereaders",
"datasets",
"rotation",
"localcopy",
"front",
"back"
};
char *wholeLine; /*Pointer to the whole line for error*/
char *begToken, *endToken; /*Beginning and ending of current token*/
WinInfoPtr logWindow = 0; /*Current log window*/
int logInhibit = 0; /*Counter to inhibit log*/
#ifdef PROTO
Bool BeginCommand(char *);
Bool EndCommand(char *);
#else
Bool BeginCommand();
Bool EndCommand();
#endif
void Log(s)
char *s;
/*Logs command s*/
{
if (logging && (logInhibit == 0))
{
if (selWinInfo && (logWindow != selWinInfo))
{
/*Make a window command*/
char windowName[256];
int k;
char *s;
/*Copy window title*/
s = selWinInfo -> winTitle;
k = 0;
while (*s)
{
if (!isalpha(*s) && ((k == 0) || !isdigit(*s)))
{
windowName[k++] = '\\';
}
windowName[k++] = *s++;
}
windowName[k] = 0;
fprintf(logFile, "window %s\n", windowName);
logWindow = selWinInfo;
}
fputs(s, logFile);
}
}
#ifdef PROTO
void InhibitLogging(Bool whether)
#else
void InhibitLogging(whether)
Bool whether;
#endif
/*Inhibits or disinhibits logging based on whether*/
{
if (whether)
{
++logInhibit;
}
else
{
--logInhibit;
}
}
void LogControl(object)
ObjPtr object;
{
if (logging)
{
char cmd[256];
char *s;
sprintf(cmd, "set value ");
s = &(cmd[0]);
while (*s) ++s;
MakeObjectName(s, object);
while (*s) ++s;
*s++ = ' ';
PrintScriptObject(s, GetVar(object, VALUE));
while (*s) ++s;
*s++ = '\n';
*s = 0;
Log(cmd);
}
}
void ScriptError(e)
char *e;
/*Prints out an error e*/
{
char *runner;
fprintf(stderr, "%s", wholeLine);
runner = wholeLine;
while (runner < begToken)
{
fprintf(stderr, *runner == '\t' ? "\t" : " ");
++runner;
}
if (runner < endToken)
{
while (runner < endToken)
{
fprintf(stderr, "-");
++runner;
}
}
else
{
fprintf(stderr, "^");
}
fprintf(stderr, "\n");
fprintf(stderr, "%s\n", e);
abortScript = true;
}
void SelectNamedWindow(name)
char *name;
/*Selects a window by name name*/
{
WinInfoPtr namedWindow;
namedWindow = GetWinFromTitle(name);
if (!namedWindow)
{
ScriptError("Cannot find a unique window by that name.");
return;
}
SelectWindow(namedWindow -> id);
scriptWindow = namedWindow;
}
void MakeObjectName(dest, object)
char *dest;
ObjPtr object;
/*Makes a short object name from object and puts it into dest*/
{
register char *s;
ObjPtr name;
name = GetStringVar("MakeObjectName", object, NAME);
if (!name)
{
*dest = 0;
return;
}
/*Copy name*/
s = GetString(name);
if (isdigit(*s))
{
*dest++ = '\\';
}
while (*s)
{
if (!isalpha(*s) && !isdigit(*s))
{
*dest++ = '\\';
}
*dest++ = *s++;
}
*dest = 0;
}
void MakeFullObjectName(dest, window, object)
char *dest;
ObjPtr window, object;
/*Makes a full name for object within window and puts it into dest*/
{
register char *s;
ObjPtr name;
name = GetStringVar("MakeFullObjectName", object, NAME);
if (!name)
{
*dest = 0;
return;
}
/*Copy title*/
s = ((WinInfoPtr) window) -> winTitle;
if (!isalpha(*s))
{
*dest++ = '\\';
}
while (*s)
{
if (!isalpha(*s) && !isdigit(*s))
{
*dest++ = '\\';
}
*dest++ = *s++;
}
/*Add a colon*/
*dest++ = ':';
/*Copy name*/
s = GetString(name);
if (!isalpha(*s))
{
*dest++ = '\\';
}
while (*s)
{
if (!isalpha(*s) && !isdigit(*s))
{
*dest++ = '\\';
}
*dest++ = *s++;
}
*dest = 0;
}
ObjPtr FindFullNamedObject(name)
char *name;
/*Finds the object with name name. Syntax for name is
[:]
|