home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d992 / cyberpager.lha / CyberPager / rexx / caw / PageOnCall < prev    next >
Text File  |  1994-04-05  |  3KB  |  151 lines

  1. /*
  2.  * PageOnCall
  3.  *
  4.  * Copyright © 1993 by Christopher A. Wichura (caw@miroc.chi.il.us)
  5.  * All rights reserved.
  6.  *
  7.  * This script will read the pager:schedule file to try and determine
  8.  * who is on call.  It will then call SpoolPage to send the page text
  9.  * to the person or persons indicated.
  10.  *
  11.  * If URGENT is the first word on the command line, PageOnCall will operate
  12.  * in urgent mode.  This means it will continue looking through multiple
  13.  * schedules until it can satisfy the request.  Thus, it is possible
  14.  * have a 'normal duty' schedule and an 'emergency duty' schedule in
  15.  * the same schedule file.  When the URGENT switch is used, SpoolPage
  16.  * will also be started in URGENT mode.
  17.  *
  18.  * The text of the message to be sent will be read from stdin if it is not
  19.  * provided on the command line.
  20.  */
  21.  
  22. scheduleFile = 'PAGER:schedule'
  23.  
  24. /*
  25.  * No general user modifiable code is found below this point.
  26.  * Make changes here at your own risk.
  27.  */
  28.  
  29. /*
  30.  * First we want to figure out what the date and time is so we know
  31.  * where to look in the schedule file.
  32.  */
  33.  
  34. weekDay = date('Weekday')
  35. select
  36.     when upper(left(weekDay, 3)) = 'SUN' then weekDay = 0
  37.     when upper(left(weekDay, 3)) = 'MON' then weekDay = 1
  38.     when upper(left(weekDay, 3)) = 'TUE' then weekDay = 2
  39.     when upper(left(weekDay, 3)) = 'WED' then weekDay = 3
  40.     when upper(left(weekDay, 3)) = 'THU' then weekDay = 4
  41.     when upper(left(weekDay, 3)) = 'FRI' then weekDay = 5
  42.     when upper(left(weekDay, 3)) = 'SAT' then weekDay = 6
  43. end
  44.  
  45. halfHour = time('Minutes') % 30
  46.  
  47. /*
  48.  * Look at the command line we got and see if we are in urgent mode
  49.  * or if we have the page text specified, etc.
  50.  */
  51.  
  52. parse arg pageText
  53.  
  54. if upper(word(pageText, 1)) = 'URGENT' then do
  55.     urgentMode = TRUE
  56.     parse var pageText . pageText
  57. end
  58. else
  59.     urgentMode = FALSE
  60.  
  61. pageText = strip(pageText)
  62.  
  63. /*
  64.  * Now open the schedule file and start looking for a match.
  65.  */
  66.  
  67. if open(fh, scheduleFile, 'R') then do
  68.     want = weekDay
  69.     exitVal = 0
  70.  
  71.     do until eof(fh)
  72.         line = readln(fh)
  73.  
  74.         if left(line, length(want)) = want then do
  75.             if want = weekDay then do
  76.                 who = substr(line, halfHour + 2, 1)
  77.  
  78.                 if (who ~= '' & who ~= '-') then
  79.                     want = who'='
  80.                 else if urgentMode = FALSE then
  81.                     leave
  82.             end
  83.             else do
  84.                 exitVal = doPage(substr(line, 3), urgentMode, pageText)
  85.                 want = ''
  86.                 leave
  87.             end
  88.         end
  89.     end
  90.  
  91.     call close(fh)
  92.  
  93.     if want = weekDay then do
  94.         say 'No one scheduled at this time.  Message not sent.'
  95.         exitVal = 1
  96.     end
  97.     else if want ~= '' then do
  98.         say 'Couldn''t find '''want''' target list identifier.  Message not sent.'
  99.         exitVal = 2
  100.     end
  101. end
  102. else do
  103.     say 'Couldn''t open' scheduleFile'.'
  104.     exitVal = 5
  105. end
  106.  
  107. exit exitVal
  108.  
  109. /*
  110.  * The doPage procedure takes a list of comma separated names and
  111.  * builds the command line to call SpoolPage with.
  112.  */
  113.  
  114. doPage: procedure
  115.     theCommand = 'spoolpage'
  116.  
  117.     targetList = arg(1)
  118.  
  119.     if targetList = '' then do
  120.         say 'Empty target list found.  Message not sent.'
  121.         return 3
  122.     end
  123.  
  124.     do while targetList ~= ''
  125.         index = pos(',', targetList)
  126.  
  127.         if index > 0 then do
  128.             target = left(targetList, index - 1)
  129.             targetList = substr(targetList, index + 1)
  130.         end
  131.         else do
  132.             target = targetList
  133.             targetList = ''
  134.         end
  135.  
  136.         theCommand = theCommand '"'target'"'
  137.     end
  138.  
  139.     if arg(2) = TRUE then
  140.         theCommand = theCommand 'URGENT'
  141.  
  142.     if arg(3) ~= '' then
  143.         theCommand = theCommand 'MESSAGE' arg(3)
  144.  
  145.     address command theCommand
  146.  
  147.     if rc ~= 0 then
  148.         return 4
  149.     else
  150.         return 0
  151.