home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / misc / sci / cp / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  9.1 KB  |  327 lines

  1. #include "cp.h"
  2. #include "spr.h"
  3.  
  4. UBYTE     *version_string     = "$VER: cp  3.0 (26.10.93)";
  5.  
  6. LONG      __oslibversion      = 37;     /* requires KickStart 37 */
  7. LONG      __BackGroundIO      = 1;
  8. LONG      __stack             = 8192;   /* stack size doesn't seem to work ??? */
  9. UBYTE     *__procname         = "cP regnoC"; /* 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.  
  20.  
  21. /* Set Defaults */
  22.  
  23. BOOL grid    = FALSE;     /* No Grid */
  24. BOOL LOGX    = FALSE;     /* Lin X */
  25. BOOL LOGY    = FALSE;     /* Lin Y */
  26. BOOL sym     = FALSE;     /* No Symbols */
  27. BOOL DEFS    = FALSE;     /* Don't make cP */
  28. BOOL MONO    = FALSE;     /* color default */
  29. BOOL CPANEL  = TRUE;      /* control panel on */
  30. BOOL NOFNAME = FALSE;     /* ussually put filename boxes on screen */
  31.  
  32. LONG Disp = HIRESLACE_KEY;    /* Hires Lace Default */
  33.  
  34. UBYTE *path;        /* extern pointer to Path */
  35. UBYTE Path[255];    /* Path String same as path but not external */
  36.  
  37. UBYTE *fName;        /* extern pointer to fontname */
  38. UBYTE fontName[32]; /* im too lazy to allocate dynamically */
  39.  
  40. UBYTE *chans   = NULL;
  41. LONG points    = 1000000; /* should be enough max per set */
  42. LONG thin      = 1;    /* dont depopulate */
  43.  
  44. WORD lastcolor = 15;     /* 16 colors default palette */
  45. WORD depth     = 4;
  46.  
  47. LONG *idkey;             /* pointer to Display ID */
  48.  
  49. UBYTE **files;           /* pointer to pointer to FILES/M/A */
  50.  
  51. #define ENVSIZE 1024     /* max char length for envvar */
  52.  
  53. UBYTE *template = "FILES=WILD/A/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,C=BINARY/F/K,P=POINTS/N/K,T=THIN/N/K,D=DEPTH/N/K,MONO/S,CPANEL/S,NOFN=NOFNBOXES/S";
  54. UBYTE *envtempl = "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,C=BINARY/F/K,P=POINTS/N/K,T=THIN/N/K,D=DEPTH/N/K,MONO/S,CPANEL/S,NOFN=NOFNBOXES/S";
  55.  
  56. LONG cli_array[ 20 ] = { 0L, 0L, 0L, 0L, 0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L, 0L, 0L, 0L, 0L};
  57. LONG env_array[ 20 ] = { 0L, 0L, 0L, 0L, 0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L ,0L, 0L, 0L, 0L, 0L};
  58.  
  59. extern void exit(int);   /* from stdlib.h */
  60.  
  61. /* Use the same function to process command line and envvar */
  62.  
  63. void arg_array_Parse( LONG *arg_array )
  64. {
  65. LONG *ptr;
  66.  
  67.      files = ( UBYTE ** ) arg_array[ 0 ];
  68.  
  69.      if ( arg_array[ 1 ] ) LOGX = TRUE;
  70.      if ( arg_array[ 2 ] ) LOGY = TRUE;
  71.      if ( arg_array[ 3 ] ) grid = TRUE;
  72.      if ( arg_array[ 4 ] ) sym  = TRUE;
  73.  
  74.      if ( arg_array[ 5 ] )
  75.        {
  76.           ptr = (LONG *)arg_array[ 5 ];
  77.           Disp = *ptr;
  78.        }
  79.  
  80.      if ( arg_array[ 6 ] )
  81.        {
  82.           strcpy( fName, (UBYTE *)arg_array[ 6 ]);
  83.           strcat( fName, ".font");
  84.           cPFont->ta_Name = (STRPTR)fName;
  85.        }
  86.  
  87.      if ( arg_array[ 7 ] )
  88.        {
  89.           ptr = (LONG *)arg_array[ 7 ];
  90.           cPFont->ta_YSize = (UWORD) *ptr;
  91.        }
  92.  
  93.      if ( arg_array[ 8 ] )  Disp  = LORES_KEY;
  94.      if ( arg_array[ 9 ] )  Disp  = HIRES_KEY;
  95.      if ( arg_array[ 10 ] ) Disp |= LORESLACE_KEY;
  96.      if ( arg_array[ 11 ] ) DEFS  = TRUE;
  97.  
  98.      if ( arg_array[ 12 ] )
  99.        {
  100.           ptr = (LONG *)arg_array[ 12 ];
  101.           SWIDTH = *ptr;
  102.        }
  103.  
  104.      if ( arg_array[ 13 ] )
  105.        {
  106.           ptr = (LONG *)arg_array[ 13 ];
  107.           SHEIGHT = *ptr;
  108.        }
  109.      if ( arg_array[ 14 ] )
  110.        {
  111.           chans = AllocVec( 1024, MEMF_CLEAR );
  112.           if ( chans ) strcpy( chans, (UBYTE *)arg_array[ 14 ]);
  113.        }
  114.      if ( arg_array[ 15 ] )
  115.        {
  116.           ptr = (LONG *)arg_array[ 15 ];
  117.           points = *ptr;
  118.        }
  119.      if ( arg_array[ 16 ] )
  120.        {
  121.           ptr = (LONG *)arg_array[ 16 ];
  122.           thin = *ptr;
  123.           if (thin <= 0) thin = 1;
  124.        }
  125.      if ( arg_array[ 17 ] )
  126.        {
  127.           ptr = (LONG *)arg_array[ 17 ];
  128.           depth = (WORD)*ptr;
  129.  
  130.           if (depth <= 1 )
  131.             {
  132.                depth = 1;
  133.                lastcolor = 1;
  134.                MONO = TRUE;
  135.             }
  136.           if (depth == 2) lastcolor = 3;
  137.           if (depth == 3) lastcolor = 7;
  138.           if (depth >= 4)
  139.             {
  140.                depth = 4;
  141.                lastcolor = 15;
  142.             }
  143.        }
  144.      if ( arg_array[ 18 ] )
  145.        {
  146.           MONO  = TRUE;
  147.           depth = 1;
  148.           lastcolor = 1;
  149.        }
  150.      if ( arg_array[ 19 ] )
  151.        {
  152.           if ( CPANEL ) CPANEL = FALSE;
  153.           else          CPANEL = TRUE;
  154.        }
  155.      if ( arg_array[ 20 ] )
  156.        {
  157.           if ( NOFNAME ) NOFNAME = FALSE;
  158.           else           NOFNAME = TRUE;
  159.        }
  160. }
  161.  
  162.  
  163. /* Clean up and die duh */
  164.  
  165. void Death( int v )
  166. {
  167.     if ( delwinWnd )     ClosedelwinWindow();
  168.  
  169.     if ( PlotWindowWnd ) ClosePlotWindowWindow();
  170.  
  171.     if ( Scr )           CloseDownScreen();
  172.  
  173.     if ( fontPtr )       CloseFont( fontPtr );
  174.  
  175.     FreeAllSets();
  176.  
  177.     if ( cli_args )      FreeArgs( cli_args );
  178.  
  179.     exit( v );
  180. }
  181.  
  182.  
  183. void main(void)
  184. {
  185. struct AnchorPath anchorpath;
  186.  
  187. LONG mres;
  188. struct List slist;
  189. WORD j = NULL;
  190. BPTR lock;
  191. LONG len;
  192. UBYTE fault[300];
  193. UBYTE *environ;
  194.  
  195.      slist.lh_Head = (struct Node *) &slist.lh_Tail;
  196.      slist.lh_Tail = 0;
  197.      slist.lh_TailPred = (struct Node *) &slist.lh_Head;
  198.      slist.lh_Type = NT_DATA;
  199.  
  200.      SetList   = &slist;
  201.  
  202.      cPFont    = &CPFont;
  203.      fName     = &fontName[0];
  204.      path      = Path;
  205.  
  206.      /* Parse envvar CPCONFIG */
  207.  
  208.      if (( environ = AllocVec( ENVSIZE, MEMF_CLEAR )))
  209.        {
  210.           len = GetVar( "CPCONFIG", environ, ENVSIZE, GVF_GLOBAL_ONLY );
  211.           if ( len > 0 )
  212.             {
  213.                environ[len]   = '\n';
  214.                environ[++len] = '\0';
  215.  
  216.                if ((env_args = (struct RDArgs *)AllocDosObject(DOS_RDARGS, TAG_DONE)))
  217.                  {
  218.                     env_args->RDA_Source.CS_Buffer = environ;
  219.                     env_args->RDA_Source.CS_Length = len;
  220.                     env_args->RDA_Source.CS_CurChr = 0L;
  221.  
  222.                     if( ReadArgs( envtempl, (LONG *)&env_array[ 0 ], env_args ))
  223.                          arg_array_Parse( &env_array[ 0 ] );
  224.  
  225.                     FreeArgs( env_args );
  226.                     FreeDosObject(DOS_RDARGS, env_args);
  227.                  }
  228.             }
  229.           FreeVec( environ );
  230.        }
  231.  
  232.      /* Read command line with ReadArgs */
  233.  
  234.      if ( ! ( cli_args = ReadArgs( template, &cli_array[ 0 ], 0L )))
  235.        {
  236.           if ( _Backstdout )
  237.             {
  238.                 if ( Fault(IoErr(), template, fault, 300)) FPuts(_Backstdout, fault);
  239.                Close( _Backstdout);
  240.             }
  241.           Death ( 1 );
  242.        }
  243.  
  244.      arg_array_Parse( &cli_array[ 0 ] );
  245.  
  246.      if ( ! (fontPtr = OpencPFont()))
  247.        {
  248.             if ( _Backstdout) Close( _Backstdout);
  249.             Death(10);
  250.        }
  251.  
  252.      if ( OpenGTXScreen())
  253.        {
  254.             if ( _Backstdout) Close( _Backstdout);
  255.             Death(10);
  256.        }
  257.  
  258.      if ( OpenGTXWindow( OpenPlotWindowWindow ))
  259.        {
  260.             if ( _Backstdout) Close( _Backstdout);
  261.             Death(10);
  262.        }
  263.  
  264.      PlotWindowWnd-> RPort-> Font = fontPtr;
  265.  
  266.      SetPointer( PlotWindowWnd, SpriteData, SpriteHeight, 15, -1 , 0 );    /* Set pointer to spr.c image */
  267.  
  268.      SetRGB4( &Scr-> ViewPort, 17,7, 8,15);  /* set colors for pointer */
  269.      SetRGB4( &Scr-> ViewPort, 19,15,3,15);
  270.  
  271.  
  272. /* load files from Wild pattern */
  273.  
  274.      while ( files[ j ]  )
  275.        {
  276.           if ( ! Stricmp(files[ j ], "*")) files[ j ] = "#?";
  277.  
  278.           mres = MatchFirst( files[ j ], &anchorpath );
  279.  
  280.           if ( mres == NULL )
  281.             {
  282.                lock = CurrentDir( anchorpath.ap_Current-> an_Lock );
  283.                if(!chans)AddSet( anchorpath.ap_Info.fib_FileName );
  284.                else rhp_Args( anchorpath.ap_Info.fib_FileName, chans);
  285.                CurrentDir( lock );
  286.  
  287.                while( MatchNext( &anchorpath ) == NULL )
  288.                  {
  289.                     lock = CurrentDir( anchorpath.ap_Current-> an_Lock );
  290.                     if(!chans)AddSet( anchorpath.ap_Info.fib_FileName );
  291.                     else rhp_Args( anchorpath.ap_Info.fib_FileName, chans);
  292.                     CurrentDir( lock );
  293.                  }
  294.             }
  295.           else if ( mres == ERROR_OBJECT_NOT_FOUND )
  296.             {
  297.                if ( _Backstdout)
  298.                  {
  299.                     FPuts( _Backstdout, " ERROR_OBJECT_NOT_FOUND -> ");
  300.                     FPuts( _Backstdout, files[ j ]);
  301.                     FPutC ( _Backstdout, '\n');
  302.                     Close( _Backstdout);
  303.                  }
  304.                MatchEnd( &anchorpath );
  305.                Death ( 5 );
  306.             }
  307.           MatchEnd( &anchorpath );
  308.           j++;
  309.        }
  310.  
  311.      if ( chans ) FreeVec( chans );
  312.  
  313.      if ( _Backstdout) Close( _Backstdout);  /* close output so we detache from shell */
  314.  
  315.      DrawView( TRUE );   /* draw everything */
  316.  
  317. /* loop to monitor window events */
  318.  
  319.      do
  320.        {
  321.           Wait ( 1L << PlotWindowWnd-> UserPort-> mp_SigBit );
  322.        }
  323.      while ( HandlePlotWindowIDCMP() );
  324.  
  325.      Death(0); /* normal exit */
  326. }
  327.