Commit 3be4919d authored by Lev Walkin's avatar Lev Walkin

make -pdu=auto a default

parent 5f4dbb75
......@@ -617,12 +617,16 @@ generate_pdu_collection(arg_t *arg) {
abuf_printf(buf, "/*\n * Generated by asn1c-" VERSION
" (http://lionet.info/asn1c)\n */\n\n");
abuf_printf(buf,
"struct asn_TYPE_descriptor_s;\t"
"/* Forward declaration */\n\n");
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(include_type_to_pdu_collection(arg) == TI_NOT_INCLUDED) continue;
abuf_printf(buf,
"extern asn_TYPE_descriptor_t "
"extern struct asn_TYPE_descriptor_s "
"asn_DEF_%s;\n",
asn1c_make_identifier(0, arg->expr, NULL));
}
......@@ -724,10 +728,19 @@ asn1c__pdu_type_lookup(const char *typename) {
static int
need_to_generate_pdu_collection(arg_t *arg) {
/* If -pdu=all or -pdu=auto are given, we need to generate one. */
if(arg->flags & (A1C_PDU_ALL|A1C_PDU_AUTO))
return 1;
if(arg->flags & A1C_PDU_TYPE)
return (pduTypes > 1) ? 1 : 0;
/*
* If no -pdu=... flags were given, need to do it, too,
* effectively producing -pdu=auto.
*/
if(!(arg->flags & (A1C_PDU_ALL | A1C_PDU_AUTO | A1C_PDU_TYPE))) return 1;
if(arg->flags & A1C_PDU_TYPE) {
return (pduTypes > 1) ? 1 : 0;
}
return 0;
}
......@@ -757,7 +770,11 @@ include_type_to_pdu_collection(arg_t *arg) {
}
if((arg->flags & A1C_PDU_ALL)
/* -pdu=auto */
|| ((arg->flags & A1C_PDU_AUTO) && !arg->expr->_type_referenced)
/* No -pdu=... whatsoever, act as if -pdu=auto */
|| (!(arg->flags & (A1C_PDU_ALL | A1C_PDU_AUTO | A1C_PDU_TYPE))
&& !arg->expr->_type_referenced)
|| asn1c__pdu_type_lookup(arg->expr->Identifier)) {
return 1;
}
......
......@@ -23,24 +23,26 @@
#include <asn_internal.h> /* for ASN__DEFAULT_STACK_MAX */
/* Convert "Type" defined by -DPDU into "asn_DEF_Type" */
#ifndef NO_ASN_PDU
#ifndef PDU
#error Define -DPDU to compile this sample converter.
#error `asn1c -pdu=...` adds it automatically.
#endif
#ifdef ASN_PDU_COLLECTION /* Generated by asn1c: -pdu=... */
extern asn_TYPE_descriptor_t *asn_pdu_collection[];
#endif
#ifdef PDU
#define ASN_DEF_PDU(t) asn_DEF_ ## t
#define DEF_PDU_Type(t) ASN_DEF_PDU(t)
#define PDU_Type DEF_PDU_Type(PDU)
extern asn_TYPE_descriptor_t PDU_Type; /* ASN.1 type to be decoded */
#define PDU_Type_Ptr (&PDU_Type)
#else /* NO_ASN_PDU */
#else /* !PDU */
#define PDU_Type_Ptr NULL
#endif /* NO_ASN_PDU */
#endif /* PDU */
#ifdef ASN_PDU_COLLECTION /* Generated by asn1c -pdu=... */
extern asn_TYPE_descriptor_t *asn_pdu_collection[];
#endif
#ifndef NO_ASN_PDU
#if !defined(PDU) && !defined(ASN_PDU_COLLECTION)
#error Define -DPDU to compile this example converter.
#error `asn1c -pdu=...` adds necessary flags automatically.
#endif
#endif
/*
* Open file and parse its contens.
......@@ -190,7 +192,8 @@ ats_by_name(const char *name, const asn_TYPE_descriptor_t *td,
int
main(int ac, char *av[]) {
FILE *binary_out;
static asn_TYPE_descriptor_t *pduType = PDU_Type_Ptr;
asn_TYPE_descriptor_t *pduType = PDU_Type_Ptr;
asn_TYPE_descriptor_t *anyPduType = PDU_Type_Ptr;
ssize_t suggested_bufsize = 8192; /* close or equal to stdio buffer */
int number_of_iterations = 1;
int num;
......@@ -199,22 +202,27 @@ main(int ac, char *av[]) {
enum asn_transfer_syntax isyntax = ATS_INVALID;
enum asn_transfer_syntax osyntax = ATS_BASIC_XER;
#ifndef PDU
if(!pduType) {
fprintf(stderr, "No -DPDU defined during compilation.\n");
#ifdef NO_ASN_PDU
exit(0);
if(!anyPduType) {
#ifdef ASN_PDU_COLLECTION
anyPduType = asn_pdu_collection[0];
if(!anyPduType) {
fprintf(stderr,
"Empty PDU collection, no reference PDU to choose from.\n");
exit(EX_SOFTWARE);
}
#else
fprintf(stderr, "Either asn1c -pdu=... or cc -DPDU should be used.\n");
exit(EX_SOFTWARE);
#endif
}
#endif
/* Figure out if specialty decoder needs to be default */
if(ats_by_name("oer", pduType, input_encodings))
isyntax = ATS_BASIC_OER;
if(ats_by_name("per", pduType, input_encodings))
isyntax = ATS_UNALIGNED_BASIC_PER;
/* Figure out if a specialty decoder needs to be default */
#ifndef ASN_DISABLE_OER_SUPPORT
isyntax = ATS_BASIC_OER;
#endif
#ifndef ASN_DISABLE_PER_SUPPORT
isyntax = ATS_UNALIGNED_BASIC_PER;
#endif
/*
* Pocess the command-line argments.
......@@ -222,7 +230,7 @@ main(int ac, char *av[]) {
while((ch = getopt(ac, av, "i:o:1b:cdn:p:hs:" JUNKOPT RANDOPT)) != -1)
switch(ch) {
case 'i':
sel = ats_by_name(optarg, pduType, input_encodings);
sel = ats_by_name(optarg, anyPduType, input_encodings);
if(sel) {
isyntax = sel->syntax;
} else {
......@@ -232,7 +240,7 @@ main(int ac, char *av[]) {
}
break;
case 'o':
sel = ats_by_name(optarg, pduType, output_encodings);
sel = ats_by_name(optarg, anyPduType, output_encodings);
if(sel) {
osyntax = sel->syntax;
} else {
......@@ -283,19 +291,23 @@ main(int ac, char *av[]) {
asn_TYPE_descriptor_t **pdu = asn_pdu_collection;
while(*pdu && strcmp((*pdu)->name, optarg)) pdu++;
if(*pdu) { pduType = *pdu; break; }
fprintf(stderr, "-p %s: Unrecognized PDU\n", optarg);
fprintf(stderr, "-p %s: Unrecognized PDU. Try '-p list'.\n",
optarg);
exit(EX_USAGE);
}
#else /* Without -pdu=auto there's just a single type */
if(strcmp(optarg, "list") == 0) {
fprintf(stderr, "Available PDU types:\n");
printf("%s\n", pduType->name);
if(pduType) {
printf("%s\n", pduType->name);
}
exit(0);
} else if(optarg[0] >= 'A' && optarg[0] <= 'Z') {
if(strcmp(optarg, pduType->name) == 0) {
if(pduType && strcmp(optarg, pduType->name) == 0) {
break;
}
fprintf(stderr, "-p %s: Unrecognized PDU\n", optarg);
fprintf(stderr, "-p %s: Unrecognized PDU. Try '-p list'.\n",
optarg);
exit(EX_USAGE);
}
#endif /* ASN_PDU_COLLECTION */
......@@ -342,21 +354,21 @@ main(int ac, char *av[]) {
fprintf(stderr, "Usage: %s [options] <datafile> ...\n", av[0]);
fprintf(stderr, "Where options are:\n");
for(sel = input_encodings; sel->name; sel++) {
if(ats_by_name(sel->name, pduType, sel)) {
if(ats_by_name(sel->name, anyPduType, sel)) {
fprintf(stderr, " -i%s %s%s\n", sel->name,
sel->full_name,
(sel->syntax == isyntax) ? " (DEFAULT)" : "");
}
}
for(sel = output_encodings; sel->name; sel++) {
if(ats_by_name(sel->name, pduType, sel)) {
if(ats_by_name(sel->name, anyPduType, sel)) {
fprintf(stderr, " -o%s%s %s%s\n", sel->name,
strlen(sel->name) > 3 ? "" : " ",
sel->full_name,
(sel->syntax == osyntax) ? " (DEFAULT)" : "");
}
}
if(pduType->op->uper_decoder) {
if(anyPduType->op->uper_decoder) {
fprintf(stderr,
" -per-nopad Assume PER PDUs are not padded (-iper)\n");
}
......@@ -384,6 +396,16 @@ main(int ac, char *av[]) {
ac -= optind;
av += optind;
if(!pduType) {
#ifdef NO_ASN_PDU
fprintf(stderr, "No -DPDU defined during compilation.\n");
exit(0);
#else
fprintf(stderr, "Use '-p <Type>' or '-p list' to select ASN.1 type.\n");
exit(EX_USAGE);
#endif /* NO_ASN_PDU */
}
if(ac < 1 && isyntax != ATS_RANDOM) {
fprintf(stderr, "%s: No input files specified. "
"Try '-h' for more information\n",
......
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