int compile_file(struct Sass_Options* options, char* input_path, char* outfile) { int ret; char* source_map_file = 0; struct Sass_File_Context* ctx = sass_make_file_context(input_path); struct Sass_Context* ctx_out = sass_file_context_get_context(ctx); if (outfile) sass_option_set_output_path(options, outfile); sass_file_context_set_options(ctx, options); sass_compile_file_context(ctx); ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_output_string(ctx_out), outfile ); if (sass_option_get_source_map_file(options)) { ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_source_map_string(ctx_out), sass_option_get_source_map_file(options) ); } free(source_map_file); sass_delete_file_context(ctx); return ret; }
int compile_stdin(struct Sass_Options* options, char* outfile) { int ret; struct Sass_Data_Context* ctx; char buffer[BUFSIZE]; size_t size = 1; char *source_string = malloc(sizeof(char) * BUFSIZE); if(source_string == NULL) { perror("Allocation failed"); exit(1); } source_string[0] = '\0'; while(fgets(buffer, BUFSIZE, stdin)) { char *old = source_string; size += strlen(buffer); source_string = realloc(source_string, size); if(source_string == NULL) { perror("Reallocation failed"); free(old); exit(2); } #ifdef _MSC_VER strcat_s(source_string, size, buffer); #else strcat(source_string, buffer); #endif } if(ferror(stdin)) { free(source_string); perror("Error reading standard input"); exit(2); } ctx = sass_make_data_context(source_string); struct Sass_Context* ctx_out = sass_data_context_get_context(ctx); sass_data_context_set_options(ctx, options); sass_compile_data_context(ctx); ret = output( sass_context_get_error_status(ctx_out), sass_context_get_error_message(ctx_out), sass_context_get_output_string(ctx_out), outfile ); sass_delete_data_context(ctx); return ret; }