1
1
#include < iostream>
2
+ #include < sstream>
2
3
#include < string>
3
4
#include < cstdlib>
4
5
#include < unistd.h>
@@ -53,13 +54,28 @@ extern "C" {
53
54
Context cpp_ctx (c_ctx->options .include_paths );
54
55
Document doc (0 , c_ctx->input_string , cpp_ctx);
55
56
c_ctx->output_string = process_document (doc, c_ctx->options .output_style );
57
+ c_ctx->error_message = 0 ;
58
+ c_ctx->error_status = 0 ;
56
59
}
57
60
catch (Error& e) {
58
- cerr << " ERROR -- " << e.file_name << " , line " << e.line_number << " : " << e.message << endl;
61
+ stringstream msg_stream;
62
+ msg_stream << " ERROR -- " << e.file_name << " , line " << e.line_number << " : " << e.message << endl;
63
+ string msg (msg_stream.str ());
64
+ char * msg_str = (char *) malloc (msg.size () + 1 );
65
+ strcpy (msg_str, msg.c_str ());
66
+ c_ctx->error_status = 1 ;
59
67
c_ctx->output_string = 0 ;
68
+ c_ctx->error_message = msg_str;
60
69
}
61
70
catch (bad_alloc& ba) {
62
- cerr << " ERROR -- unable to allocate memory: " << ba.what () << endl;
71
+ stringstream msg_stream;
72
+ msg_stream << " ERROR -- unable to allocate memory: " << ba.what () << endl;
73
+ string msg (msg_stream.str ());
74
+ char * msg_str = (char *) malloc (msg.size () + 1 );
75
+ strcpy (msg_str, msg.c_str ());
76
+ c_ctx->error_status = 1 ;
77
+ c_ctx->output_string = 0 ;
78
+ c_ctx->error_message = msg_str;
63
79
}
64
80
// TO DO: CATCH EVERYTHING ELSE
65
81
return 0 ;
@@ -72,13 +88,28 @@ extern "C" {
72
88
Context cpp_ctx (c_ctx->options .include_paths );
73
89
Document doc (c_ctx->input_path , 0 , cpp_ctx);
74
90
c_ctx->output_string = process_document (doc, c_ctx->options .output_style );
91
+ c_ctx->error_message = 0 ;
92
+ c_ctx->error_status = 0 ;
75
93
}
76
94
catch (Error& e) {
77
- cerr << " ERROR -- " << e.file_name << " , line " << e.line_number << " : " << e.message << endl;
95
+ stringstream msg_stream;
96
+ msg_stream << " ERROR -- " << e.file_name << " , line " << e.line_number << " : " << e.message << endl;
97
+ string msg (msg_stream.str ());
98
+ char * msg_str = (char *) malloc (msg.size () + 1 );
99
+ strcpy (msg_str, msg.c_str ());
100
+ c_ctx->error_status = 1 ;
78
101
c_ctx->output_string = 0 ;
102
+ c_ctx->error_message = msg_str;
79
103
}
80
104
catch (bad_alloc& ba) {
81
- cerr << " ERROR -- unable to allocate memory: " << ba.what () << endl;
105
+ stringstream msg_stream;
106
+ msg_stream << " ERROR -- unable to allocate memory: " << ba.what () << endl;
107
+ string msg (msg_stream.str ());
108
+ char * msg_str = (char *) malloc (msg.size () + 1 );
109
+ strcpy (msg_str, msg.c_str ());
110
+ c_ctx->error_status = 1 ;
111
+ c_ctx->output_string = 0 ;
112
+ c_ctx->error_message = msg_str;
82
113
}
83
114
// TO DO: CATCH EVERYTHING ELSE
84
115
return 0 ;
0 commit comments