aboutsummaryrefslogtreecommitdiff
path: root/ls_minify.c
diff options
context:
space:
mode:
Diffstat (limited to 'ls_minify.c')
-rw-r--r--ls_minify.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/ls_minify.c b/ls_minify.c
index bc0cca7..b1ba82d 100644
--- a/ls_minify.c
+++ b/ls_minify.c
@@ -26,13 +26,13 @@
typedef struct {
char const * s;
size_t len;
-} file_fetcher_ctx_t;
+} file_fetcher_t;
typedef struct {
- ls_context_t ls;
+ ls_t ls;
ls_token_t tok;
ls_token_ty_t last_type;
- file_fetcher_ctx_t * fctx;
+ file_fetcher_t * fet;
bool add_space;
FILE * f_out;
} minifier_t;
@@ -40,9 +40,9 @@ typedef struct {
// --- PRIVATE CONSTANTS -------------------------------------------------------
// --- PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
-static int _fetcher(void * ctx, uint16_t loc);
+static int _fetcher(void * arg, uint16_t loc);
static void _usage(char const * argv0, bool short_text);
-static void _minify(file_fetcher_ctx_t * fctx, FILE * f_out);
+static void _minify(file_fetcher_t * fet, FILE * f_out);
static void _min_number(minifier_t * min, ls_token_t tok);
static void _min_word(minifier_t * min, ls_token_t tok);
@@ -108,14 +108,14 @@ int main(int argc, char ** argv)
exit(EXIT_FAILURE);
}
- file_fetcher_ctx_t fctx;
+ file_fetcher_t fet;
assert(statbuf.st_size >= 0);
- fctx.len = (size_t) statbuf.st_size;
- char * s = malloc(fctx.len);
- size_t n = fread(s, 1, fctx.len, f);
- fctx.s = s;
+ fet.len = (size_t) statbuf.st_size;
+ char * s = malloc(fet.len);
+ size_t n = fread(s, 1, fet.len, f);
+ fet.s = s;
- if (n != fctx.len)
+ if (n != fet.len)
{
if (ferror(f))
perror("fread");
@@ -142,7 +142,7 @@ int main(int argc, char ** argv)
else
f = stdout;
- _minify(&fctx, f);
+ _minify(&fet, f);
free(s);
if (f != stdout)
@@ -153,14 +153,14 @@ int main(int argc, char ** argv)
// --- PRIVATE FUNCTION DEFINITIONS --------------------------------------------
-static int _fetcher(void * ctx, uint16_t loc)
+static int _fetcher(void * arg, uint16_t loc)
{
- file_fetcher_ctx_t * fctx = (file_fetcher_ctx_t *) ctx;
+ file_fetcher_t * fet = (file_fetcher_t *) arg;
- if ((size_t) loc >= fctx->len)
+ if ((size_t) loc >= fet->len)
return -LS_NO_MORE_PROGRAM;
else
- return (ls_uchar) fctx->s[(size_t) loc];
+ return (ls_uchar) fet->s[(size_t) loc];
}
static void _usage(char const * argv0, bool short_text)
@@ -178,14 +178,14 @@ static void _usage(char const * argv0, bool short_text)
fprintf(stderr, " -u un-minify\n");
}
-static void _minify(file_fetcher_ctx_t * fctx, FILE * f_out)
+static void _minify(file_fetcher_t * fet, FILE * f_out)
{
- minifier_t min = {.fctx = fctx};
+ minifier_t min = {.fet = fet};
ls_value_t pool[100]; // for labels
- ls_init_ctx(&min.ls, pool, sizeof pool / sizeof pool[0]);
+ ls_init(&min.ls, pool, sizeof pool / sizeof pool[0]);
min.ls.fetcher = _fetcher;
- min.ls.fetcher_ctx = (void *) fctx;
+ min.ls.fetcher_arg = (void *) fet;
if (setjmp(min.ls.error_jmp_buf))
{
@@ -322,23 +322,23 @@ static void _min_keyword(minifier_t * min, ls_token_t tok)
ls_addr_t pc_end;
for (pc_start = min->ls.pc;; pc_start++)
{
- if (pc_start >= min->fctx->len)
+ if (pc_start >= min->fet->len)
break;
- if (!(min->fctx->s[pc_start] == ' '
- || min->fctx->s[pc_start] == '\t'))
+ if (!(min->fet->s[pc_start] == ' '
+ || min->fet->s[pc_start] == '\t'))
break;
}
for (pc_end = pc_start;; pc_end++)
{
- if (pc_end >= min->fctx->len)
+ if (pc_end >= min->fet->len)
break;
- if (min->fctx->s[pc_end] == '\n')
+ if (min->fet->s[pc_end] == '\n')
break;
}
if (un_minify || keep_rems)
{
- fwrite(&min->fctx->s[pc_start],
+ fwrite(&min->fet->s[pc_start],
(size_t)(pc_end - pc_start), 1, min->f_out);
fprintf(min->f_out, "\n");
@@ -379,7 +379,7 @@ static void _min_string(minifier_t * min, ls_token_t tok)
i <= tok.body.string_val.pc_end;
i++)
{
- fprintf(min->f_out, "%c", min->fctx->s[i]);
+ fprintf(min->f_out, "%c", min->fet->s[i]);
}
fprintf(min->f_out, "\"");