[comp.sources.misc] v18i016: jgraph - A filter for plotting postscript graphs, Patch03

jsp@Princeton.EDU (James Plank) (04/14/91)

Submitted-by: James Plank <jsp@Princeton.EDU>
Posting-number: Volume 18, Issue 16
Archive-name: jgraph/patch03
Patch-To: jgraph: Volume 16, Issue 20

I just made a small addition to jgraph to allow for shell escapes in
the input.  More specifically, you can do things like

newcurve pts shell : awk '{print $3, $7}' stats

to extract points from columns 3 & 7 of the file stats.  
No bugs fixes in this patch, just expanded fuctionality.

Jim Plank
jsp@princeton.edu
------
# To unbundle, "sed '1,/^# To unbundle/d' < thisfile | sh"
# Fri Apr 12 17:37:43 EDT 1991
echo PATCH.3.README 1>&2
sed 's/^-//' >'PATCH.3.README' <<'End of PATCH.3.README'
-This patch adds shell escapes to jgraph.  More specifically, you can
-do things like
-
-newcurve pts shell : awk '{print $3, $7}' stats
-
-to extract points from columns 3 & 7 of the file stats.  For more information,
-see the man page.
-
-Apply the patch by:
-
-patch < patch.3
End of PATCH.3.README
echo patch.3 1>&2
sed 's/^-//' >'patch.3' <<'End of patch.3'
-*** jgraph.1	Fri Apr 12 17:23:20 1991
---- ../export/jgraph.1	Fri Apr 12 17:11:27 1991
-***************
-*** 87,94 ****
-  attributes.  All keywords and attributes except for string attributes
-  are tokens -- non-white-space characters surrounded by white-space. 
-  Special tokens are 
-! ``(*'', ``*)'', ``include'' and ``:'', which denote
-! comments, include-file statments, and string identifiers:
-  .TP 
-  .B Comments
-  Comments are surrounded by the tokens ``(*'' ``*)'' as in
---- 87,95 ----
-  attributes.  All keywords and attributes except for string attributes
-  are tokens -- non-white-space characters surrounded by white-space. 
-  Special tokens are 
-! ``(*'', ``*)'', ``include'', ``:'', and ``shell'', which denote
-! comments, include-file statements, string identifiers, and shell-include
-! statements:
-  .TP 
-  .B Comments
-  Comments are surrounded by the tokens ``(*'' ``*)'' as in
-***************
-*** 100,106 ****
-  The token following an ``include'' token is
-  expected to be a file name.  The result of the statement is to
-  include the contents of the file at that point.  Include-file
-! statments can be nested within included files.
-  .TP 
-  .B Strings
-  In places where strings are required (as in graph and
---- 101,108 ----
-  The token following an ``include'' token is
-  expected to be a file name.  The result of the statement is to
-  include the contents of the file at that point.  Include-file
-! statments can be nested within included files, and within shell
-! includes.
-  .TP 
-  .B Strings
-  In places where strings are required (as in graph and
-***************
-*** 125,130 ****
---- 127,139 ----
-  Once a string has been started, it may contain any character besides
-  a newline.  Specifically, it may contain the sequence ``(*'' or
-  ``include'' without starting a comment or including a file.
-+ .TP
-+ .B Shell\-include statements
-+ Shell include statements are of the form ``shell'', ``:'', and then
-+ a string.  The result of the statment is that the string is executed
-+ (using popen, which passes the string to sh), and the standard
-+ output is included at that point.  Shell-includes can be freely
-+ nested within include-files and other shell-includes.
-  .TP
-  .B Notation
-  In the descriptions below: 
-*** jgraph.c	Fri Apr 12 17:24:43 1991
---- ../export/jgraph.c	Fri Apr 12 17:11:23 1991
-***************
-*** 47,54 ****
-                           "ellipse", "general", "xbar", "ybar", "none" };
-  char MARKTYPES[] = { 'o', 'b', 'd', 't', 'x', 'c', 'e', 'g', 'X', 'Y', 'n' };
-  
-- 
-- 
-  Label new_label()
-  {
-    Label l;
---- 47,52 ----
-***************
-*** 55,65 ****
-  
-    l = (Label) malloc (sizeof(struct label));
-    l->label = CNULL;
-!   l->hj = 'c';
-!   l->vj = 'b';
-!   l->font = "Times-Roman";
-!   l->fontsize = 9.0;
-!   l->rotate = 0;
-  
-    return l;
-  }
---- 53,63 ----
-  
-    l = (Label) malloc (sizeof(struct label));
-    l->label = CNULL;
-!   l->hj = '!';
-!   l->vj = '!';
-!   l->font = CNULL;
-!   l->fontsize = FSIG;
-!   l->rotate = FSIG;
-  
-    return l;
-  }
-***************
-*** 198,203 ****
---- 196,221 ----
-    return new_s;
-  }
-  
-+ /*
-+ Default new_default()
-+ {
-+   Default new_d;
-+   new_d = (Default) malloc (sizeof(default));
-+   new_d->rotate = FSIG;
-+   new_d->fontsize = FSIG;
-+   new_d->general_marks = GMNULL;
-+   new_d->fill = FSIG;
-+   new_d->linethick = FSIG;
-+   new_d->font = CNULL;
-+   new_d->hj = '!';
-+   new_d->vj = '!';
-+   new_d->marktype = '!';
-+   new_d->linetype = '!';
-+   new_d->marksize[0] = FSIG;
-+   new_d->marksize[1] = FSIG;
-+ }
-+ */
-+   
-  Graph new_graph(gs, num)
-  Graph gs;
-  int num;
-***************
-*** 215,220 ****
---- 233,239 ----
-    g->strings = (String) make_list(sizeof(struct string));
-    g->title = new_title();
-    g->legend = new_legend();
-+ /*  g->def = new_default(); */
-    prio_insert(g, gs, 0);
-    return g;
-  }
-*** jgraph.h	Fri Apr 12 17:24:44 1991
---- ../export/jgraph.h	Fri Apr 12 17:11:23 1991
-***************
-*** 41,47 ****
-  
-  #include "list.h"
-  #include "prio_list.h"
-- #include "fprio_list.h"
-  #ifdef LCC
-  #include <stdlib.h>
-  #endif
---- 41,46 ----
-***************
-*** 51,56 ****
---- 50,56 ----
-  #define CPI 72.0
-  #define FCPI 72.0
-  #define CNULL ((char *)0)
-+ #define GMNULL ((Point)0)
-  #define FSIG -10010.0
-  #define HASH_SIZE 5.0
-  #define MHASH_SIZE 2.0
-***************
-*** 101,106 ****
---- 101,119 ----
-    float size;
-  } *Hash;
-  
-+ typedef struct deflt {
-+   float rotate;
-+   float fontsize;
-+   Point general_marks;
-+   float fill;
-+   float linethick;
-+   float marksize[2];
-+   char *font;
-+   char hj;
-+   char vj;
-+   char marktype;
-+ } *Default;
-+   
-  typedef struct axis {
-    Label label;
-    Label hl;
-***************
-*** 158,163 ****
---- 171,177 ----
-    Legend legend;
-    String strings;
-    Label title;
-+   Default def;
-  } *Graph;
-  
-  typedef struct graphs {
-*** makefile	Fri Apr 12 17:24:45 1991
---- ../export/makefile	Fri Apr 12 17:11:27 1991
-***************
-*** 3,9 ****
-  
-  OBJS = draw.o \
-  		edit.o \
-- 		fprio_list.o \
-  		jgraph.o \
-  		list.o \
-  		printline.o \
---- 3,8 ----
-***************
-*** 29,43 ****
-  	$(CC) -g $(OBJS) -lm -o jgraph
-  
-  ###
-! draw.o: draw.c jgraph.h list.h prio_list.h fprio_list.h
-! edit.o: edit.c jgraph.h list.h prio_list.h fprio_list.h
-! fprio_list.o: fprio_list.c list.h prio_list.h
-! jgraph.o: jgraph.c jgraph.h list.h prio_list.h fprio_list.h
-  list.o: list.c list.h
-! printline.o: printline.c jgraph.h list.h prio_list.h fprio_list.h
-  prio_list.o: prio_list.c list.h prio_list.h
-! process.o: process.c jgraph.h list.h prio_list.h fprio_list.h
-! show.o: show.c jgraph.h list.h prio_list.h fprio_list.h
-  token.o: token.c list.h
-  clean: 
-  	rm -f *.o a.out
---- 28,41 ----
-  	$(CC) -g $(OBJS) -lm -o jgraph
-  
-  ###
-! draw.o: draw.c jgraph.h list.h prio_list.h
-! edit.o: edit.c jgraph.h list.h prio_list.h
-! jgraph.o: jgraph.c jgraph.h list.h prio_list.h 
-  list.o: list.c list.h
-! printline.o: printline.c jgraph.h list.h prio_list.h 
-  prio_list.o: prio_list.c list.h prio_list.h
-! process.o: process.c jgraph.h list.h prio_list.h 
-! show.o: show.c jgraph.h list.h prio_list.h 
-  token.o: token.c list.h
-  clean: 
-  	rm -f *.o a.out
-*** token.c	Fri Apr 12 17:24:49 1991
---- ../export/token.c	Fri Apr 12 17:11:25 1991
-***************
-*** 1,4 ****
---- 1,7 ----
-  /* $Log:	token.c,v $
-+  * Revision 1.10  91/04/12  17:06:55  jsp
-+  * Added the shell command to allow jgraph to execute stuff
-+  * 
-   * Revision 1.9  91/01/16  11:04:04  jsp
-   * Fixed Rlog information
-   * 
-***************
-*** 63,68 ****
---- 66,73 ----
-    FILE *stream;
-    int oldcharvalid;
-    char oldchar;
-+   char pipe;
-+   int line;
-  } *Iostack;
-  
-  static char INPUT[300];
-***************
-*** 69,77 ****
---- 74,84 ----
-  static int getnew = 1;
-  static char oldchar = '\0';
-  static oldcharvalid = 0;
-+ static char pipe = 0;
-  static int eof = 0;
-  static int init = 0;
-  static Iostack stack;
-+ 
-  #ifndef VMS 
-  static FILE *IOSTREAM = stdin;
-  #else
-***************
-*** 143,149 ****
-    return (first(stack) == nil(stack));
-  }
-  
-! static push_iostack()
-  {
-    Iostack n;
-  
---- 150,157 ----
-    return (first(stack) == nil(stack));
-  }
-  
-! static push_iostack(p)
-! int p;
-  {
-    Iostack n;
-  
-***************
-*** 153,161 ****
-    n->filename = (char *) malloc (sizeof(char)*(strlen(FILENAME)+2));
-    n->oldchar = oldchar;
-    n->oldcharvalid = oldcharvalid;
-    strcpy(n->filename, FILENAME);
-    insert(n, stack);
-!   IOSTREAM = fopen(INPUT, "r");
-    if (IOSTREAM == NULL) {
-      error_header();
-      fprintf(stderr, "Include file \"%s\" does not exist\n", INPUT);
---- 161,177 ----
-    n->filename = (char *) malloc (sizeof(char)*(strlen(FILENAME)+2));
-    n->oldchar = oldchar;
-    n->oldcharvalid = oldcharvalid;
-+   n->pipe = pipe;
-+   n->line = line;
-    strcpy(n->filename, FILENAME);
-    insert(n, stack);
-!   if (p) {
-!     IOSTREAM = (FILE *) popen(INPUT, "r");
-!   } else {
-!     IOSTREAM = fopen(INPUT, "r");
-!   }
-!   pipe = p;
-!   line = 1;
-    if (IOSTREAM == NULL) {
-      error_header();
-      fprintf(stderr, "Include file \"%s\" does not exist\n", INPUT);
-***************
-*** 168,179 ****
-  {
-    Iostack n;
-  
-    iostackinit();
-!   fclose(IOSTREAM);
-    n = last(stack);
-    IOSTREAM = n->stream;
-    strcpy(FILENAME, n->filename);
-  /*  free(n->filename); */
-    oldchar = n->oldchar;
-    oldcharvalid = n->oldcharvalid;
-    delete(n);
---- 184,208 ----
-  {
-    Iostack n;
-  
-+ /*  error_header();
-+   fprintf(stderr, "\nCalled pop_io_stack.  Pipe = %d\n", pipe); */
-+   fflush(IOSTREAM);
-    iostackinit();
-!   if (pipe) {
-!     if (pclose(IOSTREAM)) {
-!       /*error_header();
-!       fprintf(stderr, "\n\nPipe returned a non-zero error code.\n");
-!       exit(1); */
-!     }
-!   } else {
-!     fclose(IOSTREAM);
-!   }
-    n = last(stack);
-    IOSTREAM = n->stream;
-    strcpy(FILENAME, n->filename);
-  /*  free(n->filename); */
-+   pipe = n->pipe;
-+   line = n->line;
-    oldchar = n->oldchar;
-    oldcharvalid = n->oldcharvalid;
-    delete(n);
-***************
-*** 202,209 ****
-            fprintf(stderr, "Empty include statement\n");
-            exit(1);
-          } else {
-!           push_iostack();
-          }
-        } else {
-          getnew = 1;
-          return;
---- 231,250 ----
-            fprintf(stderr, "Empty include statement\n");
-            exit(1);
-          } else {
-!           push_iostack(0);
-          }
-+       } else if (strcmp(INPUT, "shell") == 0) {
-+         char *s, fn[30];
-+         if (gettoken(INPUT) == 0 || strcmp(INPUT, ":") != 0) {
-+           error_header();
-+           fprintf(stderr, "'shell' must be followed by ':'\n");
-+           exit(1);
-+         } 
-+         if (getsystemstring() == 0) {
-+           fprintf(stderr, "Empty shell statement\n");
-+           exit(1);
-+         }
-+         push_iostack(1);
-        } else {
-          getnew = 1;
-          return;
-***************
-*** 319,324 ****
---- 360,386 ----
-    ungettokenchar();
-    INPUT[i] = '\0';
-    return new_printable_text(INPUT);
-+ }
-+ 
-+ int getsystemstring()
-+ {
-+   char c;
-+   int i;
-+ 
-+   if (getnew == 0) return 0;
-+   
-+   c = gettokenchar();
-+   if (c == EOF) {
-+     ungettokenchar();
-+     return 0;
-+   }
-+   i = 0;
-+   for (c = gettokenchar(); c != EOF && c != '\n';  c = gettokenchar()) {
-+     INPUT[i++] = c;
-+   }
-+   ungettokenchar();
-+   INPUT[i] = '\0';
-+   return 1;
-  }
-  
-  rejecttoken()
End of patch.3

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.