home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SIMPWN93.ZIP / SIMPWIN.ZIP / DELIST.C < prev    next >
C/C++ Source or Header  |  1997-08-18  |  6KB  |  309 lines

  1. # include <string.h>
  2. # include <conio.h>
  3. # include <alloc.h>
  4. # include <stdlib.h>
  5. # include <stdio.h>
  6. # include <io.h>
  7. # include <sys/stat.h>
  8. # include <dir.h>
  9. # include <dos.h>
  10.  
  11. int dev_error;
  12. FILE *t_fp;
  13.  
  14. int read_file(void *buff,char *file_name,unsigned int length,unsigned long int byte_start);
  15. int handler(int errval,int ax,int bp,int si);
  16. int write_file(void *buff,char *file_name,unsigned int length,unsigned long int byte_start);
  17. int error_write(FILE *err_pt);
  18. int creat_file(char *file_name);
  19. int read_directory(char *buff,int num_file,char *directory);
  20.  
  21. void main(void)
  22. {
  23.     char *buff;
  24.     char *direc;
  25.     int i,j,k;
  26.     int error = 0;
  27.     int skip= 0;
  28.     char *temp_point;
  29.     char pack_path[80];
  30.     char deinstall[20];
  31.     char deinst_path[80];
  32.     char title[80];
  33.     unsigned long int start = 0L;
  34.     unsigned long int pack_start = 0L;
  35.     unsigned long int deinst_start = 0L;
  36.     char check[8][20] = {"","","VOLUME IN","VOLUME SERIAL","DIRECTORY",
  37.                  "<DIR>","FILE\(S\)","BYTES FREE"};
  38.  
  39.  
  40.     system("CLS");
  41.     harderr(handler);
  42.     if((buff = (char*)malloc(257)) == NULL)
  43.     {
  44.         error = 1;
  45.     }
  46.     else
  47.     {
  48.         if((direc = (char*)malloc(80 * 13)) == NULL)
  49.         {
  50.             error = 1;
  51.             free(buff);
  52.         }
  53.     }
  54.     if(error == 1)
  55.     {
  56.         cprintf("Not enough memory!");
  57.         exit(1);
  58.     }
  59.     memset(buff,0,257);
  60.     memset(direc,0,80 * 14);
  61.     if(read_directory(direc,80,"*.txt") != 0)
  62.     {
  63.         cprintf("No files found!");
  64.         free(buff);
  65.         free(direc);
  66.         exit(1);
  67.     }
  68.     i = 0;
  69.     strcpy(pack_path,"packing.lst");
  70.     strcpy(deinst_path,"deinstal.lst");
  71.     creat_file(pack_path);
  72.     creat_file(deinst_path);
  73.     while(direc[i * 13] != 0x00)
  74.     {
  75.         strcpy(check[0],&direc[i * 13]);
  76.         strtok(check[0],".");
  77.         for(j = strlen(check[0]);j < 13;j++)
  78.         {
  79.             check[0][j] = 0x20;
  80.             switch(j)
  81.             {
  82.                 case 9 : check[0][9] = 'T'; break;
  83.                 case 10 : check[0][10] = 'X'; break;
  84.                 case 11 : check[0][11] = 'T'; break;
  85.                 case 12 : check[0][12] = ''; break;
  86.             }
  87.         }
  88.         strcpy(check[1],&direc[i * 13]);
  89.         strtok(check[1],".");
  90.         strcat(check[1],".ZIP");
  91.         strcpy(title,"\r\nFiles in ");
  92.         strcat(title,check[1]);
  93.         strcat(title,":\r\n\r\n");
  94.         error = write_file(title,pack_path,strlen(title),pack_start);
  95.         if(error > 0)
  96.         {
  97.             break;
  98.         }
  99.         pack_start = pack_start + strlen(title);
  100.         strtok(check[1],".");
  101.         for(j = strlen(check[1]);j < 13;j++)
  102.         {
  103.             check[1][j] = 0x20;
  104.             switch(j)
  105.             {
  106.                 case 9 : check[1][9] = 'Z'; break;
  107.                 case 10 : check[1][10] = 'I'; break;
  108.                 case 11 : check[1][11] = 'P'; break;
  109.                 case 12 : check[1][12] = ''; break;
  110.             }
  111.         }
  112.         start = 0L;
  113.         skip = 0;
  114.         while((error = read_file(buff,&direc[i * 13],256,start)) < 1)
  115.         {
  116.             if(buff[0] == 0x00)
  117.             {
  118.                 break;
  119.             }
  120.             temp_point = strchr(buff,'\r');
  121.             temp_point[0] = 0x00;
  122.             for(k = 1;k < 256;k++)
  123.             {
  124.                 if((temp_point[k] != '\r') & (temp_point[k] != '\n'))
  125.                 {
  126.                     break;
  127.                 }
  128.             }
  129.             start = start + strlen(buff) + k;
  130.             strupr(buff);
  131.             if(strcmp(buff,"") == 0)
  132.             {
  133.                 skip = 1;
  134.             }
  135.             for(j = 0;j < 8;j++)
  136.             {
  137.                 if(strstr(buff,check[j]) != NULL)
  138.                 {
  139.                     skip = 1;
  140.                 }
  141.             }
  142.             if(skip != 1)
  143.             {
  144.                 strcat(buff,"\r\n");
  145.                 if((error = write_file(buff,pack_path,strlen(buff),pack_start)) == 0)
  146.                 {
  147.                     pack_start = pack_start + strlen(buff);
  148.                     temp_point = strtok(buff," ");
  149.                     strcpy(deinstall,temp_point);
  150.                     strcat(deinstall,".");
  151.                     temp_point = strtok(NULL," ");
  152.                     strcat(deinstall,temp_point);
  153.                     strcat(deinstall,"\r\n");
  154.                     if((error = write_file(deinstall,deinst_path,strlen(deinstall),deinst_start)) == 0)
  155.                     {
  156.                         deinst_start = deinst_start + strlen(deinstall);
  157.                     }
  158.                 }
  159.             }
  160.             skip = 0;
  161.             memset(buff,0,256);
  162.             if(error > 0)
  163.             {
  164.                 break;
  165.             }
  166.         }
  167.         if(error > 0)
  168.         {
  169.             break;
  170.         }
  171.         i++;
  172.     }
  173.     if(error > 0)
  174.     {
  175.         cprintf("File error file %s!",&direc[i * 13]);
  176.     }
  177.     free(buff);
  178.     free(direc);
  179. }
  180.  
  181. int read_file(void *buff,char *file_name,unsigned int length,unsigned long int byte_start)
  182. {
  183.     FILE r_fp;
  184.  
  185.     dev_error = 0;
  186.     t_fp = &r_fp;
  187.     if((t_fp = fopen(file_name,"r+b")) == NULL)
  188.     {
  189.         error_write(t_fp);
  190.         return(dev_error);
  191.     }
  192.     if(fseek(t_fp,byte_start,0) != 0)
  193.     {
  194.         error_write(t_fp);
  195.         fclose(t_fp);
  196.         return(dev_error);
  197.     }
  198.     if(fread(buff,sizeof(char) * length,1,t_fp) != 1)
  199.     {
  200.         error_write(t_fp);
  201.         fclose(t_fp);
  202.         return(dev_error);
  203.     }
  204.     fclose(t_fp);
  205.     return(0);
  206. }
  207.  
  208. #pragma warn -par
  209.  
  210. int handler(int errval,int ax,int bp,int si)
  211. {
  212.     if(ax < 0)
  213.     {
  214.         dev_error = _DI & 0x00ff;
  215.         bdosptr(0x09,"$",0);
  216.         hardretn(2);
  217.     }
  218.     dev_error = errval;
  219.     bdosptr(0x09,"$",0);
  220.     hardretn(2);
  221.     return(0);
  222. }
  223.  
  224. int write_file(void *buff,char *file_name,unsigned int length,unsigned long int byte_start)
  225. {
  226.     FILE w_fp;
  227.  
  228.     dev_error = 0;
  229.     t_fp = &w_fp;
  230.     if((t_fp = fopen(file_name,"r+b")) == NULL)
  231.     {
  232.         error_write(t_fp);
  233.         return(dev_error);
  234.     }
  235.     if(fseek(t_fp,byte_start,0) != 0)
  236.     {
  237.         error_write(t_fp);
  238.         fclose(t_fp);
  239.         return(dev_error);
  240.     }
  241.     if(fwrite(buff,sizeof(char) * length,1,t_fp) != 1)
  242.     {
  243.         error_write(t_fp);
  244.         fclose(t_fp);
  245.         return(dev_error);
  246.     }
  247.     fclose(t_fp);
  248.     return(0);
  249. }
  250.  
  251. int error_write(FILE *err_pt)
  252. {
  253.     if(dev_error == 0)
  254.     {
  255.         dev_error = _doserrno;
  256.     }
  257.     if(feof(err_pt) != 0)
  258.     {
  259.         dev_error = -1;
  260.         return(1);
  261.     }
  262.     return(0);
  263. }
  264.  
  265. int creat_file(char *file_name)
  266. {
  267.     int handle;
  268.  
  269.     if(access(file_name,0) != 0)
  270.     {
  271.         handle = creat(file_name,S_IREAD|S_IWRITE);
  272.         close(handle);
  273.         return(1);
  274.     }
  275.     else
  276.     {
  277.         return(0);
  278.     }
  279. }
  280.  
  281. int read_directory(char *buff,int num_file,char *directory)
  282. {
  283.     int i;
  284.     char far *data;
  285.     struct ffblk dir_data;
  286.  
  287.  
  288.     data = getdta();
  289.     dev_error = 0;
  290.     if(findfirst(directory,&dir_data,FA_RDONLY) != 0)
  291.     {
  292.         return(1);
  293.     }
  294.     strcpy(buff,dir_data.ff_name);
  295.     buff = buff + 13;
  296.     for(i = 1;i < num_file;i++)
  297.     {
  298.         if(findnext(&dir_data) != 0)
  299.         {
  300.             break;
  301.         }
  302.         strcpy(buff,dir_data.ff_name);
  303.         buff = buff + 13;
  304.     }
  305.     setdta(data);
  306.     return(0);
  307. }
  308.  
  309.