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