Пример #1
0
static void command_find_frame_props_cache_client(void * x) {
    CommandFindFrameInfo * args = (CommandFindFrameInfo *)x;
    Channel * c = cache_channel();
    Context * ctx = NULL;
    StackTracingInfo * info = NULL;
    int err = 0;

    ctx = id2ctx(args->id);
    if (ctx == NULL) err = ERR_INV_CONTEXT;
    else if (get_stack_tracing_info(ctx, args->addr, &info) < 0) err = errno;

    cache_exit();

    write_stringz(&c->out, "R");
    write_stringz(&c->out, args->token);
    write_errno(&c->out, err);

    if (args->props) {
        unsigned cnt = 0;
        write_stream(&c->out, '{');

        if (info != NULL && info->size) {
            json_write_string(&c->out, "CodeAddr");
            write_stream(&c->out, ':');
            json_write_uint64(&c->out, info->addr);
            write_stream(&c->out, ',');
            json_write_string(&c->out, "CodeSize");
            write_stream(&c->out, ':');
            json_write_uint64(&c->out, info->size);
            cnt++;
        }

        if (info != NULL && info->fp != NULL) {
            if (cnt++ > 0) write_stream(&c->out, ',');
            json_write_string(&c->out, "FP");
            write_stream(&c->out, ':');
            write_commands(&c->out, ctx, info->fp->cmds, info->fp->cmds_cnt);
        }

        if (info != NULL && info->regs != NULL) {
            int i;
            if (cnt++ > 0) write_stream(&c->out, ',');
            json_write_string(&c->out, "Regs");
            write_stream(&c->out, ':');
            write_stream(&c->out, '{');
            for (i = 0; i < info->reg_cnt; i++) {
                if (i > 0) write_stream(&c->out, ',');
                json_write_string(&c->out, register2id(ctx, STACK_NO_FRAME, info->regs[i]->reg));
                write_stream(&c->out, ':');
                write_commands(&c->out, ctx, info->regs[i]->cmds, info->regs[i]->cmds_cnt);
            }
            write_stream(&c->out, '}');
        }

        if (info != NULL && info->subs != NULL) {
            int i;
            if (cnt++ > 0) write_stream(&c->out, ',');
            json_write_string(&c->out, "Inlined");
            write_stream(&c->out, ':');
            write_stream(&c->out, '[');
            for (i = 0; i < info->sub_cnt; i++) {
                if (i > 0) write_stream(&c->out, ',');
                write_inlined_subroutine_info(&c->out, info->subs[i]);
            }
            write_stream(&c->out, ']');
        }

        write_stream(&c->out, '}');
        write_stream(&c->out, 0);
    }
    else {
        /* Deprecated, use findFrameProps */

        json_write_uint64(&c->out, info ? info->addr : 0);
        write_stream(&c->out, 0);
        json_write_uint64(&c->out, info ? info->size : 0);
        write_stream(&c->out, 0);

        if (info == NULL || info->fp == NULL) write_string(&c->out, "null");
        else write_commands(&c->out, ctx, info->fp->cmds, info->fp->cmds_cnt);
        write_stream(&c->out, 0);

        if (info != NULL && info->regs != NULL) {
            int i;
            write_stream(&c->out, '{');
            for (i = 0; i < info->reg_cnt; i++) {
                if (i > 0) write_stream(&c->out, ',');
                json_write_string(&c->out, register2id(ctx, STACK_NO_FRAME, info->regs[i]->reg));
                write_stream(&c->out, ':');
                write_commands(&c->out, ctx, info->regs[i]->cmds, info->regs[i]->cmds_cnt);
            }
            write_stream(&c->out, '}');
        }
        else {
            write_string(&c->out, "null");
        }
        write_stream(&c->out, 0);
    }

    write_stream(&c->out, MARKER_EOM);
}
Пример #2
0
static void 
write_sref(FILE *fob, mxArray *data, double uu_to_dbu)
{
   mxArray *internal, *propfield, *pxy;
   double *pdxy=NULL;
   int32_t xy[2];
   int mxy=0;
   int k,nlen;
   element_t sref;


   /* internal structure */
   if ( !get_field_ptr(data, "internal", &internal) )
      mexErrMsgTxt("gds_write_element (sref) :  missing internal data field.");
   memcpy(&sref, (int32_t *)mxGetData(internal), sizeof(element_t));

   /* number of sref locations contained in compound element */
   if ( get_field_ptr(data, "xy", &pxy) ) {
      mxy = mxGetM(pxy);
      pdxy = (double *)mxGetData(pxy);
   }
   else   
      mexErrMsgTxt("gds_write_element (sref) :  missing or empty xy field.");

   /* 
    * write out the individual sref elements 
    */
   for (k=0; k<mxy; k++) {

      /* SREF */
      write_record_hdr(fob, SREF, 0);

      /* ELFLAGS */
      if ( sref.has & HAS_ELFLAGS ) {
	 write_record_hdr(fob, ELFLAGS, sizeof(uint16_t));
	 write_word(fob, sref.elflags);
      }

      /* PLEX */
      if ( sref.has & HAS_PLEX ) {
	 write_record_hdr(fob, PLEX, sizeof(int32_t));
	 write_int(fob, sref.plex);
      }

      /* SNAME */
      nlen = strlen(sref.sname);
      if ( !nlen )
	 mexErrMsgTxt("gds_write_element (sref) :  name of referenced structure missing.");
      if (nlen % 2)
	 nlen += 1;
      if (nlen > 32)
	 mexErrMsgTxt("gds_write_element (sref) :  structure name must have <= 32 chars.");
      write_record_hdr(fob, SNAME, nlen);
      write_string(fob, sref.sname, nlen);

      /* STRANS */
      if ( sref.has & HAS_STRANS ) {
	 write_record_hdr(fob, STRANS, sizeof(uint16_t));
	 write_word(fob, sref.strans.flags);
	 if ( sref.has & HAS_MAG && sref.strans.mag != 1.0) {
	    write_record_hdr(fob, MAG, 8);
	    write_real8(fob, sref.strans.mag);
	 }
	 if ( sref.has & HAS_ANGLE && sref.strans.angle != 0.0) {
	    write_record_hdr(fob, ANGLE, 8);
	    write_real8(fob, sref.strans.angle);
	 }
      }

      /* XY */
      xy[0] = floor(0.5 + pdxy[k]     * uu_to_dbu);
      xy[1] = floor(0.5 + pdxy[k+mxy] * uu_to_dbu);
      write_record_hdr(fob, XY, 2*sizeof(int32_t));
      write_int_n(fob, xy, 2);
   
      /* Property */
      if ( get_field_ptr(data, "prop", &propfield) )
	 write_property(fob, propfield);

      /* ENDEL */
      write_record_hdr(fob, ENDEL, 0);
   }
} 
Пример #3
0
static void 
write_aref(FILE *fob, mxArray *data, double uu_to_dbu)
{
   mxArray *field, *propfield, *internal;
   double *pd;
   int32_t xy[6];
   int mxy,nxy=0,nlen;
   element_t aref;


   /* internal structure */
   if ( !get_field_ptr(data, "internal", &internal) )
      mexErrMsgTxt("gds_write_element (aref) :  missing internal data field.");
   memcpy(&aref, (int32_t *)mxGetData(internal), sizeof(element_t));

   /* AREF */
   write_record_hdr(fob, AREF, 0);

   /* ELFLAGS */
   if ( aref.has & HAS_ELFLAGS ) {
      write_record_hdr(fob, ELFLAGS, sizeof(uint16_t));
      write_word(fob, aref.elflags);
   }

   /* PLEX */
   if ( aref.has & HAS_PLEX ) {
      write_record_hdr(fob, PLEX, sizeof(int32_t));
      write_int(fob, aref.plex);
   }

   /* SNAME */   
   nlen = strlen(aref.sname);
   if ( !nlen )
      mexErrMsgTxt("gds_write_element (aref) :  name of referenced structure missing.");
   if (nlen % 2)
      nlen += 1;
   if (nlen > 32)
      mexErrMsgTxt("gds_write_element (aref) :  structure name must have <= 32 chars.");
   write_record_hdr(fob, SNAME, nlen);
   write_string(fob, aref.sname, nlen);

   /* STRANS */
   if ( aref.has & HAS_STRANS ) {
      write_record_hdr(fob, STRANS, sizeof(uint16_t));
      write_word(fob, aref.strans.flags);
      if ( aref.has & HAS_MAG && aref.strans.mag != 1.0) {
	 write_record_hdr(fob, MAG, 8);
	 write_real8(fob, aref.strans.mag);
      }
      if ( aref.has & HAS_ANGLE && aref.strans.angle != 0.0) {
	 write_record_hdr(fob, ANGLE, 8);
	 write_real8(fob, aref.strans.angle);
      }
   }

   /* COLROW */
   if ( !aref.nrow )
      mexErrMsgTxt("gds_write_element (aref) :  number of rows is 0; must be > 0.");
   if ( !aref.ncol )
      mexErrMsgTxt("gds_write_element (aref) :  number of columns is 0; must be > 0.");
   write_record_hdr(fob, COLROW, 2*sizeof(uint16_t));
   write_word(fob, aref.ncol);
   write_word(fob, aref.nrow);
   
   /* XY */
   if ( get_field_ptr(data, "xy", &field) ) {
      pd = (double *)mxGetData(field);
      mxy = mxGetM(field);
      nxy = mxGetN(field);
      if ( (mxy != 3) || (nxy != 2) )
	 mexErrMsgTxt("gds_write_element (aref) :  xy must be 3x2 matrix.");
      scale_trans(pd, xy, mxy, uu_to_dbu);
      write_record_hdr(fob, XY, mxy*nxy*sizeof(int32_t));
      write_int_n(fob, xy, 6);
   }
   else   
      mexErrMsgTxt("gds_write_element (aref) :  missing or empty xy field.");

   /* Property */
   if ( get_field_ptr(data, "prop", &propfield) )
      write_property(fob, propfield);

   /* ENDEL */
   write_record_hdr(fob, ENDEL, 0);
} 
Пример #4
0
std::wstring json_spirit::write_formatted( const wmValue&  value )
{
    return write_string( value, true );
}
Пример #5
0
pfs::error_code ubjson_ostream<OStreamType, JsonType>::write_object (json_type const & j)
{
    _os << UBJSON_CHAR_OBJECT_BEGIN;

    bool use_count_optimization = ((_flags & count_optimized) && !j.empty());
    bool is_special_case = false;

    // If a type is specified, a count must also be specified.
    // A type cannot be specified by itself.
    bool use_type_optimization  = ((_flags & type_optimized) && use_count_optimization);

    // Additional checks for type optimization
    if (use_type_optimization) {

        // This call is safe. Array is not empty as checked before
        int8_t first_prefix = prefix(*j.cbegin());
        use_type_optimization = pfs::all_of(j.cbegin(), j.cend(), compare_prefix(first_prefix));

        if (use_type_optimization) {
            _os << UBJSON_CHAR_TYPE;
            _os << first_prefix;

            // Check special cases
            if (first_prefix == UBJSON_CHAR_NOOP
                    || first_prefix == UBJSON_CHAR_NULL
                    || first_prefix == UBJSON_CHAR_TRUE
                    || first_prefix == UBJSON_CHAR_FALSE) {
                is_special_case = true;
            }
        }
    }

    if (use_count_optimization) {
        _os << UBJSON_CHAR_SIZE;
        write_integer(static_cast<typename json_type::integer_type>(j.size()), true);
    }

    typename json_type::const_iterator first = j.cbegin();
    typename json_type::const_iterator last = j.cend();

    if (is_special_case) {
        for (; first != last; ++first) {
            // The [S] (string) marker is omitted from each of the names in the
            // name/value pairings inside the object. The JSON specification does
            // not allow non-string name values, therefore the [S] marker
            // is redundant and must not be used.
           write_string(first.key(), false);
        }
    } else {
        for (; first != last; ++first) {
            write_string(first.key(), false);
            write_json(*first, !use_type_optimization);
        }
    }

    // If a count is specified the container must not specify an end-marker.
    if (!use_count_optimization)
        _os << UBJSON_CHAR_OBJECT_END;

    return pfs::error_code();
}
Пример #6
0
static inline void
append_key(struct bson *bs, int type, const char *key, size_t sz) {
	write_byte(bs, type);
	write_string(bs, key, sz);
}
Пример #7
0
/* ====================================================================
 * Here's the real content handler.
 * ==================================================================== */
static int content_handler(request_rec *r)
{
    long length;
    wkcfg *cfg;
    WFILE* env_dict = NULL;
    int i;
    char msgbuf[MAX_STRING_LEN];
    int conn_attempt = 0;
    WFILE* whole_dict = NULL;
    WFILE* int_dict = NULL;
    const char *value;
    const char *key;
    array_header *hdr_arr;
    table_entry *elts;

    cfg = ap_get_module_config(r->per_dir_config, &webkit_module);
    if (cfg == NULL) {
        log_debug("No cfg", r);
        cfg = (wkcfg*)wk_create_dir_config(r->pool, "/");
    }

    env_dict = setup_WFILE(r);
    whole_dict = setup_WFILE(r);
    int_dict = setup_WFILE(r);

    if (env_dict == NULL || whole_dict == NULL) {
        log_error("Couldn't allocate Python data structures", r->server);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    ap_add_common_vars(r);
    ap_add_cgi_vars(r); /* not included in the common_vars above */

    /* Build the environment dictionary */

    hdr_arr = ap_table_elts(r->subprocess_env);
    elts = (table_entry *)hdr_arr->elts;

    /* start dictionary */
    w_byte(TYPE_DICT, env_dict);

    for (i = 0; i < hdr_arr->nelts; ++i) {
        if (!elts[i].key)
            continue;
        key = elts[i].key;
        value = ap_table_get(r->subprocess_env, elts[i].key);
        write_string(key, env_dict);
        if (value != NULL)
            write_string(value, env_dict);
        else
            w_byte(TYPE_NONE, env_dict);
    }
    hdr_arr = cfg->passheaders;
    if (hdr_arr) {
        char **headers = (char **)hdr_arr->elts;
        for (i = 0; i < hdr_arr->nelts; i++) {
            key = headers[i];
            value = ap_table_get(r->headers_in, key);
            if (value && *value) {
                write_string(key, env_dict);
                write_string(value, env_dict);
            }
        }
    }

#ifdef SECURITY_HOLE_PASS_AUTHORIZATION
    /* Ordinarily Apache only makes the username available to CGI scripts,
    keeping the password secret. It can be configured to make the complete
    credential details available, but only by completely rebuilding the
    server with SECURITY_HOLE_PASS_AUTHORIZATION set (enabling this feature
    is considered a security risk). By setting the same constant, you can
    have mod_webkit pass the authorization information to WebKit instead.
    (suggested by Maximillian Dornseif 2003-10-27) */
    key = "Authorization";
    value = ap_table_get(r->headers_in, key);
    if (value && *value) {
      write_string("X-HTTP_AUTHORIZATION", env_dict);
      write_string(value, env_dict);
    }
#endif

    w_byte(TYPE_NULL, env_dict);
    /* end dictionary */
    log_debug("Built env dictionary", r);

    /* We can start building the full dictionary now */
    w_byte(TYPE_DICT, whole_dict);
    write_string("format", whole_dict); /* key */
    write_string("CGI", whole_dict); /* value */
    write_string("time", whole_dict); /* key */
    w_byte(TYPE_INT, whole_dict); /* value */
    /* patch from Ken Lalonde to make the time entry useful */
    w_long((long)r->request_time, whole_dict); /* value */

    write_string("environ", whole_dict); /* key */

    /* copy env_dict into whole_dict */
    insert_data(whole_dict, env_dict);

    /* that should be it */
    /* end dictionary */
    w_byte(TYPE_NULL, whole_dict);

    length = whole_dict->ptr - whole_dict->str;

    write_integer((int)length, int_dict);

    /* now we try to send it */
    for (conn_attempt = 1; conn_attempt <= cfg->retryattempts; conn_attempt++) {
        int result = transact_with_app_server(r, cfg, whole_dict, int_dict, length);
        if (result == 0) {
            return OK;
        } else if (result == 2) {
            log_error("error transacting with app server -- giving up.", r->server);
            return HTTP_INTERNAL_SERVER_ERROR;
        }
        sprintf(msgbuf,
            "Couldn't connect to AppServer, attempt %i of %i",
            conn_attempt, cfg->retryattempts);
        log_error(msgbuf, r->server);
        sleep(cfg->retrydelay);
    }
    log_error("error transacting with app server -- giving up.", r->server);
    return HTTP_INTERNAL_SERVER_ERROR;
}
Пример #8
0
void Core::handleMessage(const Message& msg, MessageSession* session){
	write_string(session->target().bare() + " -> " + msg.body());
	// to debug
	//print_session_id(session->target().bare());
}
Пример #9
0
int serialize_tree(struct kowhai_node_t** desc, void** data, char* target_buffer, size_t target_size, int level, void* get_name_param, kowhai_get_symbol_name_t get_name, int in_union, int* largest_data_field)
{
    int target_offset = 0;
    struct kowhai_node_t* node;
    int i, chars;
    char* node_end_str;

    while (1)
    {
        node = *desc;

        if (node->type == KOW_BRANCH_END)
            return target_offset;

        // indent to current level using tabs
        chars = add_indent(&target_buffer, &target_size, &target_offset, level);
        if (chars < 0)
            return chars;

        //
        // write node
        //

        switch (node->type)
        {
            case KOW_BRANCH_START:
            case KOW_BRANCH_U_START:
            {
                int node_is_union = node->type == KOW_BRANCH_U_START;
                int largest_child_data_field = 0;
                void* initial_data = *data;
                // write header
                chars = add_header(&target_buffer, &target_size, &target_offset, node, get_name_param, get_name);
                if (chars < 0)
                    return chars;
                if (node->count > 1)
                {
                    struct kowhai_node_t* initial_node = *desc;
                    // write array identifier
                    chars = add_string(&target_buffer, &target_size, &target_offset, ", \""ARRAY"\": [\n");
                    if (chars < 0)
                    return chars;
                    for (i = 0; i < node->count; i++)
                    {
                        // set descriptor to initial node at the branch array
                        *desc = initial_node;
                        (*desc) += 1;
                        // indent to current level using tab
                        chars = add_indent(&target_buffer, &target_size, &target_offset, level + 1);
                        if (chars < 0)
                            return chars;
                        // write branch children start
                        chars = add_string(&target_buffer, &target_size, &target_offset, "[\n");
                        if (chars < 0)
                            return chars;
                        // write branch children
                        chars = serialize_tree(desc, data, target_buffer, target_size, level + 1, get_name_param, get_name, node_is_union, &largest_child_data_field);
                        if (chars < 0)
                            return chars;
                        target_offset += chars;
                        target_buffer += chars;
                        target_size -= chars;
                        // increment data pointer if node is a union
                        if (node_is_union)
                        {
                            *data = (char*)initial_data + largest_child_data_field;
                            initial_data = *data;
                        }
                        // indent to current level using tab
                        chars = add_indent(&target_buffer, &target_size, &target_offset, level + 1);
                        if (chars < 0)
                            return chars;
                        // write branch children end
                        chars = add_string(&target_buffer, &target_size, &target_offset, "]");
                        if (chars < 0)
                            return chars;
                        if (i < node->count - 1)
                        {
                            chars = add_string(&target_buffer, &target_size, &target_offset, ",\n");
                            if (chars < 0)
                                return chars;
                        }
                        else
                        {
                            chars = add_string(&target_buffer, &target_size, &target_offset, "\n");
                            if (chars < 0)
                                return chars;
                        }
                    }
                }
                else
                {
                    // write children identifier
                    chars = add_string(&target_buffer, &target_size, &target_offset, ", \""CHILDREN"\": [\n");
                    if (chars < 0)
                        return chars;
                    // write branch children
                    (*desc) += 1;
                    chars = serialize_tree(desc, data, target_buffer, target_size, level + 1, get_name_param, get_name, node_is_union, &largest_child_data_field);
                    if (chars < 0)
                        return chars;
                    target_offset += chars;
                    target_buffer += chars;
                    target_size -= chars;
                    // increment data pointer if node is a union
                    if (node_is_union)
                        *data = (char*)initial_data + largest_child_data_field;
                }
                // indent to current level using tab
                chars = add_indent(&target_buffer, &target_size, &target_offset, level);
                if (chars < 0)
                    return chars;
                // write node end
                if (level == 0 || (*desc)[1].type == KOW_BRANCH_END)
                    node_end_str = "]}\n";
                else
                    node_end_str = "]},\n";
                chars = add_string(&target_buffer, &target_size, &target_offset, node_end_str);
                if (chars < 0)
                    return chars;
                break;
            }
            default:
            {
                int value_size = kowhai_get_node_type_size(node->type);
                // write header
                chars = add_header(&target_buffer, &target_size, &target_offset, node, get_name_param, get_name);
                if (chars < 0)
                    return chars;
                // write value identifier
                chars = add_string(&target_buffer, &target_size, &target_offset, ", \""VALUE"\": ");
                if (chars < 0)
                    return chars;
                // write value/s
                if (node->type == KOW_CHAR && node->count > 1 && str_printable((char *)*data, node->count))
                {
                    // special string case
                    chars = write_string(target_buffer, target_size, "\"%.*s\"", node->count, (char*)*data);
                    if (chars >= 0)
                    {
                        target_buffer += chars;
                        target_size -= chars;
                        target_offset += chars;
                    }
                    else
                        return chars;
                    // increment data pointer
                    if (!in_union)
                        *data = (char*)*data + value_size * node->count;
                    else if (value_size * node->count > *largest_data_field)
                        *largest_data_field = value_size * node->count;
                }
                else if (node->count > 1)
                {
                    // write start bracket
                    chars = add_string(&target_buffer, &target_size, &target_offset, "[");
                    if (chars < 0)
                        return chars;
                    for (i = 0; i < node->count; i++)
                    {
                        // write leaf node array item value
                        chars = add_value(&target_buffer, &target_size, &target_offset, node->type, (char*)*data + i * value_size);
                        if (chars < 0)
                            return chars;
                        // write comma if there is another array item
                        if (i < node->count - 1)
                        {
                            chars = add_string(&target_buffer, &target_size, &target_offset, ", ");
                            if (chars < 0)
                                return chars;
                        }
                    }
                    // increment data pointer
                    if (!in_union)
                        *data = (char*)*data + value_size * node->count;
                    else if (value_size * node->count > *largest_data_field)
                        *largest_data_field = value_size * node->count;
                    // write end bracket
                    chars = add_string(&target_buffer, &target_size, &target_offset, "]");
                    if (chars < 0)
                        return chars;
                }
                else
                {
                    // write leaf node value
                    chars = add_value(&target_buffer, &target_size, &target_offset, node->type, *data);
                    if (chars < 0)
                        return chars;
                    // increment data pointer
                    if (!in_union)
                        *data = (char*)*data + value_size;
                    else if (value_size > *largest_data_field)
                        *largest_data_field = value_size;
                }
                // write node end
                if (level == 0 || node[1].type == KOW_BRANCH_END)
                    node_end_str = " }\n";
                else
                    node_end_str = " },\n";
                chars = add_string(&target_buffer, &target_size, &target_offset, node_end_str);
                if (chars < 0)
                    return chars;
                break;
            }
        }

        if (level == 0)
            return target_offset;

        (*desc) += 1;
    }
}
Пример #10
0
void Core::onDisconnect(ConnectionError e){
	connected=false;
	write_string("Disconnected!");
}
Пример #11
0
void Core::handleRosterPresence(const RosterItem &item, const std::string &resource, Presence::PresenceType presence, const std::string &msg){
		write_string("You have received a status update of: " + item.jid() + " (" + msg + ")");
		// some bugs with item.jid(), check caracters issues
		update_roster_choice();
}		
Пример #12
0
bool Core::onTLSConnect(const CertInfo& info){
	connected=true;
	write_string("Connected in TLS to the XMPP server!");
	return true;	
}
Пример #13
0
void Core::onConnect(){
	connected=true;
	write_string("Connected to the XMPP server!");
}
Пример #14
0
// to debug
void Core::print_session_id(const string bare){
	write_string(ptr_cpclient->get_session_from_bare(bare)->threadID());	
}
Пример #15
0
void filecache_update(TARGET *t)
{
	MD5SUM blobmd5sum;
	int haveblobmd5sum = 0;
	const char *cachedname;
	const char *blobname;
	int cacheerror;

	if (!t->filecache_generate)
		return;

	/* If the buildmd5sum is empty, then the file doesn't exist. */
	cacheerror = ismd5empty(t->buildmd5sum);
	if (cacheerror)
		return;

	haveblobmd5sum = 0;
	cachedname = filecache_getfilename(t, t->buildmd5sum, NULL);
	if (!cachedname)
		return;

	/* Search for the appropriate .link file that matches the target. */
	haveblobmd5sum = filecache_findlink(cachedname, blobmd5sum);

	/* If we weren't able to determine the target md5sum, do it now. */
	if (!haveblobmd5sum)
	{
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		LIST *md5callback;

		pushsettings( t->settings );
		md5callback = var_get( "MD5CALLBACK" );
		popsettings( t->settings );

		if ( md5callback )
		{
			luahelper_md5callback(t->boundname, blobmd5sum, md5callback->string);
		}
		else
		{
#endif
			md5file(t->boundname, blobmd5sum);
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		}
#endif
		memcpy(t->contentmd5sum, blobmd5sum, sizeof(MD5SUM));
		if (ismd5empty(t->contentmd5sum))
			return;
	}

	{
		/* Is the blob already there? */
		time_t blobtime;
		blobname = filecache_getfilename(t, blobmd5sum, ".blob");
		if (file_time(blobname, &blobtime) == -1)
		{
			time_t blobpartialtime;
			const char *blobpartialname;

			if(DEBUG_MD5HASH)
				printf("Caching %s as %s\n", t->name, cachedname);
			else
				printf("Caching %s\n", t->name);

			/* Write the new .blob to the cache. */
			blobpartialname = filecache_getfilename(t, blobmd5sum, ".blob.partial");
			if (file_time(blobpartialname, &blobpartialtime) == -1)
			{
				if (copyfile(blobpartialname, t->boundname, &blobmd5sum) == 0  ||
					rename(blobpartialname, blobname) != 0)
				{
					printf("** Unable to write %s to cache.\n", t->name, cachedname);
					filecache_disable(t);
					return;
				}
			}
		}
	}

	/* Write the new .link file to the cache. */
	{
		FILE *file;
		BUFFER linknamebuff;
		buffer_init(&linknamebuff);
		buffer_addstring(&linknamebuff, cachedname, strlen(cachedname));
		buffer_addchar(&linknamebuff, '-');
		buffer_addstring(&linknamebuff, md5tostring(blobmd5sum), 32);
		buffer_addstring(&linknamebuff, ".link", 5);
		buffer_addchar(&linknamebuff, 0);

		file_mkdir(buffer_ptr(&linknamebuff));
		file = fopen(buffer_ptr(&linknamebuff), "wb");
		if (file)
		{
			write_md5sum(file, blobmd5sum);
			write_string(file, t->name);
			fclose(file);
		}

		buffer_free(&linknamebuff);
	}
}
Пример #16
0
int add_value(char** dest, size_t* dest_size, int* current_offset, uint16_t node_type, void* data)
{
    int chars;
    union any_type_t val;

    // on some systems vsnprintf requires the src buffer to be aligned
    // properly, since data is possibly packed to make the tree tidier
    // the memcpy below gets our data into an aligned var
    memcpy(&val, data, kowhai_get_node_type_size(node_type));

    switch (node_type)
    {
        case KOW_CHAR:
            if (val.c < 32 || val.c >= 127)
                chars = write_string(*dest, *dest_size, "%d", val.c);
            else
                chars = write_string(*dest, *dest_size, "%c", val.c);
            break;
        case KOW_INT8:
            chars = write_string(*dest, *dest_size, "%d", val.i8);
            break;
        case KOW_INT16:
            chars = write_string(*dest, *dest_size, "%d", val.i16);
            break;
        case KOW_INT32:
            chars = write_string(*dest, *dest_size, "%d", val.i32);
            break;
        case KOW_INT64:
            chars = write_string(*dest, *dest_size, "%ld", val.i64);
            break;
        case KOW_UINT8:
            chars = write_string(*dest, *dest_size, "%d", val.ui8);
            break;
        case KOW_UINT16:
            chars = write_string(*dest, *dest_size, "%d", val.ui16);
            break;
        case KOW_UINT32:
            chars = write_string(*dest, *dest_size, "%d", val.ui32);
            break;
        case KOW_UINT64:
            chars = write_string(*dest, *dest_size, "%ld", val.ui64);
            break;
        case KOW_FLOAT:
            chars = write_string(*dest, *dest_size, "%.17g", val.f);
            break;
        case KOW_DOUBLE:
            chars = write_string(*dest, *dest_size, "%.17lg", val.d);
            break;
        default:
            return -1;
    }
    if (chars >= 0)
    {
        *dest += chars;
        *dest_size -= chars;
        *current_offset += chars;
    }
    return chars;
}
Пример #17
0
void
	hcache_writefile(HCACHEFILE *file)
{
	FILE	*f;
	HCACHEDATA	*c;
	int		header_count = 0;
	int		maxage;

	if( !file  ||  !file->dirty  ||  !file->cachefilename )
		return;

	file_mkdir(file->cachefilename);

	if( ! (f = fopen( file->cachefilename, "wb" ) ) )
		return;

	maxage = cache_maxage();

	/* print out the version */
	fprintf( f, "@%s@\n", CACHE_FILE_VERSION );

	for( c = file->hcachelist; c; c = c->next ) {
		LIST	*l;

		if( maxage == 0 )
			c->age = 0;
		else if( c->age > maxage )
			continue;

		write_string( f, c->boundname );
		write_int( f, (int)c->time );
		write_int( f, c->age );

#ifdef OPT_BUILTIN_MD5CACHE_EXT
		write_int( f, (int)c->mtime );
		write_md5sum( f, c->rulemd5sum );
		write_md5sum( f, c->contentmd5sum );
#endif

		write_int( f, list_length( c->includes ) );
		for( l = c->includes; l; l = list_next( l ) ) {
			write_string( f, l->string );
		}

		write_int( f, list_length( c->hdrscan ) );
		for( l = c->hdrscan; l; l = list_next( l ) ) {
			write_string( f, l->string );
		}

		fputc( '!', f );
		fputc( '\n', f );
		++header_count;
	}

	if( DEBUG_HEADER )
		printf( "hcache written to %s.	 %d dependencies, %.0f%% hit rate\n",
		file->cachefilename, header_count,
		queries ? 100.0 * hits / queries : 0 );

	fclose( f );
}
Пример #18
0
void
SExprFileWriter::write_path(const char* name, const Pathname& path)
{
  write_string(name, path.get_raw_path());
}
Пример #19
0
int save_game (char* s, char* d)
{
	SINT16 i;
	struct image_stack_element* ptr = image_stack;
	FILE* f = fopen (s, "wb");

	if(!f)
		return err_BadFileOpen;

#ifdef DREAMCAST
	write_vmu_header(f, d);
#endif

	write_bytes (f, strSig, 8);
	write_string (f, d);

	write_uint8 (f, (UINT8)SAVEGAME_VERSION);
	write_uint8 (f, (UINT8)game.state);
	/* game.name */
	write_string (f, game.id);
	/* game.crc */

	for (i = 0; i < MAX_FLAGS; i++)
		write_uint8 (f, game.flags[i]);
	for (i = 0; i < MAX_VARS; i++)
		write_uint8 (f, game.vars[i]);

	write_sint16 (f, (SINT8)game.horizon);
	write_sint16 (f, (SINT16)game.line_status);
	write_sint16 (f, (SINT16)game.line_user_input);
	write_sint16 (f, (SINT16)game.line_min_print);
	/* game.cursor_pos */
	/* game.input_buffer */
	/* game.echo_buffer */
	/* game.keypress */
	write_sint16 (f, (SINT16)game.input_mode);
	write_sint16 (f, (SINT16)game.lognum);

	write_sint16 (f, (SINT16)game.player_control);
	write_sint16 (f, (SINT16)game.quit_prog_now);
	write_sint16 (f, (SINT16)game.status_line);
	write_sint16 (f, (SINT16)game.clock_enabled);
	write_sint16 (f, (SINT16)game.exit_all_logics);
	write_sint16 (f, (SINT16)game.picture_shown);
	write_sint16 (f, (SINT16)game.has_prompt);
	write_sint16 (f, (SINT16)game.game_flags);

	/* Reversed to keep compatibility with old savegames */
	write_sint16 (f, (SINT16)!game.input_enabled);

	for (i = 0; i < _HEIGHT; i++)
		write_uint8 (f, game.pri_table[i]);

	/* game.msg_box_ticks */
	/* game.block */
	/* game.window */
	/* game.has_window */

	write_sint16 (f, (SINT16)game.gfx_mode);
	write_uint8 (f, game.cursor_char);
	write_sint16 (f, (SINT16)game.color_fg);
	write_sint16 (f, (SINT16)game.color_bg);

	/* game.hires (#ifdef USE_HIRES) */
	/* game.sbuf */
	/* game.ego_words */
	/* game.num_ego_words */

	write_sint16 (f, (SINT16)game.num_objects);
	for (i = 0; i < (SINT16)game.num_objects; i++)
		write_sint16 (f, (SINT16)object_get_location(i));

	/* game.ev_keyp */
	for (i = 0; i < MAX_STRINGS; i++)
		write_string (f, game.strings[i]);

	/* record info about loaded resources */
	for (i = 0; i < MAX_DIRS; i++) {
		write_uint8 (f, game.dir_logic[i].flags);
		write_sint16 (f, (SINT16)game.logics[i].sIP);
		write_sint16 (f, (SINT16)game.logics[i].cIP);
	}
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_pic[i].flags);
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_view[i].flags);
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_sound[i].flags);

	/* game.pictures */
	/* game.logics */
	/* game.views */
	/* game.sounds */

	for(i = 0; i < MAX_VIEWTABLE; i++) {
		struct vt_entry* v = &game.view_table[i];

		write_uint8(f, v->step_time);
		write_uint8(f, v->step_time_count);
		write_uint8(f, v->entry);
		write_sint16(f, v->x_pos);
		write_sint16(f, v->y_pos);
		write_uint8(f, v->current_view);

		/* v->view_data */

		write_uint8(f, v->current_loop);
		write_uint8(f, v->num_loops);

		/* v->loop_data */

		write_uint8(f, v->current_cel);
		write_uint8(f, v->num_cels);

		/* v->cel_data */
		/* v->cel_data_2 */
		
		write_sint16(f, v->x_pos2);
		write_sint16(f, v->y_pos2);

		/* v->s */

		write_sint16(f, v->x_size);
		write_sint16(f, v->y_size);
		write_uint8(f, v->step_size);
		write_uint8(f, v->cycle_time);
		write_uint8(f, v->cycle_time_count);
		write_uint8(f, v->direction);

		write_uint8(f, v->motion);
		write_uint8(f, v->cycle);
		write_uint8(f, v->priority);

		write_uint16(f, v->flags);
		
		write_uint8(f, v->parm1);
		write_uint8(f, v->parm2);
		write_uint8(f, v->parm3);
		write_uint8(f, v->parm4);
	}

	/* Save image stack */
	
	for (i = 0; i < image_stack_pointer; i++) {
		ptr = &image_stack[i];
		write_uint8 (f, ptr->type);
		write_sint16 (f, ptr->parm1);
		write_sint16 (f, ptr->parm2);
		write_sint16 (f, ptr->parm3);
		write_sint16 (f, ptr->parm4);
		write_sint16 (f, ptr->parm5);
		write_sint16 (f, ptr->parm6);
		write_sint16 (f, ptr->parm7);
	}
	write_uint8(f, 0);

	fclose(f);

	return err_OK;
}
Пример #20
0
static void
add_pool_entry (MonoCompile *cfg, ConstantPoolEntry *entry)
{
	int *cp_id= (int *) mono_mempool_alloc0 (cfg->mempool, sizeof (int));
	*cp_id = cfg->gdump_ctx->next_cp_id;
	g_hash_table_insert (cfg->gdump_ctx->constant_pool, entry, cp_id);
	write_byte (cfg, POOL_NEW);
	write_short (cfg, cfg->gdump_ctx->next_cp_id++);
	switch (entry->pt) {
		case PT_STRING:
			write_byte (cfg, POOL_STRING);
			write_string (cfg, (char *) entry->data);
			break;
		case PT_METHOD: {
			MonoMethod *method = (MonoMethod *) entry->data;
			write_byte (cfg, POOL_METHOD);
			write_pool (cfg, create_cp_entry (cfg, (void *) method->klass, PT_KLASS));
			write_pool (cfg, create_cp_entry (cfg, (void *) method->name, PT_STRING));
			write_pool (cfg, create_cp_entry (cfg, (void *) method->signature, PT_SIGNATURE));
			write_int (cfg, (int) method->flags);
			write_int (cfg, -1); // don't transmit bytecode.
			break;
		}
		case PT_KLASS: {
			MonoClass *klass = (MonoClass *) entry->data;
			write_byte (cfg, POOL_KLASS);
			write_string (cfg, klass->name);
			write_byte (cfg, KLASS);
			break;
		}
		case PT_SIGNATURE: {
			write_byte (cfg, POOL_SIGNATURE);
			MonoMethodSignature *sig = (MonoMethodSignature *) entry->data;
			write_short (cfg, sig->param_count);
			for (int i = 0; i < sig->param_count; i++) {
				GString *sbuf = g_string_new (NULL);
				mono_type_get_desc (sbuf, sig->params [i], TRUE);
				write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING));
				g_string_free (sbuf, TRUE);
			}
			GString *sbuf = g_string_new (NULL);
			mono_type_get_desc (sbuf, sig->ret, TRUE);
			write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING));
			g_string_free (sbuf, TRUE);
			break;
		}
		case PT_OPTYPE: {
			MonoInst *insn = (MonoInst *) entry->data;
			write_byte (cfg, POOL_NODE_CLASS);

			write_string (cfg, mono_inst_name (insn->opcode));
			GString *insndesc = mono_print_ins_index_strbuf (-1, insn);
			int len = strnlen (insndesc->str, 0x2000);
#define CUTOFF 40
			if (len > CUTOFF) {
				insndesc->str[CUTOFF] = '\0';
				insndesc->str[CUTOFF - 1] = '.';
				insndesc->str[CUTOFF - 2] = '.';
			}
			write_string (cfg, insndesc->str);
			if (len > CUTOFF)
				insndesc->str[CUTOFF] = ' ';
			g_string_free (insndesc, TRUE);

			// one predecessor
			write_short (cfg, 1);
			write_byte (cfg, 0);
			write_pool (cfg, create_cp_entry (cfg, (void *) "predecessor", PT_STRING));
			write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_INPUTTYPE));

			// make NUM_SUCCESSOR successor edges, not everyone will be used.
#define NUM_SUCCESSOR 5
			write_short (cfg, NUM_SUCCESSOR);
			for (int i = 0; i < NUM_SUCCESSOR; i++) {
				char *str = g_strdup ("successor1");
				str[9] = '0' + i;
				write_byte (cfg, 0);
				write_pool (cfg, create_cp_entry (cfg, (void *) str, PT_STRING));
			}

			break;
		}
		case PT_INPUTTYPE: {
			write_byte (cfg, POOL_ENUM);
			write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_ENUMKLASS));
			write_int (cfg, 0);
			break;
		}
		case PT_ENUMKLASS: {
			write_byte (cfg, POOL_KLASS);
			write_string (cfg, "InputType");
			write_byte (cfg, ENUM_KLASS);
			write_int (cfg, 1);
			write_pool (cfg, create_cp_entry (cfg, (void *) "fixed", PT_STRING));
			break;
		}
	}
}
Пример #21
0
std::wstring json_spirit::write( const wmValue&  value )
{
    return write_string( value, false );
}
Пример #22
0
std::string JSONRPCReply(const json_spirit::Value& result, const json_spirit::Value& error, const json_spirit::Value& id)
{
    json_spirit::Object reply = JSONRPCReplyObj(result, error, id);
    return write_string(json_spirit::Value(reply), false) + "\n";
}
Пример #23
0
/*
 * Encode "val" into "gap".
 * Return FAIL or OK.
 */
    static int
json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
{
    char_u	numbuf[NUMBUFLEN];
    char_u	*res;
    list_T	*l;
    dict_T	*d;

    switch (val->v_type)
    {
	case VAR_SPECIAL:
	    switch (val->vval.v_number)
	    {
		case VVAL_FALSE: ga_concat(gap, (char_u *)"false"); break;
		case VVAL_TRUE: ga_concat(gap, (char_u *)"true"); break;
		case VVAL_NONE: if ((options & JSON_JS) != 0
					     && (options & JSON_NO_NONE) == 0)
				    /* empty item */
				    break;
				/* FALLTHROUGH */
		case VVAL_NULL: ga_concat(gap, (char_u *)"null"); break;
	    }
	    break;

	case VAR_NUMBER:
	    vim_snprintf((char *)numbuf, NUMBUFLEN, "%ld",
						    (long)val->vval.v_number);
	    ga_concat(gap, numbuf);
	    break;

	case VAR_STRING:
	    res = val->vval.v_string;
	    write_string(gap, res);
	    break;

	case VAR_FUNC:
	case VAR_JOB:
	case VAR_CHANNEL:
	    /* no JSON equivalent TODO: better error */
	    EMSG(_(e_invarg));
	    return FAIL;

	case VAR_LIST:
	    l = val->vval.v_list;
	    if (l == NULL)
		ga_concat(gap, (char_u *)"null");
	    else
	    {
		if (l->lv_copyID == copyID)
		    ga_concat(gap, (char_u *)"[]");
		else
		{
		    listitem_T	*li;

		    l->lv_copyID = copyID;
		    ga_append(gap, '[');
		    for (li = l->lv_first; li != NULL && !got_int; )
		    {
			if (json_encode_item(gap, &li->li_tv, copyID,
						   options & JSON_JS) == FAIL)
			    return FAIL;
			if ((options & JSON_JS)
				&& li->li_next == NULL
				&& li->li_tv.v_type == VAR_SPECIAL
				&& li->li_tv.vval.v_number == VVAL_NONE)
			    /* add an extra comma if the last item is v:none */
			    ga_append(gap, ',');
			li = li->li_next;
			if (li != NULL)
			    ga_append(gap, ',');
		    }
		    ga_append(gap, ']');
		    l->lv_copyID = 0;
		}
	    }
	    break;

	case VAR_DICT:
	    d = val->vval.v_dict;
	    if (d == NULL)
		ga_concat(gap, (char_u *)"null");
	    else
	    {
		if (d->dv_copyID == copyID)
		    ga_concat(gap, (char_u *)"{}");
		else
		{
		    int		first = TRUE;
		    int		todo = (int)d->dv_hashtab.ht_used;
		    hashitem_T	*hi;

		    d->dv_copyID = copyID;
		    ga_append(gap, '{');

		    for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int;
									 ++hi)
			if (!HASHITEM_EMPTY(hi))
			{
			    --todo;
			    if (first)
				first = FALSE;
			    else
				ga_append(gap, ',');
			    if ((options & JSON_JS)
						 && is_simple_key(hi->hi_key))
				ga_concat(gap, hi->hi_key);
			    else
				write_string(gap, hi->hi_key);
			    ga_append(gap, ':');
			    if (json_encode_item(gap, &dict_lookup(hi)->di_tv,
				      copyID, options | JSON_NO_NONE) == FAIL)
				return FAIL;
			}
		    ga_append(gap, '}');
		    d->dv_copyID = 0;
		}
	    }
	    break;

	case VAR_FLOAT:
#ifdef FEAT_FLOAT
	    vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", val->vval.v_float);
	    ga_concat(gap, numbuf);
	    break;
#endif
	case VAR_UNKNOWN:
	    EMSG2(_(e_intern2), "json_encode_item()");
	    return FAIL;
    }
    return OK;
}
Пример #24
0
 JsonWriter& key(const char *key) {
     begin_token(KEY);
     write_string(key);
     os << ':';
     return *this;
 }
Пример #25
0
void print_string(mcstring *string) {
  write_string(stdout, string);
}
Пример #26
0
 JsonWriter& value(const char *str) {
     begin_token(VALUE);
     write_string(str);
     return *this;
 }
Пример #27
0
static void 
write_compound_sref(FILE *fob, mxArray *data, double uu_to_dbu)
{
   mxArray *internal, *propfield, *pxy;
   double *pdxy=NULL;
   int ncxy;      /* number of compound xy records */
   int mrem;      /* remainder in last record */
   int mxy=0;
   int k,nlen;
   element_t sref;


   /* internal structure */
   if ( !get_field_ptr(data, "internal", &internal) )
      mexErrMsgTxt("gds_write_element (sref) :  missing internal data field.");
   memcpy(&sref, (int32_t *)mxGetData(internal), sizeof(element_t));

   /* number of sref locations contained in compound element */
   if ( get_field_ptr(data, "xy", &pxy) ) {
      mxy = mxGetM(pxy);
      pdxy = (double *)mxGetData(pxy);
   }
   else   
      mexErrMsgTxt("gds_write_element (sref) :  missing or empty xy field.");

   /* 
    * write sref elements as non-standard compound element
    */
   /* SREF */
   write_record_hdr(fob, SREF, 0);

   /* ELFLAGS */
   if ( sref.has & HAS_ELFLAGS ) {
      write_record_hdr(fob, ELFLAGS, sizeof(uint16_t));
      write_word(fob, sref.elflags);
   }

   /* PLEX */
   if ( sref.has & HAS_PLEX ) {
      write_record_hdr(fob, PLEX, sizeof(int32_t));
      write_int(fob, sref.plex);
   }

   /* SNAME */
   nlen = strlen(sref.sname);
   if ( !nlen )
      mexErrMsgTxt("gds_write_element (sref) :  name of referenced structure missing.");
   if (nlen % 2)
      nlen += 1;
   if (nlen > 32)
      mexErrMsgTxt("gds_write_element (sref) :  structure name must have <= 32 chars.");
   write_record_hdr(fob, SNAME, nlen);
   write_string(fob, sref.sname, nlen);

   /* STRANS */
   if ( sref.has & HAS_STRANS ) {
      write_record_hdr(fob, STRANS, sizeof(uint16_t));
      write_word(fob, sref.strans.flags);
      if ( sref.has & HAS_MAG && sref.strans.mag != 1.0) {
	 write_record_hdr(fob, MAG, 8);
	 write_real8(fob, sref.strans.mag);
      }
      if ( sref.has & HAS_ANGLE && sref.strans.angle != 0.0) {
	 write_record_hdr(fob, ANGLE, 8);
	 write_real8(fob, sref.strans.angle);
      }
   }

   /* multiple large XY records */
   ncxy = mxy / MAXVERTEXNUM;
   mrem = mxy % MAXVERTEXNUM;
   for (k=0; k<ncxy; k++) {
      scale_trans(pdxy+2*k*MAXVERTEXNUM, xybuf, MAXVERTEXNUM, uu_to_dbu);
      write_record_hdr(fob, XY, (uint16_t)(MAXVERTEXNUM*2*sizeof(int32_t)));
      write_int_n(fob, xybuf, 2*MAXVERTEXNUM);
   }
   if (mrem) {
      scale_trans(pdxy+2*ncxy*MAXVERTEXNUM, xybuf, mrem, uu_to_dbu);
      write_record_hdr(fob, XY, 2*mrem*sizeof(int32_t));
      write_int_n(fob, xybuf, 2*mrem);
   }

   /* Property */
   if ( get_field_ptr(data, "prop", &propfield) )
      write_property(fob, propfield);

   /* ENDEL */
   write_record_hdr(fob, ENDEL, 0);
} 
Пример #28
0
static int st_printf(char *s,int fl,char *format,unsigned int *vargs)
{
	char itos_buf[ITOS_BSIZE],*chp;
/*	unsigned int *vargs;*/
	int varg_index=0,i,start_i,temp_char;	

	/*asm("mov %%ebp,%0":"=m" (vargs):);
	vargs+=4;*/

	s[0]=0;

	for(i=0;format[i];)
	{
		if(format[i]=='%')
		{
			switch(format[i+1]){
			case 'u':
				itos_ud(vargs[varg_index],itos_buf);
				
				if(fl<0) kstrcat(s,itos_buf);
				else write_string(fl,itos_buf);
				
				varg_index++;
				break;
			case 'x':
				itos_ux(vargs[varg_index],itos_buf);

				if(fl<0) kstrcat(s,itos_buf);
				else write_string(fl,itos_buf);

				varg_index++;
				break;
			case 's':
				chp=(char*)vargs[varg_index];
				
				if(fl<0) kstrcat(s,chp);
				else write_string(fl,chp);				

				varg_index++;

				break;				
			default:return -1;
			}
			i+=2;
		}

		start_i=i;
		for(;format[i] && format[i]!='%';i++);

		if(i!=start_i)
		{
			if(fl<0)
			{
				temp_char=format[i];
				format[i]=0;
				kstrcat(s,format+start_i);
				format[i]=temp_char;
			}
			else write(fl,format+start_i,i-start_i);				
		}
	}
	return 0;
}
Пример #29
0
static void 
write_text(FILE *fob, mxArray *data, double uu_to_dbu)
{
   mxArray *field, *propfield, *internal;
   double *pd;
   int32_t xy[2];
   int tlen;
   char txt[TXTLEN];
   element_t text;


   /* internal structure */
   if ( !get_field_ptr(data, "internal", &internal) )
      mexErrMsgTxt("gds_write_element (text) :  missing internal data field.");
   memcpy(&text, (int32_t *)mxGetData(internal), sizeof(element_t));

   /* TEXT */
   write_record_hdr(fob, TEXT, 0);

   /* ELFLAGS */
   if ( text.has & HAS_ELFLAGS ) {
      write_record_hdr(fob, ELFLAGS, sizeof(uint16_t));
      write_word(fob, text.elflags);
   }

   /* PLEX */
   if ( text.has & HAS_PLEX ) {
      write_record_hdr(fob, PLEX, sizeof(int32_t));
      write_int(fob, text.plex);
   }

   /* LAYER */
   write_record_hdr(fob, LAYER, sizeof(uint16_t));
   write_word(fob, text.layer);

   /* TEXTTYPE */
   write_record_hdr(fob, TEXTTYPE, sizeof(uint16_t));
   write_word(fob, text.dtype);

   /* PRESENTATION */
   if ( text.has & HAS_PRESTN ) {
      write_record_hdr(fob, PRESENTATION, sizeof(uint16_t));
      write_word(fob, text.present);
   }	

   /* PATHTYPE */
   if ( text.has & HAS_PTYPE ) {
      write_record_hdr(fob, PATHTYPE, sizeof(uint16_t));
      write_word(fob, text.ptype);
   }
   
   /* WIDTH */
   if ( text.has & HAS_WIDTH ) {
      write_record_hdr(fob, WIDTH, sizeof(int32_t));
      write_int(fob, text.width);
   }

   /* STRANS */
   if ( text.has & HAS_STRANS ) {
      write_record_hdr(fob, STRANS, sizeof(uint16_t));
      write_word(fob, text.strans.flags);
      if ( text.has & HAS_MAG && text.strans.mag != 1.0) {
	 write_record_hdr(fob, MAG, 8);
	 write_real8(fob, text.strans.mag);
      }
      if ( text.has & HAS_ANGLE && text.strans.angle != 0.0) {
	 write_record_hdr(fob, ANGLE, 8);
	 write_real8(fob, text.strans.angle);
      }
   }

   /* XY */
   if ( get_field_ptr(data, "xy", &field) ) {
      pd = (double *)mxGetData(field);
      scale_trans(pd, xy, 1, uu_to_dbu);
      write_record_hdr(fob, XY, 2*sizeof(int32_t));
      write_int_n(fob, xy, 2);
   }
   else   
      mexErrMsgTxt("gds_write_element (text) :  missing or empty xy field.");

   /* STRING */   
   if ( get_field_ptr(data, "text", &field) ) {
      mxGetString(field, txt, TXTLEN);
      tlen = strlen(txt);
      if (tlen % 2)
	 tlen += 1;
      if (tlen > 512)
	 mexErrMsgTxt("gds_write_element (text) :  text must have <= 512 chars.");
      write_record_hdr(fob, STRING, tlen);
      write_string(fob, txt, tlen);
   }
   else   
      mexErrMsgTxt("gds_write_element (text) :  missing text field.");

   /* Property */
   if ( get_field_ptr(data, "prop", &propfield) )
      write_property(fob, propfield);

   /* ENDEL */
   write_record_hdr(fob, ENDEL, 0);
}
Пример #30
0
static void write_commands(OutputStream * out, Context * ctx, LocationExpressionCommand * cmds, unsigned cnt) {
    if (cmds != NULL) {
        unsigned i;
        write_stream(out, '[');
        for (i = 0; i < cnt; i++) {
            LocationExpressionCommand * cmd = cmds + i;
            if (i > 0) write_stream(out, ',');
            json_write_long(out, cmd->cmd);
            switch (cmd->cmd) {
            case SFT_CMD_NUMBER:
                write_stream(out, ',');
                json_write_int64(out, cmd->args.num);
                break;
            case SFT_CMD_ARG:
            case SFT_CMD_SET_ARG:
                write_stream(out, ',');
                json_write_ulong(out, cmd->args.arg_no);
                break;
            case SFT_CMD_RD_REG:
            case SFT_CMD_WR_REG:
                write_stream(out, ',');
                json_write_string(out, register2id(ctx, STACK_NO_FRAME, cmd->args.reg));
                break;
            case SFT_CMD_RD_MEM:
            case SFT_CMD_WR_MEM:
            case SFT_CMD_LOAD:
                write_stream(out, ',');
                json_write_ulong(out, cmd->args.mem.size);
                write_stream(out, ',');
                json_write_boolean(out, cmd->args.mem.big_endian);
                break;
            case SFT_CMD_LOCATION:
                write_stream(out, ',');
                json_write_binary(out, cmd->args.loc.code_addr, cmd->args.loc.code_size);
                write_stream(out, ',');
                write_stream(out, '{');
                json_write_string(out, "Machine");
                write_stream(out, ':');
                json_write_long(out, cmd->args.loc.reg_id_scope.machine);
                write_stream(out, ',');
                if (cmd->args.loc.reg_id_scope.os_abi) {
                    json_write_string(out, "ABI");
                    write_stream(out, ':');
                    json_write_long(out, cmd->args.loc.reg_id_scope.os_abi);
                    write_stream(out, ',');
                }
                if (cmd->args.loc.reg_id_scope.fp_abi) {
                    json_write_string(out, "FPABI");
                    write_stream(out, ':');
                    json_write_long(out, cmd->args.loc.reg_id_scope.fp_abi);
                    write_stream(out, ',');
                }
                json_write_string(out, "ELF64");
                write_stream(out, ':');
                json_write_boolean(out, cmd->args.loc.reg_id_scope.elf64);
                write_stream(out, ',');
                json_write_string(out, "RegIdType");
                write_stream(out, ':');
                json_write_long(out, cmd->args.loc.reg_id_scope.id_type);
                write_stream(out, ',');
                json_write_string(out, "AddrSize");
                write_stream(out, ':');
                json_write_long(out, cmd->args.loc.addr_size);
                write_stream(out, ',');
                json_write_string(out, "BigEndian");
                write_stream(out, ':');
                json_write_boolean(out, cmd->args.loc.reg_id_scope.big_endian);
                write_stream(out, '}');
                break;
            case SFT_CMD_PIECE:
                write_stream(out, ',');
                json_write_ulong(out, cmd->args.piece.bit_offs);
                write_stream(out, ',');
                json_write_ulong(out, cmd->args.piece.bit_size);
                write_stream(out, ',');
                if (cmd->args.piece.reg == NULL) write_string(out, "null");
                else json_write_string(out, register2id(ctx, STACK_NO_FRAME, cmd->args.piece.reg));
                write_stream(out, ',');
                if (cmd->args.piece.value == NULL) write_string(out, "null");
                else json_write_binary(out, cmd->args.piece.value, (cmd->args.piece.bit_size + 7) / 8);
                break;
            }
        }
        write_stream(out, ']');
    }
    else {
        write_string(out, "null");
    }
}