home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2KIT1.ZIP / CLNZIP.C < prev    next >
C/C++ Source or Header  |  1989-11-25  |  9KB  |  286 lines

  1. /* ATKINSON - HOME COMPUTER - 414-543-8929 */
  2.  
  3. #define INCL_DOS
  4. #include <os2.h>
  5.  
  6.    USHORT cbWritten;
  7.    char achFailName[128];
  8.    RESULTCODES rescResults;
  9.    char readbuf[85];
  10.    char *p;
  11.    HDIR hdir = 0xFFFF;
  12.    FILEFINDBUF findbuf;
  13.    USHORT usSearchCount = 1;
  14.    int code;
  15.    int find_result;
  16.    int exec_result;
  17.    char *zip_string;
  18.    char *path;   
  19.    char *temp_path;
  20.    char *error_log; 
  21.    char *error_message;
  22.    ULONG ulFilePointer = 0;
  23.    HFILE open_fh;
  24.    USHORT usAction;
  25.    int open_result;
  26.    char *zip_file;
  27.    char msg_buf[100];
  28.    FILESTATUS fstsFile;
  29.    int get_info;
  30.    int set_info;
  31.    int dos_close;
  32.    USHORT usAttribute;
  33.    int mode_result;
  34.    char szFoundFile[128];
  35.    int search_result = 0;
  36.    int error_check = 0;
  37.                      
  38. main(argc, argv)
  39. int argc;
  40. char *argv[];
  41. {
  42.    DosWrite(1,"\r\nCLNZIP - version 1.00 - OS/2\r\n",32,&cbWritten);     
  43.  
  44.    path = (char *) malloc(128);   
  45.    memset(path,0,128);
  46.    strcpy(path, argv[1]); 
  47.    memset(readbuf,0,sizeof(readbuf));
  48.    strcpy(readbuf, "CMD.EXE");
  49.    temp_path = (char *) malloc(128);
  50.    memset(temp_path,0,128);
  51.    strcpy(temp_path, strupr(path));
  52.    error_log = (char *) malloc(128);
  53.    memset(error_log,0,128);
  54.    error_message = (char *) malloc(128);
  55.    memset(error_message,0,128);
  56.    zip_file = (char *) malloc(128);
  57.    memset(zip_file,0,128);
  58.    zip_string = (char *) malloc(128);
  59.    memset(zip_string,0,128);
  60.       
  61.    p = (&readbuf[strlen(readbuf)]+1);
  62.  
  63.    if (DosSearchPath(SEARCH_ENVIRONMENT,"PATH","PKZIP.EXE",szFoundFile,
  64.        sizeof(szFoundFile)) == 0)
  65.      {
  66.      }
  67.    else
  68.      {
  69.      DosWrite(1, "\r\nPKZIP.EXE not found on PATH\r\n",29,&cbWritten);
  70.      search_result = 1;
  71.      }
  72.    
  73.    if (DosSearchPath(SEARCH_ENVIRONMENT, "PATH", "CLNZIP.EXE", szFoundFile,
  74.       sizeof(szFoundFile)) == 0)
  75.      {
  76.      justpathname(szFoundFile);    
  77.      }
  78.    else
  79.      {
  80.      DosWrite(1, "\r\nCLNZIP.EXE not found on PATH\r\n",32,&cbWritten);
  81.      search_result = 1;
  82.      }            
  83.      
  84.    if (search_result == 1)
  85.      {
  86.      DosExit(EXIT_THREAD, 0);
  87.      }
  88.      
  89.    if (argc != 3)
  90.      {
  91.      usage();
  92.      DosExit(EXIT_THREAD, 0);
  93.      }      
  94.    else
  95.      {
  96.      strcpy(zip_string,strupr(argv[2]));
  97.      }      
  98.    
  99.    if ((strstr(zip_string, "*.*") != 0x00) || 
  100.        (strstr(zip_string, "*.???") != 0x00) ||
  101.        (strstr(zip_string, "????????.*") != 0x00) ||
  102.        (strstr(zip_string, "????????.???") != 0x00))  
  103.      {
  104.      DosWrite(1,"\r\nWILDCARD warning - ",21,&cbWritten);    
  105.      DosWrite(1,zip_string,strlen(zip_string),&cbWritten);
  106.      DosWrite(1,"\r\n",2,&cbWritten);
  107.      usage();
  108.      DosExit(EXIT_THREAD,0);
  109.      }      
  110.      
  111.    findfirstzip();
  112.     
  113.    if (find_result == 0)
  114.      findrestzip();            
  115.    else
  116.      usage();
  117.      
  118.    if (error_check != 0)
  119.      {
  120.      memset(error_message, 0, 128);
  121.      strcpy(error_message, "\r\nSee ");
  122.      strcat(error_message, szFoundFile);
  123.      strcat(error_message, "PKERRORS.LOG\r\n");    
  124.      DosWrite(1,error_message,strlen(error_message),&cbWritten);
  125.        }
  126.        
  127.    DosExit(EXIT_THREAD,0);
  128. }
  129.  
  130. findfirstzip()
  131. {
  132.    find_result = DosFindFirst(path,&hdir,0x00,&findbuf,sizeof(findbuf),
  133.                               &usSearchCount,0L);
  134.  
  135.    if (find_result == 0)
  136.      {
  137.      justpathname(temp_path);
  138.      strcpy(zip_file, temp_path);
  139.      strcat(zip_file, findbuf.achName);
  140.      mode_result = DosQFileMode(zip_file,&usAttribute,0L);     
  141.      open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  142.                    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);        
  143.      if (open_result == 0)
  144.        {
  145.        get_info = DosQFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  146.        dos_close = DosClose(open_fh);                          
  147.        strcpy(p, "/C PKZIP.EXE -D ");
  148.        strcat(p, temp_path);
  149.        strcat(p,findbuf.achName,strlen(findbuf.achName));
  150.        strcat(p," ");
  151.        strcat(p,zip_string);
  152.        exec_result = DosExecPgm(achFailName, sizeof(achFailName), EXEC_SYNC,
  153.                      readbuf, 0, &rescResults, readbuf);
  154.        if ((open_result == 0) && (get_info == 0) && (dos_close == 0))
  155.          {
  156.          open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, 
  157.                        FILE_OPEN, OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  158.                        0L);
  159.          set_info = DosSetFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  160.          dos_close = DosClose(open_fh);                  
  161.          mode_result = DosSetFileMode(zip_file,usAttribute,0L);     
  162.          }
  163.        if (rescResults.codeResult != 0)
  164.          {
  165.          memset(error_message,0,128);              
  166.          strcpy(error_message, temp_path);
  167.          strcat(error_message, findbuf.achName);    
  168.          strcat(error_message, "\r\n");
  169.          memset(error_log,0,128);
  170.          strcpy(error_log, szFoundFile);
  171.          strcat(error_log, "PKERRORS.LOG");
  172.          open_result = DosOpen(error_log, &open_fh, &usAction,0L, 0x00, 
  173.                        FILE_OPEN | FILE_CREATE, 
  174.                        OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);
  175.          DosChgFilePtr(open_fh, 0L, FILE_END, &ulFilePointer);
  176.          DosWrite(open_fh,error_message,strlen(error_message),&cbWritten);
  177.          dos_close = DosClose(open_fh);                        
  178.          error_check = 1;
  179.          }    
  180.        }       
  181.      }
  182. }
  183.  
  184. findrestzip()
  185. {
  186.    while (DosFindNext(hdir,&findbuf,sizeof(findbuf),&usSearchCount) == 0)
  187.      {
  188.      strcpy(zip_file, temp_path);
  189.      strcat(zip_file, findbuf.achName);
  190.      mode_result = DosQFileMode(zip_file,&usAttribute,0L);     
  191.      open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  192.                    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);        
  193.      if (open_result == 0)
  194.        {
  195.        get_info = DosQFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  196.        dos_close = DosClose(open_fh);                          
  197.        strcpy(p, "/C PKZIP.EXE -D ");
  198.        strcat(p, temp_path);
  199.        strcat(p,findbuf.achName,strlen(findbuf.achName));
  200.        strcat(p, " ");
  201.        strcat(p, zip_string);
  202.        exec_result = DosExecPgm(achFailName, sizeof(achFailName), EXEC_SYNC,
  203.                      readbuf, 0, &rescResults, readbuf);
  204.        if ((open_result == 0) && (get_info == 0) && (dos_close == 0))
  205.          {
  206.          open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00,
  207.                        FILE_OPEN, OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  208.                        0L);
  209.          set_info = DosSetFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  210.          dos_close = DosClose(open_fh);                  
  211.          mode_result = DosSetFileMode(zip_file,usAttribute,0L);     
  212.          }
  213.        if (rescResults.codeResult != 0)
  214.          {
  215.          memset(error_message,0,128);             
  216.          strcpy(error_message, temp_path);
  217.          strcat(error_message, findbuf.achName);    
  218.          strcat(error_message, "\r\n");
  219.          memset(error_log,0,128);
  220.          strcpy(error_log, szFoundFile);
  221.          strcat(error_log, "PKERRORS.LOG");
  222.          open_result = DosOpen(error_log, &open_fh, &usAction,0L, 0x00,
  223.                        FILE_OPEN | FILE_CREATE, 
  224.                        OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);
  225.          DosChgFilePtr(open_fh,0L,FILE_END,&ulFilePointer);
  226.          DosWrite(open_fh,error_message,strlen(error_message),&cbWritten);
  227.          dos_close = DosClose(open_fh);                        
  228.          error_check = 1;
  229.          }    
  230.        }                
  231.      }
  232. }
  233.  
  234. usage()
  235. {
  236.    DosWrite(1,"\r\n",2,&cbWritten);
  237.    DosWrite(1,"Usage:",6,&cbWritten);
  238.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  239.    DosWrite(1,"CLNZIP x1 x2",12,&cbWritten);
  240.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  241.    DosWrite(1,"Where x1 is full path to ZIP file/s to clean",44,&cbWritten);
  242.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  243.    DosWrite(1,"Where x2 is file collection entry to delete",43,&cbWritten);
  244.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  245.    DosWrite(1,"Ex: CLNZIP C:\\FILES\\SOME*.ZIP *.BAK",37,&cbWritten);
  246.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  247.    DosWrite(1,"Ex: CLNZIP D:\\SOME*.ZIP COMMAND.COM",36,&cbWritten);
  248.    DosWrite(1,"\r\n",2,&cbWritten);
  249. }
  250.  
  251. justpathname(temp_path)
  252.  
  253. char temp_path[];
  254.  
  255. {
  256.    char *path;
  257.    char *drive;
  258.    char *dir;
  259.    char *fname;
  260.    char *ext;
  261.    
  262.    path = (char *) malloc(128);  
  263.    drive = (char *) malloc(128);
  264.    dir = (char *) malloc(128);
  265.    fname = (char *) malloc(128);
  266.    ext = (char *) malloc(128);
  267.  
  268.    memset(path,0,128);
  269.    memset(drive,0,128);
  270.    memset(dir,0,128);
  271.    memset(fname,0,128);
  272.    memset(ext,0,128);
  273.  
  274.    strcpy(path,temp_path);
  275.    _splitpath(temp_path,drive,dir,fname,ext);
  276.    strcpy(path,drive);
  277.    strcat(path,dir);
  278.    strcpy(temp_path,path);
  279.  
  280.    free(path);
  281.    free(drive);
  282.    free(dir);
  283.    free(fname);
  284.    free(ext);
  285. }
  286.