axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] 20080614.01.tpd.patch (compress viewalone to a single


From: daly
Subject: [Axiom-developer] 20080614.01.tpd.patch (compress viewalone to a single C file)
Date: Sat, 14 Jun 2008 18:32:30 -0500

The viewalone function is now a single C file derived from bookvol8.
=====================================================================
diff --git a/books/bookvol8.pamphlet b/books/bookvol8.pamphlet
index 3cf1cd5..fc2404c 100644
--- a/books/bookvol8.pamphlet
+++ b/books/bookvol8.pamphlet
@@ -1845,6 +1845,14 @@ extern int viewOkay;
 extern viewManager *viewports;
 extern int viewType;
 
+int readViewport(viewManager *viewPort,void *info,int size);
+void discardGraph(graphStruct *theGraph);
+void sendGraphToView2D(int i,int there,viewManager *viewport,
+                       graphStateStruct *doGraphStateArray);
+void makeView2DFromSpadData(view2DStruct *viewdata,
+                            graphStateStruct graphState[]);
+void makeView3DFromSpadData(view3DStruct *viewdata,int typeOfViewport);
+
 
 /************* global variables **************/
 
@@ -2975,7 +2983,7 @@ int main(void) {
 }
 
 @
-\subsection{viewman Makefile}
+\section{viewman Makefile}
 <<viewman/Makefile>>=
 BOOK=${SPD}/books/bookvol8.pamphlet
 MIDINT=        ${INT}/graph/viewman
@@ -3004,185 +3012,94 @@ ${MIDOBJ}/viewman.o: ${SRC}/include/com.h ${BOOK}
 @
 \chapter{viewalone}
 \label{viewalone}
-The TESTFILE is created in the mnt directory to provide an example
-file to use for viewalone. The parabola example is detailed in the
-chapter on Graphics File Formats. The directory parabola.view will
-contain the data and graph0 files and is autogenerated from the
-documentation in that chapter.
-\section{viewalone Makefile}
-<<viewalone/Makefile>>=
-BOOK=${SPD}/books/bookvol8.pamphlet
-MIDINT=        ${INT}/graph/viewalone
-MIDOBJ=        ${OBJ}/${SYS}/graph/viewalone
-OUT=   ${MNT}/${SYS}/bin
-TESTFILE=${MNT}/${SYS}/graph/parabola.view
-
-CFLAGS = ${CCF} -I${SRC}/include
-LDFLAGS= ${LDF}
-
-OBJS=  ${MIDOBJ}/viewalone.o ${MIDOBJ}/spooncomp.o ${MIDOBJ}/spoon2d.o 
-
-all: ${OUT}/viewalone ${TESTFILE}
-       @echo 12 finished viewalone from ${BOOK}
+<<viewalone>>=
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+<<include/view3d.h>>
+<<include/view2d.h>>
+<<include/actions.h>>
+<<include/viewcommand.h>>
+#include "util.h1"
 
-${OUT}/viewalone: ${OBJS} ${OBJ}/${SYS}/lib/util.o
-       @ echo 1 linking viewalone
-       @ ${CC} $(OBJS) ${OBJ}/${SYS}/lib/util.o \
-               -o ${OUT}/viewalone ${LDFLAGS} -lX11
+      /* Viewport Commands */
+#define makeViewport -1
+#define makeGraph    -1
 
-${MIDOBJ}/viewalone.o: ${BOOK}
-       @ echo 3 making ${MIDOBJ}/viewalone.o from ${BOOK}
-       @ ( cd ${MIDINT} ; \
-          ${TANGLE} -R"viewalone/viewalone.c" ${BOOK} >viewalone.c )
-       @ ( cd ${MIDOBJ} ; ${CC} -c ${CFLAGS} ${MIDINT}/viewalone.c )
+      /* Assorted Junk */
+#define check(code) checker(code,__LINE__,"")
+#define components
+#define maxConnect 40
+#define intSize sizeof(int)
+#define floatSize sizeof(float)
+#define no 0
+#define spadActionMode
+#define yes 1
 
-${MIDOBJ}/spooncomp.o: ${BOOK}
-       @ echo 6 making ${MIDOBJ}/spooncomp.o from ${BOOK}
-       @ ( cd ${MIDINT} ; \
-          ${TANGLE} -R"viewalone/spooncomp.c" ${BOOK} >spooncomp.c )
-       @ ( cd ${MIDOBJ} ; ${CC} -c ${CFLAGS} ${MIDINT}/spooncomp.c )
+extern viewManager viewP;
+extern view3DStruct doView3D;
+extern view2DStruct doView2D;
+extern graphStruct graphArray[maxGraphs];
+extern graphStateStruct graphStateArray[maxGraphs];
+extern graphStateStruct graphStateBackupArray[maxGraphs];
+extern tubeModel doViewTube;
+extern int viewType;
+extern int filedes;
+extern int ack;
+extern char errorStr[80];
+extern int viewOkay;
+extern int viewError;
+extern FILE *viewFile;
+extern char filename[256];
+extern char pathname[256];
 
-${MIDOBJ}/spoon2d.o: ${BOOK}
-       @ echo 9 making ${MIDOBJ}/spoon2d.o from ${BOOK}
-       @ ( cd ${MIDINT} ; \
-            ${TANGLE} -R"viewalone/spoon2d.c" ${BOOK} >spoon2d.c )
-       @ ( cd ${MIDOBJ} ; ${CC} -c ${CFLAGS} ${MIDINT}/spoon2d.c )
+/************* global variables **************/
 
-${TESTFILE}: ${BOOK}
-       @ echo 10 making ${TESTFILE} from ${BOOK}
-       @ mkdir -p ${TESTFILE}
-       @ (cd ${TESTFILE} ; \
-          ${TANGLE} -R"parabola.view/data" ${BOOK} >data ; \
-          ${TANGLE} -R"parabola.view/graph0" ${BOOK} >graph0 )
+viewManager viewP;   /* note that in viewman, this is called viewports */
 
-@
-\section{spoon2d.c}
-<<viewalone/spoon2d.c>>=
-#define _SPOON2D_C
+/* 3D stuff */
+view3DStruct doView3D;
 
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
+/* 2D stuff */
+view2DStruct doView2D;
+graphStruct      graphArray[maxGraphs];
+graphStateStruct graphStateArray[maxGraphs];
 
-<<viewalone/viewalone.h>>
+/* tube stuff */
+tubeModel doViewTube;
 
+int ack;
+int filedes;
+char filename[256];
+char errorStr[80];
+char pathname[256];
+int viewError = -1;
+FILE *viewFile;
+int viewOkay  = 0;
+int viewType;
 
-#include "util.h1"
+/*
 extern void spoonView2D(void);
 extern void makeView2DFromFileData(view2DStruct * );
 extern void sendGraphToView2D(int  , int  , viewManager * );
 extern void spoonView3D(int );
 extern void makeView3DFromFileData(int );
 extern int main(int  , char * []);
+*/
 
-
-/* #define huhDEBUG */
-
-/* #define spoonDEBUG  */
-
-void 
-spoonView2D(void)
-{
-
-  int  i,code,pipe0[2],pipe1[2],there;
-  char envAXIOM[100],runView[100];
-
-  sprintf(errorStr,"%s","creating pipes");
-  check(pipe(pipe0));
-  check(pipe(pipe1));
-  switch(fork()) {
-
-  case -1:
-    fprintf(stderr,"Cannot create a new process - ");
-    fprintf(stderr,"probably have too many things running already.\n");
-    exit(-1);
-
-  case 0:
-    /************
-     *   Child  *
-     ************/
-    printf("(spoon2d child) mapping of pipes to standard I/O for view2d\n");
-    sprintf(errorStr,"%s","(viewalone) mapping of pipes to standard I/O for 
view2d");
-    check(dup2(pipe0[0],0));     
-    check(dup2(pipe1[1],1));
-    close(pipe0[0]);
-    close(pipe0[1]);
-    close(pipe1[0]);
-    close(pipe1[1]);
-    printf("(spoon2d child) start the TwoDimensionalViewport process\n");
-    sprintf(errorStr,"%s","(viewalone) execution of the TwoDimensionalViewport 
process");
-    sprintf(envAXIOM,"%s",getenv("AXIOM"));
-    sprintf(runView,"%s%s",envAXIOM,"/lib/view2d");
-    check(execl(runView,runView,NULL));
-    fprintf(stderr,"Could not execute view2d! Check that view2d is on your 
path variable.\n");
-    exit(-1);
-
-  default:
-    /*************
-     *   Parent  *
-     *************/
-
-    viewP.viewType = view2DType;
-    
-    /* set up pipes to child process */
-    close(pipe0[0]);
-    close(pipe1[1]);
-    viewP.viewIn  = pipe1[0];
-    viewP.viewOut = pipe0[1];
-    printf("(spoon2d parent) pipes created\n");
-    if (viewP.viewIn <0) {
-      fprintf(stderr,"  Could not connect from Viewport manager to viewport 
process. Try again.\n");
-      return;
-    } else {
-      code = read(viewP.viewIn,&ack,intSize);
-      if (code < 0) {
-        fprintf(stderr,"  Could not connect from Viewport manager to viewport 
process. Try again.\n");
-        return;
-      }
-    } 
-    printf("(spoon2d parent) making View2D data\n");
-    makeView2DFromFileData(&doView2D);
-
-    /* tell child it is to be a stand alone program */
-    i = yes;
-    fprintf(stderr,"  Transmitting data to viewport...\n");
-    write(viewP.viewOut,&i,intSize);
-
-    write(viewP.viewOut,&doView2D,sizeof(view2DStruct));
-    i = strlen(doView2D.title)+1;
-    write(viewP.viewOut,&i,intSize);        /* tell the length of the title to 
child */
-    write(viewP.viewOut,doView2D.title,i);  /* tell the title to the child, 
child */
-    for (i=0; i<maxGraphs; i++) {
-      there = graphArray[i].key;
-      write(viewP.viewOut,&there,intSize);
-      sendGraphToView2D(i,there,&viewP);
-    };  /* for i in graphs */
-
-    fprintf(stderr,"  Done.\n");
-    
-    /*** get acknowledge from viewport */
-
-    code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));
-    sleep(1);  /* wait a second...*/
-    exit(0); 
-
-  }   /* switch */
-
-}    /* forkView2D() */
-
-
-
-/*void sendGraphToView2D(i,there,viewP) */
-void 
-sendGraphToView2D(int i,int there,viewManager *viewP)
-{
+@
+\subsection{sendGraphToView2D}
+\index{viewalone!sendGraphToView2D}
+\index{sendGraphToView2D viewalone}
+<<viewalone>>=
+void sendGraphToView2D(int i,int there,viewManager *viewP) {
   graphStruct      *gPtr;
   pointListStruct  *llPtr;
   pointStruct      *p;
   int j,k;
   printf("(spoon2d sendGraphToView2D) i=%d there=%d\n",i,there);
   if (there) {
-
     gPtr = &(graphArray[i]);
     printf("(spoon2d sendGraphToView2D) graph %d is there\n",i);
     write(viewP->viewOut,&(gPtr->xmin),floatSize);
@@ -3198,7 +3115,6 @@ sendGraphToView2D(int i,int there,viewManager *viewP)
     write(viewP->viewOut,&(gPtr->originX),floatSize);
     write(viewP->viewOut,&(gPtr->originY),floatSize);
     write(viewP->viewOut,&(gPtr->numberOfLists),intSize);
-    
     llPtr = gPtr->listOfListsOfPoints;
     for (j=0; j<(gPtr->numberOfLists); j++) {
       write(viewP->viewOut,&(llPtr->numberOfPoints),intSize);
@@ -3215,7 +3131,6 @@ sendGraphToView2D(int i,int there,viewManager *viewP)
       write(viewP->viewOut,&(llPtr->pointSize),intSize);
       llPtr++;
     }   /* for j in list of lists of points */
-    
     /* a state is defined for a graph if it is there */
     write(viewP->viewOut,&(graphStateArray[i].scaleX),floatSize);
     write(viewP->viewOut,&(graphStateArray[i].scaleY),floatSize);
@@ -3229,16 +3144,15 @@ sendGraphToView2D(int i,int there,viewManager *viewP)
     write(viewP->viewOut,&(graphStateArray[i].unitsOn),intSize);
     write(viewP->viewOut,&(graphStateArray[i].unitsColor),intSize);
     write(viewP->viewOut,&(graphStateArray[i].showing),intSize);
-    
   }   /* if graph is there */
-
 }
 
-
-void  
-makeView2DFromFileData(view2DStruct *doView2D)
-{
-  
+@
+\subsection{makeView2DFromFileData}
+\index{viewalone!makeView2DFromFileData}
+\index{makeView2DFromFileData viewalone}
+<<viewalone>>=
+void makeView2DFromFileData(view2DStruct *doView2D) {  
   int i,j,k;
   char title[256];
   FILE *graphFile;
@@ -3292,9 +3206,11 @@ makeView2DFromFileData(view2DStruct *doView2D)
           &(graphStateArray[i].axesColor),
           &(graphStateArray[i].unitsOn),
           &(graphStateArray[i].unitsColor));
-    printf("(spoon2d) pointsOn=%d connectOn=%d splineOn=%d axesOn=%d 
axesColor=%d unitsOn=%d unitsColor=%d\n",
+    printf("(spoon2d) pointsOn=%d connectOn=%d splineOn=%d\n",
            graphStateArray[i].pointsOn,graphStateArray[i].connectOn,
-           graphStateArray[i].splineOn,graphStateArray[i].axesOn,
+           graphStateArray[i].splineOn);
+    printf("(spoon2d) axesOn=%d axesColor=%d unitsOn=%d unitsColor=%d\n",
+           graphStateArray[i].axesOn,
            graphStateArray[i].axesColor,graphStateArray[i].unitsOn,
            graphStateArray[i].unitsColor);
     fscanf(viewFile,"%d %d\n",
@@ -3349,7 +3265,8 @@ makeView2DFromFileData(view2DStruct *doView2D)
         if (!(aList =
               (pointListStruct *)malloc(graphArray[i].numberOfLists * 
                                        sizeof(pointListStruct)))) {
-          fprintf(stderr,"viewalone: Fatal Error>> Out of memory trying to 
receive a graph.\n");
+          fprintf(stderr,"viewalone: Fatal Error>> Out of memory trying\n");
+          fprintf(stderr," to receive a graph.\n");
           exit(-1);
         }
         graphArray[i].listOfListsOfPoints = aList;
@@ -3368,7 +3285,8 @@ makeView2DFromFileData(view2DStruct *doView2D)
                  aList->pointColor,aList->lineColor,aList->pointSize);
           if (!(aPoint = (pointStruct *)malloc(aList->numberOfPoints * 
                                               sizeof(pointStruct)))) {
-            fprintf(stderr,"viewalone: Fatal Error>> Out of memory trying to 
receive a graph.\n");
+            fprintf(stderr,"viewalone: Fatal Error>> Out of memory trying\n");
+            fprintf(stderr," to receive a graph.\n");
             exit(-1);
           }
           aList->listOfPoints = aPoint;   /** point to current point list **/
@@ -3389,157 +3307,19 @@ makeView2DFromFileData(view2DStruct *doView2D)
     } /* if graph.key */
   } /* for i */
 } /* makeView2DFromFileData */
-@
-\section{spooncomp.c}
-<<viewalone/spooncomp.c>>=
-#define _SPOONCOMP_C
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-<<viewalone/viewalone.h>>
-#define spadActionMode
-/* define spadEventMode */
-#define components
-
-#include "util.h1"
-extern void spoonView2D(void);
-extern void makeView2DFromFileData(view2DStruct * );
-extern void sendGraphToView2D(int  , int  , viewManager * );
-extern void spoonView3D(int );
-extern void makeView3DFromFileData(int );
-extern int main(int  , char * []);
-
-
-
-
-/* This file forks a child process and exits the parent. It 
-   has the same general form as ../viewman/funView3D() and so 
-   changes there may require similar changes here. */
-
-void 
-spoonView3D(int type)
-{
-  
-  int  i,j,k,code,pipe0[2],pipe1[2];
-  char envAXIOM[100],runView[100];
-  LLPoint *anLLPoint;
-  LPoint *anLPoint;
-  int *anIndex;
-  
-  sprintf(errorStr,"%s","creating pipes");
-  check(pipe(pipe0));
-  check(pipe(pipe1));
-  switch(fork()) {
-  case -1:
-    fprintf(stderr,"can't create a child process\n");
-    fprintf(stderr,"you may have too many processes running\n");
-    exit(-1);
-  case 0:
-    /*  Child  */
-    sprintf(errorStr,"%s",
-           "(viewalone) mapping of pipes to standard I/O for view3d");
-    check(dup2(pipe0[0],0));     
-    check(dup2(pipe1[1],1));
-    close(pipe0[0]);
-    close(pipe0[1]);
-    close(pipe1[0]);
-    close(pipe1[1]);
-    
-    sprintf(errorStr,"%s",
-           "(viewalone) execution of the ThreeDimensionalViewport process");
-    sprintf(envAXIOM,"%s",getenv("AXIOM"));
-    sprintf(runView,"%s%s",envAXIOM,"/lib/view3d");
-    check(execl(runView,runView,NULL));
-    fprintf(stderr,"Could not execute view3d!\n");
-    exit(-1);
-  default:
-    /*  Parent  */
-    
-    viewP.viewType = type;
-    
-    /* set up pipes to child process */
-    close(pipe0[0]);
-    close(pipe1[1]);
-    viewP.viewIn  = pipe1[0];
-    viewP.viewOut = pipe0[1];
-    
-    if (viewP.viewIn <0) {
-      fprintf(stderr,
-             "can't set up pipes to viewport process. Try again.\n");
-      return;
-    } else {
-      code = read(viewP.viewIn,&ack,intSize);
-      if (code < 0) {
-        fprintf(stderr,"can't read from viewport process pipe. Try again.\n");
-        return;
-      }
-    } 
-    
-    makeView3DFromFileData(type);
-    /* tell child it is to be a stand alone program */
-    i = yes;
-    fprintf(stderr,"  Transmitting data to viewport...\n");
-    write(viewP.viewOut,&i,intSize);
-    write(viewP.viewOut,&doView3D,sizeof(view3DStruct));
-    i = strlen(doView3D.title)+1;
-    write(viewP.viewOut,&i,intSize);  /* tell the length of 
-                                        the title to child */
-    write(viewP.viewOut,doView3D.title,i);  /* tell the title 
-                                              to the child, child */
-    write(viewP.viewOut,&(doView3D.lightVec[0]),floatSize);
-    write(viewP.viewOut,&(doView3D.lightVec[1]),floatSize);
-    write(viewP.viewOut,&(doView3D.lightVec[2]),floatSize);
-    
-    write(viewP.viewOut,&(doView3D.numOfPoints),intSize);
-    for (i=0; i<doView3D.numOfPoints; i++) {
-      write(viewP.viewOut,&(refPt(doView3D,i)->x),floatSize);
-      write(viewP.viewOut,&(refPt(doView3D,i)->y),floatSize);
-      write(viewP.viewOut,&(refPt(doView3D,i)->z),floatSize);
-      write(viewP.viewOut,&(refPt(doView3D,i)->c),floatSize);
-    }
-    
-    /* send generalized 3D components */
-    write(viewP.viewOut,&(doView3D.lllp.numOfComponents),intSize);
-    anLLPoint = doView3D.lllp.llp;
-    for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {
-      write(viewP.viewOut,&(anLLPoint->prop.closed),intSize);
-      write(viewP.viewOut,&(anLLPoint->prop.solid),intSize);
-      write(viewP.viewOut,&(anLLPoint->numOfLists),intSize);
-      anLPoint = anLLPoint->lp;
-      for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
-        write(viewP.viewOut,&(anLPoint->prop.closed),intSize);
-        write(viewP.viewOut,&(anLPoint->prop.solid),intSize);
-        write(viewP.viewOut,&(anLPoint->numOfPoints),intSize);
-        anIndex = anLPoint->indices;
-        for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)
-          write(viewP.viewOut,anIndex,intSize);
-      } /* for LPoints in LLPoints (j) */
-    } /* for LLPoints in LLLPoints (i) */
-    fprintf(stderr,"    Done.\n");
-    
-    /*** get acknowledge from viewport */
-    code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));
-    sleep(1);  /* wait a second...*/
-    exit(0); 
-    
-  }   /* switch */
-  
-}    /* spoonView3D() */
-
 
-void
-makeView3DFromFileData(int type)
-{
-  
+@
+\subsection{makeView3DFromFileData}
+\index{viewalone!makeView3DFromFileData}
+\index{makeView3DFromFileData viewalone}
+<<viewalone>>=
+void makeView3DFromFileData(int type) {
   int i,j,k;
   char title[256];
   LLPoint *anLLPoint;
   LPoint *anLPoint;
   viewTriple *aPoint;
   int *anIndex;
-
   /* fscanf(doView3D,""); */
   /* read in the view3DStruct stuff */
   /* &view3DType already read */
@@ -3551,7 +3331,6 @@ makeView3DFromFileData(int type)
         &(doView3D.ymax),
         &(doView3D.zmin),
         &(doView3D.zmax));
-
   fgets(title,256,viewFile);
   if (!(doView3D.title = (char *)malloc((strlen(title)+1) * 
                                        sizeof(char)))) {
@@ -3561,7 +3340,6 @@ makeView3DFromFileData(int type)
   sprintf(doView3D.title,"%s",title);
   /* put in a null terminator over the newline that the fgets reads */
   doView3D.title[strlen(doView3D.title)-1] = '\0'; 
-  
   fscanf(viewFile,"%f %f %f %f %f %f %f %f\n",
         &(doView3D.deltaX),
         &(doView3D.deltaY),
@@ -3571,7 +3349,6 @@ makeView3DFromFileData(int type)
         &(doView3D.scaleZ),
         &(doView3D.theta),
         &(doView3D.phi));
-  
   fscanf(viewFile,"%d %d %d %d\n",
         &(doView3D.vX),
         &(doView3D.vY),
@@ -3593,9 +3370,7 @@ makeView3DFromFileData(int type)
   fscanf(viewFile,"%d %f\n",
         &(doView3D.perspective),
         &(doView3D.eyeDistance));
-  
   /* get generalized 3D components */
-  
   fscanf(viewFile,"%d\n",
         &(doView3D.numOfPoints));
   aPoint = doView3D.points = (viewTriple *)malloc(doView3D.numOfPoints*
@@ -3631,67 +3406,208 @@ makeView3DFromFileData(int type)
       } /* for points in LPoints (k) */
     } /* for LPoints in LLPoints (j) */
   } /* for LLPoints in LLLPoints (i) */
-  
   fclose(viewFile);
   doView3D.scaleDown = no ;
 }
 
 @
-\section{viewalone.c}
-<<viewalone/viewalone.c>>=
-#define _VIEWALONE_C
-
-#include <stdlib.h>
-<<viewalone/viewalone.h>>
-
-extern void spoonView2D(void);
-extern void makeView2DFromFileData(view2DStruct * );
-extern void sendGraphToView2D(int  , int  , viewManager * );
-extern void spoonView3D(int );
-extern void makeView3DFromFileData(int );
-extern int main(int  , char * []);
-
-
-/************* global variables **************/
-
-viewManager viewP;   /* note that in viewman, this is called viewports */
-
-/* 3D stuff */
-view3DStruct doView3D;
-
-/* 2D stuff */
-view2DStruct doView2D;
-graphStruct      graphArray[maxGraphs];
-graphStateStruct graphStateArray[maxGraphs];
-
-/* tube stuff */
-tubeModel doViewTube;
-
-int         viewType;
-int         filedes,ack;
-
-char        errorStr[80];
-
-
-int viewOkay  = 0;
-int viewError = -1;
-
-FILE *viewFile;
-char filename[256];
-char pathname[256];
+\subsection{spoonView2D}
+\index{viewalone!spoonView2D}
+\index{spoonView2D viewalone}
+<<viewalone>>=
+void spoonView2D(void) {
+  int  i,code,pipe0[2],pipe1[2],there;
+  char envAXIOM[100],runView[100];
+  sprintf(errorStr,"%s","creating pipes");
+  check(pipe(pipe0));
+  check(pipe(pipe1));
+  switch(fork()) {
+  case -1:
+    fprintf(stderr,"Cannot create a new process - ");
+    fprintf(stderr,"probably have too many things running already.\n");
+    exit(-1);
+  case 0:
+    /************
+     *   Child  *
+     ************/
+    printf("(spoon2d child) mapping of pipes to standard I/O for view2d\n");
+    sprintf(errorStr,"%s",
+             "(viewalone) mapping of pipes to standard I/O for view2d");
+    check(dup2(pipe0[0],0));     
+    check(dup2(pipe1[1],1));
+    close(pipe0[0]);
+    close(pipe0[1]);
+    close(pipe1[0]);
+    close(pipe1[1]);
+    printf("(spoon2d child) start the TwoDimensionalViewport process\n");
+    sprintf(errorStr,"%s",
+            "(viewalone) execution of the TwoDimensionalViewport process");
+    sprintf(envAXIOM,"%s",getenv("AXIOM"));
+    sprintf(runView,"%s%s",envAXIOM,"/lib/view2d");
+    check(execl(runView,runView,NULL));
+    fprintf(stderr,
+     "Could not execute view2d! Check that view2d is on your path.\n");
+    exit(-1);
+  default:
+    /*************
+     *   Parent  *
+     *************/
+    viewP.viewType = view2DType;
+    /* set up pipes to child process */
+    close(pipe0[0]);
+    close(pipe1[1]);
+    viewP.viewIn  = pipe1[0];
+    viewP.viewOut = pipe0[1];
+    printf("(spoon2d parent) pipes created\n");
+    if (viewP.viewIn <0) {
+      fprintf(stderr,"Could not connect from Viewport manager to viewport\n");
+      fprintf(stderr," process. Try again.\n");
+      return;
+    } else {
+      code = read(viewP.viewIn,&ack,intSize);
+      if (code < 0) {
+       fprintf(stderr,"Could not connect from Viewport manager to viewport\n");
+       fprintf(stderr," process. Try again.\n");
+        return;
+      }
+    } 
+    printf("(spoon2d parent) making View2D data\n");
+    makeView2DFromFileData(&doView2D);
+    /* tell child it is to be a stand alone program */
+    i = yes;
+    fprintf(stderr,"  Transmitting data to viewport...\n");
+    write(viewP.viewOut,&i,intSize);
+    write(viewP.viewOut,&doView2D,sizeof(view2DStruct));
+    i = strlen(doView2D.title)+1;
+    write(viewP.viewOut,&i,intSize); /* tell the length of title to child */
+    write(viewP.viewOut,doView2D.title,i);  /* tell the title to child */
+    for (i=0; i<maxGraphs; i++) {
+      there = graphArray[i].key;
+      write(viewP.viewOut,&there,intSize);
+      sendGraphToView2D(i,there,&viewP);
+    };  /* for i in graphs */
+    fprintf(stderr,"  Done.\n");
+    /*** get acknowledge from viewport */
+    code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));
+    sleep(1);  /* wait a second...*/
+    exit(0); 
+  }   /* switch */
+}    /* forkView2D() */
 
-/************* main program **************/
+@
+\subsection{spoonView3D}
+This file forks a child process and exits the parent. It 
+has the same general form as ../viewman/funView3D() and so 
+changes there may require similar changes here. 
+\index{viewalone!spoonView2D}
+\index{spoonView2D viewalone}
+<<viewalone>>=
+void spoonView3D(int type) {
+  int  i,j,k,code,pipe0[2],pipe1[2];
+  char envAXIOM[100],runView[100];
+  LLPoint *anLLPoint;
+  LPoint *anLPoint;
+  int *anIndex;
+  sprintf(errorStr,"%s","creating pipes");
+  check(pipe(pipe0));
+  check(pipe(pipe1));
+  switch(fork()) {
+  case -1:
+    fprintf(stderr,"can't create a child process\n");
+    fprintf(stderr,"you may have too many processes running\n");
+    exit(-1);
+  case 0:
+    /*  Child  */
+    sprintf(errorStr,"%s",
+           "(viewalone) mapping of pipes to standard I/O for view3d");
+    check(dup2(pipe0[0],0));     
+    check(dup2(pipe1[1],1));
+    close(pipe0[0]);
+    close(pipe0[1]);
+    close(pipe1[0]);
+    close(pipe1[1]);
+    sprintf(errorStr,"%s",
+           "(viewalone) execution of the ThreeDimensionalViewport process");
+    sprintf(envAXIOM,"%s",getenv("AXIOM"));
+    sprintf(runView,"%s%s",envAXIOM,"/lib/view3d");
+    check(execl(runView,runView,NULL));
+    fprintf(stderr,"Could not execute view3d!\n");
+    exit(-1);
+  default:
+    /*  Parent  */
+    viewP.viewType = type;
+    /* set up pipes to child process */
+    close(pipe0[0]);
+    close(pipe1[1]);
+    viewP.viewIn  = pipe1[0];
+    viewP.viewOut = pipe0[1];
+    if (viewP.viewIn <0) {
+      fprintf(stderr,
+             "can't set up pipes to viewport process. Try again.\n");
+      return;
+    } else {
+      code = read(viewP.viewIn,&ack,intSize);
+      if (code < 0) {
+        fprintf(stderr,"can't read from viewport process pipe. Try again.\n");
+        return;
+      }
+    } 
+    makeView3DFromFileData(type);
+    /* tell child it is to be a stand alone program */
+    i = yes;
+    fprintf(stderr,"  Transmitting data to viewport...\n");
+    write(viewP.viewOut,&i,intSize);
+    write(viewP.viewOut,&doView3D,sizeof(view3DStruct));
+    i = strlen(doView3D.title)+1;
+    write(viewP.viewOut,&i,intSize);  /* tell the length of title to child */
+    write(viewP.viewOut,doView3D.title,i);  /* tell the title to */
+    write(viewP.viewOut,&(doView3D.lightVec[0]),floatSize);
+    write(viewP.viewOut,&(doView3D.lightVec[1]),floatSize);
+    write(viewP.viewOut,&(doView3D.lightVec[2]),floatSize);
+    write(viewP.viewOut,&(doView3D.numOfPoints),intSize);
+    for (i=0; i<doView3D.numOfPoints; i++) {
+      write(viewP.viewOut,&(refPt(doView3D,i)->x),floatSize);
+      write(viewP.viewOut,&(refPt(doView3D,i)->y),floatSize);
+      write(viewP.viewOut,&(refPt(doView3D,i)->z),floatSize);
+      write(viewP.viewOut,&(refPt(doView3D,i)->c),floatSize);
+    }
+    /* send generalized 3D components */
+    write(viewP.viewOut,&(doView3D.lllp.numOfComponents),intSize);
+    anLLPoint = doView3D.lllp.llp;
+    for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {
+      write(viewP.viewOut,&(anLLPoint->prop.closed),intSize);
+      write(viewP.viewOut,&(anLLPoint->prop.solid),intSize);
+      write(viewP.viewOut,&(anLLPoint->numOfLists),intSize);
+      anLPoint = anLLPoint->lp;
+      for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
+        write(viewP.viewOut,&(anLPoint->prop.closed),intSize);
+        write(viewP.viewOut,&(anLPoint->prop.solid),intSize);
+        write(viewP.viewOut,&(anLPoint->numOfPoints),intSize);
+        anIndex = anLPoint->indices;
+        for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)
+          write(viewP.viewOut,anIndex,intSize);
+      } /* for LPoints in LLPoints (j) */
+    } /* for LLPoints in LLLPoints (i) */
+    fprintf(stderr,"    Done.\n");
+    /*** get acknowledge from viewport */
+    code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));
+    sleep(1);  /* wait a second...*/
+    exit(0); 
+  }   /* switch */
+}    /* spoonView3D() */
 
-int main (int argc,char *argv[])
-{
-        printf("viewalone called with argc=%d\n",argc);
+@
+\subsection{main}
+\index{viewalone!main}
+\index{main viewalone}
+<<viewalone>>=
+int main(int argc,char *argv[])
+{       printf("viewalone called with argc=%d\n",argc);
         printf("viewalone called with argv[1]=%s\n",argv[0]);
         printf("viewalone called with argv[2]=%s\n",argv[1]);
 /******** Open files and Figure out the viewport type ********/
-
        sprintf(filename,"%s%s",argv[1],".view/data");
         if((viewFile = fopen(filename,"r")) == NULL ) {
-         
            sprintf(filename,"%s%s",argv[1],"/data");
            if((viewFile = fopen(filename,"r")) == NULL ){
              fprintf(stderr,"Error: Cannot find the file %s%s or %s%s\n",
@@ -3707,57 +3623,59 @@ int main (int argc,char *argv[])
         printf("filename = %s\n",filename);
         printf("viewType = %d\n",viewType);
        switch (viewType) {
-
        case view3DType:
        case viewTubeType:
                 printf("calling spoonView3D\n");
                spoonView3D(viewType);
                break;
-
        case view2DType:
                 printf("calling spoonView2D\n");
                spoonView2D();
                break;
-
        }  /* switch */
-      printf("The first number in the file, %d, called the viewType, not a 
valid value. It must be a number in the range of [1..4]\n",viewType);
+      printf("The first number in the file, %d, called the ",viewType);
+      printf("viewType, not a valid value. It must be a number in the ");
+      printf("range of [1..4]\n");
       return(0);
       }
 @
-\section{viewalone.h}
-<<viewalone/viewalone.h>>=
-#include <stdio.h>
-<<include/view3d.h>>
-<<include/view2d.h>>
-<<include/actions.h>>
-<<include/viewcommand.h>>
+The TESTFILE is created in the mnt directory to provide an example
+file to use for viewalone. The parabola example is detailed in the
+chapter on Graphics File Formats. The directory parabola.view will
+contain the data and graph0 files and is autogenerated from the
+documentation in that chapter.
+\section{viewalone Makefile}
+<<viewalone/Makefile>>=
+BOOK=${SPD}/books/bookvol8.pamphlet
+MIDINT=        ${INT}/graph/viewalone
+MIDOBJ=        ${OBJ}/${SYS}/graph/viewalone
+OUT=   ${MNT}/${SYS}/bin
+TESTFILE=${MNT}/${SYS}/graph/parabola.view
 
-      /* Viewport Commands */
-#define makeViewport -1
-#define makeGraph    -1
+CFLAGS = ${CCF} -I${SRC}/include
+LDFLAGS= ${LDF}
 
-      /* Assorted Junk */
-#define check(code) checker(code,__LINE__,"")
-#define maxConnect 40
-#define intSize sizeof(int)
-#define floatSize sizeof(float)
-#define yes 1
-#define no 0
+OBJS=  
 
-extern viewManager viewP;
-extern view3DStruct doView3D;
-extern view2DStruct doView2D;
-extern graphStruct      graphArray[maxGraphs];
-extern graphStateStruct 
graphStateArray[maxGraphs],graphStateBackupArray[maxGraphs];
-extern tubeModel doViewTube;
-extern int         viewType;
-extern int         filedes,ack;
-extern char        errorStr[80];
-extern int viewOkay;
-extern int viewError;
-extern FILE *viewFile;
-extern char filename[256];
-extern char pathname[256];
+all: ${OUT}/viewalone ${TESTFILE}
+       @echo 12 finished viewalone from ${BOOK}
+
+${OUT}/viewalone: ${MIDOBJ}/viewalone.o ${OBJ}/${SYS}/lib/util.o
+       @ echo 1 linking viewalone
+       @ ${CC} ${MIDOBJ}/viewalone.o ${OBJ}/${SYS}/lib/util.o \
+               -o ${OUT}/viewalone ${LDFLAGS} -lX11
+
+${MIDOBJ}/viewalone.o: ${BOOK}
+       @ echo 3 making ${MIDOBJ}/viewalone.o from ${BOOK}
+       @ ( cd ${MIDINT} ; ${TANGLE} -R"viewalone" ${BOOK} >viewalone.c )
+       @ ( cd ${MIDOBJ} ; ${CC} -c ${CFLAGS} ${MIDINT}/viewalone.c )
+
+${TESTFILE}: ${BOOK}
+       @ echo 10 making ${TESTFILE} from ${BOOK}
+       @ mkdir -p ${TESTFILE}
+       @ (cd ${TESTFILE} ; \
+          ${TANGLE} -R"parabola.view/data" ${BOOK} >data ; \
+          ${TANGLE} -R"parabola.view/graph0" ${BOOK} >graph0 )
 
 @
 \chapter{view2d}
diff --git a/changelog b/changelog
index b783c96..5abd176 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,4 @@
+20080614 tpd books/bookvol8 compress viewalone to a single C file
 20080613 tpd books/bookvol8 compress viewman.c to a single file
 20080612 tpd books/bookvol12 point to The Axiom Literate Documentation
 20080612 tpd books/bookvol11 point to The Axiom Literate Documentation




reply via email to

[Prev in Thread] Current Thread [Next in Thread]