home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume15
/
xgen
/
part10
< prev
next >
Wrap
Text File
|
1991-10-25
|
48KB
|
1,361 lines
Path: uunet!sun-barr!cronkite.Central.Sun.COM!exodus!zorro.cecer.army.mil
From: kurt@zorro.cecer.army.mil (Kurt Buehler)
Newsgroups: comp.sources.x
Subject: v15i010: Xgen - GUI generator for shell-like programs, Part10/17
Message-ID: <22152@exodus.Eng.Sun.COM>
Date: 25 Oct 91 16:38:13 GMT
References: <csx-15i001-xgen@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 1349
Approved: argv@sun.com
Submitted-by: kurt@zorro.cecer.army.mil (Kurt Buehler)
Posting-number: Volume 15, Issue 10
Archive-name: xgen/part10
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by emily!kurt on Thu Aug 29 15:39:40 CDT 1991
# Contents: ./xgen/src/procmess.c ./xgen/src/resource.h ./xgen/src/sensitive.c
# ./xgen/src/control.c ./xgen/src/docapture.c ./xgen/src/popup.c
# ./xgen/src/addnode.c
echo x - ./xgen/src/procmess.c
sed 's/^@//' > "./xgen/src/procmess.c" <<'@//E*O*F ./xgen/src/procmess.c//'
/**********************************************************************
procmess.c - process message object messages
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
/* surpress message "The result of operation '*' was not used" */
/*SURPRESS 528*/
MessageInfo *
ProcessMessage(string,columns)
char *string;
int columns;
{
/* allocate a string to keep a copy in */
char *save = XtMalloc(strlen(string) +1);
char *savePtr;
int stringlen;
Boolean subdivide = False;
MessageInfo *head;
MessageInfo *cur;
int lastpos = 1;
int count = 1;
savePtr = strcpy(save,string);
/***************************************************************
* allocate space for head of message info list and set cur pointer
**************************************************************/
cur = head = (MessageInfo *)XtMalloc(sizeof(MessageInfo));
bzero((char *)head,sizeof(MessageInfo));
/***************************************************************
* check for NULL input string
**************************************************************/
if ( !string ) return(NULL);
stringlen = strlen(string);
if ( columns < stringlen )
subdivide = True;
else {
cur->startpos = lastpos;
cur->endpos = strlen(string);
return(head);
}
/***************************************************************
* while we still need to subdivide......
**************************************************************/
while ( subdivide ) {
Boolean got_a_line = False;
int charcount = 0;
/***************************************************************
* cram as many WORDS as we can into each line
**************************************************************/
while ( !got_a_line ) {
/* we reached a space check to see if the next space
* would put us beyond columns... */
if ( isspace(*savePtr) ) {
char *t = savePtr;
int more = 0;
*t = ' ';
*t++; /* increment past space */
while ( *t && !isspace(*t) ) {
*t++; more++;
}
/* if so, save that part and break loop */
if ( more + charcount > columns ) {
/***********************************************************
* store appropraite info
**********************************************************/
cur->startpos = lastpos;
cur->endpos = lastpos + charcount;
/***********************************************************
* allocate space for another message info list element
**********************************************************/
cur->next = (MessageInfo *)XtMalloc(sizeof(MessageInfo));
bzero((char *)cur->next,sizeof(MessageInfo));
cur = cur->next;
lastpos += charcount + 1;
got_a_line = True;
count++;
}
}
*savePtr++;
/* if we reached the end of the string,
save it and break both loops */
if ( *savePtr == NULL ) {
if ( !got_a_line ) {
/***********************************************************
* store appropraite info
**********************************************************/
cur->startpos = lastpos;
cur->endpos = lastpos + charcount;
/***********************************************************
* allocate space for another message info list element
**********************************************************/
cur->next = (MessageInfo *)XtMalloc(sizeof(MessageInfo));
bzero((char *)cur->next,sizeof(MessageInfo));
cur = cur->next;
lastpos += charcount;
}
got_a_line = True;
count++;
subdivide = False;
}
charcount++;
}
/* we just got another segment, if we aren't at strings end
just see if we need to subdivide further... */
if ( subdivide && !(columns < stringlen - lastpos) ) {
subdivide = False;
cur->startpos = lastpos;
cur->endpos = stringlen;
count++;
}
}
return(head);
}
FreeMIList(mi)
MessageInfo *mi;
{
if ( mi->next != NULL ) {
FreeMIList(mi->next);
}
XtFree(mi);
}
@//E*O*F ./xgen/src/procmess.c//
chmod u=rw,g=r,o=r ./xgen/src/procmess.c
echo x - ./xgen/src/resource.h
sed 's/^@//' > "./xgen/src/resource.h" <<'@//E*O*F ./xgen/src/resource.h//'
/**********************************************************************
resource.h - resource header file
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
static struct _resourceTable {
int index;
char *name;
int type;
unsigned int valid;
} resourceTable[] = {
InitialShells, "initialshells", STRING, ENV,
X, "x", INTEGER, SHL|MU|CO|OBJ|ALLOBJ,
DX, "dx", REAL, SHL|MU|CO|OBJ|ALLOBJ,
Y, "y", INTEGER, SHL|MU|CO|OBJ|ALLOBJ,
DY, "dy", REAL, SHL|MU|CO|OBJ|ALLOBJ,
Width, "width", INTEGER, SHL|MU|CO|OBJ|ALLOBJ,
Height, "height", INTEGER, SHL|MU|CO|OBJ|ALLOBJ,
MaxWidth, "maxwidth", INTEGER, SHL|MU,
MaxHeight, "maxheight", INTEGER, SHL|MU,
Help, "help", STRING, SHL|MU|CO|OBJ|ALLOBJ,
Columns, "columns", INTEGER, OBJ|TA|ME,
Font, "font", STRING, OBJ|ALLOBJ,
EntryFont, "entryfont", STRING, OBJ|TA,
Background, "background", STRING, SHL|MU|CO|OBJ|ALLOBJ,
Foreground, "foreground", STRING, SHL|MU|CO|OBJ|ALLOBJ,
TitleString, "titlestring", STRING, SHL|MU|CO|OBJ|ALLOBJ,
Override, "override", BOOLEAN, SHL|MU|CO,
Popup, "popup", STRING, OBJ|PB,
Popdown, "popdown", STRING, OBJ|PB,
Destroy, "destroy", STRING, OBJ|PB,
Exit, "exit", INTEGER, OBJ|PB,
RunForeground, "runforeground", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
RunBackground, "runbackground", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
InputFrom, "inputfrom", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
CaptureOutput, "captureoutput", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
UpdateFrom, "updatefrom", STRING, SHL|MU|OBJ|LI,
Pane, "pane", BOOLEAN, SHL|CO,
Store, "store", STRING, OBJ|PB,
GetEnv, "getenv", STRING, OBJ|PB,
Clear, "clear", STRING, OBJ|PB,
CommandArg, "commandarg", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
Set, "set", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
Alignment, "alignment", STRING, OBJ|ME|LA|PB,
ListElement, "listelement", STRING, OBJ|LI|TO,
ListSeparator, "listseparator", STRING, OBJ|LI|TO,
ListType, "listtype", STRING, OBJ|LI,
VisibleItems, "visibleitems", INTEGER, SHL|MU|OBJ|LI,
ValueString, "valuestring", STRING, OBJ|TE|TO|LI,
LabelPixmap, "labelpixmap", STRING, OBJ|LA|PB|TO,
Minimum, "minimum", INTEGER, OBJ|SL,
Maximum, "maximum", INTEGER, OBJ|SL,
StartValue, "startvalue", INTEGER, OBJ|SL,
SliderWidth, "sliderwidth", INTEGER, OBJ|SL,
SliderHeight, "sliderheight", INTEGER, OBJ|SL,
Orientation, "orientation", STRING, OBJ|SL|SE,
DecimalPoints, "decimalpoints", INTEGER, OBJ|SL,
Rows, "rows", INTEGER, OBJ|TA,
RowsDisplayed, "rowsdisplayed", INTEGER, OBJ|TA,
ColumnsDisplayed, "columnsdisplayed", INTEGER, OBJ|TA,
ColumnHeadings, "columnheadings", STRING, OBJ|TA,
RowHeadings, "rowheadings", STRING, OBJ|TA,
RowValue, "rowvalue", STRING, OBJ|TA,
TableValue, "tablevalue", STRING, OBJ|TA,
RowHeight, "rowheight", INTEGER, OBJ|TA,
ColumnWidth, "columnwidth", INTEGER, OBJ|TA,
Separator, "separator", STRING, OBJ|TA,
Newline, "newline", BOOLEAN, OBJ|TA,
ToggleType, "toggletype", STRING, OBJ|TO,
SeparatorType, "separatortype", STRING, OBJ|SE,
Sensitive, "sensitive", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
Insensitive, "insensitive", STRING, ENV|SHL|MU|CO|OBJ|PB|PU,
};
static struct _shellTable {
char *name;
int index;
unsigned int valid;
} shellTable[] = {
"menu", MU, LA|PB|SE,
"commandboard", CO, PU|LA|LI|ME|PB|TE|TA|SE|SL|TO,
};
static struct _objectTable {
char *name;
int index;
} objectTable[] = {
"label", LA,
"message", ME,
"list", LI,
"pushbutton", PB,
"textentry", TE,
"table", TA,
"separator", SE,
"slider", SL,
"toggle", TO,
"pulldown", PU,
};
@//E*O*F ./xgen/src/resource.h//
chmod u=rw,g=r,o=r ./xgen/src/resource.h
echo x - ./xgen/src/sensitive.c
sed 's/^@//' > "./xgen/src/sensitive.c" <<'@//E*O*F ./xgen/src/sensitive.c//'
/**********************************************************************
sensitive.c - set a shell or object (in)sensitive
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
EffectSensitivity(list,onoroff)
char *list;
Boolean onoroff;
{
char **token, **Tokenize();
Boolean save = verbose;
int n;
WidgetListElement *widgetList;
verbose = True;
/* parse the list (if more than one name occurs) and set the affected
object (in)sensitive */
token = Tokenize(list," ");
for ( n = 0; token[n]; n++) {
Shell *s;
if ((s = IndexShell(token[n])) == NULL ) {
InterfaceObject *o;
Boolean longDesc = False;
if ( rindex(token[n],':') != NULL ) {
/* IN THE FORM "shell:obj" */
char *sPart, *oPart;
longDesc = True;
sPart = (char *)strtok(token[n],":");
oPart = (char *)strtok(NULL,":");
if ((s = IndexShell(sPart)) == NULL) {
sprintf(errorbuf,
"no such shell \"%s\"",sPart);
XgenWarning("set sensitivity",errorbuf);
} else if ( s->widget ) {
Boolean found = False;
o = s->objects;
while ( o && !found ) {
if ( !strcmp(oPart,o->name) ) {
if ( !strcmp(o->name,"dynamic")) {
widgetList = s->dynObjects;
while ( widgetList ) {
DoSetSensitive(widgetList->widget,onoroff);
widgetList = widgetList->next;
}
} else {
DoSetSensitive(o->widget,onoroff);
}
found = True;
}
o = o->next;
}
if ( !found ) {
sprintf(errorbuf,
"no such object \"%s\" in shell \"%s\"",
oPart,sPart);
XgenWarning("set sensitivity",errorbuf);
}
}
}
if ( !longDesc ) {
if ( (o = IndexObjectByName(token[n])) == NULL ) {
sprintf(errorbuf,
"no such shell or object \"%s\"",token[n]);
XgenWarning("set sensitivity",errorbuf);
} else if ( o->widget ) {
if ( !strcmp(o->name,"dynamic")) {
s = IndexShellByObject(o);
widgetList = s->dynObjects;
while ( widgetList ) {
DoSetSensitive(widgetList->widget,onoroff);
widgetList = widgetList->next;
}
} else {
DoSetSensitive(o->widget,onoroff);
}
}
}
} else if ( s->widget ) {
InterfaceObject *o = s->objects;
while ( o ) {
if ( !strcmp(o->name,"dynamic")) {
s = IndexShellByObject(o);
widgetList = s->dynObjects;
while ( widgetList ) {
DoSetSensitive(widgetList->widget,onoroff);
widgetList = widgetList->next;
}
} else {
DoSetSensitive(o->widget,onoroff);
}
o = o->next;
}
}
}
verbose = save;
}
DoSetSensitive(w,onoroff)
Widget w;
Boolean onoroff;
{
if ( XtIsManaged(w) ) {
XtSetSensitive(w,onoroff);
}
}
@//E*O*F ./xgen/src/sensitive.c//
chmod u=rw,g=r,o=r ./xgen/src/sensitive.c
echo x - ./xgen/src/control.c
sed 's/^@//' > "./xgen/src/control.c" <<'@//E*O*F ./xgen/src/control.c//'
/**********************************************************************
control.c - perform control box functions
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
void KillCB();
void ForegroundCB();
MakeControlBox()
{
Widget separator1, separator2, cbLabel1, cbLabel2, quitButton;
int n;
char buf[80];
XmString xmLabel;
void ControlBoxQuit();
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
XtSetArg(args[n],XmNmarginWidth,0); n++;
XtSetArg(args[n],XmNmarginHeight,0); n++;
XtSetArg(args[n],XmNpacking,XmPACK_COLUMN); n++;
XtSetArg(args[n],XmNorientation,XmVERTICAL); n++;
xgenGD.CBRowCol = XmCreateRowColumn(xgenGD.applShell,"controlbox pane",args,n);
XtManageChild(xgenGD.CBRowCol);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
sprintf(buf,"%s Control Box",xgenGD.progName);
xmLabel = XmStringLtoRCreate(buf,SDC);
XtSetArg(args[n],XmNlabelType,XmSTRING); n++;
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
cbLabel1 = XmCreateLabelGadget(xgenGD.CBRowCol,"label",args,n);
XtManageChild(cbLabel1);
XmStringFree(xmLabel);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
xmLabel = XmStringLtoRCreate("Quit",SDC);
XtSetArg(args[n],XmNlabelType,XmSTRING); n++;
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
XtSetArg(args[n],XmNborderWidth,10); n++;
quitButton = XmCreatePushButtonGadget(xgenGD.CBRowCol,"exit",args,n);
XtManageChild(quitButton);
XmStringFree(xmLabel);
XtAddCallback(quitButton, XmNactivateCallback, ControlBoxQuit, NULL);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
XtSetArg(args[n],XmNorientation,XmHORIZONTAL); n++;
XtSetArg(args[n],XmNseparatorType,XmSHADOW_ETCHED_IN); n++;
separator1 = XmCreateSeparator(xgenGD.CBRowCol,"s1",args,n);
XtManageChild(separator1);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
sprintf(buf,"Background Jobs:",xgenGD.progName);
xmLabel = XmStringLtoRCreate(buf,SDC);
XtSetArg(args[n],XmNlabelType,XmSTRING); n++;
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
cbLabel2 = XmCreateLabelGadget(xgenGD.CBRowCol,"label",args,n);
XtManageChild(cbLabel2);
XmStringFree(xmLabel);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
XtSetArg(args[n],XmNorientation,XmHORIZONTAL); n++;
XtSetArg(args[n],XmNseparatorType,XmSHADOW_ETCHED_IN); n++;
separator2 = XmCreateSeparator(xgenGD.CBRowCol,"s2",args,n);
XtManageChild(separator2);
}
void
AddCommandToControlBox(com)
Command *com;
{
Widget optMenu;
Widget optSubmenu;
Widget opts[2];
XmString xmLabel;
int n;
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
optSubmenu = XmCreatePulldownMenu(xgenGD.CBRowCol,"optionsubmenu",args,n);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
xmLabel = XmStringLtoRCreate("foreground",SDC);
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
opts[0] = XmCreatePushButtonGadget(optSubmenu,"option1",args,n);
XtManageChild(opts[0]);
XmStringFree(xmLabel);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
xmLabel = XmStringLtoRCreate("kill",SDC);
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
opts[1] = XmCreatePushButtonGadget(optSubmenu,"option2",args,n);
XtManageChild(opts[1]);
XmStringFree(xmLabel);
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
xmLabel = XmStringLtoRCreate(com->path,SDC);
XtSetArg(args[n],XmNlabelString,xmLabel); n++;
XtSetArg(args[n],XmNsubMenuId,optSubmenu); n++;
optMenu = XmCreateOptionMenu(xgenGD.CBRowCol,"command",args,n);
XtManageChild(optMenu);
XmStringFree(xmLabel);
com->widget = optMenu;
XtAddCallback(opts[0], XmNactivateCallback, ForegroundCB, com);
XtAddCallback(opts[1], XmNactivateCallback, KillCB, com);
}
void
DeleteCommandFromControlBox(pid)
int pid;
{
Command *goner = FindCommand(pid);
if ( !nocontrol )
if ( goner != NULL ) {
XtUnrealizeWidget(goner->widget);
XtDestroyWidget(goner->widget);
}
}
void
ControlBoxQuit()
{
XgenExit(0);
}
static void
ForegroundCB(w,cld,cad)
/*ARGSUSED*/
Widget w;
caddr_t cld;
caddr_t cad;
{
Command *command = (Command *)cld;
union wait status;
int pid;
while ( (pid = wait(&status)) != command->pid && pid != -1 ) {
DoReap(status,pid);
}
if ( pid != -1 )
DoReap(status,pid);
return;
}
static void
KillCB(w,cld,cad)
/*ARGSUSED*/
Widget w;
caddr_t cld;
caddr_t cad;
{
Command *command = (Command *)cld;
char s[80];
int pgrp;
/* unlink temp files if they exist */
if ( command->capture && !access(command->tmpfile,0) )
unlink(command->tmpfile);
if ( !access(command->errfile,0) )
unlink(command->errfile);
/* check for existance */
if ( kill(command->pid,0) == 0 && errno != ESRCH ) {
/* get the process group and wipe it out */
pgrp = getpgrp(command->pid);
if ( killpg(pgrp,SIGINT) < 0 ) {
sprintf(s,"killpg: process group %d",pgrp);
perror(s);
}
}
DeleteCommandFromControlBox(command->pid);
DeleteCommand(command->pid);
return;
}
@//E*O*F ./xgen/src/control.c//
chmod u=rw,g=r,o=r ./xgen/src/control.c
echo x - ./xgen/src/docapture.c
sed 's/^@//' > "./xgen/src/docapture.c" <<'@//E*O*F ./xgen/src/docapture.c//'
/**********************************************************************
docapture.c - capture output from a command in a text editor widget
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
static Widget saveDialog = NULL;
void
DoCaptureText(com)
Command *com;
{
Widget captureWidget;
Widget main_window;
Widget menu_bar;
Widget dismiss;
Widget save;
Widget frame;
Widget text;
FILE *fp;
char *string;
struct stat statbuf;
int length;
int n;
if ((fp = fopen(com->tmpfile, "r+")) == NULL)
if ((fp = fopen(com->tmpfile, "r")) != NULL) {
fprintf(stderr, "Warning: file opened read only.\n");
} else {
fprintf(stderr, "Sorry: couldn't get tmpfile\n");
return;
}
/* get the legth of the string */
if ( stat(com->tmpfile,&statbuf) == 0 )
length = statbuf.st_size;
else
length = 1000000; /* arbitrary file length */
/* read it... */
if ( length > 0 ) {
string = (char *)XtMalloc(length);
fread(string, sizeof(char), length, fp);
}
/* close up the file */
if (fclose(fp) != NULL)
fprintf(stderr, "Warning: unable to close file.\n");
if ( length ) {
n = 0;
SetGlobalArgs(&n,NOFONTS);
SetObjectColorArgs(NULL,&n);
XtSetArg(args[n],XmNallowShellResize,True); n++;
captureWidget = XtCreatePopupShell(com->path,topLevelShellWidgetClass,
xgenGD.applShell,args,n);
/***************************************************************
* create the MainWindow : this is used since it allows for a
* MenuBar, a Frame, and a ScrolledWindow (if necessary).
* The application designer might choose to place labels, lists,
* or pushbuttons in a menu.
**************************************************************/
n = 0;
SetGlobalArgs(&n,NOFONTS);
SetObjectColorArgs(NULL,&n);
main_window = XmCreateMainWindow(captureWidget,com->path,args,n);
XtManageChild(main_window);
/***************************************************************
* create the MenuBar
**************************************************************/
menu_bar = NULL;
n = 0;
SetGlobalArgs(&n,NOFONTS);
SetObjectColorArgs(NULL,&n);
menu_bar = XmCreateMenuBar(main_window,"menu_bar",args,n);
XtManageChild(menu_bar);
/***************************************************************
* create menu buttons
**************************************************************/
n = 0;
SetGlobalArgs(&n,FONTS);
SetObjectColorArgs(NULL,&n);
dismiss = XmCreateCascadeButton(menu_bar, "Dismiss", args,n);
XtManageChild(dismiss);
save = XmCreateCascadeButton(menu_bar, "Save to file", args,n);
XtManageChild(save);
/***************************************************************
* create a frame for the objects
**************************************************************/
n = 0;
SetGlobalArgs(&n,NOFONTS);
SetObjectColorArgs(NULL,&n);
frame = XmCreateFrame(main_window,"frame",args,n);
XtManageChild(frame);
n = 0;
SetGlobalArgs(&n,NOFONTS);
SetObjectColorArgs(NULL,&n);
XtSetArg (args[n], XmNrows, 24); n++;
XtSetArg (args[n], XmNcolumns, 80); n++;
XtSetArg (args[n], XmNresizeWidth, False); n++;
XtSetArg (args[n], XmNresizeHeight, False); n++;
XtSetArg (args[n], XmNscrollVertical, True); n++;
XtSetArg (args[n], XmNscrollHorizontal, True); n++;
XtSetArg (args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
text = XmCreateScrolledText(frame,"text",args,n);
XtManageChild(text);
/***************************************************************
* add callbacks
**************************************************************/
XtAddCallback(dismiss,XmNactivateCallback,dismissCB,
(caddr_t)captureWidget);
XtAddCallback(save,XmNactivateCallback,saveCB,
(caddr_t)text);
XtPopup(captureWidget,XtGrabNone);
XmTextSetString(text, string);
}
}
void
dismissCB(w,cld,cad)
/*ARGSUSED*/
Widget w;
caddr_t cld;
caddr_t cad;
{
Widget popup = (Widget)cld;
XtDestroyWidget(popup);
}
void
saveCB(w,cld,cad)
/*ARGSUSED*/
Widget w;
caddr_t cld;
caddr_t cad;
{
int n;
XmString xmstring;
Widget text = (Widget) cld;
n = 0;
xmstring = XmStringCreateLtoR("Save To File...",SDC);
XtSetArg(args[n], XmNselectionLabelString,xmstring); n++;
saveDialog = XmCreatePromptDialog(w,"save dialog",args,n);
XtManageChild(saveDialog);
XtAddCallback (saveDialog, XmNokCallback, SaveOKCB, (caddr_t)text);
XtManageChild(saveDialog);
}
void
SaveOKCB(w,cld,cad)
/*ARGSUSED*/
Widget w;
caddr_t cld;
caddr_t cad;
{
char *fileString = NULL;
char *fileName = NULL;
FILE *fp = NULL;
XmSelectionBoxCallbackStruct *scb =
(XmSelectionBoxCallbackStruct *) cad;
Widget text = (Widget) cld;
/* get the file name from the dialog */
XmStringGetLtoR(scb->value, SDC, &fileName);
/* is NULL or empty just return so maybe the user will enter one */
if ( !fileName || !strcmp(fileName,"") ) return;
/* open the file, if possible */
if ((fp = fopen(fileName, "a+")) == NULL) {
sprintf(errorbuf,"unable to open [%s], text not saved.",fileName);
XgenWarning("save captured text",errorbuf);
}
/* get the text string */
fileString = XmTextGetString(text);
/* write it to the file */
fwrite(fileString, sizeof(char), strlen(fileString) + 1, fp);
fflush(fp);
fclose(fp);
/* destroy the dialog */
XtDestroyWidget(saveDialog);
}
@//E*O*F ./xgen/src/docapture.c//
chmod u=rw,g=r,o=r ./xgen/src/docapture.c
echo x - ./xgen/src/popup.c
sed 's/^@//' > "./xgen/src/popup.c" <<'@//E*O*F ./xgen/src/popup.c//'
/**********************************************************************
popup.c - do popup's, popdown's, and getenv's
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
PopupEnviron(e)
Environ *e;
{
Shell *s = e->shells;
Resource *resource;
xgenGD.currentEnv = e;
if ( (NULL != (resource = IndexResource((char *)e,ENVIRONMENT,"set"))) ||
(NULL != (resource = IndexResource((char *)e,ENVIRONMENT,"runforeground"))) ||
(NULL != (resource = IndexResource((char *)e,ENVIRONMENT,"runbackground")))) {
while ( resource ) {
if ( !strcmp(resource->name,"set") )
DoSet((char *)e,resource,ENVIRONMENT,NULL);
if ( !strncmp(resource->name,"run",3) )
DoJob((char *)e,resource,ENVIRONMENT);
resource = resource->next;
}
}
/* Popup all initial shells */
s = e->shells;
while ( s ) {
if ( s->initial )
Popup_Shell(s);
s = s->next;
}
/***************************************************************
* check for existance of a sensitivity command....
**************************************************************/
if ( (NULL !=
(resource = IndexResource((char *)e,ENVIRONMENT,"sensitive"))) ||
(NULL !=
(resource = IndexResource((char *)e,ENVIRONMENT,"insensitive")))) {
while ( resource ) {
if ( !strcmp(resource->name,"sensitive") ) {
EffectSensitivity(resource->val.cval,True);
}
if ( !strcmp(resource->name,"insensitive") ) {
EffectSensitivity(resource->val.cval,False);
}
resource = resource->next;
}
}
}
PopdownAll(e)
Environ *e;
{
Shell *s = e->shells;
while ( s ) {
if ( s->popup )
Popdown_Shell(s);
s = s->next;
}
}
Popup_Shell(s)
Shell *s;
{
Resource *resource;
/***************************************************************
* If the shell is not in the current environment, then print
* a warning and return.
**************************************************************/
if ( !ShellInCurrentEnviron(s) ) {
sprintf(errorbuf,"shell [%s] not in current environment\n",s->name);
XgenWarning("popup shell",errorbuf);
return;
}
if ( (NULL != (resource = IndexResource((char *)s,SHELL,"set"))) ||
(NULL != (resource = IndexResource((char *)s,SHELL,"runforeground"))) ||
(NULL != (resource = IndexResource((char *)s,SHELL,"runbackground")))) {
while ( resource ) {
if ( !strcmp(resource->name,"set") )
DoSet((char *)s,resource,SHELL,NULL);
if ( !strncmp(resource->name,"run",3) )
DoJob((char *)s,resource,SHELL);
resource = resource->next;
}
}
/***************************************************************
* If the widget doesn't exist create it.
**************************************************************/
if ( !s->widget ) {
Create_Shell(s);
/***************************************************************
* else destroy the old one and recreate it.
**************************************************************/
} else {
Popdown_Shell(s);
Create_Shell(s);
}
/***************************************************************
* pop it up.
**************************************************************/
XtPopup(s->widget,XtGrabNone);
s->popup = True;
/***************************************************************
* check for existance of a sensitivity command....
**************************************************************/
if ( (NULL !=
(resource = IndexResource((char *)s,SHELL,"sensitive"))) ||
(NULL !=
(resource = IndexResource((char *)s,SHELL,"insensitive")))) {
while ( resource ) {
if ( !strcmp(resource->name,"sensitive") ) {
EffectSensitivity(resource->val.cval,True);
}
if ( !strcmp(resource->name,"insensitive") ) {
EffectSensitivity(resource->val.cval,False);
}
resource = resource->next;
}
}
}
Popdown_Shell(s)
Shell *s;
{
InterfaceObject *o = s->objects;
if ( s->widget ) {
XtPopdown(s->widget);
XtDestroyWidget(s->widget);
/***************************************************************
* If any list or toggle objects are in this shell we must clean
* them up.
**************************************************************/
while ( o ) {
switch ( o->type ) {
case LIST:
DeleteListInfo(o->name);
break;
case TOGGLE:
DeleteToggleInfo(o->name);
break;
}
o = o->next;
}
}
s->popup = False;
s->widget = (Widget)0;
if ( s->dynObjects ) {
FreeWidgetList(s->dynObjects);
}
s->dynObjects = (WidgetListElement *)0;
}
FreeWidgetList(wl)
WidgetListElement * wl;
{
if ( wl->next != NULL ) {
FreeWidgetList(wl->next);
}
XtFree(wl);
}
@//E*O*F ./xgen/src/popup.c//
chmod u=rw,g=r,o=r ./xgen/src/popup.c
echo x - ./xgen/src/addnode.c
sed 's/^@//' > "./xgen/src/addnode.c" <<'@//E*O*F ./xgen/src/addnode.c//'
/**********************************************************************
addnode.c - add a node to Xgen's internal hierarchy
*********************************************************************/
/*******************************************************************************
Xgen was developed by Kurt Buehler, while at the Center for Advanced Decision
Support for Water and Environmental Systems (CADSWES), University of Colorado
at Boulder and at the Indiana Water Resources Research Center (IWRRC),
Purdue University for the U.S. Army Construction Engineering Research
Laboratory in support of the Geographical Resources Analysis Support
System (GRASS) software. The example scripts were developed by Ms. Christine
Poulsen of USA-CERL, much thanks goes to her for her work.
Permission to use, copy, modify and distribute without charge this software,
documentation, etc. is granted, provided that this comment is retained,
and that the names of Kurt Buehler, Christine Poulsen, CADSWES, IWRRC,
the University of Colorado at Boulder, Purdue University, or USA-CERL are not
used in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
The author disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
the author be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
*******************************************************************************/
#include "xgen.h"
/***************************************************************
* AddValue
* Add a value node to a resource node. Take into account
* the type of value and assign to the proper union element.
* If the resource is a variable, store it for later expansion.
* Unless it is a run or set procedure.
**************************************************************/
AddValue(rptr,value,rtype)
Resource *rptr;
char *value;
int rtype;
{
rptr->name = ResourceString(rtype);
rptr->type = ResourceDataType(rtype);
if ( rptr->type != STRING && IsVariable(value)) {
rptr->variable = True;
rptr->varValue = SaveString(value);
} else {
switch(rptr->type) {
case STRING:
/***************************************************************
* if the string has a variable and its not a set command
* or related in any way to running jobs, assign the value to
* the variable field, else assign the value straight to
* the resource.
**************************************************************/
if ( rptr->variable && (strncmp(rptr->name,"set",3) ||
strncmp(rptr->name,"run",3) ||
strcmp(rptr->name,"commandarg")))
rptr->varValue = value;
else
rptr->val.cval = value;
break;
case REAL:
rptr->val.dval = strtod(value,(char **)NULL);
break;
case INTEGER:
rptr->val.ival = atoi(value);
break;
case BOOLEAN:
rptr->val.bval =
(((!strcmp(value,"True")) ||
(!strcmp(value,"true")) ||
(!strcmp(value,"On")) ||
(!strcmp(value,"on"))) ? True:False);
break;
}
}
}
/***************************************************************
* AddResource
* Add a value resource to a node. This function will add a
* resource node to any node type.
**************************************************************/
AddResource(rptr,cptr,type,value,rtype)
Resource *rptr;
caddr_t cptr;
int type;
char *value;
int rtype;
{
Resource *p;
switch(type) {
case ENVIRONMENT:
{
Environ *ptr = (Environ *)cptr;
if ( ptr->resources == (Resource *)0 ) {
ptr->resources = rptr;
AddValue(ptr->resources,value,rtype);
return;
}
p = ptr->resources;
while( p->next != (Resource *)0 )
p = p->next;
p->next = rptr;
AddValue(p->next,value,rtype);
}
break;
case SHELL:
{
Shell *ptr = (Shell *)cptr;
if ( ptr->resources == (Resource *)0 ) {
ptr->resources = rptr;
AddValue(ptr->resources,value,rtype);
return;
}
p = ptr->resources;
while( p->next != (Resource *)0 )
p = p->next;
p->next = rptr;
AddValue(p->next,value,rtype);
}
break;
case OBJECT:
{
InterfaceObject *ptr = (InterfaceObject *)cptr;
if ( ptr->resources == (Resource *)0 ) {
ptr->resources = rptr;
AddValue(ptr->resources,value,rtype);
return;
}
p = ptr->resources;
while( p->next != (Resource *)0 )
p = p->next;
p->next = rptr;
AddValue(p->next,value,rtype);
}
break;
default:
XgenFatalError("AddResource","invalid resource type");
}
}
/***************************************************************
* AddObject
* Add an object node to a shell node.
**************************************************************/
AddObject(optr,sptr)
InterfaceObject *optr;
Shell *sptr;
{
InterfaceObject *p;
if ( sptr->objects == (InterfaceObject *)0 ) {
sptr->objects = optr;
return;
}
p = sptr->objects;
while( p->next != (InterfaceObject *)0 )
p = p->next;
p->next = optr;
}
/***************************************************************
* AddPulldownObject
* Add an object node to a pulldown object node.
**************************************************************/
AddPulldownObject(optr,pptr)
InterfaceObject *optr;
InterfaceObject *pptr;
{
InterfaceObject *p;
if ( pptr->objects == (InterfaceObject *)0 ) {
pptr->objects = optr;
return;
}
p = pptr->objects;
while( p->next != (InterfaceObject *)0 )
p = p->next;
p->next = optr;
}
/***************************************************************
* AddShell
* Add an shell node to a environment node.
**************************************************************/
AddShell(sptr,eptr)
Shell *sptr;
Environ *eptr;
{
Shell *p;
if ( eptr->shells == (Shell *)0 ) {
eptr->shells = sptr;
return;
}
p = eptr->shells;
while( p->next != (Shell *)0 )
p = p->next;
p->next = sptr;
}
/***************************************************************
* AddEnviron
* Add an environment node to the global list.
**************************************************************/
AddEnviron(eptr)
Environ *eptr;
{
Environ *p;
if ( xgenGD.toplevelEnv == (Environ *)0 ) {
xgenGD.toplevelEnv = eptr;
return;
}
p = xgenGD.toplevelEnv;
while( p->next != (Environ *)0 )
p = p->next;
p->next = eptr;
}
@//E*O*F ./xgen/src/addnode.c//
chmod u=rw,g=r,o=r ./xgen/src/addnode.c
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
160 628 5503 procmess.c
120 530 6052 resource.h
135 521 5459 sensitive.c
220 586 6987 control.c
218 716 7040 docapture.c
197 643 6853 popup.c
226 756 7433 addnode.c
1276 4380 45327 total
!!!
wc ./xgen/src/procmess.c ./xgen/src/resource.h ./xgen/src/sensitive.c ./xgen/src/control.c ./xgen/src/docapture.c ./xgen/src/popup.c ./xgen/src/addnode.c | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0
--
Dan Heller
Z-Code Software O'Reilly && Associates Comp-sources-x:
President Senior Writer comp-sources-x@uunet.uu.net
argv@z-code.com argv@ora.com [^^^ this address only!]