home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / iaktimes.zip / iaktimes.cmd next >
OS/2 REXX Batch file  |  1995-05-28  |  3KB  |  109 lines

  1. /* Rexx utility to get connection times from TCPOS2.INI file
  2.  * These are the connection times recorded by the IBM Dial-Up for TCP/IP
  3.  * program,  SLIPPM.
  4.  *
  5.  * syntax:  IAKTIMES
  6.  *
  7.  * output:  a summary of the connection times as stored by SLIPPM listed
  8.  *          by connection identifier and totaled.
  9.  *
  10.  * Written by: Dan Douglas
  11.  *             dandoug@scruznet.com 
  12.  *
  13.  * Feel free to use, distribute or modify as you see fit.  If you find it
  14.  * helpful, send me a postcard.
  15.  */
  16.  
  17. /* Save command name for use in messages */
  18. Parse upper source . . src '.CMD'
  19. src = substr(src, lastpos('\',src)+1)
  20. msghdr = '>>'src'>>'
  21.  
  22. /* Set field widths and NLS strings for formatting */
  23. al  = 10 /* application name length */
  24. sl  = 10 /* max digits in seconds string */
  25. hl  = 4  /* max digits in connect hours */
  26. dl  = 2  /* max ditits in connect days */
  27. day = 'day, ' /* singular day label */
  28. dys = 'days,' /* plural days label */
  29. ll  = al + sl + hl + dl + length(dys) + 21
  30.  
  31. err = 'ERROR:'
  32. all = 'ALL:'
  33. tck = 'TOTAL_CONNECT'  /* key for total connect seconds */
  34. etc = 'ETC'            /* ennvironment variable with path */
  35. fn  = 'TCPOS2.INI'     /* ini file name */
  36. env = 'OS2ENVIRONMENT' /* environment for OS/2 variables */
  37.  
  38. ts     = 'total'
  39. msgs.1 = 'OS/2 environment variable 'etc' must be set to 'fn' path.'
  40. msgs.2 = 'Error reading 'fn' applications.'
  41. msgs.3 = 'No applications with non-zero 'tck' time found.'
  42.  
  43. /* Get value of ETC environment variable and use it to build
  44.    full name TCPOS2.INI file */
  45. path = VALUE(etc,,env)
  46. if path = '' then do
  47.    say msghdr msgs.1
  48.    exit -1
  49. end  /* Do */
  50. ini_file = path"\"fn
  51.  
  52. /* Load utility function to read INI file*/
  53. call RxFuncAdd 'SysIni', 'RexxUtil', 'SysIni'
  54.  
  55. /* Read all the applications in the INI file */
  56. if SysIni(ini_file,all,'Apps.') = err then do
  57.    say msghdr msgs.2
  58.    exit -2
  59. end  /* Do */
  60.  
  61. /* Find all the applications with a TOTAL_CONNECT key that has
  62.    a non-blank, non-zero value */
  63. total = 0
  64. Do i = 1 to Apps.0
  65.   l_ct = SysIni(ini_file,Apps.i,tck)
  66.   parse value l_ct with l_ct '00'x 
  67.   if l_ct \= err & l_ct \= '' & l_ct \= 0 then do
  68.     say left(Apps.i,al) right(l_ct,sl) hms(l_ct)
  69.     total = total + l_ct
  70.   end
  71. end
  72.  
  73. /* Put out summary lines */
  74. if total = 0 then do /* did we find what we wanted?*/
  75.   say msghdr msgs.3
  76.   exit -3
  77.  end
  78. else do
  79.    say copies('-',ll)
  80.    say left(ts,al) right(total,sl) hms(total)
  81. end  /* Do */
  82.  
  83. exit 0
  84.  
  85. /* Subroutine to compute hours, minutes, seconds from seconds */
  86. HMS: procedure expose hl dl day dys
  87.  p_s = ARG(1)        /* single argument, number of seconds */
  88.  
  89.  hh  = p_s %  3600   /* number of whole hours */
  90.  m_s = p_s // 3600   /* leftover seconds from whole hours */
  91.  mm  = m_s %  60     /* number of whole minutes */
  92.  ss  = m_s // 60     /* leftover seconds from whole minutes */
  93.  
  94.  dd  = hh  %  24     /* whole days */
  95.  dh  = hh  // 24     /* leftover hours from whole days */
  96.  
  97.  ms  = right(mm,2,'0')':'right(ss,2,'0')  /* min/sec part of display */
  98.  
  99.  hs = right(hh,hl)':'ms  /* hourly result */
  100.  
  101.  if dd > 1 then  /* more than one day? */
  102.   ds = '('right(dd,dl)' 'dys' 'right(dh,2,0)':'ms')'
  103.  else if dd = 1 then /* only one day, leave off 's' in display */
  104.   ds = '('right(dd,dl)' 'day' 'right(dh,2,0)':'ms')'
  105.  else /* just hours...left day part blank */
  106.   ds = '('copies(' ',dl+2+length(dys))right(dh,2,0)':'ms')'
  107.  
  108. return hs ds
  109.