home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / disk / misc / TransADF.lha / TransADF / Source / args.c next >
Encoding:
C/C++ Source or Header  |  1998-10-05  |  3.0 KB  |  99 lines

  1. /* args.c - Collect program arguments
  2. ** Copyright (C) 1998 Karl J. Ots
  3. ** 
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include <dos/rdargs.h>
  21. #include <clib/dos_protos.h>
  22.  
  23. #include <string.h>
  24.  
  25. #include "args.h"
  26.  
  27. const char TA_Template[] = "\
  28. DRIVE/A,FILE/A,S=START/N,E=END/N,W=WRITE/S,V=VERIFY/S,F=FORMAT/S,\
  29. Z=ZLIB/S,G=GZIP/S,P=PKZIP/S,N=NAME/K,L=LEVEL/N,A=ADD/S";
  30.  
  31. struct TA_RDArgs {
  32.   STRPTR  DRIVE;
  33.   STRPTR  FILE;
  34.   ULONG  *START;
  35.   ULONG  *END;
  36.   ULONG   WRITE;
  37.   ULONG   VERIFY;
  38.   ULONG   FORMAT;
  39.   ULONG   ZLIB;
  40.   ULONG   GZIP;
  41.   ULONG   PKZIP;
  42.   STRPTR  NAME;
  43.   ULONG  *LEVEL;
  44.   ULONG   ADD;
  45. };
  46.  
  47.  
  48. /*
  49. ** Collect the progam arguments.
  50. */
  51. struct TA_Args *getArgs (void)
  52. {
  53.   static struct TA_Args taArgs;
  54.   struct RDArgs *rdargs;
  55.   struct TA_RDArgs taRDArgs = {NULL,  NULL,  NULL,  NULL, FALSE, FALSE, FALSE,
  56.                                FALSE, FALSE, FALSE, NULL, NULL,  FALSE};
  57.   
  58.   
  59.   /* Analyse arguments */
  60.   rdargs = ReadArgs (TA_Template, (ULONG *)&taRDArgs, NULL);
  61.   if (!rdargs) return NULL;
  62.   
  63.   /* Fill in the defauts */
  64.   taArgs.Drive     = NULL;
  65.   taArgs.File      = NULL;
  66.   taArgs.Start     = 0;
  67.   taArgs.End       = -1;
  68.   taArgs.WriteDisk = FALSE;
  69.   taArgs.Verify    = FALSE;
  70.   taArgs.Format    = FALSE;
  71.   taArgs.ZLib      = FALSE;
  72.   taArgs.GZip      = FALSE;
  73.   taArgs.PKZip     = FALSE;
  74.   taArgs.PKZAdd    = FALSE;
  75.   taArgs.OrigName  = NULL;
  76.   taArgs.Level     = 6;
  77.   
  78.   /* Copy arguments into the 'real' structure if required          */
  79.   /* We'll assume that strdup() always works -- dumb but easier :) */
  80.   if (taRDArgs.DRIVE)  taArgs.Drive     = strdup (taRDArgs.DRIVE);
  81.   if (taRDArgs.FILE)   taArgs.File      = strdup (taRDArgs.FILE);
  82.   if (taRDArgs.START)  taArgs.Start     = *(taRDArgs.START);
  83.   if (taRDArgs.END)    taArgs.End       = *(taRDArgs.END);
  84.   if (taRDArgs.WRITE)  taArgs.WriteDisk = TRUE;
  85.   if (taRDArgs.VERIFY) taArgs.Verify    = TRUE;
  86.   if (taRDArgs.FORMAT) taArgs.Format    = TRUE;
  87.   if (taRDArgs.ZLIB)   taArgs.ZLib      = TRUE;
  88.   if (taRDArgs.GZIP)   taArgs.GZip      = TRUE;
  89.   if (taRDArgs.PKZIP)  taArgs.PKZip     = TRUE;
  90.   if (taRDArgs.ADD)    taArgs.PKZAdd    = TRUE;
  91.   if (taRDArgs.NAME)   taArgs.OrigName  = strdup (taRDArgs.NAME);
  92.   if (taRDArgs.LEVEL)  taArgs.Level     = *(taRDArgs.LEVEL);
  93.   
  94.   /* Get rid of the temporary stuff */
  95.   FreeArgs (rdargs);
  96.   
  97.   return &taArgs;
  98. }
  99.