home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / seyon197.tz / seyon197 / seyon / SeSubsX.c < prev    next >
C/C++ Source or Header  |  1993-02-20  |  6KB  |  261 lines

  1.  
  2. /*
  3.  * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
  4.  * Saggaf. All rights reserved.
  5.  *
  6.  * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
  7.  * statement of rights and permissions for this program.
  8.  */
  9.  
  10. #include <time.h>
  11.  
  12. #include <X11/Intrinsic.h>
  13. #include <X11/StringDefs.h>
  14.  
  15. #include "seyon.h"
  16. #include "SeDecl.h"
  17.  
  18. extern char    *strsqtok();
  19. extern int GetModemStat();
  20.  
  21. struct child_info {
  22.   int             exit_status;
  23.   char            msg[80];
  24. };
  25.  
  26. int             seyon_message_up = 0;
  27.  
  28. void
  29. UpdateStatusBox(clientData)
  30.      XtPointer       clientData;
  31. {
  32.   static Widget *statusWidget;
  33.   /* All members of oldState are guaranteed to be initialized to False
  34.      since the array is declared static, similarly for online */
  35.   static Boolean online, oldState[NUM_MDM_STAT];
  36.   Boolean newState;
  37.   char buf[10];
  38.   static int stat[NUM_MDM_STAT] = {MDM_DCD, MDM_DTR, MDM_DSR, MDM_RTS, 
  39.                                      MDM_CTS, MDM_RNG};
  40.   int modemStat, i;
  41.   static time_t startTime, oldOnlineTime = 0;
  42.   time_t onlineTime = 0;
  43.  
  44.   if (clientData)
  45.     statusWidget = (Widget*)clientData;
  46.  
  47.   if ((modemStat = GetModemStat()) >= 0)
  48.     for (i = 0; i < 6; i++)
  49.       if ((newState = (Boolean)((modemStat & stat[i]) ? True : False)) != 
  50.           oldState[i])
  51.         SeSetUnsetToggle(statusWidget[i], (oldState[i] = newState));
  52.   
  53.   if (online == False) {
  54.     onlineTime = 0;
  55.     startTime = time((time_t*)0);
  56.   }
  57.   if ((online = oldState[0]))
  58.     onlineTime = (time((time_t*)0) - startTime) / 60;
  59.  
  60.   if (onlineTime != oldOnlineTime) {
  61.     oldOnlineTime = onlineTime;
  62.     sprintf(buf, "%02d:%02d", onlineTime / 60, onlineTime % 60);
  63.     SeSetLabel(statusWidget[0], buf);
  64.   }
  65.  
  66.   if (clientData)
  67.     XtAppAddTimeOut(app_con, qres.modemStatusInterval * 1000, 
  68.                     UpdateStatusBox, clientData);
  69. }
  70.  
  71. void
  72. FunMessage(client_data)
  73.      XtPointer       client_data;
  74. {
  75.   static int      msg_index = 0;
  76.   String          msg;
  77.   char            vermsg[SM_BUF];
  78.  
  79.   if (seyon_message_up <= 0) {
  80.  
  81.     msg = qres.funMessages[msg_index++];
  82.     if (msg == NULL) {
  83.       msg_index = 0;
  84.       sprintf(vermsg, "Welcome to Seyon version %s%d", VERSION, REVISION);
  85.       msg = vermsg;
  86.     }
  87.  
  88.     SetStatusMessage(msg);
  89.   }
  90.  
  91.   seyon_message_up--;
  92.  
  93.   XtAppAddTimeOut((XtAppContext) client_data,
  94.           qres.funMessagesInterval * 1000, FunMessage, client_data);
  95. }
  96.  
  97. void
  98. MonitorChild(client_data)
  99.      XtPointer       client_data;
  100. {
  101.   struct child_info child_info;
  102.  
  103.   read_pipe_data(child_pipe, &child_info, sizeof(child_info));
  104.  
  105.   if (*child_info.msg)
  106.     SeyonMessage(child_info.msg);
  107.  
  108.   switch (child_info.exit_status) {
  109.   case KILL_TERM:
  110.     kill_terminal();
  111.     break;
  112.   case START_TERM:
  113.     start_terminal();
  114.     break;
  115.   case START_AUTO_ZM:
  116.     exec_cmd(qres.zmodemAutoDownloadCommand);
  117.     break;
  118.   case EXIT_PROGRAM:
  119.     s_exit();
  120.     break;
  121.   case SET_MESSAGE:
  122.     break;
  123.   default:
  124.     break;
  125.   }
  126. }
  127.  
  128. void
  129. write_child_info(pd, exit_status, msg)
  130.      int            *pd;
  131.      int             exit_status;
  132.      char           *msg;
  133. {
  134.   struct child_info child_info;
  135.  
  136.   child_info.exit_status = exit_status;
  137.  
  138.   if (msg)
  139.     strcpy(child_info.msg, msg);
  140.   else
  141.     *child_info.msg = '\0';
  142.  
  143.   write_pipe_data(pd, &child_info, sizeof(child_info));
  144. }
  145.  
  146. void
  147. writef_child_info(pd, exit_status, fmt, a, b, c, d)
  148.      int            *pd;
  149.      int             exit_status;
  150.      char           *fmt,
  151.                     *a,
  152.                     *b,
  153.                     *c,
  154.                     *d;
  155. {
  156.   char            buffer[SM_BUF];
  157.  
  158.   sprintf(buffer, fmt, a, b, c, d);
  159.   write_child_info(pd, exit_status, buffer);
  160. }
  161.  
  162. void
  163. SeyonMessage(msg)
  164.      String          msg;
  165. {
  166.   seyon_message_up = 300 / qres.funMessagesInterval;
  167.   SetStatusMessagef("- %s -", msg, "", "");
  168. }
  169.  
  170. void
  171. SeyonMessagef(fmt, a, b, c)
  172.      String          fmt,
  173.                      a,
  174.                      b,
  175.                      c;
  176. {
  177.   char            buf[REG_BUF];
  178.  
  179.   sprintf(buf, fmt, a, b, c);
  180.   SeyonMessage(buf);
  181. }
  182.  
  183. Boolean
  184. read_seyon_file(name, line)
  185.      char           *name,
  186.                     *line[];
  187. {
  188.   FILE           *fp;
  189.  
  190.   if ((fp = open_file(name, qres.defaultDirectory)) == NULL)
  191.     return False;
  192.  
  193.   ReadCommentedFile(fp, line);
  194.   fclose(fp);
  195.  
  196.   return True;
  197. }
  198.  
  199. #define done(value, type) \
  200. { \
  201.   if (toVal->addr != NULL) { \
  202.     if (toVal->size < sizeof(type)) { \
  203.       toVal->size = sizeof(type); \
  204.       return False; \
  205.     } \
  206.     *(type*)(toVal->addr) = (value); \
  207.   } \
  208.   else { \
  209.     static type static_val; \
  210.     static_val = (value); \
  211.     toVal->addr = (XtPointer)&static_val; \
  212.   } \
  213.   toVal->size = sizeof(type); \
  214.   return True; \
  215. }
  216.  
  217. Boolean
  218. CvtStringToStringArray(display, args, num_args, fromVal, toVal,
  219.                converter_data)
  220.      Display        *display;
  221.      XrmValue       *args;
  222.      Cardinal       *num_args;
  223.      XrmValue       *fromVal;
  224.      XrmValue       *toVal;
  225.      XtPointer      *converter_data;
  226. {
  227.   String          fromStr,
  228.                   buf;
  229.   static String   strArr[REG_BUF];
  230.   int             n;
  231.  
  232.   if (*num_args != 0)
  233.     XtAppWarningMsg(app_con, "wrongParameters", "cvtStringToStringArray",
  234.             "XtToolkitError",
  235.         "String to StringArray conversion needs no extra arguments",
  236.             (String *) NULL, (Cardinal *) NULL);
  237.  
  238.   fromStr = (String) fromVal->addr;
  239. /*  buf = XtMalloc((strlen(fromStr)+1) * sizeof(char));
  240.   strcpy(buf, fromStr);*/
  241.   buf = fromStr;
  242.  
  243.   if ((strArr[0] = strsqtok(buf)) == NULL) {
  244. /*    XtFree(buf);*/
  245.     done(NULL, String *);
  246.   }
  247.  
  248.   for (n = 1; n < XtNumber(strArr); n++)
  249.     if ((strArr[n] = strsqtok(NULL)) == NULL)
  250.       done(strArr, String *);
  251.  
  252.   XtAppWarningMsg(app_con, "tooManyStrings", "cvtStringToStringArray",
  253.           "XtToolkitError",
  254.        "Too many strings specified for String to StringArray converter",
  255.           (String *) NULL, (Cardinal *) NULL);
  256.   strArr[--n] = NULL;
  257.   done(strArr, String *);
  258. }
  259.  
  260. #undef done
  261.