home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / fixtree3 / fixtree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-24  |  14.0 KB  |  337 lines

  1. /****************************************************************/
  2. /*      FIXTREE  -  by Guy L. Albertelli                        */
  3. /*                      4142 Highland Dr.                       */
  4. /*                      Mogadore, Oh.  44260                    */
  5. /*                                                              */
  6. /*      ************  SHAREWARE   ************                  */
  7. /*                                                              */
  8. /*      for the benefit of the ST community                     */
  9. /*                                                              */
  10. /*      ************  SHAREWARE   ************                  */
  11. /*                                                              */
  12. /*      This set of routines will convert a resource file       */
  13. /*      in source format (.RSH) that has been compiled and      */
  14. /*      linked with these routines to a working resource file   */
  15. /*      for GEM. Conceptually this could eliminate the need     */
  16. /*      for RSC files (provided the compiler can compile the    */
  17. /*      necessary code.                                         */
  18. /*                                                              */
  19. /*      USAGE:                                                  */
  20. /*              After the appl_init call, call fix_tree with    */
  21. /*      the symbol NUM_TREE as a parameter. That symbol is      */
  22. /*      defined in the .RSH file. After that call all the       */
  23. /*      rsrc_ calls are valid except rsrc_load and rsrc_free.   */
  24. /*      If you want to load a new resource file then call       */
  25. /*      unfix_tree() to remove the effects of fix_tree.         */
  26. /*                                                              */
  27. /*      NOTE: Never call fix_tree twice, all hell will break    */
  28. /*              loose.                                          */
  29. /*                                                              */
  30. /****************************************************************/
  31.  
  32. /****************************************************************/
  33. /*      Modified by Chor-ming Lung              12/23/87        */
  34. /*      for Megamax and Mark Williams C                         */
  35. /*                                                              */
  36. /*      I think this file was written for Alcyon C.             */
  37. /*      The problems that Mark Williams C and Megamax C         */
  38. /*      encounter with this file are :                          */
  39. /* 1.   Some int and long items are actually pointer of         */
  40. /*      something else.                                         */
  41. /* 2.   rs_tedinfo[].te_ptext/te_ptmplt/te_pvalid in .C file    */
  42. /*      generated by RCS are integer index for rs_strings.      */
  43. /*      Actually, their definitions are char pointers. But,     */
  44. /*      rs_tedinfo[k].te_ptext=rs_strings[rs_tedinfo[k].te_ptext*/
  45. /*      is not acceptable.                                      */
  46. /* 3.   rs_object[].ob_spec is a long number in Mark William C. */
  47. /*      It is a char pointer in Megamax C.                      */
  48. /* Note: The offending codes have been commented out            */
  49. /* Note: Mark Williams' C preprocessor defines GEMDOS,M68000    */
  50. /*      That is the way to handle problem 3.                    */
  51. /****************************************************************/
  52.  
  53. /****************************************************************/
  54. /*      Note from Jinfu Chen                      1/23/88       */
  55. /*      Thanks to Lung for fixing the codes.                    */
  56. /*      However, he left out the char pointer typecast  for MMC */
  57. /*      so the text info still didn't work when compiled under  */
  58. /*      MMC. Fix is simple, just change the fix_tree2 to char   */
  59. /*      pointer instead of int                                  */
  60. /****************************************************************/
  61.  
  62. /****************************************************************/
  63. /* INCLUDE FILES                                                */
  64. /****************************************************************/
  65.  
  66. /* original include files for Alcyon C ?
  67. #include "portab.h"
  68. #include "obdefs.h"
  69. #include "define.h"
  70. #include "gemdefs.h"
  71. */
  72.  
  73. #include <portab.h>
  74. #include <obdefs.h>
  75. #include <gemdefs.h>
  76.  
  77. /****************************************************************/
  78. /* RESOURCE DATA                                                */
  79. /****************************************************************/
  80.  
  81. extern  BYTE *rs_strings[];
  82. extern  LONG rs_frstr[];
  83. extern  BITBLK rs_bitblk[];
  84. extern  LONG rs_frimg[];
  85. extern  ICONBLK rs_iconblk[];
  86. extern  TEDINFO rs_tedinfo[];
  87. extern  OBJECT rs_object[];
  88. extern  LONG rs_trindex[];
  89. extern  struct foobar {
  90.         WORD    dummy;
  91.         WORD    *image;
  92.         } rs_imdope[];
  93.  
  94. /****************************************************************/
  95. /* EXTERNALS                                                    */
  96. /****************************************************************/
  97.  
  98. extern WORD     global[];
  99.  
  100. /****************************************************************/
  101. /*      Take the .RSH code from the RCS output and make it a    */
  102. /*      usable set of resource trees.  This code will do the    */
  103. /*      basic items that rsrc_load() would do without requiring */
  104. /*      a file to load.                                         */
  105. /*                                                              */
  106. /* INPUT:                                                       */
  107. /*      num     number of trees in .RSH file (NUM_TREE)         */
  108. /****************************************************************/
  109. /****************************************************************/
  110. /* Note from Lung:                                              */
  111. /*      My RCS can generate .C code but no .RSH code. The file  */
  112. /*      SAMPLE.RSH seems not correct. I use RCS to generate     */
  113. /*      .C file and recompile FIXTRTST.C. It runs flawlessly.   */
  114. /****************************************************************/
  115.  
  116. fix_tree(num)
  117. WORD    num;
  118. {
  119. /*
  120.         LONG *pl;
  121. */
  122.         WORD i,j;
  123.         long fix_tree3();
  124.  
  125.  
  126.         fix_tree1( &global[5], &rs_trindex[0]);
  127. /*      pl = &global[5];
  128.         *pl = &rs_trindex;
  129. */
  130.         for (i=0;i<num;i++){
  131.                 j = rs_trindex[i];      /* get index of top obj in tree */
  132. /*              rs_trindex[i] = &rs_object[j];
  133. */              rs_trindex[i] = fix_tree3(&rs_object[j]);
  134.                 fix_object(i,j,j);      /* fix top object then all rest */
  135.                 fix_level(i,rs_object[j].ob_head,rs_object[j].ob_tail,j);
  136.         }
  137. }
  138.  
  139. /****************************************************************/
  140. /*      This routine will clear the pointer to the resource     */
  141. /*      tree so that GEM doesn't try to free the memory         */
  142. /****************************************************************/
  143. unfix_tree()
  144. {
  145. /*      LONG *pl;
  146.         pl = &global[5];
  147.         *pl = 0L;
  148. */
  149.         fix_tree1(&global[5],0L);
  150. }
  151.  
  152. /****************************************************************/
  153. /*      This routine will cycle across a level in the resource  */
  154. /*      tree and fix each object in that level. After fixing    */
  155. /*      up the object, it will use itself (recursion) to fix    */
  156. /*      any objects on a level below.                           */
  157. /*                                                              */
  158. /* INPUT:                                                       */
  159. /*      tr_x    index in rs_trindex of the tree being done      */
  160. /*              needed by fix_object                            */
  161. /*      h       object number within tree of first item in      */
  162. /*              this level                                      */
  163. /*      t       object number within tree of last item in       */
  164. /*              this level                                      */
  165. /*      to      object number within rs_object of first         */
  166. /*              item in tree                                    */
  167. /****************************************************************/
  168. fix_level(tr_x,h,t,to)
  169. WORD    tr_x,h,t,to;
  170. {
  171.         WORD i,nh,nt;
  172.  
  173.         if(h==-1 && t==-1) return;      /* nobody on this level */
  174.         do {
  175.                 i = to + h;
  176.                 fix_object(tr_x,i,to);  /* fix this object up   */
  177.                 nh = rs_object[i].ob_head;  /* get next head */
  178.                 nt = rs_object[i].ob_tail;  /* and tail indexes */
  179.                 fix_level(tr_x,nh,nt,to);   /* then fix the next level down */
  180.                 h = rs_object[i].ob_next;   /* go to next obj on this level */
  181.         } while(t+to!=i);       /* till we have done the tail item */
  182. }
  183.  
  184. /****************************************************************/
  185. /*      This routine will fix up the pointers in each object    */
  186. /*      and any associated control blocks. It will then use     */
  187. /*      rsrc_obfix to update the pixel information to adjust    */
  188. /*      for the current resolution and display format.          */
  189. /*                                                              */
  190. /* INPUT:                                                       */
  191. /*      tr_x    index in rs_trindex of the tree being done      */
  192. /*              needed by rsrc_obfix                            */
  193. /*      i       object number within rs_object to fixup         */
  194. /*      to      object number within rs_object of tree top      */
  195. /****************************************************************/
  196. fix_object(tr_x,i,to)
  197. WORD    tr_x,i,to;
  198. {
  199.         WORD k;
  200.         LONG tst;
  201.  
  202.         long fix_tree3();
  203.         int fix_tree2();
  204.         char *fix_tree4();
  205.         int lu;
  206.  
  207. /*      tst = rs_object[i].ob_spec; */  /* get current ob_spec value */
  208.         tst = fix_tree3(rs_object[i].ob_spec);  /* get current ob_spec value */
  209.         k = (WORD) tst;
  210.  
  211.         switch(rs_object[i].ob_type){   /* handle things depending on type */
  212.  
  213.         case G_TEXT:
  214.         case G_BOXTEXT:
  215.         case G_FTEXT:
  216.         case G_FBOXTEXT:
  217.                 if (tst!=-1L){
  218. /*                      rs_object[i].ob_spec = &rs_tedinfo[k];
  219.                         rs_tedinfo[k].te_ptext =
  220.                                 rs_strings[rs_tedinfo[k].te_ptext];
  221.                         rs_tedinfo[k].te_ptmplt =
  222.                                 rs_strings[rs_tedinfo[k].te_ptmplt];
  223.                         rs_tedinfo[k].te_pvalid =
  224.                                 rs_strings[rs_tedinfo[k].te_pvalid];
  225. */
  226. #ifdef GEMDOS
  227.                         rs_object[i].ob_spec = fix_tree3(&rs_tedinfo[k]);
  228. #else
  229.                         rs_object[i].ob_spec = fix_tree4(&rs_tedinfo[k]);
  230. #endif
  231.                         lu=fix_tree2(rs_tedinfo[k].te_ptext);
  232.                         rs_tedinfo[k].te_ptext = rs_strings[lu];
  233.                         lu = fix_tree2(rs_tedinfo[k].te_ptmplt);
  234.                         rs_tedinfo[k].te_ptmplt = rs_strings[lu];
  235.                         lu = fix_tree2(rs_tedinfo[k].te_pvalid);
  236.                         rs_tedinfo[k].te_pvalid = rs_strings[lu];
  237.                 }
  238.                 break;
  239.         case G_BUTTON:
  240.         case G_STRING:
  241.         case G_TITLE:
  242.                 if (tst!=-1L) {
  243. /*                      rs_object[i].ob_spec =
  244.                                 rs_strings[k];
  245. */
  246. #ifdef GEMDOS
  247.                         rs_object[i].ob_spec = fix_tree3(rs_strings[k]);
  248. #else
  249.                         rs_object[i].ob_spec = fix_tree4(rs_strings[k]);
  250. #endif
  251.                 }
  252.                 break;
  253.         case G_ICON:
  254.                 if (tst!=-1L) {
  255. /*                      rs_object[i].ob_spec =
  256.                                 &rs_iconblk[k];
  257.                         rs_iconblk[k].ib_pmask=
  258.                                 rs_imdope[rs_iconblk[k].ib_pmask].image;
  259.                         rs_iconblk[k].ib_pdata=
  260.                                 rs_imdope[rs_iconblk[k].ib_pdata].image;
  261.                         rs_iconblk[k].ib_ptext =
  262.                                 rs_strings[rs_iconblk[k].ib_ptext];
  263. */
  264. #ifdef GEMDOS
  265.                         rs_object[i].ob_spec = fix_tree3(&rs_iconblk[k]);
  266. #else
  267.                         rs_object[i].ob_spec = fix_tree4(&rs_iconblk[k]);
  268. #endif
  269.                         lu = fix_tree2(rs_iconblk[k].ib_pmask);
  270.                         rs_iconblk[k].ib_pmask = rs_imdope[lu].image;
  271.                         lu = fix_tree2(rs_iconblk[k].ib_pdata);
  272.                         rs_iconblk[k].ib_pdata = rs_imdope[lu].image;
  273.                         lu = fix_tree2(rs_iconblk[k].ib_ptext);
  274.                         rs_iconblk[k].ib_ptext = rs_strings[lu];
  275.                 }
  276.                 break;
  277. /*      case G_USERDEF:
  278. */              /* user must provide */
  279. /*              break;
  280. */
  281.         case G_IMAGE:
  282.                 if (tst!=-1L) {
  283. /*                      rs_object[i].ob_spec =
  284.                                 &rs_bitblk[k];
  285.                         rs_bitblk[k].bi_pdata=
  286.                                 rs_imdope[rs_bitblk[k].bi_pdata].image;
  287. */
  288. #ifdef GEMDOS
  289.                         rs_object[i].ob_spec = fix_tree3(&rs_bitblk[k]);
  290. #else
  291.                         rs_object[i].ob_spec = fix_tree4(&rs_bitblk[k]);
  292. #endif
  293.                         lu = fix_tree2(rs_bitblk[k].bi_pdata);
  294.                         rs_bitblk[k].bi_pdata = rs_imdope[lu].image;
  295.                 }
  296.                 break;
  297.         case G_BOX:
  298.         case G_IBOX:
  299.         case G_BOXCHAR:
  300.                 break;
  301.         }
  302.         rsrc_obfix(rs_trindex[tr_x],i-to);      /* fix pixel values for rez */
  303. }
  304.  
  305. /****************************************************************/
  306. /*      This routines will fix up the type checking problems    */
  307. /****************************************************************/
  308. fix_tree1(g,r)
  309. long *g, r;
  310. {
  311.         *g = r;
  312. }
  313. #ifdef GEMDOS           /* MWC */
  314. int fix_tree2(r)
  315. int r;
  316. {
  317.         return(r);
  318. }
  319. #else                   /* MMC, use char pointer instead. JC Jan 23, 88 */
  320. char *fix_tree2(r)
  321. char *r;
  322. {
  323.         return(r);
  324. }
  325. #endif
  326. long fix_tree3(a)
  327. long a;
  328. {
  329.         return(a);
  330. }
  331.  
  332. char *fix_tree4(a)
  333. char *a;
  334. {
  335.         return(a);
  336. }
  337.