home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-09-23 | 40.5 KB | 1,500 lines |
- Newsgroups: comp.sources.misc
- From: piggy@idea.sublink.org (Lele Gaifas)
- Subject: v23i009: tua - The Uucp Analyzer, Part03/05
- Message-ID: <1991Sep22.203522.22994@sparky.imd.sterling.com>
- X-Md4-Signature: 43a346b80ce241c3e4aa1601bb291467
- Date: Sun, 22 Sep 1991 20:35:22 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: piggy@idea.sublink.org (Lele Gaifas)
- Posting-number: Volume 23, Issue 9
- Archive-name: tua/part03
- Environment: Xenix, SYSV
-
- ---- Cut Here and feed the following to sh ----
- # This is part 03 of a multipart archive
- # ============= reports.c ==============
- if test -f 'reports.c' -a X"$1" != X"-c"; then
- echo 'x - skipping reports.c (File already exists)'
- else
- echo 'x - extracting reports.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'reports.c' &&
- /* $Id: reports.c,v 3.3 1991/09/01 14:02:43 piggy Rel $
- X * Print reports.
- X *
- X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * SYNOPSIS:
- X * void SystemsReport();
- X * void SystemsCommandReport();
- X * void UsersReport();
- X * void UsersCommandReport();
- X * void DailyReport();
- X * void DailyCommandReport();
- X * void SystemSummary();
- X * void SystemSummaryTable();
- X * void SystemHistoryTable();
- X * void MonthlyHistoryTable();
- X * void HourlyActivityCharts();
- X *
- X */
- X
- #include <stdio.h>
- X
- #ifdef USG
- #include <malloc.h>
- #else
- extern char * malloc();
- #endif
- X
- #include "hdbstat.h"
- X
- #define BYTES_PER_KBYTE 1024.0
- #define BYTES_PER_MBYTE 1024000.0
- X
- #define NotZero(rec) \
- X (rec.FilesOut || rec.FilesIn || rec.BytesOut || rec.BytesIn || \
- X rec.TimeOut || rec.TimeIn)
- X
- static char * /* Transforms seconds to "hh:mm:ss" */
- TimeToString (tim)
- X float tim;
- {
- X char *str;
- X int hh, mm, ss;
- X register time_t ltim = (time_t) tim;
- X
- X ltim = (time_t) tim;
- X hh = (int) (ltim / 3600L);
- X ltim %= 3600L;
- X mm = (int) (ltim / 60L);
- X ss = (int) (ltim % 60L);
- X str = malloc (20);
- X sprintf (str, "%4d:%02d:%02d.%02d",
- X hh, mm, ss, (int) ((tim - (int) (tim)) * 100));
- X return (str);
- }
- X
- static void
- Commands (comm)
- X commrep_t comm;
- {
- X if (comm.Number > 1)
- X printf ("\t(%3d) ", comm.Number);
- X else
- X printf ("\t ");
- X printf ("%s\n", comm.Command);
- }
- X
- static void
- SR (system)
- X sysrep_t system;
- {
- X if (NotZero (system))
- X {
- X printf ("%-11.11s %4d %8.f%s %4d %4d %8.f%s %4d\n",
- X system.System,
- X system.FilesIn, system.BytesIn / BYTES_PER_KBYTE,
- X TimeToString (system.TimeIn),
- X (system.TimeIn ? (int) (system.BytesIn / system.TimeIn) : 0),
- X system.FilesOut, system.BytesOut / BYTES_PER_KBYTE,
- X TimeToString (system.TimeOut),
- X (system.TimeOut ? (int) (system.BytesOut / system.TimeOut) : 0));
- X if (DoCommandReport && !SeparatedCommLog && system.Commands)
- X {
- X puts ("\tCommands:\n\t=========");
- X EnquiryComm (system.Commands, Commands);
- X puts ("");
- X }
- X }
- }
- X
- static void
- SRnocomm (system)
- X sysrep_t system;
- {
- X if (system.Commands)
- X {
- X printf (" %s:\n", system.System);
- X EnquiryComm (system.Commands, Commands);
- X puts ("");
- X }
- }
- X
- void
- SystemsReport ()
- {
- X puts ("By System:");
- X puts ("==========");
- X puts (" R E C E I V E D S E N T");
- X puts ("System Files KBytes Time ATP Files KBytes Time ATP\n");
- X EnquirySys (SR);
- }
- X
- void
- SystemsCommandReport ()
- {
- X if (DoCommandReport)
- X {
- X puts ("\nCommands By System:");
- X puts ("===================");
- X EnquirySys (SRnocomm);
- X puts ("");
- X }
- }
- X
- static void
- UR (user)
- X userrep_t user;
- {
- X printf ("%-11.11s %4d %8.f %s\n",
- X user.User,
- X user.FilesOut, user.BytesOut / BYTES_PER_KBYTE,
- X TimeToString (user.TimeOut));
- X if (DoCommandReport && !SeparatedCommLog && user.Commands)
- X {
- X puts ("\tCommands:");
- X puts ("\t=========");
- X EnquiryComm (user.Commands, Commands);
- X puts ("");
- X }
- }
- X
- static void
- URnocomm (user)
- X userrep_t user;
- {
- X if (user.Commands)
- X {
- X printf (" %s:\n", user.User);
- X EnquiryComm (user.Commands, Commands);
- X puts ("");
- X }
- }
- X
- void
- UsersReport ()
- {
- X puts ("\nBy User:");
- X puts ("========");
- X puts (" S E N T");
- X puts ("User Files KBytes Time\n");
- X EnquiryUser (UR);
- }
- X
- void
- UsersCommandReport ()
- {
- X if (DoCommandReport)
- X {
- X puts ("\nBy User:");
- X puts ("========");
- X EnquiryUser (URnocomm);
- X }
- }
- X
- static void
- DR (day)
- X dailyrep_t day;
- {
- X printf ("%02d/%02d %4d %8.f %s %4d %8.f %s\n",
- X day.Month, day.Day,
- X day.FilesIn, day.BytesIn / BYTES_PER_KBYTE,
- X TimeToString (day.TimeIn),
- X day.FilesOut, day.BytesOut / BYTES_PER_KBYTE,
- X TimeToString (day.TimeOut));
- X if (DoCommandReport && !SeparatedCommLog && day.Commands)
- X {
- X puts ("\tCommands:");
- X puts ("\t=========");
- X EnquiryComm (day.Commands, Commands);
- X puts ("");
- X }
- }
- X
- static void
- DRnocomm (day)
- X dailyrep_t day;
- {
- X if (day.Commands)
- X {
- X printf (" %02d/%02d:\n", day.Month, day.Day);
- X EnquiryComm (day.Commands, Commands);
- X puts ("");
- X }
- }
- X
- void
- DailyReport ()
- {
- X puts ("\nBy Day:");
- X puts ("=======");
- X puts ("Date R E C E I V E D S E N T");
- X puts ("Mo/Dy Files KBytes Time Files KBytes Time\n");
- X EnquiryDay (DR);
- }
- X
- void
- DailyCommandReport ()
- {
- X if (DoCommandReport)
- X {
- X puts ("\nBy Day:");
- X puts ("=======");
- X EnquiryDay (DRnocomm);
- X }
- }
- X
- static void
- SummBySys (system)
- X sysrep_t system;
- {
- X extern char * ctime PROTO((long *));
- X
- X if (NotZero (system) || system.Calls)
- X {
- X register idx;
- X
- X printf ("\n%s:\n", system.System);
- X printf ("\tRecvd\t%10.f (%4d Files) in %s: %4d cps\n",
- X system.BytesIn, system.FilesIn, TimeToString (system.TimeIn),
- X (system.TimeIn ? (int) (system.BytesIn / system.TimeIn) : 0));
- X printf ("\tSent\t%10.f (%4d Files) in %s: %4d cps\n",
- X system.BytesOut, system.FilesOut, TimeToString (system.TimeOut),
- X (system.TimeOut ? (int) (system.BytesOut / system.TimeOut) : 0));
- X if (system.BytesIn > system.BytesOut)
- X printf ("\tRecvd\t%10.f bytes more than sent.\n",
- X system.BytesIn - system.BytesOut);
- X else if (system.BytesIn < system.BytesOut)
- X printf ("\tSent\t%10.f bytes more than received.\n",
- X system.BytesOut - system.BytesIn);
- X printf ("\tThe system has been connected for %s\n",
- X TimeToString (system.TimeConnect));
- X printf ("\tLast connection: %s", ctime(&system.LastConnection));
- X for (idx = 0; idx < PHONE_PRICING_TB; idx++)
- X if (system.PhoneCost[idx] != .0)
- X printf ("\tTime spent transmitting in %s: %s\n",
- X PhoneCategoryNames[idx],
- X TimeToString (system.PhoneCost[idx]));
- X printf ("\tThere have been %d call%s (with an average of %d Ok/day):\n\t\t\t\t\t",
- X system.Calls, (system.Calls == 1 ? "" : "s"),
- X (system.CallsOK / DaysSinceLastClean));
- X if (system.CallsOK)
- X {
- X if (system.CallsSTOPPED)
- X printf ("%3d OK (%3d IN, %3d OUT, %3d BREAKED)\n\t\t\t\t\t",
- X system.CallsOK, system.CallsIn,
- X system.CallsOut, system.CallsSTOPPED);
- X else
- X printf ("%3d OK (%3d IN, %3d OUT)\n\t\t\t\t\t",
- X system.CallsOK, system.CallsIn, system.CallsOut);
- X }
- X if (system.CallsFAIL)
- X printf ("%3d FAILED\n\t\t\t\t\t", system.CallsFAIL);
- X }
- }
- X
- void
- SystemSummary ()
- {
- X puts ("\nSUMMARY by System:");
- X puts ("==================");
- X EnquirySys (SummBySys);
- X puts ("");
- }
- X
- static float TotTimeIn = 0.0, TotTimeOut = 0.0;
- static float TotBytesIn = 0.0, TotBytesOut = 0.0;
- static int TotFilesIn = 0, TotFilesOut = 0;
- X
- static char *
- BytesToString (byt)
- X float byt;
- {
- X char *stringa = malloc (11);
- X
- X sprintf (stringa, "%9.f", byt / BYTES_PER_KBYTE);
- X return stringa;
- }
- X
- static void
- SummBySysTable (sys)
- X sysrep_t sys;
- {
- X float TotTime = sys.TimeIn + sys.TimeOut;
- X float TotBytes = sys.BytesOut + sys.BytesIn;
- X
- X if (NotZero (sys))
- X {
- X TotTimeIn += sys.TimeIn;
- X TotTimeOut += sys.TimeOut;
- X TotBytesIn += sys.BytesIn;
- X TotBytesOut += sys.BytesOut;
- X TotFilesIn += sys.FilesIn;
- X TotFilesOut += sys.FilesOut;
- X printf ("|%-8.8s| %s :%10.10s: %5d | %s :%10.10s: %5d | %4d|\n",
- X sys.System, BytesToString (sys.BytesIn), TimeToString (sys.TimeIn), sys.FilesIn,
- X BytesToString (sys.BytesOut), TimeToString (sys.TimeOut), sys.FilesOut,
- X (TotTime ? (int) (TotBytes / TotTime) : 0));
- X }
- }
- X
- void
- SystemSummaryTable ()
- {
- X puts ("+--------+------------------------------+------------------------------+-----+");
- X puts ("| | R E C E I V E D | S E N T | |");
- X puts ("| SYSTEM | KiloBytes : Time : Files | KiloBytes : Time : Files | ATP |");
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- X EnquirySys (SummBySysTable);
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- X printf ("| TOTALS | %s :%10.10s: %5d | %s :%10.10s: %5d | ####|\n",
- X BytesToString (TotBytesIn), TimeToString (TotTimeIn), TotFilesIn,
- X BytesToString (TotBytesOut), TimeToString (TotTimeOut), TotFilesOut);
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- }
- X
- static void
- SysHistoryTable (sys)
- X sysrep_t sys;
- {
- X float TotTime = sys.History.TimeIn + sys.History.TimeOut +
- X sys.TimeIn + sys.TimeOut;
- X float TotBytes = sys.History.BytesOut + sys.History.BytesIn +
- X sys.BytesIn + sys.BytesOut;
- X
- X if (NotZero (sys) || NotZero (sys.History))
- X {
- X TotTimeIn += sys.History.TimeIn;
- X TotTimeOut += sys.History.TimeOut;
- X TotBytesIn += sys.History.BytesIn;
- X TotBytesOut += sys.History.BytesOut;
- X TotFilesIn += sys.History.FilesIn;
- X TotFilesOut += sys.History.FilesOut;
- X printf ("|%-8.8s| %s :%10.10s: %5d | %s :%10.10s: %5d | %4d|\n",
- X sys.System, BytesToString (sys.History.BytesIn + sys.BytesIn),
- X TimeToString (sys.History.TimeIn + sys.TimeIn),
- X sys.History.FilesIn + sys.FilesIn,
- X BytesToString (sys.History.BytesOut + sys.BytesOut),
- X TimeToString (sys.History.TimeOut + sys.TimeOut),
- X sys.History.FilesOut + sys.FilesOut,
- X (TotTime ? (int) (TotBytes / TotTime) : 0));
- X }
- }
- X
- void
- SystemHistoryTable ()
- {
- X printf ("\n...and since %s\n", TheEpoc);
- X puts ("+--------+------------------------------+------------------------------+-----+");
- X puts ("| | R E C E I V E D | S E N T | |");
- X puts ("| SYSTEM | KiloBytes : Time : Files | KiloBytes : Time : Files | ATP |");
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- X EnquirySys (SysHistoryTable);
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- X printf ("| TOTALS | %s :%10.10s: %5d | %s :%10.10s: %5d | ####|\n",
- X BytesToString (TotBytesIn), TimeToString (TotTimeIn), TotFilesIn,
- X BytesToString (TotBytesOut), TimeToString (TotTimeOut), TotFilesOut);
- X puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
- }
- X
- static float MonthlyActivityTotals[12];
- X
- static void
- MonHistoryTable (sys)
- X sysrep_t sys;
- {
- X int idx;
- X float sum = .0;
- X
- X for (idx = 0; idx <= 11; idx++)
- X sum += sys.History.MonthlyActivity[idx];
- X
- X if (sum > 0.0)
- X {
- X printf ("\n%-6.6s", sys.System);
- X for (idx = 0; idx <= 11; idx++)
- X {
- X float bytes =
- X sys.History.MonthlyActivity[(idx + CurrentMonth + 1) % 12];
- X
- X MonthlyActivityTotals[(idx + CurrentMonth + 1) % 12] += bytes;
- X if (bytes == -1.0)
- X printf ("| *** ");
- X else if (bytes < 10.0 * BYTES_PER_KBYTE)
- X printf ("|%4.0f ", bytes);
- X else if (bytes < 10.0 * BYTES_PER_MBYTE)
- X printf ("|%4.0fK", bytes / BYTES_PER_KBYTE);
- X else
- X printf ("|%4.0fM", bytes / BYTES_PER_MBYTE);
- X }
- X }
- }
- X
- void
- MonthlyHistoryTable ()
- {
- X static char *MonthName[] =
- X {
- X "Jan", "Feb", "Mar", "Apr",
- X "May", "Jun", "Jul", "Ago",
- X "Sep", "Oct", "Nov", "Dic"
- X };
- X int idx;
- X
- X puts ("\n\nLast 12 Months Activity");
- X puts ("=======================\n");
- X printf ("------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
- X printf ("System");
- X for (idx = 0; idx <= 11; idx++)
- X {
- X printf ("| %s", MonthName[(idx + CurrentMonth + 1) % 12]);
- X if (idx != 11)
- X putchar (' ');
- X }
- X printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----");
- X EnquirySys (MonHistoryTable);
- X printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
- X printf ("TOTALS");
- X for (idx = 0; idx <= 11; idx++)
- X {
- X float bytes = MonthlyActivityTotals[(idx + CurrentMonth + 1) % 12];
- X
- X if (bytes < 0.0)
- X printf ("| *** ");
- X else if (bytes < 10.0 * BYTES_PER_KBYTE)
- X printf ("|%4.0f ", bytes);
- X else if (bytes < 10.0 * BYTES_PER_MBYTE)
- X printf ("|%4.0fK", bytes / BYTES_PER_KBYTE);
- X else
- X printf ("|%4.0fM", bytes / BYTES_PER_MBYTE);
- X }
- X printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
- }
- X
- static float PortActivityTotals[TIMESLICES] = {0};
- static int IsGlobalActivityChart = 0;
- static int NumberOfPorts = 0;
- X
- static void
- CountPorts (port)
- X portact_t port;
- X
- {
- X NumberOfPorts++;
- }
- X
- static void
- PortActivityChart (port)
- X portact_t port;
- {
- X int row, slice;
- X float maxval = 0.0;
- X float scale;
- X
- X for (slice = 0; slice < TIMESLICES; slice++)
- X {
- X float curval;
- X
- X if (!IsGlobalActivityChart)
- X PortActivityTotals[slice] += (curval = port.Activity[slice]);
- X else
- X curval = PortActivityTotals[slice];
- X
- X if (curval > maxval)
- X maxval = curval;
- X }
- X scale = maxval / ChartSize;
- X
- X if (IsGlobalActivityChart || NumberOfPorts == 1)
- X {
- X printf ("\n\nGlobal Hourly Activity (on a 20 minutes basis)\n");
- X puts ("==============================================\n");
- X }
- X else
- X {
- X printf ("\n\nHourly Activity (on a 20 minutes basis) on %s\n", port.Port);
- X puts ("======================================================\n");
- X }
- X printf ("Max Value : %.0f bytes\nScale : '#'=%.0f bytes\n\n", maxval, scale);
- X for (row = ChartSize; row > 0; row--)
- X {
- X float current_value = row * scale;
- X
- X printf (" ");
- X for (slice = 0; slice < 72; slice++)
- X {
- X float curval = (IsGlobalActivityChart ?
- X PortActivityTotals[slice] : port.Activity[slice]);
- X if (curval >= current_value)
- X putchar ('#');
- X else
- X putchar (' ');
- X }
- X puts ("");
- X }
- X puts (" ========================================================================");
- X puts (" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23");
- }
- X
- void
- HourlyActivityCharts ()
- {
- X portact_t dummy;
- X
- X EnquiryPort (CountPorts);
- X EnquiryPort (PortActivityChart);
- X if (NumberOfPorts > 1)
- X {
- X IsGlobalActivityChart++;
- X PortActivityChart (dummy);
- X }
- }
- SHAR_EOF
- chmod 0444 reports.c ||
- echo 'restore of reports.c failed'
- Wc_c="`wc -c < 'reports.c'`"
- test 15023 -eq "$Wc_c" ||
- echo 'reports.c: original size 15023, current size' "$Wc_c"
- fi
- # ============= systree.c ==============
- if test -f 'systree.c' -a X"$1" != X"-c"; then
- echo 'x - skipping systree.c (File already exists)'
- else
- echo 'x - extracting systree.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'systree.c' &&
- /* $Id: systree.c,v 3.3 1991/09/01 14:02:47 piggy Rel $
- X * Systems tree management.
- X *
- X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * SYNOPSIS:
- X * sysrep_t * InsertSys(char * sys);
- X * Look for sys in the tree. If it is already there, return a pointer
- X * to its info. Otherwise make a new entry and initialize it.
- X *
- X * void EnquirySys(void (*funct)(sysrep_t sys))
- X * For each node in the tree, process its info through funct.
- X *
- X * void KillSys(char * sys);
- X * Do not show the system in any of the reports
- X *
- X * sysrep_t * CheckSystemEsist(char * sys)
- X * Look for sys in the tree. If it is there, return a pointer to its info,
- X * otherwise NULL.
- X */
- X
- #include <stdio.h>
- #include "mem.h"
- #include <string.h>
- #include "hdbstat.h"
- X
- typedef struct systree
- {
- X sysrep_t Node;
- X struct systree *L;
- X struct systree *R;
- } systree_t;
- X
- #define TNULL (systree_t *) NULL
- X
- static FlistHead SysFlist =
- {
- X 0, 0, 0
- };
- X
- static systree_t *Root = TNULL;
- X
- static sysrep_t *
- SysTree (tree, sys, insert_flag)
- X systree_t **tree;
- X char *sys;
- X int insert_flag;
- X
- {
- X int cmpres;
- X
- X if (*tree == TNULL)
- X if (insert_flag)
- X {
- X register sysrep_t *sr;
- X int idx;
- X
- X if (SysFlist.size == 0)
- X MemInit (&SysFlist, sizeof (systree_t), 20, 5);
- X *tree = (systree_t *) new (&SysFlist);
- X (*tree)->L = (*tree)->R = TNULL;
- X sr = &((*tree)->Node);
- X sr->System = strdup (sys);
- X sr->Killed = FALSE;
- X sr->FilesOut = sr->FilesIn = 0;
- X sr->BytesOut = sr->BytesIn = 0.0;
- X sr->TimeOut = sr->TimeIn = sr->TimeConnect = 0.0;
- X sr->Calls = sr->CallsOK = sr->CallsFAIL = sr->CallsSTOPPED = 0;
- X sr->CallsIn = sr->CallsOut = 0;
- X sr->Commands = (Tcommrep_t) NULL;
- X sr->History.FilesOut = sr->History.FilesIn = 0;
- X sr->History.BytesOut = sr->History.BytesIn = 0.0;
- X sr->History.TimeOut = sr->History.TimeIn = 0.0;
- X for (idx = 0; idx <= 11; idx++)
- X sr->History.MonthlyActivity[idx] = -1.0;
- X for (idx = 0; idx < PHONE_PRICING_TB; idx++)
- X sr->PhoneCost[idx] = 0.0;
- X sr->History.LastMonthProcessed = -1;
- X return (&(*tree)->Node);
- X }
- X else
- X return (sysrep_t *) NULL;
- X else if ((cmpres = strcmp (sys, (*tree)->Node.System)) < 0)
- X return SysTree (&(*tree)->L, sys, insert_flag);
- X else if (cmpres > 0)
- X return SysTree (&(*tree)->R, sys, insert_flag);
- X else
- X return (&(*tree)->Node);
- }
- X
- sysrep_t *
- InsertSys (sys)
- X char *sys;
- X
- {
- X return SysTree (&Root, sys, TRUE);
- }
- X
- void
- KillSys (sys)
- X char *sys;
- X
- {
- X SysTree (&Root, sys, TRUE)->Killed = TRUE;
- }
- X
- static void
- ProcSysTree (tree, funct)
- X systree_t *tree;
- X void (*funct) ();
- X
- {
- X if (tree != TNULL)
- X {
- X ProcSysTree (tree->L, funct);
- X if (!(tree->Node.Killed))
- X (*funct) (tree->Node);
- X ProcSysTree (tree->R, funct);
- X }
- }
- X
- void
- EnquirySys (funct)
- X void (*funct) ();
- X
- {
- X ProcSysTree (Root, funct);
- }
- X
- sysrep_t *
- CheckSystemEsist(sys)
- X char * sys;
- X
- {
- X return (SysTree(&Root, sys, FALSE));
- }
- X
- SHAR_EOF
- chmod 0444 systree.c ||
- echo 'restore of systree.c failed'
- Wc_c="`wc -c < 'systree.c'`"
- test 3809 -eq "$Wc_c" ||
- echo 'systree.c: original size 3809, current size' "$Wc_c"
- fi
- # ============= tua.c ==============
- if test -f 'tua.c' -a X"$1" != X"-c"; then
- echo 'x - skipping tua.c (File already exists)'
- else
- echo 'x - extracting tua.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'tua.c' &&
- /* $Id: tua.c,v 3.3 1991/09/01 14:02:49 piggy Rel $
- X * HDB-uucp Activity Analyzer. Eat all the uucp logs and extract per system,
- X * user and daily stats.
- X *
- X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X */
- X
- #include <stdio.h>
- #include <time.h>
- #include "hdbstat.h"
- #ifdef USG
- #include <string.h>
- #else
- #include <strings.h>
- #endif
- #include "patchlevel.h"
- #include "getopt.h"
- X
- #ifdef USG
- #include <malloc.h>
- #else
- extern char *malloc ();
- #endif
- X
- #ifdef __GNUC__
- static inline void
- error (char *str)
- {
- X fprintf (stderr, "Error in processing %s\n", str);
- X exit (1);
- }
- X
- #else
- #define error(str) { \
- X fprintf(stderr, "Error in processing %s\n", str); \
- X exit(1); \
- X }
- #endif
- X
- #ifdef STRDUP_MISSING
- X
- char *
- strdup (string)
- X char *string;
- X
- {
- X char *tmp = malloc (strlen (string) + 1);
- X
- X if (tmp)
- X return (strcpy (tmp, stringa));
- X else
- X return tmp;
- }
- X
- #endif /* STRDUP_MISSING */
- X
- X
- int SeparatedCommLog = FALSE;
- int DoCommandReport = FALSE;
- int VerboseOutput = FALSE;
- int JustSomeSystem = FALSE;
- int ChartSize = 10;
- char *PrefixPath = "/usr/spool/uucp";
- char *CurrentTime;
- int CurrentMonth;
- char *Since;
- int DaysSinceLastClean;
- X
- static void
- DisplayUsage ()
- {
- X fprintf (stderr, "The Uucp Analyzer (TUA) rel. %s by piggy@idea.sublink.org (Lele Gaifax)\n\nOptions:\n", RELEASE);
- X fputs ("\
- -S, +no-sys-rep Do not show the report for the Systems\n\
- -U, +no-user-rep Do not show the report for the Users\n\
- -D, +no-daily-rep Do not show the day-by-day report\n\
- -m, +no-monthly-act Do not show the monthly activity report\n\
- -h, +no-history Do not show the history\n\
- -y, +no-hourly-chart Do not show the hourly activity chart\n\
- -C, +command-lists Show the various command lists\n\
- -O, +only-system SYS Consider just SYS in the reports\n", stderr);
- X fputs ("\
- -c, +separate-com Build a separate log for the commands\n\
- -k, +kill-system SYS Do not show anything about system SYS\n\
- -K, +kill-user USER Do not show anything about user USER\n\
- -H, +update-hist Update the history file\n\
- -0, +reset-hist Reset the history file\n\
- -p, +prefix-path DIR Use DIR instead of /usr/spool/uucp (for debugging only)\n\
- -z, +chart-size SIZE Set the size of the hourly chart to SIZE rows\n", stderr);
- X fputs ("\
- -o, +chart-only Print only the hourly activity chart\n\
- -v, +verbose Print infos while processing\n\
- -i, +help Get this help\n\
- ", stderr);
- X
- #ifdef HDB_ERR_FACT
- X fputs ("\
- -f, +hdb-factor F Set the Correction Factor for HDB to F (by default. 2.5)\n\
- ", stderr);
- #endif
- X
- X fputs ("\n\tPlease report bugs and problems to:\n\
- \t\tpiggy@idea.sublink.org\n\n", stderr);
- X fputs ("\
- TUA may be copied only under the terms of the GNU General Public License,\n\
- a copy of which can be found with the TUA distribution package\n", stderr);
- }
- X
- int
- main (argc, argv)
- X int argc;
- X char *argv[];
- {
- X extern double atof ();
- X extern int uname ();
- X extern char *optarg;
- X extern int opterr;
- X int opt;
- X int optidx;
- X static int DoSystemReport = TRUE;
- X static int DoUserReport = TRUE;
- X static int DoDailyReport = TRUE;
- X static int SaveHistory = FALSE;
- X static int DoHistoryReport = TRUE;
- X static int ResetHistory = FALSE;
- X static int DoMonthlyActivityReport = TRUE;
- X static int DoHourlyActivityChart = TRUE;
- X static int DoChartOnly = FALSE;
- X extern long time ();
- X char SystemName[9];
- X long Now = time ((long *) 0);
- X static struct option long_options[] =
- X {
- X {"no-sys-rep", 0, &DoSystemReport, FALSE}, /* -S */
- X {"no-user-rep", 0, &DoUserReport, FALSE}, /* -U */
- X {"no-daily-rep", 0, &DoDailyReport, FALSE}, /* -D */
- X {"command-lists", 0, &DoCommandReport, TRUE}, /* -C */
- X {"no-monthly-act", 0, &DoMonthlyActivityReport, FALSE}, /* -m */
- X {"no-history", 0, &DoHistoryReport, FALSE}, /* -h */
- X {"only-system", 1, 0, 'O'}, /* -O */
- #ifdef HDB_ERR_FACT
- X {"hdb-factor", 1, 0, 'f'}, /* -f */
- #endif
- X {"separate-com", 0, &SeparatedCommLog, TRUE}, /* -c */
- X {"kill-system", 1, 0, 'k'}, /* -k */
- X {"kill-user", 1, 0, 'K'}, /* -K */
- X {"update-hist", 0, &SaveHistory, TRUE}, /* -H */
- X {"reset-hist", 0, &ResetHistory, TRUE}, /* -0 */
- X {"help", 0, 0, 'i'}, /* -i */
- X {"prefix-path", 1, 0, 'p'}, /* -p */
- X {"chart-size", 1, 0, 'z'}, /* -z */
- X {"no-hourly-chart", 0, &DoHourlyActivityChart, FALSE}, /* -y */
- X {"chart-only", 0, &DoChartOnly, TRUE}, /* -o */
- X {"verbose", 0, &VerboseOutput, TRUE}, /* -v */
- X {0, 0, 0, 0}
- X };
- X
- X CurrentTime = strdup (asctime (localtime (&Now)));
- X CurrentTime[strlen (CurrentTime) - 1] = '\0'; /* Strip the ending '\0' */
- X
- X CurrentMonth = localtime (&Now)->tm_mon;
- X
- X opterr = FALSE;
- X
- #ifdef SYSTEMID
- X if ((gethostname (SystemName, 9) == -1) || *SystemName == '\0')
- X {
- X FILE *fd;
- X
- X if ((fd = fopen (SYSTEMID, "r")) == NULL)
- X strcpy (SystemName, "UNKNOWN");
- X else
- X {
- X int last = strlen (fgets (SystemName, 9, fd)) - 1;
- X
- X if (last > 0)
- X {
- X if (SystemName[last] == '\n')
- X SystemName[last] = '\0';
- X }
- X else
- X strcpy (SystemName, "??????");
- X fclose (fd);
- X }
- X }
- #else
- X if ((gethostname (SystemName, 9) == -1) || *SystemName == '\0')
- X strcpy (SystemName, "UNKNOWN");
- #endif
- X
- #ifdef HDB_ERR_FACT
- #define OPTSTR "SUDCm:hck:K:H0ifp:z:yovO:"
- #else
- #define OPTSTR "SUDCm:hck:K:H0ip:z:yovO:"
- #endif
- X
- X while ((opt = getopt_long (argc, argv, OPTSTR, long_options, &optidx)) != EOF)
- X {
- X if (opt == 0 && long_options[optidx].flag == 0)
- X opt = long_options[optidx].val;
- X switch (opt)
- X {
- X case 0:
- X break;
- X case 'S':
- X DoSystemReport = FALSE;
- X break;
- X case 'U':
- X DoUserReport = FALSE;
- X break;
- X case 'D':
- X DoDailyReport = FALSE;
- X break;
- X case 'C':
- X DoCommandReport = TRUE;
- X break;
- X case 'm':
- X DoMonthlyActivityReport = FALSE;
- X break;
- X case 'h':
- X DoHistoryReport = FALSE;
- X break;
- X case 'c':
- X SeparatedCommLog = FALSE;
- X break;
- X case 'k':
- X KillSys (optarg);
- X break;
- X case 'K':
- X KillUser (optarg);
- X break;
- X case 'H':
- X SaveHistory = TRUE;
- X break;
- X case '0':
- X ResetHistory = TRUE;
- X break;
- #ifdef HDB_ERR_FACT
- X case 'f':
- X ERRFACT = (float) atof (optarg);
- X if (ERRFACT <= 0.0)
- X {
- X fprintf (stderr,
- X "Bad -f argument. Error factor fixed to %.1f\n",
- X HDB_ERR_FACT);
- X ERRFACT = HDB_ERR_FACT;
- X }
- X break;
- #endif
- X case 'p':
- X PrefixPath = optarg;
- X break;
- X case 'z':
- X ChartSize = atoi (optarg);
- X break;
- X case 'y':
- X DoHourlyActivityChart = FALSE;
- X break;
- X case 'o':
- X DoChartOnly = TRUE;
- X break;
- X case 'v':
- X VerboseOutput = TRUE;
- X break;
- X case 'O':
- X (void) InsertSys (optarg);
- X JustSomeSystem = TRUE;
- X break;
- X case '?':
- X case 'i':
- X DisplayUsage ();
- X exit (1);
- X break;
- X }
- X }
- X
- X printf ("The Uucp Analyzer (TUA) rel. %s by piggy@idea.sublink.org (Lele Gaifax)\n\n", RELEASE);
- X
- X if (ReadHistory () == ERROR)
- X error ("rhistory");
- X if (ProcXferstats () == ERROR)
- X error ("xferstats");
- X if (!DoChartOnly)
- X {
- X if (ProcUucico () == ERROR)
- X error ("uucico log");
- X if (ProcUuxqt () == ERROR)
- X error ("uuxqt log");
- X if (ProcUucp () == ERROR)
- X error ("uucp log");
- X if (ProcUux () == ERROR)
- X error ("uux log");
- X
- X Since = strdup (ctime (&StatStartingTime));
- X Since[strlen (Since) - 1] = '\0'; /* Strip the ending '\n' */
- X
- X DaysSinceLastClean = (Now - StatStartingTime) / (3600L * 24L) + 1;
- X printf ("HoneyDanBeer UUCP Analysis for ``%.9s%s'',\n since %s to %s (%d day%c)\n\n",
- X SystemName, DOMAIN, Since, CurrentTime, DaysSinceLastClean,
- X (DaysSinceLastClean > 1 ? 's' : ' '));
- X if (DoSystemReport)
- X SystemsReport ();
- X if (DoUserReport)
- X UsersReport ();
- X if (DoDailyReport)
- X DailyReport ();
- X if (SeparatedCommLog)
- X {
- X if (DoSystemReport)
- X SystemsCommandReport ();
- X if (DoUserReport)
- X UsersCommandReport ();
- X if (DoDailyReport)
- X DailyCommandReport ();
- X }
- X SystemSummary ();
- X SystemSummaryTable ();
- X if (*TheEpoc && DoHistoryReport)
- X {
- X SystemHistoryTable ();
- X if (DoMonthlyActivityReport)
- X MonthlyHistoryTable ();
- X }
- X if (DoHourlyActivityChart)
- X HourlyActivityCharts ();
- X if (SaveHistory)
- X if (WriteHistory (ResetHistory) == ERROR)
- X error ("whistory: probably you need uucp's write permission");
- X }
- X else
- X {
- X printf ("HoneyDanBeer UUCP Analysis for ``%.9s%s''\n\n", SystemName, DOMAIN);
- X HourlyActivityCharts ();
- X }
- X exit (0);
- }
- SHAR_EOF
- chmod 0444 tua.c ||
- echo 'restore of tua.c failed'
- Wc_c="`wc -c < 'tua.c'`"
- test 9130 -eq "$Wc_c" ||
- echo 'tua.c: original size 9130, current size' "$Wc_c"
- fi
- # ============= usertree.c ==============
- if test -f 'usertree.c' -a X"$1" != X"-c"; then
- echo 'x - skipping usertree.c (File already exists)'
- else
- echo 'x - extracting usertree.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'usertree.c' &&
- /* $Id: usertree.c,v 3.3 1991/09/01 14:02:51 piggy Rel $
- X * Users list maintenance. Users are kept in a binary tree.
- X *
- X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * SYNOPSIS:
- X * int InsertUser(char * user);
- X * Look for user in the users tree: if it is already there, return a
- X * pointer to it, otherwise make an entry and reset its info.
- X *
- X * void EnquiryUser(void (*funct)(userrep_t user))
- X * For each node in the tree, process it using the funct function with
- X * the userrep_t struct as parameter. It is a void function.
- X *
- X * void KillUser(char * user);
- X * Make user a phantom user,do not display its info in any of the report.
- X */
- X
- #include <stdio.h>
- #include "mem.h"
- #include <string.h>
- #include "hdbstat.h"
- X
- typedef struct usertree
- {
- X userrep_t Node;
- X struct usertree *L;
- X struct usertree *R;
- } usertree_t;
- X
- #define TNULL (usertree_t *) NULL
- X
- static FlistHead UserFlist =
- {
- X 0, 0, 0
- };
- X
- static usertree_t *Root = TNULL;
- X
- static userrep_t *
- UserTree (tree, user)
- X usertree_t **tree;
- X char *user;
- X
- {
- X int cmpres;
- X
- X if (*tree == TNULL)
- X {
- X register userrep_t *sr;
- X
- X if (UserFlist.size == 0)
- X MemInit (&UserFlist, sizeof (struct usertree), 20, 10);
- X *tree = (usertree_t *) new (&UserFlist);
- X (*tree)->L = (*tree)->R = TNULL;
- X sr = &((*tree)->Node);
- X sr->User = strdup (user);
- X sr->Killed = FALSE;
- X sr->Commands = (Tcommrep_t) NULL;
- X return (&(*tree)->Node);
- X }
- X else if ((cmpres = strcmp (user, (*tree)->Node.User)) < 0)
- X return UserTree (&(*tree)->L, user);
- X else if (cmpres > 0)
- X return UserTree (&(*tree)->R, user);
- X else
- X return (&(*tree)->Node);
- }
- X
- userrep_t *
- InsertUser (user)
- X char *user;
- X
- {
- X return UserTree (&Root, user);
- }
- X
- void
- KillUser (user)
- X char *user;
- X
- {
- X UserTree (&Root, user)->Killed = TRUE;
- }
- X
- static void
- ProcUserTree (tree, funct)
- X usertree_t *tree;
- X void (*funct) ();
- X
- {
- X if (tree != TNULL)
- X {
- X ProcUserTree (tree->L, funct);
- X if (!(tree->Node.Killed))
- X (*funct) (tree->Node);
- X ProcUserTree (tree->R, funct);
- X }
- }
- X
- void
- EnquiryUser (funct)
- X void (*funct) ();
- X
- {
- X ProcUserTree (Root, funct);
- }
- SHAR_EOF
- chmod 0444 usertree.c ||
- echo 'restore of usertree.c failed'
- Wc_c="`wc -c < 'usertree.c'`"
- test 2907 -eq "$Wc_c" ||
- echo 'usertree.c: original size 2907, current size' "$Wc_c"
- fi
- # ============= xferentry.c ==============
- if test -f 'xferentry.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xferentry.c (File already exists)'
- else
- echo 'x - extracting xferentry.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xferentry.c' &&
- /* $Id: xferentry.c,v 3.3 1991/09/01 14:02:55 piggy Rel $
- X * Process /usr/spool/uucp.Admin/xferstat: read each line, parse it and
- X * return the values in it.
- X *
- X * Copyright (C) 1991 Lele Gaifax (piggy@idea.sublink.org)
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * SYNOPSIS:
- X * int GetXferEntry( struct xferentry * entry);
- X * Returns EOF at the end, ERROR if it is not able to open the file,
- X * OK in all the other cases.
- X *
- X */
- X
- #include <stdio.h>
- #include <string.h>
- #include "hdbstat.h"
- #include <time.h>
- X
- #ifdef HDB_ERR_FACT
- float ERRFACT = 2.5;
- #endif
- X
- int
- GetXferEntry (entry)
- X struct xferentry *entry;
- X
- {
- X char line[256], datebuffer[20];
- X static FILE *xfer_fp = (FILE *) NULL;
- X extern int atoi ();
- X extern double atof ();
- X time_t timestamp;
- X
- X if (xfer_fp == NULL)
- X {
- X char xfername[LPNMAX];
- X
- X sprintf (xfername, "%s/%s", PrefixPath, XFER_NAME);
- X if ((xfer_fp = fopen (xfername, "r")) == (FILE *) NULL)
- X {
- X perror ("GetXferEntry(fopen)");
- X return (ERROR);
- X }
- X }
- X
- X if (fgets (line, 256, xfer_fp) == NULL)
- X {
- X fclose (xfer_fp);
- X return (EOF);
- X }
- X
- X strcpy (entry->System, strtok (line, "!"));
- X strcpy (entry->User, strtok (NULL, " "));
- X entry->Month = atoi (strtok (NULL, " MS(/"));
- X entry->Day = atoi (strtok (NULL, "-"));
- X entry->Hour = atoi (strtok (NULL, ":"));
- X entry->Min = atoi (strtok (NULL, ":"));
- X entry->Sec = atoi (strtok (NULL, ")"));
- X sprintf(datebuffer, "%d/%d-%d:%d:%d", entry->Month, entry->Day, entry->Hour,
- X entry->Min, entry->Sec);
- X timestamp = get_date(datebuffer);
- X entry->DayOfWeek = localtime(×tamp)->tm_wday;
- X (void) strtok (NULL, "[");
- X strcpy (entry->PortName, strtok (NULL, "]"));
- X if (strcmp ("<-", strtok (NULL, " ")))
- X entry->Direction = 'S';
- X else
- X entry->Direction = 'R';
- X entry->Bytes = atof (strtok (NULL, " "));
- X
- #ifdef HDB_ERR_FACT
- X entry->Time = (float) atof (strtok (NULL, " /")) / ERRFACT;
- #else
- X entry->Time = (float) atof (strtok (NULL, " /"));
- #endif
- X return OK;
- }
- SHAR_EOF
- chmod 0444 xferentry.c ||
- echo 'restore of xferentry.c failed'
- Wc_c="`wc -c < 'xferentry.c'`"
- test 2694 -eq "$Wc_c" ||
- echo 'xferentry.c: original size 2694, current size' "$Wc_c"
- fi
- # ============= tmparse.c ==============
- if test -f 'tmparse.c' -a X"$1" != X"-c"; then
- echo 'x - skipping tmparse.c (File already exists)'
- else
- echo 'x - extracting tmparse.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'tmparse.c' &&
- /* $Id: tmparse.c,v 3.3 1991/09/01 14:03:32 piggy Rel $
- X *
- X * @(#)tmparse.c 1.2.piggy 91/03/29 parse a time specification
- X * Written by Mike Stefanik
- X *
- X * Since it would be rather ridiculous to copyright (or copyleft) this
- X * little snippit of code, it is released into the public domain. Use
- X * as you will.
- X *
- X * tmparse(3) will parse a date specification, and return the time in
- X * natural format (the number of seconds since Jan 1, 1970 00:00)
- X *
- X * The buffer can contain the date portion (ie: 3/29/91), the time portion
- X * (ie: 14:00:34), or both. If no time is entered, the default is the
- X * current time; if no date is entered, the default is the current date.
- X *
- X */
- X
- /*
- X * Modified to deal with fixed format as the uucico's one: mm/dd-hh:mm:ss
- X * Since those silly logs are missing the year, I have to compare the
- X * month and the day with the current one: if they are greater, clearly
- X * they refer to the last year...
- X *
- X * Changed tmparse(buf,when) to get_date(buf) for compatibility with the
- X * rest of TUA.
- X *
- X * piggy@idea.sublink.org - 6 Apr 1991
- X */
- X
- X
- #include <stdio.h>
- #include <sys/types.h>
- #include <time.h>
- X
- #define ONE_DAY 86400L /* number of seconds in a day */
- #define ONE_YEAR 31536000L /* number of seconds in a year */
- X
- int mdays[12] =
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- X
- time_t
- get_date (buf)
- X char *buf;
- {
- X long date;
- X static long now = -1L;
- X static int current_year, current_month, current_day;
- X int year, month = 0, day = 0;
- X int hours, mins, secs, count;
- X struct tm *lt;
- X
- X if (now == -1L) /* Is it the first time that they call you? */
- X {
- X time (&now);
- X lt = localtime (&now);
- X current_year = lt->tm_year + 1900;
- X current_month = lt->tm_mon;
- X current_day = lt->tm_mday - 1;
- X }
- X
- X sscanf(buf, "%d/%d-%d:%d:%d", &month, &day, &hours, &mins, &secs);
- X month--;
- X day--;
- X
- X /*
- X * Check the day vs current_day and month vs current_month to if their
- X * year was last year or the current one.
- X * Thanx to all uucico engineers!
- X */
- X
- X if (current_month < month || (current_month == month && current_day < day))
- X year = current_year-1;
- X else
- X year = current_year;
- X
- X /* count the number of seconds up to the specified year */
- X
- X date = 0L;
- X for (count = 1970; count < year; count++)
- X {
- X date += ONE_YEAR;
- X
- #if 0 /* reduntant: if (count % 400) == 0 then also (count % 4) == 0)! */
- X if (count % 4 == 0 || count % 400 == 0)
- X date += ONE_DAY;
- #else
- X if (count % 4 == 0)
- X date += ONE_DAY;
- #endif
- X }
- X
- X /* adjust for timezone differences */
- X
- X date += timezone;
- X
- X /* count the number of seconds from the start of the year to
- X the specified day */
- X
- X for (count = 0; count < month; count++)
- X {
- X date += mdays[count] * ONE_DAY;
- #if 0 /* Bad leap year check! */
- X if (count == 1 && (year % 4 == 0 || year % 400 == 0))
- X date += ONE_DAY;
- #else
- X if (count == 1 && (year%4 == 0 && (year%100 != 0 || year%400 == 0)))
- X date += ONE_DAY;
- #endif
- X }
- X
- X /* adjust for the specified time */
- X
- X date += (day * ONE_DAY) + secs + (mins * 60) + (hours * 3600);
- X
- X lt = localtime (&date);
- X date += (hours - lt->tm_hour) * 3600;
- X
- X return (date);
- }
- X
- #ifdef MAIN
- X
- main ()
- {
- X char buf[64];
- X long when;
- X extern long tmparse ();
- X
- X while (gets (buf) != NULL)
- X {
- X tmparse (buf, &when);
- X printf ("%s", ctime (&when));
- X }
- }
- X
- #endif
- X
- SHAR_EOF
- chmod 0444 tmparse.c ||
- echo 'restore of tmparse.c failed'
- Wc_c="`wc -c < 'tmparse.c'`"
- test 3449 -eq "$Wc_c" ||
- echo 'tmparse.c: original size 3449, current size' "$Wc_c"
- fi
- true || echo 'restore of getopt.c failed'
- echo End of part 3, continue with part 4
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-