From patchwork Mon Oct 18 15:47:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1542775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=MyOLZ8v2; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FItlebyh; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HY1Vs4DHKz9ssP for ; Tue, 19 Oct 2021 02:48:21 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5B3D13C2F45 for ; Mon, 18 Oct 2021 17:48:19 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A0E3D3C02DA for ; Mon, 18 Oct 2021 17:47:17 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 722D11400E56 for ; Mon, 18 Oct 2021 17:47:17 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8F4CB1FD81 for ; Mon, 18 Oct 2021 15:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1634572036; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6yvgLmca0D+DvWZGTQScZjVCefxKztz0ThtoSpuaRSY=; b=MyOLZ8v2qLvFcWQjvzzCUWE/1JkjeHONWI48DOF+B8E6dkcMsG7Hsw5Q6uswnDAGZ5isva ilv2dB17IxtTh6oD1OGwgZWyUFrpCmwrjLHA3ub6c253C+NdVdrzfcN1avA2bLiXL1jLrB 5oYNe7HszjK8ST3gAvzWcT7jMwkDapE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1634572036; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6yvgLmca0D+DvWZGTQScZjVCefxKztz0ThtoSpuaRSY=; b=FItlebyhpSWXQdbt6Llo0Qw2xpcXOUaGtRokyGdgyuL5QMHIkqy2D8ucRRU4K93E77uzKD Y4DgufdQC12Ld1BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 581AC140B7 for ; Mon, 18 Oct 2021 15:47:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4STDEwSXbWF0JwAAMHmgww (envelope-from ) for ; Mon, 18 Oct 2021 15:47:16 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Mon, 18 Oct 2021 17:47:55 +0200 Message-Id: <20211018154800.11013-4-chrubis@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211018154800.11013-1-chrubis@suse.cz> References: <20211018154800.11013-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 3/7] docparse: data_storage: Add integer type node X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- docparse/data_storage.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docparse/data_storage.h b/docparse/data_storage.h index 339450c8b..117c1d127 100644 --- a/docparse/data_storage.h +++ b/docparse/data_storage.h @@ -15,6 +15,7 @@ enum data_type { DATA_ARRAY, DATA_HASH, DATA_STRING, + DATA_INT, }; struct data_node_array { @@ -41,12 +42,18 @@ struct data_node_string { char val[]; }; +struct data_node_int { + enum data_type type; + long val; +}; + struct data_node { union { enum data_type type; struct data_node_hash hash; struct data_node_array array; struct data_node_string string; + struct data_node_int i; }; }; @@ -64,6 +71,19 @@ static inline struct data_node *data_node_string(const char *string) return node; } +static inline struct data_node *data_node_int(long i) +{ + struct data_node *node = malloc(sizeof(struct data_node_int)); + + if (!node) + return NULL; + + node->type = DATA_INT; + node->i.val = i; + + return node; +} + #define MAX_ELEMS 100 static inline struct data_node *data_node_hash(void) @@ -122,6 +142,7 @@ static inline void data_node_free(struct data_node *self) switch (self->type) { case DATA_STRING: + case DATA_INT: break; case DATA_HASH: for (i = 0; i < self->hash.elems_used; i++) { @@ -209,6 +230,10 @@ static inline void data_node_print_(struct data_node *self, unsigned int padd) unsigned int i; switch (self->type) { + case DATA_INT: + data_print_padd(padd); + printf("%li\n", self->i.val); + break; case DATA_STRING: data_print_padd(padd); printf("'%s'\n", self->string.val); @@ -295,6 +320,10 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int p unsigned int i; switch (self->type) { + case DATA_INT: + padd = do_padd ? padd : 0; + data_fprintf(f, padd, "%li", self->i.val); + break; case DATA_STRING: padd = do_padd ? padd : 0; data_fprintf_esc(f, padd, self->string.val);