home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 448a.lha / Citation_Base_v1.1 / REXX / LAYOUT.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1990-09-13  |  11.4 KB  |  344 lines

  1. /* LAYOUT.rexx  version 1.1 */
  2. /* Run this ARexx macro from the WorkBench, CLI or SHELL after activating */
  3. /* ARexx and installing the RexxArpLibrary.  Your Workbench disk must */
  4. /* contain ARP (AmigaDos Resource Project version 1.3).  The citations */
  5. /* to be laid out must be in a plain text file conforming to the standard */
  6. /* citation format described below.  This macro creates a text file */
  7. /* with each citation laid out according to the format of the LAYOUT */
  8. /* template file selected by the user. */
  9.  
  10. /* The following tables summarize the embedded word processing codes */
  11. /* needed to turn on/off special formatting features in the laid out */
  12. /* citations.  These codes will function after the output citation */
  13. /* file is imported (retrieved) into the word processor.  The codes */
  14. /* used in this macro are designed to be compatible with WordPerfect */
  15. /* or Microsoft Word (RTF format).  It should be possible to substitute */
  16. /* codes for most other word processors with equivalent results. */
  17.  
  18.  
  19. /* WordPerfect formatting codes */
  20.  
  21.       WP_Bold_ON = d2c(157);
  22.      WP_Bold_OFF = d2c(156);
  23.    WP_Italics_ON = d2c(178);
  24.   WP_Italics_OFF = d2c(179);
  25.  WP_Underline_ON = d2c(148);
  26. WP_Underline_OFF = d2c(149); 
  27.           Header = d2c(128);
  28.        WP_Header = (Header || Header);
  29.  
  30.  
  31. /* Microsoft Word (Rich Text Format) formatting codes */
  32.  
  33.       MS_Bold_ON = '{\b ';
  34.      MS_Bold_OFF = '}';
  35.    MS_Italics_ON = '{\i ';
  36.   MS_Italics_OFF = '}';
  37.  MS_Underline_ON = '{\ul ';
  38. MS_Underline_OFF = '}';
  39.     MS_Paragraph = '\par ';
  40.           MS_EOF = '}';
  41.      MS_Header_1 = '{\rtf0\mac {\fonttbl{\f2\froman New York;}}{\stylesheet{';
  42.      MS_Header_2 = '\sbasedon222\snext0 Normal;}}\widowctrl\ftnbj\ftnrestart \sectd \linemod0\linex0\cols1\colsx0\endnhere \pard\plain ';
  43.  
  44.  
  45. /* open the citation text file for import */
  46. /* NOTE: change the disk/drive designations below to suit your setup */
  47. in_text = getfile(,,'ram:',,'Select citation import file');
  48. if (in_text = '') then exit;
  49. if (open(importfile,in_text,'R') ~= 1) then;
  50.   do;
  51.     say 'I could not open the file ' || in_text || ' for importing.';
  52.     exit;
  53.   end;
  54.  
  55.  
  56. /* open the text file for export */
  57. out_text = getfile(,,'ram:',,'Select export file name');
  58. if (out_text = '') then exit;
  59. if (open(exportfile,out_text,'W') ~= 1) then;
  60.   do;
  61.     say 'I could not open the file ' || out_text || ' for exporting.';
  62.     exit;
  63.   end;
  64.  
  65.  
  66. /* request user to select output file type (WordPerfect or MS_Word) */
  67. /* and assign embedded formatting characters accordingly */
  68. wp_type = request(,,'Choose output file type for laid out citations:',,'WordPerfect','Microsoft Word/Rich Text Format',);
  69. if (wp_type = 'OKAY') then;
  70.   do;
  71.           wp_type = 'WordPerfect';
  72.           Bold_ON = WP_Bold_ON;
  73.          Bold_OFF = WP_Bold_OFF;
  74.        Italics_ON = WP_Italics_ON;
  75.       Italics_OFF = WP_Italics_OFF;
  76.      Underline_ON = WP_Underline_ON;
  77.     Underline_OFF = WP_Underline_OFF;
  78.   end;
  79. else;
  80.   do;
  81.           wp_type = 'Microsoft Word';
  82.           Bold_ON = MS_Bold_ON;
  83.          Bold_OFF = MS_Bold_OFF;
  84.        Italics_ON = MS_Italics_ON;
  85.       Italics_OFF = MS_Italics_OFF;
  86.      Underline_ON = MS_Underline_ON;
  87.     Underline_OFF = MS_Underline_OFF;
  88.   end;
  89. say 'Output file may be retrieved into ' || wp_type || '!';
  90.  
  91.  
  92. /* open journal format template file for import */
  93. template_file = getfile(,,'ram:',,'Select LAYOUT template file!');
  94. if (open(templatefile,template_file,'R') ~= 1) then;
  95.   do;
  96.     say 'I could not open the file ' || template_file || ' for importing.';
  97.     exit;
  98.   end;
  99.  
  100.  
  101. /* decode LAYOUT template */
  102. /* sub.1.value = overall citation format */
  103. /* sub.2.value = format around initials  */
  104. /* sub.3.value = format around last author */
  105. /* sub.4.value = format around next to last author */
  106. /* sub.5.value = format around middle author */
  107. /* sub.6.value = format around first author */
  108. /* sub.7.value = special format for title words (e.g. species names)  */
  109. /*     where i = italics, u = underline, b = bold, s = same, n = none */
  110. template = readln(templatefile);
  111. parse var template sub.1.value '/' sub.2.value '/' sub.3.value '/' sub.4.value '/' sub.5.value '/' sub.6.value '/' sub.7.value '/';
  112. say sub.1.value ||'/'|| sub.2.value ||'/'|| sub.3.value ||'/'|| sub.4.value ||'/'|| sub.5.value ||'/'|| sub.6.value ||'/'|| sub.7.value ||'/';
  113.  
  114.  
  115. /* Title toggle character embedded word processor codes */
  116. /* Assign '&' (Toggle_ON) code  */
  117. /* Assign '$' (Toggle_OFF) code */
  118. if sub.7.value = 'u' then;
  119.   do;
  120.     Toggle_ON  = Underline_ON;
  121.     Toggle_OFF = Underline_OFF;
  122.   end;
  123. else;
  124. if sub.7.value = 'b' then;
  125.   do;
  126.     Toggle_ON  = Bold_ON;
  127.     Toggle_OFF = Bold_OFF;
  128.   end;
  129. else;
  130. if sub.7.value = 'i' then;
  131.   do;
  132.     Toggle_ON  = Italics_ON;
  133.     Toggle_OFF = Italics_OFF;
  134.   end;
  135. else;
  136. if sub.7.value = 's' then;
  137.   do;
  138.     Toggle_ON  = '&';
  139.     Toggle_OFF = '$';
  140.   end;
  141. else;
  142. if sub.7.value = 'n' then;
  143.   do;
  144.     Toggle_ON  = '';
  145.     Toggle_OFF = '';
  146.   end;
  147. else;
  148.   exit;
  149.  
  150.  
  151. /* get the first record/citation */
  152. citation_number = 0;
  153. default_number_string = '000';
  154. do loop = 1 to 5;
  155.    rec.loop.value = readln(importfile);
  156. end;
  157.  
  158.  
  159. /* Read the database citations, format (lay out) and export them */
  160. do while (~EOF(importfile));
  161.  
  162.   author_string = compress(rec.1.value);
  163.     year_string = rec.2.value;
  164.    title_string = rec.3.value;
  165.  short_j_string = rec.4.value;
  166.   long_j_string = rec.5.value;
  167. citation_number = citation_number + 1;
  168.  
  169. /* Replace title toggle characters with word processor formatting codes */
  170. /* Replace '&' with Toggle_ON  */
  171. /* Replace '$' with Toggle_OFF */
  172. do forever;
  173.   insert_pos = index(title_string,'&');
  174.   if insert_pos = 0 then leave;
  175.   title_string = insert(Toggle_ON,title_string,insert_pos);
  176.   title_string = delstr(title_string,insert_pos,1);
  177. end;
  178. title_string = translate(title_string,Toggle_OFF,'$');
  179.  
  180.  
  181. /* extract surnames and initials from author_string */
  182. n = 1;
  183. do forever;
  184.   parse var author_string sur.n.value ',' author_string;
  185.   if sur.n.value == '' then leave;
  186.   parse var author_string init.n.value ',' author_string;
  187.   n = n + 1;
  188. end;
  189. authornumber = n - 1;
  190.  
  191.  
  192. /* extract abbreviated journal name, volume, first and last pages */
  193. parse var short_j_string AbbJournal ',' volume ',' firstpage ',' lastpage ',';
  194.      volume = compress(volume);
  195.   firstpage = compress(firstpage);
  196.    lastpage = compress(lastpage);
  197.  
  198. /* extract full journal name from long_j_string */
  199. FullJournalLength = length(long_j_string);
  200. FullJournal = right(long_j_string,(FullJournalLength-1));
  201.  
  202.  
  203. /* LAYOUT citation using template */
  204. uppercase = 0;
  205. citation_string = '';
  206.   do i = 1 to length(sub.1.value);
  207.   x = substr(sub.1.value,i,1);
  208.     if x = 'a' then;
  209.       do j = 1 to authornumber;
  210.         q = '';
  211.         if ((j = 1) & (sub.6.value ~= '')) then q = sub.6.value;
  212.         if ((j = authornumber) & (length(q) = 0)) then q = sub.3.value;
  213.         if ((j = authornumber-1) & (length(q) = 0)) then q = sub.4.value;
  214.         if (length(q) = 0) then q = sub.5.value;
  215.         do k = 1 to length(q);
  216.           subq = substr(q,k,1);
  217.           if subq = 'S' then;
  218.             do;
  219.              uppercase = 1;
  220.              citation_string = (citation_string || upper(sur.j.value));
  221.             end;
  222.           else;
  223.           if subq = 's' then;
  224.             citation_string = (citation_string || sur.j.value);
  225.           else;
  226.           if ((subq = '@') & (uppercase = 1)) then;
  227.             citation_string = (citation_string || 'AND');
  228.           else;
  229.           if ((subq = '@') & (uppercase ~= 1)) then;
  230.             citation_string = (citation_string || 'and');
  231.           else;
  232.           if subq = 'i' then;
  233.             do;
  234.               L = 1;
  235.               Z = init.j.value;
  236.               E = sub.2.value;
  237.               do while L <= length(Z);
  238.                 do m = 1 to length(E);
  239.                   if substr(E,m,1) = 'i' then;
  240.                     do;
  241.                       citation_string = (citation_string || substr(Z,L,1));
  242.                       if substr(Z,L+1,1) >= 'a' then;
  243.                         do;
  244.                           citation_string = (citation_string || substr(Z,L+1,1));
  245.                           L = L + 1;
  246.                         end;
  247.                       else NOP;
  248.                     end;
  249.                   else;
  250.                     citation_string = (citation_string || substr(E,m,1));
  251.                 end;
  252.                 L = L + 1;
  253.               end;
  254.             end;
  255.           else;
  256.             citation_string = (citation_string || subq);
  257.         end;
  258.       end;
  259.     temp_string = '';
  260.     if (x = '<') then temp_string = Underline_ON;
  261.     if (x = '>') then temp_string = Underline_OFF;
  262.     if (x = '{') then temp_string = Bold_ON;
  263.     if (x = '}') then temp_string = Bold_OFF;
  264.     if (x = '[') then temp_string = Italics_ON;
  265.     if (x = ']') then temp_string = Italics_OFF;
  266.     if (x = 'J') then temp_string = FullJournal;
  267.     if (x = 'j') then temp_string = AbbJournal;
  268.     if (x = 'k') then temp_string = space(translate(AbbJournal,' ','. '),1);
  269.     if (x = 't') then temp_string = title_string;
  270.     if (x = 'v') then temp_string = volume;
  271.     if (x = 'f') then temp_string = firstpage;
  272.     if (x = 'l') then temp_string = lastpage;
  273.     if (x = 'y') then temp_string = year_string;
  274.     if (x = 'n') then temp_string = right((default_number_string || citation_number),3);
  275.     if (length(temp_string) > 0) then;
  276.       citation_string = (citation_string || temp_string);
  277.     else;
  278.     if (((x >= 'a') & (x <= 'z')) | ((x >= 'A') & (x <= 'Z'))) then;
  279.       x = '';
  280.     else;
  281.       citation_string = (citation_string || x);
  282.   end;
  283.  
  284.  
  285. /* clean up citation_string */
  286.   do forever;
  287.     del_pos1 = index(citation_string,'.,.');
  288.     if del_pos1 > 0 then citation_string = delstr(citation_string,del_pos1,2);
  289.     del_pos2 = index(citation_string,' -.');
  290.     if del_pos2 > 0 then citation_string = delstr(citation_string,del_pos2,3);
  291.     del_pos3 = index(citation_string,'-.');
  292.     if del_pos3 > 0 then citation_string = delstr(citation_string,del_pos3,1);
  293.     del_pos4 = index(citation_string,'-,');
  294.     if del_pos4 > 0 then citation_string = delstr(citation_string,del_pos4,1);
  295.     del_pos5 = index(citation_string,',:');
  296.     if del_pos5 > 0 then citation_string = delstr(citation_string,del_pos5,1);
  297.     del_pos6 = index(citation_string,',.');
  298.     if del_pos6 > 0 then citation_string = delstr(citation_string,del_pos6,1);
  299.     del_pos7 = index(citation_string,',,');
  300.     if del_pos7 > 0 then citation_string = delstr(citation_string,del_pos7,1);
  301.     del_pos8 = index(citation_string,'..');
  302.     if del_pos8 > 0 then citation_string = delstr(citation_string,del_pos8,1);
  303.     if (del_pos1 + del_pos2 + del_pos3 + del_pos4 + del_pos5 + del_pos6 + del_pos7 + del_pos8) = 0 then leave;
  304.   end;
  305.  
  306.  
  307. /* write citation_string to output file */
  308.   blankline = '';
  309.   if citation_number = 1 then;
  310.     do;
  311.       if wp_type = 'WordPerfect' then;
  312.         citation_string = (WP_Header || citation_string);
  313.       else;
  314.         do;
  315.           foo = writeln(exportfile,MS_Header_1);
  316.           citation_string = (MS_Header_2 || citation_string);
  317.         end;
  318.     end;
  319.   else NOP;
  320.   if wp_type = 'Microsoft Word' then;
  321.     do;
  322.       citation_string = (citation_string || MS_Paragraph);
  323.       blankline = (blankline || MS_Paragraph);
  324.     end;
  325.   else NOP;
  326.   say citation_string;
  327.   say blankline;
  328.   foo = writeln(exportfile,citation_string);
  329.   foo = writeln(exportfile,blankline);
  330.  
  331.  
  332. /* get the next record/citation for layout */
  333.   do loop = 1 to 5;
  334.      rec.loop.value = readln(importfile);
  335.   end;
  336. end;
  337.  
  338. /* exit from macro */
  339. if wp_type = 'Microsoft Word' then;
  340.   foo = writech(exportfile,MS_EOF);
  341. else NOP;
  342. say 'Citations laid out in the text file: ' || out_text;
  343. exit;
  344.