Commit 7d5d9303 authored by Lev Walkin's avatar Lev Walkin

more precise OER and PER code bundling

parent 30566d13
#include "asn1c_internal.h"
#include "asn1c_compat.h"
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
/* Normally file permissions are (DEFFILEMODE & ~umask(2)) */
#ifndef DEFFILEMODE /* Normally in <sys/stat.h> */
......
This diff is collapsed.
#ifndef ASN1C_FDEPS_H
#define ASN1C_FDEPS_H
typedef struct asn1c_fdeps_s {
char *filename; /* Or 0, if root. */
enum fdep_usage {
FDEP_IGNORE = -1, /* Ignore contents of the section */
FDEP_NOTUSED = 0,
FDEP_REFERRED = 1, /* Dynamic list of dependencies */
FDEP_CONVERTER = 2, /* Name of the int main() file */
FDEP_COMMON_FILES = 3, /* Section for mandatory dependencies */
FDEP_CODEC_OER = 4, /* Use contents only if -gen-OER */
FDEP_CODEC_PER = 8, /* Use contents only if -gen-PER */
} usage; /* Some file refers to it */
struct asn1c_fdeps_s **elements;
int el_size;
int el_count;
} asn1c_fdeps_t;
asn1c_fdeps_t *asn1c_read_file_dependencies(arg_t *arg, const char *datadir);
typedef struct {
char *filename;
int lineno;
int column;
} asn1c_dep_filename;
/*
* Format:
* <observed-name> [<dependent-name> ...]
*/
typedef struct {
asn1c_dep_filename **deps;
size_t deps_count;
} asn1c_dep_chain;
/*
* A single dependency chain, marked with the usage tag and activation tag.
*/
typedef struct {
enum asn1c_dep_section {
FDEP_IGNORE = 0, /* Section is not used */
FDEP_DEFAULT = (1 << 1), /* Default dependency list */
FDEP_REFERRED = (1 << 2), /* Dynamic list of dependencies */
FDEP_CONVERTER = (1 << 3), /* Name of the file with int main() */
FDEP_COMMON_FILES = (1 << 4), /* Section for mandatory dependencies */
FDEP_CODEC_OER = (1 << 5), /* Use contents only if -gen-OER */
FDEP_CODEC_PER = (1 << 6), /* Use contents only if -gen-PER */
} section; /* Some file refers to it */
/* Whether this chain is alive and has to be present in the output */
struct {
int active;
char *by;
} activated;
asn1c_dep_chain *chain;
} asn1c_tagged_dep_chain;
typedef struct {
asn1c_tagged_dep_chain **chains;
size_t chains_count;
} asn1c_dep_chainset;
asn1c_dep_chainset *asn1c_read_file_dependencies(arg_t *arg,
const char *datadir);
/* Data may be a filename or an "#include <>" string. */
int asn1c_activate_dependency(asn1c_fdeps_t *deps, asn1c_fdeps_t *cur,
const char *data);
void asn1c_activate_dependency(asn1c_dep_chainset *deps, const char *data,
const char *by);
asn1c_dep_chain *asn1c_deps_flatten(const asn1c_dep_chainset *deps,
enum asn1c_dep_section);
asn1c_fdeps_t *asn1c_deps_flatten(const asn1c_fdeps_t *deps);
void asn1c_deps_freelist(asn1c_fdeps_t *deps);
void asn1c_dep_chain_free(asn1c_dep_chain *);
void asn1c_dep_chainset_free(asn1c_dep_chainset *);
#endif /* ASN1C_FDEPS_H */
......@@ -10,6 +10,7 @@
#include <string.h> /* for strlen(3) and memset(3) */
#include <ctype.h> /* for isalnum(3) */
#include <sys/types.h> /* for fstat(2) */
#include <limits.h> /* for PATH_MAX */
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
......@@ -22,6 +23,10 @@
#include <unistd.h> /* for unlink(2) */
#endif
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#ifdef _WIN32
#include <io.h>
#include <malloc.h>
......
......@@ -38,10 +38,10 @@ enum include_type_result {
TI_INCLUDED_FROM_CMDLINE
};
static int asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *, int, char **);
static int asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *, int, char **);
static int asn1c_print_streams(arg_t *arg);
static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *, int, char **);
static int asn1c_copy_over(arg_t *arg, char *path);
static int asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *, int, char **);
static int asn1c_copy_over(arg_t *arg, const char *path, const char *msg);
static int identical_files(const char *fname1, const char *fname2);
static int need_to_generate_pdu_collection(arg_t *arg);
static abuf *generate_pdu_collection(arg_t *arg);
......@@ -54,8 +54,8 @@ static void asn1c__cleanup_pdu_type(void);
static int asn1c__pdu_type_lookup(const char *typename);
static int
asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *datadir, const char *makefile_name) {
asn1c_fdeps_t *dlist;
asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
const char *datadir, const char *makefile_name) {
asn1p_module_t *mod;
FILE *mkf;
......@@ -90,49 +90,51 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *
/*
* Move necessary skeleton files and add them to Makefile.am.targets.
*/
dlist = asn1c_deps_flatten(deps);
if(dlist) {
char buf[8129];
asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, ~FDEP_CONVERTER);
if(dlist) {
char dstpath[PATH_MAX];
char *dir_end;
size_t dlen = strlen(datadir);
assert(dlen < (sizeof(buf) / 2 - 2));
memcpy(buf, datadir, dlen);
dir_end = buf + dlen;
assert(dlen < (sizeof(dstpath) / 2 - 2));
memcpy(dstpath, datadir, dlen);
dir_end = dstpath + dlen;
*dir_end++ = '/';
for(int i = 0; i < dlist->el_count; i++) {
for(size_t i = 0; i < dlist->deps_count; i++) {
char where[32]; /* Location of the */
char *what_kind; /* HEADERS or SOURCES */
char *fname = dlist->elements[i]->filename;
const asn1c_dep_filename *dep_file = dlist->deps[i];
char *fname = dep_file->filename;
char *dotH;
assert(strlen(fname) < (sizeof(buf) / 2));
assert(strlen(fname) < (sizeof(dstpath) / 2));
strcpy(dir_end, fname);
if(dlist->elements[i]->usage == FDEP_CONVERTER
&& !(arg->flags & A1C_GEN_EXAMPLE))
continue;
if(arg->flags & A1C_DEBUG) {
snprintf(where, sizeof(where), "(line %d col %d)",
dep_file->lineno, dep_file->column);
} else {
where[0] = '\0';
}
if(asn1c_copy_over(arg, buf) == -1) {
if(asn1c_copy_over(arg, dstpath, where) == -1) {
safe_fprintf(mkf, ">>>ABORTED<<<");
fclose(mkf);
return -1;
}
/* no CONVERTER data in Makefile.am.targets */
if(dlist->elements[i]->usage != FDEP_CONVERTER) {
/* HEADERS versus SOURCES */
dotH = strrchr(fname, 'h');
if(dotH && fname<dotH && dotH[-1] == '.' && !dotH[1])
what_kind = "HEADERS";
else
what_kind = "SOURCES";
safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n",
what_kind, fname);
}
/* HEADERS versus SOURCES */
dotH = strrchr(fname, 'h');
if(dotH && fname < dotH && dotH[-1] == '.' && !dotH[1]) {
what_kind = "HEADERS";
} else {
what_kind = "SOURCES";
}
safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n", what_kind, fname);
}
asn1c_deps_freelist(dlist);
asn1c_dep_chain_free(dlist);
}
safe_fprintf(
......@@ -156,8 +158,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *
}
static int
asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
const char *makefile_name,
asn1c__save_example_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
const char *datadir, const char *makefile_name,
const char *library_makefile_name, int argc,
char **argv) {
FILE *mkf;
......@@ -180,15 +182,21 @@ asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : "");
if(arg->flags & A1C_GEN_EXAMPLE) {
asn1c_fdeps_t *dlist = asn1c_deps_flatten(deps);
asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, FDEP_CONVERTER);
if(dlist) {
/* only CONVERTER data in the makefile */
for(int i = 0; i < dlist->el_count; i++) {
if(dlist->elements[i]->usage == FDEP_CONVERTER) {
safe_fprintf(mkf, "\\\n\t%s", dlist->elements[i]->filename);
for(size_t i = 0; i < dlist->deps_count; i++) {
char dstpath[PATH_MAX];
int ret = snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir,
dlist->deps[i]->filename);
assert(ret > 0 && (size_t)ret < sizeof(dstpath));
if(asn1c_copy_over(arg, dstpath, "implicit") == -1) {
safe_fprintf(mkf, ">>>ABORTED<<<");
fclose(mkf);
return -1;
}
safe_fprintf(mkf, "\\\n\t%s", dlist->deps[i]->filename);
}
asn1c_deps_freelist(dlist);
asn1c_dep_chain_free(dlist);
}
}
......@@ -237,7 +245,6 @@ can_generate_pdu_collection(arg_t *arg) {
int
asn1c_save_compiled_output(arg_t *arg, const char *datadir,
int argc, int optc, char **argv) {
asn1c_fdeps_t *deps = 0;
int ret = -1;
/*
......@@ -247,6 +254,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
return -1;
}
asn1c_dep_chainset *deps;
do {
asn1p_module_t *mod;
......@@ -281,14 +289,14 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
if(ret) break;
if(arg->flags & A1C_GEN_EXAMPLE) {
ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example",
"Makefile.am.libasncodec", argc,
argv);
ret = asn1c__save_example_makefile(
arg, deps, datadir, "Makefile.am.example",
"Makefile.am.libasncodec", argc, argv);
if(ret) break;
}
} while(0);
asn1c_deps_freelist(deps);
asn1c_dep_chainset_free(deps);
asn1c__cleanup_pdu_type();
return ret;
......@@ -298,8 +306,9 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
* Dump the streams.
*/
static int
asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) {
if(arg->flags & A1C_PRINT_COMPILED) {
asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
char **argv) {
if(arg->flags & A1C_PRINT_COMPILED) {
return asn1c_print_streams(arg);
} else {
return asn1c_save_streams(arg, deps, optc, argv);
......@@ -330,8 +339,9 @@ asn1c_print_streams(arg_t *arg) {
}
static int
asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) {
asn1p_expr_t *expr = arg->expr;
asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
char **argv) {
asn1p_expr_t *expr = arg->expr;
compiler_streams_t *cs = expr->data;
out_chunk_t *ot;
FILE *fp_c, *fp_h;
......@@ -373,7 +383,7 @@ asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) {
if(TQ_FIRST(&(cs->destination[idx].chunks)) && *msg) \
safe_fprintf(fp, "\n/* %s */\n", msg); \
TQ_FOR(ot, &(cs->destination[idx].chunks), next) { \
if(actdep) asn1c_activate_dependency(deps, 0, ot->buf); \
if(actdep) asn1c_activate_dependency(deps, ot->buf, header_id); \
safe_fwrite(ot->buf, ot->len, 1, fp); \
} \
} while(0)
......@@ -554,7 +564,7 @@ real_copy(const char *src, const char *dst) {
}
static int
asn1c_copy_over(arg_t *arg, char *path) {
asn1c_copy_over(arg_t *arg, const char *path, const char *msg) {
#ifdef _WIN32
int use_real_copy = 1;
#else
......@@ -595,10 +605,12 @@ asn1c_copy_over(arg_t *arg, char *path) {
}
}
safe_fprintf(stderr, "%s %s\t-> %s\n",
use_real_copy ? "Copied" : "Symlinked", path, fname);
const int has_msg = msg && *msg;
safe_fprintf(stderr, "%s %s\t-> %s%s%s\n",
use_real_copy ? "Copied" : "Symlinked", path, fname,
has_msg ? " " : "", has_msg ? msg : "");
return 1;
return 1;
}
......
......@@ -7,7 +7,6 @@
#include <asn_application.h>
#include <asn_codecs_prim.h>
#include <NativeInteger.h>
#ifdef __cplusplus
extern "C" {
......
......@@ -69,17 +69,19 @@ CONVERTER: # THIS IS A SPECIAL SECTION
converter-example.c # A default name for the example transcoder
CODEC-OER: # THIS IS A SPECIAL SECTION
oer_decoder.h oer_decoder.c OPEN_TYPE.h # OER decoding support
oer_encoder.h oer_encoder.c # OER encoding support
oer_support.h oer_support.c # OER support
oer_decoder.h
oer_encoder.h
oer_support.h
oer_decoder.h oer_decoder.c OPEN_TYPE.h
oer_encoder.h oer_encoder.c
oer_support.h oer_support.c
OPEN_TYPE.h OPEN_TYPE_oer.c constr_CHOICE.h
INTEGER_oer.c INTEGER.h
OCTET_STRING_oer.c
NativeInteger_oer.c NativeInteger.h
NativeEnumerated_oer.c NativeEnumerated.h
constr_SEQUENCE_oer.c constr_SEQUENCE.h
constr_CHOICE_oer.c
constr_SET_OF_oer.c constr_SET_OF.h asn_SET_OF.h asn_SET_OF.c
BIT_STRING_oer.c
INTEGER.h INTEGER_oer.c
BIT_STRING.h BIT_STRING_oer.c OCTET_STRING_oer.c
NativeInteger.h NativeInteger_oer.c
NativeEnumerated.h NativeEnumerated_oer.c
constr_CHOICE.h constr_CHOICE_oer.c
constr_SEQUENCE.h constr_SEQUENCE_oer.c
constr_SET_OF.h constr_SET_OF_oer.c
CODEC-PER: # THIS IS A SPECIAL SECTION
......@@ -30,7 +30,7 @@ verify() {
cleanup
asncmd="${top_builddir}/asn1c/asn1c -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
asncmd="${top_builddir}/asn1c/asn1c -Wdebug-compiler -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
{
echo "$asncmd"
......@@ -52,9 +52,12 @@ verify_type_with_variants() {
}
verify_compile_and_link_variants() {
for type in INTEGER "ENUMERATED{foo}" NULL BOOLEAN "BIT STRING" \
"OBJECT IDENTIFIER" "RELATIVE-OID" "SEQUENCE{f INTEGER}" \
"CHOICE{f INTEGER}" "OCTET STRING" IA5String UTF8String \
for type in INTEGER "INTEGER(0..1)" "ENUMERATED{foo}" NULL BOOLEAN \
"BIT STRING" \
"OBJECT IDENTIFIER" "RELATIVE-OID" \
"SEQUENCE{f INTEGER}" \
"CHOICE{f INTEGER}" \
"OCTET STRING" IA5String "IA5String(SIZE(1))" UTF8String \
REAL "SET OF INTEGER" "SEQUENCE OF INTEGER"; do
verify_type_with_variants "$type"
......@@ -69,6 +72,8 @@ else
verify_type_with_variants "$type"
done
fi
set +x
trap '' EXIT ERR
cleanup
echo "OK"
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