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