#include #include #include #include #include #include // a function to chomp stdin char * chomp_stdin() { const size_t read_size = 256; size_t pos = 0; size_t space_left = read_size; size_t buf_size = read_size; char *buf = malloc(read_size); while(!feof(stdin)) { size_t bytes_read = 0; bytes_read = fread(buf + pos, sizeof(char), space_left, stdin); if(ferror(stdin) || bytes_read == 0) { break; } pos += bytes_read; space_left = buf_size - pos; if(space_left == 0) { buf = realloc(buf, buf_size + read_size); if(buf == NULL) fprintf(stderr, "%s\n", strerror(errno)); buf_size += read_size; space_left = read_size; } } // if we didn't read anything, just return NULL; if(pos == 0) { free(buf); return NULL; } // gotta throw a null terminator there if (space_left != 0) { buf[pos+1] = '\0'; } else { buf = realloc(buf, buf_size + read_size); if(buf == NULL) fprintf(stderr, "%s\n", strerror(errno)); buf[pos+1] = '\0'; } return buf; } int main (int argc, char **argv) { // load up our stdin char *input = chomp_stdin(); if(input == NULL) { exit(1); } // setup our parsing context struct sass_context *ctx = sass_new_context(); ctx->source_string = input; // parse sass_compile(ctx); // error check if (ctx->error_status) { if (ctx->error_message) fprintf(stderr,"%s\n", ctx->error_message); else fprintf(stderr,"An error occured; no error message available\n"); return ctx->error_status; } else if (ctx->output_string) { fprintf(stdout, "%s", ctx->output_string); } sass_free_context(ctx); free(input); return 0; }