1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
#ifndef PIKE_SASS_H 
#define PIKE_SASS_H 
 
 
#ifdef SASS_DEBUG 
# define SASS_TRACE(X...) printf ("# " X) 
#else 
# define SASS_TRACE(X...) 
#endif 
 
#define OPTS_INC_ARRAY_BLK_SIZE 4 
 
typedef struct my_opts_array 
{ 
  char **items; 
  int    len; 
} my_opts_array; 
 
 
typedef struct my_opts 
{ 
  int             style; 
  my_opts_array  *include_paths; 
  long            precision; 
  bool            comments; 
  char           *map_path; 
  bool            map_embed; 
  char           *map_root; 
  bool            omit_map_url; 
} my_opts; 
 
 
my_opts* my_opts_create () 
{ 
  my_opts *opts            = malloc (sizeof (my_opts)); 
  opts->include_paths      = NULL; 
  // opts->more_include_paths = NULL; 
  opts->map_path           = NULL; 
  opts->map_root           = NULL; 
  opts->style              = SASS_STYLE_NESTED; 
  opts->precision          = 5; 
  opts->omit_map_url       = true; 
 
  return opts; 
} 
 
 
void my_opts_push_include_path (my_opts *opts, const char *path) 
{ 
  if (access (path, F_OK) == -1) { 
    Pike_error ("Include path \"%s\" does not exist!\n", path); 
  } 
 
  if (opts->include_paths == NULL) { 
    int blksize = OPTS_INC_ARRAY_BLK_SIZE * sizeof (char*); 
    opts->include_paths = malloc (sizeof (my_opts_array)); 
    opts->include_paths->len = 0; 
    opts->include_paths->items = malloc (blksize); 
  } 
  else { 
    if (opts->include_paths->len % OPTS_INC_ARRAY_BLK_SIZE == 0) { 
      int blksize = OPTS_INC_ARRAY_BLK_SIZE * sizeof (char*); 
      int size = blksize * opts->include_paths->len; 
      opts->include_paths->items = 
        realloc (opts->include_paths->items, size + blksize); 
    } 
  } 
 
  int pos = opts->include_paths->len; 
  opts->include_paths->items[pos] = malloc (strlen (path) + 1); 
  strcpy (opts->include_paths->items[pos], path); 
 
  opts->include_paths->len += 1; 
} 
 
 
void my_opts_set_include_path (my_opts *opts, const char *path) 
{ 
  if (path != NULL) { 
    SASS_TRACE ("::: my_opts_set_include_path(%s)\n", path); 
 
    if (access (path, F_OK) == -1) { 
      Pike_error ("Include path \"%s\" does not exist!\n", path); 
    } 
 
    if (opts->include_paths == NULL) { 
      my_opts_push_include_path (opts, path); 
    } 
    else { 
      opts->include_paths->items[0] = strdup (path); 
    } 
  } 
} 
 
 
void my_opts_include_paths_delete (my_opts *opts) 
{ 
  SASS_TRACE ("----- my_opts_include_paths_delete -----\n"); 
 
  if (opts->include_paths) { 
    for (int i = 0; i < opts->include_paths->len; i++) { 
      free (opts->include_paths->items[i]); 
    } 
 
    free (opts->include_paths->items); 
  } 
 
  free (opts->include_paths); 
  opts->include_paths = NULL; 
} 
 
 
void my_opts_delete (my_opts *opts) 
{ 
  SASS_TRACE ("----- my_opts_delete -----\n"); 
  if (opts->include_paths) { 
    my_opts_include_paths_delete (opts); 
  } 
 
  if (opts->map_path) { 
    free (opts->map_path); 
  } 
 
  if (opts->map_root) { 
    free (opts->map_root); 
  } 
 
  free (opts); 
  SASS_TRACE ("----- /my_opts_delete -----\n"); 
} 
 
#endif /* PIKE_SASS_H */