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

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Translate 1.34 (19 Aug 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 Dutch, German, French, Italian and Norwegian are supported,    *
  13.  * but only translation to and from English is possible. Adding other       *
  14.  * languages shouldn't be hard.                                             *
  15.  *                                                                          *
  16.  * This script 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.  * Now with progress indicator, using rexxarplib.library (requested by      *
  22.  * The Great Robbie himself ;-))                                            *
  23.  *                                                                          *
  24.  ****************************************************************************/
  25.  
  26. options results
  27. arg panum outval
  28.  
  29. versionstr = "1.34"
  30. NL = '0A'x
  31. usereq = 1; /* change this to 0 if you don't want to use reqtools */
  32. outp = 1;
  33. prgrs = 1; pgopen = 0; /* use RexxArp progress indicator */
  34.   /* change prgrs to 0 for not using it */
  35.  
  36. /* parse command line options, to allow calling the script automatically,
  37.  * eg. from a function key
  38.  */
  39.   
  40. do while panum = '?'
  41.   Tell("NUMOPT/N,QUIET/S,NOREQ/s: ")
  42.   pull panum outval
  43. end
  44.  
  45. if panum ~= "" then do
  46.   if panum = "QUIET" then do
  47.     panum = ""; outval = "QUIET"
  48.     lang = 0
  49.   end
  50.   else if panum = "NOREQ" then do
  51.     panum = ""; outval = "NOREQ"
  52.     lang = 0
  53.   end
  54.   else do
  55.     pnum = C2D(upper(left(panum,1)))
  56.     if pnum >= 65 & pnum <= 90 then do
  57.       panum = pnum - 64
  58.       lang = CheckAnswer(panum)
  59.     end
  60.     else if pnum > 47 & pnum < 57 then
  61.       lang = CheckAnswer(panum)
  62.     else do
  63.       lang = 0; panum = ""
  64.     end
  65.   end
  66. end
  67. else
  68.   lang = 0
  69.  
  70. if outval = "QUIET" then do
  71.   outp = 0; usereq = 0; prgrs  0
  72. end
  73. else if outval = "NOREQ" then do
  74.   usereq = 0; prgrs = 0
  75. end
  76.  
  77. if usereq & ~show('l','rexxreqtools.library') then do
  78.   if exists('libs:rexxreqtools.library') then
  79.     call addlib('rexxreqtools.library',0,-30,0)
  80.   else do
  81.     usereq = 0; outp = 1
  82.     Tell("Unable to open rexxreqtools.library - using text output")
  83.   end
  84. end
  85.  
  86. if ~usereq then prgrs = 0
  87.  
  88. if prgrs & ~show('l','rexxarplib.library') then do
  89.   if exists('libs:rexxarplib.library') then
  90.     call addlib('rexxarplib.library',0,-30,0)
  91.   else
  92.     prgrs = 0
  93. end
  94.  
  95. /* These few lines were stolen from Peter Billings - thanks Peter ;-) */
  96. if ~show('P','SCIONGEN') then do
  97.   TermError('I am sorry to say that the SCION Genealogist' || NL ||,
  98.     'database is not available. Please start the' || NL ||,
  99.     'SCION program BEFORE using this script!')
  100. end
  101.  
  102. myport = "SCIONGEN"
  103. address value myport
  104. GETDBNAME
  105. dbname = upper(RESULT)
  106.  
  107. if outp & ~usereq then do
  108.   Tell("Translate - Scion Language Fields Converter "||versionstr||" by Freddy Ariës")
  109.   Tell("Database: "||dbname|| NL)
  110. end
  111.  
  112. if lang = 0 then do
  113.   if ~outp then
  114.     TermError("Missing required argument!")
  115.     /* even though you will never get to see the message... */
  116.   if usereq then do
  117.     answ = rtezrequest('Database: '||dbname || NL ||,
  118.       'Please select one of the following conversions: ' || NL || NL ||,
  119.       ' a) Nederlands -> English      g) Italiano -> English' || NL ||,
  120.       ' b) English    -> Nederlands   h) English  -> Italiano' || NL ||,
  121.       ' c) Deutsch    -> English      i) Norsk    -> English' || NL ||,
  122.       ' d) English    -> Deutsch      j) English  -> Norsk' || NL ||,
  123.       ' e) Français   -> English' || NL ||,
  124.       ' f) English    -> Français     0) Abort' ||,
  125.       NL, ' _a | _b | _c | _d | _e | _f | _g | _h | _i | _j | _0 ','Translate - Scion Language Field Converter '|| versionstr || ' by Freddy Ariës','rtez_flags=ezreqf_noreturnkey rt_pubscrname=SCIONGEN')
  126.   end
  127.   else if outp then do
  128.     Tell("Please select one of the following conversions: ")
  129.     Tell(" a) Nederlands -> English      g) Italiano -> English")
  130.     Tell(" b) English    -> Nederlands   h) English  -> Italiano")
  131.     Tell(" c) Deutsch    -> English      i) Norsk    -> English")
  132.     Tell(" d) English    -> Deutsch      j) English  -> Norsk")
  133.     Tell(" e) Français   -> English")
  134.     Tell(" f) English    -> Français     0) Abort")
  135.     TellNN("Your choice: ")
  136.     pull answ
  137.     pnum = C2D(upper(left(answ,1)))
  138.     if pnum >= 65 & pnum <= 90 then
  139.       answ = pnum - 64
  140.   end
  141.   lang = CheckAnswer(answ)
  142. end
  143.  
  144. if lang = 0 | answ = 0 then EXIT
  145.  
  146. if prgrs then do
  147.   Postmsg(10, 10, "Scion Translate (by Freddy Ariës)\Database: "||dbname||"\ \ ", "SCIONGEN")
  148.   pgopen = 1
  149. end
  150.  
  151. select
  152.   /* Make sure the string in datout is always <= the one in datin, or
  153.    * the resulting string might not fit in the date field anymore.
  154.    * Note: some 2-letter fields ('CA', 'VR', 'AV') can't follow this rule.
  155.    */
  156.   when lang = 1 then do
  157.     datin = "MRT MAA MEI OKT CA CA. CIRCA VR VR. VOOR NA"
  158.     datout= "Mar Mar May Oct Abt Abt About Bef Bef Bef Aft"
  159.   end
  160.   when lang = 2 then do
  161.     datin = "MAR MAY ABT ABOUT BEF BEFORE AFT AFTER"
  162.     datout= "Mrt Mei Ca Circa Vr Voor Na Na"
  163.   end
  164.   when lang = 3 then do
  165.       datin = "MÄR Mär MRZ MAI OKT DEZ CA CA. UNGEFÄHR UNGEFäHR VOR NAC NACH"
  166.       datout= "Mar Mar Mar May Oct Dec Abt Abt About About Bef Aft Aft"
  167.   end
  168.   when lang = 4 then do
  169.     datin = "MAR MAY OCT DEC ABT ABOUT BEF BEFORE AFT AFTER"
  170.     datout= "Mär Mai Okt Dez Ca Ca Vor Vor Nac Nach"
  171.   end
  172.   when lang = 5 then do
  173.     datin = "FEV FéV FÉV AVR MAI UIN UIL OUT OÛT OûT DéC DÉC ENV ENVIRON AV AVANT APR APRES APRèS APRÈS"
  174.     datout = "Feb Feb Feb Apr May Jun Jul Aug Aug Aug Dec Dec Abt About Bef Bef Aft After After After"
  175.   end
  176.   when lang = 6 then do
  177.     datin = "FEB APR MAY JUN JUL AUG DEC ABT ABOUT BEF BEFORE AFT AFTER"
  178.     datout= "Fév Avr Mai uin uil oût Déc Env Env Av Avant Apr Après"
  179.   end
  180.   when lang = 7 then do
  181.     datin = "GEN MAG GIU LUG AGO SET OTT DIC INTORNO AL CA. PRIMA PRI DOPO DOP"
  182.     datout = "Jan May Jun Jul Aug Sep Oct Dec About . Abt Bef Bef Aft Aft"
  183.   end
  184.   when lang = 8 then do
  185.     datin = "JAN MAY JUN JUL AUG SEP OCT DEC ABOUT ABT BEFORE BEF AFTER AFT"
  186.     datout= "Gen Mag Giu Lug Ago Set Ott Dic Ca. Ca. Prima Pri Dopo Dop"
  187.   end
  188.   when lang = 9 then do
  189.     datin = "MAI OKT DES OMKRING CA. FøR FØR ETTER ETT"
  190.     datout = "May Oct Dec About Abt Bef Bef After Aft"
  191.   end
  192.   when lang = 10 then do
  193.     datin = "MAY OCT DEC ABOUT ABT BEFORE BEF AFTER AFT"
  194.     datout= "Mai Okt Des Ca. Ca. Før Før Etter Ett"
  195.   end
  196.   otherwise
  197.     TermError("Invalid option: "lang)
  198. end
  199.  
  200. if ~usereq then
  201.   Tell("Parsing Personal Details...")
  202. else if pgopen then
  203.   Postmsg(,, "\\Processing person:\", "SCIONGEN")
  204.  
  205. GETTOTALIRN
  206. TotalIRN = RESULT
  207. do i = 1 to TotalIRN
  208.   if pgopen then Postmsg(,,"\\\"||i||" (of "||TotalIRN||")", "SCIONGEN")
  209.   EXISTPERSON i
  210.   /* Skip deleted persons */
  211.   if RESULT = 'YES' then
  212.   do
  213. /* No longer needed in Scion v4; it always uses the English terms,
  214.  * "M", "F" and "?"
  215.     GETSEX i
  216.     sx = ConvertSex(RESULT)
  217.     if sx ~= "" then PUTSEX i sx
  218.  */
  219.     GETBIRTHDATE i
  220.     datestr = ParseDate(RESULT)
  221.     if datestr ~= "" then PUTBIRTHDATE i datestr
  222.     GETBAPTISMDATE i
  223.     datestr = ParseDate(RESULT)
  224.     if datestr ~= "" then PUTBAPTISMDATE i datestr
  225.     GETDEATHDATE i
  226.     datestr = ParseDate(RESULT)
  227.     if datestr ~= "" then PUTDEATHDATE i datestr
  228.     GETBURIALDATE i
  229.     datestr = ParseDate(RESULT)
  230.     if datestr ~= "" then PUTBURIALDATE i datestr
  231.   end
  232. end
  233. if ~usereq then do
  234.   Tell("Done ("||TotalIRN||" persons parsed).")
  235.  
  236.   /* Now the list of families... */
  237.   Tell("Parsing Family Details...")
  238. end
  239. else if pgopen then
  240.   Postmsg(,, "\\Processing family:\ ", "SCIONGEN")
  241.  
  242.   
  243. GETTOTALFGRN
  244. TotalFGRN = Result
  245. do i = 1 to TotalFGRN
  246.   if pgopen then Postmsg(,, "\\\"||i||" (of "||TotalFGRN||")", "SCIONGEN")
  247.   EXISTFAMILY i
  248.   /* Skip deleted families */
  249.   if RESULT = 'YES' then do
  250.     GETMARRYDATE i
  251.     datestr = ParseDate(RESULT)
  252.     if datestr ~= "" then PUTMARRYDATE i datestr
  253.     GETENGAGEDATE i
  254.     datestr = ParseDate(RESULT)
  255.     if datestr ~= "" then PUTENGAGEDATE i datestr
  256.     GETENDDATE i
  257.     datestr = ParseDate(RESULT)
  258.     if datestr ~= "" then PUTENDDATE i datestr
  259.   end
  260. end
  261.  
  262. if pgopen then do
  263.   Postmsg()
  264.   pgopen = 0
  265. end
  266. if usereq then do
  267.   rtezrequest('Scion Translation is ready.' || NL || 'Parsed '||,
  268.     TotalIRN||' persons and '||TotalFGRN||' families.',,'Translate Message:','rt_pubscrname = SCIONGEN')
  269. end
  270. else do
  271.   Tell("Done ("||TotalFGRN||" families parsed)."||NL)
  272. end
  273. EXIT
  274.  
  275. CheckAnswer: PROCEDURE EXPOSE outp usereq pgopen
  276. parse arg str
  277. if str < 0 | str > 10 then
  278.   TermError("Not a valid option: "||str||" -- program terminated.")
  279. return str
  280.  
  281. ConvertSex: PROCEDURE EXPOSE lang
  282. parse arg sxstr
  283. if lang = '1' & sxstr = "V" then sxstr = "F"
  284. else if lang = '2' & sxstr = "F" then sxstr = "V"
  285. else if lang = '3' & sxstr = "W" then sxstr = "F"
  286. else if lang = '4' & sxstr = "F" then sxstr = "W"
  287. else if lang = '9' & sxstr = "F" then sxstr = "K"
  288. else if lang = '10' & sxstr = "K" then sxstr = "F"
  289. /* French and Italian: 'M' and 'F', same as in English */
  290. else sxstr = ""
  291. return sxstr
  292.  
  293. /* PARSEDATE SUBROUTINE */
  294. /* For each word in the datestr string, see if it occurs in the datin
  295.  * string. If it does, replace it with the equivalent in the datout string
  296.  */
  297. ParseDate: PROCEDURE EXPOSE datin datout
  298. parse arg datestr
  299. datestr = strip(datestr); /* remove leading blanks */
  300. if datestr = "" then return datestr
  301. rdate = translate(datestr,'  ','-/'); /* replace all '-' or '/' by ' ' */
  302.  
  303. datestr = upper(rdate)
  304.  /* keep rdate in its original case, so we don't accidentally change
  305.   * the case of any other words in the resulting
  306.   */
  307. cp = 1
  308.  
  309. /* check all words with the datin string */
  310. do cnt = 1 to words(datestr)
  311.   cw = word(datestr, cnt)
  312.   num = find(datin, cw)
  313.   if num > 0 then do
  314.     rep = word(datout, num)
  315.     if rep="." then rep=""
  316.     rl = length(rep)
  317.     cl = length(cw)
  318.     cp = index(upper(rdate), cw, cp)
  319.     rdate = delstr(rdate, cp, cl)
  320.     rdate = insert(rep, rdate, cp-1)
  321.   end
  322. end
  323. return rdate
  324.  
  325. Tell: PROCEDURE EXPOSE outp
  326. parse arg str
  327. if outp then
  328.   writeln(stdout, str)
  329. return 0
  330.  
  331. TellNN: PROCEDURE EXPOSE outp
  332. parse arg str
  333. if outp then
  334.   writech(stdout, str)
  335. return 0
  336.  
  337. TermError: PROCEDURE EXPOSE outp usereq pgopen
  338. parse arg str
  339. /* If you turned off stdout, no error messages will be shown! */
  340. if usereq then
  341.   rtezrequest(str,'E_xit','Translate Message:','rt_pubscrname = SCIONGEN')
  342. else do
  343.   Tell(str || '0A'x)
  344. end
  345. if pgopen then Postmsg()
  346. EXIT
  347.