mirror of
https://github.com/linux-msm/qmic.git
synced 2024-11-23 09:44:06 +08:00
qmic: Extract all generators into functions
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
6f19b29065
commit
a8c34af751
43
qmic.c
43
qmic.c
@ -33,6 +33,14 @@ static void qmi_const_header(FILE *fp)
|
|||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void emit_source_header(FILE *fp, const char *package)
|
||||||
|
{
|
||||||
|
fprintf(fp, "#include <errno.h>\n"
|
||||||
|
"#include <string.h>\n"
|
||||||
|
"#include \"qmi_%1$s.h\"\n\n",
|
||||||
|
package);
|
||||||
|
}
|
||||||
|
|
||||||
static void guard_header(FILE *fp, const char *package)
|
static void guard_header(FILE *fp, const char *package)
|
||||||
{
|
{
|
||||||
char *upper;
|
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, "#ifndef __QMI_%s_H__\n", upper);
|
||||||
fprintf(fp, "#define __QMI_%s_H__\n", upper);
|
fprintf(fp, "#define __QMI_%s_H__\n", upper);
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
|
fprintf(fp, "#include <stdint.h>\n"
|
||||||
|
"#include <stdlib.h>\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)
|
static void guard_footer(FILE *fp)
|
||||||
@ -72,27 +94,12 @@ int main(int argc, char **argv)
|
|||||||
if (!hfp)
|
if (!hfp)
|
||||||
err(1, "failed to open %s", fname);
|
err(1, "failed to open %s", fname);
|
||||||
|
|
||||||
fprintf(sfp, "#include <errno.h>\n"
|
/* Source output */
|
||||||
"#include <string.h>\n"
|
emit_source_header(sfp, qmi_package);
|
||||||
"#include \"qmi_%1$s.h\"\n\n",
|
|
||||||
qmi_package);
|
|
||||||
qmi_message_source(sfp, qmi_package);
|
qmi_message_source(sfp, qmi_package);
|
||||||
|
|
||||||
|
/* Header output */
|
||||||
guard_header(hfp, qmi_package);
|
guard_header(hfp, qmi_package);
|
||||||
fprintf(hfp, "#include <stdint.h>\n"
|
|
||||||
"#include <stdlib.h>\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_const_header(hfp);
|
||||||
qmi_struct_header(hfp, qmi_package);
|
qmi_struct_header(hfp, qmi_package);
|
||||||
qmi_message_header(hfp, qmi_package);
|
qmi_message_header(hfp, qmi_package);
|
||||||
|
Loading…
Reference in New Issue
Block a user