home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / demodisc / basq / source / poweru / make-ov.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-09  |  3.7 KB  |  167 lines

  1.         #include <string.h>
  2.         #include <stdio.h>
  3.         #include <stdlib.h>
  4.         #include <process.h>
  5.         #include <alloc.h>
  6.         #include <fcntl.h>
  7.         #include <io.h>
  8.         #include <sys\stat.h>
  9.  
  10. void main(int parnums,char *pars[])
  11.     {
  12.     FILE    *cfgfile;
  13.     int        rbytes,
  14.                 copycik,
  15.                 mhcik,
  16.                 fh,
  17.                 spcik,
  18.                 bfh,
  19.                 cfgrp,
  20.                 id=1,
  21.                 usid=0,
  22.                 omnum=0;
  23.     long    cfl,
  24.                 ompos,
  25.                 bcp,
  26.                 flength=0,
  27.                 fpos=0,
  28.                 pos,
  29.                 pposheader;
  30.     char    posign[]="PSO10",
  31.                 bfname[256],
  32.                 filename[256],
  33.                 usidc[256],
  34.                 *copybuf;
  35.  
  36.     printf("MAKE-OV v1.0-The Overlay file maker by Psycho/TSI (C) '93\n\n");
  37.  
  38.     printf("Allocating memory...\n");
  39.     if(!(copybuf=new char[32000]))
  40.         {
  41.         printf("Not enough memory!!\n\n");
  42.         exit(EXIT_FAILURE);
  43.         }
  44.     printf("Reading configfile...\n");
  45.     if(parnums==1) cfgfile=fopen("MAKE-OV.cfg","rt");
  46.     else cfgfile=fopen(pars[1],"rt");
  47.     if(cfgfile==NULL)
  48.         {
  49.         printf("Config file not found.\n");
  50.         printf("Please create MAKE-OV.cfg or re-run MAKE-OV with another filename.\n\n");
  51.         exit(EXIT_FAILURE);
  52.         }
  53.     cfgrp=fscanf(cfgfile,"%s",filename);
  54.     if(cfgrp==EOF) exit(EXIT_SUCCESS);
  55.     if(!cfgrp)
  56.         {
  57. roc:printf("Read error on configfile!!\n\n");
  58.         exit(EXIT_FAILURE);
  59.         }
  60.     bfh=open(filename,O_RDWR|O_BINARY);
  61.     if(bfh==-1)
  62.         {
  63.         printf("%s not found!!\n\n",filename);
  64.         exit(EXIT_FAILURE);
  65.         }
  66.     ompos=filelength(bfh);
  67.     lseek(bfh,0,SEEK_END);
  68.     sprintf(bfname,"%s",filename);
  69.     bcp=ftell(cfgfile);
  70. rec:
  71.     cfgrp=fscanf(cfgfile,"%s",filename);
  72.     if(!cfgrp) goto roc;
  73.     if(cfgrp!=EOF)
  74.         {
  75.         for(spcik=0;spcik<256;spcik++)
  76.             if(filename[spcik]==',')
  77.                 {
  78.                 filename[spcik]=0;
  79.                 break;
  80.                 }
  81.         if(!access(filename,0))
  82.             {
  83.             omnum++;
  84.             goto rec;
  85.             }
  86.         else
  87.             {
  88.             printf("%s not found!!\n\n",filename);
  89.             exit(EXIT_FAILURE);
  90.             }
  91.         }
  92.     fseek(cfgfile,bcp,SEEK_SET);
  93.     printf("Making modul header...\n");
  94.     lseek(bfh,ompos,SEEK_SET);
  95.     for(mhcik=1;mhcik<=omnum+1;mhcik++)
  96.         {
  97.         if(mhcik==omnum+1)
  98.             {
  99.             id=0;
  100.             usid=0;
  101.             }
  102.         else
  103.             {
  104.             id=mhcik;
  105.             fscanf(cfgfile,"%s",filename);
  106.             for(spcik=0;spcik<256;spcik++)
  107.                 if(filename[spcik]==',')
  108.                     {
  109.                     sprintf(usidc,"%s",&filename[spcik+1]);
  110.                     break;
  111.                     }
  112.             usid=atoi(usidc);
  113.             }
  114.         if(write(bfh,&id,2)!=2||write(bfh,&usid,2)!=2||write(bfh,&flength,4)!=4||write(bfh,&fpos,4)!=4)
  115.             {
  116. weob:    printf("Write error on base file!!Disk Full??\n\n");
  117.             exit(EXIT_FAILURE);
  118.             }
  119.         }
  120.     printf("Copying items...\n");
  121.     printf("Number of overlay items: %i\n",omnum);
  122.     fseek(cfgfile,bcp,SEEK_SET);
  123.     pposheader=ompos;
  124.     printf("Base file: %s length: %li bytes\n",bfname,ompos);
  125.     for(copycik=1;copycik<=omnum;copycik++)
  126.         {
  127.         lseek(bfh,pposheader+4,SEEK_SET);
  128.         pos=filelength(bfh);
  129.         if(write(bfh,&pos,4)!=4) goto weob;
  130.         pposheader=tell(bfh)+4;
  131.         fscanf(cfgfile,"%s",filename);
  132.         for(spcik=0;spcik<256;spcik++)
  133.             if(filename[spcik]==',')
  134.                 {
  135.                 sprintf(usidc,"%s",&filename[spcik+1]);
  136.                 filename[spcik]=0;
  137.                 break;
  138.                 }
  139.         usid=atoi(usidc);
  140.         fh=open(filename,O_RDONLY|O_BINARY);
  141.         cfl=filelength(fh);
  142.         printf("Overlay item: %s\n  Id: %i Uid: %i\n  Pos: %li Length: %li\n",filename,copycik,usid,pos,cfl);
  143.         if(write(bfh,&cfl,4)!=4) goto weob;
  144.         lseek(bfh,0,SEEK_END);
  145. rread:
  146.         rbytes=read(fh,copybuf,32000);
  147.         if(rbytes==-1)
  148.             {
  149.             printf("Read error on %s!!\n\n",filename);
  150.             exit(EXIT_FAILURE);
  151.             }
  152.         write(bfh,copybuf,rbytes);
  153.         if(rbytes==32000) goto rread;
  154.         }
  155.  
  156.     delete []copybuf;
  157.     if(write(bfh,&ompos,4)!=4) goto weob;
  158.     if(write(bfh,posign,strlen(posign))!=strlen(posign)) goto weob;
  159.     else
  160.         {
  161.         printf("\nOverlay module position on %s : %li\n",bfname,ompos);
  162.         printf("Size of overlay module: %li bytes.\n",filelength(bfh)-ompos);
  163.         printf("Linking has successful.\n");
  164.         exit(EXIT_SUCCESS);
  165.         }
  166.     }
  167.