switched to Document_Builder helper struct, compressed add_* functions
							parent
							
								
									64c19f4f12
								
							
						
					
					
						commit
						090d51dff0
					
				| 
						 | 
					@ -99,14 +99,6 @@ struct Document_Item{
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
global Document_Item null_document_item = {0};
 | 
					global Document_Item null_document_item = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum{
 | 
					 | 
				
			||||||
    ItemType_Document,
 | 
					 | 
				
			||||||
    ItemType_Image,
 | 
					 | 
				
			||||||
    ItemType_GenericFile,
 | 
					 | 
				
			||||||
    // never below this
 | 
					 | 
				
			||||||
    ItemType_COUNT,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct Basic_Node{
 | 
					struct Basic_Node{
 | 
				
			||||||
    Basic_Node *next;
 | 
					    Basic_Node *next;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -118,43 +110,6 @@ struct Basic_List{
 | 
				
			||||||
    Basic_Node *tail;
 | 
					    Basic_Node *tail;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Abstract_Item{
 | 
					 | 
				
			||||||
    i32 item_type;
 | 
					 | 
				
			||||||
    char *name;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // Document value members
 | 
					 | 
				
			||||||
    Document_Item *root_item;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // TODO(allen): make these external
 | 
					 | 
				
			||||||
    // Document building members
 | 
					 | 
				
			||||||
    Document_Item *section_stack[16];
 | 
					 | 
				
			||||||
    i32 section_top;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // Image value members
 | 
					 | 
				
			||||||
    char *source_file;
 | 
					 | 
				
			||||||
    char *extension;
 | 
					 | 
				
			||||||
    float w_h_ratio;
 | 
					 | 
				
			||||||
    float h_w_ratio;
 | 
					 | 
				
			||||||
    Basic_List img_instantiations;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
global Abstract_Item null_abstract_item = {0};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct Image_Instantiation{
 | 
					 | 
				
			||||||
    i32 w, h;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct Document_System{
 | 
					 | 
				
			||||||
    Basic_List doc_list;
 | 
					 | 
				
			||||||
    Basic_List img_list;
 | 
					 | 
				
			||||||
    Basic_List file_list;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
internal Document_System
 | 
					 | 
				
			||||||
create_document_system(){
 | 
					 | 
				
			||||||
    Document_System system = {0};
 | 
					 | 
				
			||||||
    return(system);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
internal void*
 | 
					internal void*
 | 
				
			||||||
push_item_on_list(Basic_List *list, i32 item_size){
 | 
					push_item_on_list(Basic_List *list, i32 item_size){
 | 
				
			||||||
    i32 mem_size = item_size + sizeof(Basic_Node);
 | 
					    i32 mem_size = item_size + sizeof(Basic_Node);
 | 
				
			||||||
| 
						 | 
					@ -172,10 +127,57 @@ push_item_on_list(Basic_List *list, i32 item_size){
 | 
				
			||||||
        list->tail = node;
 | 
					        list->tail = node;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    void *result = (node+1);
 | 
					    void *result = (node + 1);
 | 
				
			||||||
    return(result);
 | 
					    return(result);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum{
 | 
				
			||||||
 | 
					    ItemType_Document,
 | 
				
			||||||
 | 
					    ItemType_Image,
 | 
				
			||||||
 | 
					    ItemType_GenericFile,
 | 
				
			||||||
 | 
					    // never below this
 | 
				
			||||||
 | 
					    ItemType_COUNT,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Abstract_Item{
 | 
				
			||||||
 | 
					    i32 item_type;
 | 
				
			||||||
 | 
					    char *name;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Document value members
 | 
				
			||||||
 | 
					    Document_Item *root_item;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Image value members
 | 
				
			||||||
 | 
					    char *source_file;
 | 
				
			||||||
 | 
					    char *extension;
 | 
				
			||||||
 | 
					    float w_h_ratio;
 | 
				
			||||||
 | 
					    float h_w_ratio;
 | 
				
			||||||
 | 
					    Basic_List img_instantiations;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					global Abstract_Item null_abstract_item = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Document_Builder{
 | 
				
			||||||
 | 
					    Abstract_Item *doc;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Document_Item *section_stack[16];
 | 
				
			||||||
 | 
					    i32 section_top;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Image_Instantiation{
 | 
				
			||||||
 | 
					    i32 w, h;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Document_System{
 | 
				
			||||||
 | 
					    Basic_List doc_list;
 | 
				
			||||||
 | 
					    Basic_List img_list;
 | 
				
			||||||
 | 
					    Basic_List file_list;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal Document_System
 | 
				
			||||||
 | 
					create_document_system(){
 | 
				
			||||||
 | 
					    Document_System system = {0};
 | 
				
			||||||
 | 
					    return(system);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal Abstract_Item*
 | 
					internal Abstract_Item*
 | 
				
			||||||
get_item_by_name(Basic_List list, String name){
 | 
					get_item_by_name(Basic_List list, String name){
 | 
				
			||||||
    Abstract_Item *result = 0;
 | 
					    Abstract_Item *result = 0;
 | 
				
			||||||
| 
						 | 
					@ -299,32 +301,47 @@ set_section_id(Document_Item *item, char *id){
 | 
				
			||||||
    append(&item->section.id, id);
 | 
					    append(&item->section.id, id);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
begin_document_description(Abstract_Item *doc, char *title, b32 show_title){
 | 
					begin_document_description(Document_Builder *builder, char *title, b32 show_title){
 | 
				
			||||||
 | 
					    Abstract_Item *doc = builder->doc;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    *doc = null_abstract_item;
 | 
					    *doc = null_abstract_item;
 | 
				
			||||||
    doc->item_type = ItemType_Document;
 | 
					    doc->item_type = ItemType_Document;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    doc->root_item = fm_push_array(Document_Item, 1);
 | 
					    doc->root_item = fm_push_array(Document_Item, 1);
 | 
				
			||||||
    *doc->root_item = null_document_item;
 | 
					    *doc->root_item = null_document_item;
 | 
				
			||||||
    doc->section_stack[doc->section_top] = doc->root_item;
 | 
					    set_section_name(doc->root_item, title, show_title);
 | 
				
			||||||
    doc->root_item->type = Doc_Root;
 | 
					    doc->root_item->type = Doc_Root;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    set_section_name(doc->root_item, title, show_title);
 | 
					    builder->section_stack[builder->section_top] = doc->root_item;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal Abstract_Item*
 | 
					internal Document_Builder
 | 
				
			||||||
begin_document_description(Document_System *system, char *title, char *name, b32 show_title){
 | 
					begin_document_description(Document_System *system, char *title, char *name, b32 show_title){
 | 
				
			||||||
    Abstract_Item *item = create_item(&system->doc_list, name);
 | 
					    Document_Builder builder = {0};
 | 
				
			||||||
    if (item){
 | 
					    Abstract_Item *doc = create_item(&system->doc_list, name);
 | 
				
			||||||
        begin_document_description(item, title, show_title);
 | 
					    if (doc != 0){
 | 
				
			||||||
        item->name = name;
 | 
					        builder.doc = doc;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        *doc = null_abstract_item;
 | 
				
			||||||
 | 
					        doc->item_type = ItemType_Document;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        doc->root_item = fm_push_array(Document_Item, 1);
 | 
				
			||||||
 | 
					        *doc->root_item = null_document_item;
 | 
				
			||||||
 | 
					        set_section_name(doc->root_item, title, show_title);
 | 
				
			||||||
 | 
					        doc->name = name;
 | 
				
			||||||
 | 
					        doc->root_item->type = Doc_Root;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        builder.section_stack[builder.section_top] = doc->root_item;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return(item);
 | 
					    return(builder);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
end_document_description(Abstract_Item *item){
 | 
					end_document_description(Document_Builder *builder){
 | 
				
			||||||
    Assert(item->section_top == 0);
 | 
					    Assert(builder->section_top == 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
| 
						 | 
					@ -340,236 +357,145 @@ append_child(Document_Item *parent, Document_Item *item){
 | 
				
			||||||
    item->parent = parent;
 | 
					    item->parent = parent;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					internal Document_Item*
 | 
				
			||||||
 | 
					doc_new_item(Document_Builder *builder, u32 type){
 | 
				
			||||||
 | 
					    Assert(builder->section_top + 1 < ArrayCount(builder->section_stack));
 | 
				
			||||||
 | 
					    Document_Item *parent = builder->section_stack[builder->section_top];
 | 
				
			||||||
 | 
					    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
				
			||||||
 | 
					    *item = null_document_item;
 | 
				
			||||||
 | 
					    item->type = type;
 | 
				
			||||||
 | 
					    append_child(parent, item);
 | 
				
			||||||
 | 
					    return(item);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
begin_section(Abstract_Item *item, char *title, char *id){
 | 
					begin_section(Document_Builder *builder, char *title, char *id){
 | 
				
			||||||
    Assert(item->section_top + 1 < ArrayCount(item->section_stack));
 | 
					    Document_Item *section = doc_new_item(builder, Doc_Section);
 | 
				
			||||||
    
 | 
					    builder->section_stack[++builder->section_top] = section;
 | 
				
			||||||
    Document_Item *parent = item->section_stack[item->section_top];
 | 
					 | 
				
			||||||
    Document_Item *section = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *section = null_document_item;
 | 
					 | 
				
			||||||
    item->section_stack[++item->section_top] = section;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    section->type = Doc_Section;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    set_section_name(section, title, true);
 | 
					    set_section_name(section, title, true);
 | 
				
			||||||
    if (id != 0){
 | 
					    if (id != 0){
 | 
				
			||||||
        set_section_id(section, id);
 | 
					        set_section_id(section, id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, section);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
end_section(Abstract_Item *doc){
 | 
					end_section(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top > 0);
 | 
					    Assert(builder->section_top > 0);
 | 
				
			||||||
    --doc->section_top;
 | 
					    --builder->section_top;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_error(Abstract_Item *doc, String text){
 | 
					add_error(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Assert(builder->section_top + 1 < ArrayCount(builder->section_stack));
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					    Document_Item *item = doc_new_item(builder, Doc_Error);
 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Error;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
report_error_missing_body(Abstract_Item *doc, String command_body){
 | 
					report_error_missing_body(Document_Builder *builder, String command_body){
 | 
				
			||||||
    char space[512];
 | 
					    char space[512];
 | 
				
			||||||
    String error_string = make_fixed_width_string(space);
 | 
					    String error_string = make_fixed_width_string(space);
 | 
				
			||||||
    append(&error_string, "missing body for ");
 | 
					    append(&error_string, "missing body for ");
 | 
				
			||||||
    append(&error_string, command_body);
 | 
					    append(&error_string, command_body);
 | 
				
			||||||
    add_error(doc, error_string);
 | 
					    add_error(builder, error_string);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_todo(Abstract_Item *doc){
 | 
					add_todo(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_Todo);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Todo;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_element_list(Abstract_Item *doc, Meta_Unit *unit){
 | 
					add_element_list(Document_Builder *builder, Meta_Unit *unit){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_DocList);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_DocList;
 | 
					 | 
				
			||||||
    item->unit_elements.unit = unit;
 | 
					    item->unit_elements.unit = unit;
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
 | 
					add_element_list(Document_Builder *builder, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_DocList);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_DocList;
 | 
					 | 
				
			||||||
    item->unit_elements.unit = unit;
 | 
					    item->unit_elements.unit = unit;
 | 
				
			||||||
    item->unit_elements.alt_names = alt_names;
 | 
					    item->unit_elements.alt_names = alt_names;
 | 
				
			||||||
    item->unit_elements.alt_name_type = alt_name_type;
 | 
					    item->unit_elements.alt_name_type = alt_name_type;
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
 | 
					add_full_elements(Document_Builder *builder, Meta_Unit *unit){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_DocFull);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_DocFull;
 | 
					 | 
				
			||||||
    item->unit_elements.unit = unit;
 | 
					    item->unit_elements.unit = unit;
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
 | 
					add_full_elements(Document_Builder *builder, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_DocFull);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_DocFull;
 | 
					 | 
				
			||||||
    item->unit_elements.unit = unit;
 | 
					    item->unit_elements.unit = unit;
 | 
				
			||||||
    item->unit_elements.alt_names = alt_names;
 | 
					    item->unit_elements.alt_names = alt_names;
 | 
				
			||||||
    item->unit_elements.alt_name_type = alt_name_type;
 | 
					    item->unit_elements.alt_name_type = alt_name_type;
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_table_of_contents(Abstract_Item *doc){
 | 
					add_table_of_contents(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_TableOfContents);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_TableOfContents;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_plain_old_text(Abstract_Item *doc, String text){
 | 
					add_plain_old_text(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_PlainOldText);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_PlainOldText;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
 | 
					add_enriched_text(Document_Builder *builder, Enriched_Text *text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_PlainOldText);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Include;
 | 
					 | 
				
			||||||
    item->enriched_text.text = text;
 | 
					    item->enriched_text.text = text;
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_version(Abstract_Item *doc){
 | 
					add_version(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_Version);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Version;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_begin_style(Abstract_Item *doc, String text){
 | 
					add_begin_style(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_BeginStyle);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_BeginStyle;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_end_style(Abstract_Item *doc){
 | 
					add_end_style(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_EndStyle);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_EndStyle;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_document_link(Abstract_Item *doc, String text){
 | 
					add_document_link(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_BeginStyle);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_DocumentLink;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_begin_link(Abstract_Item *doc, String text){
 | 
					add_begin_link(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_BeginLink);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_BeginLink;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_end_link(Abstract_Item *doc){
 | 
					add_end_link(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_EndLink);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_EndLink;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_image(Abstract_Item *doc, String text, String extra_text){
 | 
					add_image(Document_Builder *builder, String text, String extra_text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_Image);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Image;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
| 
						 | 
					@ -578,88 +504,44 @@ add_image(Abstract_Item *doc, String text, String extra_text){
 | 
				
			||||||
        fm_align();
 | 
					        fm_align();
 | 
				
			||||||
        copy(&item->string.string2, extra_text);
 | 
					        copy(&item->string.string2, extra_text);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_video(Abstract_Item *doc, String text){
 | 
					add_video(Document_Builder *builder, String text){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    Document_Item *item = doc_new_item(builder, Doc_Video);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_Video;
 | 
					 | 
				
			||||||
    item->string.string = str_alloc(text.size);
 | 
					    item->string.string = str_alloc(text.size);
 | 
				
			||||||
    fm_align();
 | 
					    fm_align();
 | 
				
			||||||
    copy(&item->string.string, text);
 | 
					    copy(&item->string.string, text);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_begin_paragraph(Abstract_Item *doc){
 | 
					add_begin_paragraph(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_BeginParagraph);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_BeginParagraph;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_end_paragraph(Abstract_Item *doc){
 | 
					add_end_paragraph(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_EndParagraph);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_EndParagraph;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_begin_list(Abstract_Item *doc){
 | 
					add_begin_list(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_BeginList);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_BeginList;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_end_list(Abstract_Item *doc){
 | 
					add_end_list(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_EndList);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_EndList;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_begin_item(Abstract_Item *doc){
 | 
					add_begin_item(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_BeginItem);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_BeginItem;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal void
 | 
					internal void
 | 
				
			||||||
add_end_item(Abstract_Item *doc){
 | 
					add_end_item(Document_Builder *builder){
 | 
				
			||||||
    Assert(doc->section_top + 1 < ArrayCount(doc->section_stack));
 | 
					    doc_new_item(builder, Doc_EndItem);
 | 
				
			||||||
    Document_Item *parent = doc->section_stack[doc->section_top];
 | 
					 | 
				
			||||||
    Document_Item *item = fm_push_array(Document_Item, 1);
 | 
					 | 
				
			||||||
    *item = null_document_item;
 | 
					 | 
				
			||||||
    item->type = Doc_EndItem;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    append_child(parent, item);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Document Generation from Enriched Text
 | 
					// Document Generation from Enriched Text
 | 
				
			||||||
| 
						 | 
					@ -767,7 +649,7 @@ extract_command_body(String l, i32 *i_in_out, String *body_text_out){
 | 
				
			||||||
internal Abstract_Item*
 | 
					internal Abstract_Item*
 | 
				
			||||||
make_document_from_text(Document_System *doc_system, char *title, char *name, Enriched_Text *text){
 | 
					make_document_from_text(Document_System *doc_system, char *title, char *name, Enriched_Text *text){
 | 
				
			||||||
    String source = text->source;
 | 
					    String source = text->source;
 | 
				
			||||||
    Abstract_Item *doc = begin_document_description(doc_system, title, name, false);
 | 
					    Document_Builder builder = begin_document_description(doc_system, title, name, false);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    for (String line = get_first_double_line(source);
 | 
					    for (String line = get_first_double_line(source);
 | 
				
			||||||
         line.str;
 | 
					         line.str;
 | 
				
			||||||
| 
						 | 
					@ -775,13 +657,13 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
        String l = skip_chop_whitespace(line);
 | 
					        String l = skip_chop_whitespace(line);
 | 
				
			||||||
        if (l.size == 0) continue;
 | 
					        if (l.size == 0) continue;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        add_begin_paragraph(doc);
 | 
					        add_begin_paragraph(&builder);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        i32 start = 0, i = 0;
 | 
					        i32 start = 0, i = 0;
 | 
				
			||||||
        for (; i < l.size; ++i){
 | 
					        for (; i < l.size; ++i){
 | 
				
			||||||
            char ch = l.str[i];
 | 
					            char ch = l.str[i];
 | 
				
			||||||
            if (ch == '\\'){
 | 
					            if (ch == '\\'){
 | 
				
			||||||
                add_plain_old_text(doc, substr(l, start, i - start));
 | 
					                add_plain_old_text(&builder, substr(l, start, i - start));
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                i32 command_start = i + 1;
 | 
					                i32 command_start = i + 1;
 | 
				
			||||||
                i32 command_end = command_start;
 | 
					                i32 command_end = command_start;
 | 
				
			||||||
| 
						 | 
					@ -812,7 +694,7 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                switch (match_index){
 | 
					                switch (match_index){
 | 
				
			||||||
                    case Cmd_BackSlash:
 | 
					                    case Cmd_BackSlash:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_plain_old_text(doc, make_lit_string("\\"));
 | 
					                        add_plain_old_text(&builder, make_lit_string("\\"));
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_BeginStyle:
 | 
					                    case Cmd_BeginStyle:
 | 
				
			||||||
| 
						 | 
					@ -820,16 +702,16 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        String body_text = {0};
 | 
					                        String body_text = {0};
 | 
				
			||||||
                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
					                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
				
			||||||
                        if (has_body){
 | 
					                        if (has_body){
 | 
				
			||||||
                            add_begin_style(doc, body_text);
 | 
					                            add_begin_style(&builder, body_text);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_EndStyle:
 | 
					                    case Cmd_EndStyle:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_end_style(doc);
 | 
					                        add_end_style(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    // TODO(allen): upgrade this bs
 | 
					                    // TODO(allen): upgrade this bs
 | 
				
			||||||
| 
						 | 
					@ -838,31 +720,31 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        String body_text = {0};
 | 
					                        String body_text = {0};
 | 
				
			||||||
                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
					                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
				
			||||||
                        if (has_body){
 | 
					                        if (has_body){
 | 
				
			||||||
                            add_document_link(doc, body_text);
 | 
					                            add_document_link(&builder, body_text);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_BeginList:
 | 
					                    case Cmd_BeginList:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_begin_list(doc);
 | 
					                        add_begin_list(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_EndList:
 | 
					                    case Cmd_EndList:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_end_list(doc);
 | 
					                        add_end_list(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_BeginItem:
 | 
					                    case Cmd_BeginItem:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_begin_item(doc);
 | 
					                        add_begin_item(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_EndItem:
 | 
					                    case Cmd_EndItem:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_end_item(doc);
 | 
					                        add_end_item(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_BeginLink:
 | 
					                    case Cmd_BeginLink:
 | 
				
			||||||
| 
						 | 
					@ -870,16 +752,16 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        String body_text = {0};
 | 
					                        String body_text = {0};
 | 
				
			||||||
                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
					                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
				
			||||||
                        if (has_body){
 | 
					                        if (has_body){
 | 
				
			||||||
                            add_begin_link(doc, body_text);
 | 
					                            add_begin_link(&builder, body_text);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_EndLink:
 | 
					                    case Cmd_EndLink:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_end_link(doc);
 | 
					                        add_end_link(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_Image:
 | 
					                    case Cmd_Image:
 | 
				
			||||||
| 
						 | 
					@ -889,10 +771,10 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        if (has_body){
 | 
					                        if (has_body){
 | 
				
			||||||
                            String size_parameter = {0};
 | 
					                            String size_parameter = {0};
 | 
				
			||||||
                            extract_command_body(l, &i, &size_parameter);
 | 
					                            extract_command_body(l, &i, &size_parameter);
 | 
				
			||||||
                            add_image(doc, body_text, size_parameter);
 | 
					                            add_image(&builder, body_text, size_parameter);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
| 
						 | 
					@ -901,10 +783,10 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        String body_text = {0};
 | 
					                        String body_text = {0};
 | 
				
			||||||
                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
					                        b32 has_body = extract_command_body(l, &i, &body_text);
 | 
				
			||||||
                        if (has_body){
 | 
					                        if (has_body){
 | 
				
			||||||
                            add_video(doc, body_text);
 | 
					                            add_video(&builder, body_text);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
| 
						 | 
					@ -924,31 +806,31 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                            copy(&id, extra_text);
 | 
					                            copy(&id, extra_text);
 | 
				
			||||||
                            terminate_with_null(&id);
 | 
					                            terminate_with_null(&id);
 | 
				
			||||||
                            
 | 
					                            
 | 
				
			||||||
                            begin_section(doc, title.str, id.str);
 | 
					                            begin_section(&builder, title.str, id.str);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        else{
 | 
					                        else{
 | 
				
			||||||
                            report_error_missing_body(doc, command_string);
 | 
					                            report_error_missing_body(&builder, command_string);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_EndSection:
 | 
					                    case Cmd_EndSection:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        end_section(doc);
 | 
					                        end_section(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_Version:
 | 
					                    case Cmd_Version:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_version(doc);
 | 
					                        add_version(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_TableOfContents:
 | 
					                    case Cmd_TableOfContents:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_table_of_contents(doc);
 | 
					                        add_table_of_contents(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    case Cmd_Todo:
 | 
					                    case Cmd_Todo:
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        add_todo(doc);
 | 
					                        add_todo(&builder);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    default:
 | 
					                    default:
 | 
				
			||||||
| 
						 | 
					@ -957,7 +839,7 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
                        String error = make_fixed_width_string(space);
 | 
					                        String error = make_fixed_width_string(space);
 | 
				
			||||||
                        append(&error, "unrecognized command ");
 | 
					                        append(&error, "unrecognized command ");
 | 
				
			||||||
                        append(&error, command_string);
 | 
					                        append(&error, command_string);
 | 
				
			||||||
                        add_error(doc, error);
 | 
					                        add_error(&builder, error);
 | 
				
			||||||
                    }break;
 | 
					                    }break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
| 
						 | 
					@ -966,14 +848,14 @@ make_document_from_text(Document_System *doc_system, char *title, char *name, En
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if (start != i){
 | 
					        if (start != i){
 | 
				
			||||||
            add_plain_old_text(doc, substr(l, start, i - start));
 | 
					            add_plain_old_text(&builder, substr(l, start, i - start));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        add_end_paragraph(doc);
 | 
					        add_end_paragraph(&builder);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    end_document_description(doc);
 | 
					    end_document_description(&builder);
 | 
				
			||||||
    return(doc);
 | 
					    return(builder.doc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HTML Document Generation
 | 
					// HTML Document Generation
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,72 +109,72 @@ generate_4coder_docs(Document_System *doc_system, char *code_directory, char *sr
 | 
				
			||||||
    *lexer_introduction = load_enriched_text(src_directory, "lexer_introduction.txt");
 | 
					    *lexer_introduction = load_enriched_text(src_directory, "lexer_introduction.txt");
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // NOTE(allen): Put together the abstract document
 | 
					    // NOTE(allen): Put together the abstract document
 | 
				
			||||||
    Abstract_Item *doc = begin_document_description(doc_system, "4coder API Docs", "custom_docs", true);
 | 
					    Document_Builder builder = begin_document_description(doc_system, "4coder API Docs", "custom_docs", true);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    add_table_of_contents(doc);
 | 
					    add_table_of_contents(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    begin_section(doc, "Introduction", "introduction");
 | 
					    begin_section(&builder, "Introduction", "introduction");
 | 
				
			||||||
    add_enriched_text(doc, introduction);
 | 
					    add_enriched_text(&builder, introduction);
 | 
				
			||||||
    end_section(doc);
 | 
					    end_section(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    begin_section(doc, "4coder Systems", "4coder_systems");
 | 
					    begin_section(&builder, "4coder Systems", "4coder_systems");
 | 
				
			||||||
    add_todo(doc);
 | 
					    add_todo(&builder);
 | 
				
			||||||
    end_section(doc);
 | 
					    end_section(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    begin_section(doc, "Types and Functions", "types_and_functions");
 | 
					    begin_section(&builder, "Types and Functions", "types_and_functions");
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        begin_section(doc, "Function List", 0);
 | 
					        begin_section(&builder, "Function List", 0);
 | 
				
			||||||
        add_element_list(doc, custom_funcs_unit, custom_func_names, AltName_Public_Name);
 | 
					        add_element_list(&builder, custom_funcs_unit, custom_func_names, AltName_Public_Name);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Type List", 0);
 | 
					        begin_section(&builder, "Type List", 0);
 | 
				
			||||||
        add_element_list(doc, custom_types_unit);
 | 
					        add_element_list(&builder, custom_types_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Function Descriptions", 0);
 | 
					        begin_section(&builder, "Function Descriptions", 0);
 | 
				
			||||||
        add_full_elements(doc, custom_funcs_unit, custom_func_names, AltName_Public_Name);
 | 
					        add_full_elements(&builder, custom_funcs_unit, custom_func_names, AltName_Public_Name);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Type Descriptions", 0);
 | 
					        begin_section(&builder, "Type Descriptions", 0);
 | 
				
			||||||
        add_full_elements(doc, custom_types_unit);
 | 
					        add_full_elements(&builder, custom_types_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    end_section(doc);
 | 
					    end_section(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    begin_section(doc, "String Library", "string_library");
 | 
					    begin_section(&builder, "String Library", "string_library");
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        begin_section(doc, "String Library Intro", 0);
 | 
					        begin_section(&builder, "String Library Intro", 0);
 | 
				
			||||||
        add_todo(doc);
 | 
					        add_todo(&builder);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "String Function List", 0);
 | 
					        begin_section(&builder, "String Function List", 0);
 | 
				
			||||||
        add_element_list(doc, string_unit);
 | 
					        add_element_list(&builder, string_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "String Function Descriptions", 0);
 | 
					        begin_section(&builder, "String Function Descriptions", 0);
 | 
				
			||||||
        add_full_elements(doc, string_unit);
 | 
					        add_full_elements(&builder, string_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    end_section(doc);
 | 
					    end_section(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    begin_section(doc, "Lexer Library", "lexer_library");
 | 
					    begin_section(&builder, "Lexer Library", "lexer_library");
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        begin_section(doc, "Lexer Intro", 0);
 | 
					        begin_section(&builder, "Lexer Intro", 0);
 | 
				
			||||||
        add_enriched_text(doc, lexer_introduction);
 | 
					        add_enriched_text(&builder, lexer_introduction);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Lexer Function List", 0);
 | 
					        begin_section(&builder, "Lexer Function List", 0);
 | 
				
			||||||
        add_element_list(doc, lexer_funcs_unit);
 | 
					        add_element_list(&builder, lexer_funcs_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Lexer Type List", 0);
 | 
					        begin_section(&builder, "Lexer Type List", 0);
 | 
				
			||||||
        add_element_list(doc, lexer_types_unit);
 | 
					        add_element_list(&builder, lexer_types_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Lexer Function Descriptions", 0);
 | 
					        begin_section(&builder, "Lexer Function Descriptions", 0);
 | 
				
			||||||
        add_full_elements(doc, lexer_funcs_unit);
 | 
					        add_full_elements(&builder, lexer_funcs_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
        begin_section(doc, "Lexer Type Descriptions", 0);
 | 
					        begin_section(&builder, "Lexer Type Descriptions", 0);
 | 
				
			||||||
        add_full_elements(doc, lexer_types_unit);
 | 
					        add_full_elements(&builder, lexer_types_unit);
 | 
				
			||||||
        end_section(doc);
 | 
					        end_section(&builder);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    end_section(doc);
 | 
					    end_section(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    end_document_description(doc);
 | 
					    end_document_description(&builder);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return(doc);
 | 
					    return(builder.doc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
internal Abstract_Item*
 | 
					internal Abstract_Item*
 | 
				
			||||||
| 
						 | 
					@ -277,6 +277,8 @@ generate_site(char *code_directory, char *asset_directory, char *src_directory,
 | 
				
			||||||
    generate_page(docs, cdir, sdir, "roadmap.txt"     , "4coder Roadmap"     , "roadmap"     );
 | 
					    generate_page(docs, cdir, sdir, "roadmap.txt"     , "4coder Roadmap"     , "roadmap"     );
 | 
				
			||||||
    generate_page(docs, cdir, sdir, "tutorials.txt"   , "4coder Tutorials"   , "tutorials"   );
 | 
					    generate_page(docs, cdir, sdir, "tutorials.txt"   , "4coder Tutorials"   , "tutorials"   );
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    //resolve_all_includes(&doc_system);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    for (Basic_Node *node = doc_system.doc_list.head;
 | 
					    for (Basic_Node *node = doc_system.doc_list.head;
 | 
				
			||||||
         node != 0;
 | 
					         node != 0;
 | 
				
			||||||
         node = node->next){
 | 
					         node = node->next){
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue