home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / mpackppc-wos / src / arcpk.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  4KB  |  174 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. /* this is almost exactly the same as dospk.c */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <errno.h>
  31. #include "version.h"
  32. #include "xmalloc.h"
  33.  
  34. #define MAXADDRESS 100
  35.  
  36. /* dummy defn, since arcos.c calls this function */
  37. char *getParam(cParams, key) {
  38.     return;
  39. }
  40.  
  41. extern int optind;
  42. extern char *optarg;
  43.  
  44. main(argc, argv)
  45. int argc;
  46. char **argv;
  47. {
  48.     int opt;
  49.     char *fname = 0;
  50.     char *subject = 0;
  51.     char *descfname = 0;
  52.     long maxsize = 0;
  53.     char *outfname = 0;
  54.     char *ctype = 0;
  55.     char *headers = 0;
  56.     int i;
  57.     char *p;
  58.     char sbuf[1024];
  59.     char fnamebuf[4096];
  60.     int part;
  61.     FILE *infile;
  62.     FILE *descfile = 0;
  63.  
  64.     if ((p = getenv("SPLITSIZE")) && *p >= '0' && *p <= '9') {
  65.     maxsize = atoi(p);
  66.     }
  67.  
  68.     while ((opt = getopt(argc, argv, "s:d:m:c:o:n:")) != EOF) {
  69.     switch (opt) {
  70.     case 's':
  71.         subject = optarg;
  72.         break;
  73.  
  74.     case 'd':
  75.         descfname = optarg;
  76.         break;
  77.  
  78.     case 'm':
  79.         maxsize = atol(optarg);
  80.         break;
  81.  
  82.     case 'c':
  83.         ctype = optarg;
  84.         break;
  85.  
  86.     case 'o':
  87.         outfname = optarg;
  88.         break;
  89.  
  90.     default:
  91.         usage();
  92.  
  93.     }
  94.     }
  95.  
  96.     if (ctype) {
  97.     if (!cistrncmp(ctype, "text/", 5)) {
  98.         fprintf(stderr, "This program is not appropriate for encoding textual data\n");
  99.         exit(1);
  100.     }
  101.     if (cistrncmp(ctype, "application/", 12) && cistrncmp(ctype, "audio/", 6) &&
  102.         cistrncmp(ctype, "image/", 6) && cistrncmp(ctype, "video/", 6)) {
  103.         fprintf(stderr, "Content type must be subtype of application, audio, image, or video\n");
  104.         exit(1);
  105.     }
  106.     }
  107.  
  108.     if (!outfname) {
  109.     fprintf(stderr, "The -o switch is required\n");
  110.     usage();
  111.     }
  112.  
  113.     if (optind == argc) {
  114.     fprintf(stderr, "An input file must be specified\n");
  115.     usage();
  116.     }
  117.     fname = argv[optind++];
  118.     for (p = fname; *p; p++) {
  119.     if (isupper(*p)) *p = tolower(*p);
  120.     }
  121.  
  122.     /* Must have -o */
  123.     if (optind != argc) {
  124.     fprintf(stderr, "Too many arguments\n");
  125.     usage();
  126.     }
  127.  
  128.     if (!subject) {
  129.     fputs("Subject: ", stdout);
  130.     fflush(stdout);
  131.     if (!fgets(sbuf, sizeof(sbuf), stdin)) {
  132.         fprintf(stderr, "A subject is required\n");
  133.         usage();
  134.     }
  135.     if (p = strchr(sbuf, '\n')) *p = '\0';
  136.     subject = sbuf;
  137.     }
  138.  
  139.     infile = fopen(fname, "rb");
  140.     if (!infile) {
  141.     os_perror(fname);
  142.     exit(1);
  143.     }
  144.  
  145.     if (descfname) {
  146.     descfile = fopen(descfname, "r");
  147.     if (!descfile) {
  148.         os_perror(descfname);
  149.         exit(1);
  150.     }
  151.     }
  152.  
  153.     if (encode(infile, (FILE *)0, fname, descfile, subject, headers,
  154.            maxsize, ctype, outfname)) exit(1);
  155.  
  156.     exit(0);
  157. }
  158.  
  159. usage()
  160. {
  161.     fprintf(stderr, "mpack version %s\n", MPACK_VERSION);
  162. #ifdef TEST_VERSION
  163.     fprintf(stderr, "*** Arc "TEST_VERSION".  Report problems to olly@mantis.co.uk ***\n");
  164. #endif
  165.     fprintf(stderr,
  166. "usage: mpack [-s subj] [-d file] [-m maxsize] [-c content-type] -o output file\n");
  167.     exit(1);
  168. }
  169.  
  170. warn()
  171. {
  172.     abort();
  173. }
  174.