home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / scion407 / scionarexx.lha / Links.rexx < prev    next >
OS/2 REXX Batch file  |  1995-06-01  |  10KB  |  358 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Links 1.15 (23 May 1995)
  4.  *                                                                          *
  5.  *                      Written by Freddy Ariës                             *
  6.  *                                                                          *
  7.  * ARexx script to find unrelated family trees in the database              *
  8.  * It will detect all family trees within the database that have no links   *
  9.  * (spouse, parent or child links) to other present family trees.           *
  10.  * Eg. useful to find out if you forgot to add a link somewhere...          *
  11.  *                                                                          *
  12.  * This version uses (by default) the rexxreqtools.library (which requires  *
  13.  * a version of reqtools larger than 2.0 and rexxsyslib.library)            *
  14.  * If you do not have these, change the line 'usereq = 1' to 'usereq = 0'   *
  15.  *                                                                          *
  16.  * New (requested by Robbie): progress indicator, using rexxarplib.library  *
  17.  *                                                                          *
  18.  ****************************************************************************/
  19.  
  20. options results
  21. arg outname outval
  22.  
  23. versionstr = "1.15"
  24. usereq = 1; /* change this to 0 if you don't want to use reqtools */
  25. useirn = 1
  26. outp = 1; output = stdout
  27. plwidth = 78;  /* linewidth of the printer */
  28. fill = 9;      /* number of spaces at the beginning of lines */
  29. prgrs = 1; pgopen = 0; /* use RexxArp progress indicator */
  30.   /* change prgrs to 0 for not using it */
  31. NL = '0A'x
  32.  
  33. signal on IOERR
  34.  
  35. do while outname = '?'
  36.   writeln(stdout, "OUTFILE/A,QUIET/S,NOREQ/S ")
  37.   pull outname outval
  38. end
  39.  
  40. if outname ~= "" then do
  41.   if outname = "QUIET" | outname = "NOREQ" then do
  42.     outval = outname; outname = ""
  43.   end
  44. end
  45.  
  46. if outval = "QUIET" then do
  47.   outp = 0; usereq = 0; prgrs = 0
  48. end
  49. else if outval = "NOREQ" then do
  50.   usereq = 0; prgrs = 0
  51. end
  52.  
  53. if usereq & ~show('l','rexxreqtools.library') then do
  54.   if exists('libs:rexxreqtools.library') then
  55.     call addlib('rexxreqtools.library',0,-30,0)
  56.   else do
  57.     usereq = 0; outp = 1
  58.     Tell("Unable to open rexxreqtools.library - using text output")
  59.   end
  60. end
  61.  
  62. if ~usereq then prgrs = 0
  63.  
  64. /* These first few lines were stolen from Peter Billings - thanks Peter ;-) */
  65. if ~show('P','SCIONGEN') then do
  66.   TermError('I am sorry to say that the SCION Genealogist' || NL ||,
  67.     'database is not available. Please start the' || NL ||,
  68.     'SCION program BEFORE using this script!')
  69. end
  70.  
  71. if prgrs & ~show('l','rexxarplib.library') then do
  72.   if exists('libs:rexxarplib.library') then
  73.     call addlib('rexxarplib.library',0,-30,0)
  74.   else
  75.     prgrs = 0
  76. end
  77.  
  78. myport = "SCIONGEN"
  79. address value myport
  80. GETDBNAME
  81. dbname = upper(RESULT)
  82.  
  83. Arrays. = ""
  84. CurrIRN = 1; arr = 1; Arrays.1 = "1 "
  85. NumArrs = 1; Found = 1
  86.  
  87. if outp & ~usereq then do
  88.   Tell("Scion Links Finder v"||versionstr||" by Freddy Ariës")
  89.   Tell("Current Scion database: "||dbname)
  90.   Tell("Be patient - this may take a while...")
  91. end
  92.  
  93. /* It's a good habit to add the ".scion" extension to Scion database files */
  94. dblen = length(dbname)
  95. if dblen>6 & right(dbname, 6)=".SCION" then dbname=left(dbname, dblen - 6)
  96.  
  97. if outname = "" then do
  98.   if outp then do
  99.     if usereq then do
  100.       odev = rtezrequest('Current Scion database: '||dbname||,
  101.        NL||'Where should the Links output be sent to?'||,
  102.        NL,' _File |_Printer|_Screen|_Nowhere','Scion Links Finder v'||versionstr||' by Freddy Ariës','rt_pubscrname = SCIONGEN')
  103.       select
  104.         when odev = 1 then do
  105.           /* We need a file requester for further data */
  106.           outname = rtfilerequest(,dbname||'.LNK','Output filename',,'rtfi_buffer = true   rt_pubscrname = SCIONGEN   rtfi_initialpath = RAM:',)
  107.           if outname = '' then
  108.             outname = dbname||'.LNK'
  109.         end
  110.         when odev = 2 then
  111.           outname = 'PRT:'
  112.         when odev = 3 then
  113.           outname = 'STDOUT'
  114.         otherwise
  115.           EXIT
  116.           /* You selected 'Nowhere' */
  117.       end
  118.     end
  119.     else do
  120.       Tell("Enter output file (filename with complete path, or PRT: for printer,")
  121.       TellNN("or STDOUT for screen): ")
  122.       pull outname
  123.       Tell("Destination: "||outname)
  124.       TellNN("Continue (y/n)? ")
  125.       pull conf
  126.       /* Note that left works on empty strings ("") too! */
  127.       if left(conf,1) ~= "Y" then do
  128.         Tell("Goodbye...")
  129.         EXIT
  130.       end
  131.       Tell("")
  132.     end
  133.   end
  134.   else
  135.     outname = "RAM:"dbname".LNK"
  136.     /* If we're not allowed to use stdout, default to this filename */
  137. end
  138.  
  139. if prgrs then do
  140.   Postmsg(10, 10, "Scion Links Finder (by Freddy Ariës)\Database: "||dbname||"\ \ ", "SCIONGEN")
  141.   pgopen = 1
  142. end
  143.  
  144. GETTOTALIRN
  145. TotalIRN = RESULT
  146. if pgopen then Postmsg(,, "\\Processing person:\", "SCIONGEN")
  147.  
  148. do while CurrIRN ~= TotalIRN
  149.   if pgopen then Postmsg(,,"\\\"||CurrIRN||" (of "||TotalIRN||")", "SCIONGEN")
  150.   if Found then do
  151.     MarrNum = 0; marrexist = 1
  152.  
  153.     do while marrexist
  154.       GETMARRIAGE CurrIRN MarrNum
  155.       marriage = RESULT
  156.       EXISTFAMILY marriage
  157.       if RESULT = 'YES' then do
  158.         marrexist = 1
  159.  
  160.     PrsnIRN = 0
  161.     GETPRINCIPAL marriage
  162.     ptnr = RESULT
  163.     EXISTPERSON ptnr
  164.     if RESULT = 'YES' then do
  165.       if ptnr ~= CurrIRN then PrsnIRN = ptnr
  166.     end
  167.     if PrsnIRN = 0 then do
  168.       GETSPOUSE marriage
  169.       ptnr = RESULT
  170.       EXISTPERSON ptnr
  171.       if RESULT = 'YES' then do
  172.         if ptnr ~= CurrIRN then PrsnIRN = ptnr
  173.       end
  174.     end
  175.  
  176.     EXISTPERSON PrsnIRN
  177.         if RESULT = 'YES' then
  178.           arr = HandlePerson(PrsnIRN)
  179.  
  180.     ChildNum = 0; childexist = 1
  181.     do while childexist
  182.       GETCHILD marriage ChildNum
  183.       child = RESULT
  184.       EXISTPERSON child
  185.       if RESULT = 'YES' then do
  186.             childexist = 1
  187.         arr = HandlePerson(child)
  188.         ChildNum = ChildNum + 1
  189.       end
  190.       else childexist = 0
  191.     end
  192.  
  193.         MarrNum = MarrNum + 1
  194.       end
  195.       else marrexist = 0
  196.     end
  197.  
  198.     GETPARENTS CurrIRN
  199.     ParFGRN = RESULT
  200.     EXISTFAMILY ParFGRN
  201.     if RESULT = 'YES' then do
  202.       GETPRINCIPAL ParFGRN
  203.       PrsnIRN = RESULT
  204.       EXISTPERSON PrsnIRN
  205.       if RESULT = 'YES' then do
  206.         arr = HandlePerson(PrsnIRN)
  207.       end
  208.  
  209.       GETSPOUSE ParFGRN
  210.       PrsnIRN = RESULT
  211.       EXISTPERSON PrsnIRN
  212.       if RESULT = 'YES' then
  213.         arr = HandlePerson(PrsnIRN)
  214.  
  215.       /* Note that we don't have to process siblings, because they will
  216.        * be processed with their parents, and because you cannot create
  217.        * a family group without at least one parent
  218.        */
  219.     end
  220.   end
  221.  
  222.   CurrIRN = CurrIRN + 1
  223.   EXISTPERSON CurrIRN
  224.  
  225.   if RESULT = 'YES' then do
  226.    arr = GetArray(CurrIRN)
  227.    Found = 1
  228.   end
  229.   else Found = 0
  230. end
  231.  
  232. if pgopen then Postmsg(,, "\\Writing output...\ ", "SCIONGEN")
  233.  
  234. if outname ~= "STDOUT" then do
  235.   output = 'OUTPUT'
  236.   if ~open(output, outname, "w") then
  237.     TermError("ERROR: Unable to open output file.")
  238. end
  239.  
  240. /* Now output the resulting arrays of IRNs! */
  241. do out = 1 for NumArrs
  242.   PrintLines("Group "||out||": "||Arrays.out, fill)
  243. end
  244.  
  245. if pgopen then do
  246.   Postmsg()
  247.   pgopen = 0
  248. end
  249.  
  250. if usereq then do
  251.   rtezrequest('Scion Links Finder is ready.' || NL ||'Persons parsed: '||,
  252.     TotalIRN,,'Links Message:','rt_pubscrname = SCIONGEN')
  253. end
  254. else
  255.   Tell("Done ("||TotalIRN||" persons parsed)."||NL)
  256.  
  257. EXIT
  258.  
  259.  
  260. GetArray: PROCEDURE EXPOSE Arrays. NumArrs
  261. parse arg prsn
  262. do CurrArr = 1 for NumArrs
  263.   col = find(Arrays.CurrArr, prsn)
  264.   if col > 0 then return CurrArr
  265. end
  266. /* Not already present, then give person a new array */
  267. NumArrs = NumArrs + 1
  268. Arrays.NumArrs = prsn||' '
  269. return NumArrs
  270.  
  271. MergeArrs: PROCEDURE EXPOSE Arrays. NumArrs
  272. parse arg arr1, arr2
  273. if arr1 <= arr2 then do
  274.   minarr = arr1; maxarr = arr2
  275. end
  276. else do
  277.   minarr = arr2; maxarr = arr1
  278. end
  279. Arrays.minarr = Arrays.minarr||Arrays.maxarr
  280. if maxarr ~= NumArrs then
  281.   Arrays.maxarr = Arrays.NumArrs
  282. Arrays.NumArrs = ""
  283. NumArrs = NumArrs - 1
  284. return minarr
  285.  
  286. HandlePerson: PROCEDURE EXPOSE Arrays. NumArrs arr
  287. parse arg prsn
  288. CurrArr = 1; pers = 0
  289. do until pers ~=  0 | CurrArr > NumArrs
  290.   if find(Arrays.CurrArr, prsn) > 0 then pers = CurrArr
  291.   CurrArr = CurrArr + 1
  292. end
  293. if pers = 0 then do
  294.   /* Person isn't already present; give him same array as CurrIRN person */
  295.   pers = arr
  296.   Arrays.arr = Arrays.arr||prsn||' '
  297. end
  298. if pers ~= arr then
  299.   arr = MergeArrs(pers, arr)
  300. return arr
  301.  
  302. PrintLines: PROCEDURE EXPOSE output plwidth
  303. parse arg ostr, fill
  304. do while ostr ~= ""
  305.   nnl = plwidth+1
  306.   if length(ostr) > plwidth then do
  307.     do until pc = ' ' | nnl = 1
  308.       pc = substr(ostr, nnl, 1)
  309.       nnl = nnl - 1
  310.     end
  311.     if nnl = 1 then do
  312.       prtstr = left(ostr, plwidth)
  313.       ostr = delstr(ostr, 1, nnl)
  314.     end
  315.     else do
  316.       prtstr = left(ostr, nnl)
  317.       ostr = delstr(ostr, 1, nnl+1)
  318.     end
  319.   end
  320.   else do
  321.     prtstr = ostr
  322.     ostr = ""
  323.   end
  324.   writeln(output, prtstr)
  325.   if ostr ~= "" then
  326.     ostr = copies(' ',fill)||ostr
  327. end
  328. return 0
  329.  
  330. Tell: PROCEDURE EXPOSE outp
  331. parse arg str
  332. if outp then writeln(stdout, str)
  333. return 0
  334.  
  335. TellNN: PROCEDURE EXPOSE outp
  336. parse arg str
  337. if outp then writech(stdout, str)
  338. return 0
  339.  
  340. TermError: PROCEDURE EXPOSE outp output usereq pgopen
  341. parse arg str
  342. if pgopen then Postmsg()
  343. /* If you turned off stdout, no error messages will be shown! */
  344. if usereq then
  345.   rtezrequest(str,'E_xit','Links Message:','rt_pubscrname = SCIONGEN')
  346. else do
  347.   Tell(str || '0A'x)
  348. end
  349. /* close(output) */
  350. EXIT
  351.  
  352. IOERR:
  353.   bline = SIGL
  354.   say "I/O error #"||RC||" detected in line "||bline||":"
  355.   say sourceline(bline)
  356.   if pgopen then Postmsg()
  357.   EXIT
  358.