예제 #1
0
void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) {
  NanScope();

  if (returned_value->IsArray()) {
    Handle<Array> array = Handle<Array>::Cast(returned_value);

    ctx_w->imports = sass_make_import_list(array->Length());

    for (size_t i = 0; i < array->Length(); ++i) {
      Local<Value> value = array->Get(i);

      if (!value->IsObject())
        continue;

      Local<Object> object = Local<Object>::Cast(value);
      char* path = create_string(object->Get(NanNew<String>("file")));
      char* contents = create_string(object->Get(NanNew<String>("contents")));

      ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
    }
  }
  else if (returned_value->IsObject()) {
    ctx_w->imports = sass_make_import_list(1);
    Local<Object> object = Local<Object>::Cast(returned_value);
    char* path = create_string(object->Get(NanNew<String>("file")));
    char* contents = create_string(object->Get(NanNew<String>("contents")));

    ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
  }
  else {
    ctx_w->imports = sass_make_import_list(1);
    ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0);
  }
}
예제 #2
0
int hw_init_with_config(configuration* c)
{
    int http_listen_address_length;
#ifdef DEBUG
    char route[] = "/stats";
    hw_http_add_route(route, get_server_stats, NULL);
#endif /* DEBUG */
    /* Copy the configuration */
    config = malloc(sizeof(configuration));
    config->http_listen_address = dupstr(c->http_listen_address);
    config->http_listen_port = c->http_listen_port;
    config->thread_count = c->thread_count;
    config->tcp_nodelay = c->tcp_nodelay;
    config->parser = dupstr(c->parser);

    http_v1_0 = create_string("HTTP/1.0 ");
    http_v1_1 = create_string("HTTP/1.1 ");
    server_name = create_string("Server: Haywire/master");

    if (strcmp(config->parser, "http_parser") == 0)
    {
        http_stream_on_read = &http_stream_on_read_http_parser;
    }
    http_server_write_response = &http_server_write_response_single;
    return 0;
}
예제 #3
0
파일: utils.c 프로젝트: pombredanne/tdl
char *read_line(FILE *infile)
{
    char *line, *nline;
    int n, ch, size;

    n = 0;
    size = INITIAL_BUFFER_SIZE;
    line = create_string(size);
    while ((ch = getc(infile)) != '\n' && ch != EOF ) {
        if (n == size) {
            size *= 2;
            nline = create_string(size);
            strncpy(nline, line, n);
            free(line);
            line = nline;
        }
        /* Add this to read windows and unix files */
        /* ie always ignore '\r' */
        if (ch != '\r') line[n++] = ch;
    }
    if (n == 0 && ch == EOF) {
        free(line);
        return (NULL);
    }
    line[n] = '\0';
    nline = create_string(n);
    strcpy(nline, line);
    free(line);
    return (nline);
}
예제 #4
0
static int resolve_addr(server_conf_t *conf, req_t *req, int sd)
{
/*  Resolves the network information associated with the
 *    peer at the other end of the socket connection.
 *  Returns 0 if the remote client address is valid, or -1 on error.
 */
    struct sockaddr_in addr;
    socklen_t addrlen = sizeof(addr);
    char buf[MAX_LINE];
    char *p;
    int gotHostName = 0;

    assert(sd >= 0);

    req->sd = sd;
    if (getpeername(sd, (struct sockaddr *) &addr, &addrlen) < 0)
        log_err(errno, "Unable to get address of remote peer");
    if (!inet_ntop(AF_INET, &addr.sin_addr, buf, sizeof(buf)))
        log_err(errno, "Unable to convert network address into string");
    req->port = ntohs(addr.sin_port);
    req->ip = create_string(buf);
    /*
     *  Attempt to resolve IP address.  If it succeeds, buf contains
     *    host string; if it fails, buf is unchanged with IP addr string.
     *    Either way, copy buf to prevent having to code everything as
     *    (req->host ? req->host : req->ip).
     */
    if ((host_addr4_to_name(&addr.sin_addr, buf, sizeof(buf)))) {
        gotHostName = 1;
        req->fqdn = create_string(buf);
        if ((p = strchr(buf, '.')))
            *p = '\0';
        req->host = create_string(buf);
    }
    else {
        req->fqdn = create_string(buf);
        req->host = create_string(buf);
    }

#if WITH_TCP_WRAPPERS
    /*
     *  Check via TCP-Wrappers.
     */
    if (conf->enableTCPWrap) {
        if (hosts_ctl(CONMAN_DAEMON_NAME,
          (gotHostName ? req->fqdn : STRING_UNKNOWN),
          req->ip, STRING_UNKNOWN) == 0) {
            log_msg(LOG_NOTICE,
                "TCP-Wrappers rejected connection from <%s:%d>",
                req->fqdn, req->port);
            return(-1);
        }
    }
#endif /* WITH_TCP_WRAPPERS */

    return(0);
}
예제 #5
0
void extract_options(Local<Object> options, void* cptr, sass_context_wrapper* ctx_w, bool is_file, bool is_sync) {
  NanScope();

  struct Sass_Context* ctx;

  NanAssignPersistent(ctx_w->result, options->Get(NanNew("result"))->ToObject());

  if (is_file) {
    ctx_w->fctx = (struct Sass_File_Context*) cptr;
    ctx = sass_file_context_get_context(ctx_w->fctx);
  }
  else {
    ctx_w->dctx = (struct Sass_Data_Context*) cptr;
    ctx = sass_data_context_get_context(ctx_w->dctx);
  }

  struct Sass_Options* sass_options = sass_context_get_options(ctx);

  ctx_w->importer_callback = NULL;
  ctx_w->is_sync = is_sync;

  if (!is_sync) {
    ctx_w->request.data = ctx_w;

    // async (callback) style
    Local<Function> success_callback = Local<Function>::Cast(options->Get(NanNew("success")));
    Local<Function> error_callback = Local<Function>::Cast(options->Get(NanNew("error")));

    ctx_w->success_callback = new NanCallback(success_callback);
    ctx_w->error_callback = new NanCallback(error_callback);
  }

  Local<Function> importer_callback = Local<Function>::Cast(options->Get(NanNew("importer")));

  if (importer_callback->IsFunction()) {
    ctx_w->importer_callback = new NanCallback(importer_callback);
    uv_async_init(uv_default_loop(), &ctx_w->async, (uv_async_cb)dispatched_async_uv_callback);
    sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w));
  }

  if(!is_file) {
    sass_option_set_input_path(sass_options, create_string(options->Get(NanNew("file"))));
  }

  sass_option_set_output_path(sass_options, create_string(options->Get(NanNew("outFile"))));
  sass_option_set_image_path(sass_options, create_string(options->Get(NanNew("imagePath"))));
  sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value());
  sass_option_set_is_indented_syntax_src(sass_options, options->Get(NanNew("indentedSyntax"))->BooleanValue());
  sass_option_set_source_comments(sass_options, options->Get(NanNew("comments"))->BooleanValue());
  sass_option_set_omit_source_map_url(sass_options, options->Get(NanNew("omitSourceMapUrl"))->BooleanValue());
  sass_option_set_source_map_embed(sass_options, options->Get(NanNew("sourceMapEmbed"))->BooleanValue());
  sass_option_set_source_map_contents(sass_options, options->Get(NanNew("sourceMapContents"))->BooleanValue());
  sass_option_set_source_map_file(sass_options, create_string(options->Get(NanNew("sourceMap"))));
  sass_option_set_include_path(sass_options, create_string(options->Get(NanNew("paths"))));
  sass_option_set_precision(sass_options, options->Get(NanNew("precision"))->Int32Value());
}
예제 #6
0
파일: sql.c 프로젝트: elechak/blue
static int callback_convert(void *pArg, int argc, char **argv, char **azColName){
    Link array = (Link) pArg;
    Link record = object_create(record_type);
    int i;
    for (i = 0; i < argc; i++){
        //printf("%s    %s\n", azColName[i], argv[i]);
        addAttr(record, create_string(argv[i]) , create_string(azColName[i]));
    }
    array_push(array, record);
    return 0; /* okay */
}
SassImportList CustomImporterBridge::post_process_return_value(v8::Local<v8::Value> returned_value) const {
  SassImportList imports = 0;
  Nan::HandleScope scope;

  if (returned_value->IsArray()) {
    v8::Local<v8::Array> array = returned_value.As<v8::Array>();

    imports = sass_make_import_list(array->Length());

    for (size_t i = 0; i < array->Length(); ++i) {
      v8::Local<v8::Value> value = Nan::Get(array, static_cast<uint32_t>(i)).ToLocalChecked();

      if (!value->IsObject()) {
        auto entry = sass_make_import_entry(0, 0, 0);
        sass_import_set_error(entry, "returned array must only contain object literals", -1, -1);
        continue;
      }

      v8::Local<v8::Object> object = value.As<v8::Object>();

      if (value->IsNativeError()) {
        char* message = create_string(Nan::Get(object, Nan::New<v8::String>("message").ToLocalChecked()));

        imports[i] = sass_make_import_entry(0, 0, 0);

        sass_import_set_error(imports[i], message, -1, -1);
      }
      else {
        imports[i] = get_importer_entry(object);
      }
    }
  }
  else if (returned_value->IsNativeError()) {
    imports = sass_make_import_list(1);
    v8::Local<v8::Object> object = returned_value.As<v8::Object>();
    char* message = create_string(Nan::Get(object, Nan::New<v8::String>("message").ToLocalChecked()));

    imports[0] = sass_make_import_entry(0, 0, 0);

    sass_import_set_error(imports[0], message, -1, -1);
  }
  else if (returned_value->IsObject()) {
    imports = sass_make_import_list(1);
    imports[0] = get_importer_entry(returned_value.As<v8::Object>());
  }

  return imports;
}
예제 #8
0
파일: utils.c 프로젝트: pombredanne/tdl
/******************************************************************************
* concat_3()
* Concatenate 3 strings
*
* Parameters
* ---------
* - 3 strings
*
* Returns
* -------
* - a new string
******************************************************************************/
char *concat_3(char *s1, char *s2, char *s3)
{
    char *s;
    int len1, len2, len3, len;
    int s1_ok = TRUE;
    int s2_ok = TRUE;
    int s3_ok = TRUE;

    if(s1 == NULL){
        len1 = 0;
        s1_ok = FALSE;
    }else {
        len1 = string_len(s1);
    }
    if(s2 == NULL){
        len2 = 0;
        s2_ok = FALSE;
    }else {
        len2 = string_len(s2);
    }
    if(s3 == NULL){
        len3 = 0;
        s3_ok = FALSE;
    }else {
        len3 = string_len(s3);
    }
    len = len1 + len2 + len3;
    if (len == 0) return( (char *)NULL );
    s = create_string(len);
    if (s1_ok) strcpy(s, s1);
    if (s2_ok) strcpy(s + len1, s2);
    if (s3_ok) strcpy(s + len1 + len2, s3);
    return (s);
}
예제 #9
0
파일: mni_io.c 프로젝트: seanm/libminc
VIOAPI Status  mni_input_line(
    FILE     *file,
    STRING   *string )
{
    Status   status;
    char     ch;

    *string = create_string( NULL );

    status = input_character( file, &ch );

    while( status == OK && ch != '\n' )
    {
        if (ch != '\r') {       /* Always ignore carriage returns */
            concat_char_to_string( string, ch );
        }

        status = input_character( file, &ch );
    }

    if( status != OK )
    {
        delete_string( *string );
        *string = NULL;
    }

    return( status );
}
예제 #10
0
파일: block.cpp 프로젝트: ShenTensen/circa
void load_script(Block* block, const char* filename)
{
    // Store the filename
    set_string(block_insert_property(block, s_filename), filename);

    // Read the text file
    circa::Value contents;
    circa_read_file(block->world, filename, &contents);

    if (is_null(&contents)) {
        Value msg;
        set_string(&msg, "File not found: ");
        string_append(&msg, filename);
        Term* term = create_string(block, as_cstring(&msg));
        apply(block, FUNCS.error, TermList(term));
        return;
    }

    parse(block, parse_statement_list, &contents);

    // Make sure the block has a primary output.
    if (get_output_placeholder(block, 0) == NULL)
        append_output_placeholder(block, NULL);

    update_static_error_list(block);

    return;
}
예제 #11
0
파일: block.cpp 프로젝트: ShenTensen/circa
Block* load_script_term(Block* block, const char* filename)
{
    ca_assert(block != NULL);
    Term* filenameTerm = create_string(block, filename);
    Term* includeFunc = apply(block, FUNCS.load_script, TermList(filenameTerm));
    return nested_contents(includeFunc);
}
예제 #12
0
int cdf_generic(char *fname, void* pvApiCtx, struct cdf_descriptor *cdf)
{
    int iErr = 0;
    struct cdf_item const * it;
    char *option;

    CheckRhs(cdf->minrhs, cdf->maxrhs);
    CheckLhs(cdf->minlhs, cdf->maxlhs);
    option = create_string(pvApiCtx, 1);
    for (it = cdf->items; it != cdf->end_item; ++it)
    {
        if (strcmp(option, it->option) == 0)
        {
            /* "which" argument (5th) inferred from position in item list */
            iErr = CdfBase(fname, pvApiCtx, it->inarg, it->oarg, it->shift, it - cdf->items + 1, cdf->fun);
            break;
        }
    }

    destroy_string(option);
    if (it == cdf->end_item)
    {
        /* no target found */
        char *optlist;
        optlist = cdf_options(cdf);
        Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), fname, 1, optlist);
        FREE(optlist);
        return 1;
    }

    return iErr;
}
예제 #13
0
파일: ccache.c 프로젝트: asankah/MKShim
static cc_int32
ccache_get_principal(cc_ccache_t  in_ccache, cc_uint32    in_credentials_version, cc_string_t *out_principal)
{
    struct cc_ccache *c = (struct cc_ccache *)in_ccache;
    krb5_principal princ;
    krb5_error_code ret;
    char *name;
    
    LOG_ENTRY();

    if (out_principal == NULL)
	return ccErrBadParam;
    if (in_credentials_version != cc_credentials_v5)
	return LOG_FAILURE(ccErrBadCredentialsVersion, "wrong version");
    if (c->id == NULL)
	return ccErrInvalidCCache;

    ret = heim_krb5_cc_get_principal(milcontext, c->id, &princ);
    if (ret)
	return LOG_FAILURE(ret, "get principal");
    ret = heim_krb5_unparse_name(milcontext, princ, &name);
    heim_krb5_free_principal(milcontext, princ);
    if (ret)
	return LOG_FAILURE(ret, "unparse name");
    *out_principal = create_string(name);
    free(name);

    return ccNoError;
}
예제 #14
0
int is_serial_dev(const char *dev, const char *cwd, char **path_ref)
{
    char         buf[PATH_MAX];
    int          n;
    struct stat  st;

    assert(dev != NULL);

    if ((dev[0] != '/') && (cwd != NULL)) {
        n = snprintf(buf, sizeof(buf), "%s/%s", cwd, dev);
        if ((n < 0) || (n >= sizeof(buf))) {
            return(0);
        }
        dev = buf;
    }
    if (stat(dev, &st) < 0) {
        return(0);
    }
    if (!S_ISCHR(st.st_mode)) {
        return(0);
    }
    if (path_ref) {
        *path_ref = create_string(dev);
    }
    return(1);
}
예제 #15
0
int is_unixsock_dev(const char *dev, const char *cwd, char **path_ref)
{
    const char *prefix = "unix:";
    int         n;
    char        buf[PATH_MAX];

    assert(dev != NULL);

    if (strncasecmp(dev, prefix, strlen(prefix)) != 0) {
        return(0);
    }
    dev += strlen(prefix);
    if (dev[0] == '\0') {
        return(0);
    }
    if ((dev[0] != '/') && (cwd != NULL)) {
        n = snprintf(buf, sizeof(buf), "%s/%s", cwd, dev);
        if ((n < 0) || (n >= sizeof(buf))) {
            return(0);
        }
        dev = buf;
    }
    if (path_ref) {
        *path_ref = create_string(dev);
    }
    return(1);
}
예제 #16
0
static int query_consoles_via_regex(
    server_conf_t *conf, req_t *req, List matches)
{
/*  Match request patterns against console names using regular expressions.
 */
    char *p;
    ListIterator i;
    char buf[MAX_SOCK_LINE];
    int rc;
    regex_t rex;
    regmatch_t match;
    obj_t *obj;

    /*  An empty list for the QUERY command matches all consoles.
     */
    if (list_is_empty(req->consoles)) {
        p = create_string(".*");
        list_append(req->consoles, p);
    }

    /*  Combine console patterns via alternation to create single regex.
     */
    i = list_iterator_create(req->consoles);
    strlcpy(buf, list_next(i), sizeof(buf));
    while ((p = list_next(i))) {
        strlcat(buf, "|", sizeof(buf));
        strlcat(buf, p, sizeof(buf));
    }
    list_iterator_destroy(i);

    /*  Initialize 'rex' to silence "uninitialized use" warnings.
     */
    memset(&rex, 0, sizeof(rex));

    /*  Compile regex for searching server's console objs.
     */
    rc = regcomp(&rex, buf, REG_EXTENDED | REG_ICASE);
    if (rc != 0) {
        if (regerror(rc, &rex, buf, sizeof(buf)) > sizeof(buf))
            log_msg(LOG_WARNING, "Got regerror() buffer overrun");
        regfree(&rex);
        send_rsp(req, CONMAN_ERR_BAD_REGEX, buf);
        return(-1);
    }

    /*  Search objs for console names matching console patterns in the request.
     */
    i = list_iterator_create(conf->objs);
    while ((obj = list_next(i))) {
        if (!is_console_obj(obj))
            continue;
        if (!regexec(&rex, obj->name, 1, &match, 0)
          && (match.rm_so == 0) && (match.rm_eo == strlen(obj->name)))
            list_append(matches, obj);
    }
    list_iterator_destroy(i);
    regfree(&rex);
    return(0);
}
예제 #17
0
파일: secarg.c 프로젝트: AltSysrq/tgl
/* @builtin-bind { 'u', builtin_secondary_argument }, */
int builtin_secondary_argument(interpreter* interp) {
  byte c;
  string s;
  unsigned i;
  stack_elt* stack;

  ++interp->ip;
  if (!is_ip_valid(interp)) {
    print_error("Secondary argument specifier expected");
    return 0;
  }

  if (interp->ux >= NUM_SECONDARY_ARGS) {
    print_error("Too many secondary arguments");
    return 0;
  }

  c = curr(interp);
  switch (c) {
  case '%':
    if (!(s = stack_pop(interp))) UNDERFLOW;
    break;

  case ' ':
    s = NULL;
    break;

  case '.':
    i = 0;
    for (stack = interp->stack; stack; stack = stack->next)
      ++i;

    s = int_to_string(i);
    break;

  case '+':
  case '-':
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    if (!builtin_number(interp)) return 0;
    s = stack_pop(interp);
    break;

  default:
    s = create_string(&c, (&c)+1);
    break;
  }

  interp->u[interp->ux++] = s;
  return 1;
}
예제 #18
0
파일: utils.c 프로젝트: pombredanne/tdl
/******************************************************************************
* char_to_string()
* Convert a char to a string
*
* Parameters
* ---------
* - single character
*
* Returns
* -------
* - a new string
*
******************************************************************************/
char *char_to_string(char ch)
{
    char *result;
    result = create_string(1);
    result[0] = ch;
    result[1] = '\0';
    return (result);
}
예제 #19
0
svn_string_t *
svn_string_createv(apr_pool_t *pool, const char *fmt, va_list ap)
{
  char *data = apr_pvsprintf(pool, fmt, ap);

  /* wrap an svn_string_t around the new data */
  return create_string(data, strlen(data), pool);
}
예제 #20
0
int hw_init_with_config(configuration* c)
{
    int http_listen_address_length;
#ifdef DEBUG
    char route[] = "/stats";
    hw_http_add_route(route, get_server_stats, NULL);
#endif /* DEBUG */
    /* Copy the configuration */
    config = malloc(sizeof(configuration));
    config->http_listen_address = dupstr(c->http_listen_address);
    config->http_listen_port = c->http_listen_port;
    
    http_v1_0 = create_string("HTTP/1.0 ");
    http_v1_1 = create_string("HTTP/1.1 ");
    server_name = create_string("Server: Haywire/master");
    return 0;
}
예제 #21
0
static int recv_greeting(req_t *req)
{
/*  Performs the initial handshake with the client
 *    (SOMEDAY including authentication & encryption, if needed).
 *  Returns 0 if the greeting is valid, or -1 on error.
 */
    int n;
    char buf[MAX_SOCK_LINE];
    Lex l;
    int done = 0;
    int tok;

    assert(req->sd >= 0);

    if ((n = read_line(req->sd, buf, sizeof(buf))) < 0) {
        log_msg(LOG_NOTICE, "Unable to read greeting from <%s:%d>: %s",
            req->fqdn, req->port, strerror(errno));
        return(-1);
    }
    else if (n == 0) {
        log_msg(LOG_NOTICE, "Connection terminated by <%s:%d>",
            req->fqdn, req->port);
        return(-1);
    }

    DPRINTF((5, "Received greeting: %s", buf));

    l = lex_create(buf, proto_strs);
    while (!done) {
        tok = lex_next(l);
        switch(tok) {
        case CONMAN_TOK_HELLO:
            parse_greeting(l, req);
            break;
        case LEX_EOF:
        case LEX_EOL:
            done = 1;
            break;
        default:
            break;
        }
    }
    lex_destroy(l);

    /*  Validate greeting.
     */
    if (!req->user) {
        req->user = create_string("unknown");
        send_rsp(req, CONMAN_ERR_BAD_REQUEST,
            "Invalid greeting: no user specified");
        return(-1);
    }

    /*  Send response to greeting.
     */
    return(send_rsp(req, CONMAN_ERR_NONE, NULL));
}
예제 #22
0
파일: utils.c 프로젝트: pombredanne/tdl
/******************************************************************************
* copy_string()
* Copy a string
*
* Parameters
* ---------
* - a string
*
* Returns
* -------
* - a new string
*
* Notes
* -----
* copy_string copies the string s into dynamically allocated
* storage and returns the new string.
******************************************************************************/
char *copy_string(char *s)
{
    char *newstr;
    //if (s == NULL) print_error("NULL string passed to copy_string");
    if (s == NULL) return (NULL);
    newstr = create_string(string_len(s));
    strcpy(newstr, s);
    return (newstr);
}
예제 #23
0
SYMBOL *read_symbol(MPL *mpl)
{     SYMBOL *sym;
      insist(is_symbol(mpl));
      if (is_number(mpl))
         sym = create_symbol_num(mpl, mpl->value);
      else
         sym = create_symbol_str(mpl, create_string(mpl, mpl->image));
      get_token(mpl /* <symbol> */);
      return sym;
}
예제 #24
0
static char *create_no_debug_exp(void)
{
    int uid = getuid();
    int euid = geteuid();
    char *exp;

    exp = create_string("debug called for uid=%d euid=%d, "
			"output disabled\n",
			uid, euid);
    return exp;
}
예제 #25
0
void test__type_get_varg_value__cstr(void** state)
{
    _typeinfo_t t_info;
    string_t* pstr_result = create_string();
    _test__get_type(&t_info, "char*");
    t_info._t_style = _TYPE_C_BUILTIN;
    string_init(pstr_result);
    _test__type_get_varg_value__stub(pstr_result, &t_info, "linux");
    assert_true(strcmp(string_c_str(pstr_result), "linux") == 0);
    string_destroy(pstr_result);
}
예제 #26
0
파일: sax2.c 프로젝트: OviDanielB/WebServer
static devicedef_t* create_devicedef(parse_context_t* context, int nb_attributes, const xmlChar** attributes) {

	const xmlChar* id = get_attribute(context, nb_attributes, attributes, ATTR_ID);
	const xmlChar* user_agent = get_attribute(context, nb_attributes, attributes, ATTR_USER_AGENT);
	const xmlChar* fallback = get_attribute(context, nb_attributes, attributes, ATTR_FALL_BACK);
	const xmlChar* actual_device_root = get_attribute(context, nb_attributes, attributes, ATTR_ACTUAL_DEVICE_ROOT);

	devicedef_t* devicedef = malloc(sizeof(devicedef_t));
	if(devicedef==NULL) {
		error(1, errno, "error allocating device");
	}
	hashmap_options_t caps_opts = {400, .75f};
	devicedef->capabilities = hashmap_init(&string_eq, &string_hash, &caps_opts);


	if(!id || xmlStrlen(id)==0) {
		error(2,0,"The device id must be != null");
	}
	else {
		devicedef->id = create_string(id, context);
	}

	if(!user_agent || xmlStrlen(user_agent)==0) {
		devicedef->user_agent = NULL;
	}
	else {
		devicedef->user_agent = create_string(user_agent, context);
	}

	if(xmlStrEqual(fallback, BAD_CAST("root")) || xmlStrlen(fallback)<=0) {
		devicedef->fall_back = NULL;
	}
	else {
		devicedef->fall_back = create_string(fallback, context);
	}
	devicedef->actual_device_root = xmlStrEqual(actual_device_root, BAD_CAST("true"));

	return devicedef;


}
Sass_Import* CustomImporterBridge::get_importer_entry(const v8::Local<v8::Object>& object) const {
  auto returned_file = Nan::Get(object, Nan::New<v8::String>("file").ToLocalChecked());
  auto returned_contents = Nan::Get(object, Nan::New<v8::String>("contents").ToLocalChecked()).ToLocalChecked();
  auto returned_map = Nan::Get(object, Nan::New<v8::String>("map").ToLocalChecked());
  Sass_Import *err;

  if ((err = check_returned_string(returned_file, "returned value of `file` must be a string")))
    return err;

  if ((err = check_returned_string(returned_contents, "returned value of `contents` must be a string")))
    return err;

  if ((err = check_returned_string(returned_map, "returned value of `returned_map` must be a string")))
    return err;

  char* path = create_string(returned_file);
  char* contents = create_string(returned_contents);
  char* srcmap = create_string(returned_map);

  return sass_make_import_entry(path, contents, srcmap);
}
예제 #28
0
파일: utils.c 프로젝트: pombredanne/tdl
/******************************************************************************
* to_upper
* Convert a string to upper
*
* Parameters
* ---------
* - a string
*
* Returns
* -------
* This function returns a new string with all
* alphabetic characters converted to upper case.
******************************************************************************/
char *to_upper(char *s)
{
    char *result;
    int i;

    if (s == NULL) {
        print_error("NULL string passed to to_upper");
    }
    result = create_string(string_len(s));
    for (i = 0; s[i] != '\0'; i++) result[i] = toupper(s[i]);
    result[i] = '\0';
    return (result);
}
예제 #29
0
  Sass_Value* Error::construct(const std::vector<v8::Local<v8::Value>> raw_val, Sass_Value **out) {
    char const* value = "";

    if (raw_val.size() >= 1) {
      if (!raw_val[0]->IsString()) {
        return fail("Argument should be a string.", out);
      }

      value = create_string(raw_val[0]);
    }

    return *out = sass_make_error(value);
  }
예제 #30
0
int main(int argc, char* argv[])
{
    string_t* pstr_hello = create_string();
    string_t* pstr_s = create_string();
    string_iterator_t it_pos;

    if(pstr_hello == NULL || pstr_s == NULL)
    {
        return -1;
    }

    string_init_cstr(pstr_hello, "Hello, how are you?");
    string_init_copy_range(pstr_s,
        string_begin(pstr_hello), string_end(pstr_hello));

    for(it_pos = string_begin(pstr_s);
        !iterator_equal(it_pos, string_end(pstr_s));
        it_pos = iterator_next(it_pos))
    {
        printf("%c", *(char*)iterator_get_pointer(it_pos));
    }
    printf("\n");

    algo_reverse(string_begin(pstr_s), string_end(pstr_s));
    printf("reverse: %s\n", string_c_str(pstr_s));

    algo_sort(string_begin(pstr_s), string_end(pstr_s));
    printf("ordered: %s\n", string_c_str(pstr_s));

    string_erase_range(pstr_s,
        algo_unique(string_begin(pstr_s), string_end(pstr_s)),
        string_end(pstr_s));
    printf("uniqued: %s\n", string_c_str(pstr_s));

    string_destroy(pstr_hello);
    string_destroy(pstr_s);

    return 0;
}