home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume23 / tua / part03 < prev    next >
Encoding:
Text File  |  1991-09-23  |  40.5 KB  |  1,500 lines

  1. Newsgroups: comp.sources.misc
  2. From: piggy@idea.sublink.org (Lele Gaifas)
  3. Subject:  v23i009:  tua - The Uucp Analyzer, Part03/05
  4. Message-ID: <1991Sep22.203522.22994@sparky.imd.sterling.com>
  5. X-Md4-Signature: 43a346b80ce241c3e4aa1601bb291467
  6. Date: Sun, 22 Sep 1991 20:35:22 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: piggy@idea.sublink.org (Lele Gaifas)
  10. Posting-number: Volume 23, Issue 9
  11. Archive-name: tua/part03
  12. Environment: Xenix, SYSV
  13.  
  14. ---- Cut Here and feed the following to sh ----
  15. # This is part 03 of a multipart archive
  16. # ============= reports.c ==============
  17. if test -f 'reports.c' -a X"$1" != X"-c"; then
  18.     echo 'x - skipping reports.c (File already exists)'
  19. else
  20. echo 'x - extracting reports.c (Text)'
  21. sed 's/^X//' << 'SHAR_EOF' > 'reports.c' &&
  22. /* $Id: reports.c,v 3.3 1991/09/01 14:02:43 piggy Rel $
  23. X * Print reports.
  24. X *
  25. X *   Copyright (C) 1991  Lele Gaifax (piggy@idea.sublink.org)
  26. X *
  27. X *   This program is free software; you can redistribute it and/or modify
  28. X *   it under the terms of the GNU General Public License as published by
  29. X *   the Free Software Foundation; either version 1, or (at your option)
  30. X *   any later version.
  31. X *
  32. X *   This program is distributed in the hope that it will be useful,
  33. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. X *   GNU General Public License for more details.
  36. X *
  37. X *   You should have received a copy of the GNU General Public License
  38. X *   along with this program; if not, write to the Free Software
  39. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40. X *
  41. X * SYNOPSIS:
  42. X * void    SystemsReport();
  43. X * void SystemsCommandReport();
  44. X * void UsersReport();
  45. X * void UsersCommandReport();
  46. X * void DailyReport();
  47. X * void DailyCommandReport();
  48. X * void SystemSummary();
  49. X * void SystemSummaryTable();
  50. X * void SystemHistoryTable();
  51. X * void MonthlyHistoryTable();
  52. X * void HourlyActivityCharts();
  53. X *
  54. X */
  55. X
  56. #include    <stdio.h>
  57. X
  58. #ifdef USG
  59. #include    <malloc.h>
  60. #else
  61. extern char * malloc();
  62. #endif
  63. X
  64. #include    "hdbstat.h"
  65. X
  66. #define BYTES_PER_KBYTE         1024.0
  67. #define BYTES_PER_MBYTE         1024000.0
  68. X
  69. #define NotZero(rec)    \
  70. X    (rec.FilesOut || rec.FilesIn || rec.BytesOut || rec.BytesIn || \
  71. X     rec.TimeOut || rec.TimeIn)
  72. X
  73. static char *            /* Transforms seconds to "hh:mm:ss" */
  74. TimeToString (tim)
  75. X     float tim;
  76. {
  77. X  char *str;
  78. X  int hh, mm, ss;
  79. X  register time_t ltim = (time_t) tim;
  80. X
  81. X  ltim = (time_t) tim;
  82. X  hh = (int) (ltim / 3600L);
  83. X  ltim %= 3600L;
  84. X  mm = (int) (ltim / 60L);
  85. X  ss = (int) (ltim % 60L);
  86. X  str = malloc (20);
  87. X  sprintf (str, "%4d:%02d:%02d.%02d",
  88. X           hh, mm, ss, (int) ((tim - (int) (tim)) * 100));
  89. X  return (str);
  90. }
  91. X
  92. static void
  93. Commands (comm)
  94. X     commrep_t comm;
  95. {
  96. X  if (comm.Number > 1)
  97. X    printf ("\t(%3d) ", comm.Number);
  98. X  else
  99. X    printf ("\t      ");
  100. X  printf ("%s\n", comm.Command);
  101. }
  102. X
  103. static void
  104. SR (system)
  105. X     sysrep_t system;
  106. {
  107. X  if (NotZero (system))
  108. X    {
  109. X      printf ("%-11.11s  %4d %8.f%s %4d   %4d %8.f%s %4d\n",
  110. X          system.System,
  111. X          system.FilesIn, system.BytesIn / BYTES_PER_KBYTE,
  112. X          TimeToString (system.TimeIn),
  113. X          (system.TimeIn ? (int) (system.BytesIn / system.TimeIn) : 0),
  114. X          system.FilesOut, system.BytesOut / BYTES_PER_KBYTE,
  115. X          TimeToString (system.TimeOut),
  116. X        (system.TimeOut ? (int) (system.BytesOut / system.TimeOut) : 0));
  117. X      if (DoCommandReport && !SeparatedCommLog && system.Commands)
  118. X    {
  119. X      puts ("\tCommands:\n\t=========");
  120. X      EnquiryComm (system.Commands, Commands);
  121. X      puts ("");
  122. X    }
  123. X    }
  124. }
  125. X
  126. static void
  127. SRnocomm (system)
  128. X     sysrep_t system;
  129. {
  130. X  if (system.Commands)
  131. X    {
  132. X      printf ("    %s:\n", system.System);
  133. X      EnquiryComm (system.Commands, Commands);
  134. X      puts ("");
  135. X    }
  136. }
  137. X
  138. void
  139. SystemsReport ()
  140. {
  141. X  puts ("By System:");
  142. X  puts ("==========");
  143. X  puts ("                     R E C E I V E D                       S E N T");
  144. X  puts ("System       Files  KBytes     Time      ATP   Files  KBytes     Time      ATP\n");
  145. X  EnquirySys (SR);
  146. }
  147. X
  148. void
  149. SystemsCommandReport ()
  150. {
  151. X  if (DoCommandReport)
  152. X    {
  153. X      puts ("\nCommands By System:");
  154. X      puts ("===================");
  155. X      EnquirySys (SRnocomm);
  156. X      puts ("");
  157. X    }
  158. }
  159. X
  160. static void
  161. UR (user)
  162. X     userrep_t user;
  163. {
  164. X  printf ("%-11.11s  %4d  %8.f  %s\n",
  165. X      user.User,
  166. X          user.FilesOut, user.BytesOut / BYTES_PER_KBYTE,
  167. X          TimeToString (user.TimeOut));
  168. X  if (DoCommandReport && !SeparatedCommLog && user.Commands)
  169. X    {
  170. X      puts ("\tCommands:");
  171. X      puts ("\t=========");
  172. X      EnquiryComm (user.Commands, Commands);
  173. X      puts ("");
  174. X    }
  175. }
  176. X
  177. static void
  178. URnocomm (user)
  179. X     userrep_t user;
  180. {
  181. X  if (user.Commands)
  182. X    {
  183. X      printf ("    %s:\n", user.User);
  184. X      EnquiryComm (user.Commands, Commands);
  185. X      puts ("");
  186. X    }
  187. }
  188. X
  189. void
  190. UsersReport ()
  191. {
  192. X  puts ("\nBy User:");
  193. X  puts ("========");
  194. X  puts ("                        S E N T");
  195. X  puts ("User         Files   KBytes      Time\n");
  196. X  EnquiryUser (UR);
  197. }
  198. X
  199. void
  200. UsersCommandReport ()
  201. {
  202. X  if (DoCommandReport)
  203. X    {
  204. X      puts ("\nBy User:");
  205. X      puts ("========");
  206. X      EnquiryUser (URnocomm);
  207. X    }
  208. }
  209. X
  210. static void
  211. DR (day)
  212. X     dailyrep_t day;
  213. {
  214. X  printf ("%02d/%02d  %4d  %8.f  %s  %4d  %8.f  %s\n",
  215. X      day.Month, day.Day,
  216. X      day.FilesIn, day.BytesIn / BYTES_PER_KBYTE,
  217. X          TimeToString (day.TimeIn),
  218. X      day.FilesOut, day.BytesOut / BYTES_PER_KBYTE,
  219. X          TimeToString (day.TimeOut));
  220. X  if (DoCommandReport && !SeparatedCommLog && day.Commands)
  221. X    {
  222. X      puts ("\tCommands:");
  223. X      puts ("\t=========");
  224. X      EnquiryComm (day.Commands, Commands);
  225. X      puts ("");
  226. X    }
  227. }
  228. X
  229. static void
  230. DRnocomm (day)
  231. X     dailyrep_t day;
  232. {
  233. X  if (day.Commands)
  234. X    {
  235. X      printf ("    %02d/%02d:\n", day.Month, day.Day);
  236. X      EnquiryComm (day.Commands, Commands);
  237. X      puts ("");
  238. X    }
  239. }
  240. X
  241. void
  242. DailyReport ()
  243. {
  244. X  puts ("\nBy Day:");
  245. X  puts ("=======");
  246. X  puts ("Date       R E C E I V E D                     S E N T");
  247. X  puts ("Mo/Dy  Files   KBytes       Time      Files   KBytes       Time\n");
  248. X  EnquiryDay (DR);
  249. }
  250. X
  251. void
  252. DailyCommandReport ()
  253. {
  254. X  if (DoCommandReport)
  255. X    {
  256. X      puts ("\nBy Day:");
  257. X      puts ("=======");
  258. X      EnquiryDay (DRnocomm);
  259. X    }
  260. }
  261. X
  262. static void
  263. SummBySys (system)
  264. X     sysrep_t system;
  265. {
  266. X  extern char * ctime PROTO((long *));
  267. X  
  268. X  if (NotZero (system) || system.Calls)
  269. X    {
  270. X      register idx;
  271. X
  272. X      printf ("\n%s:\n", system.System);
  273. X      printf ("\tRecvd\t%10.f (%4d Files) in %s: %4d cps\n",
  274. X          system.BytesIn, system.FilesIn, TimeToString (system.TimeIn),
  275. X          (system.TimeIn ? (int) (system.BytesIn / system.TimeIn) : 0));
  276. X      printf ("\tSent\t%10.f (%4d Files) in %s: %4d cps\n",
  277. X        system.BytesOut, system.FilesOut, TimeToString (system.TimeOut),
  278. X       (system.TimeOut ? (int) (system.BytesOut / system.TimeOut) : 0));
  279. X      if (system.BytesIn > system.BytesOut)
  280. X    printf ("\tRecvd\t%10.f bytes more than sent.\n",
  281. X        system.BytesIn - system.BytesOut);
  282. X      else if (system.BytesIn < system.BytesOut)
  283. X    printf ("\tSent\t%10.f bytes more than received.\n",
  284. X        system.BytesOut - system.BytesIn);
  285. X      printf ("\tThe system has been connected for  %s\n",
  286. X          TimeToString (system.TimeConnect));
  287. X      printf ("\tLast connection: %s", ctime(&system.LastConnection));
  288. X      for (idx = 0; idx < PHONE_PRICING_TB; idx++)
  289. X        if (system.PhoneCost[idx] != .0)
  290. X          printf ("\tTime spent transmitting in %s: %s\n",
  291. X                  PhoneCategoryNames[idx],
  292. X                  TimeToString (system.PhoneCost[idx]));
  293. X      printf ("\tThere have been %d call%s (with an average of %d Ok/day):\n\t\t\t\t\t",
  294. X          system.Calls, (system.Calls == 1 ? "" : "s"),
  295. X          (system.CallsOK / DaysSinceLastClean));
  296. X      if (system.CallsOK)
  297. X        {
  298. X          if (system.CallsSTOPPED)
  299. X            printf ("%3d OK (%3d IN, %3d OUT, %3d BREAKED)\n\t\t\t\t\t",
  300. X                    system.CallsOK, system.CallsIn,
  301. X                    system.CallsOut, system.CallsSTOPPED);
  302. X          else
  303. X            printf ("%3d OK (%3d IN, %3d OUT)\n\t\t\t\t\t",
  304. X                    system.CallsOK, system.CallsIn, system.CallsOut);
  305. X        }
  306. X      if (system.CallsFAIL)
  307. X    printf ("%3d FAILED\n\t\t\t\t\t", system.CallsFAIL);
  308. X    }
  309. }
  310. X
  311. void
  312. SystemSummary ()
  313. {
  314. X  puts ("\nSUMMARY by System:");
  315. X  puts ("==================");
  316. X  EnquirySys (SummBySys);
  317. X  puts ("");
  318. }
  319. X
  320. static float TotTimeIn = 0.0, TotTimeOut = 0.0;
  321. static float TotBytesIn = 0.0, TotBytesOut = 0.0;
  322. static int TotFilesIn = 0, TotFilesOut = 0;
  323. X
  324. static char *
  325. BytesToString (byt)
  326. X     float byt;
  327. {
  328. X  char *stringa = malloc (11);
  329. X
  330. X  sprintf (stringa, "%9.f", byt / BYTES_PER_KBYTE);
  331. X  return stringa;
  332. }
  333. X
  334. static void
  335. SummBySysTable (sys)
  336. X     sysrep_t sys;
  337. {
  338. X  float TotTime = sys.TimeIn + sys.TimeOut;
  339. X  float TotBytes = sys.BytesOut + sys.BytesIn;
  340. X
  341. X  if (NotZero (sys))
  342. X    {
  343. X      TotTimeIn += sys.TimeIn;
  344. X      TotTimeOut += sys.TimeOut;
  345. X      TotBytesIn += sys.BytesIn;
  346. X      TotBytesOut += sys.BytesOut;
  347. X      TotFilesIn += sys.FilesIn;
  348. X      TotFilesOut += sys.FilesOut;
  349. X      printf ("|%-8.8s| %s :%10.10s: %5d | %s :%10.10s: %5d | %4d|\n",
  350. X          sys.System, BytesToString (sys.BytesIn), TimeToString (sys.TimeIn), sys.FilesIn,
  351. X      BytesToString (sys.BytesOut), TimeToString (sys.TimeOut), sys.FilesOut,
  352. X          (TotTime ? (int) (TotBytes / TotTime) : 0));
  353. X    }
  354. }
  355. X
  356. void
  357. SystemSummaryTable ()
  358. {
  359. X  puts ("+--------+------------------------------+------------------------------+-----+");
  360. X  puts ("|        |        R E C E I V E D       |            S E N T           |     |");
  361. X  puts ("| SYSTEM | KiloBytes :   Time   : Files | KiloBytes :   Time   : Files | ATP |");
  362. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  363. X  EnquirySys (SummBySysTable);
  364. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  365. X  printf ("| TOTALS | %s :%10.10s: %5d | %s :%10.10s: %5d | ####|\n",
  366. X      BytesToString (TotBytesIn), TimeToString (TotTimeIn), TotFilesIn,
  367. X       BytesToString (TotBytesOut), TimeToString (TotTimeOut), TotFilesOut);
  368. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  369. }
  370. X
  371. static void
  372. SysHistoryTable (sys)
  373. X     sysrep_t sys;
  374. {
  375. X  float TotTime = sys.History.TimeIn + sys.History.TimeOut +
  376. X  sys.TimeIn + sys.TimeOut;
  377. X  float TotBytes = sys.History.BytesOut + sys.History.BytesIn +
  378. X  sys.BytesIn + sys.BytesOut;
  379. X
  380. X  if (NotZero (sys) || NotZero (sys.History))
  381. X    {
  382. X      TotTimeIn += sys.History.TimeIn;
  383. X      TotTimeOut += sys.History.TimeOut;
  384. X      TotBytesIn += sys.History.BytesIn;
  385. X      TotBytesOut += sys.History.BytesOut;
  386. X      TotFilesIn += sys.History.FilesIn;
  387. X      TotFilesOut += sys.History.FilesOut;
  388. X      printf ("|%-8.8s| %s :%10.10s: %5d | %s :%10.10s: %5d | %4d|\n",
  389. X          sys.System, BytesToString (sys.History.BytesIn + sys.BytesIn),
  390. X          TimeToString (sys.History.TimeIn + sys.TimeIn),
  391. X          sys.History.FilesIn + sys.FilesIn,
  392. X          BytesToString (sys.History.BytesOut + sys.BytesOut),
  393. X          TimeToString (sys.History.TimeOut + sys.TimeOut),
  394. X          sys.History.FilesOut + sys.FilesOut,
  395. X          (TotTime ? (int) (TotBytes / TotTime) : 0));
  396. X    }
  397. }
  398. X
  399. void
  400. SystemHistoryTable ()
  401. {
  402. X  printf ("\n...and since %s\n", TheEpoc);
  403. X  puts ("+--------+------------------------------+------------------------------+-----+");
  404. X  puts ("|        |        R E C E I V E D       |            S E N T           |     |");
  405. X  puts ("| SYSTEM | KiloBytes :   Time   : Files | KiloBytes :   Time   : Files | ATP |");
  406. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  407. X  EnquirySys (SysHistoryTable);
  408. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  409. X  printf ("| TOTALS | %s :%10.10s: %5d | %s :%10.10s: %5d | ####|\n",
  410. X      BytesToString (TotBytesIn), TimeToString (TotTimeIn), TotFilesIn,
  411. X       BytesToString (TotBytesOut), TimeToString (TotTimeOut), TotFilesOut);
  412. X  puts ("+--------+-----------:----------:-------+-----------:----------:-------+-----|");
  413. }
  414. X
  415. static float MonthlyActivityTotals[12];
  416. X
  417. static void
  418. MonHistoryTable (sys)
  419. X     sysrep_t sys;
  420. {
  421. X  int idx;
  422. X  float sum = .0;
  423. X
  424. X  for (idx = 0; idx <= 11; idx++)
  425. X    sum += sys.History.MonthlyActivity[idx];
  426. X
  427. X  if (sum > 0.0)
  428. X    {
  429. X      printf ("\n%-6.6s", sys.System);
  430. X      for (idx = 0; idx <= 11; idx++)
  431. X    {
  432. X      float bytes =
  433. X      sys.History.MonthlyActivity[(idx + CurrentMonth + 1) % 12];
  434. X
  435. X      MonthlyActivityTotals[(idx + CurrentMonth + 1) % 12] += bytes;
  436. X      if (bytes == -1.0)
  437. X        printf ("| *** ");
  438. X      else if (bytes < 10.0 * BYTES_PER_KBYTE)
  439. X        printf ("|%4.0f ", bytes);
  440. X      else if (bytes < 10.0 * BYTES_PER_MBYTE)
  441. X        printf ("|%4.0fK", bytes / BYTES_PER_KBYTE);
  442. X      else
  443. X        printf ("|%4.0fM", bytes / BYTES_PER_MBYTE);
  444. X    }
  445. X    }
  446. }
  447. X
  448. void
  449. MonthlyHistoryTable ()
  450. {
  451. X  static char *MonthName[] =
  452. X  {
  453. X    "Jan", "Feb", "Mar", "Apr",
  454. X    "May", "Jun", "Jul", "Ago",
  455. X    "Sep", "Oct", "Nov", "Dic"
  456. X  };
  457. X  int idx;
  458. X
  459. X  puts ("\n\nLast 12 Months Activity");
  460. X  puts ("=======================\n");
  461. X  printf ("------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
  462. X  printf ("System");
  463. X  for (idx = 0; idx <= 11; idx++)
  464. X    {
  465. X      printf ("| %s", MonthName[(idx + CurrentMonth + 1) % 12]);
  466. X      if (idx != 11)
  467. X    putchar (' ');
  468. X    }
  469. X  printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----");
  470. X  EnquirySys (MonHistoryTable);
  471. X  printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
  472. X  printf ("TOTALS");
  473. X  for (idx = 0; idx <= 11; idx++)
  474. X    {
  475. X      float bytes = MonthlyActivityTotals[(idx + CurrentMonth + 1) % 12];
  476. X
  477. X      if (bytes < 0.0)
  478. X    printf ("| *** ");
  479. X      else if (bytes < 10.0 * BYTES_PER_KBYTE)
  480. X    printf ("|%4.0f ", bytes);
  481. X      else if (bytes < 10.0 * BYTES_PER_MBYTE)
  482. X    printf ("|%4.0fK", bytes / BYTES_PER_KBYTE);
  483. X      else
  484. X    printf ("|%4.0fM", bytes / BYTES_PER_MBYTE);
  485. X    }
  486. X  printf ("\n------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----\n");
  487. }
  488. X
  489. static float PortActivityTotals[TIMESLICES] = {0};
  490. static int IsGlobalActivityChart = 0;
  491. static int NumberOfPorts = 0;
  492. X
  493. static void
  494. CountPorts (port)
  495. X     portact_t port;
  496. X
  497. {
  498. X  NumberOfPorts++;
  499. }
  500. X
  501. static void
  502. PortActivityChart (port)
  503. X     portact_t port;
  504. {
  505. X  int row, slice;
  506. X  float maxval = 0.0;
  507. X  float scale;
  508. X
  509. X  for (slice = 0; slice < TIMESLICES; slice++)
  510. X    {
  511. X      float curval;
  512. X
  513. X      if (!IsGlobalActivityChart)
  514. X    PortActivityTotals[slice] += (curval = port.Activity[slice]);
  515. X      else
  516. X    curval = PortActivityTotals[slice];
  517. X
  518. X      if (curval > maxval)
  519. X    maxval = curval;
  520. X    }
  521. X  scale = maxval / ChartSize;
  522. X
  523. X  if (IsGlobalActivityChart || NumberOfPorts == 1)
  524. X    {
  525. X      printf ("\n\nGlobal Hourly Activity (on a 20 minutes basis)\n");
  526. X      puts ("==============================================\n");
  527. X    }
  528. X  else
  529. X    {
  530. X      printf ("\n\nHourly Activity (on a 20 minutes basis) on %s\n", port.Port);
  531. X      puts ("======================================================\n");
  532. X    }
  533. X  printf ("Max Value :     %.0f bytes\nScale     : '#'=%.0f bytes\n\n", maxval, scale);
  534. X  for (row = ChartSize; row > 0; row--)
  535. X    {
  536. X      float current_value = row * scale;
  537. X
  538. X      printf ("     ");
  539. X      for (slice = 0; slice < 72; slice++)
  540. X    {
  541. X      float curval = (IsGlobalActivityChart ?
  542. X              PortActivityTotals[slice] : port.Activity[slice]);
  543. X      if (curval >= current_value)
  544. X        putchar ('#');
  545. X      else
  546. X        putchar (' ');
  547. X    }
  548. X      puts ("");
  549. X    }
  550. X  puts ("     ========================================================================");
  551. 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");
  552. }
  553. X
  554. void
  555. HourlyActivityCharts ()
  556. {
  557. X  portact_t dummy;
  558. X
  559. X  EnquiryPort (CountPorts);
  560. X  EnquiryPort (PortActivityChart);
  561. X  if (NumberOfPorts > 1)
  562. X    {
  563. X      IsGlobalActivityChart++;
  564. X      PortActivityChart (dummy);
  565. X    }
  566. }
  567. SHAR_EOF
  568. chmod 0444 reports.c ||
  569. echo 'restore of reports.c failed'
  570. Wc_c="`wc -c < 'reports.c'`"
  571. test 15023 -eq "$Wc_c" ||
  572.     echo 'reports.c: original size 15023, current size' "$Wc_c"
  573. fi
  574. # ============= systree.c ==============
  575. if test -f 'systree.c' -a X"$1" != X"-c"; then
  576.     echo 'x - skipping systree.c (File already exists)'
  577. else
  578. echo 'x - extracting systree.c (Text)'
  579. sed 's/^X//' << 'SHAR_EOF' > 'systree.c' &&
  580. /* $Id: systree.c,v 3.3 1991/09/01 14:02:47 piggy Rel $
  581. X * Systems tree management.
  582. X *
  583. X *   Copyright (C) 1991  Lele Gaifax (piggy@idea.sublink.org)
  584. X *
  585. X *   This program is free software; you can redistribute it and/or modify
  586. X *   it under the terms of the GNU General Public License as published by
  587. X *   the Free Software Foundation; either version 1, or (at your option)
  588. X *   any later version.
  589. X *
  590. X *   This program is distributed in the hope that it will be useful,
  591. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  592. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  593. X *   GNU General Public License for more details.
  594. X *
  595. X *   You should have received a copy of the GNU General Public License
  596. X *   along with this program; if not, write to the Free Software
  597. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  598. X *
  599. X * SYNOPSIS:
  600. X * sysrep_t * InsertSys(char * sys);
  601. X *      Look for sys in the tree. If it is already there, return a pointer
  602. X *      to its info. Otherwise make a new entry and initialize it.
  603. X *
  604. X * void EnquirySys(void (*funct)(sysrep_t sys))
  605. X *      For each node in the tree, process its info through funct.
  606. X *
  607. X * void KillSys(char * sys);
  608. X *      Do not show the system in any of the reports
  609. X *
  610. X * sysrep_t * CheckSystemEsist(char * sys)
  611. X *      Look for sys in the tree. If it is there, return a pointer to its info,
  612. X *      otherwise NULL.
  613. X */
  614. X
  615. #include    <stdio.h>
  616. #include    "mem.h"
  617. #include    <string.h>
  618. #include    "hdbstat.h"
  619. X
  620. typedef struct systree
  621. {
  622. X  sysrep_t Node;
  623. X  struct systree *L;
  624. X  struct systree *R;
  625. } systree_t;
  626. X
  627. #define    TNULL    (systree_t *) NULL
  628. X
  629. static FlistHead SysFlist =
  630. {
  631. X  0, 0, 0
  632. };
  633. X
  634. static systree_t *Root = TNULL;
  635. X
  636. static sysrep_t *
  637. SysTree (tree, sys, insert_flag)
  638. X     systree_t **tree;
  639. X     char *sys;
  640. X     int insert_flag;
  641. X
  642. {
  643. X  int cmpres;
  644. X
  645. X  if (*tree == TNULL)
  646. X    if (insert_flag)
  647. X      {
  648. X        register sysrep_t *sr;
  649. X        int idx;
  650. X
  651. X        if (SysFlist.size == 0)
  652. X          MemInit (&SysFlist, sizeof (systree_t), 20, 5);
  653. X        *tree = (systree_t *) new (&SysFlist);
  654. X        (*tree)->L = (*tree)->R = TNULL;
  655. X        sr = &((*tree)->Node);
  656. X        sr->System = strdup (sys);
  657. X        sr->Killed = FALSE;
  658. X        sr->FilesOut = sr->FilesIn = 0;
  659. X        sr->BytesOut = sr->BytesIn = 0.0;
  660. X        sr->TimeOut = sr->TimeIn = sr->TimeConnect = 0.0;
  661. X        sr->Calls = sr->CallsOK = sr->CallsFAIL = sr->CallsSTOPPED = 0;
  662. X        sr->CallsIn = sr->CallsOut = 0;
  663. X        sr->Commands = (Tcommrep_t) NULL;
  664. X        sr->History.FilesOut = sr->History.FilesIn = 0;
  665. X        sr->History.BytesOut = sr->History.BytesIn = 0.0;
  666. X        sr->History.TimeOut = sr->History.TimeIn = 0.0;
  667. X        for (idx = 0; idx <= 11; idx++)
  668. X          sr->History.MonthlyActivity[idx] = -1.0;
  669. X        for (idx = 0; idx < PHONE_PRICING_TB; idx++)
  670. X          sr->PhoneCost[idx] = 0.0;
  671. X        sr->History.LastMonthProcessed = -1;
  672. X        return (&(*tree)->Node);
  673. X      }
  674. X    else
  675. X      return (sysrep_t *) NULL;
  676. X  else if ((cmpres = strcmp (sys, (*tree)->Node.System)) < 0)
  677. X    return SysTree (&(*tree)->L, sys, insert_flag);
  678. X  else if (cmpres > 0)
  679. X    return SysTree (&(*tree)->R, sys, insert_flag);
  680. X  else
  681. X    return (&(*tree)->Node);
  682. }
  683. X
  684. sysrep_t *
  685. InsertSys (sys)
  686. X     char *sys;
  687. X
  688. {
  689. X  return SysTree (&Root, sys, TRUE);
  690. }
  691. X
  692. void
  693. KillSys (sys)
  694. X     char *sys;
  695. X
  696. {
  697. X  SysTree (&Root, sys, TRUE)->Killed = TRUE;
  698. }
  699. X
  700. static void
  701. ProcSysTree (tree, funct)
  702. X     systree_t *tree;
  703. X     void (*funct) ();
  704. X
  705. {
  706. X  if (tree != TNULL)
  707. X    {
  708. X      ProcSysTree (tree->L, funct);
  709. X      if (!(tree->Node.Killed))
  710. X    (*funct) (tree->Node);
  711. X      ProcSysTree (tree->R, funct);
  712. X    }
  713. }
  714. X
  715. void
  716. EnquirySys (funct)
  717. X     void (*funct) ();
  718. X
  719. {
  720. X  ProcSysTree (Root, funct);
  721. }
  722. X
  723. sysrep_t *
  724. CheckSystemEsist(sys)
  725. X     char * sys;
  726. X
  727. {
  728. X  return (SysTree(&Root, sys, FALSE));
  729. }
  730. SHAR_EOF
  731. chmod 0444 systree.c ||
  732. echo 'restore of systree.c failed'
  733. Wc_c="`wc -c < 'systree.c'`"
  734. test 3809 -eq "$Wc_c" ||
  735.     echo 'systree.c: original size 3809, current size' "$Wc_c"
  736. fi
  737. # ============= tua.c ==============
  738. if test -f 'tua.c' -a X"$1" != X"-c"; then
  739.     echo 'x - skipping tua.c (File already exists)'
  740. else
  741. echo 'x - extracting tua.c (Text)'
  742. sed 's/^X//' << 'SHAR_EOF' > 'tua.c' &&
  743. /* $Id: tua.c,v 3.3 1991/09/01 14:02:49 piggy Rel $
  744. X * HDB-uucp Activity Analyzer. Eat all the uucp logs and extract per system,
  745. X * user and daily stats.
  746. X *
  747. X *   Copyright (C) 1991  Lele Gaifax (piggy@idea.sublink.org)
  748. X *
  749. X *   This program is free software; you can redistribute it and/or modify
  750. X *   it under the terms of the GNU General Public License as published by
  751. X *   the Free Software Foundation; either version 1, or (at your option)
  752. X *   any later version.
  753. X *
  754. X *   This program is distributed in the hope that it will be useful,
  755. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  756. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  757. X *   GNU General Public License for more details.
  758. X *
  759. X *   You should have received a copy of the GNU General Public License
  760. X *   along with this program; if not, write to the Free Software
  761. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  762. X *
  763. X */
  764. X
  765. #include    <stdio.h>
  766. #include    <time.h>
  767. #include    "hdbstat.h"
  768. #ifdef USG
  769. #include    <string.h>
  770. #else
  771. #include    <strings.h>
  772. #endif
  773. #include    "patchlevel.h"
  774. #include    "getopt.h"
  775. X
  776. #ifdef USG
  777. #include <malloc.h>
  778. #else
  779. extern char *malloc ();
  780. #endif
  781. X
  782. #ifdef __GNUC__
  783. static inline void
  784. error (char *str)
  785. {
  786. X  fprintf (stderr, "Error in processing %s\n", str);
  787. X  exit (1);
  788. }
  789. X
  790. #else
  791. #define    error(str)  { \
  792. X            fprintf(stderr, "Error in processing %s\n", str); \
  793. X            exit(1); \
  794. X            }
  795. #endif
  796. X
  797. #ifdef STRDUP_MISSING
  798. X
  799. char *
  800. strdup (string)
  801. X     char *string;
  802. X
  803. {
  804. X  char *tmp = malloc (strlen (string) + 1);
  805. X
  806. X  if (tmp)
  807. X    return (strcpy (tmp, stringa));
  808. X  else
  809. X    return tmp;
  810. }
  811. X
  812. #endif /* STRDUP_MISSING */
  813. X
  814. X
  815. int SeparatedCommLog = FALSE;
  816. int DoCommandReport = FALSE;
  817. int VerboseOutput = FALSE;
  818. int JustSomeSystem = FALSE;
  819. int ChartSize = 10;
  820. char *PrefixPath = "/usr/spool/uucp";
  821. char *CurrentTime;
  822. int CurrentMonth;
  823. char *Since;
  824. int DaysSinceLastClean;
  825. X
  826. static void
  827. DisplayUsage ()
  828. {
  829. X  fprintf (stderr, "The Uucp Analyzer (TUA) rel. %s by piggy@idea.sublink.org (Lele Gaifax)\n\nOptions:\n", RELEASE);
  830. X  fputs ("\
  831. -S, +no-sys-rep      Do not show the report for the Systems\n\
  832. -U, +no-user-rep     Do not show the report for the Users\n\
  833. -D, +no-daily-rep    Do not show the day-by-day report\n\
  834. -m, +no-monthly-act  Do not show the monthly activity report\n\
  835. -h, +no-history      Do not show the history\n\
  836. -y, +no-hourly-chart Do not show the hourly activity chart\n\
  837. -C, +command-lists   Show the various command lists\n\
  838. -O, +only-system SYS Consider just SYS in the reports\n", stderr);
  839. X  fputs ("\
  840. -c, +separate-com    Build a separate log for the commands\n\
  841. -k, +kill-system SYS Do not show anything about system SYS\n\
  842. -K, +kill-user USER  Do not show anything about user USER\n\
  843. -H, +update-hist     Update the history file\n\
  844. -0, +reset-hist      Reset the history file\n\
  845. -p, +prefix-path DIR Use DIR instead of /usr/spool/uucp (for debugging only)\n\
  846. -z, +chart-size SIZE Set the size of the hourly chart to SIZE rows\n", stderr);
  847. X  fputs ("\
  848. -o, +chart-only      Print only the hourly activity chart\n\
  849. -v, +verbose         Print infos while processing\n\
  850. -i, +help            Get this help\n\
  851. ", stderr);
  852. X
  853. #ifdef HDB_ERR_FACT
  854. X  fputs ("\
  855. -f, +hdb-factor F    Set the Correction Factor for HDB to F (by default. 2.5)\n\
  856. ", stderr);
  857. #endif
  858. X
  859. X  fputs ("\n\tPlease report bugs and problems to:\n\
  860. \t\tpiggy@idea.sublink.org\n\n", stderr);
  861. X  fputs ("\
  862. TUA may be copied only under the terms of the GNU General Public License,\n\
  863. a copy of which can be found with the TUA distribution package\n", stderr);
  864. }
  865. X
  866. int
  867. main (argc, argv)
  868. X     int argc;
  869. X     char *argv[];
  870. {
  871. X  extern double atof ();
  872. X  extern int uname ();
  873. X  extern char *optarg;
  874. X  extern int opterr;
  875. X  int opt;
  876. X  int optidx;
  877. X  static int DoSystemReport = TRUE;
  878. X  static int DoUserReport = TRUE;
  879. X  static int DoDailyReport = TRUE;
  880. X  static int SaveHistory = FALSE;
  881. X  static int DoHistoryReport = TRUE;
  882. X  static int ResetHistory = FALSE;
  883. X  static int DoMonthlyActivityReport = TRUE;
  884. X  static int DoHourlyActivityChart = TRUE;
  885. X  static int DoChartOnly = FALSE;
  886. X  extern long time ();
  887. X  char SystemName[9];
  888. X  long Now = time ((long *) 0);
  889. X  static struct option long_options[] =
  890. X  {
  891. X    {"no-sys-rep", 0, &DoSystemReport, FALSE},    /* -S */
  892. X    {"no-user-rep", 0, &DoUserReport, FALSE},    /* -U */
  893. X    {"no-daily-rep", 0, &DoDailyReport, FALSE},    /* -D */
  894. X    {"command-lists", 0, &DoCommandReport, TRUE},    /* -C */
  895. X    {"no-monthly-act", 0, &DoMonthlyActivityReport, FALSE},    /* -m */
  896. X    {"no-history", 0, &DoHistoryReport, FALSE},    /* -h */
  897. X    {"only-system", 1, 0, 'O'},    /* -O */
  898. #ifdef HDB_ERR_FACT
  899. X    {"hdb-factor", 1, 0, 'f'},    /* -f */
  900. #endif
  901. X    {"separate-com", 0, &SeparatedCommLog, TRUE},    /* -c */
  902. X    {"kill-system", 1, 0, 'k'},    /* -k */
  903. X    {"kill-user", 1, 0, 'K'},    /* -K */
  904. X    {"update-hist", 0, &SaveHistory, TRUE},    /* -H */
  905. X    {"reset-hist", 0, &ResetHistory, TRUE},    /* -0 */
  906. X    {"help", 0, 0, 'i'},    /* -i */
  907. X    {"prefix-path", 1, 0, 'p'},    /* -p */
  908. X    {"chart-size", 1, 0, 'z'},    /* -z */
  909. X    {"no-hourly-chart", 0, &DoHourlyActivityChart, FALSE},    /* -y */
  910. X    {"chart-only", 0, &DoChartOnly, TRUE},    /* -o */
  911. X    {"verbose", 0, &VerboseOutput, TRUE},    /* -v */
  912. X    {0, 0, 0, 0}
  913. X  };
  914. X
  915. X  CurrentTime = strdup (asctime (localtime (&Now)));
  916. X  CurrentTime[strlen (CurrentTime) - 1] = '\0';    /* Strip the ending '\0' */
  917. X
  918. X  CurrentMonth = localtime (&Now)->tm_mon;
  919. X
  920. X  opterr = FALSE;
  921. X
  922. #ifdef SYSTEMID
  923. X  if ((gethostname (SystemName, 9) == -1) || *SystemName == '\0')
  924. X    {
  925. X      FILE *fd;
  926. X
  927. X      if ((fd = fopen (SYSTEMID, "r")) == NULL)
  928. X    strcpy (SystemName, "UNKNOWN");
  929. X      else
  930. X    {
  931. X      int last = strlen (fgets (SystemName, 9, fd)) - 1;
  932. X
  933. X      if (last > 0)
  934. X        {
  935. X          if (SystemName[last] == '\n')
  936. X        SystemName[last] = '\0';
  937. X        }
  938. X      else
  939. X        strcpy (SystemName, "??????");
  940. X      fclose (fd);
  941. X    }
  942. X    }
  943. #else
  944. X  if ((gethostname (SystemName, 9) == -1) || *SystemName == '\0')
  945. X    strcpy (SystemName, "UNKNOWN");
  946. #endif
  947. X
  948. #ifdef HDB_ERR_FACT
  949. #define OPTSTR "SUDCm:hck:K:H0ifp:z:yovO:"
  950. #else
  951. #define OPTSTR "SUDCm:hck:K:H0ip:z:yovO:"
  952. #endif
  953. X
  954. X  while ((opt = getopt_long (argc, argv, OPTSTR, long_options, &optidx)) != EOF)
  955. X    {
  956. X      if (opt == 0 && long_options[optidx].flag == 0)
  957. X    opt = long_options[optidx].val;
  958. X      switch (opt)
  959. X    {
  960. X    case 0:
  961. X      break;
  962. X    case 'S':
  963. X      DoSystemReport = FALSE;
  964. X      break;
  965. X    case 'U':
  966. X      DoUserReport = FALSE;
  967. X      break;
  968. X    case 'D':
  969. X      DoDailyReport = FALSE;
  970. X      break;
  971. X    case 'C':
  972. X      DoCommandReport = TRUE;
  973. X      break;
  974. X    case 'm':
  975. X      DoMonthlyActivityReport = FALSE;
  976. X      break;
  977. X    case 'h':
  978. X      DoHistoryReport = FALSE;
  979. X      break;
  980. X    case 'c':
  981. X      SeparatedCommLog = FALSE;
  982. X      break;
  983. X    case 'k':
  984. X      KillSys (optarg);
  985. X      break;
  986. X    case 'K':
  987. X      KillUser (optarg);
  988. X      break;
  989. X    case 'H':
  990. X      SaveHistory = TRUE;
  991. X      break;
  992. X    case '0':
  993. X      ResetHistory = TRUE;
  994. X      break;
  995. #ifdef HDB_ERR_FACT
  996. X    case 'f':
  997. X      ERRFACT = (float) atof (optarg);
  998. X      if (ERRFACT <= 0.0)
  999. X        {
  1000. X          fprintf (stderr,
  1001. X               "Bad -f argument. Error factor fixed to %.1f\n",
  1002. X               HDB_ERR_FACT);
  1003. X          ERRFACT = HDB_ERR_FACT;
  1004. X        }
  1005. X      break;
  1006. #endif
  1007. X    case 'p':
  1008. X      PrefixPath = optarg;
  1009. X      break;
  1010. X    case 'z':
  1011. X      ChartSize = atoi (optarg);
  1012. X      break;
  1013. X    case 'y':
  1014. X      DoHourlyActivityChart = FALSE;
  1015. X      break;
  1016. X    case 'o':
  1017. X      DoChartOnly = TRUE;
  1018. X      break;
  1019. X    case 'v':
  1020. X      VerboseOutput = TRUE;
  1021. X      break;
  1022. X    case 'O':
  1023. X      (void) InsertSys (optarg);
  1024. X      JustSomeSystem = TRUE;
  1025. X      break;
  1026. X    case '?':
  1027. X    case 'i':
  1028. X      DisplayUsage ();
  1029. X      exit (1);
  1030. X      break;
  1031. X    }
  1032. X    }
  1033. X
  1034. X  printf ("The Uucp Analyzer (TUA) rel. %s by piggy@idea.sublink.org (Lele Gaifax)\n\n", RELEASE);
  1035. X
  1036. X  if (ReadHistory () == ERROR)
  1037. X    error ("rhistory");
  1038. X  if (ProcXferstats () == ERROR)
  1039. X    error ("xferstats");
  1040. X  if (!DoChartOnly)
  1041. X    {
  1042. X      if (ProcUucico () == ERROR)
  1043. X    error ("uucico log");
  1044. X      if (ProcUuxqt () == ERROR)
  1045. X    error ("uuxqt log");
  1046. X      if (ProcUucp () == ERROR)
  1047. X    error ("uucp log");
  1048. X      if (ProcUux () == ERROR)
  1049. X    error ("uux log");
  1050. X
  1051. X      Since = strdup (ctime (&StatStartingTime));
  1052. X      Since[strlen (Since) - 1] = '\0';    /* Strip the ending '\n' */
  1053. X
  1054. X      DaysSinceLastClean = (Now - StatStartingTime) / (3600L * 24L) + 1;
  1055. X      printf ("HoneyDanBeer UUCP Analysis for ``%.9s%s'',\n  since %s to %s (%d day%c)\n\n",
  1056. X          SystemName, DOMAIN, Since, CurrentTime, DaysSinceLastClean,
  1057. X          (DaysSinceLastClean > 1 ? 's' : ' '));
  1058. X      if (DoSystemReport)
  1059. X    SystemsReport ();
  1060. X      if (DoUserReport)
  1061. X    UsersReport ();
  1062. X      if (DoDailyReport)
  1063. X    DailyReport ();
  1064. X      if (SeparatedCommLog)
  1065. X    {
  1066. X      if (DoSystemReport)
  1067. X        SystemsCommandReport ();
  1068. X      if (DoUserReport)
  1069. X        UsersCommandReport ();
  1070. X      if (DoDailyReport)
  1071. X        DailyCommandReport ();
  1072. X    }
  1073. X      SystemSummary ();
  1074. X      SystemSummaryTable ();
  1075. X      if (*TheEpoc && DoHistoryReport)
  1076. X    {
  1077. X      SystemHistoryTable ();
  1078. X      if (DoMonthlyActivityReport)
  1079. X        MonthlyHistoryTable ();
  1080. X    }
  1081. X      if (DoHourlyActivityChart)
  1082. X    HourlyActivityCharts ();
  1083. X      if (SaveHistory)
  1084. X    if (WriteHistory (ResetHistory) == ERROR)
  1085. X      error ("whistory: probably you need uucp's write permission");
  1086. X    }
  1087. X  else
  1088. X    {
  1089. X      printf ("HoneyDanBeer UUCP Analysis for ``%.9s%s''\n\n", SystemName, DOMAIN);
  1090. X      HourlyActivityCharts ();
  1091. X    }
  1092. X  exit (0);
  1093. }
  1094. SHAR_EOF
  1095. chmod 0444 tua.c ||
  1096. echo 'restore of tua.c failed'
  1097. Wc_c="`wc -c < 'tua.c'`"
  1098. test 9130 -eq "$Wc_c" ||
  1099.     echo 'tua.c: original size 9130, current size' "$Wc_c"
  1100. fi
  1101. # ============= usertree.c ==============
  1102. if test -f 'usertree.c' -a X"$1" != X"-c"; then
  1103.     echo 'x - skipping usertree.c (File already exists)'
  1104. else
  1105. echo 'x - extracting usertree.c (Text)'
  1106. sed 's/^X//' << 'SHAR_EOF' > 'usertree.c' &&
  1107. /* $Id: usertree.c,v 3.3 1991/09/01 14:02:51 piggy Rel $
  1108. X * Users list maintenance. Users are kept in a binary tree.
  1109. X *
  1110. X *   Copyright (C) 1991  Lele Gaifax (piggy@idea.sublink.org)
  1111. X *
  1112. X *   This program is free software; you can redistribute it and/or modify
  1113. X *   it under the terms of the GNU General Public License as published by
  1114. X *   the Free Software Foundation; either version 1, or (at your option)
  1115. X *   any later version.
  1116. X *
  1117. X *   This program is distributed in the hope that it will be useful,
  1118. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1119. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1120. X *   GNU General Public License for more details.
  1121. X *
  1122. X *   You should have received a copy of the GNU General Public License
  1123. X *   along with this program; if not, write to the Free Software
  1124. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1125. X *
  1126. X * SYNOPSIS:
  1127. X * int    InsertUser(char * user);
  1128. X *      Look for user in the users tree: if it is already there, return a
  1129. X *      pointer to it, otherwise make an entry and reset its info.
  1130. X *
  1131. X * void EnquiryUser(void (*funct)(userrep_t user))
  1132. X *      For each node in the tree, process it using the funct function with
  1133. X *      the userrep_t struct as parameter. It is a void function.
  1134. X *
  1135. X * void KillUser(char * user);
  1136. X *    Make user a phantom user,do not display its info in any of the report.
  1137. X */
  1138. X
  1139. #include    <stdio.h>
  1140. #include    "mem.h"
  1141. #include    <string.h>
  1142. #include    "hdbstat.h"
  1143. X
  1144. typedef struct usertree
  1145. {
  1146. X  userrep_t Node;
  1147. X  struct usertree *L;
  1148. X  struct usertree *R;
  1149. } usertree_t;
  1150. X
  1151. #define    TNULL    (usertree_t *) NULL
  1152. X
  1153. static FlistHead UserFlist =
  1154. {
  1155. X  0, 0, 0
  1156. };
  1157. X
  1158. static usertree_t *Root = TNULL;
  1159. X
  1160. static userrep_t *
  1161. UserTree (tree, user)
  1162. X     usertree_t **tree;
  1163. X     char *user;
  1164. X
  1165. {
  1166. X  int cmpres;
  1167. X
  1168. X  if (*tree == TNULL)
  1169. X    {
  1170. X      register userrep_t *sr;
  1171. X
  1172. X      if (UserFlist.size == 0)
  1173. X    MemInit (&UserFlist, sizeof (struct usertree), 20, 10);
  1174. X      *tree = (usertree_t *) new (&UserFlist);
  1175. X      (*tree)->L = (*tree)->R = TNULL;
  1176. X      sr = &((*tree)->Node);
  1177. X      sr->User = strdup (user);
  1178. X      sr->Killed = FALSE;
  1179. X      sr->Commands = (Tcommrep_t) NULL;
  1180. X      return (&(*tree)->Node);
  1181. X    }
  1182. X  else if ((cmpres = strcmp (user, (*tree)->Node.User)) < 0)
  1183. X    return UserTree (&(*tree)->L, user);
  1184. X  else if (cmpres > 0)
  1185. X    return UserTree (&(*tree)->R, user);
  1186. X  else
  1187. X    return (&(*tree)->Node);
  1188. }
  1189. X
  1190. userrep_t *
  1191. InsertUser (user)
  1192. X     char *user;
  1193. X
  1194. {
  1195. X  return UserTree (&Root, user);
  1196. }
  1197. X
  1198. void 
  1199. KillUser (user)
  1200. X     char *user;
  1201. X
  1202. {
  1203. X  UserTree (&Root, user)->Killed = TRUE;
  1204. }
  1205. X
  1206. static void 
  1207. ProcUserTree (tree, funct)
  1208. X     usertree_t *tree;
  1209. X     void (*funct) ();
  1210. X
  1211. {
  1212. X  if (tree != TNULL)
  1213. X    {
  1214. X      ProcUserTree (tree->L, funct);
  1215. X      if (!(tree->Node.Killed))
  1216. X    (*funct) (tree->Node);
  1217. X      ProcUserTree (tree->R, funct);
  1218. X    }
  1219. }
  1220. X
  1221. void 
  1222. EnquiryUser (funct)
  1223. X     void (*funct) ();
  1224. X
  1225. {
  1226. X  ProcUserTree (Root, funct);
  1227. }
  1228. SHAR_EOF
  1229. chmod 0444 usertree.c ||
  1230. echo 'restore of usertree.c failed'
  1231. Wc_c="`wc -c < 'usertree.c'`"
  1232. test 2907 -eq "$Wc_c" ||
  1233.     echo 'usertree.c: original size 2907, current size' "$Wc_c"
  1234. fi
  1235. # ============= xferentry.c ==============
  1236. if test -f 'xferentry.c' -a X"$1" != X"-c"; then
  1237.     echo 'x - skipping xferentry.c (File already exists)'
  1238. else
  1239. echo 'x - extracting xferentry.c (Text)'
  1240. sed 's/^X//' << 'SHAR_EOF' > 'xferentry.c' &&
  1241. /* $Id: xferentry.c,v 3.3 1991/09/01 14:02:55 piggy Rel $
  1242. X * Process /usr/spool/uucp.Admin/xferstat: read each line, parse it and
  1243. X * return the values in it.
  1244. X *
  1245. X *   Copyright (C) 1991  Lele Gaifax (piggy@idea.sublink.org)
  1246. X *
  1247. X *   This program is free software; you can redistribute it and/or modify
  1248. X *   it under the terms of the GNU General Public License as published by
  1249. X *   the Free Software Foundation; either version 1, or (at your option)
  1250. X *   any later version.
  1251. X *
  1252. X *   This program is distributed in the hope that it will be useful,
  1253. X *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1254. X *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1255. X *   GNU General Public License for more details.
  1256. X *
  1257. X *   You should have received a copy of the GNU General Public License
  1258. X *   along with this program; if not, write to the Free Software
  1259. X *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1260. X *
  1261. X * SYNOPSIS:
  1262. X * int    GetXferEntry( struct xferentry * entry);
  1263. X *      Returns EOF at the end, ERROR if it is not able to open the file,
  1264. X *      OK in all the other cases.
  1265. X *
  1266. X */
  1267. X
  1268. #include    <stdio.h>
  1269. #include    <string.h>
  1270. #include    "hdbstat.h"
  1271. #include    <time.h>
  1272. X
  1273. #ifdef HDB_ERR_FACT
  1274. float ERRFACT = 2.5;
  1275. #endif
  1276. X
  1277. int
  1278. GetXferEntry (entry)
  1279. X     struct xferentry *entry;
  1280. X
  1281. {
  1282. X  char line[256], datebuffer[20];
  1283. X  static FILE *xfer_fp = (FILE *) NULL;
  1284. X  extern int atoi ();
  1285. X  extern double atof ();
  1286. X  time_t timestamp;
  1287. X
  1288. X  if (xfer_fp == NULL)
  1289. X    {
  1290. X      char xfername[LPNMAX];
  1291. X
  1292. X      sprintf (xfername, "%s/%s", PrefixPath, XFER_NAME);
  1293. X      if ((xfer_fp = fopen (xfername, "r")) == (FILE *) NULL)
  1294. X    {
  1295. X      perror ("GetXferEntry(fopen)");
  1296. X      return (ERROR);
  1297. X    }
  1298. X    }
  1299. X
  1300. X  if (fgets (line, 256, xfer_fp) == NULL)
  1301. X    {
  1302. X      fclose (xfer_fp);
  1303. X      return (EOF);
  1304. X    }
  1305. X
  1306. X  strcpy (entry->System, strtok (line, "!"));
  1307. X  strcpy (entry->User, strtok (NULL, " "));
  1308. X  entry->Month = atoi (strtok (NULL, " MS(/"));
  1309. X  entry->Day = atoi (strtok (NULL, "-"));
  1310. X  entry->Hour = atoi (strtok (NULL, ":"));
  1311. X  entry->Min = atoi (strtok (NULL, ":"));
  1312. X  entry->Sec = atoi (strtok (NULL, ")"));
  1313. X  sprintf(datebuffer, "%d/%d-%d:%d:%d", entry->Month, entry->Day, entry->Hour,
  1314. X          entry->Min, entry->Sec);
  1315. X  timestamp = get_date(datebuffer);
  1316. X  entry->DayOfWeek = localtime(×tamp)->tm_wday;
  1317. X  (void) strtok (NULL, "[");
  1318. X  strcpy (entry->PortName, strtok (NULL, "]"));
  1319. X  if (strcmp ("<-", strtok (NULL, " ")))
  1320. X    entry->Direction = 'S';
  1321. X  else
  1322. X    entry->Direction = 'R';
  1323. X  entry->Bytes = atof (strtok (NULL, " "));
  1324. X
  1325. #ifdef HDB_ERR_FACT
  1326. X  entry->Time = (float) atof (strtok (NULL, " /")) / ERRFACT;
  1327. #else
  1328. X  entry->Time = (float) atof (strtok (NULL, " /"));
  1329. #endif
  1330. X  return OK;
  1331. }
  1332. SHAR_EOF
  1333. chmod 0444 xferentry.c ||
  1334. echo 'restore of xferentry.c failed'
  1335. Wc_c="`wc -c < 'xferentry.c'`"
  1336. test 2694 -eq "$Wc_c" ||
  1337.     echo 'xferentry.c: original size 2694, current size' "$Wc_c"
  1338. fi
  1339. # ============= tmparse.c ==============
  1340. if test -f 'tmparse.c' -a X"$1" != X"-c"; then
  1341.     echo 'x - skipping tmparse.c (File already exists)'
  1342. else
  1343. echo 'x - extracting tmparse.c (Text)'
  1344. sed 's/^X//' << 'SHAR_EOF' > 'tmparse.c' &&
  1345. /* $Id: tmparse.c,v 3.3 1991/09/01 14:03:32 piggy Rel $
  1346. X * 
  1347. X * @(#)tmparse.c   1.2.piggy     91/03/29    parse a time specification
  1348. X * Written by Mike Stefanik
  1349. X *
  1350. X * Since it would be rather ridiculous to copyright (or copyleft) this
  1351. X * little snippit of code, it is released into the public domain.  Use
  1352. X * as you will.
  1353. X *
  1354. X * tmparse(3) will parse a date specification, and return the time in
  1355. X * natural format (the number of seconds since Jan 1, 1970 00:00)
  1356. X *
  1357. X * The buffer can contain the date portion (ie: 3/29/91), the time portion
  1358. X * (ie: 14:00:34), or both.   If no time is entered, the default is the
  1359. X * current time; if no date is entered, the default is the current date.
  1360. X *
  1361. X */
  1362. X
  1363. /*
  1364. X * Modified to deal with fixed format as the uucico's one: mm/dd-hh:mm:ss
  1365. X * Since those silly logs are missing the year, I have to compare the
  1366. X * month and the day with the current one: if they are greater, clearly
  1367. X * they refer to the last year...
  1368. X *
  1369. X * Changed tmparse(buf,when) to get_date(buf) for compatibility with the
  1370. X * rest of TUA.
  1371. X * 
  1372. X * piggy@idea.sublink.org - 6 Apr 1991
  1373. X */
  1374. X
  1375. X
  1376. #include <stdio.h>
  1377. #include <sys/types.h>
  1378. #include <time.h>
  1379. X
  1380. #define ONE_DAY        86400L    /* number of seconds in a day */
  1381. #define ONE_YEAR    31536000L    /* number of seconds in a year */
  1382. X
  1383. int mdays[12] =
  1384. {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  1385. X
  1386. time_t
  1387. get_date (buf)
  1388. X     char *buf;
  1389. {
  1390. X  long date;
  1391. X  static long now = -1L;
  1392. X  static int current_year, current_month, current_day;
  1393. X  int year, month = 0, day = 0;
  1394. X  int hours, mins, secs, count;
  1395. X  struct tm *lt;
  1396. X
  1397. X  if (now == -1L)               /* Is it the first time that they call you? */
  1398. X    {
  1399. X      time (&now);
  1400. X      lt = localtime (&now);
  1401. X      current_year = lt->tm_year + 1900;
  1402. X      current_month = lt->tm_mon;
  1403. X      current_day = lt->tm_mday - 1;
  1404. X    }
  1405. X  
  1406. X  sscanf(buf, "%d/%d-%d:%d:%d", &month, &day, &hours, &mins, &secs);
  1407. X  month--;
  1408. X  day--;
  1409. X  
  1410. X  /*
  1411. X   * Check the day vs current_day and month vs current_month to if their
  1412. X   * year was last year or the current one.
  1413. X   * Thanx to all uucico engineers!
  1414. X   */
  1415. X  
  1416. X  if (current_month < month || (current_month == month && current_day < day))
  1417. X    year = current_year-1;
  1418. X  else
  1419. X    year = current_year;
  1420. X  
  1421. X  /* count the number of seconds up to the specified year */
  1422. X
  1423. X  date = 0L;
  1424. X  for (count = 1970; count < year; count++)
  1425. X    {
  1426. X      date += ONE_YEAR;
  1427. X
  1428. #if 0     /* reduntant: if (count % 400) == 0 then also (count % 4) == 0)! */
  1429. X      if (count % 4 == 0 || count % 400 == 0)
  1430. X    date += ONE_DAY;
  1431. #else
  1432. X      if (count % 4 == 0)
  1433. X        date += ONE_DAY;
  1434. #endif      
  1435. X    }
  1436. X
  1437. X  /* adjust for timezone differences */
  1438. X
  1439. X  date += timezone;
  1440. X
  1441. X  /* count the number of seconds from the start of the year to
  1442. X     the specified day */
  1443. X
  1444. X  for (count = 0; count < month; count++)
  1445. X    {
  1446. X      date += mdays[count] * ONE_DAY;
  1447. #if 0                           /* Bad leap year check! */
  1448. X      if (count == 1 && (year % 4 == 0 || year % 400 == 0))
  1449. X    date += ONE_DAY;
  1450. #else
  1451. X      if (count == 1 && (year%4 == 0 && (year%100 != 0 || year%400 == 0)))
  1452. X        date += ONE_DAY;
  1453. #endif    
  1454. X    }
  1455. X
  1456. X  /* adjust for the specified time */
  1457. X
  1458. X  date += (day * ONE_DAY) + secs + (mins * 60) + (hours * 3600);
  1459. X
  1460. X  lt = localtime (&date);
  1461. X  date += (hours - lt->tm_hour) * 3600;
  1462. X
  1463. X  return (date);
  1464. }
  1465. X
  1466. #ifdef MAIN
  1467. X
  1468. main ()
  1469. {
  1470. X  char buf[64];
  1471. X  long when;
  1472. X  extern long tmparse ();
  1473. X
  1474. X  while (gets (buf) != NULL)
  1475. X    {
  1476. X      tmparse (buf, &when);
  1477. X      printf ("%s", ctime (&when));
  1478. X    }
  1479. }
  1480. X
  1481. #endif
  1482. X
  1483. SHAR_EOF
  1484. chmod 0444 tmparse.c ||
  1485. echo 'restore of tmparse.c failed'
  1486. Wc_c="`wc -c < 'tmparse.c'`"
  1487. test 3449 -eq "$Wc_c" ||
  1488.     echo 'tmparse.c: original size 3449, current size' "$Wc_c"
  1489. fi
  1490. true || echo 'restore of getopt.c failed'
  1491. echo End of part 3, continue with part 4
  1492. exit 0
  1493. exit 0 # Just in case...
  1494. -- 
  1495. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1496. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1497. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1498. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1499.