]> git.lyx.org Git - lyx.git/blobdiff - src/BiblioInfo.cpp
fix "make check" with gcc 4.3
[lyx.git] / src / BiblioInfo.cpp
index 1e32445891f00a0a8ea4dbe3ef9a48a7acc8c9f5..f0db8396def4261ed8db6c33273f290c372466ad 100644 (file)
@@ -72,6 +72,16 @@ docstring const & BibTeXInfo::operator[](string const & field) const
 }
 
 
+docstring BibTeXInfo::getValueForKey(string const & key, 
+               BibTeXInfo const * const xref) const
+{
+       docstring const ret = operator[](key);
+       if (!ret.empty() || !xref)
+               return ret;
+       return (*xref)[key];
+}
+
+
 docstring familyName(docstring const & name)
 {
        if (name.empty())
@@ -174,6 +184,14 @@ docstring const BibTeXInfo::getYear() const
 }
 
 
+docstring const BibTeXInfo::getXRef() const
+{
+       if (!is_bibtex_)
+               return docstring();
+       return operator[]("crossref");
+}
+
+
 namespace {
 
        docstring convertLaTeXCommands(docstring const & str)
@@ -274,7 +292,7 @@ namespace {
 } // anon namespace
 
 
-docstring const BibTeXInfo::getInfo() const
+docstring const & BibTeXInfo::getInfo(BibTeXInfo const * const xref) const
 {
        if (!info_.empty())
                return info_;
@@ -286,35 +304,35 @@ docstring const BibTeXInfo::getInfo() const
        }
  
        // FIXME
-       // This could be made a lot better using the entryType
+       // This could be made a lot better using the entry_type_
        // field to customize the output based upon entry type.
        
        // Search for all possible "required" fields
-       docstring author = operator[]("author");
+       docstring author = getValueForKey("author", xref);
        if (author.empty())
-               author = operator[]("editor");
+               author = getValueForKey("editor", xref);
  
-       docstring year   = operator[]("year");
-       docstring title  = operator[]("title");
-       docstring docLoc = operator[]("pages");
+       docstring year   = getValueForKey("year", xref);
+       docstring title  = getValueForKey("title", xref);
+       docstring docLoc = getValueForKey("pages", xref);
        if (docLoc.empty()) {
-               docLoc = operator[]("chapter");
+               docLoc = getValueForKey("chapter", xref);
                if (!docLoc.empty())
-                       docLoc = from_ascii("Ch. ") + docLoc;
+                       docLoc = _("Ch. ") + docLoc;
        }       else {
-               docLoc = from_ascii("pp. ") + docLoc;
+               docLoc = _("pp. ") + docLoc;
        }
 
-       docstring media = operator[]("journal");
+       docstring media = getValueForKey("journal", xref);
        if (media.empty()) {
-               media = operator[]("publisher");
+               media = getValueForKey("publisher", xref);
                if (media.empty()) {
-                       media = operator[]("school");
+                       media = getValueForKey("school", xref);
                        if (media.empty())
-                               media = operator[]("institution");
+                               media = getValueForKey("institution");
                }
        }
-       docstring volume = operator[]("volume");
+       docstring volume = getValueForKey("volume", xref);
 
        odocstringstream result;
        if (!author.empty())
@@ -324,7 +342,7 @@ docstring const BibTeXInfo::getInfo() const
        if (!media.empty())
                result << ", " << media;
        if (!year.empty())
-               result << ", " << year;
+               result << " (" << year << ")";
        if (!docLoc.empty())
                result << ", " << docLoc;
 
@@ -335,7 +353,8 @@ docstring const BibTeXInfo::getInfo() const
        }
 
        // This should never happen (or at least be very unusual!)
-       return docstring();
+       static docstring e = docstring();
+       return e;
 }
 
 
@@ -408,6 +427,18 @@ docstring const BiblioInfo::getYear(docstring const & key) const
        if (it == end())
                return docstring();
        BibTeXInfo const & data = it->second;
+       docstring year = data.getYear();
+       if (!year.empty())
+               return year;
+       // let's try the crossref
+       docstring const xref = data.getXRef();
+       if (xref.empty())
+               return year; // no luck
+       BiblioInfo::const_iterator const xrefit = find(xref);
+       if (xrefit == end())
+               return year; // no luck again
+       BibTeXInfo const & xref_data = xrefit->second;
+       return xref_data.getYear();
        return data.getYear();
 }
 
@@ -418,7 +449,14 @@ docstring const BiblioInfo::getInfo(docstring const & key) const
        if (it == end())
                return docstring();
        BibTeXInfo const & data = it->second;
-       return data.getInfo();
+       BibTeXInfo const * xrefptr = 0;
+       docstring const xref = data.getXRef();
+       if (!xref.empty()) {
+               BiblioInfo::const_iterator const xrefit = find(xref);
+               if (xrefit != end())
+                       xrefptr = &(xrefit->second);
+       }
+       return data.getInfo(xrefptr);
 }