home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / mpackppc-wos / src / dospk.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  4KB  |  165 lines

  1. /* (C) Copyright 1993,1994 by Carnegie Mellon University
  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 Carnegie
  9.  * Mellon University not be used in advertising or publicity
  10.  * pertaining to distribution of the software without specific,
  11.  * written prior permission.  Carnegie Mellon University makes no
  12.  * representations about the suitability of this software for any
  13.  * purpose.  It is provided "as is" without express or implied
  14.  * warranty.
  15.  *
  16.  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
  17.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  18.  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
  19.  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  21.  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  22.  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <errno.h>
  30. #include "version.h"
  31. #include "xmalloc.h"
  32.  
  33. #define MAXADDRESS 100
  34.  
  35. extern int optind;
  36. extern char *optarg;
  37.  
  38. main(argc, argv)
  39. int argc;
  40. char **argv;
  41. {
  42.     int opt;
  43.     char *fname = 0;
  44.     char *subject = 0;
  45.     char *descfname = 0;
  46.     long maxsize = 0;
  47.     char *outfname = 0;
  48.     char *ctype = 0;
  49.     char *headers = 0;
  50.     int i;
  51.     char *p;
  52.     char sbuf[1024];
  53.     char fnamebuf[4096];
  54.     int part;
  55.     FILE *infile;
  56.     FILE *descfile = 0;
  57.  
  58.     if ((p = getenv("SPLITSIZE")) && *p >= '0' && *p <= '9') {
  59.     maxsize = atoi(p);
  60.     }
  61.  
  62.     while ((opt = getopt(argc, argv, "s:d:m:c:o:n:")) != EOF) {
  63.     switch (opt) {
  64.     case 's':
  65.         subject = optarg;
  66.         break;
  67.  
  68.     case 'd':
  69.         descfname = optarg;
  70.         break;
  71.  
  72.     case 'm':
  73.         maxsize = atol(optarg);
  74.         break;
  75.  
  76.     case 'c':
  77.         ctype = optarg;
  78.         break;
  79.  
  80.     case 'o':
  81.         outfname = optarg;
  82.         break;
  83.  
  84.     default:
  85.         usage();
  86.  
  87.     }
  88.     }
  89.  
  90.     if (ctype) {
  91.     if (!cistrncmp(ctype, "text/", 5)) {
  92.         fprintf(stderr, "This program is not appropriate for encoding textual data\n");
  93.         exit(1);
  94.     }
  95.     if (cistrncmp(ctype, "application/", 12) && cistrncmp(ctype, "audio/", 6) &&
  96.         cistrncmp(ctype, "image/", 6) && cistrncmp(ctype, "video/", 6)) {
  97.         fprintf(stderr, "Content type must be subtype of application, audio, image, or video\n");
  98.         exit(1);
  99.     }
  100.     }
  101.  
  102.     if (!outfname) {
  103.     fprintf(stderr, "The -o switch is required\n");
  104.     usage();
  105.     }
  106.  
  107.     if (optind == argc) {
  108.     fprintf(stderr, "An input file must be specified\n");
  109.     usage();
  110.     }
  111.     fname = argv[optind++];
  112.     for (p = fname; *p; p++) {
  113.     if (isupper(*p)) *p = tolower(*p);
  114.     }
  115.  
  116.     /* Must have -o */
  117.     if (optind != argc) {
  118.     fprintf(stderr, "Too many arguments\n");
  119.     usage();
  120.     }
  121.  
  122.     if (!subject) {
  123.     fputs("Subject: ", stdout);
  124.     fflush(stdout);
  125.     if (!fgets(sbuf, sizeof(sbuf), stdin)) {
  126.         fprintf(stderr, "A subject is required\n");
  127.         usage();
  128.     }
  129.     if (p = strchr(sbuf, '\n')) *p = '\0';
  130.     subject = sbuf;
  131.     }    
  132.  
  133.     infile = fopen(fname, "rb");
  134.     if (!infile) {
  135.     os_perror(fname);
  136.     exit(1);
  137.     }
  138.  
  139.     if (descfname) {
  140.     descfile = fopen(descfname, "r");
  141.     if (!descfile) {
  142.         os_perror(descfname);
  143.         exit(1);
  144.     }
  145.     }
  146.  
  147.     if (encode(infile, (FILE *)0, fname, descfile, subject, headers,
  148.            maxsize, ctype, outfname)) exit(1);
  149.  
  150.     exit(0);
  151. }
  152.  
  153. usage()
  154. {
  155.     fprintf(stderr, "mpack version %s\n", MPACK_VERSION);
  156.     fprintf(stderr, 
  157. "usage: mpack [-s subj] [-d file] [-m maxsize] [-c content-type] -o output file\n");
  158.     exit(1);
  159. }
  160.  
  161. warn()
  162. {
  163.     abort();
  164. }
  165.