scripts/asn1_compiler.c
Source file repositories/reference/linux-study-clean/scripts/asn1_compiler.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/asn1_compiler.c- Extension
.c- Size
- 36169 bytes
- Lines
- 1612
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdarg.hstdio.hstdlib.hstdint.hstdbool.hstring.hctype.hunistd.hfcntl.hsys/stat.hlinux/asn1_ber_bytecode.h
Detected Declarations
struct actionstruct tokenstruct elementstruct typeenum token_typeenum compoundfunction directive_comparefunction tokenisefunction mainfunction type_index_comparefunction type_finderfunction build_type_listfunction parsefunction dump_elementfunction dump_elementsfunction render_opcodefunction render_morefunction renderfunction render_out_of_line_listfunction render_element
Annotated Snippet
struct action {
struct action *next;
char *name;
unsigned char index;
};
static struct action *action_list;
static unsigned nr_actions;
struct token {
unsigned short line;
enum token_type token_type : 8;
unsigned char size;
struct action *action;
char *content;
struct type *type;
};
static struct token *token_list;
static unsigned nr_tokens;
static bool verbose_opt;
static bool debug_opt;
#define verbose(fmt, ...) do { if (verbose_opt) printf(fmt, ## __VA_ARGS__); } while (0)
#define debug(fmt, ...) do { if (debug_opt) printf(fmt, ## __VA_ARGS__); } while (0)
static int directive_compare(const void *_key, const void *_pdir)
{
const struct token *token = _key;
const char *const *pdir = _pdir, *dir = *pdir;
size_t dlen, clen;
int val;
dlen = strlen(dir);
clen = (dlen < token->size) ? dlen : token->size;
//debug("cmp(%s,%s) = ", token->content, dir);
val = memcmp(token->content, dir, clen);
if (val != 0) {
//debug("%d [cmp]\n", val);
return val;
}
if (dlen == token->size) {
//debug("0\n");
return 0;
}
//debug("%d\n", (int)dlen - (int)token->size);
return dlen - token->size; /* shorter -> negative */
}
/*
* Tokenise an ASN.1 grammar
*/
static void tokenise(char *buffer, char *end)
{
struct token *tokens;
char *line, *nl, *start, *p, *q;
unsigned tix, lineno;
/* Assume we're going to have half as many tokens as we have
* characters
*/
token_list = tokens = calloc((end - buffer) / 2, sizeof(struct token));
if (!tokens) {
perror(NULL);
exit(1);
}
tix = 0;
lineno = 0;
while (buffer < end) {
/* First of all, break out a line */
lineno++;
line = buffer;
nl = memchr(line, '\n', end - buffer);
if (!nl) {
buffer = nl = end;
} else {
buffer = nl + 1;
*nl = '\0';
}
/* Remove "--" comments */
p = line;
next_comment:
while ((p = memchr(p, '-', nl - p))) {
if (p[1] == '-') {
/* Found a comment; see if there's a terminator */
Annotation
- Immediate include surface: `stdarg.h`, `stdio.h`, `stdlib.h`, `stdint.h`, `stdbool.h`, `string.h`, `ctype.h`, `unistd.h`.
- Detected declarations: `struct action`, `struct token`, `struct element`, `struct type`, `enum token_type`, `enum compound`, `function directive_compare`, `function tokenise`, `function main`, `function type_index_compare`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.