Blame docs/api-context-example.md

Packit Service 7770af
## Example main.c
Packit Service 7770af
Packit Service 7770af
```C
Packit Service 7770af
#include <stdio.h>
Packit Service 7770af
#include "sass/context.h"
Packit Service 7770af
Packit Service 7770af
int main( int argc, const char* argv[] )
Packit Service 7770af
{
Packit Service 7770af
Packit Service 7770af
  // get the input file from first argument or use default
Packit Service 7770af
  const char* input = argc > 1 ? argv[1] : "styles.scss";
Packit Service 7770af
Packit Service 7770af
  // create the file context and get all related structs
Packit Service 7770af
  struct Sass_File_Context* file_ctx = sass_make_file_context(input);
Packit Service 7770af
  struct Sass_Context* ctx = sass_file_context_get_context(file_ctx);
Packit Service 7770af
  struct Sass_Options* ctx_opt = sass_context_get_options(ctx);
Packit Service 7770af
Packit Service 7770af
  // configure some options ...
Packit Service 7770af
  sass_option_set_precision(ctx_opt, 10);
Packit Service 7770af
Packit Service 7770af
  // context is set up, call the compile step now
Packit Service 7770af
  int status = sass_compile_file_context(file_ctx);
Packit Service 7770af
Packit Service 7770af
  // print the result or the error to the stdout
Packit Service 7770af
  if (status == 0) puts(sass_context_get_output_string(ctx));
Packit Service 7770af
  else puts(sass_context_get_error_message(ctx));
Packit Service 7770af
Packit Service 7770af
  // release allocated memory
Packit Service 7770af
  sass_delete_file_context(file_ctx);
Packit Service 7770af
Packit Service 7770af
  // exit status
Packit Service 7770af
  return status;
Packit Service 7770af
Packit Service 7770af
}
Packit Service 7770af
```
Packit Service 7770af
Packit Service 7770af
### Compile main.c
Packit Service 7770af
Packit Service 7770af
```bash
Packit Service 7770af
gcc -c main.c -o main.o
Packit Service 7770af
gcc -o sample main.o -lsass
Packit Service 7770af
echo "foo { margin: 21px * 2; }" > foo.scss
Packit Service 7770af
./sample foo.scss => "foo { margin: 42px }"
Packit Service 7770af
```
Packit Service 7770af