Commit 68723b6e authored by v0-e's avatar v0-e

Add -fprefix as an option

parent 1b1e30a6
......@@ -145,6 +145,9 @@ main(int ac, char **av) {
asn1_compiler_flags &= ~A1C_LINK_SKELETONS;
} else if(strcmp(optarg, "link-skeletons") == 0) {
asn1_compiler_flags |= A1C_LINK_SKELETONS;
} else if(strncmp(optarg, "prefix=", 7) == 0) {
char *prefix = optarg + 7;
asn1c_prefix_set(prefix);
} else {
fprintf(stderr, "-f%s: Invalid argument\n", optarg);
exit(EX_USAGE);
......@@ -589,6 +592,7 @@ usage(const char *av0) {
" -fno-include-deps Do not generate the courtesy #includes for dependencies\n"
" -funnamed-unions Enable unnamed unions in structures\n"
" -fwide-types Use INTEGER_t instead of \"long\" by default, etc.\n"
" -fprefix=<prefix> Add the specified prefix to generated types\n"
"\n"
" -no-gen-BER Do not generate the Basic Encoding Rules (BER, X.690) support code\n"
......
......@@ -38,14 +38,28 @@ reserved_keyword(const char *str) {
return 0;
}
const char *
asn1c_prefix()
{
const char *prefix = getenv("ASN1C_PREFIX");
const char *asn1c_prefix = NULL;
void
asn1c_prefix_set(const char *prefix) {
asn1c_prefix = prefix;
}
const char *
asn1c_prefix_get() {
const char *prefix;
prefix = asn1c_prefix;
if (prefix)
return prefix;
prefix = getenv("ASN1C_PREFIX");
if (prefix)
return prefix;
if(!prefix) prefix = "";
prefix = "";
return prefix;
return prefix;
}
/*
......@@ -68,7 +82,7 @@ asn1c_make_identifier(enum ami_flags_e flags, asn1p_expr_t *expr, ...) {
int sptr_cnt = 0;
if(flags & AMI_USE_PREFIX)
prefix = asn1c_prefix();
prefix = asn1c_prefix_get();
if(expr) {
/*
......@@ -348,7 +362,7 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
}
}
prefix = stdname ? "" : asn1c_prefix();
prefix = stdname ? "" : asn1c_prefix_get();
switch(_format) {
case TNF_UNMODIFIED:
......
......@@ -52,6 +52,5 @@ enum asn1c_fitsfloat_e {
RL_FITS_DOUBLE64
};
enum asn1c_fitsfloat_e asn1c_REAL_fits(arg_t *arg, asn1p_expr_t *expr);
const char *asn1c_prefix(void);
#endif /* ASN1_COMPILER_MISC_H */
......@@ -193,7 +193,7 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) {
construct_base_name(&tmp_compoundable_part_name, expr, compound_names, 0, 0);
construct_base_name(&compound_part_name, expr, 1, 0, 0);
if(strlen(asn1c_prefix()) == 0) {
if(strlen(asn1c_prefix_get()) == 0) {
if(!expr->_anonymous_type) {
if(arg->embed) {
abuf_printf(&b_short_name, "%s", b_as_member.buffer);
......@@ -209,16 +209,16 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) {
} else {
if(!expr->_anonymous_type) {
if(arg->embed) {
abuf_printf(&b_short_name, "%s%s", asn1c_prefix(), b_as_member.buffer);
abuf_printf(&b_short_name, "%s%s", asn1c_prefix_get(), b_as_member.buffer);
} else {
abuf_printf(&b_short_name, "%s%s_t", asn1c_prefix(), b_as_member.buffer);
abuf_printf(&b_short_name, "%s%s_t", asn1c_prefix_get(), b_as_member.buffer);
}
}
abuf_printf(&b_full_name, "struct %s%s", asn1c_prefix(), b_base_name.buffer);
abuf_printf(&b_presence_enum, "enum %s%s_PR", asn1c_prefix(), tmp_compoundable_part_name.buffer);
abuf_printf(&b_presence_name, "%s%s_PR", asn1c_prefix(), tmp_compoundable_part_name.buffer);
abuf_printf(&b_members_enum, "enum %s%s", asn1c_prefix(), b_base_name.buffer);
abuf_printf(&b_members_name, "e_%s%s", asn1c_prefix(), tmp_compoundable_part_name.buffer);
abuf_printf(&b_full_name, "struct %s%s", asn1c_prefix_get(), b_base_name.buffer);
abuf_printf(&b_presence_enum, "enum %s%s_PR", asn1c_prefix_get(), tmp_compoundable_part_name.buffer);
abuf_printf(&b_presence_name, "%s%s_PR", asn1c_prefix_get(), tmp_compoundable_part_name.buffer);
abuf_printf(&b_members_enum, "enum %s%s", asn1c_prefix_get(), b_base_name.buffer);
abuf_printf(&b_members_name, "e_%s%s", asn1c_prefix_get(), tmp_compoundable_part_name.buffer);
}
names.type.asn_name = b_type_asn_name.buffer;
......@@ -268,7 +268,7 @@ c_member_name(arg_t *arg, asn1p_expr_t *expr) {
abuf_clear(&ab);
/* NB: do not use part_name, doesn't work for -fcompound-names */
abuf_str(&ab, asn1c_prefix());
abuf_str(&ab, asn1c_prefix_get());
abuf_str(&ab, c_name_impl(arg, arg->expr, 0).base_name);
abuf_str(&ab, "_");
abuf_str(&ab, asn1c_make_identifier(0, expr, 0));
......@@ -283,7 +283,7 @@ c_presence_name(arg_t *arg, asn1p_expr_t *expr) {
abuf_clear(&ab);
abuf_str(&ab, asn1c_prefix());
abuf_str(&ab, asn1c_prefix_get());
if(expr) {
/* NB: do not use part_name, doesn't work for -fcompound-names */
abuf_str(&ab, c_name_impl(arg, arg->expr, 0).base_name);
......
......@@ -1021,7 +1021,7 @@ generate_constant_collection(arg_t *arg) {
abuf_printf(buf, "/*\n * Generated by asn1c-" VERSION
" (http://lionet.info/asn1c)\n */\n\n");
abuf_printf(buf, "#ifndef _%sASN_CONSTANT_H\n#define _%sASN_CONSTANT_H\n\n", asn1c_prefix(), asn1c_prefix());
abuf_printf(buf, "#ifndef _%sASN_CONSTANT_H\n#define _%sASN_CONSTANT_H\n\n", asn1c_prefix_get(), asn1c_prefix_get());
abuf_printf(buf, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
......@@ -1054,7 +1054,7 @@ generate_constant_collection(arg_t *arg) {
}
}
abuf_printf(buf, "\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _%sASN_CONSTANT_H */\n", asn1c_prefix());
abuf_printf(buf, "\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _%sASN_CONSTANT_H */\n", asn1c_prefix_get());
if(empty_file) {
abuf_free(buf);
......@@ -1071,9 +1071,9 @@ generate_constant_file(arg_t *arg, const char *destdir) {
if(!buf) return 0;
filename_len = strlen(asn1c_prefix()) + strlen("asn_constant");
filename_len = strlen(asn1c_prefix_get()) + strlen("asn_constant");
filename = calloc(filename_len + 1, 1);
snprintf(filename, filename_len + 1, "%sasn_constant", asn1c_prefix());
snprintf(filename, filename_len + 1, "%sasn_constant", asn1c_prefix_get());
if(arg->flags & A1C_PRINT_COMPILED) {
printf("\n/*** <<< asn_constant.h >>> ***/\n\n");
......
......@@ -141,6 +141,9 @@ void asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags,
void asn1c__add_pdu_type(const char *typename);
void asn1c_prefix_set(const char *prefix);
const char* asn1c_prefix_get(void);
int asn1c_attach_streams(asn1p_expr_t *expr);
#endif /* ASN1_COMPILER_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment