home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / MPack1_2_1.lha / MPack / src / dosunpk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-05  |  2.8 KB  |  116 lines

  1. /* (C) Copyright 1993 by John G. Myers
  2.  * All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without
  6.  * fee, provided that the above copyright notice appear in all copies
  7.  * and that both that copyright notice and this permission notice
  8.  * appear in supporting documentation, and that the name of John G.
  9.  * Myers not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  John G. Myers makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as
  13.  * is" without express or implied warranty.
  14.  *
  15.  * JOHN G. MYERS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL JOHN G. MYERS BE LIABLE FOR ANY SPECIAL,
  18.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. #include <dir.h>
  25. #include <errno.h>
  26. #include "version.h"
  27.  
  28. extern int optind;
  29. extern char *optarg;
  30.  
  31. extern int overwrite_files;
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     int opt;
  38.     FILE *file;
  39.     char *p, *q, *path = 0;
  40.     int done, gotone;
  41.     struct ffblk ffblk;
  42.     
  43.     while ((opt = getopt(argc, argv, "fC:")) != EOF) {
  44.     switch (opt) {
  45.     case 'f':
  46.         overwrite_files = 1;
  47.         break;
  48.  
  49.     case 'C':
  50.         if (chdir(optarg)) {
  51.         perror(optarg);
  52.         exit(1);
  53.         }
  54.         break;
  55.  
  56.     default:
  57.         usage();
  58.     }
  59.     }
  60.  
  61.     if (optind == argc) {
  62.     fprintf(stderr, "munpack: reading from standard input\n");
  63.     handleMessage(stdin, "text/plain", 0);
  64.     exit(0);
  65.     }
  66.  
  67.     while (argv[optind]) {
  68.     if (path) free(path);
  69.     path = 0;
  70.  
  71.     p = argv[optind];
  72.     if (p[1] == ':') p += 2;
  73.     if (q = strrchr(p, '\\')) p = q+1;
  74.     if (q = strrchr(p, '/')) p = q+1;
  75.  
  76.     if (p != argv[optind]) {
  77.         path = xmalloc(strlen(argv[optind])+20);
  78.         strcpy(path, argv[optind]);
  79.         p = path + (p - argv[optind]);
  80.     }
  81.  
  82.     gotone = 0;
  83.     done = findfirst(argv[optind], &ffblk, 0);
  84.     while (!done) {
  85.         if (path) strcpy(p, ffblk.ff_name);
  86.         file = fopen(path ? path : ffblk.ff_name, "r");
  87.         if (!file) {
  88.         perror(path ? path : ffblk.ff_name);
  89.         }
  90.         else {
  91.         handleMessage(file, "text/plain", 0);
  92.         fclose(file);
  93.         }
  94.         gotone = 1;
  95.         done = findnext(&ffblk);
  96.     }
  97.     if (!gotone) {
  98.         perror(argv[optind]);
  99.     }
  100.     optind++;
  101.     }
  102.     exit(0);
  103. }
  104.  
  105. usage() {
  106.     fprintf(stderr, "usage: munpack [-C directory] [files...]\n");
  107.     exit(1);
  108. }
  109.  
  110. warn(s)
  111. char *s;
  112. {
  113.     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
  114.     fprintf(stderr, "munpack: warning: %s\n", s);
  115. }
  116.