home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / MTAconsole / drive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  9.6 KB  |  348 lines

  1. /* drive.c: driving routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/MTAconsole/RCS/drive.c,v 6.0 1991/12/18 20:26:48 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/MTAconsole/RCS/drive.c,v 6.0 1991/12/18 20:26:48 jpo Rel $
  9.  *
  10.  * $Log: drive.c,v $
  11.  * Revision 6.0  1991/12/18  20:26:48  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include    "console.h"
  19.  
  20. #ifdef    notdef
  21. #include    "IntrinsicP.h"
  22. #include    "TranslateI.h"
  23. #include    "ConvertI.h"
  24. #include    "InitialI.h"
  25. #endif
  26. #include    <sys/stat.h>
  27. #include    <pwd.h>
  28.  
  29. struct stat    statbuf;
  30. #define MAXMTAS        10    /* shouldn't get anything longer than that ? */
  31.  
  32. #define    DEFAULT_NORMALFONT    "*-medium-r-normal--14-*"
  33. #define DEFAULT_ACTIVEFONT    "*-bold-r-normal--14-*"
  34. #define DEFAULT_DISABLEDFONT    "*-medium-i-normal--14-*"
  35.  
  36. typedef struct _cmdLineResources {
  37.     int    percentage;
  38.     int    lowerbound;
  39.     int    totalnumber;
  40.     int    totalvolume;
  41.     int    maxvert;
  42.     Boolean    confirm;
  43.     Boolean    ukorder;
  44.     Boolean    compat;
  45.     Boolean    ignoreInactiveInbounds;
  46.     int    ncolours;
  47.     char    *connectHost;
  48.     char    *heuristic;
  49.     XFontStruct    *defaultFont;
  50.     char    *refresh;
  51.     char    *inactive;
  52. } CmdLineResources;
  53.  
  54. static CmdLineResources cmdLine_resources;
  55.  
  56. static XtResource resources[] = {
  57. {"xtDefaultFont", "XtDefaultFont", XtRFontStruct, sizeof(XFontStruct *),
  58.      XtOffset(struct _cmdLineResources *, defaultFont),
  59.      XtRImmediate, (caddr_t) 0},
  60. {"percentage", "Percentage", XtRInt, sizeof(int),
  61.      XtOffset(struct _cmdLineResources *, percentage),
  62.      XtRImmediate, (caddr_t) 0},
  63. {"lowerbound", "Lowerbound", XtRInt, sizeof(int),
  64.      XtOffset(struct _cmdLineResources *, lowerbound),
  65.      XtRImmediate, (caddr_t) 0},
  66. {"totalnumber", "Totalnumber", XtRInt, sizeof(int),
  67.      XtOffset(struct _cmdLineResources *, totalnumber),
  68.      XtRImmediate, (caddr_t) 0},
  69. {"totalvolume", "Totalvolume", XtRInt, sizeof(int),
  70.      XtOffset(struct _cmdLineResources *, totalvolume),
  71.      XtRImmediate, (caddr_t) 0},
  72. {"maxvert", "Maxvert", XtRInt, sizeof(int),
  73.      XtOffset(struct _cmdLineResources *, maxvert),
  74.      XtRImmediate, (caddr_t) 0},
  75. {"confirm", "Confirm", XtRBoolean, sizeof(Boolean),
  76.      XtOffset(struct _cmdLineResources *, confirm),
  77.      XtRImmediate, (caddr_t) TRUE},
  78. {"ukorder", "UkOrder", XtRBoolean, sizeof(Boolean),
  79.      XtOffset(struct _cmdLineResources *, ukorder),
  80.      XtRImmediate, (caddr_t) FALSE},
  81. {"ncolours", "Ncolours", XtRInt, sizeof(int),
  82.      XtOffset(struct _cmdLineResources *, ncolours),
  83.      XtRImmediate, (caddr_t) 0},
  84. {"connectHost", "ConnectHost", XtRString, sizeof(String),
  85.      XtOffset(struct _cmdLineResources *, connectHost),
  86.      XtRImmediate, (caddr_t) NULLCP},
  87. {"compat", "Compat", XtRBoolean, sizeof(Boolean),
  88.      XtOffset(struct _cmdLineResources *, compat),
  89.      XtRImmediate, (caddr_t) FALSE},
  90. {"ignoreInactiveInbounds", "IgnoreInactiveInbounds", XtRBoolean, sizeof(Boolean),
  91.      XtOffset(struct _cmdLineResources *, ignoreInactiveInbounds),
  92.      XtRImmediate, (caddr_t) FALSE},
  93. {"heuristic", "Heuristic", XtRString, sizeof(String),
  94.      XtOffset(struct _cmdLineResources *, heuristic),
  95.      XtRImmediate, (caddr_t) NULLCP},
  96. {"refresh", "Refresh", XtRString, sizeof(String),
  97.      XtOffset(struct _cmdLineResources *, refresh),
  98.      XtRImmediate, (caddr_t) NULLCP},
  99. {"inactiveTime", "InactiveTime", XtRString, sizeof(String),
  100.      XtOffset(struct _cmdLineResources *, inactive),
  101.      XtRImmediate, (caddr_t) NULLCP},
  102. };
  103.  
  104. static XrmOptionDescRec options[] = {
  105. {"-percentage",    "percentage",    XrmoptionSepArg,    0},
  106. {"-lowerbound",    "lowerbound",    XrmoptionSepArg,    0},
  107. {"-number", "totalnumber",    XrmoptionSepArg,    0},
  108. {"-volume", "totalvolume",    XrmoptionSepArg,    0},
  109. {"-downLines", "maxvert",    XrmoptionSepArg,    0},
  110. {"-NoConfirm", "confirm",    XrmoptionNoArg,        "False"},
  111. {"-ukorder", "ukorder",        XrmoptionNoArg,        "True"},
  112. {"-colours", "ncolours",    XrmoptionSepArg,    0},
  113. {"-Queue", "connectHost",    XrmoptionSepArg,    NULLCP},
  114. {"-compat", "compat",        XrmoptionNoArg,     "True"},
  115. {"-ignoreInactiveInbounds", "ignoreInactiveInbounds", XrmoptionNoArg,    "True"},
  116. {"-heuristic", "heuristic",    XrmoptionSepArg,    NULLCP},
  117. {"-refresh", "refresh",        XrmoptionSepArg,    NULLCP},
  118. {"-inactiveTime", "inactiveTime",XrmoptionSepArg,    NULLCP},
  119. };
  120.  
  121. XtAppContext    appContext;
  122. Display        *disp;
  123. char        *hostname,
  124.         tailorfile[MAXPATHLENGTH];
  125. int        confirm = TRUE,
  126.         uk_order = FALSE,
  127.         doConnect = FALSE,
  128.         userConnected = FALSE,
  129.         autoRefresh = TRUE,
  130.         compat = FALSE,
  131.         displayInactIns = TRUE,
  132.         autoReconnect = TRUE,
  133.         auth = FALSE,
  134.         lower_bound_mtas,
  135.         percent;
  136. Heuristic    heuristic;
  137. State        connectState = notconnected;
  138. Authentication  authentication = limited;
  139. char        *Qinformation = NULLCP,
  140.         *Qversion = NULLCP;
  141. extern unsigned long    timeoutFor, inactiveFor;
  142. time_t        currentTime;
  143. XFontStruct    *disabledFont = NULL,
  144.         *activeFont = NULL,
  145.         *normalFont = NULL,
  146.         *defaultFont = NULL;
  147.  
  148. static void general_initialise();
  149. extern Widget    header, error, top;
  150. #define        WAIT_CONNECTION        "Please wait for connection to the queue manager"
  151.  
  152. char    *myname;
  153. char    password[100],
  154.     username[100];
  155.  
  156. extern double    ub_total_number, ub_total_volume;
  157. extern ConnectRetry();
  158.  
  159. main(argc, argv)
  160. int    argc;
  161. char    **argv;
  162. {
  163.     int    uid;
  164.     struct passwd *pwd;
  165.     uid = getuid();
  166.     pwd = getpwuid(uid);
  167.     strcpy(username, pwd->pw_name);
  168.     strcpy(password, "dummy");
  169.     strcpy(tailorfile,".MTAconsole");
  170.     if ((myname = rindex (argv[0], '/')) != NULL)
  171.         myname++;
  172.     if (myname == NULL || *myname == NULL)
  173.         myname = argv[0];
  174.  
  175.     fillin_passwdpep(username, NULLCP, 0);
  176.     general_initialise(argc, argv);
  177.     initiate_assoc(argc, argv);
  178.     create_widgets(disp, appContext);
  179.     
  180.     SetColours(disp, XtWindow(top));
  181.     if (doConnect == TRUE) {
  182.         XtVaSetValues(header,
  183.               XtNlabel, WAIT_CONNECTION,
  184.               NULL);
  185.         InitConnectTimeOut();
  186.     }
  187.     XtAppMainLoop(appContext);
  188. }
  189.  
  190. #define        DEFAULT_MAX_BORDER        5
  191. #define     DEFAULT_NUM_COLORS         10
  192. #define        DEFAULT_UL_MAX_LINES        4
  193. int    max_chan_border = DEFAULT_MAX_BORDER,
  194.     max_mta_border = DEFAULT_MAX_BORDER,
  195.     max_msg_border = DEFAULT_MAX_BORDER;
  196. int     num_colors = DEFAULT_NUM_COLORS;
  197. int    max_horiz_mtas,
  198.     max_vert_lines;
  199.  
  200. extern time_t    parsetime();
  201. extern void    advise();
  202.  
  203. static void general_initialise(argc, argv)
  204. int     argc;
  205. char    **argv;
  206. {
  207.     char    buf[BUFSIZ];
  208.     Arg    arg[1];
  209.     extern int optind;
  210.     extern char *optarg;
  211.     extern Widget    top;
  212.  
  213.     gethostname(buf,BUFSIZ);
  214.     hostname = strdup(buf);
  215.  
  216.     isodetailor(myname, 1);
  217.  
  218.     XtToolkitInitialize();
  219.  
  220.     appContext = XtCreateApplicationContext();
  221.  
  222.     disp = XtOpenDisplay(appContext,
  223.                 (String) NULL,
  224.                 (String) myname,
  225.                 (String) APPLICATION_CLASS,
  226.                  options, XtNumber(options),
  227.                 &argc,
  228.                 argv);
  229.     if (disp == NULL) {
  230.         printf("%s\n", "unable to open display");
  231.             exit(1);
  232.     }
  233.     /* to get round bug in XtRemoveInput */
  234.     XtRemoveInput(XtAppAddInput(appContext,
  235.                     0,
  236.                     XtInputReadMask,
  237.                     ConnectRetry,
  238.                     NULL));
  239.  
  240.     XtSetArg(arg[0], XtNinput, True);
  241.     /* create top level */
  242.     top = XtAppCreateShell(myname,
  243.                    APPLICATION_CLASS,
  244.                    applicationShellWidgetClass,
  245.                    disp,
  246.                    arg,
  247.                    0);
  248.  
  249.     
  250.     if (DisplayCells (disp, DefaultScreen(disp)) <= 2)
  251.         num_colors = 1;
  252.     else 
  253.         max_chan_border = max_mta_border = 2;
  254.  
  255.     max_horiz_mtas = MAXMTAS;
  256.     max_vert_lines = DEFAULT_UL_MAX_LINES;
  257.     heuristic = line;
  258.     lower_bound_mtas = 20;
  259.     percent = 50;
  260.  
  261.     XtGetApplicationResources (top, &cmdLine_resources,
  262.                    resources, XtNumber(resources), NULL, 0);
  263.     
  264.  
  265.     if (cmdLine_resources.defaultFont) {
  266.         defaultFont = cmdLine_resources.defaultFont;
  267.     }
  268.  
  269.     if (cmdLine_resources.percentage) {
  270.         percent = cmdLine_resources.percentage;
  271.     }
  272.     if (cmdLine_resources.lowerbound) {
  273.         lower_bound_mtas = cmdLine_resources.lowerbound;
  274.     }
  275.     if (cmdLine_resources.totalnumber)
  276.         ub_total_number = cmdLine_resources.totalnumber;
  277.     if (cmdLine_resources.totalvolume)
  278.         ub_total_volume = cmdLine_resources.totalvolume;
  279.     if (cmdLine_resources.maxvert)
  280.         max_vert_lines = cmdLine_resources.maxvert;
  281.     confirm = cmdLine_resources.confirm;
  282.     uk_order = cmdLine_resources.ukorder;
  283.     if (cmdLine_resources.ncolours)
  284.         num_colors = cmdLine_resources.ncolours;
  285.     if (cmdLine_resources.connectHost) {
  286.         doConnect = TRUE;
  287.         hostname = strdup(cmdLine_resources.connectHost);
  288.     }
  289.     compat = cmdLine_resources.compat;
  290.     displayInactIns = (cmdLine_resources.ignoreInactiveInbounds == TRUE) ?
  291.         FALSE : TRUE;
  292.     if (cmdLine_resources.heuristic != NULLCP) {
  293.         if (lexequ(cmdLine_resources.heuristic, "all") == 0)
  294.             heuristic = all;    
  295.         else if (lexnequ(cmdLine_resources.heuristic, 
  296.                 "percent", strlen("percent")) == 0)
  297.             heuristic = percentage;
  298.         else if (lexequ(cmdLine_resources.heuristic,
  299.                  "line") == 0)
  300.             heuristic = line;
  301.         else if (lexequ(cmdLine_resources.heuristic, "mtaonly") == 0
  302.              || lexequ(cmdLine_resources.heuristic, "chanonly") == 0)
  303.             heuristic = chanonly;
  304.     }
  305.     if (cmdLine_resources.refresh != NULLCP) 
  306.         settimeoutFor(cmdLine_resources.refresh);
  307.     if (cmdLine_resources.inactive != NULLCP)
  308.         inactiveFor = parsetime(cmdLine_resources.inactive) * 1000;
  309.     setfonts();
  310. }
  311.  
  312. XFontStruct    *get_three_choice_font(font, one, two, three)
  313. char    *font, *one, *two, *three;
  314. {
  315.     char    *retstr;
  316.     XFontStruct    *retfont;
  317.  
  318.     if ((retstr = XGetDefault(disp, one, font)) != NULLCP
  319.         && (retfont = XLoadQueryFont(disp, retstr)) != NULL)
  320.         return retfont;
  321.     if ((retstr = XGetDefault(disp, two, font)) != NULLCP
  322.         && (retfont = XLoadQueryFont(disp, retstr)) != NULL)
  323.         return retfont;
  324.     if ((retfont = XLoadQueryFont(disp, three)) != NULL)
  325.         return retfont;
  326.     if (defaultFont == NULL) {
  327.         printf("Unable to load font '%s'\n", font);
  328.         exit(0);
  329.     } 
  330.     return defaultFont;
  331. }
  332.     
  333. setfonts ()
  334. {
  335.     normalFont = get_three_choice_font("normalfont",
  336.                        myname,
  337.                        APPLICATION_CLASS,
  338.                        DEFAULT_NORMALFONT);
  339.     activeFont = get_three_choice_font("activefont",    
  340.                        myname,
  341.                        APPLICATION_CLASS,
  342.                        DEFAULT_NORMALFONT);
  343.     disabledFont = get_three_choice_font("disabledfont",
  344.                          myname,
  345.                          APPLICATION_CLASS,
  346.                          DEFAULT_NORMALFONT);
  347. }    
  348.