Example #1
0
/* main -- Output any command line arguments as comments
        and then minify the input.
*/
extern int
main(int argc, char* argv[])
{
    int i;
    for (i = 1; i < argc; i += 1) {
        fprintf(stdout, "// %s\n", argv[i]);
    }
    jsmin();
    return 0;
}
Example #2
0
/* main -- Output any command line arguments as comments
        and then minify the input.
*/
extern int
main(int argc, char* argv[])
{
    int i;
    for (i = 1; i < argc; i += 1) {
        fprintf(stdout, "// %s\n", argv[i]);
    }
    theString = readStdin();
    preprocess(theString);
    jsmin();
    return 0;
}
static ngx_int_t 
ngx_http_minify_buf_in_memory(ngx_buf_t *buf,ngx_http_request_t *r)
{
    ngx_buf_t   *b = NULL, *dst = NULL, *min_dst = NULL;
    ngx_int_t size;

    size = buf->end - buf->start;

    dst = buf;
    dst->end[0] = 0;
    
    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }
    
    b->start = ngx_palloc(r->pool, size);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size;
    b->temporary = 1;
    
    min_dst = b;
    if (ngx_strcmp(r->headers_out.content_type.data,
                   ngx_http_minify_default_types[0].data) 
        == 0)
    {
        jsmin(dst,min_dst);

    } else if (ngx_strcmp(r->headers_out.content_type.data, 
                          ngx_http_minify_default_types[1].data) 
               == 0)
    {
        cssmin(dst,min_dst);

    } else {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    buf->start = min_dst->start;     
    buf->pos = min_dst->pos;
    buf->last = min_dst->last;
    buf->end = min_dst->end;
    buf->memory = 1;
    buf->in_file = 0;
    

    return NGX_OK;

}
Example #4
0
static VALUE minify(VALUE self, VALUE _in_s) {
    jsmin_struct s;

    char *in_s = StringValueCStr(_in_s);
    long in_length = strlen(in_s);
    char out_s[in_length + 1];

#ifdef RUBY_19
    VALUE prev_encoding = rb_funcall(_in_s, rb_intern("encoding"), 0);
#endif

    s.in = in_s;
    s.out = out_s;
    jsmin(&s);

#ifdef RUBY_19
    return rb_funcall(rb_str_new2(out_s + 1), rb_intern("force_encoding"), 1, prev_encoding);
#else
    return rb_str_new2(out_s + 1);
#endif
}
Example #5
0
extern int JSMinCmd(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
	int res;
	tcljsminCtx *ctx;
	jsminCtx *jctx;

	if (objc != 2) {
		Tcl_WrongNumArgs(interp, 1, objv, "Usage: jsmin string");
		return TCL_ERROR;
	}

	ctx=ckalloc(sizeof(tcljsminCtx));

	ctx->in = Tcl_GetStringFromObj(objv[1], &ctx->len);
	ctx->pos = 0;

	Tcl_DStringInit(&ctx->out);
	Tcl_DStringInit(&ctx->err);

	jctx=jsminInit(ctx, tcljsminInput, tcljsminOutput, tcljsminError);

	switch (jsmin(jctx)) {
		case JSMIN_ERROR: 
			Tcl_DStringResult(interp, &ctx->err);
			res=TCL_ERROR;
			break;
		case JSMIN_OK:
			Tcl_DStringResult(interp, &ctx->out);
			res=TCL_OK;
			break;
	}

	jsminCleanup(jctx);

	Tcl_DStringFree(&ctx->out);
	Tcl_DStringFree(&ctx->err);
	ckfree(ctx);
	return res;
}
static ngx_int_t 
ngx_http_minify_buf(ngx_buf_t *buf,ngx_http_request_t *r,
                    ngx_open_file_info_t *of)
{
    ngx_buf_t   *b = NULL, *dst = NULL, *min_dst = NULL;
    ngx_int_t    size;
    ngx_file_t  *src_file ;
    ssize_t n;

    src_file =  ngx_pcalloc(r->pool, sizeof(ngx_file_t));
    if (src_file == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    src_file->fd = of->fd;
    src_file->name = buf->file->name;
    src_file->log = r->connection->log;
    src_file->directio = of->is_directio;

    size = of->size;

    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    b->start = ngx_palloc(r->pool, size+1);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size ;
    b->temporary = 1;

    dst = b;

    #if (NGX_HAVE_FILE_AIO)
    
         ngx_output_chain_ctx_t       *ctx;
         ctx = ngx_http_get_module_ctx(r, ngx_http_minify_filter_module);
         if (ctx->aio_handler) {
             n = ngx_file_aio_read(src_file, dst->pos, (size_t) size, 0, 
                                   ctx->pool);

             if (n == NGX_AGAIN) {
             ctx->aio_handler(ctx, src_file);
             return NGX_AGAIN;
             }
    
         } else {
             n = ngx_read_file(src_file, dst->pos, (size_t) size, 0);
         }
    #else
    
        ngx_read_file(src_file, dst->pos, (size_t) size, 0);
    #endif

    dst->end[0] = 0;
    
    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }
    
    b->start = ngx_palloc(r->pool, size);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size;
    b->temporary = 1;
    
    min_dst = b;
    if (ngx_strcmp(r->headers_out.content_type.data,
                   ngx_http_minify_default_types[0].data) 
        == 0)
    {
        jsmin(dst,min_dst);

    } else if (ngx_strcmp(r->headers_out.content_type.data, 
                          ngx_http_minify_default_types[1].data) 
               == 0)
    {
        cssmin(dst,min_dst);

    } else {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    buf->start = min_dst->start;     
    buf->pos = min_dst->pos;
    buf->last = min_dst->last;
    buf->end = min_dst->end;
    buf->memory = 1;
    buf->in_file = 0;
    

    return NGX_OK;

}