home *** CD-ROM | disk | FTP | other *** search
- /*
- * Internal resource setup for C.
- *
- * Daniel L. Moore
- *
- * revision history:
- * Jan '87 -- first cut, only works with my object struct def.
- * May '87 -- added support for "protected" resources
- * to stop jerks who change copyright notices.
- * Sep '87 -- cut for public release, added in support for the
- * standard DRI object struct def. removed the protected
- * resource code.
- * Sep '87 again -- forgot to change the OBJECT_PTR typedefs to
- * OBJECT * so other people can use it. This copy
- * is changed.
- *
- * This file supplies the code to include the resource data file internal
- * to the program. This is done by including the .rsh file produced by
- * the RSC into the program. The three routines in this file then take
- * care of actually getting the resource data that was loaded ready to
- * use. The routines are:
- *
- * rsrc_load() --- does a rsrc_obfix on all objects and puts
- * all the trees/strings together.
- *
- * rsrc_gaddr() --- returns the address of the loaded resoruce
- * object tree.
- *
- * rsrc_free() --- a dummy, just to catch the "real" call.
- *
- * by using this file you can write and debug your program while using
- * the real resource library. that makes changing the resource faster
- * since this file isn't compiled (which can get real slow sometimes,
- * some compilers hate inited data). then this file can be compiled and
- * linked with the program for the "production" version.
- *
- * Tested with Mark Williams C version 2.0 and Megamax C versions 1.0 and 1.1.
- *
- * HELP STAMP OUT RESOURCE FILES IN YOUR LIFETIME.
- *
- **************************************************************************
- * *
- * Copyright Notice *
- * *
- * This source code and the object code it represents are copyright 1987 *
- * by Daniel L. Moore. The rights to use this source and object code are *
- * hereby granted to any and all who may desire to use it with no *
- * restrictions. It would be nice if you would credit me with writing *
- * this if you use it but that is not required. *
- * *
- * Not withstanding the above any employee or represenative of *
- * Micro Systems Software can NOT use this code in any program written *
- * for commercial or private use without prior written permission from *
- * the Author. *
- * *
- * This source code and the object code it represents are supplied on an *
- * as is basis. There is no warranty (explicit or implied) on it's *
- * useability or reliabilty when used. Use at your own risk. *
- * *
- **************************************************************************
- *
- * The above was brought to you curtesy of the US legal system.
- *
- *
- * Daniel L. Moore --- September 3, 1987
- * ---- September 11, 1987
- *
- */
-
- #define DRI_STRUCTS 1 /* use my structure defs or DRIs */
-
- #include <portab.h>
- #include <obdefs.h>
- #include <gemdefs.h>
-
- /*
- * The following line includes the C source code to the resource. It is
- * written by the RCS program. Change to match the name of your resource
- * file.
- *
- * NOTE: There is a bug in some versions of the Megamax C compiler. The
- * compiler gives an incorrect error message on lines of the form:
- * BYTE pname[] = "MY.RSC";
- * Since this is the VERY last line of the .rsh file it causes compiles
- * to blow up at that point. In order to compile this using Megamax
- * that line must be deleted.
- *
- * Note: There is no CR/LF after that BYTE line, just a ^Z eof marker
- * (it shows in the Tempus editor that way). Just delete that
- * ^Z character and add a CR/LF, and it compiles OK. This package
- * was compiled and tested with Megamax in development of
- * the WP Importer by Mat*Rat on 9/12/87. Works great! Thanks DLM!
- * Note that the 'void's were removed, since Megamax didn't care
- * much for them. Caused wierd problems!
- *
- *
- * Another problem with Megamax is the way it handles initialized
- * data structures. Instead of initing the data at compile time and
- * placing it in the data segment it generates code in the "Init!"
- * segment that when run generates the inited data. The "Init!"
- * segment code is called from __main() before _main() is run.
- * Since it generates code to init the data it is very easy to
- * write a resource that takes more than 32K of code to initialize.
- * These resources can not be made resident using this program, it
- * requires another version which converts all the data into inline
- * asm data statements and places them into a code segment. This
- * allows resources containing up to 32K of data to be made
- * resident. If anyone is interested in that version leave a message
- * to me on either CIS (ppn 74035,243) or Delphi (username DLM).
- */
- #include "wpimport.rsh" /* C source to resource data */
-
- /*
- * now a bunch of silly defines that handle structure element
- * references. defines are used in order to support two different
- * stucture formats, mine and the standard DRI ones.
- */
- #if DRI_STRUCTS
- # define object_spec(x) (rs_object[x].ob_spec)
- # define object_type(x) (rs_object[x].ob_type)
- # define tedinfo_ptext(x) (rs_tedinfo[x].te_ptext)
- # define tedinfo_ptmplt(x) (rs_tedinfo[x].te_ptmplt)
- # define tedinfo_pvalid(x) (rs_tedinfo[x].te_pvalid)
- # define bitblk_pdata(x) (rs_bitblk[x].bi_pdata)
- # define iconblk_pmask(x) (rs_iconblk[x].ib_pmask)
- # define iconblk_pdata(x) (rs_iconblk[x].ib_pdata)
- # define iconblk_ptext(x) (rs_iconblk[x].ib_ptext)
- #else /* use my structure definitions */
- # define object_spec(x) (rs_object[x].spec)
- # define object_type(x) (rs_object[x].type)
- # define tedinfo_ptext(x) (rs_tedinfo[x].ptext)
- # define tedinfo_ptmplt(x) (rs_tedinfo[x].ptplt)
- # define tedinfo_pvalid(x) (rs_tedinfo[x].pvalid)
- # define bitblk_pdata(x) (rs_bitblk[x].pdata)
- # define iconblk_pmask(x) (rs_iconblk[x].pmask)
- # define iconblk_pdata(x) (rs_iconblk[x].pdata)
- # define iconblk_ptext(x) (rs_iconblk[x].ptext)
- #endif DRI_STRUCTS
-
- int
- rsrc_load(name)
- char *name; /* passed param, ignored here */
- { /* rsrc_load function */
- /*
- * loads the resource. This really means it just hooks all the objects
- * together and does rsrc_obfix() calls for all of them.
- *
- * NOTE: there are a couple of variables in the control arrays that
- * this code doesn't bother to init. since we catch most
- * of the resource library calls it wasn't worth the effort
- * to init them. but they may be need for some of the
- * object tree editing calls, if so they will have to be
- * inited by this code.
- */
- register int i, j;
-
- /* first loop the rs_index array and locate the trees */
- for (i = 0; i < NUM_TREE; i++)
- rs_trindex[i] = (long) &(rs_object[(int)rs_trindex[i]]);
-
- /* now go thru the rs_object array and take care of the objects */
- for (i = 0; i < NUM_OBS; i++) { /* FOR */
- rsrc_obfix(rs_object, i); /* fix coordinates */
- j = (int) object_spec(i);
- switch (object_type(i)) { /* SWITCH */
- case G_STRING :
- case G_BUTTON :
- case G_TITLE :
- object_spec(i) = rs_strings[j];
- break;
- #if NUM_TI /* any tedinfos? */
- case G_TEXT :
- case G_BOXTEXT :
- case G_FBOXTEXT :
- case G_FTEXT :
- object_spec(i) = (BYTE *) &rs_tedinfo[j];
- tedinfo_ptext(j) = rs_strings[(int)tedinfo_ptext(j)];
- tedinfo_ptmplt(j) = rs_strings[(int)tedinfo_ptmplt(j)];
- tedinfo_pvalid(j) = rs_strings[(int)tedinfo_pvalid(j)];
- break;
- #endif NUM_TI
- #if NUM_BB /* any bit blocks? */
- case G_IMAGE :
- object_spec(i) = (BYTE *) &rs_bitblk[j];
- bitblk_pdata(j) = rs_imdope[(int)bit_block_pdata(j)].image;
- break;
- #endif NUM_BB
- #if NUM_IB /* any icons? */
- case G_ICON :
- object_spec(i) = (BYTE *) &rs_iconblk[j];
- iconblk_pmask(j) = rs_imdope[(int)iconblk_pmask(j)].image;
- iconblk_pdata(j) = rs_imdope[(int)iconblk_pdata(j)].image;
- iconblk_ptext(j) = rs_strings[(int)iconblk_ptext(j)];
- break;
- #endif NUM_IB
- } /* END SWITCH */
- } /* END FOR */
-
- /*
- * in theory we could compare the resource name to the passed name
- * to make sure the right .rsh file is included. but why bother,
- * as soon as the program is run it will be obvious if the wrong
- * file is included. and EVERYONE tests their files before
- * releasing them, RIGHT?
- */
-
- return(1); /* return a success flag, we never fail */
- } /* END rsrc_load */
-
- rsrc_gaddr(type, which, tree_ptr)
- int type, which;
- OBJECT **tree_ptr;
- { /* rsrc_gaddr function */
- /*
- * get the address of the start of the tree
- *
- * NOTE: the only gaddr command we support is R_TREE. but since
- * none of the others work in the "real" resource library
- * it really doesn't matter. (I've always wondered why the
- * other options were in there. Just to make things look
- * impressive I guess.)
- */
- if (type == R_TREE) { /* do we understand the command? */
- *tree_ptr = (OBJECT *) rs_trindex[which];
- } /* point to next tree */
- } /* rsrc_gaddr end */
-
- /* A resource is never REALLY loaded. It is part of the program. */
- /* The resource does not need to be FREED. It goes away when the */
- /* program itself does. */
-
- rsrc_free()
- { /* rsrc_free function */
-
- ; /* don't do much of anything */
- } /* rsrc_free end */
-