home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 177 / c / resource.c < prev   
Encoding:
C/C++ Source or Header  |  1987-09-15  |  11.1 KB  |  237 lines

  1. /*
  2.  * Internal resource setup for C.
  3.  *
  4.  * Daniel L. Moore
  5.  *
  6.  * revision history:
  7.  *      Jan '87  -- first cut, only works with my object struct def.
  8.  *      May '87  -- added support for "protected" resources
  9.  *                  to stop jerks who change copyright notices.
  10.  *      Sep '87  -- cut for public release, added in support for the
  11.  *                  standard DRI object struct def.  removed the protected
  12.  *                  resource code.
  13.  *      Sep '87 again -- forgot to change the OBJECT_PTR typedefs to 
  14.  *                       OBJECT * so other people can use it.  This copy
  15.  *                       is changed.       
  16.  *
  17.  * This file supplies the code to include the resource data file internal
  18.  * to the program.  This is done by including the .rsh file produced by
  19.  * the RSC into the program.  The three routines in this file then take
  20.  * care of actually getting the resource data that was loaded ready to 
  21.  * use.  The routines are:
  22.  *
  23.  *       rsrc_load()       --- does a rsrc_obfix on all objects and puts
  24.  *                             all the trees/strings together.  
  25.  *
  26.  *       rsrc_gaddr()      --- returns the address of the loaded resoruce 
  27.  *                             object tree.
  28.  *
  29.  *       rsrc_free()       --- a dummy, just to catch the "real" call.
  30.  *
  31.  * by using this file you can write and debug your program while using
  32.  * the real resource library.  that makes changing the resource faster
  33.  * since this file isn't compiled (which can get real slow sometimes,
  34.  * some compilers hate inited data).  then this file can be compiled and
  35.  * linked with the program for the "production" version.
  36.  *
  37.  * Tested with Mark Williams C version 2.0 and Megamax C versions 1.0 and 1.1.
  38.  *
  39.  * HELP STAMP OUT RESOURCE FILES IN YOUR LIFETIME.
  40.  *
  41.  **************************************************************************
  42.  *                                                                        *
  43.  *       Copyright Notice                                                 *
  44.  *                                                                        *
  45.  * This source code and the object code it represents are copyright 1987  *
  46.  * by Daniel L. Moore.  The rights to use this source and object code are *
  47.  * hereby granted to any and all who may desire to use it with no         *
  48.  * restrictions.  It would be nice if you would credit me with writing    *
  49.  * this if you use it but that is not required.                           *
  50.  *                                                                        *
  51.  * Not withstanding the above any employee or represenative of            *
  52.  * Micro Systems Software can NOT use this code in any program written    *
  53.  * for commercial or private use without prior written permission from    *
  54.  * the Author.                                                            *
  55.  *                                                                        *
  56.  * This source code and the object code it represents are supplied on an  *
  57.  * as is basis.  There is no warranty (explicit or implied) on it's       *
  58.  * useability or reliabilty when used.  Use at your own risk.             *
  59.  *                                                                        *
  60.  **************************************************************************
  61.  *
  62.  * The above was brought to you curtesy of the US legal system. 
  63.  *
  64.  *
  65.  *  Daniel L. Moore  ---  September 3,  1987
  66.  *                   ---- September 11, 1987
  67.  *
  68.  */
  69.  
  70. #define DRI_STRUCTS     1       /* use my structure defs or DRIs */
  71.  
  72. #include <portab.h>
  73. #include <obdefs.h>
  74. #include <gemdefs.h>
  75.  
  76. /*
  77.  * The following line includes the C source code to the resource.  It is
  78.  * written by the RCS program.  Change to match the name of your resource
  79.  * file.
  80.  *
  81.  * NOTE:  There is a bug in some versions of the Megamax C compiler.  The
  82.  *        compiler gives an incorrect error message on lines of the form:
  83.  *            BYTE pname[] = "MY.RSC";
  84.  *        Since this is the VERY last line of the .rsh file it causes compiles
  85.  *        to blow up at that point.  In order to compile this using Megamax
  86.  *        that line must be deleted.
  87.  *
  88.  * Note:  There is no CR/LF after that BYTE line, just a ^Z eof marker
  89.  *        (it shows in the Tempus editor that way).  Just delete that
  90.  *        ^Z character and add a CR/LF, and it compiles OK.  This package
  91.  *        was compiled and tested with Megamax in development of
  92.  *        the WP Importer by Mat*Rat on 9/12/87. Works great! Thanks DLM!
  93.  *        Note that the 'void's were removed, since Megamax didn't care
  94.  *        much for them. Caused wierd problems!
  95.  *
  96.  *
  97.  *        Another problem with Megamax is the way it handles initialized
  98.  *        data structures.  Instead of initing the data at compile time and
  99.  *        placing it in the data segment it generates code in the "Init!"
  100.  *        segment that when run generates the inited data.  The "Init!"
  101.  *        segment code is called from __main() before _main() is run.
  102.  *        Since it generates code to init the data it is very easy to 
  103.  *        write a resource that takes more than 32K of code to initialize.
  104.  *        These resources can not be made resident using this program, it
  105.  *        requires another version which converts all the data into inline
  106.  *        asm data statements and places them into a code segment.  This
  107.  *        allows resources containing up to 32K of data to be made
  108.  *        resident.  If anyone is interested in that version leave a message
  109.  *        to me on either CIS (ppn 74035,243) or Delphi (username DLM).
  110.  */
  111. #include "wpimport.rsh"   /* C source to resource data */
  112.  
  113. /*
  114.  * now a bunch of silly defines that handle structure element
  115.  * references.  defines are used in order to support two different
  116.  * stucture formats, mine and the standard DRI ones.
  117.  */
  118. #if DRI_STRUCTS
  119. #       define object_spec(x)           (rs_object[x].ob_spec)
  120. #       define object_type(x)           (rs_object[x].ob_type)
  121. #       define tedinfo_ptext(x)         (rs_tedinfo[x].te_ptext)
  122. #       define tedinfo_ptmplt(x)        (rs_tedinfo[x].te_ptmplt)
  123. #       define tedinfo_pvalid(x)        (rs_tedinfo[x].te_pvalid)
  124. #       define bitblk_pdata(x)          (rs_bitblk[x].bi_pdata)
  125. #       define iconblk_pmask(x)         (rs_iconblk[x].ib_pmask)
  126. #       define iconblk_pdata(x)         (rs_iconblk[x].ib_pdata)
  127. #       define iconblk_ptext(x)         (rs_iconblk[x].ib_ptext)
  128. #else /* use my structure definitions */
  129. #       define object_spec(x)           (rs_object[x].spec)
  130. #       define object_type(x)           (rs_object[x].type)
  131. #       define tedinfo_ptext(x)         (rs_tedinfo[x].ptext)
  132. #       define tedinfo_ptmplt(x)        (rs_tedinfo[x].ptplt)
  133. #       define tedinfo_pvalid(x)        (rs_tedinfo[x].pvalid)
  134. #       define bitblk_pdata(x)          (rs_bitblk[x].pdata)
  135. #       define iconblk_pmask(x)         (rs_iconblk[x].pmask)
  136. #       define iconblk_pdata(x)         (rs_iconblk[x].pdata)
  137. #       define iconblk_ptext(x)         (rs_iconblk[x].ptext)
  138. #endif DRI_STRUCTS
  139.  
  140. int
  141. rsrc_load(name)
  142. char *name;                     /* passed param, ignored here */
  143. { /* rsrc_load function */
  144.         /*
  145.          * loads the resource.  This really means it just hooks all the objects
  146.          * together and does rsrc_obfix() calls for all of them.
  147.          *
  148.          * NOTE: there are a couple of variables in the control arrays that
  149.          *       this code doesn't bother to init.  since we catch most
  150.          *       of the resource library calls it wasn't worth the effort
  151.          *       to init them.  but they may be need for some of the 
  152.          *       object tree editing calls, if so they will have to be
  153.          *       inited by this code.
  154.          */
  155.         register int i, j;
  156.  
  157.         /* first loop the rs_index array and locate the trees */
  158.         for (i = 0; i < NUM_TREE; i++)
  159.                 rs_trindex[i] = (long) &(rs_object[(int)rs_trindex[i]]);    
  160.  
  161.         /* now go thru the rs_object array and take care of the objects */
  162.         for (i = 0; i < NUM_OBS; i++) { /* FOR */
  163.                 rsrc_obfix(rs_object, i);   /* fix coordinates */
  164.                 j = (int) object_spec(i);
  165.                 switch (object_type(i)) { /* SWITCH */
  166.                 case G_STRING :
  167.                 case G_BUTTON : 
  168.                 case G_TITLE  :
  169.                         object_spec(i) = rs_strings[j];
  170.                         break;
  171. #if NUM_TI      /* any tedinfos? */
  172.                 case G_TEXT     :
  173.                 case G_BOXTEXT  :
  174.                 case G_FBOXTEXT :
  175.                 case G_FTEXT    :
  176.                         object_spec(i)    = (BYTE *) &rs_tedinfo[j];
  177.                         tedinfo_ptext(j)  = rs_strings[(int)tedinfo_ptext(j)];
  178.                         tedinfo_ptmplt(j) = rs_strings[(int)tedinfo_ptmplt(j)];
  179.                         tedinfo_pvalid(j) = rs_strings[(int)tedinfo_pvalid(j)];
  180.                         break;
  181. #endif NUM_TI
  182. #if NUM_BB      /* any bit blocks? */
  183.                 case G_IMAGE    :
  184.                         object_spec(i)  = (BYTE *) &rs_bitblk[j];
  185.                         bitblk_pdata(j) = rs_imdope[(int)bit_block_pdata(j)].image;
  186.                         break;
  187. #endif NUM_BB
  188. #if NUM_IB      /* any icons?   */
  189.                 case G_ICON     :
  190.                         object_spec(i)   = (BYTE *) &rs_iconblk[j];
  191.                         iconblk_pmask(j) = rs_imdope[(int)iconblk_pmask(j)].image;
  192.                         iconblk_pdata(j) = rs_imdope[(int)iconblk_pdata(j)].image;
  193.                         iconblk_ptext(j) = rs_strings[(int)iconblk_ptext(j)];
  194.                         break;
  195. #endif NUM_IB
  196.                 } /* END SWITCH */
  197.         } /* END FOR */
  198.  
  199.         /*
  200.          * in theory we could compare the resource name to the passed name
  201.          * to make sure the right .rsh file is included.  but why bother,
  202.          * as soon as the program is run it will be obvious if the wrong
  203.          * file is included.  and EVERYONE tests their files before 
  204.          * releasing them, RIGHT?
  205.          */
  206.  
  207.         return(1);      /* return a success flag, we never fail */
  208. } /* END rsrc_load */
  209.  
  210. rsrc_gaddr(type, which, tree_ptr)
  211.        int type, which;
  212. OBJECT **tree_ptr;
  213. { /* rsrc_gaddr function */
  214.         /*
  215.          * get the address of the start of the tree
  216.          *
  217.          * NOTE: the only gaddr command we support is R_TREE.  but since
  218.          *       none of the others work in the "real" resource library
  219.          *       it really doesn't matter.  (I've always wondered why the
  220.          *       other options were in there.  Just to make things look
  221.          *       impressive I guess.)
  222.          */
  223.         if (type == R_TREE) {   /* do we understand the command? */
  224.                 *tree_ptr = (OBJECT *) rs_trindex[which];
  225.         } /* point to next tree */
  226. } /* rsrc_gaddr end */
  227.  
  228. /* A resource is never REALLY loaded. It is part of the program. */
  229. /* The resource does not need to be FREED. It goes away when the */
  230. /* program itself does.                                          */
  231.  
  232. rsrc_free()
  233. { /* rsrc_free function */
  234.  
  235.         ;       /* don't do much of anything */
  236. } /* rsrc_free end */
  237.