home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / header.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-29  |  3.9 KB  |  169 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.  
  12.  
  13. save_file(size,start)
  14.     long size;
  15.     char *start;
  16. {
  17.     char temp[30], pname[30];
  18.     int len, i, fildes, c, button;
  19.  
  20.     len = strlen(thefrontwin->title);
  21.     for(i = len - 1; i > 0; i--)
  22.         if(thefrontwin->title[i] == '.')
  23.             break;
  24.     strncpy(temp,thefrontwin->title,i);
  25.     temp[i] = '\0';
  26.     sprintf(pname,"%s.RSC",temp);    
  27.  
  28.         fildes = open(pname,O_RDONLY);
  29.         if (fildes > 0)
  30.             {    button =  form_alert(1, "[1][ File already exists. | Ok to overwrite? ][OK|CANCEL]");
  31.                 if (button == 2)
  32.                     {    c = close(fildes);
  33.                         return;
  34.                     }
  35.                 c = close(fildes);
  36.             }
  37.         save_rsc(pname,size,start);
  38.         sprintf(pname,"%s.H",temp);    
  39.         make_hdr(pname);
  40.  
  41.         sprintf(pname,"%s.DEF",temp);    
  42.         make_def(pname);
  43.  
  44.         if(cout)
  45.         {    for(i = len - 1; i > 0; i--)
  46.             if(temp[i] == '\\')
  47.                 break;
  48.             temp[i+6] = '\0';
  49.             strcat(temp,"RSC.C");
  50.             make_cout(temp);
  51.         }
  52. /*
  53.           if(cout)
  54.          {    sprintf(pname,"%s.RSH",temp);
  55.             make_cout(pname);
  56.           }
  57. */
  58. }
  59.  
  60. int make_hdr(hname)
  61.     char hname[];
  62. {
  63.     long size;
  64.     char temp[80];
  65.     int fildes, c, i, j, button;
  66.     long flenw;   /* number of bytes written to file */
  67.     objtreeptr    thetree, *linkptr;
  68.     int numobjs, order[MAXONUM];
  69.  
  70.     thetree = thefrontwin->inwindow;
  71.     linkptr = thetree->treelink;
  72.  
  73.  
  74.           Fdelete(hname);
  75. #ifndef __GNUC__
  76.           fildes = creat(hname,O_RDWR);
  77.       if(fildes != -1)    
  78. #else
  79.         fildes = creat(hname,0666);
  80.     if(fildes > -1)    
  81. #endif
  82.         { 
  83.             for( i=1;i < thetree->count + 1; i++)
  84.             {    if(strlen(thetree->name[i]))
  85.                 {    sprintf(temp,"#define %s %d\n",thetree->name[i],i-1);
  86.                     size = strlen(temp);
  87.                     if( (flenw = Fwrite(fildes,size,temp)) <= 0)
  88.                     {
  89.                         button = form_alert(1, "[1][ Error writing file ][OK]");
  90.                            c = close(fildes);
  91.                         return;
  92.                     }
  93.                 }
  94.             numobjs = trav_tree(linkptr[i]->objt,order);
  95.                 for(j=0;j < numobjs; j++)
  96.                 if(strlen(linkptr[i]->name[order[j]]))
  97.                 {    sprintf(temp,"#define %s %d\n",linkptr[i]->name[order[j]],j);
  98.                     size = strlen(temp);
  99.                     if( (flenw = Fwrite(fildes,size,temp)) <= 0)
  100.                     {
  101.                         button = form_alert(1, "[1][ Error writing file ][OK]");
  102.                            c = close(fildes);
  103.                         return;
  104.                     }
  105.                 }
  106.             }
  107.             c = close(fildes);
  108.         }
  109.         else
  110.             button = form_alert(1, "[1][ Error creating file | Try 'SAVE AS' ][OK]");
  111. }
  112.  
  113. int save_rsc(rname,size,start)
  114.     long size;
  115.     char *start, rname[];
  116. {
  117.     int fildes, c, button;
  118.     long flenw;   /* number of bytes written to file */
  119.     unsigned dummy;
  120.        
  121.                  Fdelete(rname);
  122. #ifndef __GNUC__
  123.                   fildes = creat(rname,O_RDWR);
  124.               if(fildes != -1)    
  125. #else
  126.                 fildes = creat(rname,0666);
  127.             if(fildes > -1)    
  128. #endif
  129.                 {     if(flenw = Fwrite(fildes,size,start))
  130.                         ;
  131.                      else
  132.                         button = form_alert(1, "[1][ Error writing file ][OK]");
  133.                        c = close(fildes);
  134.                 }
  135.             else
  136.                 button = form_alert(1, "[1][ Error creating file | Try 'SAVE AS' ][OK]");
  137. }
  138.  
  139.  
  140.  
  141. getfile(thewin)  /* returns 1 with name in thewin->title, 0 with cancel */
  142.      windowptr thewin;
  143.  
  144. {        int  fs_button, c, i, len;
  145.         char *fname;
  146.         
  147.         len = strlen(thewin->title);
  148.         for(i=len;i>0;i--)  /* find last occurrence of \  */
  149.             if(thewin->title[i]=='\\') break;
  150.         fname = (char *)&(thewin->title[i+1]);
  151.         strcpy(fs_insel,fname); /* copy title to fs_insel */
  152.  
  153.         c = fsel_input(fs_inpath,fs_insel,&fs_button);
  154.         if(( c!=0 ) && (fs_button != 0))
  155.         {
  156.             len = strlen(fs_inpath);
  157.             for(i=len;i>0;i--)  /* find last occurrence of \  */
  158.                 if(fs_inpath[i]=='\\') break;
  159.  
  160.             strncpy(thewin->title,fs_inpath,i+1); /* copy pathname to title */
  161.             thewin->title[i+1] = '\0';
  162.             strcat(thewin->title,fs_insel);
  163.             if(thefrontwin)
  164.                 wind_set(thewin->wihandle, WF_NAME, thewin -> title, 0, 0);
  165.             return(1);
  166.         }
  167.         else    return(0);
  168. }
  169.