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

  1.         #include <stdio.h>
  2.         #include <io.h>
  3.         #include <fcntl.h>
  4.         #include <sys\stat.h>
  5.         #include <stdlib.h>
  6.         #include <process.h>
  7.         #include <alloc.h>
  8.  
  9. void main(int parnum,char *pars[],char *env[])
  10.     {
  11.     int     hfileexe,
  12.             hfiledata,
  13.             flmodulo,
  14.             fl,
  15.             rrbytes,
  16.             checksumexe;
  17.     long    fileexel,
  18.             filedatal;
  19.     char    far *buff;
  20.  
  21.     printf("LINKPLUS v1.0ß by Psycho/TSI (C) '92\n\n");
  22.     if(parnum!=3)
  23.         {
  24.         printf("Too ");
  25.         if(parnum<3) printf("few ");
  26.         else printf("much ");
  27.         printf("parameters!!\n");
  28.         printf("USAGE: linkplus <exefile> <datafile>\n\n");
  29.         exit(EXIT_FAILURE);
  30.         }
  31.     if((hfileexe=open(pars[1],O_RDWR|O_BINARY))==-1||
  32.         (hfiledata=open(pars[2],O_RDONLY|O_BINARY))==-1)
  33.         {
  34.         printf("Error in file operations!!\n");
  35.         printf("USAGE: linkplus <exefile> <datafile>\n\n");
  36.         exit(EXIT_FAILURE);
  37.         }
  38.     printf("Checking file header...");
  39.     read(hfileexe,&checksumexe,2);
  40.     if(checksumexe!=0x5a4d)
  41.         {
  42.         printf("The %s is not exefile!!\n",pars[1]);
  43.         exit(EXIT_FAILURE);
  44.         }
  45.     fileexel=filelength(hfileexe);
  46.     filedatal=filelength(hfiledata);
  47.     printf("Allocating memory...");
  48.     if(!(buff=(char far *) farmalloc(32000)))
  49.         {
  50.         printf("Not enough memory!!\n\n");
  51.         exit(EXIT_FAILURE);
  52.         }
  53.     printf("\nSize of %s %li bytes.\n",pars[1],fileexel);
  54.     printf("Size of %s %li bytes.\n",pars[2],filedatal);
  55.     fileexel+=filedatal;
  56.     printf("New size of %s %li bytes.\n",pars[1],fileexel);
  57.     flmodulo=(int) (fileexel%512L);
  58.     fl=(int) (fileexel/512L);
  59.     if(flmodulo) fl++;
  60.     write(hfileexe,&flmodulo,2);
  61.     write(hfileexe,&fl,2);
  62.     lseek(hfileexe,0,SEEK_END);
  63.     printf("Linking...");
  64.     do    {
  65.         if((rrbytes=read(hfiledata,buff,32000))==-1)
  66.             {
  67.             printf("Read error!!\n\n");
  68.             exit(EXIT_FAILURE);
  69.             }
  70.         if(rrbytes!=write(hfileexe,buff,rrbytes))
  71.             {
  72.             printf("Write error!!\n\n");
  73.             exit(EXIT_FAILURE);
  74.             }
  75.         } while(rrbytes==32000);
  76.     printf("\nLinking has successful.\n");
  77.     exit(EXIT_SUCCESS);
  78.     }
  79.