From a8c34af7511d495a767bcdc17b9ee5a4fe53f863 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 30 Jan 2018 16:42:22 -0800 Subject: [PATCH] qmic: Extract all generators into functions Signed-off-by: Bjorn Andersson --- qmic.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/qmic.c b/qmic.c index e2c0bfb..b8b9faa 100644 --- a/qmic.c +++ b/qmic.c @@ -33,6 +33,14 @@ static void qmi_const_header(FILE *fp) fprintf(fp, "\n"); } +static void emit_source_header(FILE *fp, const char *package) +{ + fprintf(fp, "#include \n" + "#include \n" + "#include \"qmi_%1$s.h\"\n\n", + package); +} + static void guard_header(FILE *fp, const char *package) { char *upper; @@ -47,6 +55,20 @@ static void guard_header(FILE *fp, const char *package) fprintf(fp, "#ifndef __QMI_%s_H__\n", upper); fprintf(fp, "#define __QMI_%s_H__\n", upper); fprintf(fp, "\n"); + fprintf(fp, "#include \n" + "#include \n\n"); + fprintf(fp, "struct qmi_tlv;\n" + "\n" + "struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id, unsigned type);\n" + "struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn, unsigned type);\n" + "void *qmi_tlv_encode(struct qmi_tlv *tlv, size_t *len);\n" + "void qmi_tlv_free(struct qmi_tlv *tlv);\n" + "\n" + "void *qmi_tlv_get(struct qmi_tlv *tlv, unsigned id, size_t *len);\n" + "void *qmi_tlv_get_array(struct qmi_tlv *tlv, unsigned id, unsigned len_size, size_t *len, size_t *size);\n" + "int qmi_tlv_set(struct qmi_tlv *tlv, unsigned id, void *buf, size_t len);\n" + "int qmi_tlv_set_array(struct qmi_tlv *tlv, unsigned id, unsigned len_size, void *buf, size_t len, size_t size);\n" + "\n"); } static void guard_footer(FILE *fp) @@ -72,27 +94,12 @@ int main(int argc, char **argv) if (!hfp) err(1, "failed to open %s", fname); - fprintf(sfp, "#include \n" - "#include \n" - "#include \"qmi_%1$s.h\"\n\n", - qmi_package); + /* Source output */ + emit_source_header(sfp, qmi_package); qmi_message_source(sfp, qmi_package); + /* Header output */ guard_header(hfp, qmi_package); - fprintf(hfp, "#include \n" - "#include \n\n"); - fprintf(hfp, "struct qmi_tlv;\n" - "\n" - "struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id, unsigned type);\n" - "struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn, unsigned type);\n" - "void *qmi_tlv_encode(struct qmi_tlv *tlv, size_t *len);\n" - "void qmi_tlv_free(struct qmi_tlv *tlv);\n" - "\n" - "void *qmi_tlv_get(struct qmi_tlv *tlv, unsigned id, size_t *len);\n" - "void *qmi_tlv_get_array(struct qmi_tlv *tlv, unsigned id, unsigned len_size, size_t *len, size_t *size);\n" - "int qmi_tlv_set(struct qmi_tlv *tlv, unsigned id, void *buf, size_t len);\n" - "int qmi_tlv_set_array(struct qmi_tlv *tlv, unsigned id, unsigned len_size, void *buf, size_t len, size_t size);\n" - "\n"); qmi_const_header(hfp); qmi_struct_header(hfp, qmi_package); qmi_message_header(hfp, qmi_package);