home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / uupoll068.lha / source / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-03  |  19.4 KB  |  709 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7. #include "cus.h"
  8. #include "defines.h"
  9. #include "lbio.h"
  10. #include "proto.h"
  11. #include "stat.h"
  12.  
  13. /*
  14.     [...]
  15.  
  16.     The second field (Any in the examples above) has been implemented
  17.     for 1.06D and beyond.  There are no spaces anywhere in the field:
  18.  
  19.         Any         the system can be called at any time
  20.  
  21.         Never        the system can never be calleod
  22.  
  23.         hh:mm-hh:mm     any day in the hour range indicated (24hr time)
  24.  
  25.         MoTuWeThFrSaSuhh:mm-hh:mm
  26.                 On the days indicated in the hour range indicated.
  27.  
  28.         <timespec>,<timespec>
  29.         MoTuWeThFr02:00-03:00,SaSu00:00-23:59
  30.                 On the days indicated in the hour range indicated,
  31.                 time specs separated by commas.
  32.     [...]
  33.                                                                             */
  34.  
  35. struct time {
  36.     int hour;
  37.     int min;
  38. };
  39.  
  40. struct date {
  41.     int year;
  42.     int month;
  43.     int day;
  44.     int dow;
  45.     struct time time;
  46. };
  47.  
  48. #define DAYMINS (24*60)
  49. #define DAYSECS (DAYMINS * 60)
  50. #define WEEKMINS (DAYMINS*7)
  51.  
  52. #define MOW_FORBIDDEN   0
  53. #define MOW_PERMITTED   1
  54. #define MOW_ACTIVETIMES 2
  55. #define MOW_CURRENTTIME 3
  56.  
  57. struct TimeInfo {
  58.     struct {
  59.         int type;
  60.         struct date from;
  61.         struct date to;
  62.         struct time total;
  63.         struct time remain;
  64.     } active;
  65.     struct {
  66.         int type;
  67.         struct date from;
  68.         struct date to;
  69.         struct time total;
  70.         struct time in;
  71.     } next;
  72.     int aMOW[WEEKMINS];
  73. };
  74.  
  75. #define WEEKDAY_NUM   7
  76. #define WDAYNAME_NUM  WEEKDAY_NUM
  77. #define WDAYNAME_LEN1 2
  78.  
  79. static char wday_name1[WDAYNAME_NUM][WDAYNAME_LEN1+1] = {
  80.     "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"
  81. };
  82.  
  83. #define SUN 0
  84. #define SAT 6
  85.  
  86. /* time interval times */
  87. #define TYPE_ACTIVE_SPECIFIC     1
  88. #define TYPE_ACTIVE_NOTCURRENTLY 2
  89. #define TYPE_ACTIVE_ALWAYS       3
  90. #define TYPE_ACTIVE_NEVER        4
  91. #define TYPE_NEXT_SPECIFIC       5
  92. #define TYPE_NEXT_ALWAYS         6
  93. #define TYPE_NEXT_NEVER          7
  94.  
  95. #define TYPESTR_ACTIVE_NOTCURRENTLY "-no one currently-"
  96. #define TYPESTR_ACTIVE_ALWAYS       "-always-"
  97. #define TYPESTR_ACTIVE_NEVER        "-never-"
  98. #define TYPESTR_NEXT_ALWAYS         "-always-"
  99. #define TYPESTR_NEXT_NEVER          "-never-"
  100.  
  101. #define MODE_FIRST   1
  102. #define MODE_ANOTHER 2
  103.  
  104.  
  105. static void setti(struct TimeInfo *ti, char *timeentry, int mode)
  106. {
  107.     static time_t t;
  108.     time_t tTMP1, tTMP2;
  109.     struct tm *tm;
  110.     int i,j;
  111.     int nTok;
  112.     char **cppTok;
  113.     char *cp;
  114.     unsigned int days, mincnt, days_o;
  115.     int sh, sm, eh, em, et, st, ct;
  116.     int s_active, e_active, s_next, e_next;
  117.  
  118.  
  119.     if (mode == MODE_FIRST)
  120.         time(&t);
  121.     tm = localtime(&t);
  122.  
  123.     if (mode == MODE_FIRST) {
  124.         for (i=0; i < WEEKMINS; i++)
  125.             ti->aMOW[i] = MOW_FORBIDDEN;
  126.     }
  127.     else
  128.         for (i=0; i < WEEKMINS; i++) {
  129.             if (ti->aMOW[i] == MOW_ACTIVETIMES)
  130.                 ti->aMOW[i] = MOW_PERMITTED;
  131.  
  132.             if (ti->aMOW[i] == MOW_CURRENTTIME)
  133.                 if (ti->active.type == TYPE_ACTIVE_SPECIFIC ||
  134.                     ti->active.type == TYPE_ACTIVE_ALWAYS     )
  135.                     ti->aMOW[i] = MOW_PERMITTED;
  136.                 else
  137.                     ti->aMOW[i] = MOW_FORBIDDEN;
  138.         }
  139.  
  140.  
  141.     if ((nTok = tokenize(&cppTok, timeentry, strlen(timeentry), ",", 0)) != 0) {
  142.         while(*cppTok != NULL) {
  143.             cp = *cppTok++;
  144.  
  145.             if (strcmpi("Never", cp) == 0) {
  146.                 if (mode == MODE_FIRST)
  147.                     for (i=0; i < WEEKMINS; i++)
  148.                         ti->aMOW[i] = MOW_FORBIDDEN;
  149.                 continue;
  150.             }
  151.  
  152.             if (strcmpi("Any", cp) == 0) {
  153.                 for (i=0; i < WEEKMINS; i++)
  154.                     ti->aMOW[i] = MOW_PERMITTED;
  155.                 continue;
  156.             }
  157.  
  158.             days = 0;
  159.             while(isalpha(*cp)) {
  160.                 for (i = 0; i < WDAYNAME_NUM; i++) {
  161.                     if (strnicmp(cp, wday_name1[i], WDAYNAME_LEN1) == 0) {
  162.                         days |= 1L << i;
  163.                         cp += 2;
  164.                     }
  165.                 }
  166.             }
  167.             if (days == 0)    /* not specifying a day explicitely    */
  168.                 days = ~0;    /* means the whole week */
  169.  
  170.             if (sscanf(cp, "%d:%d-%d:%d", &sh, &sm, &eh, &em) != 4)
  171.                 continue;
  172.  
  173.             st = sh*60+sm;
  174.             et = eh*60+em;
  175.  
  176.             if (et < st) {    /* if the interval goes through 00:00    */
  177.                             /* we split it up into two peaces        */
  178.                 /* select all following days */
  179.                 days_o = days << 1;
  180.                 if (days_o & (1L << (SAT+1)))
  181.                     days_o = ((days_o & ~(1L << (SAT+1))) | (1L << SUN));
  182.  
  183.                 for (i = 0; i < WDAYNAME_NUM; i++)
  184.                     if (days_o & (1L << i))
  185.                         for (j = 0; j < et; j++)
  186.                             ti->aMOW[i*DAYMINS+j] = MOW_PERMITTED;
  187.                 eh = 24;
  188.                 em = 0;
  189.                 et = sh*60+sm;
  190.             }
  191.  
  192.             for (i = 0; i < WDAYNAME_NUM; i++)
  193.                 if (days & (1L << i))
  194.                     for (j = st; j < et; j++)
  195.                         ti->aMOW[i*DAYMINS+j] = MOW_PERMITTED;
  196.         }
  197.     }
  198.  
  199.     ct = tm->tm_wday * DAYMINS + tm->tm_hour * 60 + tm->tm_min;
  200.  
  201.     if (ti->aMOW[ct] != MOW_PERMITTED) {
  202.         ti->active.type = TYPE_ACTIVE_NOTCURRENTLY;
  203.     }
  204.     else {
  205.  
  206.         i = ct;
  207.         j = (i-1 < 0) ? WEEKMINS-1 : i-1;
  208.         mincnt = 0;
  209.         while(     ti->aMOW[i] == MOW_PERMITTED
  210.               && ti->aMOW[j] == MOW_PERMITTED
  211.               && mincnt < WEEKMINS           ) {
  212.             ++mincnt;
  213.             i = (i-1 < 0) ? WEEKMINS-1 : i-1;
  214.             j = (i-1 < 0) ? WEEKMINS-1 : i-1;
  215.         }
  216.         s_active = ct - mincnt;
  217.         if (mincnt >= WEEKMINS) {
  218.             ti->active.type = TYPE_ACTIVE_ALWAYS;
  219.         }
  220.         else {
  221.             ti->active.type = TYPE_ACTIVE_SPECIFIC;
  222.             tTMP1 = t - mincnt * 60;
  223.             tm = localtime(&tTMP1);
  224.             ti->active.from.year = tm->tm_year;
  225.             ti->active.from.month = tm->tm_mon+1;
  226.             ti->active.from.day = tm->tm_mday;
  227.             ti->active.from.dow = tm->tm_wday;
  228.             ti->active.from.time.hour = tm->tm_hour;
  229.             ti->active.from.time.min = tm->tm_min;
  230.  
  231.             mincnt = 0;
  232.             i = ct;
  233.             while(   ti->aMOW[i] == MOW_PERMITTED
  234.                   && mincnt < WEEKMINS           ) {
  235.                 ++mincnt;
  236.                 i = (i + 1) % WEEKMINS;
  237.             }
  238.             e_active = ct + mincnt;
  239.             tTMP2 = t + mincnt * 60;
  240.             tm = localtime(&tTMP2);
  241.             ti->active.to.year = tm->tm_year;
  242.             ti->active.to.month = tm->tm_mon+1;
  243.             ti->active.to.day = tm->tm_mday;
  244.             ti->active.to.dow = tm->tm_wday;
  245.             ti->active.to.time.hour = tm->tm_hour;
  246.             ti->active.to.time.min = tm->tm_min;
  247.  
  248.             ti->active.total.hour = ((tTMP2-tTMP1) / 60) / 60;
  249.             ti->active.total.min = ((tTMP2-tTMP1) / 60) % 60;
  250.             ti->active.remain.hour = ((tTMP2-t) / 60) / 60;
  251.             ti->active.remain.min = ((tTMP2-t) / 60) % 60;
  252.         }
  253.     }
  254.  
  255.     if (ti->active.type == TYPE_ACTIVE_ALWAYS) {
  256.         ti->next.type = TYPE_NEXT_ALWAYS;
  257.     }
  258.     else {
  259.         i = (ct + (ti->active.type == TYPE_ACTIVE_SPECIFIC ? mincnt : 0)) % WEEKMINS;
  260.         mincnt = 0;
  261.         while(   ti->aMOW[i] == MOW_FORBIDDEN
  262.               && mincnt < WEEKMINS           ) {
  263.             ++mincnt;
  264.             i = (i + 1) % WEEKMINS;
  265.         }
  266.         if (mincnt >= WEEKMINS) {
  267.             ti->next.type = TYPE_NEXT_NEVER;
  268.             ti->active.type = TYPE_ACTIVE_NEVER;
  269.         }
  270.         else {
  271.             ti->next.type = TYPE_NEXT_SPECIFIC;
  272.             s_next = i;
  273.             tTMP1 = (ti->active.type == TYPE_ACTIVE_SPECIFIC ? tTMP2 : t) + mincnt * 60;
  274.             tm = localtime(&tTMP1);
  275.             ti->next.from.year = tm->tm_year;
  276.             ti->next.from.month = tm->tm_mon+1;
  277.             ti->next.from.day = tm->tm_mday;
  278.             ti->next.from.dow = tm->tm_wday;
  279.             ti->next.from.time.hour = tm->tm_hour;
  280.             ti->next.from.time.min = tm->tm_min;
  281.  
  282.             mincnt = 0;
  283.             while(   ti->aMOW[i] == MOW_PERMITTED
  284.                   && mincnt < WEEKMINS           ) {
  285.                 ++mincnt;
  286.                 i = (i + 1) % WEEKMINS;
  287.             }
  288.             e_next = i;
  289.             tTMP2 = tTMP1 + mincnt * 60;
  290.             tm = localtime(&tTMP2);
  291.             ti->next.to.year = tm->tm_year;
  292.             ti->next.to.month = tm->tm_mon+1;
  293.             ti->next.to.day = tm->tm_mday;
  294.             ti->next.to.dow = tm->tm_wday;
  295.             ti->next.to.time.hour = tm->tm_hour;
  296.             ti->next.to.time.min = tm->tm_min;
  297.  
  298.             ti->next.total.hour = ((tTMP2-tTMP1) / 60) / 60;
  299.             ti->next.total.min = ((tTMP2-tTMP1) / 60) % 60;
  300.             ti->next.in.hour = ((tTMP1-t) / 60) / 60;
  301.             ti->next.in.min = ((tTMP1-t) / 60) % 60;
  302.         }
  303.     }
  304.  
  305.     if (ti->active.type == TYPE_ACTIVE_SPECIFIC) {
  306.         if (s_active < e_active) {
  307.             i = s_active;
  308.             while(i < e_active) {
  309.                 ti->aMOW[i] = MOW_ACTIVETIMES;
  310.                 i = (i + 1) % WEEKMINS;
  311.             }
  312.         }
  313.     }
  314.     if (ti->active.type == TYPE_ACTIVE_ALWAYS) {
  315.         for (i=0; i < WEEKMINS; i++)
  316.             ti->aMOW[i] = MOW_ACTIVETIMES;
  317.     }
  318.  
  319.     ti->aMOW[ct] = MOW_CURRENTTIME;
  320.  
  321.     return;
  322. }
  323.  
  324.  
  325. int calctimes(char *cpLsys, char *cpSystem, struct TimeInfo *ti)
  326. {
  327.     int nTok;
  328.     char **cppTok;
  329.     int mode;
  330.     int rc;
  331.     FILE *fpLsys = NULL;
  332.     char *cpBuf = NULL;
  333.     long wLsys;
  334.     LB *lb = NULL;
  335.     char caTimeentry[256];
  336.  
  337.     if ((fpLsys = fopen(cpLsys, "r")) == NULL)
  338.         CU(FALSE);
  339.     if (fseek(fpLsys, 0L, SEEK_END) == -1L)
  340.         CU(FALSE);
  341.     if ((wLsys = ftell(fpLsys)) == -1L)
  342.         CU(FALSE);
  343.     if (fseek(fpLsys, 0L, SEEK_SET) == -1L)
  344.         CU(FALSE);
  345.     if ((cpBuf = (char *)malloc(wLsys)) == NULL)
  346.         CU(FALSE);
  347.     if ((fread(cpBuf, wLsys, 1, fpLsys) != 1) && ferror(fpLsys))
  348.         CU(FALSE);
  349.     if ((lb = lbopen(cpBuf, cpBuf + wLsys -1)) == NULL)
  350.         CU(FALSE);
  351.     if (lbseek(lb, 0, LBSEEK_SET) == NULL)
  352.         CU(FALSE);
  353.  
  354.     mode = MODE_FIRST;
  355.     do {
  356.         if ((nTok = tokenize(&cppTok, lb->lb_cpLnCur, lb->lb_wLnCur, "     ", 0)) != 0) {
  357.             if (nTok > 5) {
  358.                 if (stricmp(*(cppTok+0), cpSystem) == 0) {
  359.                     strcpy(caTimeentry, *(cppTok+1));
  360.                     setti(ti, caTimeentry, mode);
  361.                     mode = MODE_ANOTHER;
  362.                 }
  363.             }
  364.         }
  365.     } while (lbseek(lb, 1, LBSEEK_CUR));
  366.  
  367.     rc = TRUE;
  368.  
  369.     CUS:
  370.     if (lb)
  371.         lbfree(lb);
  372.     if (fpLsys)
  373.         fclose(fpLsys);
  374.     if (cpBuf)
  375.         free(cpBuf);
  376.     return rc;
  377. }
  378.  
  379.  
  380.  
  381. /*
  382.  
  383.  UUPoll Host Status on angle                        Fri Jun 05 23:39:47 1992
  384.  
  385.  remote host  : cyvaned                                  [|] permitted times
  386.  last polling : successful                               [.] forbidden times
  387.  
  388.  55 .||||||..|..#####.||||||.||||||..|..|||||.||||||.||||||..|..|||||.||||||
  389.  50 .||||||..|..#####.||||||.||||||..|..|||||.||||||.||||||..|..|||||.||||||
  390.  45 .||||||..|..#####.||||||.||||||..|..|||||.||||||.||||||..|..|||||.||||||
  391.  40 .||||||..||.#####.||||||.||||||..||.|||||.||||||.||||||..||.|||||.||||||
  392.  35 .||||||..||.X####.||||||.||||||..||.|||||.||||||.||||||..||.|||||.||||||
  393.  30 .||||||..||.#####.||||||.||||||..||.|||||.||||||.||||||..||.|||||.||||||
  394.  25 ..|||||...|.#####.||||||..|||||...|.|||||.||||||..|||||...|.|||||.||||||
  395.  20 ..|||||...|.#####.||||||..|||||...|.|||||.||||||..|||||...|.|||||.||||||
  396.  15 ..|||||...|.#####.||||||..|||||...|.|||||.||||||..|||||...|.|||||.||||||
  397.  10 ..||.||...||#####.||||||..||.||...|||||||.||||||..||.||...|||||||.||||||
  398.  05 ..||.||...||#####.||||||..||.||...|||||||.||||||..||.||...|||||||.||||||
  399.  00 ..||.||...||#####.||||||..||.||...|||||||.||||||..||.||...|||||||.||||||
  400.                 ^
  401.     123456789012301234567890123456789012301234567890123456789012301234567890
  402.              2   Sat       1         2   Sun       1         2   Mon       1
  403.  
  404.  ACTIVE polling time intervall [#]    NEXT polling time intervall
  405.  from Fri/23:00 to Sat/04:00          from Sat/05:00 to Sat/11:00
  406.  total time 05:00, remaining 04:21    total time 06:00, in 05:21
  407.  
  408. */
  409.  
  410. #define SCREEN_LINES 24
  411. #define SCREEN_COLS  76
  412.  
  413. static char *cpaScreen[SCREEN_LINES] = {
  414.  
  415. /*   0123456789012345678901234567890123456789012345678901234567890123456789012345678
  416.      0         1         2         3         4         5         6         7         */
  417.  
  418.     " UUPoll Host Status on XXXXXXXX       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 00 */
  419.     "                                                                            \n",    /* 01 */
  420.     " remote host  : XXXXXXXX                                 [|] permitted times\n",    /* 02 */
  421.     " last polling : XXXXXXXXXX                               [.] forbidden times\n",    /* 03 */
  422.     "                                                                            \n",    /* 04 */
  423.     " 55 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 05 */
  424.     " 50 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 06 */
  425.     " 45 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 07 */
  426.     " 40 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 08 */
  427.     " 35 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 09 */
  428.     " 30 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 10 */
  429.     " 25 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 11 */
  430.     " 20 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 12 */
  431.     " 15 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 13 */
  432.     " 10 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 14 */
  433.     " 05 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 15 */
  434.     " 00 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 16 */
  435.     "                ^                                                           \n",    /* 17 */
  436.     "    aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",      /* 18 */
  437.     "    bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",    /* 19 */
  438.     "                                                                            \n",    /* 20 */
  439.     " ACTIVE polling time intervall [#]    NEXT polling time intervall           \n",    /* 21 */
  440.     " from XXX/XX:XX to XXX/XX:XX          from XXX/XX:XX to XXX/XX:XX           \n",    /* 22 */
  441.     " total time XX:XX, remaining XX:XX    total time XX:XX, in XX:XX            \n"    /* 23 */
  442. };
  443.  
  444. #define CHARTP_FORBIDDEN '.'
  445. #define CHARTP_PERMITTED '|'
  446. #define CHARTP_ACTIVETIMES '#'
  447. #define CHARTP_CURRENTTIME 'X'
  448.  
  449. #define CHART_X0    4
  450. #define CHART_Y0    16
  451. #define CHART_XNUM  24*3
  452. #define CHART_YNUM  12
  453.  
  454. char chart_map[CHART_XNUM][CHART_YNUM];
  455. char chart_xline1[CHART_XNUM];
  456. char chart_xline2[CHART_XNUM];
  457.  
  458. #define LOCALHOSTFIELD "NodeName"
  459.  
  460. #define WDAYNAME_LEN2 3
  461.  
  462. static char wday_name2[WDAYNAME_NUM][WDAYNAME_LEN2+1] = {
  463.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  464. };
  465.  
  466. void hostinfo(char *cpProgname, char *cpLsys, char *cpConfig, char *cpSystem, int mode)
  467. {
  468.     int i;
  469.     long t;
  470.     struct tm *tm;
  471.     char *cpTmp;
  472.     char caTmp[128];
  473.     char caTmp2[128];
  474.     char *cpEnvvar;
  475.     char caEnvname[256];
  476.     struct TimeInfo *ti = NULL;
  477.     int ch;
  478.     int x,y;
  479.     int h;
  480.     char *cpXl1 = chart_xline1;
  481.     char *cpXl2 = chart_xline2;
  482.  
  483.     if ((ti = (struct TimeInfo *)malloc(sizeof(struct TimeInfo))) == NULL)
  484.         CU2();
  485.  
  486.     (void)time(&t);
  487.     tm = localtime(&t);
  488.  
  489.     sprintf(caTmp, "%s", asctime(tm));
  490.     caTmp[strlen(caTmp)-1] = NUL;
  491.     if (mode == HOSTINFO_LONG)
  492.         sprintf(caTmp2, "%38s", caTmp);
  493.     else
  494.         sprintf(caTmp2, "%-38s", caTmp);
  495.     memcpy(cpaScreen[0]+38, caTmp2, strlen(caTmp2));
  496.  
  497.     if ((cpTmp = getfield(cpConfig, LOCALHOSTFIELD, caTmp)) == NULL)
  498.         cpTmp = "-unknown-";
  499.     else
  500.         truncdomain(cpTmp);
  501.     sprintf(caTmp2, "%-8s", cpTmp);
  502.     memcpy(cpaScreen[0]+23, caTmp2, strlen(caTmp2));
  503.  
  504.     sprintf(caTmp, "%-8s", cpSystem);
  505.     memcpy(cpaScreen[2]+16, caTmp, strlen(caTmp));
  506.  
  507.     sprintf(caEnvname, "%s.STAT.%s", cpProgname, cpSystem);
  508.     if ((cpEnvvar = getenv(caEnvname)) == NULL) {
  509.         cpTmp = "-unknown-";
  510.     }
  511.     else {
  512.         sprintf(caTmp, "%s", strlwr(cpEnvvar));
  513.          cpTmp = caTmp;
  514.     }
  515.     sprintf(caTmp2, "%-10s", cpTmp);
  516.     memcpy(cpaScreen[3]+16, caTmp2, strlen(caTmp2));
  517.  
  518.     if (calctimes(cpLsys, cpSystem, ti)) {
  519.  
  520.         if (ti->active.type == TYPE_ACTIVE_SPECIFIC) {
  521.             sprintf(caTmp, "%03s", wday_name2[ti->active.from.dow]);
  522.             memcpy(cpaScreen[22]+6, caTmp, strlen(caTmp));
  523.             sprintf(caTmp, "%02d:%02d", ti->active.from.time.hour, ti->active.from.time.min);
  524.             memcpy(cpaScreen[22]+10, caTmp, strlen(caTmp));
  525.             sprintf(caTmp, "%03s", wday_name2[ti->active.to.dow]);
  526.             memcpy(cpaScreen[22]+19, caTmp, strlen(caTmp));
  527.             sprintf(caTmp, "%02d:%02d", ti->active.to.time.hour, ti->active.to.time.min);
  528.             memcpy(cpaScreen[22]+23, caTmp, strlen(caTmp));
  529.  
  530.             sprintf(caTmp, "%02d:%02d", ti->active.total.hour, ti->active.total.min);
  531.             memcpy(cpaScreen[23]+12, caTmp, strlen(caTmp));
  532.             sprintf(caTmp, "%02d:%02d", ti->active.remain.hour, ti->active.remain.min);
  533.             memcpy(cpaScreen[23]+29, caTmp, strlen(caTmp));
  534.         }
  535.         else {
  536.             for (i = 1; i < 34; i++) {
  537.                 *(cpaScreen[22]+i) = ' ';
  538.                 *(cpaScreen[23]+i) = ' ';
  539.             }
  540.             if (ti->active.type == TYPE_ACTIVE_NOTCURRENTLY)
  541.                 cpTmp = TYPESTR_ACTIVE_NOTCURRENTLY;
  542.             if (ti->active.type == TYPE_ACTIVE_ALWAYS)
  543.                 cpTmp = TYPESTR_ACTIVE_ALWAYS;
  544.             if (ti->active.type == TYPE_ACTIVE_NEVER)
  545.                 cpTmp = TYPESTR_ACTIVE_NEVER;
  546.             memcpy(cpaScreen[22]+1, cpTmp, strlen(cpTmp));
  547.         }
  548.  
  549.         if (ti->next.type == TYPE_NEXT_SPECIFIC) {
  550.             sprintf(caTmp, "%03s", wday_name2[ti->next.from.dow]);
  551.             memcpy(cpaScreen[22]+43, caTmp, strlen(caTmp));
  552.             sprintf(caTmp, "%02d:%02d", ti->next.from.time.hour, ti->next.from.time.min);
  553.             memcpy(cpaScreen[22]+47, caTmp, strlen(caTmp));
  554.             sprintf(caTmp, "%03s", wday_name2[ti->next.to.dow]);
  555.             memcpy(cpaScreen[22]+56, caTmp, strlen(caTmp));
  556.             sprintf(caTmp, "%02d:%02d", ti->next.to.time.hour, ti->next.to.time.min);
  557.             memcpy(cpaScreen[22]+60, caTmp, strlen(caTmp));
  558.  
  559.             sprintf(caTmp, "%02d:%02d", ti->next.total.hour, ti->next.total.min);
  560.             memcpy(cpaScreen[23]+49, caTmp, strlen(caTmp));
  561.             sprintf(caTmp, "%02d:%02d", ti->next.in.hour, ti->next.in.min);
  562.             memcpy(cpaScreen[23]+59, caTmp, strlen(caTmp));
  563.         }
  564.         else {
  565.             for (i = 38; i < 65; i++) {
  566.                 *(cpaScreen[22]+i) = ' ';
  567.                 *(cpaScreen[23]+i) = ' ';
  568.             }
  569.  
  570.             if (ti->next.type == TYPE_NEXT_ALWAYS)
  571.                 cpTmp = TYPESTR_NEXT_ALWAYS;
  572.             if (ti->next.type == TYPE_NEXT_NEVER)
  573.                 cpTmp = TYPESTR_NEXT_NEVER;
  574.             memcpy(cpaScreen[22]+38, cpTmp, strlen(cpTmp));
  575.         }
  576.  
  577.  
  578.         if (mode == HOSTINFO_LONG) {
  579.             (void)time(&t);
  580.             tm = localtime(&t);
  581.  
  582.             for (i=0; i < CHART_XNUM; i++) {
  583.                 cpXl1[i] = ' ';
  584.                 cpXl2[i] = ' ';
  585.             }
  586.  
  587.             ch = tm->tm_wday * 24 + tm->tm_hour - 12;
  588.             if (ch < 0)
  589.                 ch = WEEKDAY_NUM*24 - abs(ch);
  590.  
  591.             for (x=0; x < CHART_XNUM; x++) {
  592.  
  593.                 h = ch % 24;
  594.                 cpXl1[x] = ('0' + (h % 10));
  595.                 if ((h % 10) == 0) {
  596.                     if ((h / 10) != 0) {
  597.                         cpXl2[x] = ('0' + (h / 10));
  598.                     }
  599.                     else {
  600.                         if (x + WDAYNAME_LEN2 <= CHART_XNUM) {
  601.                             memcpy(&cpXl2[x], wday_name2[ch / 24], WDAYNAME_LEN2);
  602.                         }
  603.                     }
  604.                 }
  605.  
  606.                 for (y=0; y < CHART_YNUM; y++) {
  607.  
  608.                     if (ti->aMOW[ch*60+y*5+0] == MOW_FORBIDDEN ||
  609.                         ti->aMOW[ch*60+y*5+1] == MOW_FORBIDDEN ||
  610.                         ti->aMOW[ch*60+y*5+2] == MOW_FORBIDDEN ||
  611.                         ti->aMOW[ch*60+y*5+3] == MOW_FORBIDDEN ||
  612.                         ti->aMOW[ch*60+y*5+4] == MOW_FORBIDDEN     ) {
  613.                         chart_map[x][y] = CHARTP_FORBIDDEN;
  614.                     }
  615.  
  616.                     if (ti->aMOW[ch*60+y*5+1] == MOW_PERMITTED &&
  617.                         ti->aMOW[ch*60+y*5+2] == MOW_PERMITTED &&
  618.                         ti->aMOW[ch*60+y*5+3] == MOW_PERMITTED     ) {
  619.                         chart_map[x][y] = CHARTP_PERMITTED;
  620.                     }
  621.  
  622.                     if (ti->aMOW[ch*60+y*5+1] == MOW_ACTIVETIMES &&
  623.                         ti->aMOW[ch*60+y*5+2] == MOW_ACTIVETIMES &&
  624.                         ti->aMOW[ch*60+y*5+3] == MOW_ACTIVETIMES   ) {
  625.                         chart_map[x][y] = CHARTP_ACTIVETIMES;
  626.                     }
  627.  
  628.                     if (ti->aMOW[ch*60+y*5+0] == MOW_CURRENTTIME ||
  629.                         ti->aMOW[ch*60+y*5+1] == MOW_CURRENTTIME ||
  630.                         ti->aMOW[ch*60+y*5+2] == MOW_CURRENTTIME ||
  631.                         ti->aMOW[ch*60+y*5+3] == MOW_CURRENTTIME ||
  632.                         ti->aMOW[ch*60+y*5+4] == MOW_CURRENTTIME   ) {
  633.                         chart_map[x][y] = CHARTP_CURRENTTIME;
  634.                     }
  635.                 }
  636.  
  637.                 ch = (ch + 1) % (WEEKDAY_NUM * 24);
  638.             }
  639.  
  640.             for (x=0; x < CHART_XNUM; x++) {
  641.                 *(cpaScreen[CHART_Y0+2]+CHART_X0+x) = *(cpXl1+x);
  642.                 *(cpaScreen[CHART_Y0+3]+CHART_X0+x) = *(cpXl2+x);
  643.  
  644.                 for (y=0; y < CHART_YNUM; y++)
  645.                     *(cpaScreen[CHART_Y0-y]+CHART_X0+x) = chart_map[x][y];
  646.             }
  647.  
  648.         }
  649.         else {
  650.             for (i = 57; i < 76; i++) {
  651.                 *(cpaScreen[2]+i) = ' ';
  652.                 *(cpaScreen[3]+i) = ' ';
  653.             }
  654.             for (i = 31; i < 34; i++)
  655.                 *(cpaScreen[21]+i) = ' ';
  656.         }
  657.  
  658.     }
  659.  
  660.     printf("\n");
  661.  
  662.     if (mode == HOSTINFO_LONG) {
  663.         for (i = 0; i < SCREEN_LINES; i++)
  664.             fwrite(cpaScreen[i], SCREEN_COLS+1, 1, stdout);
  665.     }
  666.     else {
  667.         for (i = 0; i < 4; i++)
  668.             fwrite(cpaScreen[i], SCREEN_COLS+1, 1, stdout);
  669.         for (i = 20; i < SCREEN_LINES; i++)
  670.             fwrite(cpaScreen[i], SCREEN_COLS+1, 1, stdout);
  671.     }
  672.  
  673.     printf("\n");
  674.  
  675.     CUS:
  676.     if (ti)
  677.         free(ti);
  678.     return;
  679. }
  680.  
  681.  
  682. int timerestriction(char *cpLsys, char *cpSystem)
  683. {
  684.     int rc;
  685.     struct TimeInfo *ti = NULL;
  686.  
  687.     if ((ti = (struct TimeInfo *)malloc(sizeof(struct TimeInfo))) == NULL)
  688.         CU(-1);
  689.     if (calctimes(cpLsys, cpSystem, ti) == FALSE)
  690.         CU(-1);
  691.     if (ti->active.type == TYPE_ACTIVE_NOTCURRENTLY ||
  692.         ti->active.type == TYPE_ACTIVE_NEVER            )
  693.         CU(-1);
  694.     if (ti->active.type == TYPE_ACTIVE_ALWAYS)
  695.         CU(0);
  696.     if (ti->active.type == TYPE_ACTIVE_SPECIFIC)
  697.         CU(ti->active.remain.hour * 60 + ti->active.remain.min);
  698.  
  699.     rc = -1;
  700.  
  701.     CUS:
  702.     if (ti)
  703.         free(ti);
  704.     return rc;
  705. }
  706.  
  707.  
  708.  
  709.