void Write::select_type(int a, void*p, std::string &str) { switch(a) { case jyjson_string: get_string(p,str); break; case jyjson_numint: get_int(p,str); break; case jyjson_numdouble: get_double(p,str); break; case jyjson_object: get_object(p,str); break; case jyjson_array: get_array(p,str); break; case jyjson_bool: get_bool(p,str); break; case jyjson_null: get_null(p,str); break; case jyjson_nothing: break; } }
int ROKEN_LIB_FUNCTION getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { int ret; int port = 0; int protocol = 0; int socktype = 0; *res = NULL; if (servname == NULL && nodename == NULL) return EAI_NONAME; if (hints != NULL && hints->ai_family != PF_UNSPEC && hints->ai_family != PF_INET #ifdef HAVE_IPV6 && hints->ai_family != PF_INET6 #endif ) return EAI_FAMILY; if (servname != NULL) { ret = get_port_protocol_socktype (servname, hints, &port, &protocol, &socktype); if (ret) return ret; } if (nodename != NULL) { ret = get_number (nodename, hints, port, protocol, socktype, res); if (ret) { if(hints && hints->ai_flags & AI_NUMERICHOST) ret = EAI_NONAME; else ret = get_nodes (nodename, hints, port, protocol, socktype, res); } } else { ret = get_null (hints, port, protocol, socktype, res); } if (ret) freeaddrinfo (*res); return ret; }
int List_push(List list, ListNode node) { if (list == NULL || node == NULL) { return FAIL; } int blank_space = get_null(list); int id; if (blank_space == -1) { if (list->count >= list->max) { increment_array_size(list); } id = list->count + 1; list->count++; } else { id = blank_space; } node->id = malloc(2); sprintf(node->id, "%d", id); list->elements[id] = (ListNode) malloc(sizeof(struct ListNode)); memcpy(list->elements[id], node, sizeof(struct ListNode)); return id; }
/** @brief Get the next JSON node -- be it string, number, hash, or whatever. @param parser Pointer to a Parser. @param firstc The first character in the part that we're parsing. @return Pointer to the next JSON node, or NULL upon error. The first character tells us what kind of thing we're parsing next: a string, an array, a hash, a number, a boolean, or a null. Branch accordingly. In the case of an array or a hash, this function indirectly calls itself in order to parse subordinate nodes. */ static jsonObject* get_json_node( Parser* parser, char firstc ) { jsonObject* obj = NULL; // Branch on the first character if( '"' == firstc ) { const char* str = get_string( parser ); if( str ) { obj = jsonNewObject( NULL ); obj->type = JSON_STRING; obj->value.s = strdup( str ); } } else if( '[' == firstc ) { obj = get_array( parser ); } else if( '{' == firstc ) { if( parser->decode ) obj = get_decoded_hash( parser ); else obj = get_hash( parser ); } else if( 'n' == firstc ) { obj = get_null( parser ); } else if( 't' == firstc ) { obj = get_true( parser ); } else if( 'f' == firstc ) { obj = get_false( parser ); } else if( isdigit( (unsigned char) firstc ) || '.' == firstc || '-' == firstc || '+' == firstc || 'e' == firstc || 'E' == firstc ) { obj = get_number( parser, firstc ); } else { report_error( parser, firstc, "Unexpected character" ); } return obj; }