1bibtexImport <- function(infile, ..., tex = NULL, encoding = NULL, options, extra = FALSE){
2    ## informat is always "bibtex"
3    stopifnot(length(list(...)) == 0) # no ... arguments allowed
4
5    outfile <- tempfile(fileext = ".R")
6    on.exit(unlink(outfile))
7
8    argv_2be <- c("dummy")
9
10    if(!is.null(encoding)){
11        if(length(encoding) == 1)
12            encoding <- rep(encoding, 2)
13
14        if(encoding[1] == "UTF-8" || encoding[1] == "default")
15            encoding[1] <- "utf8"
16        if(encoding[2] == "UTF-8" || encoding[2] == "default")
17            encoding[2] <- "utf8"
18
19        argv_2be <- c(argv_2be, "-i", encoding[1])
20        argv_2be <- c(argv_2be, "-o", encoding[2])
21    }
22
23    if(!is.null(tex)){
24        for(tex_op in tex){
25            switch(tex_op,
26                   keep_tex_chars = {  #  Georgi
27                       argv_2be <- c(argv_2be, "--keep-tex-chars")
28                   },
29                   no_latex = { # accents to letters    # TODO: this needs further work
30                       argv_2be <- c(argv_2be, "-nl")
31                   },
32                   export_tex_chars = {
33                       argv_2be <- c(argv_2be, "--export_tex_chars")
34                   },
35                   ## uppercase = {
36                   ##     argv_2be <- c(argv_2be, "-U")
37                   ## },
38                   brackets = {
39                       argv_2be <- c(argv_2be, "-b")
40                   },
41                   dash = {
42                       argv_2be <- c(argv_2be, "-sd")
43                   },
44                   comma = {
45                       argv_2be <- c(argv_2be, "-fc")
46                   },
47                   Rdpack = {
48                       argv_2be <- c(argv_2be, "--Rdpack")
49                   },
50                   convert_latex_escapes = {
51                       argv_2be <- c(argv_2be, "--convert_latex_escapes")
52                   },
53                   ## default
54                   stop("unsupported 'tex' option")
55                   )
56        }
57    }
58
59    if(!missing(options)){
60        nams <- names(options)
61        ## options <- as.vector(options)
62        for(j in seq_along(options)){
63            switch(nams[j],
64                   i = { argv_2be <- c(argv_2be, "-i", options[j]) },
65                   o = { argv_2be <- c(argv_2be, "-o", options[j]) },
66                   ## oxml = {argv_2xml <- c(argv_2xml, "-o", options[j])},
67                   h = {argv_2be <- c(argv_2be, "-h")},
68                   v = {argv_2be <- c(argv_2be, "-v")},
69                   a = {argv_2be <- c(argv_2be, "-a")},
70                   s = {argv_2be <- c(argv_2be, "-s")},
71                   u = {argv_2be <- c(argv_2be, "-u")},
72                   U = {argv_2be <- c(argv_2be, "-U")},
73                   un = {argv_2be <- c(argv_2be, "-un")},
74                   x = {argv_2be <- c(argv_2be, "-x")},
75                   nl = { argv_2be <- c(argv_2be, "-nl") },
76                   d = { argv_2be <- c(argv_2be, "-d") },
77                   c = {argv_2be <- c(argv_2be, "-c", options[j])},
78                   ## as = {argv_2be <- c(argv_2be, "-as", options[j])},
79                   nt = {argv_2be <- c(argv_2be, "-nt")},
80                   verbose = {argv_2be <- c(argv_2be, "--verbose")},
81                   debug = {
82                       argv_2be <- c(argv_2be, "--debug")
83                   },
84
85                   ##default
86                   stop("unsupported option '", nams[j])
87                   )
88        }
89    }
90
91    argv_2be <- c(argv_2be, infile)
92    argc_2be <- as.integer(length(argv_2be))
93
94    n_2be <- as.double(0)  # for the number of references (double)
95
96    prg <- paste0("bib", "2be")
97    argv_2be[1] <- prg
98    wrk_out <- .C(C_bib2be_main, as.integer(argc_2be), argv_2be, outfile, nref_in = n_2be)
99
100    bibe <- readBibentry(outfile, extra = extra)
101
102    bibe
103}
104