On Wed, Mar 19, 2014 at 05:53:11PM +0100, Pino Toscano wrote:
---
builder/index-parse.y | 4 +++-
builder/index-parser-c.c | 5 +++--
builder/index-struct.h | 1 +
builder/index_parser.ml | 2 +-
builder/ini_reader.ml | 6 +++---
builder/ini_reader.mli | 2 +-
builder/sources.ml | 2 +-
7 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/builder/index-parse.y b/builder/index-parse.y
index 9c75f71..5554e53 100644
--- a/builder/index-parse.y
+++ b/builder/index-parse.y
@@ -143,7 +143,9 @@ emptylines:
void
yyerror (YYLTYPE * yylloc, yyscan_t scanner, struct parse_context *context, const char
*msg)
{
- fprintf (stderr, "%s%ssyntax error at line %d: %s\n",
+ fprintf (stderr, "%s%s%s%ssyntax error at line %d: %s\n",
+ context->program_name ? context->program_name : "",
+ context->program_name ? ": " : "",
context->input_file ? context->input_file : "",
context->input_file ? ": " : "",
yylloc->first_line, msg);
diff --git a/builder/index-parser-c.c b/builder/index-parser-c.c
index 8cae7b8..5dcc82f 100644
--- a/builder/index-parser-c.c
+++ b/builder/index-parser-c.c
@@ -46,9 +46,9 @@ extern void unix_error (int errcode, char * cmdname, value arg)
Noreturn;
extern int do_parse (struct parse_context *context, FILE *in);
value
-virt_builder_parse_index (value filenamev)
+virt_builder_parse_index (value progv, value filenamev)
{
- CAMLparam1 (filenamev);
+ CAMLparam2 (progv, filenamev);
CAMLlocal5 (rv, v, sv, sv2, fv);
struct section *sections;
size_t i, nr_sections;
@@ -56,6 +56,7 @@ virt_builder_parse_index (value filenamev)
FILE *in;
parse_context_init (&context);
+ context.program_name = String_val (progv);
context.input_file = String_val (filenamev);
in = fopen (String_val (filenamev), "r");
diff --git a/builder/index-struct.h b/builder/index-struct.h
index 7d4b8e0..7e16637 100644
--- a/builder/index-struct.h
+++ b/builder/index-struct.h
@@ -44,6 +44,7 @@ struct parse_context {
*/
int seen_comments;
const char *input_file;
+ const char *program_name;
};
/* Initialize the content of a parse_context. */
diff --git a/builder/index_parser.ml b/builder/index_parser.ml
index 472a6c7..5d566f9 100644
--- a/builder/index_parser.ml
+++ b/builder/index_parser.ml
@@ -119,7 +119,7 @@ let get_index ~prog ~debug ~downloader ~sigchecker source =
Sigchecker.verify sigchecker tmpfile;
(* Try parsing the file. *)
- let sections = Ini_reader.read_ini tmpfile in
+ let sections = Ini_reader.read_ini ~prog tmpfile in
if delete_tmpfile then
(try Unix.unlink tmpfile with _ -> ());
diff --git a/builder/ini_reader.ml b/builder/ini_reader.ml
index fbd4d2f..68e3863 100644
--- a/builder/ini_reader.ml
+++ b/builder/ini_reader.ml
@@ -27,10 +27,10 @@ and c_section = string * c_fields (* [name] + fields *)
and c_fields = field array
(* Calls yyparse in the C code. *)
-external parse_index : string -> c_sections = "virt_builder_parse_index"
+external parse_index : prog:string -> string -> c_sections =
"virt_builder_parse_index"
-let read_ini file =
- let sections = parse_index file in
+let read_ini ~prog file =
+ let sections = parse_index ~prog file in
let sections = Array.to_list sections in
List.map (
fun (n, fields) ->
diff --git a/builder/ini_reader.mli b/builder/ini_reader.mli
index 992a1cb..ac3bebe 100644
--- a/builder/ini_reader.mli
+++ b/builder/ini_reader.mli
@@ -21,4 +21,4 @@ and section = string * fields (* [name] + fields *)
and fields = field list
and field = string * string option * string (* key + subkey + value *)
-val read_ini : string -> sections
+val read_ini : prog:string -> string -> sections
diff --git a/builder/sources.ml b/builder/sources.ml
index 016adc4..1fee65e 100644
--- a/builder/sources.ml
+++ b/builder/sources.ml
@@ -32,7 +32,7 @@ let parse_conf ~prog ~debug file =
if debug then (
eprintf (f_"%s: trying to read %s\n") prog file;
);
- let sections = Ini_reader.read_ini file in
+ let sections = Ini_reader.read_ini ~prog file in
let sources = List.fold_right (
fun (n, fields) acc ->
ACK.
Thanks, Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/