2016-11-03 21:37:29 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 25.02.2016
|
|
|
|
*
|
|
|
|
* File editing view for 4coder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
// Enriched Text
|
|
|
|
|
|
|
|
struct Enriched_Text{
|
2016-11-28 19:13:53 +00:00
|
|
|
String source;
|
2016-11-03 21:37:29 +00:00
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Enriched_Text
|
|
|
|
load_enriched_text(char *directory, char *filename){
|
2016-11-03 21:37:29 +00:00
|
|
|
Enriched_Text result = {0};
|
|
|
|
|
|
|
|
char space[256];
|
|
|
|
String fname = make_fixed_width_string(space);
|
|
|
|
append_sc(&fname, directory);
|
2016-11-14 14:58:20 +00:00
|
|
|
append_sc(&fname, "/");
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(&fname, filename);
|
|
|
|
terminate_with_null(&fname);
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
result.source = file_dump(fname.str);
|
2016-11-03 21:37:29 +00:00
|
|
|
return(result);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-03 21:37:29 +00:00
|
|
|
|
|
|
|
// Document Declaration
|
|
|
|
|
|
|
|
enum{
|
|
|
|
Doc_Root,
|
|
|
|
Doc_Section,
|
|
|
|
Doc_Todo,
|
|
|
|
Doc_Enriched_Text,
|
|
|
|
Doc_Element_List,
|
|
|
|
Doc_Full_Elements,
|
|
|
|
Doc_Table_Of_Contents
|
|
|
|
};
|
|
|
|
|
2016-11-24 06:02:18 +00:00
|
|
|
struct Alternate_Name{
|
2016-11-10 03:18:22 +00:00
|
|
|
String macro;
|
|
|
|
String public_name;
|
2016-11-24 06:02:18 +00:00
|
|
|
};
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-24 06:02:18 +00:00
|
|
|
struct Alternate_Names_Array{
|
2016-11-10 03:18:22 +00:00
|
|
|
Alternate_Name *names;
|
2016-11-24 06:02:18 +00:00
|
|
|
};
|
2016-11-10 03:18:22 +00:00
|
|
|
|
|
|
|
enum{
|
|
|
|
AltName_Standard,
|
|
|
|
AltName_Macro,
|
|
|
|
AltName_Public_Name,
|
|
|
|
};
|
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
struct Document_Item{
|
|
|
|
Document_Item *next;
|
|
|
|
Document_Item *parent;
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 type;
|
2016-11-03 21:37:29 +00:00
|
|
|
union{
|
|
|
|
struct{
|
|
|
|
Document_Item *first_child;
|
|
|
|
Document_Item *last_child;
|
2016-11-28 19:13:53 +00:00
|
|
|
String name;
|
2016-11-03 21:37:29 +00:00
|
|
|
String id;
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 show_title;
|
2016-11-28 19:13:53 +00:00
|
|
|
} section;
|
|
|
|
|
|
|
|
struct{
|
|
|
|
Meta_Unit *unit;
|
|
|
|
Alternate_Names_Array *alt_names;
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 alt_name_type;
|
2016-11-28 19:13:53 +00:00
|
|
|
} unit_elements;
|
|
|
|
|
|
|
|
struct{
|
|
|
|
Enriched_Text *text;
|
|
|
|
} text;
|
|
|
|
};
|
2016-11-03 21:37:29 +00:00
|
|
|
};
|
2017-07-10 14:51:19 +00:00
|
|
|
global Document_Item null_document_item = {0};
|
2016-11-03 21:37:29 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
enum{
|
|
|
|
ItemType_Document,
|
|
|
|
ItemType_Image,
|
2016-12-08 17:16:50 +00:00
|
|
|
ItemType_GenericFile,
|
2016-11-28 19:13:53 +00:00
|
|
|
// never below this
|
|
|
|
ItemType_COUNT,
|
|
|
|
};
|
|
|
|
|
2016-12-08 17:16:50 +00:00
|
|
|
struct Basic_Node{
|
|
|
|
Basic_Node *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NodeGetData(node, T) ((T*) ((node)+1))
|
|
|
|
|
|
|
|
struct Basic_List{
|
|
|
|
Basic_Node *head;
|
|
|
|
Basic_Node *tail;
|
|
|
|
};
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
struct Abstract_Item{
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 item_type;
|
2016-11-28 19:13:53 +00:00
|
|
|
char *name;
|
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
// Document value members
|
|
|
|
Document_Item *root_item;
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// TODO(allen): make these external
|
2016-11-03 21:37:29 +00:00
|
|
|
// Document building members
|
|
|
|
Document_Item *section_stack[16];
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 section_top;
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
// Image value members
|
|
|
|
char *source_file;
|
2016-12-08 17:16:50 +00:00
|
|
|
char *extension;
|
2016-11-28 19:13:53 +00:00
|
|
|
float w_h_ratio;
|
|
|
|
float h_w_ratio;
|
2016-12-08 17:16:50 +00:00
|
|
|
Basic_List img_instantiations;
|
2016-11-28 19:13:53 +00:00
|
|
|
};
|
2017-07-10 14:51:19 +00:00
|
|
|
global Abstract_Item null_abstract_item = {0};
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2016-12-08 17:16:50 +00:00
|
|
|
struct Image_Instantiation{
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 w, h;
|
2016-11-24 06:02:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Document_System{
|
2016-11-28 19:13:53 +00:00
|
|
|
Basic_List doc_list;
|
|
|
|
Basic_List img_list;
|
2016-12-08 17:16:50 +00:00
|
|
|
Basic_List file_list;
|
2016-11-24 06:02:18 +00:00
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Document_System
|
|
|
|
create_document_system(){
|
2016-11-24 06:02:18 +00:00
|
|
|
Document_System system = {0};
|
|
|
|
return(system);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void*
|
|
|
|
push_item_on_list(Basic_List *list, i32 item_size){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 mem_size = item_size + sizeof(Basic_Node);
|
2017-07-10 14:51:19 +00:00
|
|
|
void *mem = fm__push(mem_size);
|
|
|
|
Assert(mem != 0);
|
2016-11-28 19:13:53 +00:00
|
|
|
memset(mem, 0, mem_size);
|
2016-11-24 06:02:18 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
Basic_Node *node = (Basic_Node*)mem;
|
|
|
|
if (list->head == 0){
|
|
|
|
list->head = node;
|
|
|
|
list->tail = node;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
list->tail->next = node;
|
|
|
|
list->tail = node;
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
void *result = (node+1);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
2016-11-28 19:13:53 +00:00
|
|
|
get_item_by_name(Basic_List list, String name){
|
|
|
|
Abstract_Item *result = 0;
|
|
|
|
|
|
|
|
for (Basic_Node *node = list.head;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
Abstract_Item *item = NodeGetData(node, Abstract_Item);
|
|
|
|
if (match(item->name, name)){
|
|
|
|
result = item;
|
|
|
|
break;
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
2016-11-28 19:13:53 +00:00
|
|
|
get_item_by_name(Basic_List list, char *name){
|
|
|
|
Abstract_Item *result = 0;
|
2016-11-24 06:02:18 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (Basic_Node *node = list.head;
|
2016-11-24 06:02:18 +00:00
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
2016-11-28 19:13:53 +00:00
|
|
|
Abstract_Item *item = NodeGetData(node, Abstract_Item);
|
|
|
|
if (match(item->name, name)){
|
|
|
|
result = item;
|
2016-11-24 06:02:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Image_Instantiation*
|
2017-01-07 02:59:55 +00:00
|
|
|
get_image_instantiation(Basic_List list, i32 w, i32 h){
|
2016-12-08 17:16:50 +00:00
|
|
|
Image_Instantiation *result = 0;
|
|
|
|
|
|
|
|
for (Basic_Node *node = list.head;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
Image_Instantiation *instantiation = NodeGetData(node, Image_Instantiation);
|
|
|
|
if (instantiation->w == w && instantiation->h == h){
|
|
|
|
result = instantiation;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
|
|
|
create_item(Basic_List *list, char *name){
|
2016-11-28 19:13:53 +00:00
|
|
|
Abstract_Item *lookup = get_item_by_name(*list, name);
|
|
|
|
|
|
|
|
Abstract_Item *result = 0;
|
2016-12-08 17:16:50 +00:00
|
|
|
if (lookup == 0){
|
2017-07-10 14:51:19 +00:00
|
|
|
result = (Abstract_Item*)push_item_on_list(list, sizeof(Abstract_Item));
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
add_image_instantiation(Basic_List *list, i32 w, i32 h){
|
|
|
|
Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(list, sizeof(Image_Instantiation));
|
2016-12-08 17:16:50 +00:00
|
|
|
instantiation->w = w;
|
|
|
|
instantiation->h = h;
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
set_section_name(Document_Item *item, char *name, i32 show_title){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 name_len = str_size(name);
|
2017-07-10 14:51:19 +00:00
|
|
|
item->section.name = make_string_cap(fm_push_array(char, name_len+1), 0, name_len+1);
|
|
|
|
fm_align();
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(&item->section.name, name);
|
2016-11-28 19:13:53 +00:00
|
|
|
item->section.show_title = show_title;
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
set_section_id(Document_Item *item, char *id){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 id_len = str_size(id);
|
2017-07-10 14:51:19 +00:00
|
|
|
item->section.id = make_string_cap(fm_push_array(char, id_len+1), 0, id_len+1);
|
|
|
|
fm_align();
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(&item->section.id, id);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
begin_document_description(Abstract_Item *doc, char *title, i32 show_title){
|
2016-11-28 19:13:53 +00:00
|
|
|
*doc = null_abstract_item;
|
|
|
|
doc->item_type = ItemType_Document;
|
2016-11-03 21:37:29 +00:00
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
doc->root_item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*doc->root_item = null_document_item;
|
|
|
|
doc->section_stack[doc->section_top] = doc->root_item;
|
|
|
|
doc->root_item->type = Doc_Root;
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
set_section_name(doc->root_item, title, show_title);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
2016-12-08 17:16:50 +00:00
|
|
|
add_generic_file(Document_System *system, char *source_file, char *extension, char *name){
|
2017-07-10 14:51:19 +00:00
|
|
|
Abstract_Item *item = create_item(&system->file_list, name);
|
2016-12-08 17:16:50 +00:00
|
|
|
if (item){
|
|
|
|
item->item_type = ItemType_GenericFile;
|
|
|
|
item->extension = extension;
|
|
|
|
item->source_file = source_file;
|
|
|
|
item->name = name;
|
|
|
|
}
|
|
|
|
return(item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
2016-12-08 17:16:50 +00:00
|
|
|
add_image_description(Document_System *system, char *source_file, char *extension, char *name){
|
2017-07-10 14:51:19 +00:00
|
|
|
Abstract_Item *item = create_item(&system->img_list, name);
|
|
|
|
if (item != 0){
|
2016-11-28 19:13:53 +00:00
|
|
|
item->item_type = ItemType_Image;
|
2016-12-08 17:16:50 +00:00
|
|
|
item->extension = extension;
|
2016-11-28 19:13:53 +00:00
|
|
|
item->source_file = source_file;
|
|
|
|
item->name = name;
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 w = 0, h = 0, comp = 0;
|
|
|
|
i32 stbi_r = stbi_info(source_file, &w, &h, &comp);
|
2016-12-08 17:16:50 +00:00
|
|
|
if (!stbi_r){
|
|
|
|
fprintf(stderr, "Did not find file %s\n", source_file);
|
|
|
|
item->w_h_ratio = 1.f;
|
|
|
|
item->h_w_ratio = 1.f;
|
|
|
|
}
|
|
|
|
else{
|
2017-01-07 02:59:55 +00:00
|
|
|
item->w_h_ratio = ((float)w/(float)h);
|
|
|
|
item->h_w_ratio = ((float)h/(float)w);
|
2016-12-08 17:16:50 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
return(item);
|
2016-11-22 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal Abstract_Item*
|
2017-01-07 02:59:55 +00:00
|
|
|
begin_document_description(Document_System *system, char *title, char *name, i32 show_title){
|
2017-07-10 14:51:19 +00:00
|
|
|
Abstract_Item *item = create_item(&system->doc_list, name);
|
2016-11-28 19:13:53 +00:00
|
|
|
if (item){
|
2017-07-10 14:51:19 +00:00
|
|
|
begin_document_description(item, title, show_title);
|
2016-11-28 19:13:53 +00:00
|
|
|
item->name = name;
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
return(item);
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
end_document_description(Abstract_Item *item){
|
|
|
|
Assert(item->section_top == 0);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-03 21:37:29 +00:00
|
|
|
append_child(Document_Item *parent, Document_Item *item){
|
|
|
|
Assert(parent->type == Doc_Root || parent->type == Doc_Section);
|
|
|
|
if (parent->section.last_child == 0){
|
|
|
|
parent->section.first_child = item;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
parent->section.last_child->next = item;
|
|
|
|
}
|
|
|
|
parent->section.last_child = item;
|
|
|
|
item->parent = parent;
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
begin_section(Abstract_Item *item, char *title, char *id){
|
|
|
|
Assert(item->section_top+1 < ArrayCount(item->section_stack));
|
2016-11-03 21:37:29 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
Document_Item *parent = item->section_stack[item->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *section = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*section = null_document_item;
|
2016-11-28 19:13:53 +00:00
|
|
|
item->section_stack[++item->section_top] = section;
|
2016-11-03 21:37:29 +00:00
|
|
|
|
|
|
|
section->type = Doc_Section;
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
set_section_name(section, title, 1);
|
|
|
|
if (id != 0){
|
|
|
|
set_section_id(section, id);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
append_child(parent, section);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-03 21:37:29 +00:00
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
end_section(Abstract_Item *doc){
|
2016-11-03 21:37:29 +00:00
|
|
|
Assert(doc->section_top > 0);
|
|
|
|
--doc->section_top;
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
add_todo(Abstract_Item *doc){
|
2016-11-03 21:37:29 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Todo;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
add_element_list(Abstract_Item *doc, Meta_Unit *unit){
|
2016-11-03 21:37:29 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Element_List;
|
|
|
|
item->unit_elements.unit = unit;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2017-01-07 02:59:55 +00:00
|
|
|
add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
|
2016-11-10 03:18:22 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-10 03:18:22 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Element_List;
|
|
|
|
item->unit_elements.unit = unit;
|
|
|
|
item->unit_elements.alt_names = alt_names;
|
|
|
|
item->unit_elements.alt_name_type = alt_name_type;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
|
2016-11-03 21:37:29 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Full_Elements;
|
|
|
|
item->unit_elements.unit = unit;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2017-01-07 02:59:55 +00:00
|
|
|
add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
|
2016-11-10 03:18:22 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-10 03:18:22 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Full_Elements;
|
|
|
|
item->unit_elements.unit = unit;
|
|
|
|
item->unit_elements.alt_names = alt_names;
|
|
|
|
item->unit_elements.alt_name_type = alt_name_type;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
add_table_of_contents(Abstract_Item *doc){
|
2016-11-03 21:37:29 +00:00
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Table_Of_Contents;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
|
2016-11-03 21:37:29 +00:00
|
|
|
Assert(doc->section_top+1 < ArrayCount(doc->section_stack));
|
|
|
|
|
|
|
|
Document_Item *parent = doc->section_stack[doc->section_top];
|
2017-07-10 14:51:19 +00:00
|
|
|
Document_Item *item = fm_push_array(Document_Item, 1);
|
2016-11-03 21:37:29 +00:00
|
|
|
*item = null_document_item;
|
|
|
|
item->type = Doc_Enriched_Text;
|
|
|
|
item->text.text = text;
|
|
|
|
|
|
|
|
append_child(parent, item);
|
|
|
|
}
|
|
|
|
|
2016-11-24 06:02:18 +00:00
|
|
|
// HTML Document Generation
|
2016-11-03 21:37:29 +00:00
|
|
|
|
|
|
|
#define HTML_BACK_COLOR "#FAFAFA"
|
|
|
|
#define HTML_TEXT_COLOR "#0D0D0D"
|
|
|
|
#define HTML_CODE_BACK "#DFDFDF"
|
|
|
|
#define HTML_EXAMPLE_BACK "#EFEFDF"
|
|
|
|
|
|
|
|
#define HTML_POP_COLOR_1 "#309030"
|
|
|
|
#define HTML_POP_BACK_1 "#E0FFD0"
|
|
|
|
#define HTML_VISITED_LINK "#A0C050"
|
|
|
|
|
|
|
|
#define HTML_POP_COLOR_2 "#005000"
|
|
|
|
|
|
|
|
#define HTML_CODE_STYLE "font-family: \"Courier New\", Courier, monospace; text-align: left;"
|
|
|
|
|
|
|
|
#define HTML_CODE_BLOCK_STYLE(back) \
|
|
|
|
"margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; " \
|
|
|
|
"background: "back"; padding: 0.25em;"
|
|
|
|
|
|
|
|
#define HTML_DESCRIPT_SECTION_STYLE HTML_CODE_BLOCK_STYLE(HTML_CODE_BACK)
|
|
|
|
#define HTML_EXAMPLE_CODE_STYLE HTML_CODE_BLOCK_STYLE(HTML_EXAMPLE_BACK)
|
|
|
|
|
|
|
|
#define HTML_DOC_HEAD_OPEN "<div style='margin-top: 3mm; margin-bottom: 3mm; color: "HTML_POP_COLOR_1";'><b><i>"
|
|
|
|
#define HTML_DOC_HEAD_CLOSE "</i></b></div>"
|
|
|
|
|
|
|
|
#define HTML_DOC_ITEM_HEAD_STYLE "font-weight: 600;"
|
|
|
|
|
|
|
|
#define HTML_DOC_ITEM_HEAD_INL_OPEN "<span style='"HTML_DOC_ITEM_HEAD_STYLE"'>"
|
|
|
|
#define HTML_DOC_ITEM_HEAD_INL_CLOSE "</span>"
|
|
|
|
|
|
|
|
#define HTML_DOC_ITEM_HEAD_OPEN "<div style='"HTML_DOC_ITEM_HEAD_STYLE"'>"
|
|
|
|
#define HTML_DOC_ITEM_HEAD_CLOSE "</div>"
|
|
|
|
|
|
|
|
#define HTML_DOC_ITEM_OPEN "<div style='margin-left: 5mm; margin-right: 5mm;'>"
|
|
|
|
#define HTML_DOC_ITEM_CLOSE "</div>"
|
|
|
|
|
|
|
|
#define HTML_EXAMPLE_CODE_OPEN "<div style='"HTML_CODE_STYLE HTML_EXAMPLE_CODE_STYLE"'>"
|
|
|
|
#define HTML_EXAMPLE_CODE_CLOSE "</div>"
|
|
|
|
|
|
|
|
struct Section_Counter{
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 counter[16];
|
|
|
|
i32 nest_level;
|
2016-11-03 21:37:29 +00:00
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal i32
|
2017-01-07 02:59:55 +00:00
|
|
|
doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){
|
2016-11-24 06:02:18 +00:00
|
|
|
String str = make_string_cap(space, 0, capacity);
|
|
|
|
append_sc(&str, doc->name);
|
|
|
|
append_sc(&str, ".html");
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 result = terminate_with_null(&str);
|
2016-11-24 06:02:18 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal i32
|
2017-01-07 02:59:55 +00:00
|
|
|
img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){
|
2016-11-28 19:13:53 +00:00
|
|
|
String str = make_string_cap(space, 0, capacity);
|
2016-12-08 17:16:50 +00:00
|
|
|
append_sc(&str, img->name);
|
|
|
|
|
|
|
|
append_sc(&str, "_");
|
|
|
|
append_int_to_str(&str, w);
|
|
|
|
append_sc(&str, "_");
|
|
|
|
append_int_to_str(&str, h);
|
|
|
|
|
|
|
|
append_sc(&str, ".");
|
|
|
|
append_sc(&str, img->extension);
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 result = terminate_with_null(&str);
|
2016-11-28 19:13:53 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2017-01-07 02:59:55 +00:00
|
|
|
append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){
|
|
|
|
i32 level = section_counter->nest_level-reduce;
|
|
|
|
for (i32 i = 1; i <= level; ++i){
|
2016-11-22 18:26:58 +00:00
|
|
|
append_int_to_str(out, section_counter->counter[i]);
|
2016-11-10 03:18:22 +00:00
|
|
|
if (i != level){
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(out, ".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-22 18:26:58 +00:00
|
|
|
append_section_number(String *out, Section_Counter *section_counter){
|
2016-11-10 03:18:22 +00:00
|
|
|
append_section_number_reduced(out, section_counter, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal i32
|
2017-01-07 02:59:55 +00:00
|
|
|
extract_command_body(String *out, String l, i32 *i_in_out, i32 *body_start_out, i32 *body_end_out, String command_name, i32 require_body){
|
|
|
|
i32 result = 0;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 i = *i_in_out;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (; i < l.size; ++i){
|
|
|
|
if (!char_is_whitespace(l.str[i])){
|
|
|
|
break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 found_command_body = 0;
|
|
|
|
i32 body_start = 0, body_end = 0;
|
2016-11-28 19:13:53 +00:00
|
|
|
if (l.str[i] == '{'){
|
|
|
|
body_start = i+1;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (++i; i < l.size; ++i){
|
|
|
|
if (l.str[i] == '}'){
|
|
|
|
found_command_body = 1;
|
|
|
|
body_end = i;
|
|
|
|
++i;
|
|
|
|
break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (found_command_body){
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
else{
|
2016-12-08 17:16:50 +00:00
|
|
|
if (require_body){
|
2016-11-10 03:18:22 +00:00
|
|
|
#define STR_START "<span style='color:#F00'>! Doc generator error: missing body for "
|
2016-11-28 19:13:53 +00:00
|
|
|
#define STR_SLOW " !</span>"
|
2017-01-07 02:59:55 +00:00
|
|
|
append_sc(out, STR_START);
|
|
|
|
append_ss(out, command_name);
|
|
|
|
append_sc(out, STR_SLOW);
|
2016-11-10 03:18:22 +00:00
|
|
|
#undef STR
|
2017-01-07 02:59:55 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "error: missing body for %.*s\n", command_name.size, command_name.str);
|
2016-12-08 17:16:50 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*i_in_out = i;
|
|
|
|
*body_start_out = body_start;
|
|
|
|
*body_end_out = body_end;
|
|
|
|
|
2016-11-10 03:18:22 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-22 18:26:58 +00:00
|
|
|
html_render_section_header(String *out, String section_name, String section_id, Section_Counter *section_counter){
|
|
|
|
if (section_counter->nest_level <= 1){
|
|
|
|
if (section_id.size > 0){
|
|
|
|
append_sc(out, "\n<h2 id='section_");
|
|
|
|
append_ss(out, section_id);
|
|
|
|
append_sc(out, "'>§");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc(out, "\n<h2>§");
|
|
|
|
}
|
|
|
|
append_section_number(out, section_counter);
|
|
|
|
append_sc(out, " ");
|
|
|
|
append_ss(out, section_name);
|
|
|
|
append_sc(out, "</h2>");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (section_id.size > 0){
|
|
|
|
append_sc(out, "<h3 id='section_");
|
|
|
|
append_ss(out, section_id);
|
|
|
|
append_sc(out, "'>§");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc(out, "<h3>§");
|
|
|
|
}
|
|
|
|
append_section_number(out, section_counter);
|
|
|
|
append_sc(out, " ");
|
|
|
|
append_ss(out, section_name);
|
|
|
|
append_sc(out, "</h3>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
#define HTML_WIDTH 800
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
write_enriched_text_html(String *out, Enriched_Text *text, Document_System *doc_system, Section_Counter *section_counter){
|
2016-11-03 21:37:29 +00:00
|
|
|
String source = text->source;
|
|
|
|
|
|
|
|
append_sc(out, "<div>");
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 item_counter = 0;
|
2016-11-24 06:02:18 +00:00
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
for (String line = get_first_double_line(source);
|
|
|
|
line.str;
|
2016-11-05 02:59:35 +00:00
|
|
|
line = get_next_double_line(source, line)){
|
|
|
|
String l = skip_chop_whitespace(line);
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(out, "<p>");
|
2016-11-05 02:59:35 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 start = 0, i = 0;
|
2016-11-05 02:59:35 +00:00
|
|
|
for (; i < l.size; ++i){
|
2017-04-01 06:15:33 +00:00
|
|
|
char ch = l.str[i];
|
|
|
|
switch (ch){
|
|
|
|
case '<':
|
|
|
|
{
|
|
|
|
append_ss(out, substr(l, start, i-start));
|
|
|
|
append_sc(out, "<");
|
|
|
|
start = i+1;
|
|
|
|
}break;
|
2016-11-05 02:59:35 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
case '>':
|
|
|
|
{
|
|
|
|
append_ss(out, substr(l, start, i-start));
|
|
|
|
append_sc(out, ">");
|
|
|
|
start = i+1;
|
|
|
|
}break;
|
2016-11-05 02:59:35 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
case '\\':
|
|
|
|
{
|
|
|
|
append_ss(out, substr(l, start, i-start));
|
|
|
|
|
|
|
|
i32 command_start = i+1;
|
|
|
|
i32 command_end = command_start;
|
|
|
|
for (; command_end < l.size; ++command_end){
|
|
|
|
if (!char_is_alpha_numeric(l.str[command_end])){
|
|
|
|
break;
|
|
|
|
}
|
2016-11-05 02:59:35 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
|
|
|
|
if (command_end == command_start){
|
|
|
|
if (command_end < l.size && l.str[command_end] == '\\'){
|
|
|
|
++command_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String command_string = substr(l, command_start, command_end - command_start);
|
|
|
|
|
|
|
|
enum Command_Types{
|
|
|
|
Cmd_BackSlash,
|
|
|
|
Cmd_Version,
|
|
|
|
Cmd_BeginStyle,
|
|
|
|
Cmd_EndStyle,
|
|
|
|
Cmd_DocLink,
|
|
|
|
Cmd_BeginList,
|
|
|
|
Cmd_EndList,
|
|
|
|
Cmd_BeginItem,
|
|
|
|
Cmd_EndItem,
|
|
|
|
Cmd_BoldFace,
|
|
|
|
Cmd_Section,
|
|
|
|
Cmd_BeginLink,
|
|
|
|
Cmd_EndLink,
|
|
|
|
Cmd_Image,
|
|
|
|
Cmd_Video,
|
|
|
|
// never below this
|
|
|
|
Cmd_COUNT,
|
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
local_persist String enriched_commands[Cmd_COUNT];
|
2017-04-01 06:15:33 +00:00
|
|
|
|
|
|
|
enriched_commands[Cmd_BackSlash] = make_lit_string("\\");
|
|
|
|
enriched_commands[Cmd_Version] = make_lit_string("VERSION");
|
|
|
|
enriched_commands[Cmd_BeginStyle] = make_lit_string("BEGIN_STYLE");
|
|
|
|
enriched_commands[Cmd_EndStyle] = make_lit_string("END_STYLE");
|
|
|
|
enriched_commands[Cmd_DocLink] = make_lit_string("DOC_LINK");
|
|
|
|
enriched_commands[Cmd_BeginList] = make_lit_string("BEGIN_LIST");
|
|
|
|
enriched_commands[Cmd_EndList] = make_lit_string("END_LIST");
|
|
|
|
enriched_commands[Cmd_BeginItem] = make_lit_string("BEGIN_ITEM");
|
|
|
|
enriched_commands[Cmd_EndItem] = make_lit_string("END_ITEM");
|
|
|
|
enriched_commands[Cmd_BoldFace] = make_lit_string("BOLD_FACE");
|
|
|
|
enriched_commands[Cmd_Section] = make_lit_string("SECTION");
|
|
|
|
enriched_commands[Cmd_BeginLink] = make_lit_string("BEGIN_LINK");
|
|
|
|
enriched_commands[Cmd_EndLink] = make_lit_string("END_LINK");
|
|
|
|
enriched_commands[Cmd_Image] = make_lit_string("IMAGE");
|
|
|
|
enriched_commands[Cmd_Video] = make_lit_string("VIDEO");
|
|
|
|
|
|
|
|
i = command_end;
|
|
|
|
|
|
|
|
i32 match_index = 0;
|
|
|
|
if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){
|
|
|
|
switch (match_index){
|
|
|
|
case Cmd_BackSlash: append_sc(out, "\\"); break;
|
|
|
|
case Cmd_Version: append_sc(out, VERSION); break;
|
|
|
|
|
|
|
|
case Cmd_BeginStyle:
|
|
|
|
{
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
|
|
|
if (has_body){
|
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
|
|
|
if (match_sc(body_text, "code")){
|
|
|
|
append_sc(out, "<span style='"HTML_CODE_STYLE"'>");
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_EndStyle:
|
|
|
|
{
|
|
|
|
append_sc(out, "</span>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
// TODO(allen): upgrade this bs
|
|
|
|
case Cmd_DocLink:
|
|
|
|
{
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
|
|
|
if (has_body){
|
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
|
|
|
append_sc(out, "<a href='#");
|
|
|
|
append_ss(out, body_text);
|
|
|
|
append_sc(out, "_doc'>");
|
|
|
|
append_ss(out, body_text);
|
|
|
|
append_sc(out, "</a>");
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_BeginList:
|
|
|
|
{
|
|
|
|
append_sc(out,"<ul style='margin-top: 5mm; margin-left: 1mm;'>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_EndList:
|
|
|
|
{
|
|
|
|
append_sc(out, "</ul>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_BeginItem:
|
|
|
|
{
|
|
|
|
if (item_counter == 0){
|
|
|
|
append_sc(out, "<li style='font-size: 95%; background: #EFEFDF;'>");
|
|
|
|
++item_counter;
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-04-01 06:15:33 +00:00
|
|
|
append_sc(out, "<li style='font-size: 95%;'>");
|
|
|
|
item_counter = 0;
|
2016-11-24 06:02:18 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
2016-12-08 17:16:50 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
case Cmd_EndItem:
|
|
|
|
{
|
|
|
|
append_sc(out, "</li>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_Section:
|
|
|
|
{
|
|
|
|
// TODO(allen): undo the duplication of this body extraction code.
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
2016-12-08 17:16:50 +00:00
|
|
|
if (has_body){
|
2017-04-01 06:15:33 +00:00
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
|
|
|
|
|
|
|
html_render_section_header(out, body_text, null_string, section_counter);
|
|
|
|
++section_counter->counter[section_counter->nest_level];
|
|
|
|
item_counter = 0;
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_BeginLink:
|
|
|
|
{
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
|
|
|
if (has_body){
|
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
|
|
|
|
|
|
|
append_sc(out, "<a ");
|
|
|
|
if (body_text.str[0] == '!'){
|
|
|
|
append_sc(out, "target='_blank' ");
|
|
|
|
body_text.str++;
|
|
|
|
body_text.size--;
|
|
|
|
}
|
|
|
|
append_sc(out, "href='");
|
|
|
|
if (match_part_sc(body_text, "document:")){
|
|
|
|
String doc_name = substr_tail(body_text, sizeof("document:")-1);
|
|
|
|
Abstract_Item *doc_lookup = get_item_by_name(doc_system->doc_list, doc_name);
|
|
|
|
if (doc_lookup){
|
|
|
|
char space[256];
|
|
|
|
if (doc_get_link_string(doc_lookup, space, sizeof(space))){
|
|
|
|
append_sc(out, space);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
NotImplemented;
|
|
|
|
}
|
2016-12-08 17:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
else{
|
|
|
|
append_ss(out, body_text);
|
|
|
|
}
|
|
|
|
append_sc(out, "'>");
|
2016-12-08 17:16:50 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_EndLink:
|
|
|
|
{
|
|
|
|
append_sc(out, "</a>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Cmd_Image:
|
|
|
|
{
|
|
|
|
// TODO(allen): generalize this
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
if (has_body){
|
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
i32 pixel_height = 10;
|
|
|
|
i32 pixel_width = HTML_WIDTH;
|
|
|
|
|
|
|
|
body_start = 0, body_end = 0;
|
|
|
|
has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 0);
|
|
|
|
if (has_body){
|
|
|
|
String size_parameter = substr(l, body_start, body_end - body_start);
|
|
|
|
if (match_part_sc(size_parameter, "width:")){
|
|
|
|
String width_string = substr_tail(size_parameter, sizeof("width:")-1);
|
|
|
|
if (str_is_int_s(width_string)){
|
|
|
|
pixel_width = str_to_int_s(width_string);
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (match_part_sc(body_text, "image:")){
|
|
|
|
String img_name = substr_tail(body_text, sizeof("image:")-1);
|
|
|
|
Abstract_Item *img_lookup = get_item_by_name(doc_system->img_list, img_name);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
if (img_lookup){
|
|
|
|
pixel_height = ceil32(pixel_width*img_lookup->h_w_ratio);
|
|
|
|
|
|
|
|
append_sc(out, "<img src='");
|
|
|
|
|
|
|
|
char space[256];
|
|
|
|
if (img_get_link_string(img_lookup, space, sizeof(space), pixel_width, pixel_height)){
|
|
|
|
append_sc(out, space);
|
2017-07-10 14:51:19 +00:00
|
|
|
add_image_instantiation(&img_lookup->img_instantiations, pixel_width, pixel_height);
|
2017-04-01 06:15:33 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
append_sc(out, "' style='width: ");
|
|
|
|
append_int_to_str(out, pixel_width);
|
|
|
|
append_sc(out, "px; height: ");
|
|
|
|
append_int_to_str(out, pixel_height);
|
|
|
|
append_sc(out, "px;'>");
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
2016-12-08 17:16:50 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
case Cmd_Video:
|
|
|
|
{
|
|
|
|
// TODO(allen): generalize this
|
|
|
|
i32 body_start = 0, body_end = 0;
|
|
|
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
|
|
|
|
|
|
|
i32 pixel_width = HTML_WIDTH;
|
|
|
|
i32 pixel_height = (i32)(pixel_width * 0.5625);
|
2016-12-08 17:16:50 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
if (has_body){
|
|
|
|
String body_text = substr(l, body_start, body_end - body_start);
|
|
|
|
body_text = skip_chop_whitespace(body_text);
|
2016-12-08 17:16:50 +00:00
|
|
|
|
2017-04-01 06:15:33 +00:00
|
|
|
if (match_part_sc(body_text, "youtube:")){
|
|
|
|
String youtube_str = substr_tail(body_text, sizeof("youtube:")-1);
|
|
|
|
|
|
|
|
append_sc(out, "<iframe width='");
|
|
|
|
append_int_to_str(out, pixel_width);
|
|
|
|
append_sc(out, "' height='");
|
|
|
|
append_int_to_str(out, pixel_height);
|
|
|
|
append_sc(out, "' src='");
|
|
|
|
append_ss(out, youtube_str);
|
|
|
|
append_sc(out, "' allowfullscreen> </iframe>");
|
|
|
|
}
|
2016-12-08 17:16:50 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
}break;
|
|
|
|
}
|
2016-11-05 02:59:35 +00:00
|
|
|
}
|
2017-04-01 06:15:33 +00:00
|
|
|
else{
|
|
|
|
append_sc(out, "<span style='color:#F00'>! Doc generator error: unrecognized command !</span>");
|
|
|
|
fprintf(stderr, "error: unrecognized command %.*s\n", command_string.size, command_string.str);
|
|
|
|
}
|
|
|
|
|
|
|
|
start = i;
|
2016-11-05 02:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start != i){
|
|
|
|
append_ss(out, substr(l, start, i-start));
|
|
|
|
}
|
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(out, "</p>");
|
|
|
|
}
|
|
|
|
|
|
|
|
append_sc(out, "</div>");
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
print_item_in_list(String *out, String name, char *id_postfix){
|
|
|
|
append_sc(out, "<li><a href='#");
|
|
|
|
append_ss(out, name);
|
|
|
|
append_sc(out, id_postfix);
|
|
|
|
append_sc(out, "'>");
|
|
|
|
append_ss(out, name);
|
|
|
|
append_sc(out, "</a></li>");
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
init_used_links(Used_Links *used, i32 count){
|
|
|
|
used->strs = fm_push_array(String, count);
|
2016-11-28 19:13:53 +00:00
|
|
|
used->count = 0;
|
|
|
|
used->max = count;
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal i32
|
2016-11-28 19:13:53 +00:00
|
|
|
try_to_use(Used_Links *used, String str){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 result = 1;
|
|
|
|
i32 index = 0;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (string_set_match(used->strs, used->count, str, &index)){
|
|
|
|
result = 0;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
else{
|
|
|
|
used->strs[used->count++] = str;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2017-01-07 02:59:55 +00:00
|
|
|
print_struct_html(String *out, Item_Node *member, i32 hide_children){
|
2016-11-28 19:13:53 +00:00
|
|
|
String name = member->name;
|
|
|
|
String type = member->type;
|
|
|
|
String type_postfix = member->type_postfix;
|
|
|
|
|
|
|
|
append_ss (out, type);
|
|
|
|
append_s_char (out, ' ');
|
|
|
|
append_ss (out, name);
|
|
|
|
append_ss (out, type_postfix);
|
|
|
|
|
|
|
|
if (match_ss(type, make_lit_string("struct")) ||
|
|
|
|
match_ss(type, make_lit_string("union"))){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (hide_children){
|
|
|
|
append_sc(out, " { /* non-public internals */ } ;");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, " {<br><div style='margin-left: 8mm;'>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (Item_Node *member_iter = member->first_child;
|
|
|
|
member_iter != 0;
|
|
|
|
member_iter = member_iter->next_sibling){
|
|
|
|
print_struct_html(out, member_iter, hide_children);
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
append_sc(out, "</div>};<br>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
else{
|
|
|
|
append_sc(out, ";<br>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
print_function_html(String *out, Used_Links *used, String cpp_name, String ret, char *function_call_head, String name, Argument_Breakdown breakdown){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_ss (out, ret);
|
|
|
|
append_s_char (out, ' ');
|
|
|
|
append_sc (out, function_call_head);
|
|
|
|
append_ss (out, name);
|
|
|
|
|
|
|
|
if (breakdown.count == 0){
|
|
|
|
append_sc(out, "()");
|
|
|
|
}
|
|
|
|
else if (breakdown.count == 1){
|
|
|
|
append_sc(out, "(");
|
|
|
|
append_ss(out, breakdown.args[0].param_string);
|
|
|
|
append_sc(out, ")");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc(out, "(<div style='margin-left: 4mm;'>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 j = 0; j < breakdown.count; ++j){
|
2016-11-28 19:13:53 +00:00
|
|
|
append_ss(out, breakdown.args[j].param_string);
|
|
|
|
if (j < breakdown.count - 1){
|
|
|
|
append_s_char(out, ',');
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, "<br>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
append_sc(out, "</div>)");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
print_macro_html(String *out, String name, Argument_Breakdown breakdown){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc (out, "#define ");
|
|
|
|
append_ss (out, name);
|
|
|
|
|
|
|
|
if (breakdown.count == 0){
|
|
|
|
append_sc(out, "()");
|
|
|
|
}
|
|
|
|
else if (breakdown.count == 1){
|
|
|
|
append_s_char (out, '(');
|
|
|
|
append_ss (out, breakdown.args[0].param_string);
|
|
|
|
append_s_char (out, ')');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc (out, "(<div style='margin-left: 4mm;'>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 j = 0; j < breakdown.count; ++j){
|
2016-11-28 19:13:53 +00:00
|
|
|
append_ss(out, breakdown.args[j].param_string);
|
|
|
|
if (j < breakdown.count - 1){
|
|
|
|
append_s_char(out, ',');
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, "<br>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
append_sc(out, ")</div>)");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Doc_Chunk_Type{
|
|
|
|
DocChunk_PlainText,
|
|
|
|
DocChunk_CodeExample,
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
DocChunk_Count
|
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
global String doc_chunk_headers[] = {
|
2016-11-28 19:13:53 +00:00
|
|
|
make_lit_string(""),
|
|
|
|
make_lit_string("CODE_EXAMPLE"),
|
|
|
|
};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal String
|
2016-11-28 19:13:53 +00:00
|
|
|
get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
|
|
|
String chunk = {0};
|
|
|
|
String word = {0};
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 pos = source.size;
|
|
|
|
i32 word_index = 0;
|
2016-11-28 19:13:53 +00:00
|
|
|
Doc_Chunk_Type t = DocChunk_PlainText;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 start_pos = (i32)(prev_chunk.str - source.str) + prev_chunk.size;
|
2016-11-28 19:13:53 +00:00
|
|
|
String source_tail = substr_tail(source, start_pos);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
Assert(DocChunk_Count == ArrayCount(doc_chunk_headers));
|
|
|
|
|
|
|
|
for (word = get_first_word(source_tail);
|
|
|
|
word.str;
|
|
|
|
word = get_next_word(source_tail, word), ++word_index){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 i = 1; i < DocChunk_Count; ++i){
|
2016-11-28 19:13:53 +00:00
|
|
|
if (match_ss(word, doc_chunk_headers[i])){
|
2017-01-07 02:59:55 +00:00
|
|
|
pos = (i32)(word.str - source.str);
|
2016-11-28 19:13:53 +00:00
|
|
|
t = (Doc_Chunk_Type)i;
|
|
|
|
goto doublebreak;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
doublebreak:;
|
|
|
|
|
|
|
|
*type = DocChunk_PlainText;
|
|
|
|
if (word_index == 0){
|
|
|
|
*type = t;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 nest_level = 1;
|
|
|
|
i32 i = find_s_char(source, pos, '(');
|
2016-11-28 19:13:53 +00:00
|
|
|
for (++i; i < source.size; ++i){
|
|
|
|
if (source.str[i] == '('){
|
|
|
|
++nest_level;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
else if (source.str[i] == ')'){
|
|
|
|
--nest_level;
|
|
|
|
if (nest_level == 0){
|
|
|
|
break;
|
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
pos = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk = substr(source, start_pos, pos - start_pos);
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 is_all_white = 1;
|
|
|
|
for (i32 i = 0; i < chunk.size; ++i){
|
2016-11-28 19:13:53 +00:00
|
|
|
if (!char_is_whitespace(chunk.str[i])){
|
|
|
|
is_all_white = 0;
|
|
|
|
break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (is_all_white){
|
|
|
|
chunk = null_string;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
return(chunk);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal String
|
2016-11-28 19:13:53 +00:00
|
|
|
get_first_doc_chunk(String source, Doc_Chunk_Type *type){
|
|
|
|
String start_str = make_string(source.str, 0);
|
|
|
|
String chunk = get_next_doc_chunk(source, start_str, type);
|
|
|
|
return(chunk);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
print_doc_description(String *out, String src){
|
2016-11-28 19:13:53 +00:00
|
|
|
Doc_Chunk_Type type;
|
|
|
|
|
|
|
|
for (String chunk = get_first_doc_chunk(src, &type);
|
|
|
|
chunk.str;
|
|
|
|
chunk = get_next_doc_chunk(src, chunk, &type)){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
switch (type){
|
|
|
|
case DocChunk_PlainText:
|
|
|
|
{
|
|
|
|
for (String line = get_first_double_line(chunk);
|
|
|
|
line.str;
|
|
|
|
line = get_next_double_line(chunk, line)){
|
|
|
|
append_ss(out, line);
|
|
|
|
append_sc(out, "<br><br>");
|
|
|
|
}
|
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
case DocChunk_CodeExample:
|
|
|
|
{
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 start = 0;
|
|
|
|
i32 end = chunk.size-1;
|
2016-11-28 19:13:53 +00:00
|
|
|
while (start < end && chunk.str[start] != '(') ++start;
|
|
|
|
start += 1;
|
|
|
|
while (end > start && chunk.str[end] != ')') --end;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
append_sc(out, HTML_EXAMPLE_CODE_OPEN);
|
|
|
|
|
|
|
|
if (start < end){
|
|
|
|
String code_example = substr(chunk, start, end - start);
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 first_line = 1;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (String line = get_first_line(code_example);
|
|
|
|
line.str;
|
|
|
|
line = get_next_line(code_example, line)){
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (!(first_line && line.size == 0)){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 space_i = 0;
|
2016-11-28 19:13:53 +00:00
|
|
|
for (; space_i < line.size; ++space_i){
|
|
|
|
if (line.str[space_i] == ' '){
|
|
|
|
append_sc(out, " ");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
String line_tail = substr_tail(line, space_i);
|
|
|
|
append_ss(out, line_tail);
|
|
|
|
append_sc(out, "<br>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
first_line = 0;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_EXAMPLE_CODE_CLOSE);
|
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
print_struct_docs(String *out, Item_Node *member){
|
2016-11-28 19:13:53 +00:00
|
|
|
for (Item_Node *member_iter = member->first_child;
|
|
|
|
member_iter != 0;
|
|
|
|
member_iter = member_iter->next_sibling){
|
|
|
|
String type = member_iter->type;
|
|
|
|
if (match_ss(type, make_lit_string("struct")) ||
|
|
|
|
match_ss(type, make_lit_string("union"))){
|
2017-07-10 14:51:19 +00:00
|
|
|
print_struct_docs(out, member_iter);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
Documentation doc = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(member_iter->doc_string, &doc);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, "<div>");
|
|
|
|
|
|
|
|
append_sc(out, "<div style='"HTML_CODE_STYLE"'>"HTML_DOC_ITEM_HEAD_INL_OPEN);
|
|
|
|
append_ss(out, member_iter->name);
|
|
|
|
append_sc(out, HTML_DOC_ITEM_HEAD_INL_CLOSE"</div>");
|
|
|
|
|
|
|
|
append_sc(out, "<div style='margin-bottom: 6mm;'>"HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, doc.main_doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE"</div>");
|
|
|
|
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
2016-11-28 19:13:53 +00:00
|
|
|
print_see_also(String *out, Documentation *doc){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 doc_see_count = doc->see_also_count;
|
2016-11-28 19:13:53 +00:00
|
|
|
if (doc_see_count > 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"See Also"HTML_DOC_HEAD_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 j = 0; j < doc_see_count; ++j){
|
2016-11-28 19:13:53 +00:00
|
|
|
String see_also = doc->see_also[j];
|
|
|
|
append_sc(out, HTML_DOC_ITEM_OPEN"<a href='#");
|
|
|
|
append_ss(out, see_also);
|
|
|
|
append_sc(out, "_doc'>");
|
|
|
|
append_ss(out, see_also);
|
|
|
|
append_sc(out, "</a>"HTML_DOC_ITEM_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
print_function_docs(String *out, String name, String doc_string){
|
2016-11-28 19:13:53 +00:00
|
|
|
if (doc_string.size == 0){
|
|
|
|
append_sc(out, "No documentation generated for this function.");
|
|
|
|
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
Temp temp = fm_begin_temp();
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
Documentation doc = {0};
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(doc_string, &doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 doc_param_count = doc.param_count;
|
2016-11-28 19:13:53 +00:00
|
|
|
if (doc_param_count > 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Parameters"HTML_DOC_HEAD_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 j = 0; j < doc_param_count; ++j){
|
2016-11-28 19:13:53 +00:00
|
|
|
String param_name = doc.param_name[j];
|
|
|
|
String param_docs = doc.param_docs[j];
|
|
|
|
|
|
|
|
// TODO(allen): check that param_name is actually
|
|
|
|
// a parameter to this function!
|
|
|
|
|
|
|
|
append_sc(out, "<div>"HTML_DOC_ITEM_HEAD_OPEN);
|
|
|
|
append_ss(out, param_name);
|
|
|
|
append_sc(out, HTML_DOC_ITEM_HEAD_CLOSE"<div style='margin-bottom: 6mm;'>"HTML_DOC_ITEM_OPEN);
|
|
|
|
append_ss(out, param_docs);
|
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE"</div></div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String ret_doc = doc.return_doc;
|
|
|
|
if (ret_doc.size != 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Return"HTML_DOC_HEAD_CLOSE HTML_DOC_ITEM_OPEN);
|
|
|
|
append_ss(out, ret_doc);
|
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
String main_doc = doc.main_doc;
|
|
|
|
if (main_doc.size != 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, main_doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_see_also(out, &doc);
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
fm_end_temp(temp);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
print_item_html(String *out, Used_Links *used, Item_Node *item, char *id_postfix, char *section, i32 I, Alternate_Name *alt_name, i32 alt_name_type){
|
|
|
|
Temp temp = fm_begin_temp();
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
String name = item->name;
|
|
|
|
|
|
|
|
switch (alt_name_type){
|
|
|
|
case AltName_Macro:
|
|
|
|
{
|
|
|
|
name = alt_name->macro;
|
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
case AltName_Public_Name:
|
|
|
|
{
|
|
|
|
name = alt_name->public_name;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE(allen):
|
|
|
|
Open a div for the whole item.
|
|
|
|
Put a heading in it with the name and section.
|
|
|
|
Open a "descriptive" box for the display of the code interface.
|
|
|
|
*/
|
|
|
|
append_sc(out, "<div id='");
|
|
|
|
append_ss(out, name);
|
|
|
|
append_sc(out, id_postfix);
|
|
|
|
append_sc(out, "' style='margin-bottom: 1cm;'>");
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 has_cpp_name = 0;
|
2016-11-28 19:13:53 +00:00
|
|
|
if (item->cpp_name.str != 0){
|
|
|
|
if (try_to_use(used, item->cpp_name)){
|
|
|
|
append_sc(out, "<div id='");
|
|
|
|
append_ss(out, item->cpp_name);
|
|
|
|
append_sc(out, id_postfix);
|
|
|
|
append_sc(out, "'>");
|
|
|
|
has_cpp_name = 1;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc (out, "<h4>§");
|
|
|
|
append_sc (out, section);
|
|
|
|
append_s_char (out, '.');
|
|
|
|
append_int_to_str (out, I);
|
|
|
|
append_sc (out, ": ");
|
|
|
|
append_ss (out, name);
|
|
|
|
append_sc (out, "</h4>");
|
|
|
|
|
|
|
|
append_sc(out, "<div style='"HTML_CODE_STYLE" "HTML_DESCRIPT_SECTION_STYLE"'>");
|
|
|
|
|
|
|
|
switch (item->t){
|
|
|
|
case Item_Function:
|
|
|
|
{
|
|
|
|
// NOTE(allen): Code box
|
|
|
|
print_function_html(out, used, item->cpp_name, item->ret, "", name, item->breakdown);
|
|
|
|
|
|
|
|
// NOTE(allen): Close the code box
|
|
|
|
append_sc(out, "</div>");
|
|
|
|
|
|
|
|
// NOTE(allen): Descriptive section
|
2017-07-10 14:51:19 +00:00
|
|
|
print_function_docs(out, name, item->doc_string);
|
2016-11-28 19:13:53 +00:00
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
case Item_Macro:
|
|
|
|
{
|
|
|
|
// NOTE(allen): Code box
|
|
|
|
print_macro_html(out, name, item->breakdown);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Close the code box
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Descriptive section
|
2017-07-10 14:51:19 +00:00
|
|
|
print_function_docs(out, name, item->doc_string);
|
2016-11-28 19:13:53 +00:00
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
case Item_Typedef:
|
|
|
|
{
|
|
|
|
String type = item->type;
|
|
|
|
|
|
|
|
// NOTE(allen): Code box
|
|
|
|
append_sc (out, "typedef ");
|
|
|
|
append_ss (out, type);
|
|
|
|
append_s_char (out, ' ');
|
|
|
|
append_ss (out, name);
|
|
|
|
append_s_char (out, ';');
|
|
|
|
|
|
|
|
// NOTE(allen): Close the code box
|
|
|
|
append_sc(out, "</div>");
|
|
|
|
|
|
|
|
// NOTE(allen): Descriptive section
|
|
|
|
String doc_string = item->doc_string;
|
|
|
|
Documentation doc = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(doc_string, &doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
String main_doc = doc.main_doc;
|
|
|
|
if (main_doc.size != 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
|
|
|
|
|
|
|
|
append_sc(out, HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, main_doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
else{
|
|
|
|
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_see_also(out, &doc);
|
|
|
|
|
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
case Item_Enum:
|
|
|
|
{
|
|
|
|
// NOTE(allen): Code box
|
|
|
|
append_sc (out, "enum ");
|
|
|
|
append_ss (out, name);
|
|
|
|
append_s_char (out, ';');
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Close the code box
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Descriptive section
|
|
|
|
String doc_string = item->doc_string;
|
|
|
|
Documentation doc = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(doc_string, &doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
String main_doc = doc.main_doc;
|
|
|
|
if (main_doc.size != 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, main_doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->first_child){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Values"HTML_DOC_HEAD_CLOSE);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
for (Item_Node *member = item->first_child;
|
|
|
|
member;
|
|
|
|
member = member->next_sibling){
|
|
|
|
Documentation doc = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(member->doc_string, &doc);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, "<div>");
|
|
|
|
|
|
|
|
// NOTE(allen): Dafuq is this all?
|
|
|
|
append_sc(out, "<div><span style='"HTML_CODE_STYLE"'>"HTML_DOC_ITEM_HEAD_INL_OPEN);
|
|
|
|
append_ss(out, member->name);
|
|
|
|
append_sc(out, HTML_DOC_ITEM_HEAD_INL_CLOSE);
|
|
|
|
|
|
|
|
if (member->value.str){
|
|
|
|
append_sc(out, " = ");
|
|
|
|
append_ss(out, member->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
append_sc(out, "</span></div>");
|
|
|
|
|
|
|
|
append_sc(out, "<div style='margin-bottom: 6mm;'>"HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, doc.main_doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE"</div>");
|
|
|
|
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_see_also(out, &doc);
|
|
|
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Item_Struct: case Item_Union:
|
|
|
|
{
|
|
|
|
String doc_string = item->doc_string;
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 hide_members = 0;
|
2016-11-28 19:13:53 +00:00
|
|
|
|
|
|
|
if (doc_string.size == 0){
|
|
|
|
hide_members = 1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for (String word = get_first_word(doc_string);
|
|
|
|
word.str;
|
|
|
|
word = get_next_word(doc_string, word)){
|
|
|
|
if (match_ss(word, make_lit_string("HIDE_MEMBERS"))){
|
|
|
|
hide_members = 1;
|
|
|
|
break;
|
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Code box
|
|
|
|
print_struct_html(out, item, hide_members);
|
|
|
|
|
|
|
|
// NOTE(allen): Close the code box
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Descriptive section
|
2016-11-10 03:18:22 +00:00
|
|
|
{
|
|
|
|
Documentation doc = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
perform_doc_parse(doc_string, &doc);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
|
|
|
String main_doc = doc.main_doc;
|
|
|
|
if (main_doc.size != 0){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Description"HTML_DOC_HEAD_CLOSE);
|
|
|
|
|
|
|
|
append_sc(out, HTML_DOC_ITEM_OPEN);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_doc_description(out, main_doc);
|
2016-11-10 03:18:22 +00:00
|
|
|
append_sc(out, HTML_DOC_ITEM_CLOSE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fprintf(stderr, "warning: no documentation string for %.*s\n", name.size, name.str);
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (!hide_members){
|
|
|
|
if (item->first_child){
|
|
|
|
append_sc(out, HTML_DOC_HEAD_OPEN"Fields"HTML_DOC_HEAD_CLOSE);
|
2017-07-10 14:51:19 +00:00
|
|
|
print_struct_docs(out, item);
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print_see_also(out, &doc);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_cpp_name){
|
|
|
|
append_sc(out, "</div>");
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
// NOTE(allen): Close the item box
|
|
|
|
append_sc(out, "</div><hr>");
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
fm_end_temp(temp);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
doc_item_head_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
|
2016-11-03 21:37:29 +00:00
|
|
|
switch (item->type){
|
|
|
|
case Doc_Root:
|
|
|
|
{
|
|
|
|
append_sc(out,
|
|
|
|
"<html lang=\"en-US\">"
|
|
|
|
"<head>"
|
2016-12-08 17:16:50 +00:00
|
|
|
"<link rel='shortcut icon' type='image/x-icon' href='4coder_icon.ico' />"
|
2016-11-03 21:37:29 +00:00
|
|
|
"<title>");
|
2016-11-05 02:59:35 +00:00
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
append_ss(out, item->section.name);
|
2016-11-05 02:59:35 +00:00
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
append_sc(out,
|
|
|
|
"</title>"
|
|
|
|
"<style>"
|
|
|
|
|
|
|
|
"body { "
|
|
|
|
"background: " HTML_BACK_COLOR "; "
|
|
|
|
"color: " HTML_TEXT_COLOR "; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
// H things
|
|
|
|
"h1,h2,h3,h4 { "
|
|
|
|
"color: " HTML_POP_COLOR_1 "; "
|
|
|
|
"margin: 0; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
"h2 { "
|
|
|
|
"margin-top: 6mm; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
"h3 { "
|
|
|
|
"margin-top: 5mm; margin-bottom: 5mm; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
"h4 { "
|
|
|
|
"font-size: 1.1em; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
// ANCHORS
|
|
|
|
"a { "
|
|
|
|
"color: " HTML_POP_COLOR_1 "; "
|
|
|
|
"text-decoration: none; "
|
|
|
|
"}"
|
|
|
|
"a:visited { "
|
|
|
|
"color: " HTML_VISITED_LINK "; "
|
|
|
|
"}"
|
|
|
|
"a:hover { "
|
|
|
|
"background: " HTML_POP_BACK_1 "; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
// LIST
|
|
|
|
"ul { "
|
|
|
|
"list-style: none; "
|
|
|
|
"padding: 0; "
|
|
|
|
"margin: 0; "
|
|
|
|
"}"
|
|
|
|
|
|
|
|
"</style>"
|
|
|
|
"</head>\n"
|
|
|
|
"<body>"
|
|
|
|
"<div style='font-family:Arial; margin: 0 auto; "
|
2016-11-28 19:13:53 +00:00
|
|
|
"width: ");
|
|
|
|
append_int_to_str(out, HTML_WIDTH);
|
|
|
|
append_sc(out, "px; text-align: justify; line-height: 1.25;'>");
|
2016-11-03 21:37:29 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
if (item->section.show_title){
|
|
|
|
append_sc(out, "<h1 style='margin-top: 5mm; margin-bottom: 5mm;'>");
|
|
|
|
append_ss(out, item->section.name);
|
|
|
|
append_sc(out, "</h1>");
|
|
|
|
}
|
2016-11-03 21:37:29 +00:00
|
|
|
}break;
|
|
|
|
|
|
|
|
case Doc_Section:
|
|
|
|
{
|
2016-11-22 18:26:58 +00:00
|
|
|
html_render_section_header(out, item->section.name, item->section.id, section_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
}break;
|
|
|
|
|
2016-11-10 03:18:22 +00:00
|
|
|
case Doc_Todo:
|
|
|
|
{
|
|
|
|
append_sc(out, "<div><i>Coming Soon</i><div>");
|
|
|
|
}break;
|
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
case Doc_Enriched_Text:
|
|
|
|
{
|
2017-07-10 14:51:19 +00:00
|
|
|
write_enriched_text_html(out, item->text.text, doc_system, section_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
}break;
|
|
|
|
|
2016-11-10 03:18:22 +00:00
|
|
|
case Doc_Element_List:
|
|
|
|
{
|
|
|
|
append_sc(out, "<ul>");
|
|
|
|
|
|
|
|
Meta_Unit *unit = item->unit_elements.unit;
|
|
|
|
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 count = unit->set.count;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-28 19:13:53 +00:00
|
|
|
switch (item->unit_elements.alt_name_type){
|
|
|
|
case AltName_Standard:
|
|
|
|
{
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 i = 0; i < count; ++i){
|
2016-11-28 19:13:53 +00:00
|
|
|
print_item_in_list(out, unit->set.items[i].name, "_doc");
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case AltName_Macro:
|
|
|
|
{
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 i = 0; i < count; ++i){
|
2016-11-28 19:13:53 +00:00
|
|
|
print_item_in_list(out, alt_names->names[i].macro, "_doc");
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case AltName_Public_Name:
|
|
|
|
{
|
2017-01-07 02:59:55 +00:00
|
|
|
for (i32 i = 0; i < count; ++i){
|
2016-11-28 19:13:53 +00:00
|
|
|
print_item_in_list(out, alt_names->names[i].public_name, "_doc");
|
|
|
|
}
|
|
|
|
}break;
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
append_sc(out, "</ul>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Doc_Full_Elements:
|
|
|
|
{
|
|
|
|
Meta_Unit *unit = item->unit_elements.unit;
|
|
|
|
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 count = unit->set.count;
|
2016-11-10 03:18:22 +00:00
|
|
|
|
|
|
|
char section_space[32];
|
|
|
|
String section_str = make_fixed_width_string(section_space);
|
|
|
|
append_section_number_reduced(§ion_str, section_counter, 1);
|
|
|
|
terminate_with_null(§ion_str);
|
|
|
|
|
|
|
|
if (alt_names){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 I = 1;
|
|
|
|
for (i32 i = 0; i < count; ++i, ++I){
|
2017-07-10 14:51:19 +00:00
|
|
|
print_item_html(out, used_links, &unit->set.items[i], "_doc", section_str.str, I, &alt_names->names[i], item->unit_elements.alt_name_type);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
else{
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 I = 1;
|
|
|
|
for (i32 i = 0; i < count; ++i, ++I){
|
2017-07-10 14:51:19 +00:00
|
|
|
print_item_html(out, used_links, &unit->set.items[i], "_doc", section_str.str, I, 0, 0);
|
2016-11-28 19:13:53 +00:00
|
|
|
}
|
2016-11-10 03:18:22 +00:00
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
case Doc_Table_Of_Contents:
|
|
|
|
{
|
|
|
|
append_sc(out, "<h3 style='margin:0;'>Table of Contents</h3><ul>");
|
|
|
|
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 i = 1;
|
2016-11-03 21:37:29 +00:00
|
|
|
for (Document_Item *toc_item = item->parent->section.first_child;
|
|
|
|
toc_item != 0;
|
|
|
|
toc_item = toc_item->next){
|
|
|
|
if (toc_item->type == Doc_Section){
|
|
|
|
if (toc_item->section.id.size > 0){
|
2016-11-28 19:13:53 +00:00
|
|
|
append_sc(out, "<li><a href='#section_");
|
|
|
|
append_ss(out, toc_item->section.id);
|
|
|
|
append_sc(out, "'>§");
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
append_sc(out, "<li>§");
|
|
|
|
}
|
2016-11-28 19:13:53 +00:00
|
|
|
append_int_to_str (out, i);
|
|
|
|
append_s_char (out, ' ');
|
2016-11-03 21:37:29 +00:00
|
|
|
append_ss (out, toc_item->section.name);
|
|
|
|
append_sc (out, "</a></li>");
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
append_sc(out, "</ul>");
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
doc_item_foot_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
|
2016-11-03 21:37:29 +00:00
|
|
|
switch (item->type){
|
|
|
|
case Doc_Root:
|
|
|
|
{
|
|
|
|
append_sc(out, "</div></body></html>");
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case Doc_Section: break;
|
|
|
|
|
|
|
|
case Doc_Table_Of_Contents: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
generate_item_html(String *out, Document_System *doc_system, Used_Links *used_links, Document_Item *item, Section_Counter *section_counter){
|
|
|
|
doc_item_head_html(out, doc_system, used_links, item, section_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
|
|
|
|
if (item->type == Doc_Root || item->type == Doc_Section){
|
2017-01-07 02:59:55 +00:00
|
|
|
i32 level = ++section_counter->nest_level;
|
2016-11-03 21:37:29 +00:00
|
|
|
section_counter->counter[level] = 1;
|
|
|
|
for (Document_Item *m = item->section.first_child;
|
|
|
|
m != 0;
|
|
|
|
m = m->next){
|
2017-07-10 14:51:19 +00:00
|
|
|
generate_item_html(out, doc_system, used_links, m, section_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
--section_counter->nest_level;
|
|
|
|
++section_counter->counter[section_counter->nest_level];
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
doc_item_foot_html(out, doc_system, used_links, item, section_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 14:51:19 +00:00
|
|
|
internal void
|
|
|
|
generate_document_html(String *out, Document_System *doc_system, Abstract_Item *doc){
|
|
|
|
Assert(doc->root_item != 0);
|
2016-11-28 19:13:53 +00:00
|
|
|
|
2016-11-10 03:18:22 +00:00
|
|
|
Used_Links used_links = {0};
|
2017-07-10 14:51:19 +00:00
|
|
|
init_used_links(&used_links, 4000);
|
2016-11-10 03:18:22 +00:00
|
|
|
|
2016-11-03 21:37:29 +00:00
|
|
|
Section_Counter section_counter = {0};
|
|
|
|
section_counter.counter[section_counter.nest_level] = 1;
|
2017-07-10 14:51:19 +00:00
|
|
|
generate_item_html(out, doc_system, &used_links, doc->root_item, §ion_counter);
|
2016-11-03 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|