Code Map
1 worgle.c
worgle.org:44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parg.h"
1.1 global_variables
worgle.org:2016
static int use_debug = 0;
worgle.org:2026
static int use_warnings = 0;
worgle.org:2088
static int map_source_code = 0;
static char *map_filename = NULL;
1.2 enums
worgle.org:468
enum {
1.2.1 parse_modes
worgle.org:476
MODE_ORG,
worgle.org:573
MODE_BEGINCODE,
worgle.org:721
MODE_CODE
worgle.org:470
};
1.3 structs
1.3.1 worgle_string
worgle.org:1118
typedef struct {
char *str;
size_t size;
} worgle_string;
1.3.2 worgle_segment
worgle.org:1184
enum {
1.3.2.1 worgle_segment_types
worgle.org:1212
SEGTYPE_TEXT,
worgle.org:1224
SEGTYPE_REFERENCE
worgle.org:1186
};
typedef struct worgle_segment {
int type;
worgle_string str;
1.3.2.2 worgle_segment_line_control
worgle.org:1201
size_t linum;
worgle_string *filename;
worgle.org:1191
struct worgle_segment *nxt;
} worgle_segment;
1.3.3 worgle_block
worgle.org:1314
typedef struct worgle_block {
int nsegs;
worgle_segment *head;
worgle_segment *tail;
worgle_string name;
int am_i_used;
struct worgle_block *nxt;
} worgle_block;
1.3.4 worgle_blocklist
worgle.org:1510
typedef struct {
int nblocks;
worgle_block *head;
worgle_block *tail;
} worgle_blocklist;
1.3.5 worgle_hashmap
worgle.org:1589
#define HASH_SIZE 256
typedef struct {
worgle_blocklist blk[HASH_SIZE];
int nwords;
} worgle_hashmap;
1.3.6 worgle_file
worgle.org:1731
typedef struct worgle_file {
worgle_string filename;
worgle_block *top;
struct worgle_file *nxt;
} worgle_file;
1.3.7 worgle_filelist
worgle.org:1784
typedef struct {
worgle_file *head;
worgle_file *tail;
int nfiles;
} worgle_filelist;
1.3.8 worgle_textbuf
worgle.org:1898
typedef struct {
char *buf;
size_t size;
worgle_string filename;
} worgle_textbuf;
1.3.9 worgle_struct
worgle.org:916
typedef struct {
1.3.9.1 worgle_struct_contents
worgle.org:966
worgle_string block; /* TODO: rename */
worgle.org:982
size_t curline;
worgle.org:997
int block_started;
worgle.org:1012
worgle_hashmap dict;
worgle.org:1034
worgle_filelist flist;
worgle.org:1057
worgle_textbuf *curbuf;
worgle_textbuf *buffers;
int nbuffers;
worgle.org:1087
worgle_block *curblock;
worgle.org:1101
size_t linum;
worgle.org:918
} worgle_d;
1.4 static_function_declarations
worgle.org:499
static int parse_name(char *line, size_t len, worgle_string *str);
worgle.org:793
static int check_for_reference(char *line , size_t size, worgle_string *str);
1.5 function_declarations
worgle.org:166
static int loadfile(worgle_d *worg, int file);
worgle.org:267
int parse_file(worgle_d *worg, int file);
worgle.org:411
static int worgle_getline(char *fullbuf,
char **line,
size_t *pos,
size_t *line_size,
size_t buf_size);
worgle.org:555
void worgle_begin_block(worgle_d *worg, worgle_string *name);
worgle.org:609
static int parse_begin(char *line, size_t len, worgle_string *str);
worgle.org:707
void worgle_append_file(worgle_d *worg, worgle_string *filename);
worgle.org:759
void worgle_append_string(worgle_d *worg);
worgle.org:776
void worgle_append_reference(worgle_d *worg, worgle_string *ref);
worgle.org:864
int worgle_generate(worgle_d *worg);
worgle.org:927
void worgle_init(worgle_d *worg);
worgle.org:945
void worgle_free(worgle_d *worg);
worgle.org:1129
void worgle_string_reset(worgle_string *str);
worgle.org:1146
void worgle_string_init(worgle_string *str);
worgle.org:1165
int worgle_string_write(FILE *fp, worgle_string *str);
worgle.org:1231
void worgle_segment_init(worgle_segment *s,
int type,
worgle_string *str,
worgle_string *filename,
size_t linum);
worgle.org:1263
int worgle_segment_write(worgle_segment *s, worgle_hashmap *h, FILE *fp);
worgle.org:1329
void worgle_block_init(worgle_block *b);
worgle.org:1352
void worgle_block_free(worgle_block *lst);
worgle.org:1387
void worgle_block_append_segment(worgle_block *b,
worgle_string *str,
int type,
size_t linum,
worgle_string *filename);
worgle.org:1425
void worgle_block_append_string(worgle_block *b,
worgle_string *str,
size_t linum,
worgle_string *filename);
worgle.org:1448
void worgle_block_append_reference(worgle_block *b,
worgle_string *str,
size_t linum,
worgle_string *filename);
worgle.org:1480
int worgle_block_write(worgle_block *b, worgle_hashmap *h, FILE *fp);
worgle.org:1522
void worgle_blocklist_init(worgle_blocklist *lst);
worgle.org:1541
void worgle_blocklist_free(worgle_blocklist *lst);
worgle.org:1567
void worgle_blocklist_append(worgle_blocklist *lst, worgle_block *b);
worgle.org:1601
void worgle_hashmap_init(worgle_hashmap *h);
worgle.org:1624
void worgle_hashmap_free(worgle_hashmap *h);
worgle.org:1648
int worgle_hashmap_find(worgle_hashmap *h, worgle_string *name, worgle_block **b);
worgle.org:1703
worgle_block * worgle_hashmap_get(worgle_hashmap *h, worgle_string *name);
worgle.org:1745
int worgle_file_write(worgle_file *f, worgle_hashmap *h);
worgle.org:1797
void worgle_filelist_init(worgle_filelist *flist);
worgle.org:1816
void worgle_filelist_free(worgle_filelist *flist);
worgle.org:1841
void worgle_filelist_append(worgle_filelist *flist,
worgle_string *name,
worgle_block *top);
worgle.org:1874
int worgle_filelist_write(worgle_filelist *flist, worgle_hashmap *h);
worgle.org:1911
void worgle_textbuf_zero(worgle_textbuf *txt);
worgle.org:1927
void worgle_textbuf_init(worgle_textbuf *txt,
char *buf,
size_t bufsize);
worgle.org:1951
void worgle_textbuf_free(worgle_textbuf *txt);
worgle.org:2049
int worgle_warn_unused(worgle_d *worg);
worgle.org:2106
static void append_filename(worgle_d *worg, char *filename);
worgle.org:2149
void worgle_map(worgle_d *worg, worgle_block *b, int lvl, FILE *out);
worgle.org:2198
void worgle_map_files(worgle_d *worg, char *filename);
void worgle_map_a_file(worgle_d *worg, worgle_file *file, FILE *out);
1.6 functions
worgle.org:171
static int loadfile(worgle_d *worg, int file)
{
1.6.1 loadfile_localvars
worgle.org:183
FILE *fp;
char *filename;
worgle_textbuf *txt;
worgle.org:205
size_t size;
worgle.org:219
char *buf;
1.6.2 loadfile
worgle.org:190
txt = &worg->buffers[file];
filename = txt->filename.str;
fp = fopen(filename, "r");
if(fp == NULL) {
fprintf(stderr, "Could not find file %s\n", filename);
return 1;
}
worgle.org:210
fseek(fp, 0, SEEK_END);
size = ftell(fp);
worgle.org:224
buf = calloc(1, size);
worgle_textbuf_init(&worg->buffers[file], buf, size);
worgle.org:233
fseek(fp, 0, SEEK_SET);
fread(buf, size, 1, fp);
fclose(fp);
worgle.org:175
return 1;
}
worgle.org:272
int parse_file(worgle_d *worg, int file)
{
char *buf;
size_t size;
worgle_textbuf *curbuf;
curbuf = &worg->buffers[file];
buf = curbuf->buf;
size = curbuf->size;
worg->curbuf = curbuf;
1.6.3 parser_local_variables
worgle.org:304
worgle_string str;
worgle.org:316
char *line;
worgle.org:328
size_t pos;
worgle.org:340
size_t read;
worgle.org:347
int mode;
worgle.org:361
int rc;
worgle.org:376
int status;
1.6.4 parser_initialization
worgle.org:309
worgle_string_init(&str);
worgle.org:321
line = NULL;
worgle.org:333
pos = 0;
worgle.org:354
mode = MODE_ORG;
worgle.org:368
rc = 0;
worgle.org:383
status = 0;
worgle.org:284
while(1) {
1.6.5 getline
worgle.org:404
worg->linum++;
status = worgle_getline(buf, &line, &pos, &read, size);
if(!status) break;
worgle.org:286
if(mode == MODE_ORG) {
1.6.6 parse_mode_org
worgle.org:485
if(read >= 7) {
if(!strncmp(line, "#+NAME:",7)) {
mode = MODE_BEGINCODE;
parse_name(line, read, &str);
worgle_begin_block(worg, &str);
}
}
worgle.org:288
} else if(mode == MODE_CODE) {
1.6.7 parse_mode_code
worgle.org:730
if(read >= 9) {
if(!strncmp(line, "#+END_SRC", 9)) {
mode = MODE_ORG;
worg->block_started = 0;
worgle_append_string(worg);
continue;
}
}
if(check_for_reference(line, read, &str)) {
worgle_append_string(worg);
worgle_append_reference(worg, &str);
worg->block_started = 1;
worgle_string_reset(&worg->block);
continue;
}
worg->block.size += read;
if(worg->block_started) {
worg->block.str = line;
worg->block_started = 0;
worg->curline = worg->linum;
}
worgle.org:290
} else if(mode == MODE_BEGINCODE) {
1.6.8 parse_mode_begincode
worgle.org:583
if(read >= 11) {
if(!strncmp(line, "#+BEGIN_SRC",11)) {
1.6.8.1 begin_the_code
worgle.org:697
mode = MODE_CODE;
worg->block_started = 1;
worgle_string_reset(&worg->block);
worgle.org:586
if(parse_begin(line, read, &str) == 2) {
worgle_append_file(worg, &str);
}
continue;
} else {
fwrite(line, read, 1, stderr);
fprintf(stderr, "line %lu: Expected #+BEGIN_SRC\n", worg->linum);
rc = 1;
break;
}
}
fprintf(stderr, "line %lu: Expected #+BEGIN_SRC\n", worg->linum);
rc = 1;
worgle.org:292
}
}
return rc;
}
worgle.org:432
static int worgle_getline(char *fullbuf,
char **line,
size_t *pos,
size_t *line_size,
size_t buf_size)
{
size_t p;
size_t s;
*line_size = 0;
p = *pos;
*line = &fullbuf[p];
s = 0;
while(1) {
s++;
if(p >= buf_size) return 0;
if(fullbuf[p] == '\n') {
*pos = p + 1;
*line_size = s;
return 1;
}
p++;
}
}
worgle.org:506
static int parse_name(char *line, size_t len, worgle_string *str)
{
size_t n;
size_t pos;
int mode;
line+=7;
len-=7;
/* *namelen = 0; */
str->size = 0;
str->str = NULL;
if(len <= 0) return 1;
pos = 0;
mode = 0;
for(n = 0; n < len; n++) {
if(mode == 2) break;
switch(mode) {
case 0:
if(line[n] == ' ') {
} else {
str->str = &line[n];
str->size++;
pos++;
mode = 1;
}
break;
case 1:
if(line[n] == 0xa) {
mode = 2;
break;
}
pos++;
str->size++;
break;
default:
break;
}
}
/* *namelen = pos; */
return 1;
}
worgle.org:563
void worgle_begin_block(worgle_d *worg, worgle_string *name)
{
worg->curblock = worgle_hashmap_get(&worg->dict, name);
}
worgle.org:625
static int parse_begin(char *line, size_t len, worgle_string *str)
{
size_t n;
int mode;
int rc;
line += 11;
len -= 11;
if(len <= 0) return 0;
mode = 0;
n = 0;
rc = 1;
str->str = NULL;
str->size = 0;
while(n < len) {
switch(mode) {
case 0: /* initial spaces after BEGIN_SRC */
if(line[n] == ' ') {
n++;
} else {
mode = 1;
}
break;
case 1: /* look for :tangle */
if(line[n] == ' ') {
mode = 0;
n++;
} else {
if(line[n] == ':') {
if(!strncmp(line + n + 1, "tangle", 6)) {
n+=7;
mode = 2;
rc = 2;
}
}
n++;
}
break;
case 2: /* save file name, spaces after tangle */
if(line[n] != ' ') {
str->str = &line[n];
str->size++;
mode = 3;
}
n++;
break;
case 3: /* read up to next space or line break */
if(line[n] == ' ' || line[n] == '\n') {
mode = 4;
} else {
str->size++;
}
n++;
break;
case 4: /* countdown til end */
n++;
break;
}
}
return rc;
}
worgle.org:712
void worgle_append_file(worgle_d *worg, worgle_string *filename)
{
worgle_filelist_append(&worg->flist, filename, worg->curblock);
}
worgle.org:764
void worgle_append_string(worgle_d *worg)
{
if(worg->curblock == NULL) return;
worgle_block_append_string(worg->curblock,
&worg->block,
worg->curline,
&worg->curbuf->filename);
}
worgle.org:781
void worgle_append_reference(worgle_d *worg, worgle_string *ref)
{
if(worg->curblock == NULL) return;
worgle_block_append_reference(worg->curblock,
ref,
worg->linum,
&worg->curbuf->filename);
}
worgle.org:798
static int check_for_reference(char *line , size_t size, worgle_string *str)
{
int mode;
size_t n;
mode = 0;
str->size = 0;
str->str = NULL;
for(n = 0; n < size; n++) {
if(mode < 0) break;
switch(mode) {
case 0: /* spaces */
if(line[n] == ' ') continue;
else if(line[n] == '<') mode = 1;
else mode = -1;
break;
case 1: /* second < */
if(line[n] == '<') mode = 2;
else mode = -1;
break;
case 2: /* word setup */
str->str = &line[n];
str->size++;
mode = 3;
break;
case 3: /* the word */
if(line[n] == '>') {
mode = 4;
break;
}
str->size++;
break;
case 4: /* last > */
if(line[n] == '>') mode = 5;
else mode = -1;
break;
}
}
return (mode == 5);
}
worgle.org:869
int worgle_generate(worgle_d *worg)
{
return worgle_filelist_write(&worg->flist, &worg->dict);
}
worgle.org:932
void worgle_init(worgle_d *worg)
{
1.6.9 worgle_init
worgle.org:973
worgle_string_init(&worg->block);
worgle.org:989
worg->curline = -1;
worgle.org:1004
worg->block_started = 0;
worgle.org:1018
worgle_hashmap_init(&worg->dict);
worgle.org:1041
worgle_filelist_init(&worg->flist);
worgle.org:1067
worg->curbuf = NULL;
worg->buffers = NULL;
worg->nbuffers = 0;
worgle.org:1093
worg->curblock = NULL;
worgle.org:1109
worg->linum = 0;
worgle.org:935
}
worgle.org:950
void worgle_free(worgle_d *worg)
{
int i;
1.6.10 worgle_free
worgle.org:1026
worgle_hashmap_free(&worg->dict);
worgle.org:1048
worgle_filelist_free(&worg->flist);
worgle.org:1076
for(i = 0; i < worg->nbuffers; i++) {
worgle_textbuf_free(&worg->buffers[i]);
}
if(worg->nbuffers > 0) free(worg->buffers);
worgle.org:954
}
worgle.org:1134
void worgle_string_reset(worgle_string *str)
{
str->str = NULL;
str->size = 0;
}
worgle.org:1151
void worgle_string_init(worgle_string *str)
{
worgle_string_reset(str);
}
worgle.org:1172
int worgle_string_write(FILE *fp, worgle_string *str)
{
return fwrite(str->str, 1, str->size, fp);
}
worgle.org:1240
void worgle_segment_init(worgle_segment *s,
int type,
worgle_string *str,
worgle_string *filename,
size_t linum)
{
s->type = type;
s->str = *str;
s->filename = filename;
s->linum = linum;
}
worgle.org:1281
int worgle_segment_write(worgle_segment *s, worgle_hashmap *h, FILE *fp)
{
worgle_block *b;
if(s->type == SEGTYPE_TEXT) {
if(use_debug) {
fprintf(fp, "#line %lu \"", s->linum);
worgle_string_write(fp, s->filename);
fprintf(fp, "\"\n");
}
worgle_string_write(fp, &s->str);
} else {
if(!worgle_hashmap_find(h, &s->str, &b)) {
fprintf(stderr, "Warning: could not find reference segment '");
worgle_string_write(stderr, &s->str);
fprintf(stderr, "'\n");
if(use_warnings == 2) {
return 0;
} else {
return 1;
}
}
return worgle_block_write(b, h, fp);
}
return 1;
}
worgle.org:1337
void worgle_block_init(worgle_block *b)
{
b->nsegs = 0;
b->head = NULL;
b->tail = NULL;
b->nxt = NULL;
b->am_i_used = 0;
worgle_string_init(&b->name);
}
worgle.org:1361
void worgle_block_free(worgle_block *lst)
{
worgle_segment *s;
worgle_segment *nxt;
int n;
s = lst->head;
for(n = 0; n < lst->nsegs; n++) {
nxt = s->nxt;
free(s);
s = nxt;
}
}
worgle.org:1399
void worgle_block_append_segment(worgle_block *b,
worgle_string *str,
int type,
size_t linum,
worgle_string *filename)
{
worgle_segment *s;
s = malloc(sizeof(worgle_segment));
if(b->nsegs == 0) {
b->head = s;
b->tail = s;
}
worgle_segment_init(s, type, str, filename, linum);
b->tail->nxt = s;
b->tail = s;
b->nsegs++;
}
worgle.org:1433
void worgle_block_append_string(worgle_block *b,
worgle_string *str,
size_t linum,
worgle_string *filename)
{
worgle_block_append_segment(b, str, SEGTYPE_TEXT, linum, filename);
}
worgle.org:1456
void worgle_block_append_reference(worgle_block *b,
worgle_string *str,
size_t linum,
worgle_string *filename)
{
worgle_block_append_segment(b, str, SEGTYPE_REFERENCE, linum, filename);
}
worgle.org:1489
int worgle_block_write(worgle_block *b, worgle_hashmap *h, FILE *fp)
{
worgle_segment *s;
int n;
s = b->head;
b->am_i_used = 1;
for(n = 0; n < b->nsegs; n++) {
if(!worgle_segment_write(s, h, fp)) return 0;
s = s->nxt;
}
return 1;
}
worgle.org:1527
void worgle_blocklist_init(worgle_blocklist *lst)
{
lst->head = NULL;
lst->tail = NULL;
lst->nblocks = 0;
}
worgle.org:1546
void worgle_blocklist_free(worgle_blocklist *lst)
{
worgle_block *b;
worgle_block *nxt;
int n;
b = lst->head;
for(n = 0; n < lst->nblocks; n++) {
nxt = b->nxt;
worgle_block_free(b);
free(b);
b = nxt;
}
}
worgle.org:1572
void worgle_blocklist_append(worgle_blocklist *lst, worgle_block *b)
{
if(lst->nblocks == 0) {
lst->head = b;
lst->tail = b;
}
lst->tail->nxt = b;
lst->tail = b;
lst->nblocks++;
}
worgle.org:1608
void worgle_hashmap_init(worgle_hashmap *h)
{
int n;
h->nwords = 0;
for(n = 0; n < HASH_SIZE; n++) {
worgle_blocklist_init(&h->blk[n]);
}
}
worgle.org:1631
void worgle_hashmap_free(worgle_hashmap *h)
{
int n;
for(n = 0; n < HASH_SIZE; n++) {
worgle_blocklist_free(&h->blk[n]);
}
}
1.6.11 hashmap_hasher
worgle.org:1682
static int hash(const char *str, size_t size)
{
unsigned int h = 5381;
size_t i = 0;
for(i = 0; i < size; i++) {
h = ((h << 5) + h) ^ str[i];
h %= 0x7FFFFFFF;
}
return h % HASH_SIZE;
}
worgle.org:1654
int worgle_hashmap_find(worgle_hashmap *h, worgle_string *name, worgle_block **b)
{
int pos;
worgle_blocklist *lst;
int n;
worgle_block *blk;
pos = hash(name->str, name->size);
lst = &h->blk[pos];
blk = lst->head;
for(n = 0; n < lst->nblocks; n++) {
if(name->size == blk->name.size) {
if(!strncmp(name->str, blk->name.str, name->size)) {
*b = blk;
return 1;
}
}
blk = blk->nxt;
}
return 0;
}
worgle.org:1708
worgle_block * worgle_hashmap_get(worgle_hashmap *h, worgle_string *name)
{
worgle_block *b;
worgle_blocklist *lst;
int pos;
if(worgle_hashmap_find(h, name, &b)) return b;
pos = hash(name->str, name->size);
b = NULL;
b = malloc(sizeof(worgle_block));
worgle_block_init(b);
b->name = *name;
lst = &h->blk[pos];
worgle_blocklist_append(lst, b);
return b;
}
worgle.org:1757
int worgle_file_write(worgle_file *f, worgle_hashmap *h)
{
FILE *fp;
char tmp[128];
size_t n;
size_t size;
int rc;
if(f->filename.size > 128) size = 127;
else size = f->filename.size;
for(n = 0; n < size; n++) tmp[n] = f->filename.str[n];
tmp[size] = 0;
fp = fopen(tmp, "w");
rc = worgle_block_write(f->top, h, fp);
fclose(fp);
return rc;
}
worgle.org:1802
void worgle_filelist_init(worgle_filelist *flist)
{
flist->head = NULL;
flist->tail = NULL;
flist->nfiles = 0;
}
worgle.org:1821
void worgle_filelist_free(worgle_filelist *flist)
{
worgle_file *f;
worgle_file *nxt;
int n;
f = flist->head;
for(n = 0; n < flist->nfiles; n++) {
nxt = f->nxt;
free(f);
f = nxt;
}
}
worgle.org:1848
void worgle_filelist_append(worgle_filelist *flist,
worgle_string *name,
worgle_block *top)
{
worgle_file *f;
f = malloc(sizeof(worgle_file));
f->filename = *name;
f->top = top;
if(flist->nfiles == 0) {
flist->head = f;
flist->tail = f;
}
flist->tail->nxt = f;
flist->tail = f;
flist->nfiles++;
}
worgle.org:1879
int worgle_filelist_write(worgle_filelist *flist, worgle_hashmap *h)
{
worgle_file *f;
int n;
f = flist->head;
for(n = 0; n < flist->nfiles; n++) {
if(!worgle_file_write(f, h)) return 0;
f = f->nxt;
}
return 1;
}
worgle.org:1916
void worgle_textbuf_zero(worgle_textbuf *txt)
{
txt->buf = NULL;
worgle_string_init(&txt->filename);
txt->size = 0;
}
worgle.org:1934
void worgle_textbuf_init(worgle_textbuf *txt,
char *buf,
size_t bufsize)
{
txt->buf = buf;
txt->size = bufsize;
}
worgle.org:1956
void worgle_textbuf_free(worgle_textbuf *txt)
{
if(txt->buf != NULL) free(txt->buf);
worgle_textbuf_zero(txt);
}
worgle.org:2054
int worgle_warn_unused(worgle_d *worg)
{
worgle_hashmap *dict;
worgle_block *blk;
worgle_blocklist *lst;
int n;
int b;
int rc;
dict = &worg->dict;
rc = 0;
for(n = 0; n < HASH_SIZE; n++) {
lst = &dict->blk[n];
blk = lst->head;
for(b = 0; b < lst->nblocks; b++) {
if(blk->am_i_used == 0) {
fprintf(stderr, "Warning: block '");
worgle_string_write(stderr, &blk->name);
fprintf(stderr, "' unused.\n");
if(use_warnings == 2) rc = 1;
}
blk = blk->nxt;
}
}
return rc;
}
worgle.org:2113
static void append_filename(worgle_d *worg, char *filename)
{
worgle_string *str;
int pos;
pos = worg->nbuffers;
worg->nbuffers++;
if(worg->nbuffers == 1) {
worg->buffers = calloc(1, sizeof(worgle_textbuf));
} else {
worg->buffers = realloc(worg->buffers,
sizeof(worgle_textbuf) * worg->nbuffers);
}
str = &worg->buffers[pos].filename;
str->str = filename;
str->size = strlen(filename);
}
worgle.org:2154
void worgle_map(worgle_d *worg, worgle_block *b, int lvl, FILE *out)
{
int i;
worgle_segment *s;
worgle_block *newblk;
worgle_hashmap *h;
h = &worg->dict;
if(lvl != 0) {
for(i = 0; i <= lvl; i++) {
fputc('*', out);
}
fputc(' ', out);
worgle_string_write(out, &b->name);
fputc('\n', out);
}
s = b->head;
newblk = NULL;
for(i = 0; i < b->nsegs; i++) {
if(s->type == SEGTYPE_TEXT) {
if(s->str.size > 0) {
worgle_string_write(out, s->filename);
fprintf(out, ":%zu\n", s->linum);
fprintf(out, "#+NAME: ");
worgle_string_write(out, &b->name);
fprintf(out, "_%d\n", i);
fprintf(out, "#+BEGIN_SRC\n");
worgle_string_write(out, &s->str);
fprintf(out, "#+END_SRC");
}
fprintf(out, "\n");
} else if(worgle_hashmap_find(h, &s->str, &newblk)) {
worgle_map(worg, newblk, lvl + 1, out);
}
s = s->nxt;
}
}
worgle.org:2204
void worgle_map_files(worgle_d *worg, char *filename)
{
int n;
worgle_file *f;
FILE *fp;
fp = fopen(filename, "w");
if(fp == NULL) return;
f = worg->flist.head;
fprintf(fp, "#+TITLE: Code Map\n");
for(n = 0; n < worg->flist.nfiles; n++) {
worgle_map_a_file(worg, f, fp);
f = f->nxt;
}
fclose(fp);
}
void worgle_map_a_file(worgle_d *worg, worgle_file *file, FILE *out)
{
fprintf(out, "* ");
worgle_string_write(out, &file->filename);
fprintf(out, "\n");
worgle_map(worg, file->top, 0, out);
}
worgle.org:55
int main(int argc, char *argv[])
{
1.7 local_variables
worgle.org:81
worgle_d worg;
worgle.org:96
char *filename;
worgle.org:127
int rc;
worgle.org:251
int i;
worgle.org:1971
struct parg_state ps;
int c;
1.8 initialization
worgle.org:86
worgle_init(&worg);
worgle.org:101
filename = NULL;
if(argc < 2) {
fprintf(stderr, "Usage: %s filename.org\n", argv[0]);
return 1;
}
1.8.1 parse_cli_args
worgle.org:1977
parg_init(&ps);
while((c = parg_getopt(&ps, argc, argv, "gW:m:")) != -1) {
switch(c) {
case 1:
filename = (char *)ps.optarg;
1.8.1.1 append_filename
worgle.org:2101
append_filename(&worg, (char *)ps.optarg);
worgle.org:1983
break;
case 'g':
1.8.1.2 turn_on_debug_macros
worgle.org:2008
use_debug = 1;
worgle.org:1986
break;
case 'W':
1.8.1.3 turn_on_warnings
worgle.org:2031
if(!strncmp(ps.optarg, "soft", 4)) {
use_warnings = 1;
} else if(!strncmp(ps.optarg, "error", 5)) {
use_warnings = 2;
} else {
fprintf(stderr, "Unidentified warning mode '%s'\n", ps.optarg);
return 1;
}
worgle.org:1989
break;
case 'm':
1.8.1.4 map_source_code
worgle.org:2094
map_source_code = 1;
map_filename = (char *)ps.optarg;
worgle.org:1992
break;
default:
fprintf(stderr, "Unknown option -%c\n", c);
return 1;
}
}
1.8.2 check_filename
worgle.org:115
if(filename == NULL) {
fprintf(stderr, "No filename specified\n");
return 1;
}
worgle.org:134
rc = 0;
1.9 loading
worgle.org:151
for(i = 0; i < worg.nbuffers; i++) {
rc = loadfile(&worg, i);
if(!rc) goto cleanup;
}
1.10 parsing
worgle.org:256
for(i = 0; i < worg.nbuffers; i++) {
rc = parse_file(&worg, i);
if(rc) goto cleanup;
}
1.11 generation
worgle.org:859
if(!rc) if(!worgle_generate(&worg)) rc = 1;
worgle.org:880
if(use_warnings) rc = worgle_warn_unused(&worg);
1.12 mapping
worgle.org:2136
if(map_source_code && map_filename != NULL) {
worgle_map_files(&worg, map_filename);
}
1.13 cleanup
worgle.org:887
cleanup:
worgle_free(&worg);
return rc;
worgle.org:65
}