Skip to content

Commit

Permalink
Generate asn_constant.h
Browse files Browse the repository at this point in the history
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 generate asn_constant.h which has the following macro
defitions :

    #define maxnoofErrors (256)
    #define maxnoofBPLMNs (6)
    #define maxnoofPLMNsPerMME (32)
    #define maxnoofEPLMNs (15)
    #define maxnoofEPLMNsPlusOne (16)
    ...

It only handles ASN_BASIC_INTEGER type. Other built-in types shall
be added in the future.
  • Loading branch information
brchiu committed Jan 23, 2018
1 parent 8d1673d commit e436f61
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions libasn1compiler/asn1c_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static int pdu_collection_has_unused_types(arg_t *arg);
static const char *generate_pdu_C_definition(void);
static void asn1c__cleanup_pdu_type(void);
static int asn1c__pdu_type_lookup(const char *typename);
static int generate_constant_file(arg_t *arg, const char *destdir);

static int
asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
Expand Down Expand Up @@ -436,6 +437,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
asn1c_dep_chainset_free(deps);
asn1c__cleanup_pdu_type();

generate_constant_file(arg, destdir);

return ret;
}

Expand Down Expand Up @@ -944,3 +947,49 @@ include_type_to_pdu_collection(arg_t *arg) {

return 0;
}

static abuf *
generate_constant_collection(arg_t *arg) {
asn1p_module_t *mod;
abuf *buf = abuf_new();

abuf_printf(buf, "/*\n * Generated by asn1c-" VERSION
" (http://lionet.info/asn1c)\n */\n\n");
abuf_printf(buf, "#ifndef _ASN_CONSTANT_H\n#define _ASN_CONSTANT_H\n\n");

abuf_printf(buf, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");

TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(arg->expr->meta_type != AMT_VALUE)
continue;

if(arg->expr->expr_type == ASN_BASIC_INTEGER) {
abuf_printf(buf, "#define %s (%s)\n",
asn1c_make_identifier(0, arg->expr, 0),
asn1p_itoa(arg->expr->value->value.v_integer));
}
}
}

abuf_printf(buf, "\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _ASN_CONSTANT_H */\n");
return buf;
}

static int
generate_constant_file(arg_t *arg, const char *destdir) {
abuf *buf = generate_constant_collection(arg);
assert(buf);

FILE *fp = asn1c_open_file(destdir, "asn_constant", ".h", 0);
if(fp == NULL) {
perror("asn_constant.h");
return -1;
}
safe_fwrite(buf->buffer, buf->length, 1, fp);
fclose(fp);
abuf_free(buf);

safe_fprintf(stderr, "Generated asn_constant.h\n");
return 0;
}

0 comments on commit e436f61

Please sign in to comment.