home *** CD-ROM | disk | FTP | other *** search
- #include "dialer.h"
-
- /* our memory pool header */
- #define POOLSIZE 4096
- APTR pool;
-
- /* storage for library bases */
- struct Library *UtilityBase;
- struct Library *PagerSupportBase;
- struct Library *OwnDevUnitBase;
-
- /* our pager-support.library handle */
- APTR ph;
-
- LONG openedModem;
-
- #define ARG_TEMPLATE "SERVICE/K,MODEM/N/K,LOGLEVEL/N/K"
- enum ReadArgsArray {
- ARG_SERVICE,
- ARG_MODEM,
- ARG_LOGLEVEL,
- ARG_sizeof
- };
-
- static int DoArgs(void)
- {
- struct RDArgs *RArgs;
- STRPTR ArgArray[ARG_sizeof];
- LONG modem, modemStart;
- int result;
-
- /* do the stuff needed to call ReadArgs to parse the command line */
- memset(ArgArray, 0, sizeof(ArgArray));
-
- if (RArgs = ReadArgs(ARG_TEMPLATE, (LONG *)&ArgArray, NULL)) {
- if (ArgArray[ARG_LOGLEVEL])
- SetLogLevel(ph, *((LONG *)ArgArray[ARG_LOGLEVEL]));
-
- if (ArgArray[ARG_MODEM])
- modem = *((LONG *)ArgArray[ARG_MODEM]);
- else
- modem = 0;
-
- modemStart = 1;
-
- for (result = 2; result == 2;) {
- if (openedModem = OpenModem(modem, modemStart)) {
- if (ArgArray[ARG_SERVICE])
- result = DoOneService(ArgArray[ARG_SERVICE], TRUE);
- else
- result = DoAllServices();
-
- if (result == 2) {
- modemStart = openedModem + 1;
- modem = 0;
- }
-
- CloseSerial();
- }
- else {
- STRPTR msg;
-
- if (modem)
- msg = "couldn't open modem %ld.";
- else
- msg = "unable to obtain a free modem from pool.";
-
- result = 11;
-
- ErrorMsg(msg, modem);
- ULog(ph, -1, msg, modem);
- }
- }
-
- FreeArgs(RArgs);
- }
- else {
- PrintFault(IoErr(), PROGNAME);
- result = 12;
- }
-
- return result;
- }
-
- void __regargs main(char *cmdptr, int cmdlen, struct WBStartup *WBMsg)
- {
- int result;
-
- /* punt if started from Workbench */
- if (WBMsg)
- XCEXIT(20);
-
- #ifdef _DEBUG
- #define SUPPORT_LIB "pager:libs/pager-support-debug.library"
- #else
- #define SUPPORT_LIB "pager:libs/pager-support.library"
- #endif
-
- if (UtilityBase = OpenLibrary("utility.library", 37)) {
- if (PagerSupportBase = OpenLibrary(SUPPORT_LIB, 0)) {
- if (OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) {
- if (pool = CreatePool(MEMF_CLEAR, POOLSIZE, POOLSIZE / 2)) {
- if (ph = AllocPagerHandle(PROGNAME)) {
- ULog(ph, -1, "startup: version %s", VersionID);
-
- result = DoArgs();
-
- FreePagerHandle(ph);
- }
- else {
- ErrorMsg("couldn't allocate support library handle.");
- result = 15;
- }
-
- DeletePool(pool);
- }
- else {
- ErrorMsg("out of memory!");
- result = 20;
- }
-
- CloseLibrary(OwnDevUnitBase);
- }
- else {
- ErrorMsg("couldn't open %s.\n", ODU_NAME);
- result = 20;
- }
-
- CloseLibrary(PagerSupportBase);
- }
- else {
- ErrorMsg("couldn't open %s.\n", SUPPORT_LIB);
- result = 20;
- }
-
- CloseLibrary(UtilityBase);
- }
- else {
- ErrorMsg("couldn't open %s.\n", "utility.library");
- result = 20;
- }
-
- XCEXIT(result);
- }
-