home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2KIT1.ZIP / CHKZIP.C next >
C/C++ Source or Header  |  1989-11-25  |  8KB  |  260 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 *exec_path;
  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\nCHKZIP - version 1.00 - OS/2\r\n",32,&cbWritten);     
  43.  
  44.    exec_path = (char *) malloc(128);
  45.    memset(exec_path,0,128);
  46.    strcpy(exec_path, argv[0]);     
  47.    justpathname(exec_path);
  48.    path = (char *) malloc(128);   
  49.    memset(path,0,128);
  50.    strcpy(path, argv[1]); 
  51.    memset(readbuf,0,sizeof(readbuf));
  52.    strcpy(readbuf, "CMD.EXE");
  53.    temp_path = (char *) malloc(128);
  54.    memset(temp_path,0,128);
  55.    strcpy(temp_path, strupr(path));
  56.    error_log = (char *) malloc(128);
  57.    memset(error_log,0,128);
  58.    error_message = (char *) malloc(128);
  59.    memset(error_message,0,128);
  60.    zip_file = (char *) malloc(128);
  61.    memset(zip_file,0,128);
  62.    
  63.    p = (&readbuf[strlen(readbuf)]+1);
  64.  
  65.    if (DosSearchPath(SEARCH_ENVIRONMENT,"PATH","PKUNZIP.EXE",szFoundFile,
  66.        sizeof(szFoundFile)) == 0)
  67.      {
  68.      }
  69.    else
  70.      {
  71.      DosWrite(1, "\r\nPKUNZIP.EXE not found on PATH\r\n",31,&cbWritten);
  72.      search_result = 1;
  73.      }
  74.    
  75.    if (DosSearchPath(SEARCH_ENVIRONMENT, "PATH", "CHKZIP.EXE", szFoundFile,
  76.       sizeof(szFoundFile)) == 0)
  77.      {
  78.      justpathname(szFoundFile);    
  79.      }
  80.    else
  81.      {
  82.      DosWrite(1, "\r\nCHKZIP.EXE not found on PATH\r\n",32,&cbWritten);
  83.      search_result = 1;
  84.      }            
  85.      
  86.    if (search_result == 1)
  87.      {
  88.      DosExit(EXIT_THREAD, 0);
  89.      }
  90.           
  91.    findfirstzip();
  92.     
  93.    if (find_result == 0)
  94.      findrestzip();            
  95.    else
  96.      usage();
  97.      
  98.    if (error_check != 0)
  99.      {
  100.      memset(error_message, 0, 128);
  101.      strcpy(error_message, "\r\nSee ");
  102.      strcat(error_message, szFoundFile);
  103.      strcat(error_message, "PKERRORS.LOG\r\n");    
  104.      DosWrite(1,error_message,strlen(error_message),&cbWritten);
  105.        }
  106.        
  107.    DosExit(EXIT_THREAD,0);
  108. }
  109.  
  110. findfirstzip()
  111. {
  112.    find_result = DosFindFirst(path,&hdir,0x00,&findbuf,sizeof(findbuf),
  113.                               &usSearchCount,0L);
  114.  
  115.    if (find_result == 0)
  116.      {
  117.      justpathname(temp_path);
  118.      strcpy(zip_file, temp_path);
  119.      strcat(zip_file, findbuf.achName);
  120.      mode_result = DosQFileMode(zip_file,&usAttribute,0L);     
  121.      open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  122.                    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);        
  123.      if (open_result == 0)
  124.        {
  125.        get_info = DosQFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  126.        dos_close = DosClose(open_fh);                          
  127.        strcpy(p, "/C PKUNZIP.EXE -T ");
  128.        strcat(p, temp_path);
  129.        strcat(p,findbuf.achName,strlen(findbuf.achName));
  130.        exec_result = DosExecPgm(achFailName, sizeof(achFailName), EXEC_SYNC,
  131.                      readbuf, 0, &rescResults, readbuf);
  132.        if ((open_result == 0) && (get_info == 0) && (dos_close == 0))
  133.          {
  134.          open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, 
  135.                        FILE_OPEN, OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  136.                        0L);
  137.          set_info = DosSetFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  138.          dos_close = DosClose(open_fh);                  
  139.          mode_result = DosSetFileMode(zip_file,usAttribute,0L);     
  140.          }
  141.        if (rescResults.codeResult != 0)
  142.          {
  143.          memset(error_message,0,128);              
  144.          strcpy(error_message, temp_path);
  145.          strcat(error_message, findbuf.achName);    
  146.          strcat(error_message, "\r\n");
  147.          memset(error_log,0,128);
  148.          strcpy(error_log, szFoundFile);
  149.          strcat(error_log, "PKERRORS.LOG");
  150.          open_result = DosOpen(error_log, &open_fh, &usAction,0L, 0x00, 
  151.                        FILE_OPEN | FILE_CREATE, 
  152.                        OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);
  153.          DosChgFilePtr(open_fh, 0L, FILE_END, &ulFilePointer);
  154.          DosWrite(open_fh,error_message,strlen(error_message),&cbWritten);
  155.          dos_close = DosClose(open_fh);                        
  156.          error_check = 1;
  157.          }    
  158.        }       
  159.      }
  160. }
  161.  
  162. findrestzip()
  163. {
  164.    while (DosFindNext(hdir,&findbuf,sizeof(findbuf),&usSearchCount) == 0)
  165.      {
  166.      strcpy(zip_file, temp_path);
  167.      strcat(zip_file, findbuf.achName);
  168.      mode_result = DosQFileMode(zip_file,&usAttribute,0L);     
  169.      open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  170.                    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);        
  171.      if (open_result == 0)
  172.        {
  173.        get_info = DosQFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  174.        dos_close = DosClose(open_fh);                          
  175.        strcpy(p, "/C PKUNZIP.EXE -T ");
  176.        strcat(p, temp_path);
  177.        strcat(p,findbuf.achName,strlen(findbuf.achName));
  178.        exec_result = DosExecPgm(achFailName, sizeof(achFailName), EXEC_SYNC,
  179.                      readbuf, 0, &rescResults, readbuf);
  180.        if ((open_result == 0) && (get_info == 0) && (dos_close == 0))
  181.          {
  182.          open_result = DosOpen(zip_file, &open_fh, &usAction, 0L, 0x00,
  183.                        FILE_OPEN, OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  184.                        0L);
  185.          set_info = DosSetFileInfo(open_fh, 1, &fstsFile, sizeof(fstsFile));
  186.          dos_close = DosClose(open_fh);                  
  187.          mode_result = DosSetFileMode(zip_file,usAttribute,0L);     
  188.          }
  189.        if (rescResults.codeResult != 0)
  190.          {
  191.          memset(error_message,0,128);             
  192.          strcpy(error_message, temp_path);
  193.          strcat(error_message, findbuf.achName);    
  194.          strcat(error_message, "\r\n");
  195.          memset(error_log,0,128);
  196.          strcpy(error_log, szFoundFile);
  197.          strcat(error_log, "PKERRORS.LOG");
  198.          open_result = DosOpen(error_log, &open_fh, &usAction,0L, 0x00,
  199.                        FILE_OPEN | FILE_CREATE, 
  200.                        OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L);
  201.          DosChgFilePtr(open_fh,0L,FILE_END,&ulFilePointer);
  202.          DosWrite(open_fh,error_message,strlen(error_message),&cbWritten);
  203.          dos_close = DosClose(open_fh);                        
  204.          error_check = 1;
  205.          }    
  206.        }                
  207.      }
  208. }
  209.  
  210. usage()
  211. {
  212.    DosWrite(1,"\r\n",2,&cbWritten);
  213.    DosWrite(1,"Usage:",6,&cbWritten);
  214.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  215.    DosWrite(1,"CHKZIP n",8,&cbWritten);
  216.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  217.    DosWrite(1,"Where n is full path to ZIP file/s to check",43,&cbWritten);
  218.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  219.    DosWrite(1,"Ex: CHKZIP C:\\FILES\\SOME*.ZIP",31,&cbWritten);
  220.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  221.    DosWrite(1,"Ex: CHKZIP D:\\SOME*.ZIP",23,&cbWritten);
  222.    DosWrite(1,"\r\n",2,&cbWritten);
  223. }
  224.  
  225. justpathname(temp_path)
  226.  
  227. char temp_path[];
  228.  
  229. {
  230.    char *path;
  231.    char *drive;
  232.    char *dir;
  233.    char *fname;
  234.    char *ext;
  235.    
  236.    path = (char *) malloc(128);  
  237.    drive = (char *) malloc(128);
  238.    dir = (char *) malloc(128);
  239.    fname = (char *) malloc(128);
  240.    ext = (char *) malloc(128);
  241.  
  242.    memset(path,0,128);
  243.    memset(drive,0,128);
  244.    memset(dir,0,128);
  245.    memset(fname,0,128);
  246.    memset(ext,0,128);
  247.  
  248.    strcpy(path,temp_path);
  249.    _splitpath(temp_path,drive,dir,fname,ext);
  250.    strcpy(path,drive);
  251.    strcat(path,dir);
  252.    strcpy(temp_path,path);
  253.  
  254.    free(path);
  255.    free(drive);
  256.    free(dir);
  257.    free(fname);
  258.    free(ext);
  259. }
  260.