]> git.lyx.org Git - lyx.git/blob - src/insets/InsetBibtex.cpp
* moved text completion logic into Text class
[lyx.git] / src / insets / InsetBibtex.cpp
1 /**
2  * \file InsetBibtex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Richard Heck (BibTeX parser improvements)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetBibtex.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "DispatchResult.h"
19 #include "EmbeddedFiles.h"
20 #include "Encoding.h"
21 #include "FuncRequest.h"
22 #include "LaTeXFeatures.h"
23 #include "MetricsInfo.h"
24 #include "OutputParams.h"
25 #include "TextClass.h"
26
27 #include "frontends/alert.h"
28
29 #include "support/debug.h"
30 #include "support/docstream.h"
31 #include "support/ExceptionMessage.h"
32 #include "support/filetools.h"
33 #include "support/gettext.h"
34 #include "support/lstrings.h"
35 #include "support/os.h"
36 #include "support/Path.h"
37 #include "support/textutils.h"
38
39 #include <limits>
40
41 using namespace std;
42 using namespace lyx::support;
43
44 namespace lyx {
45
46 namespace Alert = frontend::Alert;
47 namespace os = support::os;
48
49
50 InsetBibtex::InsetBibtex(InsetCommandParams const & p)
51         : InsetCommand(p, "bibtex"), bibfiles_()
52 {}
53
54
55 void InsetBibtex::setBuffer(Buffer & buffer)
56 {
57         if (buffer_) {
58                 EmbeddedFileList::iterator it = bibfiles_.begin();
59                 EmbeddedFileList::iterator it_end = bibfiles_.end();
60                 for (; it != it_end; ++it)
61                         *it = it->copyTo(&buffer);
62         }
63         Inset::setBuffer(buffer);
64 }
65
66
67 ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
68 {
69         static ParamInfo param_info_;
70         if (param_info_.empty()) {
71                 param_info_.add("btprint", ParamInfo::LATEX_OPTIONAL);
72                 param_info_.add("bibfiles", ParamInfo::LATEX_REQUIRED);
73                 param_info_.add("embed", ParamInfo::LYX_INTERNAL);
74                 param_info_.add("options", ParamInfo::LYX_INTERNAL);
75         }
76         return param_info_;
77 }
78
79
80 void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
81 {
82         switch (cmd.action) {
83
84         case LFUN_INSET_MODIFY: {
85                 InsetCommandParams p(BIBTEX_CODE);
86                 try {
87                         if (!InsetCommandMailer::string2params("bibtex", 
88                                         to_utf8(cmd.argument()), p)) {
89                                 cur.noUpdate();
90                                 break;
91                         }
92                 } catch (ExceptionMessage const & message) {
93                         if (message.type_ == WarningException) {
94                                 Alert::warning(message.title_, message.details_);
95                                 cur.noUpdate();
96                         } else 
97                                 throw message;
98                         break;
99                 }
100                 //
101                 createBibFiles(p["bibfiles"], p["embed"]);
102                 updateParam();
103                 buffer().updateBibfilesCache();
104                 break;
105         }
106
107         default:
108                 InsetCommand::doDispatch(cur, cmd);
109                 break;
110         }
111 }
112
113
114 docstring InsetBibtex::screenLabel() const
115 {
116         return _("BibTeX Generated Bibliography");
117 }
118
119
120 static string normalizeName(Buffer const & buffer,
121         OutputParams const & runparams, string const & name, string const & ext)
122 {
123         string const fname = makeAbsPath(name, buffer.filePath()).absFilename();
124         if (FileName(name).isAbsolute() || !FileName(fname + ext).isReadableFile())
125                 return name;
126         if (!runparams.nice)
127                 return fname;
128
129         // FIXME UNICODE
130         return to_utf8(makeRelPath(from_utf8(fname),
131                                          from_utf8(buffer.masterBuffer()->filePath())));
132 }
133
134
135 int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
136 {
137         // the sequence of the commands:
138         // 1. \bibliographystyle{style}
139         // 2. \addcontentsline{...} - if option bibtotoc set
140         // 3. \bibliography{database}
141         // and with bibtopic:
142         // 1. \bibliographystyle{style}
143         // 2. \begin{btSect}{database}
144         // 3. \btPrint{Cited|NotCited|All}
145         // 4. \end{btSect}
146
147         // Database(s)
148         // If we are processing the LaTeX file in a temp directory then
149         // copy the .bib databases to this temp directory, mangling their
150         // names in the process. Store this mangled name in the list of
151         // all databases.
152         // (We need to do all this because BibTeX *really*, *really*
153         // can't handle "files with spaces" and Windows users tend to
154         // use such filenames.)
155         // Otherwise, store the (maybe absolute) path to the original,
156         // unmangled database name.
157         EmbeddedFileList::const_iterator it = bibfiles_.begin();
158         EmbeddedFileList::const_iterator it_end = bibfiles_.end();
159         odocstringstream dbs;
160         for (; it != it_end; ++it) {
161                 string utf8input = removeExtension(it->availableFile().absFilename());
162                 string database =
163                         normalizeName(buffer(), runparams, utf8input, ".bib");
164                 FileName const try_in_file =
165                         makeAbsPath(database + ".bib", buffer().filePath());
166                 bool const not_from_texmf = try_in_file.isReadableFile();
167
168                 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
169                     not_from_texmf) {
170
171                         // mangledFilename() needs the extension
172                         DocFileName const in_file = DocFileName(try_in_file);
173                         database = removeExtension(in_file.mangledFilename());
174                         FileName const out_file = makeAbsPath(database + ".bib",
175                                         buffer().masterBuffer()->temppath());
176
177                         bool const success = in_file.copyTo(out_file);
178                         if (!success) {
179                                 lyxerr << "Failed to copy '" << in_file
180                                        << "' to '" << out_file << "'"
181                                        << endl;
182                         }
183                 } else if (!runparams.inComment && runparams.nice && not_from_texmf &&
184                            !isValidLaTeXFilename(database)) {
185                                 frontend::Alert::warning(_("Invalid filename"),
186                                                          _("The following filename is likely to cause trouble "
187                                                            "when running the exported file through LaTeX: ") +
188                                                             from_utf8(database));
189                 }
190
191                 if (it != bibfiles_.begin())
192                         dbs << ',';
193                 // FIXME UNICODE
194                 dbs << from_utf8(latex_path(database));
195         }
196         docstring const db_out = dbs.str();
197
198         // Post this warning only once.
199         static bool warned_about_spaces = false;
200         if (!warned_about_spaces &&
201             runparams.nice && db_out.find(' ') != docstring::npos) {
202                 warned_about_spaces = true;
203
204                 Alert::warning(_("Export Warning!"),
205                                _("There are spaces in the paths to your BibTeX databases.\n"
206                                               "BibTeX will be unable to find them."));
207         }
208
209         // Style-Options
210         string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
211         string bibtotoc;
212         if (prefixIs(style, "bibtotoc")) {
213                 bibtotoc = "bibtotoc";
214                 if (contains(style, ','))
215                         style = split(style, bibtotoc, ',');
216         }
217
218         // line count
219         int nlines = 0;
220
221         if (!style.empty()) {
222                 string base = normalizeName(buffer(), runparams, style, ".bst");
223                 FileName const try_in_file = 
224                         makeAbsPath(base + ".bst", buffer().filePath());
225                 bool const not_from_texmf = try_in_file.isReadableFile();
226                 // If this style does not come from texmf and we are not
227                 // exporting to .tex copy it to the tmp directory.
228                 // This prevents problems with spaces and 8bit charcaters
229                 // in the file name.
230                 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
231                     not_from_texmf) {
232                         // use new style name
233                         DocFileName const in_file = DocFileName(try_in_file);
234                         base = removeExtension(in_file.mangledFilename());
235                         FileName const out_file = makeAbsPath(base + ".bst",
236                                         buffer().masterBuffer()->temppath());
237                         bool const success = in_file.copyTo(out_file);
238                         if (!success) {
239                                 lyxerr << "Failed to copy '" << in_file
240                                        << "' to '" << out_file << "'"
241                                        << endl;
242                         }
243                 }
244                 // FIXME UNICODE
245                 os << "\\bibliographystyle{"
246                    << from_utf8(latex_path(normalizeName(buffer(), runparams, base, ".bst")))
247                    << "}\n";
248                 nlines += 1;
249         }
250
251         // Post this warning only once.
252         static bool warned_about_bst_spaces = false;
253         if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
254                 warned_about_bst_spaces = true;
255                 Alert::warning(_("Export Warning!"),
256                                _("There are spaces in the path to your BibTeX style file.\n"
257                                               "BibTeX will be unable to find it."));
258         }
259
260         if (!db_out.empty() && buffer().params().use_bibtopic) {
261                 os << "\\begin{btSect}{" << db_out << "}\n";
262                 docstring btprint = getParam("btprint");
263                 if (btprint.empty())
264                         // default
265                         btprint = from_ascii("btPrintCited");
266                 os << "\\" << btprint << "\n"
267                    << "\\end{btSect}\n";
268                 nlines += 3;
269         }
270
271         // bibtotoc-Option
272         if (!bibtotoc.empty() && !buffer().params().use_bibtopic) {
273                 if (buffer().params().documentClass().hasLaTeXLayout("chapter")) {
274                         if (buffer().params().sides == OneSide) {
275                                 // oneside
276                                 os << "\\clearpage";
277                         } else {
278                                 // twoside
279                                 os << "\\cleardoublepage";
280                         }
281                         os << "\\addcontentsline{toc}{chapter}{\\bibname}";
282                 } else if (buffer().params().documentClass().hasLaTeXLayout("section"))
283                         os << "\\addcontentsline{toc}{section}{\\refname}";
284         }
285
286         if (!db_out.empty() && !buffer().params().use_bibtopic) {
287                 docstring btprint = getParam("btprint");
288                 if (btprint == "btPrintAll") {
289                         os << "\\nocite{*}\n";
290                         nlines += 1;
291                 }
292                 os << "\\bibliography{" << db_out << "}\n";
293                 nlines += 1;
294         }
295
296         return nlines;
297 }
298
299
300 EmbeddedFileList InsetBibtex::embeddedFiles() const
301 {
302         return bibfiles_;
303 }
304
305 namespace {
306
307         // methods for parsing bibtex files
308
309         typedef map<docstring, docstring> VarMap;
310
311         /// remove whitespace characters, optionally a single comma,
312         /// and further whitespace characters from the stream.
313         /// @return true if a comma was found, false otherwise
314         ///
315         bool removeWSAndComma(idocfstream & ifs) {
316                 char_type ch;
317
318                 if (!ifs)
319                         return false;
320
321                 // skip whitespace
322                 do {
323                         ifs.get(ch);
324                 } while (ifs && isSpace(ch));
325
326                 if (!ifs)
327                         return false;
328
329                 if (ch != ',') {
330                         ifs.putback(ch);
331                         return false;
332                 }
333
334                 // skip whitespace
335                 do {
336                         ifs.get(ch);
337                 } while (ifs && isSpace(ch));
338
339                 if (ifs) {
340                         ifs.putback(ch);
341                 }
342
343                 return true;
344         }
345
346
347         enum charCase {
348                 makeLowerCase,
349                 keepCase
350         };
351
352         /// remove whitespace characters, read characer sequence
353         /// not containing whitespace characters or characters in
354         /// delimChars, and remove further whitespace characters.
355         ///
356         /// @return true if a string of length > 0 could be read.
357         ///
358         bool readTypeOrKey(docstring & val, idocfstream & ifs,
359                 docstring const & delimChars, docstring const &illegalChars, 
360                 charCase chCase) {
361
362                 char_type ch;
363
364                 val.clear();
365
366                 if (!ifs)
367                         return false;
368
369                 // skip whitespace
370                 do {
371                         ifs.get(ch);
372                 } while (ifs && isSpace(ch));
373
374                 if (!ifs)
375                         return false;
376
377                 // read value
378                 bool legalChar = true;
379                 while (ifs && !isSpace(ch) && 
380                                                  delimChars.find(ch) == docstring::npos &&
381                                                  (legalChar = (illegalChars.find(ch) == docstring::npos))
382                                         ) 
383                 {
384                         if (chCase == makeLowerCase)
385                                 val += lowercase(ch);
386                         else
387                                 val += ch;
388                         ifs.get(ch);
389                 }
390                 
391                 if (!legalChar) {
392                         ifs.putback(ch);
393                         return false;
394                 }
395
396                 // skip whitespace
397                 while (ifs && isSpace(ch)) {
398                         ifs.get(ch);
399                 }
400
401                 if (ifs) {
402                         ifs.putback(ch);
403                 }
404
405                 return val.length() > 0;
406         }
407
408         /// read subsequent bibtex values that are delimited with a #-character.
409         /// Concatenate all parts and replace names with the associated string in
410         /// the variable strings.
411         /// @return true if reading was successfull (all single parts were delimited
412         /// correctly)
413         bool readValue(docstring & val, idocfstream & ifs, const VarMap & strings) {
414
415                 char_type ch;
416
417                 val.clear();
418
419                 if (!ifs)
420                         return false;
421
422                 do {
423                         // skip whitespace
424                         do {
425                                 ifs.get(ch);
426                         } while (ifs && isSpace(ch));
427
428                         if (!ifs)
429                                 return false;
430
431                         // check for field type
432                         if (isDigit(ch)) {
433
434                                 // read integer value
435                                 do {
436                                         val += ch;
437                                         ifs.get(ch);
438                                 } while (ifs && isDigit(ch));
439
440                                 if (!ifs)
441                                         return false;
442
443                         } else if (ch == '"' || ch == '{') {
444                                 // set end delimiter
445                                 char_type delim = ch == '"' ? '"': '}';
446
447                                 //Skip whitespace
448                                 do {
449                                         ifs.get(ch);
450                                 } while (ifs && isSpace(ch));
451                                 
452                                 if (!ifs)
453                                         return false;
454                                 
455                                 //We now have the first non-whitespace character
456                                 //We'll collapse adjacent whitespace.
457                                 bool lastWasWhiteSpace = false;
458                                 
459                                 // inside this delimited text braces must match.
460                                 // Thus we can have a closing delimiter only
461                                 // when nestLevel == 0
462                                 int nestLevel = 0;
463  
464                                 while (ifs && (nestLevel > 0 || ch != delim)) {
465                                         if (isSpace(ch)) {
466                                                 lastWasWhiteSpace = true;
467                                                 ifs.get(ch);
468                                                 continue;
469                                         }
470                                         //We output the space only after we stop getting 
471                                         //whitespace so as not to output any whitespace
472                                         //at the end of the value.
473                                         if (lastWasWhiteSpace) {
474                                                 lastWasWhiteSpace = false;
475                                                 val += ' ';
476                                         }
477                                         
478                                         val += ch;
479
480                                         // update nesting level
481                                         switch (ch) {
482                                                 case '{':
483                                                         ++nestLevel;
484                                                         break;
485                                                 case '}':
486                                                         --nestLevel;
487                                                         if (nestLevel < 0) return false;
488                                                         break;
489                                         }
490
491                                         ifs.get(ch);
492                                 }
493
494                                 if (!ifs)
495                                         return false;
496
497                                 ifs.get(ch);
498
499                                 if (!ifs)
500                                         return false;
501
502                         } else {
503
504                                 // reading a string name
505                                 docstring strName;
506
507                                 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
508                                         strName += lowercase(ch);
509                                         ifs.get(ch);
510                                 }
511
512                                 if (!ifs)
513                                         return false;
514
515                                 // replace the string with its assigned value or
516                                 // discard it if it's not assigned
517                                 if (strName.length()) {
518                                         VarMap::const_iterator pos = strings.find(strName);
519                                         if (pos != strings.end()) {
520                                                 val += pos->second;
521                                         }
522                                 }
523                         }
524
525                         // skip WS
526                         while (ifs && isSpace(ch)) {
527                                 ifs.get(ch);
528                         }
529
530                         if (!ifs)
531                                 return false;
532
533                         // continue reading next value on concatenate with '#'
534                 } while (ch == '#');
535
536                 ifs.putback(ch);
537
538                 return true;
539         }
540 }
541
542
543 // This method returns a comma separated list of Bibtex entries
544 void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist,
545         InsetIterator const & /*di*/) const
546 {
547         EmbeddedFileList const files = embeddedFiles();
548         for (vector<EmbeddedFile>::const_iterator it = files.begin();
549              it != files.end(); ++ it) {
550                 // This bibtex parser is a first step to parse bibtex files
551                 // more precisely.
552                 //
553                 // - it reads the whole bibtex entry and does a syntax check
554                 //   (matching delimiters, missing commas,...
555                 // - it recovers from errors starting with the next @-character
556                 // - it reads @string definitions and replaces them in the
557                 //   field values.
558                 // - it accepts more characters in keys or value names than
559                 //   bibtex does.
560                 //
561                 // Officially bibtex does only support ASCII, but in practice
562                 // you can use the encoding of the main document as long as
563                 // some elements like keys and names are pure ASCII. Therefore
564                 // we convert the file from the buffer encoding.
565                 // We don't restrict keys to ASCII in LyX, since our own
566                 // InsetBibitem can generate non-ASCII keys, and nonstandard
567                 // 8bit clean bibtex forks exist.
568                 
569                 idocfstream ifs(it->availableFile().toFilesystemEncoding().c_str(),
570                         ios_base::in, buffer().params().encoding().iconvName());
571
572                 char_type ch;
573                 VarMap strings;
574
575                 while (ifs) {
576
577                         ifs.get(ch);
578                         if (!ifs)
579                                 break;
580
581                         if (ch != '@')
582                                 continue;
583
584                         docstring entryType;
585
586                         if (!readTypeOrKey(entryType, ifs, from_ascii("{("), 
587                                            docstring(), makeLowerCase) || !ifs)
588                                 continue;
589
590                         if (entryType == from_ascii("comment")) {
591
592                                 ifs.ignore(numeric_limits<int>::max(), '\n');
593                                 continue;
594                         }
595
596                         ifs.get(ch);
597                         if (!ifs)
598                                 break;
599
600                         if ((ch != '(') && (ch != '{')) {
601                                 // invalid entry delimiter
602                                 ifs.putback(ch);
603                                 continue;
604                         }
605
606                         // process the entry
607                         if (entryType == from_ascii("string")) {
608
609                                 // read string and add it to the strings map
610                                 // (or replace it's old value)
611                                 docstring name;
612                                 docstring value;
613
614                                 if (!readTypeOrKey(name, ifs, from_ascii("="), 
615                                                    from_ascii("#{}(),"), makeLowerCase) || !ifs)
616                                         continue;
617
618                                 // next char must be an equal sign
619                                 ifs.get(ch);
620                                 if (!ifs || ch != '=')
621                                         continue;
622
623                                 if (!readValue(value, ifs, strings))
624                                         continue;
625
626                                 strings[name] = value;
627
628                         } else if (entryType == from_ascii("preamble")) {
629
630                                 // preamble definitions are discarded.
631                                 // can they be of any use in lyx?
632                                 docstring value;
633
634                                 if (!readValue(value, ifs, strings))
635                                         continue;
636
637                         } else {
638
639                                 // Citation entry. Try to read the key.
640                                 docstring key;
641
642                                 if (!readTypeOrKey(key, ifs, from_ascii(","), 
643                                                    from_ascii("}"), keepCase) || !ifs)
644                                         continue;
645
646                                 /////////////////////////////////////////////
647                                 // now we have a key, so we will add an entry 
648                                 // (even if it's empty, as bibtex does)
649                                 //
650                                 // we now read the field = value pairs.
651                                 // all items must be separated by a comma. If
652                                 // it is missing the scanning of this entry is
653                                 // stopped and the next is searched.
654                                 docstring fields;
655                                 docstring name;
656                                 docstring value;
657                                 docstring commaNewline;
658                                 docstring data;
659                                 BibTeXInfo keyvalmap(key, entryType);
660                                 
661                                 bool readNext = removeWSAndComma(ifs);
662  
663                                 while (ifs && readNext) {
664
665                                         // read field name
666                                         if (!readTypeOrKey(name, ifs, from_ascii("="), 
667                                                            from_ascii("{}(),"), makeLowerCase) || !ifs)
668                                                 break;
669
670                                         // next char must be an equal sign
671                                         ifs.get(ch);
672                                         if (!ifs)
673                                                 break;
674                                         if (ch != '=') {
675                                                 ifs.putback(ch);
676                                                 break;
677                                         }
678
679                                         // read field value
680                                         if (!readValue(value, ifs, strings))
681                                                 break;
682
683                                         keyvalmap[name] = value;
684                                         data += "\n\n" + value;
685                                         keylist.addFieldName(name);
686                                         readNext = removeWSAndComma(ifs);
687                                 }
688
689                                 // add the new entry
690                                 keylist.addEntryType(entryType);
691                                 keyvalmap.setAllData(data);
692                                 keylist[key] = keyvalmap;
693                         }
694                 } //< searching '@'
695         } //< for loop over files
696 }
697
698
699
700 bool InsetBibtex::addDatabase(string const & db)
701 {
702         EmbeddedFile file(changeExtension(db, "bib"), buffer().filePath());
703         
704         // only compare filename
705         EmbeddedFileList::iterator it = bibfiles_.begin();
706         EmbeddedFileList::iterator it_end = bibfiles_.end();
707         for (; it != it_end; ++it)
708                 if (it->absFilename() == file.absFilename())
709                         return false;
710         
711         bibfiles_.push_back(file);
712         updateParam();
713         return true;
714 }
715
716
717 bool InsetBibtex::delDatabase(string const & db)
718 {
719         EmbeddedFile file(changeExtension(db, "bib"), buffer().filePath());
720         
721         // only compare filename
722         EmbeddedFileList::iterator it = bibfiles_.begin();
723         EmbeddedFileList::iterator it_end = bibfiles_.end();
724         for (; it != it_end; ++it)
725                 if (it->absFilename() == file.absFilename()) {
726                         bibfiles_.erase(it);
727                         updateParam();
728                         return true;
729                 }
730         return false;
731 }
732
733
734 void InsetBibtex::validate(LaTeXFeatures & features) const
735 {
736         if (features.bufferParams().use_bibtopic)
737                 features.require("bibtopic");
738 }
739
740
741 void InsetBibtex::createBibFiles(docstring const & bibParam,
742         docstring const & embedParam) const
743 {
744         bibfiles_.clear();
745         
746         string tmp;
747         string emb;
748         
749         string bibfiles = to_utf8(bibParam);
750         string embedStatus = to_utf8(embedParam);
751         
752         LYXERR(Debug::FILES, "Create bib files from parameters "
753                 << bibfiles << " and " << embedStatus);
754
755         bibfiles = split(bibfiles, tmp, ',');
756         embedStatus = split(embedStatus, emb, ',');
757         
758         while (!tmp.empty()) {
759                 EmbeddedFile file(changeExtension(tmp, "bib"), buffer().filePath());
760                 
761                 file.setInzipName(emb);
762                 file.setEmbed(!emb.empty());
763                 file.enable(buffer().embedded(), &buffer(), false);
764                 bibfiles_.push_back(file);
765                 // Get next file name
766                 bibfiles = split(bibfiles, tmp, ',');
767                 embedStatus = split(embedStatus, emb, ',');
768         }
769 }
770
771
772 void InsetBibtex::updateParam()
773 {
774         docstring bibfiles;
775         docstring embed;
776
777         bool first = true;
778         for (EmbeddedFileList::iterator it = bibfiles_.begin();
779                 it != bibfiles_.end(); ++it) {
780                 if (!first) {
781                         bibfiles += ',';
782                         embed += ',';
783                 } else
784                         first = false;
785                 bibfiles += from_utf8(it->outputFilename(buffer().filePath()));
786                 if (it->embedded())
787                         embed += from_utf8(it->inzipName());
788         }
789         setParam("bibfiles", bibfiles);
790         setParam("embed", embed);
791 }
792
793
794 void InsetBibtex::registerEmbeddedFiles(EmbeddedFileList & files) const
795 {
796         if (bibfiles_.empty())
797                 createBibFiles(params()["bibfiles"], params()["embed"]);
798
799         EmbeddedFileList::const_iterator it = bibfiles_.begin();
800         EmbeddedFileList::const_iterator it_end = bibfiles_.end();
801         for (; it != it_end; ++it)
802                 files.registerFile(*it, this, buffer());
803 }
804
805
806 void InsetBibtex::updateEmbeddedFile(EmbeddedFile const & file)
807 {
808         // look for the item and update status
809         for (EmbeddedFileList::iterator it = bibfiles_.begin();
810                 it != bibfiles_.end(); ++it)
811                 if (it->absFilename() == file.absFilename())
812                         *it = file;
813         
814         updateParam();
815 }
816
817
818 } // namespace lyx