home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / apilot.lha / APilot / APilot_Ser / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-03  |  4.1 KB  |  135 lines

  1. /***************************************************************************
  2.  *
  3.  * prefs.c -- Parse commandline and set user preferences
  4.  *
  5.  *-------------------------------------------------------------------------
  6.  * Authors: Casper Gripenberg  (casper@alpha.hut.fi)
  7.  *          Kjetil Jacobsen  (kjetilja@stud.cs.uit.no)  
  8.  *
  9.  */
  10.     
  11. #include <dos/dos.h>
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <libraries/dos.h>
  15. #include <intuition/intuition.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22.  
  23. #include "common.h"
  24. #include "prefs_protos.h"
  25. #include "main_protos.h"
  26.  
  27. #define EXTENDED_HELPSTRING "\nAPilot extended help\n"\
  28.   "--------------------------------------------------------------\n"\
  29.   "Authors:\n"\
  30.   "  Casper Gripenberg  (Casper.Gripenberg@hut.fi)\n"\
  31.   "  Kjetil Jacobsen    (kjetilja@stud.cs.uit.no)\n"\
  32.   "==============================================================\n"\
  33.   "Usage: APilot [options]\n"\
  34.   "Where options include:\n"\        
  35.   "      MAPFILE <mapfile>   : Specify a mapfile other than the\n"\ 
  36.   "                            default one.\n"\
  37.   "      SCREENMODE          : Choose screenmode.\n"\
  38.   "                          : (Only available if compiled with DYN_SCR)\n"\
  39.   "      NOSERIAL            : One player only.\n"\
  40.   "      DEVICE <devicename> : Serial device to use.\n"\
  41.   "      UNIT   <unitnumber> : Serial device unit number to use.\n"\
  42.   "      SPEED  <bps>        : Communication speed.\n"\
  43.   "=============================================================\n";
  44.  
  45. #define PREFS_FAIL FreeArgs(RDArgs);\
  46.   FreeDosObject(DOS_RDARGS, RDArgs);\
  47.   FreeVec(Args);\
  48.   cleanExit( RETURN_WARN,\
  49.              "** Failed to allocate space for argument strings.\n" )
  50.  
  51. #ifdef DYN_SCR
  52. static const char *Template = "MF=MAPFILE/K,SM=SCREENMODE/S,NS=NOSERIAL/S,DEVICE/K,UNIT/N/K,SPEED/N/K";
  53. enum { MAPFILE_ARG, SCRNMODE_ARG, NOSER_ARG, DEV_ARG, UNIT_ARG, SPEED_ARG, LAST_ARG };
  54. #else
  55. static const char *Template = "MF=MAPFILE/K,NS=NOSERIAL/S,DEVICE/K,UNIT/N/K,SPEED/N/K";
  56. enum { MAPFILE_ARG, NOSER_ARG, DEV_ARG, UNIT_ARG, SPEED_ARG, LAST_ARG };
  57. #endif
  58.  
  59.  
  60. void 
  61. set_prefs(void)
  62. {
  63.   APTR    *Args;
  64.   struct  RDArgs  *RDArgs;
  65.  
  66.   /*
  67.    * Set default prefs.
  68.    */
  69.   prefs.ser_dev        = DEF_SERIALDEVICE;
  70.   prefs.ser_unitnr     = DEF_SERIALUNIT;
  71.   prefs.ser_bps        = DEF_SERIALBPS;
  72.   prefs.noserial       = FALSE;
  73.   prefs.mapname        = MAPFILE;
  74.   prefs.dpy_modeid     = HIRES|LACE;
  75.   prefs.dpy_autoscroll = 0;
  76.   prefs.dpy_oscan      = OSCAN_STANDARD;    
  77.   prefs.dpy_width      = 641; /* Default values (could really be anything) */
  78.   prefs.dpy_height     = 513;
  79.   prefs.native_mode    = TRUE;
  80.  
  81.     if ((Args = AllocVec((LAST_ARG * sizeof(ULONG)), MEMF_CLEAR))) {
  82.     if ((RDArgs = AllocDosObjectTags(DOS_RDARGS, TAG_DONE))) {
  83.       RDArgs->RDA_ExtHelp = EXTENDED_HELPSTRING;
  84.       if ((ReadArgs((char *)Template, (LONG *)Args, RDArgs))) {
  85.  
  86.         /*
  87.          * A OK so far, now check which arguments have been used.
  88.          */
  89. #ifdef DYN_SCR
  90.         if (Args[SCRNMODE_ARG])
  91.           prefs.native_mode = FALSE;
  92. #endif
  93.         if (Args[MAPFILE_ARG]) {
  94.           if ((prefs.mapname = (char *)
  95.                malloc(strlen(Args[MAPFILE_ARG]) + 1)) == NULL) {
  96.             PREFS_FAIL;
  97.           }
  98.           strcpy(prefs.mapname, Args[MAPFILE_ARG]);
  99.         }
  100.  
  101.         if (Args[NOSER_ARG]) {
  102.           printf("** Noserial not implemented yet.\n");
  103.           prefs.noserial = TRUE;
  104.         }
  105.  
  106.         if (Args[DEV_ARG]) {
  107.           if ((prefs.ser_dev = (char *)
  108.                malloc(strlen(Args[DEV_ARG]) + 1)) == NULL) {
  109.             PREFS_FAIL;
  110.           }
  111.           strcpy(prefs.ser_dev, Args[DEV_ARG]);
  112.         }
  113.  
  114.         if (Args[UNIT_ARG])
  115.           prefs.ser_unitnr = *((ULONG *)Args[UNIT_ARG]);
  116.  
  117.         if (Args[SPEED_ARG])
  118.           prefs.ser_bps = *((ULONG *)Args[SPEED_ARG]);
  119.  
  120.         /*
  121.          * Just for debugging..
  122.          */
  123.         printf("Mapfile: %s\n", prefs.mapname);
  124.         printf("Serdev : %s\n", prefs.ser_dev);
  125.         printf("Serunit: %d\n", prefs.ser_unitnr);
  126.         printf("Serbps : %d\n", prefs.ser_bps);
  127.  
  128.         FreeArgs(RDArgs);
  129.       }
  130.       FreeDosObject(DOS_RDARGS, RDArgs);
  131.     }
  132.     FreeVec(Args);
  133.   }
  134. }
  135.