home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / comm / cyberpager-1.5.lha / CyberPager / source / dialer / main.c < prev    next >
C/C++ Source or Header  |  1994-02-07  |  3KB  |  145 lines

  1. #include "dialer.h"
  2.  
  3. /* our memory pool header */
  4. #define POOLSIZE 4096
  5. APTR pool;
  6.  
  7. /* storage for library bases */
  8. struct Library *UtilityBase;
  9. struct Library *PagerSupportBase;
  10. struct Library *OwnDevUnitBase;
  11.  
  12. /* our pager-support.library handle */
  13. APTR ph;
  14.  
  15. LONG openedModem;
  16.  
  17. #define ARG_TEMPLATE "SERVICE/K,MODEM/N/K,LOGLEVEL/N/K"
  18.   enum ReadArgsArray {
  19.       ARG_SERVICE,
  20.       ARG_MODEM,
  21.       ARG_LOGLEVEL,
  22.       ARG_sizeof
  23.   };
  24.  
  25. static int DoArgs(void)
  26. {
  27.     struct RDArgs *RArgs;
  28.     STRPTR ArgArray[ARG_sizeof];
  29.     LONG modem, modemStart;
  30.     int result;
  31.  
  32.     /* do the stuff needed to call ReadArgs to parse the command line */
  33.     memset(ArgArray, 0, sizeof(ArgArray));
  34.  
  35.     if (RArgs = ReadArgs(ARG_TEMPLATE, (LONG *)&ArgArray, NULL)) {
  36.         if (ArgArray[ARG_LOGLEVEL])
  37.             SetLogLevel(ph, *((LONG *)ArgArray[ARG_LOGLEVEL]));
  38.  
  39.         if (ArgArray[ARG_MODEM])
  40.             modem = *((LONG *)ArgArray[ARG_MODEM]);
  41.         else
  42.             modem = 0;
  43.  
  44.         modemStart = 1;
  45.  
  46.         for (result = 2; result == 2;) {
  47.             if (openedModem = OpenModem(modem, modemStart)) {
  48.                 if (ArgArray[ARG_SERVICE])
  49.                     result = DoOneService(ArgArray[ARG_SERVICE], TRUE);
  50.                 else
  51.                     result = DoAllServices();
  52.  
  53.                 if (result == 2) {
  54.                     modemStart = openedModem + 1;
  55.                     modem = 0;
  56.                 }
  57.  
  58.                 CloseSerial();
  59.             }
  60.             else {
  61.                 STRPTR msg;
  62.  
  63.                 if (modem)
  64.                     msg = "couldn't open modem %ld.";
  65.                 else
  66.                     msg = "unable to obtain a free modem from pool.";
  67.  
  68.                 result = 11;
  69.  
  70.                 ErrorMsg(msg, modem);
  71.                 ULog(ph, -1, msg, modem);
  72.             }
  73.         }
  74.  
  75.         FreeArgs(RArgs);
  76.     }
  77.     else {
  78.         PrintFault(IoErr(), PROGNAME);
  79.         result = 12;
  80.     }
  81.  
  82.     return result;
  83. }
  84.  
  85. void __regargs main(char *cmdptr, int cmdlen, struct WBStartup *WBMsg)
  86. {
  87.     int result;
  88.  
  89.     /* punt if started from Workbench */
  90.     if (WBMsg)
  91.         XCEXIT(20);
  92.  
  93. #ifdef _DEBUG
  94. #define SUPPORT_LIB "pager:libs/pager-support-debug.library"
  95. #else
  96. #define SUPPORT_LIB "pager:libs/pager-support.library"
  97. #endif
  98.  
  99.     if (UtilityBase = OpenLibrary("utility.library", 37)) {
  100.         if (PagerSupportBase = OpenLibrary(SUPPORT_LIB, 0)) {
  101.             if (OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) {
  102.                 if (pool = CreatePool(MEMF_CLEAR, POOLSIZE, POOLSIZE / 2)) {
  103.                     if (ph = AllocPagerHandle(PROGNAME)) {
  104.                         ULog(ph, -1, "startup: version %s", VersionID);
  105.  
  106.                         result = DoArgs();
  107.  
  108.                         FreePagerHandle(ph);
  109.                     }
  110.                     else {
  111.                         ErrorMsg("couldn't allocate support library handle.");
  112.                         result = 15;
  113.                     }
  114.  
  115.                     DeletePool(pool);
  116.                 }
  117.                 else {
  118.                     ErrorMsg("out of memory!");
  119.                     result = 20;
  120.                 }
  121.  
  122.                 CloseLibrary(OwnDevUnitBase);
  123.             }
  124.             else {
  125.                 ErrorMsg("couldn't open %s.\n", ODU_NAME);
  126.                 result = 20;
  127.             }
  128.  
  129.             CloseLibrary(PagerSupportBase);
  130.         }
  131.         else {
  132.             ErrorMsg("couldn't open %s.\n", SUPPORT_LIB);
  133.             result = 20;
  134.         }
  135.  
  136.         CloseLibrary(UtilityBase);
  137.     }
  138.     else {
  139.         ErrorMsg("couldn't open %s.\n", "utility.library");
  140.         result = 20;
  141.     }
  142.  
  143.     XCEXIT(result);
  144. }
  145.