Skip to content

Commit 6950a07

Browse files
committed
Generate asn_constant.h
Currently, there is no code generated for following ASN.1 excerpt. Thus application is not aware of these values. maxnoofErrors INTEGER ::= 256 maxnoofBPLMNs INTEGER ::= 6 maxnoofPLMNsPerMME INTEGER ::= 32 maxnoofEPLMNs INTEGER ::= 15 This commit only handles ASN_BASIC_INTEGER type. Other built-in type shall be added in the future.
1 parent 1378392 commit 6950a07

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

libasn1compiler/asn1c_save.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static int pdu_collection_has_unused_types(arg_t *arg);
5252
static const char *generate_pdu_C_definition(void);
5353
static void asn1c__cleanup_pdu_type(void);
5454
static int asn1c__pdu_type_lookup(const char *typename);
55+
static int generate_constant_file(arg_t *arg, const char *destdir);
5556

5657
static int
5758
asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
@@ -430,6 +431,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
430431
asn1c_dep_chainset_free(deps);
431432
asn1c__cleanup_pdu_type();
432433

434+
generate_constant_file(arg, destdir);
435+
433436
return ret;
434437
}
435438

@@ -934,3 +937,49 @@ include_type_to_pdu_collection(arg_t *arg) {
934937

935938
return 0;
936939
}
940+
941+
static abuf *
942+
generate_constant_collection(arg_t *arg) {
943+
asn1p_module_t *mod;
944+
abuf *buf = abuf_new();
945+
946+
abuf_printf(buf, "/*\n * Generated by asn1c-" VERSION
947+
" (http://lionet.info/asn1c)\n */\n\n");
948+
abuf_printf(buf, "#ifndef _ASN_CONSTANT_H\n#define _ASN_CONSTANT_H\n\n");
949+
950+
abuf_printf(buf, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
951+
952+
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
953+
TQ_FOR(arg->expr, &(mod->members), next) {
954+
if(arg->expr->meta_type != AMT_VALUE)
955+
continue;
956+
957+
if(arg->expr->expr_type == ASN_BASIC_INTEGER) {
958+
abuf_printf(buf, "#define %s (%s)\n",
959+
asn1c_make_identifier(0, arg->expr, 0),
960+
asn1p_itoa(arg->expr->value->value.v_integer));
961+
}
962+
}
963+
}
964+
965+
abuf_printf(buf, "\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _ASN_CONSTANT_H */\n");
966+
return buf;
967+
}
968+
969+
static int
970+
generate_constant_file(arg_t *arg, const char *destdir) {
971+
abuf *buf = generate_constant_collection(arg);
972+
assert(buf);
973+
974+
FILE *fp = asn1c_open_file(destdir, "asn_constant", ".h", 0);
975+
if(fp == NULL) {
976+
perror("asn_constant.h");
977+
return -1;
978+
}
979+
safe_fwrite(buf->buffer, buf->length, 1, fp);
980+
fclose(fp);
981+
abuf_free(buf);
982+
983+
safe_fprintf(stderr, "Generated asn_constant.h\n");
984+
return 0;
985+
}

0 commit comments

Comments
 (0)