Commit 5a0eae49 by Aaron Leung

Storing the error status and message into the interface struct.

parent f5dc2c38
...@@ -21,5 +21,6 @@ div[hux ~= "hello"] { ...@@ -21,5 +21,6 @@ div[hux ~= "hello"] {
foo: boo; foo: boo;
@include moogoo; @include moogoo;
dux: mux; dux: mux;
@import "foogoo"; @import bugaboo "foogoo"
blah: blah;
} }
#include <iostream> #include <iostream>
#include <sstream>
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#include <unistd.h> #include <unistd.h>
...@@ -53,13 +54,28 @@ extern "C" { ...@@ -53,13 +54,28 @@ extern "C" {
Context cpp_ctx(c_ctx->options.include_paths); Context cpp_ctx(c_ctx->options.include_paths);
Document doc(0, c_ctx->input_string, cpp_ctx); Document doc(0, c_ctx->input_string, cpp_ctx);
c_ctx->output_string = process_document(doc, c_ctx->options.output_style); c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
c_ctx->error_message = 0;
c_ctx->error_status = 0;
} }
catch (Error& e) { catch (Error& e) {
cerr << "ERROR -- " << e.file_name << ", line " << e.line_number << ": " << e.message << endl; stringstream msg_stream;
msg_stream << "ERROR -- " << e.file_name << ", line " << e.line_number << ": " << e.message << endl;
string msg(msg_stream.str());
char* msg_str = (char*) malloc(msg.size() + 1);
strcpy(msg_str, msg.c_str());
c_ctx->error_status = 1;
c_ctx->output_string = 0; c_ctx->output_string = 0;
c_ctx->error_message = msg_str;
} }
catch(bad_alloc& ba) { catch(bad_alloc& ba) {
cerr << "ERROR -- unable to allocate memory: " << ba.what() << endl; stringstream msg_stream;
msg_stream << "ERROR -- unable to allocate memory: " << ba.what() << endl;
string msg(msg_stream.str());
char* msg_str = (char*) malloc(msg.size() + 1);
strcpy(msg_str, msg.c_str());
c_ctx->error_status = 1;
c_ctx->output_string = 0;
c_ctx->error_message = msg_str;
} }
// TO DO: CATCH EVERYTHING ELSE // TO DO: CATCH EVERYTHING ELSE
return 0; return 0;
...@@ -72,13 +88,28 @@ extern "C" { ...@@ -72,13 +88,28 @@ extern "C" {
Context cpp_ctx(c_ctx->options.include_paths); Context cpp_ctx(c_ctx->options.include_paths);
Document doc(c_ctx->input_path, 0, cpp_ctx); Document doc(c_ctx->input_path, 0, cpp_ctx);
c_ctx->output_string = process_document(doc, c_ctx->options.output_style); c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
c_ctx->error_message = 0;
c_ctx->error_status = 0;
} }
catch (Error& e) { catch (Error& e) {
cerr << "ERROR -- " << e.file_name << ", line " << e.line_number << ": " << e.message << endl; stringstream msg_stream;
msg_stream << "ERROR -- " << e.file_name << ", line " << e.line_number << ": " << e.message << endl;
string msg(msg_stream.str());
char* msg_str = (char*) malloc(msg.size() + 1);
strcpy(msg_str, msg.c_str());
c_ctx->error_status = 1;
c_ctx->output_string = 0; c_ctx->output_string = 0;
c_ctx->error_message = msg_str;
} }
catch(bad_alloc& ba) { catch(bad_alloc& ba) {
cerr << "ERROR -- unable to allocate memory: " << ba.what() << endl; stringstream msg_stream;
msg_stream << "ERROR -- unable to allocate memory: " << ba.what() << endl;
string msg(msg_stream.str());
char* msg_str = (char*) malloc(msg.size() + 1);
strcpy(msg_str, msg.c_str());
c_ctx->error_status = 1;
c_ctx->output_string = 0;
c_ctx->error_message = msg_str;
} }
// TO DO: CATCH EVERYTHING ELSE // TO DO: CATCH EVERYTHING ELSE
return 0; return 0;
......
...@@ -16,18 +16,24 @@ struct sass_context { ...@@ -16,18 +16,24 @@ struct sass_context {
char* input_string; char* input_string;
char* output_string; char* output_string;
struct sass_options options; struct sass_options options;
int error_status;
char* error_message;
}; };
struct sass_folder_context { struct sass_folder_context {
char* search_path; char* search_path;
char* output_path; char* output_path;
struct sass_options options; struct sass_options options;
int error_status;
char* error_message;
}; };
struct sass_file_context { struct sass_file_context {
char* input_path; char* input_path;
char* output_string; char* output_string;
struct sass_options options; struct sass_options options;
int error_status;
char* error_message;
}; };
struct sass_context* sass_new_context (); struct sass_context* sass_new_context ();
......
...@@ -34,7 +34,16 @@ int main(int argc, char** argv) ...@@ -34,7 +34,16 @@ int main(int argc, char** argv)
sass_compile_file(ctx); sass_compile_file(ctx);
if (ctx->output_string) printf("%s", ctx->output_string); if (ctx->error_status) {
if (ctx->error_message) printf("%s", ctx->error_message);
else printf("An error occured; no error message available.\n");
}
else if (ctx->output_string) {
printf("%s", ctx->output_string);
}
else {
printf("Unknown internal error.\n");
}
sass_free_file_context(ctx); sass_free_file_context(ctx);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment