*COPAC-CLEAN. Automatic editing of Copac/BibTeX records. *Version 0.7 10th January 2014 *Copyright (C) Guido Milanese * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * If you do not have a copy of the GNU General Public License write to * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. * * If the author of this software was too lazy to include the full GPL * text along with the code, you can find it at: * http://www.gnu.org/copyleft/gpl.html. * * COPAC-CLEAN.SNO * Edits library cards from COPAC removing BibTeX errors * version 0.6 05.01.2014 * guido.milanese@unicatt.it * requires xclip and tcltk * called from copac-clean.sh * * ---> Set tabstop=3 to read/edit this file * Tkyn = host(0) * LIBRARY FILES * for convenience all copied in one file: -include "copac-clean-lib.inc" *-include "bq.sno" ;* shell operations *-include "itrim.inc" ;* initial trim *-include "mami.inc" ;* converts uppercase to lowercase *-include "newline.inc" ;* sets newline according to OS *-include "nopairs.inc" ;* nopairs (' ' = ' ') *-include "repl.inc" ;* string-by-string replacement *-include "tcltkchk.inc" ;* checks if tcltk available ************************* * INITIALISATIONS ************************* * Copacbib is the BibTeX item produced by COPAC, now empty Copacbib = nl = newline() ;* sets newline according to OS ErrMsg1 = "No_valid_BibTeX_file/Exiting" OkMsg1 = "Done/Exiting" * Pattern: hyphenation. Admits 2 forms, old (wrong) and new P_hyphen = (("language = {") | ("langage = {")) + (("English" | "French" | "German" | "Italian" | "Latin") . Language) '}' * Pattern: entrytype P_entrytype = '@' (arb . V_entrytype) '{' * Pattern: author. Accepts space/no space P_author = "author" . Label_author + (span(' ') | '') '=' (span(' ') | '') '{' (arb . Name_author) "}," * Pattern: note, as above P_note = ((nl | ' ') "note" . Label_note) + (span(' ') | '') '=' (span(' ') | '') arb "}," * Pattern: title, as above P_title = "title" (span(' ') | '') '=' (span(' ') | '') arb "}," ************************* * INTERNAL FUNCTIONS ************************* ************************************** *-- Function READANDCHECK *-- Reads from clipbpoard, checks if it is all right ************************************** *-- requires itrim.inc *-- requires tcltkchk.inc define("readandcheck()Par1,Par2") :(readandcheck_end) readandcheck readandcheck_bg * first check tcltk: * if tcltk does not work exits tcltkchk() :f(freturn) * * now read/check the COPAC item * Copacbib is the BibTeX item produced by COPAC * reads from the clipboard, if fails exits Copacbib = bq("xclip -o") :f(freturn) * checks if it is a valid BibTeX item: * if Copacbib does not begin with a '@' fails and exits * First removes any blank at the beginning Copacbib = itrim(Copacbib) * then checks item, if fails exits ( + (~(Copacbib ? pos(0) '@')) + (ident(Tkyn,) + (STCL_EVAL(INTERP, "tk_messageBox -message " ErrMsg1 " -type ok -icon info")), + (Terminal = ErrMsg1)) + ) :s(freturn) * (~(Copacbib ? '@') (Terminal = "Not a valid BibTeX file")) :s(end) readandcheck_rt readandcheck = Copacbib :(return) readandcheck_end ************************************** *-- Function CPCTR *-- Transformation of COPAC data ************************************** define("cpctr(Copacdata)Par1,Par2") :(cpctr_end) cpctr cpctr_bg * common errors in the AUTHOR field Copacdata ? P_author Name_author2 = Name_author authors1 Name_author2 ? ", and" = " and" :s(authors1) authors2 Name_author2 ? ". and" = " and" :s(authors2) ;* 28.12.2013 Copacdata ? Name_author = Name_author2 * * if entrytype is proceedings changes "author" to "editor" * entrytype? Copacdata ? P_entrytype * Copacdata ? P_author ( + (V_entrytype ? "proceedings") + (Copacdata ? Label_author = "editor") + ) * * adds always a SHORTTITLE field. * The SHORTTITLE is to be later edited manually, according to the * user's preferences. * Adds a BOOKTITLE field only if entrytype is PROCEEDINGS * Useless for BIBLATEX but necessary for standard BIBTEX * title Copacdata ? P_title . V_title Shorttitle = " short" V_title Booktitle = " book" V_title ;* leave it here! Copacdata ? V_title = V_title Shorttitle ((V_entrytype ? "proceedings") (Copacdata ? V_title = V_title Booktitle)) * * Hyphenation. Works only if ONE language is declared * Using langid and not hyphenation (version 0.6) Copacdata ? P_hyphen . V_hyphen V_hyphen2 = V_hyphen V_hyphen2 ? "language" = "langid" ;* corrected by COPAC, at last! V_hyphen2 ? "langage" = "langid" ;* try also the wrong form, no harm * V_hyphen2 ? "language" = "hyphenation" ;* corrected by COPAC, at last! * V_hyphen2 ? "langage" = "hyphenation" ;* try also the wrong form, no harm Language2 = mami(Language) Language2 ? "english" = "british" ;* optional Language2 ? "latin" = "italian" V_hyphen2 ? Language = Language2 Copacdata ? V_hyphen = V_hyphen2 * * Location. Changes to 'library' - see documentation * Copacdata ? "location " = "ll " Copacdata ? "location " = "library " * * Changes NOTE fields to ANNOTE: the NOTE field is normally printed, * while the NOTE field produced by Copac is normally an annotation * loops because there are frequently more than 1 NOTE fields cpctrlpn Copacdata ? P_note . V_note :f(cpctrlpn_nd) V_note2 = V_note V_note2 ? "note" = "annote" Copacdata ? V_note = V_note2 :(cpctrlpn) cpctrlpn_nd * * Punctuation cleanup punct1 Copacdata ? " : }" = "}" :s(punct1) punct2 Copacdata ? (any(",.:; ") '}') . W = "}" :s(punct2) punct3 Copacdata ? "title=" = "title = " :s(punct3) Copacdata = nopairs(Copacdata) newlines Copacdata = repl(Copacdata,"},", "}," nl) Copacdata = repl(Copacdata, ", author", ',' nl "author") Copacdata = repl(Copacdata, ", editor", ',' nl "editor") Copacdata = repl(Copacdata," :",':') Output = Copacdata (ident(Tkyn,) + (STCL_EVAL(INTERP, "tk_messageBox -message " OkMsg1 " -type ok -icon info")), + (Terminal = OkMsg1) + ) cpctr_rt cpctr = Copacdata :s(return)f(freturn) cpctr_end ****************************** * MAIN PROGRAMME ****************************** * Reads from clipboard and checks data Copacbib = readandcheck() :f(end) * Transforms data ( + ~(Copacbib = Cpctr(Copacbib)) + (Terminal = "Something wrong!") + ) end * ****************************** * HISTORY ****************************** 10.09.2013 version 0.1 15.09.2013 version 0.2 -- first usable 30.10.2013 version 0.3 -- some fields corrected; comments edited 27.12.2013 version 0.4 -- changes author to editor in proceedings 28.12.2013 version 0.5 -- general editing of functions 07.01.2014 version 0.6 -- improved check - using langid and library