home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / rexx / unrelated.rexx < prev    next >
OS/2 REXX Batch file  |  1995-09-21  |  6KB  |  185 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Unrelated 1.01 (18 Jul 1995)
  4.  *                                                                          *
  5.  *                      Written by Robbie Akins                             *
  6.  *                                                                          *
  7.  * Adapted from ARexx scripts by Freddy Ariës - Many thanks Freddy :-)      *
  8.  *                                                                          *
  9.  * ARexx script to find "unrelated" people in the database.                 *
  10.  * That is, it will locate all those people who have no parents and who     *
  11.  * have no marriages recorded (and hence cannot have any recorded children) *
  12.  *                                                                          *
  13.  * This script uses (by default) the rexxreqtools.library (which requires   *
  14.  * a version of reqtools larger than 2.0 and rexxsyslib.library)            *
  15.  * If you do not have these, change the line 'usereq = 1' to 'usereq = 0'   *
  16.  *                                                                          *
  17.  *                                                                          *
  18.  ****************************************************************************/
  19.  
  20. options results
  21. arg outname outval
  22.  
  23. versionstr = "1.01"
  24. usereq = 1; /* change this to 0 if you don't want to use reqtools */
  25. outp = 1; output = stdout
  26. NL = '0A'x
  27.  
  28. signal on IOERR
  29.  
  30. /* parse command line options, to enable calling the script automatically,
  31.  * eg. from a function key
  32.  */
  33.  
  34. do while outname = '?'
  35.   writeln(stdout, "OUTFILE/A,QUIET/S,NOREQ/S ")
  36.   pull outname outval
  37. end
  38.  
  39. if outname ~= "" then do
  40.   if outname = "QUIET" | outname = "NOREQ" then do
  41.     outval = outname; outname = ""
  42.   end
  43. end
  44.  
  45. if outval = "QUIET" then do
  46.   outp = 0; usereq = 0
  47. end
  48. else if outval = "NOREQ" then usereq = 0
  49.  
  50. if usereq & ~show('l','rexxreqtools.library') then do
  51.   if exists('libs:rexxreqtools.library') then
  52.     call addlib('rexxreqtools.library',0,-30,0)
  53.   else do
  54.     usereq = 0; outp = 1
  55.     Tell("Unable to open rexxreqtools.library - using text output")
  56.   end
  57. end
  58.  
  59. /* These first few lines were stolen from Peter Billings - thanks Peter ;-) */
  60. if ~show('P','SCIONGEN') then do
  61.   TermError('I am sorry to say that the SCION Genealogist' || NL ||,
  62.     'database is not available. Please start the' || NL ||,
  63.     'SCION program BEFORE using this script!')
  64. end
  65.  
  66. myport = "SCIONGEN"
  67. address value myport
  68. GETDBNAME
  69. dbname = upper(RESULT)
  70.  
  71. CurrIRN = 1
  72.  
  73. if outp & ~usereq then do
  74.   Tell("Scion Unrelated Person Finder v"||versionstr||" by Robbie Akins")
  75.   Tell("Current Scion database: "||dbname)
  76. end
  77.  
  78. GETTOTALIRN
  79. TotalIRN = RESULT
  80. if  TotalIRN = 0 then EXIT    /* No database to work on! */
  81.  
  82. /* It's a good habit to add an ".UNREL" extension to "unrelated" files */
  83. dblen = length(dbname)
  84. if dblen>6 & right(dbname, 6)=".Scion" then dbname=left(dbname, dblen - 6)
  85.  
  86. if outname = "" then do
  87.   if outp then do
  88.     if usereq then do
  89.        odev = rtezrequest('Current Scion database: '||dbname||,
  90.        NL||'Where should the output be sent to?'||,
  91.        NL,' _File |_Printer|_Screen|_Nowhere','Unrelated People v'||versionstr||' by Robbie Akins','rt_pubscrname = SCIONGEN')
  92.  
  93.       select
  94.         when odev = 1 then do
  95.           /* We need a file requester for further data */
  96.           outname = rtfilerequest(,dbname||'.UNREL','Output filename',,'rtfi_buffer = true   rt_pubscrname = SCIONGEN   rtfi_initialpath = RAM:',)
  97.           if outname = '' then
  98.             outname = dbname||'.UNREL'
  99.         end
  100.         when odev = 2 then
  101.           outname = 'PRT:'
  102.         when odev = 3 then
  103.           outname = 'STDOUT'
  104.         otherwise
  105.           EXIT
  106.           /* You selected 'Nowhere' */
  107.       end
  108.     end
  109.     else do
  110.       Tell("Enter output file (filename with complete path, or PRT: for printer,")
  111.       TellNN("or STDOUT for screen): ")
  112.       pull outname
  113.       Tell("Destination: "||outname)
  114.       TellNN("Continue (y/n)? ")
  115.       pull conf
  116.       /* Note that left works on empty strings ("") too! */
  117.       if left(conf,1) ~= "Y" then do
  118.         Tell("Goodbye...")
  119.         EXIT
  120.       end
  121.       Tell("")
  122.     end
  123.   end
  124.   else
  125.     outname = "RAM:"dbname".UNREL"
  126.     /* If we're not allowed to use stdout, default to this filename */
  127. end
  128.  
  129. if outname ~= "STDOUT" then do
  130.   output = 'OUTPUT'
  131.   if ~open(output, outname, "w") then
  132.     TermError("ERROR: Unable to open output file.")
  133. end
  134.  
  135. writeln(output, "List of unrelated people:")
  136. do while CurrIRN <= TotalIRN
  137.     EXISTPERSON CurrIRN
  138.         if RESULT = 'YES' then do
  139.         GETNUMMARRY CurrIRN
  140.         if RESULT = 0 then do
  141.             /* No marriages. Possible candidate */
  142.             GETPARENTS CurrIRN
  143.             if RESULT = '' then do
  144.             /* This person is unrelated */
  145.             GETLASTNAME CurrIRN
  146.             last = result
  147.             GETFIRSTNAME CurrIRN
  148.             first = result
  149.             str = "IRN" CurrIRN": "Last", "First
  150.             writeln(output, str)
  151.         end
  152.         end
  153.     end
  154.   CurrIRN = CurrIRN + 1    /* Do next possible person */
  155. end
  156.  
  157. EXIT
  158.  
  159. Tell: PROCEDURE EXPOSE outp
  160. parse arg str
  161. if outp then writeln(stdout, str)
  162. return 0
  163.  
  164. TellNN: PROCEDURE EXPOSE outp
  165. parse arg str
  166. if outp then writech(stdout, str)
  167. return 0
  168.  
  169. TermError: PROCEDURE EXPOSE outp output usereq
  170. parse arg str
  171. /* If you turned off stdout, no error messages will be shown! */
  172. if usereq then
  173.   rtezrequest(str,'E_xit','Finder Message:','rt_pubscrname = SCIONGEN')
  174. else do
  175.   Tell(str || '0A'x)
  176. end
  177. close(output)
  178. EXIT
  179.  
  180. IOERR:
  181.   bline = SIGL
  182.   say "I/O error #"||RC||" detected in line "||bline||":"
  183.   say sourceline(bline)
  184.   EXIT
  185.