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