1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/*******************************************************************************
* *
* Viewmol *
* *
* R U N S C R I P T . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: runscript.c,v 1.2 2003/11/07 11:15:29 jrh Exp $
* $Log: runscript.c,v $
* Revision 1.2 2003/11/07 11:15:29 jrh
* Release 2.4
*
* Revision 1.1 2000/12/10 15:16:22 jrh
* Initial revision
*
*/
#include<stdio.h>
#include<Xm/Xm.h>
#include "viewmol.h"
#include "dialog.h"
extern char *selectFile(char *, char *, int);
extern char *getStringResource(Widget, char *);
extern int messgb(Widget, int, char *, struct PushButtonRow *, int);
extern void GetMessageBoxButton(Widget, XtPointer, caddr_t);
extern Widget topShell;
extern int pythonInterrupt;
void runScript(Widget, caddr_t, XmAnyCallbackStruct *);
void startModule(Widget, caddr_t, XmAnyCallbackStruct *);
void runScript(Widget w, caddr_t data, XmAnyCallbackStruct *dummy)
{
FILE *file;
static struct PushButtonRow buttons[] = {{"continue", GetMessageBoxButton, (XtPointer)0, NULL}};
static char *filename="";
char line[MAXLENLINE], *word;
if ((char *)data == NULL)
filename=selectFile("*.py", filename, TRUE);
else
filename=(char *)data;
if (filename != NULL)
{
if ((file=fopen(filename, "r")) == NULL)
{
word=getStringResource(topShell, "noFile");
sprintf(line, word, filename);
(void)messgb(topShell, 1, line, buttons, 1);
}
else
{
pythonInterrupt=FALSE;
PyRun_SimpleFile(file, filename);
fclose(file);
}
}
}
void startModule(Widget w, caddr_t data, XmAnyCallbackStruct *dummy)
{
char cmd[MAXLENLINE], number[4];
sprintf(number, "%2.2d", (int)data);
strncpy(cmd, "module", MAXLENLINE-1);
strncat(cmd, number, MAXLENLINE-strlen(cmd));
strncat(cmd, ".run()", MAXLENLINE-strlen(cmd)-strlen(number));
PyRun_SimpleString(cmd);
}
|