home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV-Ray
-
- Version: 3
-
- File: ArgvTrix.c
-
- Description:
- Faked Argv/argc handling routines. This file maintains a simple simulation
- of the Standard C argc/argv program command line parameters, letting an
- "outer" Mac application build an argument list and pass it to "main()".
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 941221 [esp] Created
- ==============================================================================*/
-
- #define ARGVTRIX_C
-
- /*==== my header =====*/
- #include "ArgvTrix.h"
-
-
- /*==== Macintosh-specific headers ====*/
- #include <errors.h> /* dupFNErr, etc */
- #include <strings.h> /* p2cstr */
- #include <Memory.h> /* NewPtr*/
-
-
- /*==== Standard C headers ====*/
-
- #include <string.h> /* strcpy */
-
-
- /*==== General definitions ====*/
-
- #define ARGV_MAX 100 /* maximum # of parameters in argv */
-
-
- /*==== Global variables (external scope) ====*/
-
- int my_argc = 0;
- char **my_argv = NULL;
-
-
- /*==== Global variables (local scope) ====*/
-
-
- // ---------------------------------------------------------------------
- // InitArgv
- // Allocate memory for the fake argv parameter buffer
- // ---------------------------------------------------------------------
- void InitArgv(void)
- {
- // If user forgot to dispose, do it now
- if (my_argv)
- DestroyArgv();
- // Create an Argv array that can handle ARGV_MAX pointers
- my_argv = (char**)NewPtr(ARGV_MAX * sizeof(char*));
- // reset argc
- my_argc = 0;
- } // InitArgs
-
-
- // ---------------------------------------------------------------------
- // DestroyArgv
- // All done with argc/argv, dispose storage
- // ---------------------------------------------------------------------
- void DestroyArgv(void)
- {
- int k;
- // if array is allocated...
- if (my_argv)
- {
- // destroy each argv string first, from argc on down
- for (k=my_argc-1; k>=0; k--)
- {
- if (my_argv[k])
- {
- DisposePtr((Ptr)my_argv[k]);
- my_argv[k] = NULL;
- }
- }
- // destroy the argv array itself now
- DisposePtr((Ptr)my_argv);
- my_argv = NULL;
- }
- my_argc = 0;
- }
-
-
- // ---------------------------------------------------------------------
- // AddArg
- // Add "s" as the next parameter in the argv/argc list (copies it)
- // ---------------------------------------------------------------------
- void AddArg(char *s)
- {
-
- #ifdef PROJECT_POVRAY
- if ((**gPrefs2Use_h).progress >= eProgDebug)
- printf("-d argv='%s', argc=%d, argcMax=%d\n",
- s, my_argc, ARGV_MAX);
- #endif
-
- if (my_argc < ARGV_MAX)
- {
- my_argv[my_argc] = (char*)NewPtr(strlen(s)+1);
- if (my_argv[my_argc])
- {
- strcpy(my_argv[my_argc], s);
- my_argc++;
- }
- }
- else
- {
- #ifdef PROJECT_POVRAY
- if ((**gPrefs2Use_h).progress >= eProgDebug)
- printf("## [AddArg.Error!] Argument overflow adding '%s'! index=%d, max=%d\n",
- s, my_argc, ARGV_MAX);
- #endif
- }
- } // AddArg
-
-
-