home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <process.h>
- #include <alloc.h>
- #include <fcntl.h>
- #include <io.h>
- #include <sys\stat.h>
-
- void main(int parnums,char *pars[])
- {
- FILE *cfgfile;
- int rbytes,
- copycik,
- mhcik,
- fh,
- spcik,
- bfh,
- cfgrp,
- id=1,
- usid=0,
- omnum=0;
- long cfl,
- ompos,
- bcp,
- flength=0,
- fpos=0,
- pos,
- pposheader;
- char posign[]="PSO10",
- bfname[256],
- filename[256],
- usidc[256],
- *copybuf;
-
- printf("MAKE-OV v1.0-The Overlay file maker by Psycho/TSI (C) '93\n\n");
-
- printf("Allocating memory...\n");
- if(!(copybuf=new char[32000]))
- {
- printf("Not enough memory!!\n\n");
- exit(EXIT_FAILURE);
- }
- printf("Reading configfile...\n");
- if(parnums==1) cfgfile=fopen("MAKE-OV.cfg","rt");
- else cfgfile=fopen(pars[1],"rt");
- if(cfgfile==NULL)
- {
- printf("Config file not found.\n");
- printf("Please create MAKE-OV.cfg or re-run MAKE-OV with another filename.\n\n");
- exit(EXIT_FAILURE);
- }
- cfgrp=fscanf(cfgfile,"%s",filename);
- if(cfgrp==EOF) exit(EXIT_SUCCESS);
- if(!cfgrp)
- {
- roc:printf("Read error on configfile!!\n\n");
- exit(EXIT_FAILURE);
- }
- bfh=open(filename,O_RDWR|O_BINARY);
- if(bfh==-1)
- {
- printf("%s not found!!\n\n",filename);
- exit(EXIT_FAILURE);
- }
- ompos=filelength(bfh);
- lseek(bfh,0,SEEK_END);
- sprintf(bfname,"%s",filename);
- bcp=ftell(cfgfile);
- rec:
- cfgrp=fscanf(cfgfile,"%s",filename);
- if(!cfgrp) goto roc;
- if(cfgrp!=EOF)
- {
- for(spcik=0;spcik<256;spcik++)
- if(filename[spcik]==',')
- {
- filename[spcik]=0;
- break;
- }
- if(!access(filename,0))
- {
- omnum++;
- goto rec;
- }
- else
- {
- printf("%s not found!!\n\n",filename);
- exit(EXIT_FAILURE);
- }
- }
- fseek(cfgfile,bcp,SEEK_SET);
- printf("Making modul header...\n");
- lseek(bfh,ompos,SEEK_SET);
- for(mhcik=1;mhcik<=omnum+1;mhcik++)
- {
- if(mhcik==omnum+1)
- {
- id=0;
- usid=0;
- }
- else
- {
- id=mhcik;
- fscanf(cfgfile,"%s",filename);
- for(spcik=0;spcik<256;spcik++)
- if(filename[spcik]==',')
- {
- sprintf(usidc,"%s",&filename[spcik+1]);
- break;
- }
- usid=atoi(usidc);
- }
- if(write(bfh,&id,2)!=2||write(bfh,&usid,2)!=2||write(bfh,&flength,4)!=4||write(bfh,&fpos,4)!=4)
- {
- weob: printf("Write error on base file!!Disk Full??\n\n");
- exit(EXIT_FAILURE);
- }
- }
- printf("Copying items...\n");
- printf("Number of overlay items: %i\n",omnum);
- fseek(cfgfile,bcp,SEEK_SET);
- pposheader=ompos;
- printf("Base file: %s length: %li bytes\n",bfname,ompos);
- for(copycik=1;copycik<=omnum;copycik++)
- {
- lseek(bfh,pposheader+4,SEEK_SET);
- pos=filelength(bfh);
- if(write(bfh,&pos,4)!=4) goto weob;
- pposheader=tell(bfh)+4;
- fscanf(cfgfile,"%s",filename);
- for(spcik=0;spcik<256;spcik++)
- if(filename[spcik]==',')
- {
- sprintf(usidc,"%s",&filename[spcik+1]);
- filename[spcik]=0;
- break;
- }
- usid=atoi(usidc);
- fh=open(filename,O_RDONLY|O_BINARY);
- cfl=filelength(fh);
- printf("Overlay item: %s\n Id: %i Uid: %i\n Pos: %li Length: %li\n",filename,copycik,usid,pos,cfl);
- if(write(bfh,&cfl,4)!=4) goto weob;
- lseek(bfh,0,SEEK_END);
- rread:
- rbytes=read(fh,copybuf,32000);
- if(rbytes==-1)
- {
- printf("Read error on %s!!\n\n",filename);
- exit(EXIT_FAILURE);
- }
- write(bfh,copybuf,rbytes);
- if(rbytes==32000) goto rread;
- }
-
- delete []copybuf;
- if(write(bfh,&ompos,4)!=4) goto weob;
- if(write(bfh,posign,strlen(posign))!=strlen(posign)) goto weob;
- else
- {
- printf("\nOverlay module position on %s : %li\n",bfname,ompos);
- printf("Size of overlay module: %li bytes.\n",filelength(bfh)-ompos);
- printf("Linking has successful.\n");
- exit(EXIT_SUCCESS);
- }
- }
-