Description: get charset from locale or commandline
Author: Ralf Treinen <treinen@debian.org>
Credits: Junichi Uekawa <dancer@netfort.gr.jp> for submitting the idea of
 solving the same problem for the hevea package
Closes-Bug:  Debian Bug#198802

Index: bibtex2html/html.ml
===================================================================
--- bibtex2html.orig/html.ml	2014-07-06 19:48:42.491331063 +0200
+++ bibtex2html/html.ml	2014-07-06 19:48:42.483331063 +0200
@@ -21,11 +21,28 @@
 let bgcolor = ref None
 let css = ref None
 
+let defaultcharset = "ISO-8859-1"
+let charset =
+  ref (try
+	 let c = Unix.open_process_in "/usr/bin/locale charmap"
+	 in let s = input_line c
+	 in begin
+	     Unix.close_process_in c;
+	     if s = "" then defaultcharset else s
+	   end
+       with
+	   _ -> defaultcharset)
+    
 let open_document ch ftitle =
   output_string ch
     "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n\n";
   output_string ch "<html>\n\n<head>\n";
   output_string ch "<title>"; ftitle(); output_string ch "</title>\n";
+  fprintf ch
+    "<meta http-equiv=\"content-type\" content=\"text/html; charset=%s\">\n"
+    !charset;
+  output_string ch "<meta name=\"generator\" content=\"bibtex2html\">\n";
+
   begin match !css with
     | None -> ()
     | Some f ->
Index: bibtex2html/main.ml
===================================================================
--- bibtex2html.orig/main.ml	2014-07-06 19:48:42.491331063 +0200
+++ bibtex2html/main.ml	2014-07-06 19:48:42.483331063 +0200
@@ -344,6 +344,7 @@
   -revkeys   entries numbered in reverse order
   -t title   title of the HTML file (default is the filename)
   -bg color  background color of the HTML file (default is none)
+  -charset c specify a charset c to use in the HEAD tag
   -css file  specify a style sheet file
   -o file    redirect the output
   -header    additional header in the HTML file
@@ -416,6 +417,10 @@
 	Html.bgcolor := Some s; parse_rec rem
     | ("-bg" | "-background" | "--background") :: [] ->
 	usage()
+    | ("-charset" | "--charset") :: c :: rem ->
+        Html.charset := c; parse_rec rem
+    | ("-charset" | "--charset") :: [] ->
+        usage()
     | ("-css" | "-style-sheet" | "--style-sheet") :: f :: rem ->
 	Html.css := Some f; parse_rec rem
     | ("-css" | "-style-sheet" | "--style-sheet") :: [] ->
Index: bibtex2html/manual.tex
===================================================================
--- bibtex2html.orig/manual.tex	2014-07-06 19:48:42.491331063 +0200
+++ bibtex2html/manual.tex	2014-07-06 19:48:42.483331063 +0200
@@ -276,6 +276,12 @@
 
   set a style sheet file for the HTML document (default is none).
 
+\item[\texttt{-charset} \textit{c}, \texttt{\mm{}charset} \textit{c}] ~
+
+  specify the charset to use in the META tag of generated html files.
+  The default is the output of the command \verb|locale charmap|, or if
+  this doesn't work, \texttt{ISO-8859-1}.
+  
 \item[\texttt{-dl}, \texttt{\mm{}dl}] ~
 
   use HTML \texttt{DL} lists instead of HTML tables to format entries.
Index: bibtex2html/Makefile.in
===================================================================
--- bibtex2html.orig/Makefile.in	2014-07-06 19:48:42.491331063 +0200
+++ bibtex2html/Makefile.in	2014-07-06 19:49:55.435328392 +0200
@@ -112,7 +112,7 @@
 	strip bibtex2html$(EXE)
 
 bibtex2html.byte: $(OBJS:.cmx=.cmo)
-	$(OCAMLC) $(PROFILE) $(FLAGS)-o bibtex2html.byte str.cma $(OBJS:.cmx=.cmo) $(STRLIB)
+	$(OCAMLC) $(PROFILE) $(FLAGS)-o bibtex2html.byte str.cma unix.cma $(OBJS:.cmx=.cmo) $(STRLIB)
 
 bibtex2html.pbyte: $(OBJS:.cmx=.cmo)
 	$(OCAMLC) -use-runtime ~demons/bin/$(OSTYPE)/ocamlcustomrun \
@@ -132,7 +132,7 @@
 	strip bib2bib$(EXE)
 
 bib2bib.byte: $(BIB2BIBOBJS:.cmx=.cmo)
-	$(OCAMLC)  $(PROFILE) $(FLAGS) -o bib2bib.byte str.cma $(BIB2BIBOBJS:.cmx=.cmo) $(STRLIB)
+	$(OCAMLC)  $(PROFILE) $(FLAGS) -o bib2bib.byte str.cma unix.cma $(BIB2BIBOBJS:.cmx=.cmo) $(STRLIB)
 
 bib2bib.pbyte: $(BIB2BIBOBJS:.cmx=.cmo)
 	$(OCAMLC) -use-runtime ~demons/bin/$(OSTYPE)/ocamlcustomrun \
