v11i007: catcher -- drag and drop manager, Part02/05
Chuck Musciano
chuck at trantor.harris-atd.com
Tue Jan 29 19:17:05 AEST 1991
Submitted-by: chuck at trantor.harris-atd.com (Chuck Musciano)
Posting-number: Volume 11, Issue 7
Archive-name: catcher/part02
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 5)."
# Contents: catcher.h execute.c lex.c misc.c option.c panel.c
# place_dialog.c samples/sort.dd
# Wrapped by chuck at melmac on Wed Jan 16 13:10:28 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'catcher.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'catcher.h'\"
else
echo shar: Extracting \"'catcher.h'\" \(3686 characters\)
sed "s/^X//" >'catcher.h' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* catcher.h main catcher data structures */
X/* */
X/************************************************************************/
X
X#define PARM_TEXT 0
X#define PARM_NUMERIC 1
X
X#define OPT_EXCLUSIVE 0
X#define OPT_NONEXCLUSIVE 1
X#define OPT_TEXT 2
X
Xtypedef struct catch Catch;
Xtypedef struct choice Choice;
Xtypedef struct command Command;
Xtypedef struct option Option;
Xtypedef struct text Text;
X
Xstruct catch {char *icon; /* the tool icon */
X char *icon_mask; /* and its mask, for color systems */
X char *label; /* name for title bar */
X char *suffix; /* suffix to use for dropped text */
X char escape; /* substitution escape character */
X char ldelim; /* substitution left delimiter */
X char rdelim; /* substitution right delimiter */
X char *message; /* message for the footer while running */
X Command *command; /* a list of command specs */
X };
X
Xstruct command {char *command; /* the command to be run */
X char *label; /* name to put in the panel */
X int optional; /* is this command optional? */
X Option *option; /* a list of command options */
X Panel panel; /* the control panel for this command */
X Panel_item toggle; /* if optional, the comand toggle */
X Command *next; /* more commands */
X };
X
Xstruct text {int type; /* one of PARM_* */
X int length; /* display length of this field */
X int low; /* if numeric, the range minimum */
X int high; /* if numeric, the range maximum */
X char *text_init; /* if text, the initial value */
X int int_init; /* if numeric, the initial value */
X };
X
Xstruct option {char *id; /* internal id of this option */
X char *label; /* name of this option group */
X int type; /* one of OPT_* */
X int horizontal; /* if a choice, layout direction */
X Text text; /* if a text option, the parameters */
X Choice *choice; /* if a choice, the various choices */
X Panel_item item; /* the panel item for this option */
X Option *next; /* more options */
X };
X
Xstruct choice {char *id; /* internal id of this choice */
X char *value; /* insertion text for this choice */
X char *label; /* displayed name of this choice */
X int parameter; /* is there a text parameter? */
X int is_default; /* if a choice, is this one selected? */
X Text text; /* text parameter, if it exists */
X Panel_item item; /* the panel item for the parameter */
X Choice *next; /* more choices */
X };
X
XPUBLIC Catch config;
X
XPUBLIC int output_width;
XPUBLIC int output_height;
END_OF_FILE
if test 3686 -ne `wc -c <'catcher.h'`; then
echo shar: \"'catcher.h'\" unpacked with wrong size!
fi
# end of 'catcher.h'
fi
if test -f 'execute.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'execute.c'\"
else
echo shar: Extracting \"'execute.c'\" \(7281 characters\)
sed "s/^X//" >'execute.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* execute.c fork and run a subcommand */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X#include <fcntl.h>
X
X#include <sys/types.h>
X#include <sys/ioctl.h>
X#include <sys/wait.h>
X
X#include <xview/xview.h>
X#include <xview/textsw.h>
X
X#include "manifest.h"
X
XEXPORT int output_width = 80;
XEXPORT int output_height = 40;
X
XPUBLIC Frame base;
X
XPRIVATE Frame out_win = NULL, err_win = NULL;
XPRIVATE Textsw out_text, err_text;
X
XPRIVATE struct {int pid;
X int output;
X int errors;
X } child[32];
X
XPRIVATE int children = 0;
X
X/************************************************************************/
XPRIVATE close_window(frame)
X
XFrame frame;
X
X{
X textsw_reset((frame == out_win)? out_text : err_text, 0, 0);
X xv_set(frame, FRAME_CMD_PUSHPIN_IN, FALSE, XV_SHOW, FALSE, NULL);
X}
X
X/************************************************************************/
XPRIVATE Notify_value catch_close(frame, event, arg, type)
X
XFrame frame;
XEvent *event;
XNotify_arg arg;
XNotify_event_type type;
X
X{
X if (event_id(event) == '\003' && event_is_down(event)) {
X close_window((frame == (Frame) xv_get(out_text, OPENWIN_NTH_VIEW, 0))? out_win : err_win);
X return(NOTIFY_DONE);
X }
X return(notify_next_event_func(frame, event, arg, type));
X}
X
X/************************************************************************/
XPRIVATE create_windows()
X
X{ char buf[128];
X
X lets_get_busy(base, TRUE, NULL);
X sprintf(buf, "%s: Output", xv_get(base, FRAME_LABEL));
X out_win = (Frame) xv_create(base, FRAME_CMD,
X FRAME_LABEL, buf,
X FRAME_SHOW_FOOTER, TRUE,
X FRAME_DONE_PROC, close_window,
X FRAME_SHOW_RESIZE_CORNER, TRUE,
X NULL);
X xv_set(xv_get(out_win, FRAME_CMD_PANEL), WIN_SHOW, FALSE, NULL);
X out_text = (Textsw) xv_create(out_win, TEXTSW, XV_X, 0, XV_Y, 0, NULL);
X xv_set(out_text, XV_WIDTH, xv_cols(out_text, output_width), XV_HEIGHT, xv_rows(out_text, output_height), NULL);
X window_fit(out_win);
X sprintf(buf, "%s: Errors", xv_get(base, FRAME_LABEL));
X err_win = (Frame) xv_create(base, FRAME_CMD,
X FRAME_LABEL, buf,
X FRAME_SHOW_FOOTER, TRUE,
X FRAME_DONE_PROC, close_window,
X FRAME_SHOW_RESIZE_CORNER, TRUE,
X NULL);
X xv_set(xv_get(err_win, FRAME_CMD_PANEL), WIN_SHOW, FALSE, NULL);
X err_text = (Textsw) xv_create(err_win, TEXTSW, XV_X, 0, XV_Y, 0, NULL);
X xv_set(err_text, XV_WIDTH, xv_cols(err_text, output_width), XV_HEIGHT, xv_rows(err_text, output_height), NULL);
X window_fit(err_win);
X place_dialog(base, out_win);
X place_dialog(base, err_win);
X notify_interpose_event_func(xv_get(out_text, OPENWIN_NTH_VIEW, 0), catch_close, NOTIFY_SAFE);
X notify_interpose_event_func(xv_get(err_text, OPENWIN_NTH_VIEW, 0), catch_close, NOTIFY_SAFE);
X lets_get_busy(base, FALSE, NULL);
X}
X
X/************************************************************************/
XPRIVATE Notify_value reader(client, fd)
X
XNotify_client client;
Xint fd;
X
X{ int i, output, size;
X char buf[1024];
X
X for (i = 0; i < children; i++)
X if (child[i].output == fd) {
X output = TRUE;
X break;
X }
X else if (child[i].errors == fd) {
X output = FALSE;
X break;
X }
X if (i >= children)
X error("output from unknown descriptor %d", fd);
X else if (ioctl(fd, FIONREAD, &size) == 0)
X while (size > 0)
X if ((i = read(fd, buf, sizeof(buf))) > 0) {
X textsw_insert(output? out_text : err_text, buf, i);
X xv_set(output? out_win : err_win, WIN_SHOW, TRUE, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
X if (xv_get(base, FRAME_CLOSED))
X xv_set(base, FRAME_CLOSED, FALSE, NULL);
X size -= i;
X }
X return(NOTIFY_DONE);
X}
X
X/************************************************************************/
XPRIVATE Notify_value reaper(client, pid, status)
X
XNotify_client client;
Xint pid;
Xunion wait *status;
X
X{ int i, j;
X
X if (WIFEXITED(*status)) {
X for (i = 0; i < children; i++)
X if (child[i].pid == pid) {
X notify_set_input_func(client, NOTIFY_FUNC_NULL, child[i].output);
X notify_set_input_func(client, NOTIFY_FUNC_NULL, child[i].errors);
X xv_set(base, FRAME_LEFT_FOOTER, "", NULL);
X close(child[i].output);
X close(child[i].errors);
X for (j = i + 1; j < children; j++)
X child[j - 1] = child[j];
X children--;
X break;
X }
X return(NOTIFY_DONE);
X }
X return(NOTIFY_IGNORED);
X}
X
X/************************************************************************/
XEXPORT execute(cmd, path)
X
Xchar *cmd;
Xchar *path;
X
X{ int pid, input, output[2], errors[2], result;
X FILE *f;
X
X if (out_win == NULL)
X create_windows();
X if (pipe(output) == -1) {
X error("cannot create a pipe: %s", sys_errlist[errno]);
X return;
X }
X if (pipe(errors) == -1) {
X error("cannot create a pipe: %s", sys_errlist[errno]);
X return;
X }
X if ((input = open(path, O_RDONLY)) == -1) {
X error("cannot open %s for reading: %s", path, sys_errlist[errno]);
X return;
X }
X if ((pid = fork()) == -1) {
X error("cannot fork subcommand: %s", sys_errlist[errno]);
X return;
X }
X else if (pid == 0) {
X if (input != 0) {
X dup2(input, 0);
X close(input);
X }
X dup2(output[1], 1);
X dup2(errors[1], 2);
X close(output[0]);
X close(output[1]);
X close(errors[0]);
X close(errors[1]);
X result = system(cmd);
X sleep(2); /* let the output make it through */
X exit(result);
X }
X else {
X child[children].pid = pid;
X child[children].output = output[0];
X child[children].errors = errors[0];
X children++;
X close(input);
X close(output[1]);
X close(errors[1]);
X notify_set_input_func(base, reader, output[0]);
X notify_set_input_func(base, reader, errors[0]);
X notify_set_wait3_func(base, reaper, pid);
X xv_set(out_win, FRAME_LEFT_FOOTER, cmd, NULL);
X xv_set(err_win, FRAME_LEFT_FOOTER, cmd, NULL);
X }
X}
X
X/************************************************************************/
XEXPORT shutdown_windows()
X
X{
X if (out_win) {
X close_window(out_win);
X close_window(err_win);
X }
X}
END_OF_FILE
if test 7281 -ne `wc -c <'execute.c'`; then
echo shar: \"'execute.c'\" unpacked with wrong size!
fi
# end of 'execute.c'
fi
if test -f 'lex.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lex.c'\"
else
echo shar: Extracting \"'lex.c'\" \(7343 characters\)
sed "s/^X//" >'lex.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X#define RETURN(x) return(last_token = (x))
X
X#define FIRST_KEYWORD BY
X#define LAST_KEYWORD WINDOW_
X#define NUM_KEYWORDS (LAST_KEYWORD - FIRST_KEYWORD + 1)
X
XPRIVATE FILE *f = NULL;
XPRIVATE int last_token = -1;
XPRIVATE char buf[1024];
X
XPRIVATE struct {char *name;
X int value;
X } token[] = {{"by", BY},
X {"choice", CHOICE},
X {"command", COMMAND},
X {"default", DEFAULT},
X {"delimiter", DELIMITER},
X {"exclusive", EXCLUSIVE},
X {"horizontal", HORIZONTAL},
X {"icon", ICON_},
X {"icon_mask", ICON_MASK},
X {"init", INIT},
X {"label", LABEL},
X {"message", MESSAGE},
X {"nonexclusive", NONEXCLUSIVE},
X {"numeric", NUMERIC},
X {"optional", OPTIONAL},
X {"output", OUTPUT},
X {"parameter", PARAMETER},
X {"suffix", SUFFIX},
X {"text", TEXT},
X {"to", TO},
X {"value", VALUE},
X {"window", WINDOW_}};
X
X
X
XPRIVATE struct {char first;
X char next;
X int name;
X } punc[] = {{'{', '\0', LBRACE},
X {'}', '\0', RBRACE},
X {'\0', '\0', -1}};
X
X/************************************************************************/
XEXPORT int lex_init(path)
X
Xchar *path;
X
X{
X if (f)
X fclose(f);
X if (path == NULL) {
X curr_file = "stdin";
X f = stdin;
X line_count = 1;
X ungetc = -1;
X return(TRUE);
X }
X else if (f = fopen(path, "r")) {
X curr_file = strsave(path);
X line_count = 1;
X ungetc = -1;
X return(TRUE);
X }
X else
X return(FALSE);
X}
X
X/************************************************************************/
XPRIVATE char getch()
X
X{ register char c;
X static int first = TRUE;
X
X if (ungetc != -1)
X c = ungetc, ungetc = -1;
X else if (f == NULL)
X return(EOF);
X else {
X c = getc(f);
X if (c == '\n')
X line_count++;
X }
X return(c);
X}
X
X/************************************************************************/
XEXPORT fix_escapes(buf)
X
Xchar *buf;
X
X{ char *q;
X int i;
X
X for (q = buf; *buf; buf++, q++)
X if (*buf == '\\')
X switch (*++buf) {
X case 'b' : *q = '\010'; /* ^h */
X break;
X case 'e' : *q = '\033'; /* esc */
X break;
X case 'f' : *q = '\014'; /* ^l */
X break;
X case 'n' : *q = '\012'; /* ^j */
X break;
X case 'r' : *q = '\015'; /* ^m */
X break;
X case 't' : *q = '\011'; /* ^i */
X break;
X case '0' :
X case '1' :
X case '2' :
X case '3' :
X case '4' :
X case '5' :
X case '6' :
X case '7' : *q = *buf++ - '0';
X for (i = 0; i < 2 && *buf >= '0' && *buf <= '7'; i++)
X *q = (*q << 3) + *buf++ - '0';
X buf--;
X break;
X default : *q = *buf;
X break;
X }
X else if (*buf == '^' && *(buf + 1) >= '@' && *(buf + 1) <= '_')
X *q = *++buf & 0x1f;
X else
X *q = *buf;
X *q = '\0';
X}
X
X/************************************************************************/
XPRIVATE int is_keyword(s)
X
Xchar *s;
X
X{ register int cmp, high, low, pos;
X
X for (low = 0, high = NUM_KEYWORDS - 1; low <= high; )
X if ((cmp = strcmp(s, token[pos = (high - low) / 2 + low].name)) == 0)
X return(token[pos].value);
X else if (cmp < 0)
X high = pos - 1;
X else
X low = pos + 1;
X return(NULL);
X}
X
X/************************************************************************/
XPRIVATE int yylex()
X
X{ register char c, c1, *p;
X register int i, j, val;
X char *index(), *temp;
X double atof();
X
X c = getch();
X while (isspace(c))
X c = getch();
X if (isalpha(c)) {
X p = buf;
X *p++ = c;
X while (isalnum(c = getch()) || c == '_')
X *p++ = c;
X ungetc = c;
X *p = '\0';
X temp = strsave(buf);
X for (p = buf; *p; p++)
X if (isupper(*p))
X *p = tolower(*p);
X if (i = is_keyword(buf)) {
X free(temp);
X RETURN(i);
X }
X else {
X strcpy(buf, temp);
X free(temp);
X yylval.cpval = buf;
X RETURN(ID);
X }
X }
X else if (c == '"') {
X for (p = buf; TRUE; p++)
X if ((*p = getch()) == '"')
X break;
X else if (*p == '\\')
X *++p = getch();
X else if (*p == '\n' || *p == '\r') {
X yyerror("Newline in string not allowed");
X break;
X }
X *p = '\0';
X fix_escapes(buf);
X yylval.cpval = buf;
X RETURN(STRING);
X }
X else if (c == '-' || isdigit(c)) {
X p = buf;
X *p++ = c;
X while (isdigit(c = getch()))
X *p++ = c;
X *p = '\0';
X ungetc = c;
X yylval.ival = atoi(buf);
X RETURN(INTEGER);
X }
X else if (c == EOF) {
X fclose(f);
X f = NULL;
X RETURN(EOF);
X }
X else if (c == '#') {
X while (getch() != '\n')
X ;
X RETURN(yylex());
X }
X else {
X for (i = 0; punc[i].first; i++)
X if (c == punc[i].first) {
X for (c1 = getch(), j = 1; punc[i + j].first == c; j++)
X if (c1 == punc[i + j].next)
X RETURN(punc[i + j].name);
X ungetc = c1;
X RETURN(punc[i].name);
X }
X yyerror("Invalid character in source file: %c (0x%02x)", c, c);
X }
X RETURN(yylex());
X}
X
X/************************************************************************/
XPRIVATE char *get_last_token()
X
X{ int i;
X static char msg[512];
X
X if (last_token == INTEGER || last_token == STRING || last_token == ID)
X sprintf(msg, "\"%s\"", buf);
X else if (last_token >= LBRACE && last_token <= RBRACE) {
X for (i = 0; punc[i].first; i++)
X if (punc[i].name == last_token) {
X sprintf(msg, "\"%c\"", punc[i].first);
X if (punc[i].next)
X sprintf(msg + 2, "%c\"", punc[i].next);
X break;
X }
X if (punc[i].first == '\0')
X sprintf(msg, "!!Geez! Some punctuation, I don't know!!");
X }
X else if (last_token >= FIRST_KEYWORD && last_token <= LAST_KEYWORD)
X sprintf(msg, "\"%s\"", token[last_token - FIRST_KEYWORD].name);
X else if (last_token == EOF)
X sprintf(msg, "End Of File");
X else
X sprintf(msg, "!!Geez! Some keyword, I don't know!!");
X return(msg);
X}
END_OF_FILE
if test 7343 -ne `wc -c <'lex.c'`; then
echo shar: \"'lex.c'\" unpacked with wrong size!
fi
# end of 'lex.c'
fi
if test -f 'misc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'misc.c'\"
else
echo shar: Extracting \"'misc.c'\" \(2821 characters\)
sed "s/^X//" >'misc.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* misc.c miscellaneous support and conversion routines */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X#include <ctype.h>
X
X#include "manifest.h"
X
X/************************************************************************/
XEXPORT error(a, b, c, d, e, f, g, h)
X
Xint a, b, c, d, e, f, g, h;
X
X{ char buf[1024];
X
X sprintf(buf, a, b, c, d, e, f, g, h);
X fprintf(stderr, "%s\n", buf);
X}
X
X/************************************************************************/
XEXPORT abend(a, b, c, d, e, f, g, h)
X
Xint a, b, c, d, e, f, g, h;
X
X{
X error(a, b, c, d, e, f, g, h);
X exit(1);
X}
X
X/************************************************************************/
XPRIVATE delarg(argc, argv)
X
Xint *argc;
Xchar **argv;
X
X{ char *p;
X
X while (*argv = *(argv+1))
X argv++;
X (*argc)--;
X}
X
X/************************************************************************/
XEXPORT char getopt(argc, argv, opts, parm)
X
Xint *argc;
Xchar **argv;
Xchar *opts;
Xchar **parm;
X
X{ char c, *p, *index();
X int killed;
X
X *parm = NULL;
X while (*argv && ((**argv != '-') || (*(*argv+1) == '\0')))
X argv++;
X if (*argv == NULL)
X return(EOF);
X c = *(*argv+1);
X *++(*argv) = '-';
X if (killed = (*(*argv+1) == '\0'))
X delarg(argc, argv);
X if ((p = index(opts, c)) == NULL)
X c = '\0';
X else if (*(p+1) == ':') {
X *parm = killed ? *argv : *argv+1;
X delarg(argc, argv);
X }
X return(c);
X}
X
X/************************************************************************/
XEXPORT int is_empty(s)
X
Xchar *s;
X
X{
X if (s == NULL)
X return(TRUE);
X for (; *s; s++)
X if (!isspace(*s))
X return(FALSE);
X return(TRUE);
X}
END_OF_FILE
if test 2821 -ne `wc -c <'misc.c'`; then
echo shar: \"'misc.c'\" unpacked with wrong size!
fi
# end of 'misc.c'
fi
if test -f 'option.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'option.c'\"
else
echo shar: Extracting \"'option.c'\" \(5448 characters\)
sed "s/^X//" >'option.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* option.c build a single option */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X
X#include <xview/xview.h>
X#include <xview/panel.h>
X
X#include "manifest.h"
X#include "catcher.h"
X
X/************************************************************************/
XPRIVATE choice_toggle(item, value, event)
X
XPanel_item item;
Xint value;
XEvent *event;
X
X{ Option *opt;
X Choice *c;
X int i;
X
X opt = (Option *) xv_get(item, PANEL_CLIENT_DATA);
X for (i = 0, c = opt->choice; c; i++, c = c->next)
X if (c->item)
X if (opt->type == OPT_EXCLUSIVE)
X xv_set(c->item, PANEL_INACTIVE, value != i, NULL);
X else
X xv_set(c->item, PANEL_INACTIVE, !(value & (1 << i)), NULL);
X}
X
X/************************************************************************/
XPRIVATE create_text(panel, item, i, choice)
X
XPanel panel;
XPanel_item item;
Xint i;
XChoice *choice;
X
X{
X if (choice->text.type == PARM_TEXT)
X choice->item = (Panel_item) xv_create(panel, PANEL_TEXT,
X PANEL_VALUE_DISPLAY_LENGTH, choice->text.length,
X PANEL_VALUE_STORED_LENGTH, 10 * choice->text.length,
X PANEL_VALUE, choice->text.text_init? choice->text.text_init : "",
X PANEL_INACTIVE, TRUE,
X XV_X, (int) X_MARGIN + (int) xv_get(item, XV_WIDTH) + ITEM_GAP,
X XV_Y, (int) xv_get(item, PANEL_CHOICE_Y, i) + 5,
X NULL);
X else
X choice->item = (Panel_item) xv_create(panel, PANEL_NUMERIC_TEXT,
X PANEL_MIN_VALUE, choice->text.low,
X PANEL_MAX_VALUE, choice->text.high,
X PANEL_VALUE_DISPLAY_LENGTH, choice->text.length,
X PANEL_VALUE_STORED_LENGTH, 10 * choice->text.length,
X PANEL_VALUE, choice->text.int_init,
X PANEL_INACTIVE, TRUE,
X XV_X, (int) X_MARGIN + (int) xv_get(item, XV_WIDTH) + ITEM_GAP,
X XV_Y, (int) xv_get(item, PANEL_CHOICE_Y, i) + 5,
X NULL);
X}
X
X/************************************************************************/
XEXPORT create_option(panel, opt, option_y)
X
XPanel panel;
XOption *opt;
Xint option_y;
X
X{ int i, val;
X Choice *c;
X
X if (opt->type == OPT_EXCLUSIVE)
X opt->item = (Panel_item) xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, opt->label,
X PANEL_LABEL_BOLD, TRUE,
X opt->horizontal? PANEL_CHOICE_NROWS : PANEL_CHOICE_NCOLS, 1,
X PANEL_CLIENT_DATA, opt,
X PANEL_NOTIFY_PROC, choice_toggle,
X XV_X, X_MARGIN,
X XV_Y, option_y,
X NULL);
X else if (opt->type == OPT_NONEXCLUSIVE)
X opt->item = (Panel_item) xv_create(panel, PANEL_TOGGLE,
X PANEL_LABEL_STRING, opt->label,
X PANEL_LABEL_BOLD, TRUE,
X opt->horizontal? PANEL_CHOICE_NROWS : PANEL_CHOICE_NCOLS, 1,
X PANEL_CLIENT_DATA, opt,
X PANEL_NOTIFY_PROC, choice_toggle,
X XV_X, X_MARGIN,
X XV_Y, option_y,
X NULL);
X else if (opt->text.type == PARM_TEXT)
X opt->item = (Panel_item) xv_create(panel, PANEL_TEXT,
X PANEL_LABEL_STRING, opt->label,
X PANEL_LABEL_BOLD, TRUE,
X PANEL_VALUE_DISPLAY_LENGTH, opt->text.length,
X PANEL_VALUE_STORED_LENGTH, 10 * opt->text.length,
X XV_X, X_MARGIN,
X XV_Y, option_y,
X NULL);
X else
X opt->item = (Panel_item) xv_create(panel, PANEL_NUMERIC_TEXT,
X PANEL_LABEL_STRING, opt->label,
X PANEL_LABEL_BOLD, TRUE,
X PANEL_MIN_VALUE, opt->text.low,
X PANEL_MAX_VALUE, opt->text.high,
X PANEL_VALUE_DISPLAY_LENGTH, opt->text.length,
X PANEL_VALUE_STORED_LENGTH, 10 * opt->text.length,
X XV_X, X_MARGIN,
X XV_Y, option_y,
X NULL);
X if (opt->type != OPT_TEXT) {
X for (i = val = 0, c = opt->choice; c; i++, c = c->next) {
X xv_set(opt->item, PANEL_CHOICE_STRING, i, c->label, NULL);
X if (c->is_default)
X if (opt->type == OPT_EXCLUSIVE)
X val = i;
X else
X val |= 1 << i;
X }
X for (i = 0, c = opt->choice; c; i++, c = c->next)
X if (c->parameter)
X create_text(panel, opt->item, i, c);
X xv_set(opt->item, PANEL_VALUE, val, NULL);
X choice_toggle(opt->item, val, NULL);
X }
X}
END_OF_FILE
if test 5448 -ne `wc -c <'option.c'`; then
echo shar: \"'option.c'\" unpacked with wrong size!
fi
# end of 'option.c'
fi
if test -f 'panel.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'panel.c'\"
else
echo shar: Extracting \"'panel.c'\" \(3631 characters\)
sed "s/^X//" >'panel.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* panel.c build a command panel */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X
X#include <xview/xview.h>
X#include <xview/panel.h>
X
X#include "manifest.h"
X#include "catcher.h"
X
X/************************************************************************/
XPRIVATE command_toggle(item, value, event)
X
XPanel_item item;
Xint value;
XEvent *event;
X
X{ Option *o;
X Command *c;
X Choice *ch;
X int i, val;
X
X c = (Command *) xv_get(item, PANEL_CLIENT_DATA);
X for (o = c->option; o; o = o->next) {
X xv_set(o->item, PANEL_INACTIVE, !value, NULL);
X if (o->type != OPT_TEXT) {
X val = (int) xv_get(o->item, PANEL_VALUE);
X for (i = 0, ch = o->choice; ch; ch = ch->next, i++)
X if (ch->item)
X if (value == 0)
X xv_set(ch->item, PANEL_INACTIVE, TRUE, NULL);
X else if (o->type == OPT_EXCLUSIVE)
X xv_set(ch->item, PANEL_INACTIVE, val != i, NULL);
X else if (o->type == OPT_NONEXCLUSIVE)
X xv_set(ch->item, PANEL_INACTIVE, !(val & (1 << i)), NULL);
X }
X }
X}
X
X/************************************************************************/
XEXPORT create_panel(base, cmd, panel_y)
X
XFrame base;
XCommand *cmd;
Xint panel_y;
X
X{ int y;
X Option *opt;
X Choice *c;
X
X cmd->panel = (Panel) xv_create(base, PANEL,
X XV_X, 0,
X XV_Y, panel_y,
X WIN_BORDER, TRUE,
X NULL);
X if (cmd->optional)
X cmd->toggle = (Panel_item) xv_create(cmd->panel, PANEL_CHECK_BOX,
X PANEL_CHOICE_STRINGS, "", NULL,
X PANEL_LABEL_STRING, cmd->label,
X PANEL_LABEL_BOLD, TRUE,
X PANEL_VALUE_X, TOP_MARGIN,
X PANEL_VALUE_Y, TOP_MARGIN,
X PANEL_LABEL_X, TOP_MARGIN + 20,
X PANEL_LABEL_Y, TOP_MARGIN,
X PANEL_VALUE, 1,
X PANEL_NOTIFY_PROC, command_toggle,
X PANEL_CLIENT_DATA, cmd,
X NULL);
X else
X cmd->toggle = (Panel_item) xv_create(cmd->panel, PANEL_MESSAGE,
X PANEL_LABEL_STRING, cmd->label,
X PANEL_LABEL_BOLD, TRUE,
X PANEL_LABEL_X, TOP_MARGIN,
X PANEL_LABEL_Y, TOP_MARGIN,
X NULL);
X
X y = (int) xv_get(cmd->toggle, XV_HEIGHT) + TOP_MARGIN + ITEM_GAP;
X for (opt = cmd->option; opt; opt = opt->next) {
X create_option(cmd->panel, opt, y);
X y += (int) xv_get(opt->item, XV_HEIGHT) + ITEM_GAP;
X }
X
X window_fit(cmd->panel);
X}
END_OF_FILE
if test 3631 -ne `wc -c <'panel.c'`; then
echo shar: \"'panel.c'\" unpacked with wrong size!
fi
# end of 'panel.c'
fi
if test -f 'place_dialog.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'place_dialog.c'\"
else
echo shar: Extracting \"'place_dialog.c'\" \(2563 characters\)
sed "s/^X//" >'place_dialog.c' <<'END_OF_FILE'
X/************************************************************************/
X/* Copyright 1987-1991 by Chuck Musciano and Harris Corporation */
X/* */
X/* Full ownership of this software, and all rights pertaining to */
X/* the for-profit distribution of this software, are retained by */
X/* Chuck Musciano and Harris Corporation. You are permitted to */
X/* use this software without fee. This software is provided "as */
X/* is" without express or implied warranty. You may redistribute */
X/* this software, provided that this copyright notice is retained, */
X/* and that the software is not distributed for profit. If you */
X/* wish to use this software in a profit-making venture, you must */
X/* first license this code and its underlying technology from */
X/* Harris Corporation. */
X/* */
X/* Bottom line: you can have this software, you can use it, you */
X/* can give it away. You just can't sell any or all parts of it */
X/* without prior permission from Harris Corporation. */
X/************************************************************************/
X
X/************************************************************************/
X/* */
X/* place_dialog.c position a dialog box at the right place */
X/* */
X/************************************************************************/
X
X#include <stdio.h>
X#include <sys/param.h>
X#include <sys/types.h>
X#include <xview/xview.h>
X#include <X11/Xutil.h>
X
X#include "manifest.h"
X
X/************************************************************************/
XEXPORT void place_dialog(base, dialog)
X
XXv_opaque base;
XXv_opaque dialog;
X
X{ Rect br, dr, sr;
X XWMHints *hints;
X
X sr = *((Rect *) xv_get(base, WIN_SCREEN_RECT));
X frame_get_rect(base, &br);
X frame_get_rect(dialog, &dr);
X if (rect_right(&br) + dr.r_width < sr.r_width) {
X dr.r_left = rect_right(&br);
X dr.r_top = br.r_top;
X }
X else if (dr.r_width <= br.r_left) {
X dr.r_left = br.r_left - dr.r_width;
X dr.r_top = br.r_top;
X }
X else {
X dr.r_left = br.r_left + 32;
X dr.r_top = br.r_top + 32;
X }
X if (dr.r_top + dr.r_height > sr.r_height)
X dr.r_top = sr.r_height - dr.r_height;
X if (dr.r_top < 0)
X dr.r_top = 0;
X if (rect_right(&dr) > sr.r_width)
X dr.r_left = sr.r_width - dr.r_width;
X if (dr.r_left < 0)
X dr.r_left = 0;
X frame_set_rect(dialog, &dr);
X
X hints = XGetWMHints(xv_get(dialog, XV_DISPLAY), xv_get(dialog, XV_XID));
X hints->flags |= StateHint;
X hints->initial_state = NormalState;
X XSetWMHints(xv_get(dialog, XV_DISPLAY), xv_get(dialog, XV_XID), hints);
X XFree(hints);
X}
X
END_OF_FILE
if test 2563 -ne `wc -c <'place_dialog.c'`; then
echo shar: \"'place_dialog.c'\" unpacked with wrong size!
fi
# end of 'place_dialog.c'
fi
if test -f 'samples/sort.dd' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'samples/sort.dd'\"
else
echo shar: Extracting \"'samples/sort.dd'\" \(2522 characters\)
sed "s/^X//" >'samples/sort.dd' <<'END_OF_FILE'
X#!/usr/local/bin/catcher
X#
X# Sort, uniq, and wc a dropped file
X
Xlabel "Sort A File"
Xicon "sort.icon"
Xicon_mask "sort.mask"
Xoutput 24 by 80
Xsuffix ""
Xmessage "Processing ${file:t}..."
Xcommand {
X label "Sort a file:"
X optional
X command "sort $dict $fold $month $number $reverse $field"
X exclusive field {
X label "Key field:"
X horizontal
X choice {
X label "First"
X value ""
X default
X }
X choice {
X label "Second"
X value "+1"
X }
X choice {
X label "Third"
X value "+2"
X }
X choice {
X label "Fourth"
X value "+3"
X }
X choice {
X label "Fifth"
X value "+4"
X }
X }
X nonexclusive {
X label "Options:"
X choice fold {
X label "Case does not matter"
X value "-f"
X }
X choice month {
X label "Sort by months"
X value "-M"
X }
X choice reverse {
X label "Sort in reverse order"
X value "-r"
X }
X choice number {
X label "Sort numerically"
X value "-n"
X }
X choice dict {
X label "Use dictionary order"
X value "-d"
X }
X }
X }
Xcommand {
X label "Remove duplicate lines:"
X optional
X command "uniq $option"
X exclusive option {
X label "Extract:"
X choice {
X label "One copy of each line"
X value ""
X }
X choice {
X label "One copy of each line, with occurence counts"
X value "-c"
X }
X choice {
X label "One copy of lines only"
X value "-d"
X }
X choice {
X label "One copy of lines only"
X value "-u"
X }
X }
X }
Xcommand {
X label "Count lines:"
X optional
X command "wc $option"
X exclusive option {
X label "Count:"
X horizontal
X choice {
X label "Characters"
X value "-c"
X }
X choice {
X label "Words"
X value "-w"
X }
X choice {
X label "Lines"
X value "-l"
X default
X }
X }
X }
Xcommand {
X label "Disposition of results:"
X command "cat $result"
X exclusive result {
X label ""
X choice {
X label "A window"
X value ""
X default
X }
X choice {
X label "A file suffixed with .sort"
X value ">${file:r}.sort"
X }
X choice {
X label "Another file"
X parameter text 25
X value ">${result.value}"
X }
X }
X }
END_OF_FILE
if test 2522 -ne `wc -c <'samples/sort.dd'`; then
echo shar: \"'samples/sort.dd'\" unpacked with wrong size!
fi
# end of 'samples/sort.dd'
fi
echo shar: End of archive 2 \(of 5\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 5 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list