home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / misc / cp-4.3.lha / cP / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-03  |  12.1 KB  |  452 lines

  1. #include "cp.h"
  2. #include "spr.h"
  3.  
  4. UBYTE     *version_string     = "$VER: cP 4.3 (31.7.94)";
  5.  
  6. long      __oslibversion      = 37;     /* requires KickStart 37 */
  7. long      __BackGroundIO      = 1;
  8. long      __stack             = 6000L;   /* stack size doesn't seem to work for cli proc??? */
  9. char     *__procname          = "cPlot"; /* process name */
  10.  
  11. extern BPTR _Backstdout;      /* keep stdout till we get past startup */
  12.  
  13. struct List         *SetList       = NULL;
  14. struct RDArgs       *cli_args      = NULL;
  15. struct RDArgs       *env_args      = NULL;
  16. struct TextFont     *fontPtr       = NULL;
  17. struct TextAttr     CPFont         = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  18. struct TextAttr     *cPFont        = NULL;
  19. struct AnchorPath   *anchorpath;
  20.  
  21. AREXXCONTEXT    RexxStuff;
  22.  
  23. /* Set Defaults */
  24.  
  25. BOOL grid    = FALSE;     /* No Grid */
  26. BOOL LOGX    = FALSE;     /* Lin X */
  27. BOOL LOGY    = FALSE;     /* Lin Y */
  28. BOOL sym     = FALSE;     /* No Symbols */
  29. BOOL DEFS    = FALSE;     /* Don't make cP */
  30. BOOL MONO    = FALSE;     /* color default */
  31. BOOL CPANEL  = TRUE;      /* control panel on */
  32. BOOL NOFNAME = FALSE;     /* usually put filename boxes on screen */
  33. BOOL BEHIND  = FALSE;     /* usually open screen to front */
  34. BOOL RealTime = FALSE;    /* May not be time sampled data */
  35.  
  36. LONG Disp;
  37.  
  38. UBYTE *path;        /* extern pointer to Path */
  39. UBYTE Path[255];    /* Path String same as path but not external */
  40.  
  41. UBYTE *fName;        /* extern pointer to fontname */
  42. UBYTE fontName[64]; /* im too lazy to allocate dynamically */
  43.  
  44. UBYTE *MyName;        /* extern pointer to name of process screen and rexxport */
  45. UBYTE Name[64];
  46.  
  47. UBYTE *XLAB=NULL;
  48. UBYTE xlabel[64];
  49. UBYTE *YLAB=NULL;
  50. UBYTE ylabel[64];
  51. UBYTE *TITLE=NULL;
  52. UBYTE title[128];
  53.  
  54.  
  55. LONG points    = 1000000; /* should be enough max per set */
  56. LONG thin      = 1;    /* dont depopulate */
  57.  
  58. WORD lastcolor = 15;     /* 16 colors default palette */
  59. WORD depth     = 4;
  60.  
  61.  
  62. UBYTE **files=NULL;           /* pointer to pointer to FILES/M */
  63.  
  64. UBYTE RexxName[64];
  65.  
  66. #define ENVSIZE 1024     /* max char length for envvar */
  67.  
  68. UBYTE *template = "FILES=WILD/M,LX=LOGX/S,LY=LOGY/S,GRID/S,SYM/S,ID=DISPLAYID/N/K,FONT/K,FS=SIZE/N/K,LORES/S,HIRES/S,LACE/S,SETDEF/S,W=WIDTH/N/K,H=HEIGHT/N/K,P=POINTS/N/K,T=THIN/N/K,D=DEPTH/N/K,MONO/S,CPANEL/S,NOFN=NOFNBOXES/S,OB=OPENBEHIND/S,MYNAME/K,XLAB/K,YLAB/K,TITLE/K,REALTIME/S,SD=DIGITS/N/K";
  69.  
  70. LONG cli_array[ 27 ] = { 0L, 0L, 0L, 0L, 0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
  71. LONG env_array[ 27 ] = { 0L, 0L, 0L, 0L, 0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
  72.  
  73. extern void exit(int);   /* from stdlib.h */
  74.  
  75. /* Use the same function to process command line and envvar */
  76.  
  77. void arg_array_Parse( LONG *arg_array )
  78. {
  79. LONG *ptr;
  80.  
  81.      if ( arg_array[ 0 ] ) files = ( UBYTE ** ) arg_array[ 0 ];
  82.  
  83.      if ( arg_array[ 1 ] ) LOGX = TRUE;
  84.      if ( arg_array[ 2 ] ) LOGY = TRUE;
  85.  
  86.      if ( arg_array[ 3 ] )
  87.        {
  88.           if ( grid ) grid = FALSE;
  89.           else        grid = TRUE;
  90.        }
  91.      if ( arg_array[ 4 ] )
  92.        {
  93.           if ( sym ) sym = FALSE;
  94.           else       sym = TRUE;
  95.        }
  96.  
  97.      if ( arg_array[ 5 ] )
  98.        {
  99.           ptr = (LONG *)arg_array[ 5 ];
  100.           Disp = *ptr;
  101.        }
  102.  
  103.      if ( arg_array[ 6 ] )
  104.        {
  105.           strcpy( fName, (UBYTE *)arg_array[ 6 ]);
  106.           strcat( fName, ".font");
  107.           cPFont->ta_Name = (STRPTR)fName;
  108.        }
  109.  
  110.      if ( arg_array[ 7 ] )
  111.        {
  112.           ptr = (LONG *)arg_array[ 7 ];
  113.           cPFont->ta_YSize = (UWORD) *ptr;
  114.        }
  115.  
  116.      if ( arg_array[ 8 ] )  Disp  = LORES_KEY;
  117.      if ( arg_array[ 9 ] )  Disp  = HIRES_KEY;
  118.      if ( arg_array[ 10 ] ) Disp |= LORESLACE_KEY;
  119.      if ( arg_array[ 11 ] ) DEFS  = TRUE;
  120.  
  121.      if ( arg_array[ 12 ] )
  122.        {
  123.           ptr = (LONG *)arg_array[ 12 ];
  124.           SWIDTH = *ptr;
  125.        }
  126.  
  127.      if ( arg_array[ 13 ] )
  128.        {
  129.           ptr = (LONG *)arg_array[ 13 ];
  130.           SHEIGHT = *ptr;
  131.        }
  132.      if ( arg_array[ 14 ] )
  133.        {
  134.           ptr = (LONG *)arg_array[ 14 ];
  135.           points = *ptr;
  136.        }
  137.      if ( arg_array[ 15 ] )
  138.        {
  139.           ptr = (LONG *)arg_array[ 15 ];
  140.           thin = *ptr;
  141.           if (thin <= 0) thin = 1;
  142.        }
  143.      if ( arg_array[ 16 ] )
  144.        {
  145.           ptr = (LONG *)arg_array[ 16 ];
  146.           depth = (WORD)*ptr;
  147.  
  148.           if (depth <= 1 )
  149.             {
  150.                depth = 1;
  151.                lastcolor = 1;
  152.                MONO = TRUE;
  153.             }
  154.           if (depth == 2) lastcolor = 3;
  155.           if (depth == 3) lastcolor = 7;
  156.           if (depth >= 4)
  157.             {
  158.                depth = 4;
  159.                lastcolor = 15;
  160.             }
  161.        }
  162.      if ( arg_array[ 17 ] )
  163.        {
  164.           MONO  = TRUE;
  165.           depth = 1;
  166.           lastcolor = 1;
  167.        }
  168.      if ( arg_array[ 18 ] )
  169.        {
  170.           if ( CPANEL ) CPANEL = FALSE;
  171.           else          CPANEL = TRUE;
  172.        }
  173.      if ( arg_array[ 19 ] )
  174.        {
  175.           if ( NOFNAME ) NOFNAME = FALSE;
  176.           else           NOFNAME = TRUE;
  177.        }
  178.      if ( arg_array[ 20 ] )
  179.        {
  180.           if ( BEHIND ) BEHIND = FALSE;
  181.           else          BEHIND = TRUE;
  182.        }
  183.      if ( arg_array[ 21 ] )
  184.        {
  185.           strcpy( Name, (UBYTE *)arg_array[ 21 ]);
  186.        }
  187.      if ( arg_array[ 22 ] )
  188.        {
  189.           strcpy( xlabel, (UBYTE *)arg_array[ 22 ]);
  190.        }
  191.      if ( arg_array[ 23 ] )
  192.        {
  193.           strcpy( ylabel, (UBYTE *)arg_array[ 23 ]);
  194.        }
  195.      if ( arg_array[ 24 ] )
  196.        {
  197.           strcpy( title, (UBYTE *)arg_array[ 24 ]);
  198.        }
  199.      if ( arg_array[ 25 ] )
  200.        {
  201.           if ( RealTime ) RealTime = FALSE;
  202.           else            RealTime = TRUE;
  203.        }
  204.      if ( arg_array[ 26 ] )
  205.        {
  206.           ptr = (LONG *)arg_array[ 26 ];
  207.           precision = *ptr - 1;
  208.        }
  209.  
  210. }
  211.  
  212.  
  213. /* Clean up and die duh */
  214.  
  215. void Death( int v )
  216. {
  217.     if ( delwinWnd )     ClosedelwinWindow();
  218.  
  219.     if ( PlotWindowWnd ) ClosePlotWindowWindow();
  220.  
  221.     if ( Scr )           CloseDownScreen();
  222.  
  223.     if ( fontPtr )       CloseFont( fontPtr );
  224.  
  225.     FreeARexx(RexxStuff);
  226.  
  227.     FreeAllSets();
  228.  
  229.     if ( cli_args )      FreeArgs( cli_args );
  230.     if ( anchorpath )    FreeVec( anchorpath );
  231.  
  232.  
  233.     exit( v );
  234. }
  235.  
  236.  
  237. void main(int argc, char **argv)
  238. {
  239. ULONG sigs;
  240. ULONG rexxsigs;
  241. LONG  mres;
  242. struct List slist;
  243. LONG j = 0;
  244. BPTR lock;
  245. LONG len;
  246. UBYTE fault[300];
  247. UBYTE *environ;
  248. LONG alive;
  249. struct Screen *WB_Screen;
  250.  
  251.  
  252.      slist.lh_Head = (struct Node *) &slist.lh_Tail;
  253.      slist.lh_Tail = 0;
  254.      slist.lh_TailPred = (struct Node *) &slist.lh_Head;
  255.      slist.lh_Type = NT_DATA;
  256.  
  257.      SetList   = &slist;
  258.  
  259.      cPFont    = &CPFont;
  260.      fName     = &fontName[0];
  261.      path      = (STRPTR)Path;
  262.      MyName    = (STRPTR)Name;
  263.     XLAB      = (STRPTR)xlabel;
  264.     YLAB      = (STRPTR)ylabel;
  265.     TITLE     = (STRPTR)title;
  266.  
  267.     strcpy(MyName,&version_string[5]);
  268.  
  269.      if ( argc == 2 && Stricmp(argv[1],"?")==0)  /* give help and exit */
  270.        {
  271.           if ( _Backstdout )
  272.             {
  273.                 FPuts(_Backstdout, template);
  274.                FPutC ( _Backstdout, '\n');
  275.                Close( _Backstdout);
  276.             }
  277.           Death ( 1 );
  278.       }       
  279.  
  280.  
  281.     /* Clone Workbench DisplayID default to hires lace if we fail */
  282.     
  283.     WB_Screen = LockPubScreen("Workbench");
  284.     if (WB_Screen!=NULL)
  285.       {
  286.           Disp = GetVPModeID(&WB_Screen->ViewPort);
  287.           if (Disp==INVALID_ID) Disp = HIRESLACE_KEY;    /* Hires Lace Default */
  288.       }
  289.     
  290.  
  291.      /* Parse envvar CPCONFIG */
  292.  
  293.      if (( environ = AllocVec( ENVSIZE, MEMF_CLEAR )))
  294.        {
  295.           len = GetVar( "CPCONFIG", environ, ENVSIZE, NULL );
  296.           if ( len > 0 )
  297.             {
  298.                environ[len]   = '\n';
  299.                environ[++len] = '\0';
  300.  
  301.                if ((env_args = (struct RDArgs *)AllocDosObject(DOS_RDARGS, TAG_DONE)))
  302.                  {
  303.                     env_args->RDA_Source.CS_Buffer = environ;
  304.                     env_args->RDA_Source.CS_Length = len;
  305.                     env_args->RDA_Source.CS_CurChr = 0L;
  306.  
  307.                    memset(env_array,0,sizeof(env_array));
  308.  
  309.                     if( ReadArgs( template, (LONG *)&env_array[ 0 ], env_args ))
  310.                          arg_array_Parse( &env_array[ 0 ] );
  311.  
  312.                     FreeArgs( env_args );
  313.                     FreeDosObject(DOS_RDARGS, env_args);
  314.                  }
  315.             }
  316.           FreeVec( environ );
  317.        }
  318.  
  319.      /* Read command line with ReadArgs */
  320.  
  321.      memset(cli_array,0,sizeof(cli_array));
  322.  
  323.      if ( ! ( cli_args = ReadArgs( template, &cli_array[ 0 ], 0L )))
  324.        {
  325.           if ( _Backstdout )
  326.             {
  327.                 if ( Fault(IoErr(), "ERROR", fault, 300)) FPuts(_Backstdout, fault);
  328.                FPutC ( _Backstdout, '\n');
  329.                Close( _Backstdout);
  330.             }
  331.           Death ( 1 );
  332.        }
  333.  
  334.      arg_array_Parse( &cli_array[ 0 ] );
  335.  
  336.  
  337.     if (argc==0) AddNewSet(); /* program was run from workbench */
  338.  
  339.  
  340.  
  341.      if ( ! (fontPtr = OpencPFont()))
  342.        {
  343.             if ( _Backstdout) Close( _Backstdout);
  344.             Death(10);
  345.        }
  346.  
  347.      if ( OpenGTXScreen())
  348.        {
  349.             if ( _Backstdout) Close( _Backstdout);
  350.             Death(10);
  351.        }
  352.  
  353.      if ( OpenGTXWindow( OpenPlotWindowWindow ))
  354.        {
  355.             if ( _Backstdout) Close( _Backstdout);
  356.             Death(10);
  357.        }
  358.  
  359.  
  360. /* load files from Wild pattern */
  361.  
  362.      SetPointer( PlotWindowWnd, WAITPointer, WAITHEIGHT, WAITWIDTH, WAITXOFF , WAITYOFF);  /* set wait pointer image */
  363.  
  364.     anchorpath = (struct AnchorPath *) AllocVec(sizeof(struct AnchorPath)+255,MEMF_CLEAR);
  365.      anchorpath->ap_Strlen = 255;
  366.  
  367.      while ( files && files[ j ]  && anchorpath )
  368.        {
  369.           if ( ! Stricmp(files[ j ], "*")) files[ j ] = "#?";
  370.           
  371.           mres = MatchFirst( files[ j ], anchorpath );
  372.  
  373.           if ( mres == NULL )
  374.             {
  375.                 if (anchorpath->ap_Info.fib_DirEntryType < 0)
  376.                   {
  377.                    lock = CurrentDir( anchorpath->ap_Current-> an_Lock );
  378.                    AddSet( anchorpath->ap_Info.fib_FileName );
  379.                    CurrentDir( lock );
  380.               }
  381.                while ( MatchNext( anchorpath ) == NULL )
  382.                  {
  383.                     if (anchorpath->ap_Info.fib_DirEntryType < 0)
  384.                       {
  385.                         lock = CurrentDir( anchorpath->ap_Current-> an_Lock );
  386.                         AddSet( anchorpath->ap_Info.fib_FileName );
  387.                         CurrentDir( lock );
  388.                      }
  389.               }
  390.             }
  391.           else
  392.             {
  393.                if ( _Backstdout)
  394.                  {
  395.                 if ( Fault(IoErr(), files[ j ], fault, 300)) FPuts(_Backstdout, fault);
  396.                     FPutC ( _Backstdout, '\n');
  397.                     Close( _Backstdout);
  398.                  }
  399.                MatchEnd( anchorpath );
  400.                Death ( 5 );
  401.             }
  402.  
  403.           MatchEnd( anchorpath );
  404.           j++;
  405.        }
  406.  
  407.  
  408.      if ( _Backstdout) Close( _Backstdout);  /* close output so we detache from shell */
  409.  
  410.      DrawView( TRUE );   /* draw everything */
  411.  
  412.     /*
  413.      * Note that SimpleRexx is set up such that you do not
  414.      * need to check for an error to initialize your REXX port
  415.      * This is so application could run without REXX...
  416.      */
  417.  
  418.     if (Stricmp(MyName,&version_string[5])==0) strcpy (RexxName,"CPLOT_REXX");
  419.     else strcpy(RexxName,MyName);
  420.  
  421.     RexxStuff=InitARexx(RexxName,NULL);
  422.  
  423.     rexxsigs = ARexxSignal(RexxStuff);
  424.  
  425. /* loop to monitor window events and rexx port and watch for break */
  426.  
  427.      do
  428.        {
  429.          SetPointer( PlotWindowWnd, SAIPointer, SAIHEIGHT, SAIWIDTH, SAIXOFF , SAIYOFF);    /* Set SAIC pointer image */
  430.  
  431.           sigs = Wait ( rexxsigs | SIGBREAKF_CTRL_C | 1L<<PlotWindowWnd->UserPort->mp_SigBit );
  432.  
  433.          SetPointer( PlotWindowWnd, WAITPointer, WAITHEIGHT, WAITWIDTH, WAITXOFF , WAITYOFF);    /* Set wait pointer image */
  434.  
  435.           SetWindowTitles( PlotWindowWnd, MyName, MyName );
  436.  
  437.         if (sigs & 1L<<PlotWindowWnd->UserPort->mp_SigBit) alive = HandlePlotWindowIDCMP();
  438.           else if (sigs & rexxsigs ) alive = HandleARexxMes();
  439.           else if (sigs & SIGBREAKF_CTRL_C ) alive = 0;
  440.           
  441.           if      (alive == 10) NewDepth(1);
  442.           else if (alive == 20) NewDepth(2);
  443.           else if (alive == 30) NewDepth(3);
  444.           else if (alive == 40) NewDepth(4);
  445.        }
  446.      while ( alive );
  447.  
  448.      SetPointer( PlotWindowWnd, BOOMPointer, BOOMHEIGHT, BOOMWIDTH, BOOMXOFF , BOOMYOFF);    /* Set nuke pointer image */
  449.  
  450.      Death(0); /* normal exit */
  451. }
  452.