Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
1f73d162
Commit
1f73d162
authored
Feb 20, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing and debugging the context initialization functions.
parent
ccc9f0a4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
context.c
src/context.c
+41
-5
context.h
src/context.h
+3
-2
No files found.
src/context.c
View file @
1f73d162
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "context.h"
#include "file.h"
s
ass_context
*
make_sass_context_from_file
(
char
*
path
)
{
s
tatic
sass_context
*
sass_alloc_context
(
)
{
sass_context
*
ctx
=
malloc
(
sizeof
(
sass_context
));
if
(
!
ctx
)
{
printf
(
"ERROR: could not allocate
s
ass context object.
\n
"
);
printf
(
"ERROR: could not allocate
S
ass context object.
\n
"
);
abort
();
}
return
ctx
;
}
static
char
*
sass_read_file
(
char
*
path
)
{
FILE
*
f
;
f
=
fopen
(
path
,
"rb"
);
if
(
!
f
)
{
printf
(
"ERROR: could not open Sass source file %s"
,
path
);
abort
();
}
fseek
(
f
,
0L
,
SEEK_END
);
int
len
=
ftell
(
f
);
rewind
(
f
);
char
*
buf
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
);
fread
(
buf
,
sizeof
(
char
),
len
,
f
);
buf
[
len
]
=
'\0'
;
fclose
(
f
);
return
buf
;
}
sass_context
*
sass_make_context_from_file
(
char
*
path
)
{
sass_context
*
ctx
=
sass_alloc_context
();
ctx
->
path
=
path
;
ctx
->
src
=
sass_read_file
(
path
);
ctx
->
pos
=
src
;
ctx
->
pos
=
ctx
->
src
=
sass_read_file
(
path
);
ctx
->
line
=
1
;
return
ctx
;
}
sass_context
*
sass_make_context_from_string
(
char
*
src
)
{
size_t
len
=
strlen
(
src
);
sass_context
*
ctx
=
sass_alloc_context
();
if
(
!
(
ctx
->
pos
=
ctx
->
src
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
)
))
{
printf
(
"ERROR: could not copy Sass source string.
\n
"
);
abort
();
}
memcpy
(
ctx
->
src
,
src
,
len
);
ctx
->
src
[
len
]
=
'\0'
;
ctx
->
line
=
1
;
return
ctx
;
}
...
...
@@ -19,3 +54,4 @@ void *free_sass_context(sass_context *ctx) {
free
(
ctx
->
src
);
free
(
ctx
);
}
src/context.h
View file @
1f73d162
...
...
@@ -4,8 +4,10 @@ typedef struct {
char
*
path
;
/* the full directory+filename of the source file */
char
*
src
;
/* the text of the entire source file */
char
*
pos
;
/* keeps track of the parser/scanner's current position */
size_t
line
;
/* the number of the line currently being parsed/scanned */
jmp_buf
env
;
/* the top of the exception-handling stack */
/* more to come */
}
sass_context
;
sass_context
*
make_sass_context_from_file
(
char
*
path
);
\ No newline at end of file
sass_context
*
sass_make_context_from_file
(
char
*
path
);
sass_context
*
sass_make_context_from_string
(
char
*
src
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment