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

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Translate 1.30 (23 May 1995)
  4.  *                                                                          *
  5.  *                      Written by Freddy Ariës                             *
  6.  *                                                                          *
  7.  * You may have noticed that setting another language in Locale means that  *
  8.  * the date (month) fields of your database are no longer recognized        *
  9.  * correctly. This is where Translate comes in.                             *
  10.  * It will convert all the standard language fields in a Scion database (in *
  11.  * v4.0+, that means the Date fields) into another (predefined) language.   *
  12.  * Currently only Dutch, German and French are supported, and only          *
  13.  * translation to and from English is possible. Adding other languages      *
  14.  * is easy, though.                                                         *
  15.  *                                                                          *
  16.  * This version uses (by default) the rexxreqtools.library (which requires  *
  17.  * a version of reqtools larger than 2.0 and rexxsyslib.library)            *
  18.  * If you do not have these, you need to supply the NOREQ argument (for     *
  19.  * Shell output), or the QUIET argument (for no output at all).             *
  20.  *                                                                          *
  21.  * New (requested by Robbie): progress indicator, using rexxarplib.library  *
  22.  *                                                                          *
  23.  ****************************************************************************/
  24.  
  25. options results
  26. arg panum outval
  27.  
  28. versionstr = "1.30"
  29. NL = '0A'x
  30. usereq = 1; /* change this to 0 if you don't want to use reqtools */
  31. outp = 1;
  32. prgrs = 1; pgopen = 0; /* use RexxArp progress indicator */
  33.   /* change prgrs to 0 for not using it */
  34.  
  35. /* parse command line options, to allow calling the script automatically,
  36.  * eg. from a function key
  37.  */
  38.   
  39. do while panum = '?'
  40.   Tell("NUMOPT/N,QUIET/S,NOREQ/s: ")
  41.   pull panum outval
  42. end
  43.  
  44. if panum ~= "" then do
  45.   if panum = "QUIET" then do
  46.     panum = ""; outval = "QUIET"
  47.     lang = 0
  48.   end
  49.   else if panum = "NOREQ" then do
  50.     panum = ""; outval = "NOREQ"
  51.     lang = 0
  52.   end
  53.   else
  54.     lang = CheckAnswer(panum)
  55. end
  56. else lang = 0
  57.  
  58. if outval = "QUIET" then do
  59.   outp = 0; usereq = 0; prgrs  0
  60. end
  61. else if outval = "NOREQ" then do
  62.   usereq = 0; prgrs = 0
  63. end
  64.  
  65. if usereq & ~show('l','rexxreqtools.library') then do
  66.   if exists('libs:rexxreqtools.library') then
  67.     call addlib('rexxreqtools.library',0,-30,0)
  68.   else do
  69.     usereq = 0; outp = 1
  70.     Tell("Unable to open rexxreqtools.library - using text output")
  71.   end
  72. end
  73.  
  74. if ~usereq then prgrs = 0
  75.  
  76. if prgrs & ~show('l','rexxarplib.library') then do
  77.   if exists('libs:rexxarplib.library') then
  78.     call addlib('rexxarplib.library',0,-30,0)
  79.   else
  80.     prgrs = 0
  81. end
  82.  
  83. /* These few lines were stolen from Peter Billings - thanks Peter ;-) */
  84. if ~show('P','SCIONGEN') then do
  85.   TermError('I am sorry to say that the SCION Genealogist' || NL ||,
  86.     'database is not available. Please start the' || NL ||,
  87.     'SCION program BEFORE using this script!')
  88. end
  89.  
  90. myport = "SCIONGEN"
  91. address value myport
  92. GETDBNAME
  93. dbname = upper(RESULT)
  94.  
  95. if outp & ~usereq then do
  96.   Tell("Translate - Scion Language Fields Converter "||versionstr||" by Freddy Ariës")
  97.   Tell("Database: "||dbname|| NL)
  98. end
  99.  
  100. if lang = 0 then do
  101.   if ~outp then
  102.     TermError("Missing required argument!")
  103.     /* even though you will never get to see the message... */
  104.   if usereq then do
  105.     answ = rtezrequest('Database: '||dbname || NL ||,
  106.       'Please select one of the following conversions: ' || NL || NL ||,
  107.       ' 1. Dutch to English           5. French to English' || NL ||,
  108.       ' 2. English to Dutch           6. English to French' || NL ||,
  109.       ' 3. German to English' || NL ||,
  110.       ' 4. English to German          0. Abort' ||,
  111.       NL, ' _1 | _2 | _3 | _4 | _5 | _6 | _0 ', 'Translate - Scion Language Field Converter '|| versionstr || ' by Freddy Ariës','rt_pubscrname = SCIONGEN')
  112.   end
  113.   else if outp then do
  114.     Tell("Please select one of the following conversions: ")
  115.     Tell(" 1. Dutch to English      5. French to English")
  116.     Tell(" 2. English to Dutch      6. English to French")
  117.     Tell(" 3. German to English")
  118.     Tell(" 4. English to German     0. Abort" || NL)
  119.     TellNN("Your choice: ")
  120.     pull answ
  121.   end
  122.   lang = CheckAnswer(answ)
  123. end
  124.  
  125. if answ = 0 then EXIT
  126.  
  127. if prgrs then do
  128.   Postmsg(10, 10, "Scion Translate (by Freddy Ariës)\Database: "||dbname||"\ \ ", "SCIONGEN")
  129.   pgopen = 1
  130. end
  131.  
  132. select
  133.   /* Make sure the string in datout is always <= the one in datin, or
  134.    * the resulting string might not fit in the field date anymore.
  135.    * Note: some 2-letter fields ('CA', 'VR', 'AV') can't follow this rule.
  136.    */
  137.   when lang = 1 then do
  138.     datin = "MRT MEI OKT CA CIRCA VR VOOR NA"
  139.     datout= "Mar May Oct Abt About Bef Bef Aft"
  140.   end
  141.   when lang = 2 then do
  142.     datin = "MAR MAY ABT ABOUT BEF BEFORE AFT AFTER"
  143.     datout= "Mrt Mei Ca Circa Vr Voor Na Na"
  144.   end
  145.   when lang = 3 then do
  146.       datin = "MÄR MAI OKT DEZ CA UNGEFÄHR VOR NAC NACH"
  147.       datout= "Mar May Oct Dec Abt About Bef Aft Aft"
  148.   end
  149.   when lang = 4 then do
  150.     datin = "MAR MAY OCT DEC ABT ABOUT BEF BEFORE AFT AFTER"
  151.     datout= "Mär Mai Okt Dez Ca Ca Vor Vor Nac Nach"
  152.   end
  153.   when lang = 5 then do
  154.     datin = "FEV FéV FÉV AVR MAI UIN UIL OUT DEC DéC DÉC ENV ENVIRON AV AVANT APR APRES APRèS APRÈS"
  155.     datout = "Feb Feb Feb Apr May Jun Jul Aug Dec Dec Dec Abt About Bef Bef Aft After After After")
  156.   end
  157.   when lang = 6 then do
  158.     datin = "FEB APR MAY JUN JUL AUG DEC ABT ABOUT BEF BEFORE AFT AFTER"
  159.     datout= "Fév Avr Mai uin uil out Déc Env Env Av Avant Apr Après"
  160.   end
  161.   otherwise
  162.     TermError("Invalid option.")
  163. end
  164.  
  165. if ~usereq then
  166.   Tell("Parsing Personal Details...")
  167. else if pgopen then
  168.   Postmsg(,, "\\Processing person:\", "SCIONGEN")
  169.  
  170. GETTOTALIRN
  171. TotalIRN = RESULT
  172. do i = 1 to TotalIRN
  173.   if pgopen then Postmsg(,,"\\\"||i||" (of "||TotalIRN||")", "SCIONGEN")
  174.   EXISTPERSON i
  175.   /* Skip deleted persons */
  176.   if RESULT = 'YES' then
  177.   do
  178. /* No longer needed in Scion v4; it always uses the English terms,
  179.  * "M", "F" and "?"
  180.     GETSEX i
  181.     sx = ConvertSex(RESULT)
  182.     if sx ~= "" then PUTSEX i sx
  183.  */
  184.     GETBIRTHDATE i
  185.     datestr = ParseDate(RESULT)
  186.     if datestr ~= "" then PUTBIRTHDATE i datestr
  187.     GETBAPTISMDATE i
  188.     datestr = ParseDate(RESULT)
  189.     if datestr ~= "" then PUTBAPTISMDATE i datestr
  190.     GETDEATHDATE i
  191.     datestr = ParseDate(RESULT)
  192.     if datestr ~= "" then PUTDEATHDATE i datestr
  193.     GETBURIALDATE i
  194.     datestr = ParseDate(RESULT)
  195.     if datestr ~= "" then PUTBURIALDATE i datestr
  196.   end
  197. end
  198. if ~usereq then do
  199.   Tell("Done ("||TotalIRN||" persons parsed).")
  200.  
  201.   /* Now the list of families... */
  202.   Tell("Parsing Family Details...")
  203. end
  204. else if pgopen then
  205.   Postmsg(,, "\\Processing family:\ ", "SCIONGEN")
  206.  
  207.   
  208. GETTOTALFGRN
  209. TotalFGRN = Result
  210. do i = 1 to TotalFGRN
  211.   EXISTFAMILY i
  212.   if pgopen then Postmsg(,, "\\\"||i||" (of "||TotalFGRN||")", "SCIONGEN")
  213.   /* Skip deleted families */
  214.   if RESULT = 'YES' then do
  215.     GETMARRYDATE i
  216.     datestr = ParseDate(RESULT)
  217.     if datestr ~= "" then PUTMARRYDATE i datestr
  218.     GETENGAGEDATE i
  219.     datestr = ParseDate(RESULT)
  220.     if datestr ~= "" then PUTENGAGEDATE i datestr
  221.     GETENDDATE i
  222.     datestr = ParseDate(RESULT)
  223.     if datestr ~= "" then PUTENDDATE i datestr
  224.   end
  225. end
  226.  
  227. if pgopen then do
  228.   Postmsg()
  229.   pgopen = 0
  230. end
  231. if usereq then do
  232.   rtezrequest('Scion Translation is ready.' || NL || 'Parsed '||,
  233.     TotalIRN||' persons and '||TotalFGRN||' families.',,'Translate Message:','rt_pubscrname = SCIONGEN')
  234. end
  235. else do
  236.   Tell("Done ("||TotalFGRN||" families parsed)."||NL)
  237. end
  238. EXIT
  239.  
  240. CheckAnswer: PROCEDURE EXPOSE outp
  241. parse arg str
  242. str = left(str, 1)
  243. if ~DATATYPE(str, 'w') then
  244.   TermError("Not a valid number -- program terminated.")
  245. if str < 0 | str > 6 then
  246.   TermError("Not a valid number -- program terminated.")
  247. return str
  248.  
  249. ConvertSex: PROCEDURE EXPOSE lang
  250. parse arg sxstr
  251. if lang = 1 & sxstr = "V" then sxstr = "F"
  252. else if lang = 2 & sxstr = "F" then sxstr = "V"
  253. else if lang = 3 & sxstr = "W" then sxstr = "F"
  254. else if lang = 4 & sxstr = "F" then sxstr = "W"
  255. /* French: 'M' and 'F', same as in English */
  256. else sxstr = ""
  257. return sxstr
  258.  
  259. /* PARSEDATE SUBROUTINE */
  260. /* For each word in the datestr string, see if it occurs in the datin
  261.  * string. If it does, replace it with the equivalent in the datout string
  262.  */
  263. ParseDate: PROCEDURE EXPOSE datin datout
  264. parse arg datestr
  265. datestr = strip(datestr); /* remove leading blanks */
  266. if datestr = "" then return datestr
  267. rdate = translate(datestr,'  ','-.'); /* replace all '.' or '-' by ' ' */
  268.  
  269. datestr = upper(rdate)
  270.  /* keep rdate in its original case, so we don't accidentally change
  271.   * the case of any other words in the resulting
  272.   */
  273. cp = 1
  274.  
  275. /* check all words with the datin string */
  276. do cnt = 1 to words(datestr)
  277.   cw = word(datestr, cnt)
  278.   num = find(datin, cw)
  279.   if num > 0 then do
  280.     rep = word(datout, num)
  281.     rl = length(rep)
  282.     cl = length(cw)
  283.     cp = index(upper(rdate), cw, cp)
  284.     rdate = delstr(rdate, cp, cl)
  285.     rdate = insert(rep, rdate, cp-1)
  286.   end
  287. end
  288. return rdate
  289.  
  290. Tell: PROCEDURE EXPOSE outp
  291. parse arg str
  292. if outp then
  293.   writeln(stdout, str)
  294. return 0
  295.  
  296. TellNN: PROCEDURE EXPOSE outp
  297. parse arg str
  298. if outp then
  299.   writech(stdout, str)
  300. return 0
  301.  
  302. TermError: PROCEDURE EXPOSE outp usereq pgopen
  303. parse arg str
  304. /* If you turned off stdout, no error messages will be shown! */
  305. if usereq then
  306.   rtezrequest(str,'E_xit','Translate Message:','rt_pubscrname = SCIONGEN')
  307. else do
  308.   Tell(str || '0A'x)
  309. end
  310. if pgopen then Postmsg()
  311. EXIT
  312.