home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / progem.lzh / apndx13.prf < prev    next >
Encoding:
Text File  |  1987-06-23  |  25.6 KB  |  1,193 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!            Begin Appendix XIII
  18. .!
  19. .!***************************************************************************
  20. .!
  21. .!
  22. .AP XIII Sample Code for Part XVII
  23.             /*** rsconv.h ***/
  24. #define MODE 0      /* TREE */
  25. #define N2F 7      /* OBJECT in TREE #0 */
  26. #define F2N 8      /* OBJECT in TREE #0 */
  27. #define DEF2 15      /* OBJECT in TREE #0 */
  28. #define HELPMODE 21      /* OBJECT in TREE #0 */
  29. #define CONVMODE 22      /* OBJECT in TREE #0 */
  30. #define QUITMODE 23      /* OBJECT in TREE #0 */
  31. #define NODEF 0      /* STRING */
  32. #define DEFYES 18      /* OBJECT in TREE #0 */
  33. #define DEFNO 19      /* OBJECT in TREE #0 */
  34. #define HELP 1      /* TREE */
  35. #define NOMEM 1      /* STRING */
  36. #define DFNYES 20      /* OBJECT in TREE #0 */
  37. #define DEF1 13      /* OBJECT in TREE #0 */
  38. #define RSC1 10      /* OBJECT in TREE #0 */
  39. #define RSC2 12      /* OBJECT in TREE #0 */
  40. #define PROGRESS 2      /* TREE */
  41. #define STRINGS 3      /* TREE */
  42. #define PLINE 2      /* OBJECT in TREE #2 */
  43. #define IMGALIGN 2      /* OBJECT in TREE #3 */
  44. #define RSCREAD 1      /* OBJECT in TREE #3 */
  45. #define BYTESWAP 3      /* OBJECT in TREE #3 */
  46. #define RSCWRITE 4      /* OBJECT in TREE #3 */
  47. #define DEFREAD 5      /* OBJECT in TREE #3 */
  48. #define DEFWRITE 6      /* OBJECT in TREE #3 */
  49. .bp
  50.             /*** rscvmain.c **/
  51. /*------------------------------*/
  52. /*    includes        */
  53. /*------------------------------*/
  54.  
  55. #include "portab.h"                /* portable coding conv    */
  56. #include "machine.h"                /* machine depndnt conv    */
  57. #include "obdefs.h"                /* object definitions    */
  58. #include "gembind.h"                /* gem binding structs    */
  59. #include "osbind.h"                /* BDOS definitions    */
  60. #include "gemdefs.h"
  61. #include "rsconv.h"
  62.  
  63.  
  64. /*------------------------------*/
  65. /*    defines            */
  66. /*------------------------------*/
  67.  
  68. #define    NIL        -1
  69. #define DESK        0
  70. #define    ARROW        0
  71. #define    HOUR_GLASS    2            
  72. #define END_UPDATE    0
  73. #define    BEG_UPDATE    1
  74.  
  75. typedef struct memform
  76.     {
  77.     WORD        *mp;
  78.     WORD        fwp;
  79.     WORD        fh;
  80.     WORD        fww;
  81.     WORD        ff;
  82.     WORD        np;
  83.     WORD        r1;
  84.     WORD        r2;
  85.     WORD        r3;
  86.     } MFDB;
  87.  
  88. /*------------------------------*/
  89. /*    Global            */
  90. /*------------------------------*/
  91. GLOBAL    WORD    gl_apid;
  92.  
  93. GLOBAL WORD    contrl[11];        /* control inputs        */
  94. GLOBAL WORD    intin[80];        /* max string length        */
  95. GLOBAL WORD    ptsin[256];        /* polygon fill points        */
  96. GLOBAL WORD    intout[45];        /* open workstation output    */
  97. GLOBAL WORD    ptsout[12];
  98.  
  99. GLOBAL    WORD    gl_wchar;        /* character width        */
  100. GLOBAL    WORD    gl_hchar;        /* character height        */
  101. GLOBAL    WORD    gl_wbox;        /* box (cell) width        */
  102. GLOBAL    WORD    gl_hbox;        /* box (cell) height        */
  103. GLOBAL    WORD    gem_handle;        /* GEM handle            */
  104. GLOBAL    WORD    vdi_handle;        /* VDI handle            */
  105. GLOBAL    WORD    work_out[57];        /* open virt workstation values    */
  106. GLOBAL    GRECT    scrn_area;        /* scrn area            */
  107. GLOBAL    MFDB    scrn_mfdb;        /* scrn memory def'n for blt    */
  108. GLOBAL    GRECT    full;            /* desktop size            */
  109. .bp
  110. /*------------------------------*/
  111. /*    External        */
  112. /*------------------------------*/
  113.  
  114. EXTERN    WORD    desel_obj();
  115.  
  116. /*------------------------------*/
  117. /*    Local            */
  118. /*------------------------------*/
  119.  
  120. MLOCAL    WORD    native_in = TRUE;    /* TRUE: input .RSC is native    */
  121.                     /* FALSE: input .RSC is foreign */
  122. MLOCAL    WORD    conv_def = TRUE;    /* TRUE: convert .DEF also    */
  123. MLOCAL    WORD    new_dfn = FALSE;    /* TRUE: use new symbol fmt    */
  124. MLOCAL    BYTE    old_rsc[4] = "RSC";    /* new resource file extent    */
  125. MLOCAL    BYTE    new_rsc[4] = "RS2";    /* new resource file extent    */
  126. MLOCAL    BYTE    old_def[4] = "DEF";    /* new definition file extend   */
  127. MLOCAL    BYTE    new_def[4] = "DF2";    /* new definition file extend   */
  128. MLOCAL    BYTE    r_file[81];        /* resource file name         */
  129. MLOCAL    BYTE    d_file[81];        /* definition file name     */
  130. MLOCAL    BYTE    r2_file[81];        /* output resource name        */
  131. MLOCAL    BYTE    d2_file[81];        /* output definition name    */
  132. MLOCAL    WORD    r_hndl = -1;        /* resource file handle     */
  133. MLOCAL    WORD    d_hndl = -1;        /* definition file handle     */
  134. MLOCAL    WORD    r2_hndl = -1;        /* output resource handle    */
  135. MLOCAL    WORD    d2_hndl = -1;        /* output definition handle    */
  136.  
  137. MLOCAL    LONG    f_err;            /* file error            */
  138. MLOCAL    BYTE    *head;            /* location of buffer        */
  139. MLOCAL    LONG    buff_size;        /* size of buffer        */
  140. MLOCAL    BYTE    buff[20];        /* def file work area        */
  141. MLOCAL    UWORD    img_offset, addr;    /* for image fixup        */
  142. MLOCAL    WORD    img_odd;        /* image fixup needed?        */
  143. MLOCAL    GRECT    prog_rect;        /* rectangle for prog indicator */
  144. .bp
  145. /*------------------------------*/
  146. /*    swap_bytes         */
  147. /*------------------------------*/
  148.     VOID
  149. swap_bytes(where, len)
  150.     BYTE    *where;
  151.     WORD    len;
  152.     {
  153.     BYTE    swap;
  154.  
  155.     for (; len > 0; len -= 2)
  156.         {
  157.         swap = *where;
  158.         *where = *(where + 1);
  159.         *(where + 1) = swap;
  160.         where += 2;
  161.         }
  162.     }
  163.  
  164. /*------------------------------*/
  165. /*    swap_words         */
  166. /*------------------------------*/
  167.     VOID
  168. swap_words(where, len)
  169.     WORD    *where;
  170.     WORD    len;
  171.     {
  172.     UWORD    swap;
  173.  
  174.     for (; len > 0; len -= 4)
  175.         {
  176.         swap = *where;
  177.         *where = *(where + 1);
  178.         *(where + 1) = swap;
  179.         where += 2;
  180.         }
  181.     }
  182. .bp
  183. /*------------------------------*/
  184. /*    swap_images         */
  185. /*------------------------------*/
  186.     VOID
  187. swap_images()
  188.     {
  189.     BITBLK    *where;
  190.     ICONBLK *where2;
  191.     BYTE    *taddr;
  192.     WORD    num;
  193.     WORD    wb, hl;
  194.  
  195.     where = (BITBLK *) (head + ((RSHDR *) head)->rsh_bitblk);
  196.     num = ((RSHDR *) head)->rsh_nbb;
  197.     for (; num--; where++)
  198.         {
  199.         taddr = where->bi_pdata;
  200.         wb = where->bi_wb;
  201.         hl = where->bi_hl;
  202.         if ((LONG) taddr != -1L)
  203.             {
  204.             if (img_odd)
  205.                 where->bi_pdata = ++taddr;
  206.             swap_bytes(head + taddr, wb * hl);
  207.             }
  208.         }
  209.  
  210.     where2 = (ICONBLK *) (head + ((RSHDR *) head)->rsh_iconblk);
  211.     num = ((RSHDR *) head)->rsh_nib;
  212.     for (; num--; where2++)
  213.         {
  214.         wb = (where2->ib_wicon + 7) >> 3;
  215.         hl = where2->ib_hicon;
  216.         taddr = where2->ib_pdata;
  217.         if ((LONG) taddr != -1L)
  218.             {
  219.             if (img_odd)
  220.                 where2->ib_pdata = ++taddr;
  221.             swap_bytes(head + taddr, wb * hl);
  222.             }
  223.         taddr = where2->ib_pmask;
  224.         if ((LONG) taddr != -1L)
  225.             {
  226.             if (img_odd)
  227.                 where2->ib_pmask = ++taddr;
  228.             swap_bytes(head + taddr, wb * hl);
  229.             }
  230.         }
  231.     }
  232. .bp
  233. /*------------------------------*/
  234. /*    swap_trees         */
  235. /*------------------------------*/
  236.     VOID
  237. swap_trees()
  238.     {
  239.     BYTE    *where;
  240.     WORD    size;
  241.  
  242.     where = head + ((RSHDR *) head)->rsh_trindex;
  243.     size = ((RSHDR *) head)->rsh_ntree * sizeof(LONG);
  244.     swap_bytes(where, size);
  245.     swap_words((WORD *) where, size);
  246.     }
  247.  
  248. /*------------------------------*/
  249. /*    swap_objs         */
  250. /*------------------------------*/
  251.     VOID
  252. swap_objs()
  253.     {
  254.     OBJECT    *where;
  255.     WORD    num;
  256.  
  257.     where = (OBJECT *) (head + ((RSHDR *) head)->rsh_object);
  258.     num = ((RSHDR *) head)->rsh_nobs;
  259.     swap_bytes((BYTE *) where, num * sizeof(OBJECT));
  260.     for (; num--; where++)
  261.         swap_words((WORD *) &where->ob_spec, sizeof(LONG));
  262.     }
  263. .bp
  264. /*------------------------------*/
  265. /*    swap_teds         */
  266. /*------------------------------*/
  267.     VOID
  268. swap_teds()
  269.     {
  270.     TEDINFO    *where;
  271.     WORD    num;
  272.  
  273.     where = (TEDINFO *) (head + ((RSHDR *) head)->rsh_tedinfo);
  274.     num = ((RSHDR *) head)->rsh_nted;
  275.     swap_bytes((BYTE *) where, num * sizeof(TEDINFO));
  276.     for (; num--; where++)
  277.         {
  278.         swap_words((WORD *) &where->te_ptext, sizeof(LONG));
  279.         swap_words((WORD *) &where->te_ptmplt, sizeof(LONG));
  280.         swap_words((WORD *) &where->te_pvalid, sizeof(LONG));
  281.         }
  282.     }
  283.  
  284. /*------------------------------*/
  285. /*    swap_ibs         */
  286. /*------------------------------*/
  287.     VOID
  288. swap_ibs()
  289.     {
  290.     ICONBLK    *where;
  291.     WORD    num;
  292.  
  293.     where = (ICONBLK *) (head + ((RSHDR *) head)->rsh_iconblk);
  294.     num = ((RSHDR *) head)->rsh_nib;
  295.     swap_bytes((BYTE *) where, num * sizeof(ICONBLK));
  296.     for (; num--; where++)
  297.         {
  298.         swap_words((WORD *) &where->ib_pdata, sizeof(LONG));
  299.         swap_words((WORD *) &where->ib_pmask, sizeof(LONG));
  300.         swap_words((WORD *) &where->ib_ptext, sizeof(LONG));
  301.         }
  302.     }
  303. .bp
  304. /*------------------------------*/
  305. /*    swap_bbs         */
  306. /*------------------------------*/
  307.     VOID
  308. swap_bbs()
  309.     {
  310.     BITBLK    *where;
  311.     WORD    num;
  312.  
  313.     where = (BITBLK *) (head + ((RSHDR *) head)->rsh_bitblk);
  314.     num = ((RSHDR *) head)->rsh_nbb;
  315.     swap_bytes((BYTE *) where, num * sizeof(BITBLK));
  316.     for (; num--; where++)
  317.         swap_words((WORD *) &where->bi_pdata, sizeof(LONG));
  318.     }
  319.  
  320. /*------------------------------*/
  321. /*    swap_fstr         */
  322. /*------------------------------*/
  323.     VOID
  324. swap_fstr()
  325.     {
  326.     BYTE    *where;
  327.     WORD    size;
  328.  
  329.     where = head + ((RSHDR *) head)->rsh_frstr;
  330.     size = ((RSHDR *) head)->rsh_nstring * sizeof(LONG);
  331.     swap_bytes(where, size);
  332.     swap_words((WORD *) where, size);
  333.     }
  334.  
  335. /*------------------------------*/
  336. /*    swap_fimg         */
  337. /*------------------------------*/
  338.     VOID
  339. swap_fimg()
  340.     {
  341.     LONG    where;
  342.     WORD    size;
  343.  
  344.     where = head + ((RSHDR *) head)->rsh_frimg;
  345.     size = ((RSHDR *) head)->rsh_nimages * sizeof(LONG);
  346.     swap_bytes(where, size);
  347.     swap_words((WORD *) where, size);
  348.     }
  349. .bp
  350. /*------------------------------*/
  351. /*    close_files         */
  352. /*------------------------------*/
  353.     VOID
  354. close_files()
  355.     {
  356.     if (r_hndl != -1)
  357.         Fclose(r_hndl);
  358.     if (d_hndl != -1)
  359.         Fclose(d_hndl);
  360.     if (r2_hndl != -1)
  361.         Fclose(r2_hndl);
  362.     if (d2_hndl != -1)
  363.         Fclose(d2_hndl);
  364.     r_hndl = d_hndl = r2_hndl = d2_hndl = -1; 
  365.     }
  366. .bp
  367. /*------------------------------*/
  368. /*    do_conv         */
  369. /*------------------------------*/
  370.     WORD
  371. do_conv()
  372.     {
  373.     BYTE    *str; 
  374.     LONG    size;
  375.     WORD    reply, nsym;
  376.  
  377.     r_file[0] = '\0';
  378.  
  379.     if (!get_file(old_rsc, r_file))
  380.         return;
  381.     if ((r_hndl = open_file(r_file)) == -1)
  382.         return;
  383.     if (conv_def)
  384.         {
  385.         new_ext(r_file, d_file, old_def);
  386.         FOREVER {
  387.             d_hndl = (WORD) Fopen(d_file, 0);
  388.             if (d_hndl >= 0)
  389.                 break;
  390.             rsrc_gaddr(R_STRING, NODEF, &str);
  391.             reply = form_alert(1, str);
  392.             if (reply == 3)
  393.                 {
  394.                 close_files();
  395.                 return;
  396.                 }
  397.             if (reply == 1)
  398.                 {
  399.                 conv_def = FALSE;
  400.                 break;
  401.                 }
  402.                         /* if (reply == 2) */
  403.             if (!get_file(old_def, d_file))
  404.                 break;
  405.             }
  406.         }
  407.  
  408.     graf_mouse(HOUR_GLASS, 0x0L);
  409.     beg_prog(&prog_rect);
  410.     set_prog(RSCREAD);
  411.  
  412.     f_err = Fread(r_hndl, (LONG) sizeof(RSHDR), head);
  413.     if ( f_err < 0)
  414.         {
  415.         dos_error((WORD) f_err);
  416.         return;
  417.         }
  418.  
  419.     if (!native_in)
  420.         swap_bytes(head, sizeof(RSHDR));
  421.  
  422.     size = ((RSHDR *) head)->rsh_rssize;
  423.  
  424.     if (buff_size < size)
  425.         {
  426.         graf_mouse(ARROW, 0x0L);        /* Before alert */
  427.         rsrc_gaddr(R_STRING, NOMEM, &str);
  428.         form_alert(1, str);
  429.         close_files();
  430.         return;
  431.         }
  432.  
  433.     f_err = Fread(r_hndl, size - sizeof(RSHDR), head + sizeof(RSHDR));
  434.     if ( f_err < 0)
  435.         {
  436.         dos_error((WORD) f_err);
  437.         return;
  438.         }
  439.  
  440.     img_offset = ((RSHDR *) head)->rsh_imdata;
  441.     if ( (img_odd = img_offset & 0x0001) )
  442.         {
  443.         set_prog(IMGALIGN);
  444.         ((RSHDR *) head)->rsh_rssize = img_offset + 1;
  445.         for (addr = ((RSHDR *) head)->rsh_frstr; --addr > img_offset; )
  446.             *(head + addr) = *(head + addr - 1);
  447.         }
  448.  
  449.     set_prog(BYTESWAP);
  450.     if (native_in)
  451.         swap_images();
  452.  
  453.     swap_trees();
  454.     swap_objs();
  455.     swap_teds();
  456.     swap_ibs();
  457.     swap_bbs();
  458.     swap_fstr();
  459.     swap_fimg();
  460.  
  461.     if (native_in)
  462.         swap_bytes(head, sizeof(RSHDR));
  463.     else
  464.         swap_images();
  465.  
  466.     set_prog(RSCWRITE);
  467.     new_ext(r_file, r2_file, new_rsc);
  468.     if ( (r2_hndl = create_file(r2_file)) == -1)
  469.         {
  470.         close_files();
  471.         return;
  472.         }
  473.     graf_mouse(HOUR_GLASS, 0x0L);        /* Create_file could reset */
  474.  
  475.     f_err = Fwrite(r2_hndl, size, head);
  476.     if ( f_err < 0)
  477.         {
  478.         dos_error((WORD) f_err);
  479.         return;
  480.         }
  481.  
  482.     if (!conv_def)
  483.         {
  484.         close_files();
  485.         end_prog(&prog_rect);
  486.         return;
  487.         }
  488.  
  489.     set_prog(DEFREAD);
  490.     new_ext(r_file, d2_file, new_def);
  491.     if ( (d2_hndl = create_file(d2_file)) == -1)
  492.         {
  493.         close_files();
  494.         return;
  495.         }
  496.  
  497.     f_err = Fread(d_hndl, (LONG) sizeof(WORD), &nsym);
  498.     if ( f_err < 0)
  499.         {
  500.         dos_error((WORD) f_err);
  501.         return;
  502.         }
  503.  
  504.  
  505.     set_prog(BYTESWAP);
  506.     reply = nsym;
  507.     swap_bytes(&reply, 2);
  508.  
  509.     f_err = Fwrite(d2_hndl, (LONG) sizeof(WORD), new_dfn? &nsym: &reply);
  510.     if ( f_err < 0)
  511.         {
  512.         dos_error((WORD) f_err);
  513.         return;
  514.         }
  515.  
  516.     if (!native_in || new_dfn)
  517.         nsym = reply;
  518.  
  519.     for (; nsym--; )
  520.         {
  521.         if (!new_dfn)            /* Spare words only if */
  522.                         /* using old format    */
  523.         if (!native_in)
  524.             {            /* insert spare word */
  525.             reply = 0;
  526.             f_err = Fwrite(d2_hndl, (LONG) sizeof(WORD), &reply);
  527.             if ( f_err < 0)
  528.                 {
  529.                 dos_error((WORD) f_err);
  530.                 return;
  531.                 }
  532.             }
  533.         else
  534.             {            /* delete extra word */ 
  535.             f_err = Fread(d_hndl, (LONG) sizeof(WORD), buff);
  536.             if ( f_err < 0)
  537.                 {
  538.                 dos_error((WORD) f_err);
  539.                 return;
  540.                 }
  541.             }
  542.  
  543.         f_err = Fread(d_hndl, (LONG) sizeof(WORD), buff);
  544.         if ( f_err < 0)
  545.             {
  546.             dos_error((WORD) f_err);
  547.             return;
  548.             }
  549.  
  550.         if (!new_dfn)            /* Just copy for new fmt */
  551.             swap_bytes(buff, 2);
  552.  
  553.         f_err = Fwrite(d2_hndl, (LONG) sizeof(WORD), buff);
  554.         if ( f_err < 0)
  555.             {
  556.             dos_error((WORD) f_err);
  557.             return;
  558.             }
  559.         f_err = Fread(d_hndl, (LONG) (sizeof(WORD) + 10), buff);
  560.         if ( f_err < 0)
  561.             {
  562.             dos_error((WORD) f_err);
  563.             return;
  564.             }
  565.  
  566.         if (!new_dfn)
  567.             swap_bytes(buff, 2);    /* only swap value */
  568.  
  569.         f_err = Fwrite(d2_hndl, (LONG) (sizeof(WORD) + 10), buff);
  570.         if ( f_err < 0)
  571.             {
  572.             dos_error((WORD) f_err);
  573.             return;
  574.             }
  575.         }
  576.  
  577.     set_prog(DEFWRITE);
  578.     close_files();
  579.     end_prog(&prog_rect);
  580.     }
  581. .bp
  582. /*------------------------------*/
  583. /*    do_help         */
  584. /*------------------------------*/
  585.     VOID
  586. do_help()
  587.     {
  588.     OBJECT    *tree;
  589.     WORD    obj;
  590.  
  591.     rsrc_gaddr(R_TREE, HELP, &tree);
  592.     obj = hndl_dial(tree, 0, 0, 0, 0, 0);
  593.     desel_obj(tree, obj);
  594.     }
  595.  
  596. /*------------------------------*/
  597. /*    do_mode         */
  598. /*------------------------------*/
  599.     WORD
  600. do_mode()
  601.     {
  602.     OBJECT    *tree;
  603.     WORD    obj;
  604.     WORD    xdial, ydial, wdial, hdial;
  605.  
  606.     rsrc_gaddr(R_TREE, MODE, &tree);
  607.  
  608.     sel_obj(tree, native_in? N2F: F2N);
  609.     if (!conv_def)
  610.         sel_obj(tree, DEFNO);
  611.     else if (!new_dfn)
  612.         sel_obj(tree, DEFYES);
  613.     else
  614.         sel_obj(tree, DFNYES);
  615.     set_text(tree, RSC1, old_rsc, 4);
  616.     set_text(tree, RSC2, new_rsc, 4);
  617.     set_text(tree, DEF1, old_def, 4);
  618.     set_text(tree, DEF2, new_def, 4);
  619.  
  620.     form_center(tree, &xdial, &ydial, &wdial, &hdial);
  621.     form_dial(0, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  622.     form_dial(1, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  623.     objc_draw(tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial);
  624.  
  625.     while (TRUE)
  626.         {
  627.         obj = form_do(tree, 0) & 0x7FFF;
  628.         if (obj == DEFYES)
  629.             {
  630.             if (strcmp(old_def, "DFN") == 0)
  631.                 {
  632.                 strcpy(old_def, "DEF");
  633.                 disp_obj(tree, DEF1);
  634.                 }
  635.             }
  636.         else if (obj == DFNYES)
  637.             {
  638.             if (strcmp(old_def, "DEF") == 0)
  639.                 {
  640.                 strcpy(old_def, "DFN");
  641.                 disp_obj(tree, DEF1);
  642.                 }
  643.             }
  644.         else
  645.             break;
  646.         }
  647.  
  648.     form_dial(2, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  649.     form_dial(3, 0, 0, 0, 0, xdial, ydial, wdial, hdial);
  650.  
  651.     native_in = selected(tree, N2F);
  652.     conv_def = !selected(tree, DEFNO);
  653.     new_dfn = selected(tree, DFNYES);
  654.  
  655.     map_tree(tree, ROOT, NIL, desel_obj);
  656.     return (obj);
  657.     }
  658. .bp
  659. /*------------------------------*/
  660. /*    rscv_run        */
  661. /*------------------------------*/
  662.     WORD
  663. rscv_run()
  664.     {
  665.     WORD    obj;
  666.  
  667.     FOREVER {
  668.         obj = do_mode();
  669.         if (obj == HELPMODE)
  670.             do_help();
  671.         else if (obj == CONVMODE)
  672.             {
  673.             do_conv();
  674.             graf_mouse(ARROW, 0x0L);
  675.             }
  676.         else 
  677.             break;
  678.         }
  679.     }
  680.  
  681. /*------------------------------*/
  682. /*    rscv_term        */
  683. /*------------------------------*/
  684.     VOID
  685. rscv_term(term_type)
  686.     WORD    term_type;
  687.     {
  688.     switch (term_type)    /* NOTE: all cases fall through        */
  689.         {
  690.         case (0 /* normal termination */):
  691.             Mfree(head);
  692.         case (2):
  693.             v_clsvwk( vdi_handle );
  694.         case (3):
  695.             rsrc_free();
  696.         case (4):
  697.             if (term_type)
  698.                 wind_update(END_UPDATE);
  699.             appl_exit();
  700.         case (5):
  701.             break;
  702.         }
  703.     }
  704. .bp
  705. /*------------------------------*/
  706. /*    rscv_init        */
  707. /*------------------------------*/
  708.     WORD
  709. rscv_init()
  710.     {
  711.     WORD    i;
  712.     WORD    work_in[11];
  713.     LONG    tree;
  714.  
  715.     appl_init();                /* initialize libraries    */
  716.     if (gl_apid == -1)
  717.         return (5);            /* No handles ! */
  718.     graf_mouse(HOUR_GLASS, 0x0L);
  719.     wind_update(BEG_UPDATE);
  720.     if (!rsrc_load( "RSCONV.RSC" ))
  721.         {
  722.         graf_mouse(ARROW, 0x0L);
  723.         form_alert(1,
  724.         "[3][Fatal Error !|RSCONV.RSC|File Not Found][ Abort ]" );
  725.         return(4);    /* Can't find resource */
  726.         }
  727.  
  728.     for (i=0; i<10; i++)
  729.         {
  730.         work_in[i]=1;
  731.         }
  732.     work_in[10]=2;
  733.     gem_handle = graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  734.     vdi_handle = gem_handle;
  735.     v_opnvwk(work_in,&vdi_handle,work_out);    /* open virtual work stn*/
  736.     if (vdi_handle == 0)
  737.         return (3);
  738.  
  739.     vqt_attributes (vdi_handle, work_in);
  740.  
  741.     scrn_area.g_x = 0;
  742.     scrn_area.g_y = 0;
  743.     scrn_area.g_w = work_out[0] + 1;
  744.     scrn_area.g_h = work_out[1] + 1;
  745.  
  746.     scrn_mfdb.np = work_out[4];
  747.     scrn_mfdb.mp = 0x0L;
  748.  
  749.     wind_get(DESK, WF_WXYWH, &full.g_x, &full.g_y, &full.g_w, &full.g_h);
  750.  
  751.     vst_height(vdi_handle, work_in[7],
  752.         &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox);
  753.  
  754.     buff_size = Malloc(-1L);
  755.     head = Malloc(buff_size - 4000L);
  756.  
  757.     graf_mouse(ARROW,0x0L);
  758.     wind_update(END_UPDATE);
  759.     return(0);
  760.     }
  761. .bp
  762. /*------------------------------*/
  763. /*    main            */
  764. /*------------------------------*/
  765. main()
  766.     {
  767.     WORD    rscv_code;
  768.  
  769.     if ( !(rscv_code = rscv_init()) )    /* initialization    */
  770.         rscv_run();
  771.     rscv_term(rscv_code);            /* termination        */
  772.     }
  773. .bp
  774.             /*** rscvfile.c ***/
  775. /*------------------------------*/
  776. /*    includes        */
  777. /*------------------------------*/
  778.  
  779. #include "portab.h"                /* portable coding conv    */
  780. #include "machine.h"                /* machine depndnt conv    */
  781. #include "osbind.h"                /* BDOS defintions    */
  782. #include "gemdefs.h"
  783. .bp
  784. /*------------------------------*/
  785. /*    open_file         */
  786. /*------------------------------*/
  787.     WORD
  788. open_file(file_name)
  789.     BYTE    *file_name;
  790.     {
  791.     LONG    dos_hndl;
  792.  
  793.     FOREVER
  794.         {
  795.         dos_hndl = Fopen(file_name, 0);
  796.         if (dos_hndl >= 0)
  797.             return ((WORD) dos_hndl);
  798.         if ( !dos_error((WORD) dos_hndl) )
  799.             return (-1);
  800.         }
  801.  
  802.     return (-1);        /* Appease lint */
  803.     }
  804. .bp
  805. /*------------------------------*/
  806. /*    create_file         */
  807. /*------------------------------*/
  808.     WORD
  809. create_file(file_name)
  810.     BYTE    *file_name;
  811.     {
  812.     LONG    dos_hndl;
  813.  
  814.     FOREVER
  815.         {
  816.         dos_hndl = Fcreate(file_name, 0);
  817.         if (dos_hndl >= 0)
  818.             return ((WORD) dos_hndl);
  819.         if ( !dos_error((WORD) dos_hndl) )
  820.             return (-1);
  821.         }
  822.  
  823.     return (-1);        /* Appease lint */
  824.     }
  825.  
  826. /*------------------------------*/
  827. /*    dos_error         */
  828. /*------------------------------*/
  829.     WORD
  830. dos_error(tos_err)
  831.     WORD    tos_err;
  832.     {
  833.     WORD    f_ret;
  834.  
  835.     graf_mouse(ARROW, 0x0L);
  836.     if (tos_err > -50)
  837.         {
  838.         tos_err += 31;
  839.         tos_err = -tos_err;
  840.         }
  841.     f_ret = form_error(tos_err);
  842.     close_files();
  843.     return (f_ret);
  844.     }
  845. .bp
  846. /*------------------------------*/
  847. /*    get_file         */
  848. /*------------------------------*/
  849.     WORD
  850. get_file(extnt, got_file)
  851.     BYTE    *extnt, *got_file;
  852.     {
  853.     WORD    butn, ii;
  854.     BYTE    tmp_path[64], tmp_name[13];
  855.  
  856.     tmp_name[0] = '\0';
  857.     tmp_path[0] = '\0';
  858.  
  859.     if (*got_file)
  860.         parse_fname(got_file, tmp_path, tmp_name, extnt);
  861.     if (!tmp_path[0])
  862.         get_path(&tmp_path[0], extnt);
  863.  
  864.     fsel_input(tmp_path, tmp_name, &butn);
  865.     if (butn)
  866.         {
  867.         strcpy(got_file, tmp_path);
  868.         for (ii = 0; got_file[ii] && got_file[ii] != '*'; ii++);
  869.         got_file[ii - 1] = '\0';
  870.         strcat (got_file, "\\");
  871.         strcat(got_file, tmp_name);
  872.         return (TRUE);
  873.         }
  874.     else
  875.         return (FALSE);
  876.     }
  877.  
  878. /*------------------------------*/
  879. /*    parse_fname         */
  880. /*------------------------------*/
  881.     VOID
  882. parse_fname(full, path, name, extnt)
  883.     BYTE    *full, *path, *name, *extnt;
  884.     {
  885.     WORD    i, j;
  886.     BYTE    *s, *d;
  887.  
  888.     for (i = strlen(full); i--; )        /* scan for end of path */
  889.         if (full[i] == '\\' || full[i] == ':')
  890.             break;
  891.     if (i == -1)
  892.         strcpy(name, full);        /* "Naked" file name */
  893.     else
  894.         {
  895.         strcpy(name, &full[i+1]);
  896.         for (s = full, d = path, j = 0; j++ < i + 1;
  897.             *d++ = *s++);
  898.         strcpy(&path[i+1], "*.");
  899.         strcat(path, extnt);
  900.         }
  901.     }
  902. .bp
  903. /*------------------------------*/
  904. /*    get_path         */
  905. /*------------------------------*/
  906.     VOID
  907. get_path(tmp_path, spec)
  908.     BYTE    *tmp_path, *spec;
  909.     {
  910.     WORD    cur_drv;
  911.  
  912.     cur_drv = Dgetdrv();
  913.     tmp_path[0] = cur_drv + 'A';
  914.     tmp_path[1] = ':';
  915.     Dgetpath(&tmp_path[2], 0);
  916.     if (strlen(tmp_path) > 3)
  917.         strcat(tmp_path, "\\");
  918.     else
  919.         tmp_path[2] = '\0';
  920.     strcat(tmp_path, "*.");
  921.     strcat(tmp_path, spec);
  922.     }
  923.  
  924. /*------------------------------*/
  925. /*    new_ext         */
  926. /*------------------------------*/
  927.     VOID
  928. new_ext(o_fname, n_fname, ext)
  929.     BYTE    *o_fname, *n_fname, *ext;
  930.     {
  931.     WORD    ii, jj;
  932.  
  933.     strcpy(n_fname, o_fname);
  934.     for (ii = (jj = strlen(n_fname)) - 1; ii && n_fname[ii] != '.'; ii--);
  935.     if (!ii)
  936.         n_fname[ii = jj] = '.';
  937.     strcpy(&n_fname[++ii], ext);
  938.     }
  939. .bp
  940.             /*** rscvlib.c ***/
  941. /*------------------------------*/
  942. /*    includes        */
  943. /*------------------------------*/
  944.  
  945. #include "portab.h"                /* portable coding conv    */
  946. #include "machine.h"                /* machine depndnt conv    */
  947. #include "obdefs.h"                /* object definitions    */
  948. #include "gembind.h"                /* gem binding structs    */
  949. #include "taddr.h"
  950. #include "rsconv.h"
  951.  
  952.  
  953. /*------------------------------*/
  954. /*    defines            */
  955. /*------------------------------*/
  956.  
  957. #define    NIL        -1
  958. #define DESK        0
  959. #define    ARROW        0
  960. #define    HOUR_GLASS    2            
  961. #define END_UPDATE    0
  962. #define    BEG_UPDATE    1
  963.  
  964. #define TE_PTEXT(x)    (x)
  965. #define TE_TXTLEN(x)     ((x) + 24)
  966. .bp
  967. /*------------------------------*/
  968. /*    do_obj            */
  969. /*------------------------------*/
  970.     VOID
  971. do_obj(tree, which, bit)    /* set specified bit in object state    */
  972.     OBJECT    *tree;
  973.     WORD    which, bit;
  974.     {
  975.     (tree + which)->ob_state |= bit;
  976.     }
  977.  
  978.  
  979. /*------------------------------*/
  980. /*    undo_obj        */
  981. /*------------------------------*/
  982.     VOID
  983. undo_obj(tree, which, bit)    /* clear specified bit in object state    */
  984.     OBJECT    *tree;
  985.     WORD    which, bit;
  986.     {
  987.     (tree + which)->ob_state &= (~bit);
  988.     }
  989.  
  990. /*------------------------------*/
  991. /*    sel_obj            */
  992. /*------------------------------*/
  993.     WORD
  994. sel_obj(tree, which)
  995.     OBJECT    *tree;
  996.     WORD    which;
  997.     {
  998.     do_obj(tree, which, SELECTED);
  999.     return (TRUE);
  1000.     }
  1001. .bp
  1002. /*------------------------------*/
  1003. /*    desel_obj        */
  1004. /*------------------------------*/
  1005.     WORD
  1006. desel_obj(tree, which)
  1007.     OBJECT    *tree;
  1008.     WORD    which;
  1009.     {
  1010.     undo_obj(tree, which, SELECTED);
  1011.     return (TRUE);
  1012.     }
  1013.  
  1014. /*------------------------------*/
  1015. /*    disab_obj        */
  1016. /*------------------------------*/
  1017.     WORD
  1018. disab_obj(tree, obj)
  1019.     OBJECT    *tree;
  1020.     WORD    obj;
  1021.     {
  1022.     undo_obj(tree, obj, DISABLED);
  1023.     return (TRUE);
  1024.     }
  1025.  
  1026. /*------------------------------*/
  1027. /*    objc_xywh        */
  1028. /*------------------------------*/
  1029.     VOID
  1030. objc_xywh(tree, obj, p)
  1031.     OBJECT    *tree;
  1032.     WORD    obj;
  1033.     GRECT    *p;
  1034.     {
  1035.     objc_offset(tree, obj, &p->g_x, &p->g_y);
  1036.     p->g_w = (tree + obj)->ob_width;
  1037.     p->g_h = (tree + obj)->ob_height;
  1038.     }
  1039. .bp
  1040. /*------------------------------*/
  1041. /*    disp_obj        */
  1042. /*------------------------------*/
  1043.     VOID
  1044. disp_obj(tree, obj)
  1045.     OBJECT    *tree;
  1046.     WORD    obj;
  1047.     {
  1048.     GRECT    box;
  1049.  
  1050.     objc_xywh(tree, obj, &box);
  1051.     objc_draw(tree, ROOT, MAX_DEPTH, box.g_x, box.g_y,
  1052.         box.g_w, box.g_h);
  1053.     }
  1054.  
  1055. /*------------------------------*/
  1056. /*    selected        */
  1057. /*------------------------------*/
  1058.     WORD
  1059. selected(tree, obj)
  1060.     OBJECT    *tree;
  1061.     WORD    obj;
  1062.     {
  1063.     return (SELECTED & (tree + obj)->ob_state)? TRUE: FALSE;
  1064.     }
  1065.  
  1066. /*------------------------------*/
  1067. /*    map_tree        */
  1068. /*------------------------------*/
  1069.         VOID
  1070. map_tree(tree, this, last, routine)
  1071.         OBJECT          *tree;
  1072.         WORD            this, last;
  1073.         WORD            (*routine)();
  1074.         {
  1075.         WORD            tmp1;
  1076.  
  1077.         tmp1 = this;            /* Initialize to impossible value: */
  1078.                                 /* TAIL won't point to self!       */
  1079.                                 /* Look until final node, or off   */
  1080.                                 /* the end of tree                 */ 
  1081.         while (this != last && this != NIL)
  1082.                                 /* Did we 'pop' into this node     */
  1083.                                 /* for the second time?            */
  1084.                 if ((tree + this)->ob_tail != tmp1)
  1085.                         {
  1086.                         tmp1 = this;    /* This is a new node       */
  1087.                         this = NIL;
  1088.                                         /* Apply operation, testing  */
  1089.                                         /* for rejection of sub-tree */
  1090.                         if ((*routine)(tree, tmp1))
  1091.                                 this = (tree + tmp1)->ob_head;
  1092.                                         /* Subtree path not taken,   */
  1093.                                         /* so traverse right         */ 
  1094.                         if (this == NIL)
  1095.                                 this = (tree + tmp1)->ob_next;
  1096.                         }
  1097.                 else                    /* Revisiting parent:        */
  1098.                                         /* No operation, move right  */
  1099.                         {
  1100.                         tmp1 = this;
  1101.                         this = (tree + tmp1)->ob_next;
  1102.                         }
  1103.         }
  1104. .bp
  1105. /*------------------------------*/
  1106. /*    hndl_dial        */
  1107. /*------------------------------*/
  1108.     VOID
  1109. hndl_dial(tree, def, x, y, w, h)
  1110.     OBJECT    *tree;
  1111.     WORD    def;
  1112.     WORD    x, y, w, h;
  1113.     {
  1114.     WORD    xdial, ydial, wdial, hdial, exitobj;
  1115.     UWORD    xtype;
  1116.  
  1117.     form_center(tree, &xdial, &ydial, &wdial, &hdial);
  1118.     form_dial(0, x, y, w, h, xdial, ydial, wdial, hdial);
  1119.     form_dial(1, x, y, w, h, xdial, ydial, wdial, hdial);
  1120.     objc_draw(tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial);
  1121.     exitobj = form_do(tree, def) & 0x7FFF;
  1122.     form_dial(2, x, y, w, h, xdial, ydial, wdial, hdial);
  1123.     form_dial(3, x, y, w, h, xdial, ydial, wdial, hdial);
  1124.     return (exitobj);
  1125.     }
  1126.  
  1127. /*------------------------------*/
  1128. /*    set_text         */
  1129. /*------------------------------*/
  1130.     VOID
  1131. set_text(tree, obj, str, len)
  1132.     OBJECT    *tree;
  1133.     BYTE    *str;
  1134.     WORD    obj, len;
  1135.     {
  1136.     TEDINFO    *obspec;
  1137.  
  1138.     obspec = (TEDINFO *) (tree + obj)->ob_spec;
  1139.     obspec->te_ptext = str;
  1140.     obspec->te_txtlen = len;
  1141.     }
  1142. .bp
  1143. /*------------------------------*/
  1144. /*    beg_prog         */
  1145. /*------------------------------*/
  1146.     VOID
  1147. beg_prog(rect)
  1148.     GRECT    *rect;
  1149.     {
  1150.     OBJECT    *tree;
  1151.     WORD    xdial, ydial, wdial, hdial;
  1152.  
  1153.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  1154.     form_center(tree, &rect->g_x, &rect->g_y, &rect->g_w, &rect->g_h);
  1155.     form_dial(0, 0, 0, 0, 0, rect->g_x, rect->g_y, 
  1156.         rect->g_w, rect->g_h);
  1157.     objc_draw(tree, ROOT, MAX_DEPTH, rect->g_x, rect->g_y, 
  1158.         rect->g_w, rect->g_h);
  1159.     }
  1160.  
  1161. /*------------------------------*/
  1162. /*    end_prog         */
  1163. /*------------------------------*/
  1164.     VOID
  1165. end_prog(rect)
  1166.     GRECT    *rect;
  1167.     {
  1168.     form_dial(3, 0, 0, 0, 0, rect->g_x, rect->g_y, rect->g_w, rect->g_h);
  1169.     }
  1170. .bp
  1171. /*------------------------------*/
  1172. /*    set_prog         */
  1173. /*------------------------------*/
  1174.     VOID
  1175. set_prog(strno)
  1176.     UWORD    strno;
  1177.     {
  1178.     OBJECT    *tree;
  1179.     BYTE    *saddr;
  1180.  
  1181.     rsrc_gaddr(R_TREE, STRINGS, &tree);
  1182.     saddr = (BYTE *) (tree + strno)->ob_spec;
  1183.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  1184.     set_text(tree, PLINE, saddr);
  1185.     disp_obj(tree, PLINE);
  1186.     }
  1187. .!
  1188. .!****************************************************************************
  1189. .!
  1190. .!            End Appendix 13
  1191. .!
  1192. .!****************************************************************************
  1193.