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

  1. /* REFER-BibIX_IMPORT.rexx  version 1.1  */
  2. /* This macro can be run from the CLI, SHELL or WorkBench and  */
  3. /* acts on a text or word processor-based citation database from  */
  4. /* which you wish to import citations in REFER-BibIX format.  The  */
  5. /* macro generates a text file of Citation_Base compatible  */
  6. /* citations.  */
  7.  
  8. /* open the REFER-BibIX file (database) for import */
  9. /* NOTE: change the disk/drive designations below to suit your setup */
  10. in_text = getfile(,,'ram:',,'Select REFER-BibIX import file');
  11. if (in_text = '') then exit;
  12. if (open(importfile,in_text,'R') ~= 1) then;
  13.   do;
  14.     say 'I could not open the file ' || in_text || ' for importing.';
  15.     exit;
  16.   end;
  17.  
  18. /* open the Citation_Base text file for export */
  19. out_text = getfile(,,'ram:',,'Select citation export name');
  20. if (out_text = '') then exit;
  21. if (open(exportfile,out_text,'W') ~= 1) then;
  22.   do;
  23.     say 'I could not open the file ' || out_text || ' for exporting.';
  24.     exit;
  25.   end;
  26.  
  27.  
  28. /* Start input-output loop for citations */
  29. do while (~EOF(importfile));
  30.  
  31.  
  32. /* Read REFER/BibIX citation */
  33.   j = 1;
  34.   a_num = 0;
  35.   output = 'OK';
  36.   do forever;
  37.     refer.j = readln(importfile);
  38.     if left(refer.j,2) = '%A' then a_num = a_num + 1;
  39.     if left(refer.j,2) = '%D' then year = substr(refer.j,4);
  40.     if left(refer.j,2) = '%T' then title = substr(refer.j,4);
  41.     if left(refer.j,2) = '%J' then full_journal = substr(refer.j,4);
  42.     if left(refer.j,2) = '%V' then volume = substr(refer.j,4);
  43.     if left(refer.j,2) = '%P' then pages = substr(refer.j,4);
  44.     if left(refer.j,2) = '%K' then keywords = substr(refer.j,4);
  45.     if refer.j = '' then leave;
  46.     j = j + 1;
  47.   end;
  48.   if j <= 1 then output = 'BAD';
  49.  
  50.  
  51. /* Reconstruct author string from REFER-BibIX input */
  52.   CB_authors = '';
  53.   do i = 1 to a_num;
  54.     parse var refer.i junk '%A ' initials '. ' surname;
  55.     initials = compress(initials,' .');
  56.     CB_authors = (CB_authors || surname || ', ' || initials || ', ');
  57.   end;
  58.   CB_authors = strip(CB_authors,'T',', ');
  59.  
  60.  
  61. /* Extract page numbers from REFER-BibIX pages input */
  62.   parse var pages first_page '-' last_page;
  63.   first_page = compress(first_page);
  64.   last_page = compress(last_page);
  65.  
  66.  
  67. /* Assign abbreviate journal name the full journal name */
  68.   journal = full_journal;
  69.  
  70.  
  71. /* Append asterix to full journal name */
  72.   full_journal = ('*' || full_journal);
  73.  
  74.  
  75. /* Assign string values to the citation fields and add record */
  76.   CB_field.1 = CB_authors;
  77.   CB_field.2 = year;
  78.   CB_field.3 = title;
  79.   CB_field.4 = (journal || ', ' || volume || ', ' || first_page || ', ' || last_page || ', ' || keywords);
  80.   CB_field.5 = full_journal;
  81.  
  82.  
  83. /* Export the citation in the Citation_Base format */
  84.   if output = 'OK' then;
  85.     do;
  86.       do k = 1 to 5;
  87.         foo = writeln(exportfile,CB_field.k)
  88.         say CB_field.k;
  89.       end;
  90.     end
  91.   else NOP;
  92.  
  93.  
  94. /* Get next REFER-BibIX citation or exit */
  95. end;
  96.  
  97.  
  98. /* exit macro */
  99. say 'Imported REFER/BibIX style citations in file ' || out_text;
  100. exit;
  101.