home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / pcjr / arc / PAKUTL12.LZH / PAKAS.C < prev    next >
Text File  |  1988-09-11  |  3KB  |  120 lines

  1. /*
  2.     PAKAS.C        ARCA -> PKPAK converter, with sort.
  3.  
  4.     Copyright 1988, Michael J. Housky
  5.     Released to the Public Domain ... *no* rights reserved.
  6. */
  7.  
  8. /*
  9.     Update log:
  10.  
  11.     Version 1.2, 10 September 1988: Released to public domain.
  12.     Version 1.0, 27 August 1988: First version.
  13. */
  14.  
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <process.h>
  19. #include <errno.h>
  20.  
  21.  
  22. /*
  23.     spawn_err:    Decode/print spawn/exec error message.
  24.             Return ERRORLEVEL exit code.
  25. */
  26.  
  27. int spawn_err( char*, int );
  28. int spawn_err( pname, err )
  29.     char    *pname;        /* program name */
  30.     int        err;        /* copy of errno */
  31. {
  32.     register int rc;
  33.  
  34.     switch ( err )
  35.     {
  36.     case ENOENT:
  37.         printf("Can't find %s in DOS PATH\n",pname);
  38.         rc = 254;
  39.         break;
  40.     case ENOMEM:
  41.         printf("Insufficient memory to load %s\n",pname);
  42.         rc = 253;
  43.         break;
  44.     default:
  45.         printf("Error %d loading %s\n",errno,pname);
  46.         rc = 252;
  47.         break;
  48.     }
  49.     return rc;
  50.  
  51. } /* spawn_err */
  52.  
  53.  
  54. /*
  55.     PAKAS.C main program
  56. */
  57.  
  58. int main(int,char **);
  59. int main( argc, argv )
  60.     int        argc;
  61.     char    **argv;
  62. {
  63.     register int
  64.         i,j;
  65.     char    *pname;
  66.     char    *order;
  67.     char    pakfile[88];
  68.  
  69. /* First, identify self and examine paramter: */
  70.  
  71.     printf("\nPAKAS: ARCA-to-PKPAK/PAKSORT v1.2\n");
  72.  
  73.     if ( argc < 3 )
  74.     {
  75.     printf("Usage: arca archive filespec\n");
  76.     return 255;
  77.     }
  78.  
  79. /* Next, copy archive name and append default filetype, if necessary */
  80.  
  81.     strncpy(pakfile, argv[1], sizeof(pakfile)-5);
  82.     pakfile[sizeof(pakfile)-5] = '\0';
  83.     i = strlen(pakfile);
  84.     do
  85.     {
  86.     j = pakfile[--i];
  87.     if ( j=='\\' || j==':' || i==0 )
  88.     {
  89.         strcat(pakfile,".ARC");
  90.         break;
  91.     }
  92.     } while ( j!='.' && i>0 );
  93.  
  94. /* Now spawn PKPAK to move files to archive: */
  95.  
  96.     pname = "PKPAK";            /* run PKPAK first */
  97.     printf(">PKPAK -oct m %s %s\n",pakfile,argv[2]);
  98.     j = spawnlp( P_WAIT, pname, pname, "-oct", "m", pakfile, argv[2], NULL );
  99.     
  100.     if ( j )                /* if error from PKPAK */
  101.     {
  102.     if ( j==-1 )            /* if spawn error */
  103.         return spawn_err(pname,errno);
  104.     return j;            /* return code to caller */
  105.     }
  106.  
  107. /* PKPAK succeeded, run PAKSORT to sort by date/time/name.ext: */
  108.  
  109.     pname = "PAKSORT";            /* run PAKSORT next */
  110.     order = "D+T+F+";            /* sort by date/time/name.ext */
  111.     printf(">PAKSORT %s %s\n", pakfile, order);
  112.     j = execlp( pname, pname, pakfile, order, NULL );
  113.  
  114. /* Arrive here on spawn/exec trouble: global errno has reason */
  115.  
  116.     spawn_err(pname,errno);        /* Display reason */
  117.     return 0;                /* good return, PKPAK succeeded */
  118.  
  119. } /* main */
  120.