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	2019-10-11 08:54:23.913323313 +0200
+++ bibtex2html/html.ml	2019-10-11 08:54:23.913323313 +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	2019-10-11 08:54:23.913323313 +0200
+++ bibtex2html/main.ml	2019-10-11 08:54:23.913323313 +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	2019-10-11 08:54:23.913323313 +0200
+++ bibtex2html/manual.tex	2019-10-11 08:54:23.913323313 +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	2019-10-11 08:54:23.913323313 +0200
+++ bibtex2html/Makefile.in	2019-10-11 08:57:21.546271028 +0200
@@ -111,38 +111,38 @@
 	cp *.1 $$HOME/man/man1
 
 bibtex2html$(EXE): $(OBJS)
-	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o bibtex2html$(EXE) str.cmxa $(OBJS) $(STRLIB)
+	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o bibtex2html$(EXE) str.cmxa unix.cmxa $(OBJS) $(STRLIB)
 	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 \
 		-o bibtex2html.pbyte str.cma $(OBJS:.cmx=.cmo)
 
 bibtex2html.static: $(OBJS)
-	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o $@ str.cmxa $(OBJS) $(STRLIB) -cclib "-L. -static"
+	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o $@ str.cmxa unix.cmxa $(OBJS) $(STRLIB) -cclib "-L. -static"
 	strip $@
 
 SRC=$(OBJS:.cmx=.ml)
 bibtex2html.dfc: $(SRC)
 	ocamldefun -d defun `ocamldefun-args $(SRC)`
-	cd defun; $(OCAMLOPT) $(FLAGS) -o ../$@ str.cmxa $(SRC)
+	cd defun; $(OCAMLOPT) $(FLAGS) -o ../$@ str.cmxa unix.cmxa $(SRC)
 
 bib2bib$(EXE): $(BIB2BIBOBJS)
-	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o bib2bib$(EXE) str.cmxa $(BIB2BIBOBJS) $(STRLIB)
+	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o bib2bib$(EXE) str.cmxa unix.cmxa $(BIB2BIBOBJS) $(STRLIB)
 	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 \
 		-o bib2bib.pbyte str.cma $(BIB2BIBOBJS:.cmx=.cmo)
 
 bib2bib.static: $(BIB2BIBOBJS)
-	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o $@ str.cmxa $(BIB2BIBOBJS) $(STRLIB) -cclib "-L. -static"
+	$(OCAMLOPT) $(PROFILE) $(FLAGS) -o $@ str.cmxa unix.cmxa $(BIB2BIBOBJS) $(STRLIB) -cclib "-L. -static"
 	strip $@
 
 static: bibtex2html.static bib2bib.static
