home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / cout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-27  |  5.7 KB  |  217 lines

  1. #include "stdio.h"
  2. #include "gemdefs.h"
  3. #include "obdefs.h"
  4. #include "osbind.h"
  5. #include "mkrsc.h"
  6. #include "globals.h"
  7. #include "strings.h"
  8. #include <fcntl.h>
  9.  
  10.  
  11. int make_cout(cname)
  12.     char cname[];
  13. {
  14.     char temp[80], trname[30], *type;
  15.     int fildes, i, j, c, k, len;
  16.     objtreeptr    thetree, *linkptr;
  17.     int numobjs, order[MAXONUM];
  18.     int tednum, first, tinum, upb;
  19.     TEDINFO *tiptr;
  20.     OBJECT tempobj;
  21.  
  22.     thetree = thefrontwin->inwindow;
  23.     linkptr = thetree->treelink;
  24.  
  25.     tednum = 0;
  26.  
  27.     Fdelete(cname);
  28. #ifndef __GNUC__
  29.       fildes = creat(cname,O_RDWR);
  30.       if(fildes != -1)    
  31. #else
  32.      fildes = creat(cname,0666);
  33.      if(fildes > -1)    
  34. #endif
  35.     {    for( i=1;i < thetree->count + 1; i++)
  36.         {    first = TRUE;
  37.             strcpy(trname,thetree->name[i]);
  38.             len = strlen(trname);
  39.             for(k=0;k<len;k++)
  40.                 trname[k] = tolower(trname[k]);
  41.             numobjs = trav_tree(linkptr[i]->objt,order);
  42.             for(j=0;j < numobjs; j++)
  43.             {    switch (linkptr[i]->objt[order[j]].ob_type)
  44.             {
  45.             case G_TEXT        :
  46.             case G_BOXTEXT    :
  47.             case G_FTEXT    :
  48.             case G_FBOXTEXT    :
  49.             {    tiptr = (TEDINFO *)linkptr[i]->objt[order[j]].ob_spec;
  50.                 if(first)
  51.                 {    sprintf(temp,"TEDINFO ted%d[] = {\n",tednum++);
  52.                     if(!(wr_it(fildes,temp))) return;
  53.                     sprintf(temp,"    \"%s\",\n",tiptr->te_ptext);
  54.                     if(!(wr_it(fildes,temp))) return;
  55.                     first = FALSE;
  56.                 }
  57.                 else
  58.                 {
  59.                     sprintf(temp,",\n    \"%s\",\n",tiptr->te_ptext);
  60.                     if(!(wr_it(fildes,temp))) return;
  61.                 }
  62.                 sprintf(temp,"    \"%s\",\n",tiptr->te_ptmplt);
  63.                 if(!(wr_it(fildes,temp))) return;
  64.                 sprintf(temp,"    \"%s\",\n",tiptr->te_pvalid);
  65.                 if(!(wr_it(fildes,temp))) return;
  66.                 sprintf(temp,"    %d,%d,%d,0x%x,%d,%d,%d,%d",
  67.                     tiptr->te_font, tiptr->te_junk1,
  68.                     tiptr->te_just, tiptr->te_color,
  69.                     tiptr->te_junk2, tiptr->te_thickness,
  70.                     tiptr->te_txtlen, tiptr->te_tmplen);
  71.                 if(!(wr_it(fildes,temp))) return;
  72.                 break;
  73.             }
  74.             } /* end of switch        */
  75.             } /*    end of for j =    */
  76.             if(!first)
  77.             {    sprintf(temp,"      };\n\n");
  78.                 if(!(wr_it(fildes,temp))) return;
  79.             }
  80.  
  81. /*    now build the object tree    */
  82.  
  83.             first = TRUE;
  84.             tinum = 0;
  85.             for(j=0;j < numobjs; j++)
  86.             {
  87. /*    make a copy of the object and fix the pointers in the new order    */
  88.  
  89.                 tempobj = linkptr[i]->objt[order[j]];    
  90.                 /*    fix the size and width and special bytes    */
  91.                 if(order[j]==0)
  92.                     tempobj.ob_x = tempobj.ob_y = 0;
  93.                 upb = (tempobj.ob_x & ~0xFFF8) << 8;
  94.                 tempobj.ob_x = tempobj.ob_x/gl_wchar + upb;
  95.                 upb = (tempobj.ob_width & ~0xFFF8) << 8;
  96.                 tempobj.ob_width = tempobj.ob_width/gl_wchar + upb;
  97.                 upb = (tempobj.ob_y & ~(0xFFFF-gl_hchar+1)) << 8;
  98.                 tempobj.ob_y = tempobj.ob_y/gl_hchar + upb;
  99.                 upb = (tempobj.ob_height & ~(0xFFFF-gl_hchar+1)) << 8;
  100.                 tempobj.ob_height = tempobj.ob_height/gl_hchar + upb;
  101.  
  102.                 tempobj.ob_next = newpos(tempobj.ob_next,numobjs,order);
  103.                 tempobj.ob_head = newpos(tempobj.ob_head,numobjs,order);
  104.                 tempobj.ob_tail = newpos(tempobj.ob_tail,numobjs,order);
  105.             
  106.     /*    mark last object in subtree    */
  107.                 if(j == (numobjs - 1))
  108.                     tempobj.ob_flags |= LASTOB;
  109.                 else
  110.                     tempobj.ob_flags &= ~LASTOB;
  111.  
  112.                 if(first)
  113.                 {    sprintf(temp,"OBJECT %s[] = {\n",trname);
  114.                     if(!(wr_it(fildes,temp))) return;
  115.                 }
  116.  
  117.             switch (c = tempobj.ob_type)
  118.             {
  119.             case G_TEXT        :
  120.             case G_BOXTEXT    :
  121.             case G_FTEXT    :
  122.             case G_FBOXTEXT    :
  123.                 if( c == G_TEXT)    type = "G_TEXT";
  124.                 else if (c == G_BOXTEXT)    type = "G_BOXTEXT";
  125.                 else if (c == G_FTEXT)    type = "G_FTEXT";
  126.                 else if (c == G_FBOXTEXT)     type = "G_FBOXTEXT"; 
  127.                 sprintf(temp,",\n    %d,%d,%d,%s,0x%x,0x%x,(char *)&ted%d[%d],%d,%d,%d,%d",
  128.                 tempobj.ob_next, tempobj.ob_head,
  129.                 tempobj.ob_tail,
  130.                 type,
  131.                 (int)tempobj.ob_flags,
  132.                 (int)tempobj.ob_state,
  133.                 tednum-1,tinum++,
  134.                 tempobj.ob_x,
  135.                 tempobj.ob_y, tempobj.ob_width,
  136.                 tempobj.ob_height);
  137.                 if(!(wr_it(fildes,temp))) return;
  138.                 break;
  139.             case G_BUTTON    :
  140.             case G_STRING    :
  141.             case G_TITLE    :
  142.                 if(c == G_BUTTON)    type = "G_BUTTON";
  143.                 else if (c == G_STRING)    type = "G_STRING";
  144.                 else if (c == G_TITLE)    type = "G_TITLE";
  145.                 sprintf(temp,",\n    %d,%d,%d,%s,0x%x,0x%x, \"%s\" ,%d,%d,%d,%d",
  146.                     tempobj.ob_next,
  147.                     tempobj.ob_head,
  148.                     tempobj.ob_tail,
  149.                     type,
  150.                     (int)tempobj.ob_flags,
  151.                     (int)tempobj.ob_state,
  152.                     (char *)tempobj.ob_spec,
  153.                     tempobj.ob_x,
  154.                     tempobj.ob_y,
  155.                     tempobj.ob_width,
  156.                     tempobj.ob_height);
  157.                 if(!(wr_it(fildes,temp))) return;
  158.                 break;
  159.             case G_ICON        :
  160.                                 break;
  161.             case G_BOXCHAR    :
  162.             case G_BOX        :
  163.             case G_IBOX        :
  164.                 if(c == G_BOXCHAR)    type = " G_BOXCHAR";
  165.                 else if (c == G_BOX)    type = " G_BOX";
  166.                 else if (c == G_IBOX)    type = " G_IBOX";
  167.                 if(first)
  168.                 {    sprintf(temp,"    %d,",tempobj.ob_next);
  169.                     if(!(wr_it(fildes,temp))) return;
  170.                     first = FALSE;
  171.                 }
  172.                 else
  173.                 {    sprintf(temp,",\n    %d,",tempobj.ob_next);
  174.                     if(!(wr_it(fildes,temp))) return;
  175.                 }
  176.                     
  177.                 sprintf(temp,"%d,%d,%s,0x%x,0x%x,0x%lxL,%d,%d,%d,%d",
  178.                      tempobj.ob_head,
  179.                     tempobj.ob_tail,
  180.                     type,
  181.                     (int)tempobj.ob_flags,
  182.                     (int)tempobj.ob_state,
  183.                     (long)tempobj.ob_spec,
  184.                     tempobj.ob_x,
  185.                     tempobj.ob_y,
  186.                      tempobj.ob_width,
  187.                     tempobj.ob_height);
  188.                 if(!(wr_it(fildes,temp))) return;
  189.                                 break;
  190.             }        
  191.             }
  192.             if(!first)
  193.             {    sprintf(temp,"      };\n\n");
  194.                 if(!(wr_it(fildes,temp))) return;
  195.             }
  196.         }    c = close(fildes);        
  197.     }
  198.  
  199. }
  200.  
  201. int    wr_it(fildes,str)
  202.     int fildes;
  203.     char *str;
  204. {
  205.         long size, flenw;
  206.         int c, button;
  207.  
  208.         size = strlen(str);
  209.         if( (flenw = Fwrite(fildes,size,str)) <= 0)
  210.         {
  211.             button = form_alert(1, "[1][ Error writing file ][OK]");
  212.             c = close(fildes);
  213.             return(0);
  214.         }
  215.         return(1);
  216. }
  217.