home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / FileQueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-14  |  3.8 KB  |  138 lines  |  [TEXT/CWIE]

  1. /*
  2. ==============================================================================
  3. Project:    POV-Ray
  4.  
  5. Version:    3
  6.  
  7. File Name:    FileQueue.c
  8.  
  9. Description:
  10.     Generic Macintosh File Spec queueing routine.  This is intended to
  11.     be used to collect the list of files passed in via System 7 ODOC
  12.     AppleEvents, for processing at a more convenient time.
  13.  
  14.     This is the main implementation of the functions.
  15.  
  16. Related Files:
  17.     FileQueue.h    - External interface for these routines
  18. ------------------------------------------------------------------------------
  19. Author:
  20.     Eduard [esp] Schwan
  21. ------------------------------------------------------------------------------
  22.     from Persistence of Vision(tm) Ray Tracer
  23.     Copyright 1996 Persistence of Vision Team
  24. ------------------------------------------------------------------------------
  25.     NOTICE: This source code file is provided so that users may experiment
  26.     with enhancements to POV-Ray and to port the software to platforms other 
  27.     than those supported by the POV-Ray Team.  There are strict rules under
  28.     which you are permitted to use this file.  The rules are in the file
  29.     named POVLEGAL.DOC which should be distributed with this file. If 
  30.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  31.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  32.     Forum.  The latest version of POV-Ray may be found there as well.
  33.  
  34.     This program is based on the popular DKB raytracer version 2.12.
  35.     DKBTrace was originally written by David K. Buck.
  36.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  37. ------------------------------------------------------------------------------
  38. Change History:
  39.     920820    [esp]    Created
  40.     921221    [esp]    Added logic in Get() routine to call destructor after getting last item
  41.     931001    [esp]    version 2.0 finished (Released on 10/4/93)
  42. ==============================================================================
  43. */
  44.  
  45. #include "config.h"
  46. #include "FileQueue.h"
  47. #include "LnkLst.h"    // generic list handler
  48.  
  49. #include <memory.h>    // NewHandle
  50.  
  51.  
  52.  
  53. // a static global instance for our internal use
  54. LLHeadPtr    gFileQueue = NULL;
  55.  
  56.  
  57. // ------------------------------------------------------------------
  58. // Initialize the list handling structures prior to use
  59. void FileQ_c(void)
  60. {
  61.     gFileQueue = LLCreateList(1);
  62. } // FileQ_c
  63.  
  64.  
  65.  
  66. // ------------------------------------------------------------------
  67. // Add a file to the list
  68. void FileQ_Put(FSSpecPtr    pFSSpecPtr)
  69. {
  70.     flistptr_t    newFlistptr;
  71.  
  72.     // create new record
  73.     newFlistptr = (flistptr_t)NewPtr(sizeof(flistrec_t));
  74.  
  75.     if (newFlistptr)
  76.     {
  77.         // fill it up
  78.         newFlistptr->fFSSpec = *pFSSpecPtr;
  79.     
  80. #if defined (DO_DEBUG)
  81. printf("PutFileInList - '%P'\n",newFlistptr->fFSSpec.name);
  82. #endif // DO_DEBUG
  83.  
  84.         // append it to the list
  85.         LLAppendElement(gFileQueue, newFlistptr);
  86.     }
  87. } // FileQ_Put
  88.  
  89.  
  90.  
  91. // ------------------------------------------------------------------
  92. // Retrieve the next file from the list (increments after each call)
  93. Boolean FileQ_Get(FSSpecPtr    pFSSpecPtr)
  94. {
  95.     Boolean        GotIt = false;
  96.     FSSpecPtr    fsp;
  97.  
  98.     if (FileQ_NumItems() > 0)
  99.     {
  100.         // get first off list
  101.         fsp = (FSSpecPtr)LLGetElementByIndex(gFileQueue, 1);
  102.         if (fsp)
  103.         {
  104.             // copy data into parm
  105.             *pFSSpecPtr = *fsp;
  106.             GotIt = true;
  107. #if defined (DO_DEBUG)
  108. printf("GetFileFromList - '%P'\n",pFSSpecPtr->name);
  109. #endif // DO_DEBUG
  110.             // and remove list element
  111.             LLDeleteElementByIndex(gFileQueue, 1);
  112.             // and delete data storage of element
  113.             DisposePtr((Ptr)fsp);
  114.         }
  115.     }
  116.  
  117.     return GotIt;
  118.  
  119. } // FileQ_Get
  120.  
  121.  
  122. // ------------------------------------------------------------------
  123. // Return the # of items in the queue
  124. short FileQ_NumItems(void)
  125. {
  126.     return LLGetNumElements(gFileQueue);
  127. } // FileQ_NumItems
  128.  
  129.  
  130. // ------------------------------------------------------------------
  131. // Delete the list and its contents after its use
  132. void FileQ_d(void)
  133. {
  134.     LLDestroyList(gFileQueue);
  135.     gFileQueue = NULL;
  136. } // FileQ_d
  137.  
  138.