home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / std_unix / pax / 1 / cpio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-07  |  4.4 KB  |  218 lines

  1. /* $Source: /u/mark/src/pax/RCS/cpio.c,v $
  2.  *
  3.  * $Revision: 1.1 $
  4.  *
  5.  * cpio.c - Cpio specific functions for archive handling
  6.  *
  7.  * DESCRIPTION
  8.  *
  9.  *    These function provide a cpio conformant interface to the pax
  10.  *    program.
  11.  *
  12.  * AUTHOR
  13.  *
  14.  *     Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
  15.  *
  16.  * Sponsored by The USENIX Association for public distribution. 
  17.  *
  18.  * Copyright (c) 1989 Mark H. Colburn.
  19.  * All rights reserved.
  20.  *
  21.  * Redistribution and use in source and binary forms are permitted
  22.  * provided that the above copyright notice is duplicated in all such 
  23.  * forms and that any documentation, advertising materials, and other 
  24.  * materials related to such distribution and use acknowledge that the 
  25.  * software was developed * by Mark H. Colburn and sponsored by The 
  26.  * USENIX Association. 
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31.  *
  32.  * $Log:    cpio.c,v $
  33.  * Revision 1.1  88/12/23  18:02:05  mark
  34.  * Initial revision
  35.  * 
  36.  */
  37.  
  38. #ifndef lint
  39. static char *ident = "$Id: cpio.c,v 1.1 88/12/23 18:02:05 mark Rel $";
  40. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  41. #endif /* ! lint */
  42.  
  43.  
  44. /* Headers */
  45.  
  46. #include "pax.h"
  47.  
  48.  
  49. /* Function Prototypes */
  50.  
  51. #ifdef __STDC__
  52. static void     usage(void);
  53. #else /* !__STDC__ */
  54. static void     usage();
  55. #endif /* __STDC__ */
  56.  
  57.  
  58. /* do_cpio - handle cpio format archives
  59.  *
  60.  * DESCRIPTION
  61.  *
  62.  *    Do_cpio provides a standard CPIO interface to the PAX program.  All
  63.  *    of the standard cpio flags are available, and the behavior of the
  64.  *    program mimics traditonal cpio.
  65.  *
  66.  * PARAMETERS
  67.  *
  68.  *    int    argc    - command line argument count
  69.  *    char    **argv    - pointer to command line arguments
  70.  *
  71.  * RETURNS
  72.  *
  73.  *    Nothing.
  74.  */
  75.  
  76. #ifdef __STDC__
  77.  
  78. int do_cpio(int argc, char **argv)
  79.  
  80. #else
  81.  
  82. int do_cpio(argc, argv)
  83. int             argc;
  84. char          **argv;
  85.  
  86. #endif
  87. {
  88.     int             c;
  89.     char           *dirname;
  90.     Stat            st;
  91.  
  92.     /* default input/output file for CPIO is STDIN/STDOUT */
  93.     ar_file = "-";
  94.     names_from_stdin = 1;
  95.  
  96.     /* set up the flags to reflect the default CPIO inteface. */
  97.     blocksize = BLOCKSIZE;
  98.     ar_interface = CPIO;
  99.     ar_format = CPIO;
  100.     msgfile=stderr;
  101.  
  102.     while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
  103.     switch (c) {
  104.     case 'i':
  105.         f_extract = 1;
  106.         break;
  107.     case 'o':
  108.         f_create = 1;
  109.         break;
  110.     case 'p':
  111.         f_pass = 1;
  112.         dirname = argv[--argc];
  113.  
  114.         /* check to make sure that the argument is a directory */
  115.         if (LSTAT(dirname, &st) < 0) {
  116.         fatal(syserr());
  117.         }
  118.         if ((st.sb_mode & S_IFMT) != S_IFDIR) {
  119.         fatal("Not a directory");
  120.         }
  121.         break;
  122.     case 'B':
  123.         blocksize = BLOCK;
  124.         break;
  125.     case 'a':
  126.         f_access_time = 1;
  127.         break;
  128.     case 'c':
  129.         break;
  130.     case 'D':
  131.         ar_file = optarg;
  132.         break;
  133.     case 'd':
  134.         f_create_dirs = 1;
  135.         break;
  136.     case 'f':
  137.         f_reverse_match = 1;
  138.         break;
  139.     case 'l':
  140.         f_link = 1;
  141.         break;
  142.     case 'm':
  143.         f_modification_time = 1;
  144.         break;
  145.     case 'r':
  146.         f_interactive = 1;
  147.         break;
  148.     case 't':
  149.         f_list = 1;
  150.         break;
  151.     case 'u':
  152.         f_unconditional = 1;
  153.         break;
  154.     case 'v':
  155.         f_verbose = 1;
  156.         break;
  157.     default:
  158.         usage();
  159.     }
  160.     }
  161.  
  162.     if (f_create + f_pass + f_extract != 1) {
  163.     usage();
  164.     }
  165.     if (!f_pass) {
  166.     buf_allocate((OFFSET) blocksize);
  167.     }
  168.     if (f_extract) {
  169.     open_archive(AR_READ);    /* Open for reading */
  170.     read_archive();
  171.     } else if (f_create) {
  172.     open_archive(AR_WRITE);
  173.     create_archive();
  174.     } else if (f_pass) {
  175.     pass(dirname);
  176.     }
  177.  
  178.     /* print out the total block count transfered */
  179.     fprintf(stderr, "%d Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
  180.     
  181.     exit(0);
  182.     /* NOTREACHED */
  183. }
  184.  
  185.  
  186. /* usage - print a helpful message and exit
  187.  *
  188.  * DESCRIPTION
  189.  *
  190.  *    Usage prints out the usage message for the CPIO interface and then
  191.  *    exits with a non-zero termination status.  This is used when a user
  192.  *    has provided non-existant or incompatible command line arguments.
  193.  *
  194.  * RETURNS
  195.  *
  196.  *    Returns an exit status of 1 to the parent process.
  197.  *
  198.  */
  199.  
  200. #ifdef __STDC__
  201.  
  202. static void usage(void)
  203.  
  204. #else
  205.  
  206. static void usage()
  207.  
  208. #endif
  209. {
  210.     fprintf(stderr, "\
  211. Usage: %s -o[Bacv]\n", myname);
  212.     fprintf(stderr, "\
  213.        %s -i[Bcdmrtuvf] [pattern...]\n", myname);
  214.     fprintf(stderr, "\
  215.        %s -p[adlmruv] directory\n", myname);
  216.     exit(1);
  217. }
  218.