/* _write_hhp: */ static int _write_hhp(const char *filename) { FILE *file = fopen(filename, "wt"); TOC *toc; int section_number = -1; char *stripped_filename, *p; if (!file) return 1; stripped_filename = m_strdup(get_filename(filename)); if ((p = get_extension(stripped_filename))) *(p-1) = 0; fprintf(file, "[OPTIONS]\n"); fprintf(file, "Compiled file=%s.chm\n", stripped_filename); fprintf(file, "Contents file=%s.hhc\n", stripped_filename); fprintf(file, "Default topic=%s.%s\n", stripped_filename, html_extension); fprintf(file, "Full-text search=Yes\n"); fprintf(file, "Index file=%s.hhk\n", stripped_filename); fprintf(file, "Language=0x409 English (USA)\n"); if((html_flags & HTML_DOCUMENT_TITLE_FLAG) && !(html_flags & HTML_OLD_H_TAG_FLAG)) fprintf(file, "Title=%s\n", html_document_title); else { /* Write the filename without extension and capitalized */ fputc(toupper(*stripped_filename), file); fprintf(file, "%s", stripped_filename+1); } fprintf(file, "\n"); fprintf(file, "[FILES]\n"); free(stripped_filename); toc = tochead; if (toc) toc = toc->next; for (; toc; toc = toc->next) { if (toc->htmlable && toc->root) { char name[256]; if (toc->otherfile) { sprintf(name, "%s.%s", toc->text, html_extension); } else { section_number++; get_section_filename(name, filename, section_number); } mystrlwr(name); fprintf(file, "%s\n", name); } } return 0; }
virtual const char * stristr(const char *str,const char *key) // case insensitive ststr { HACD_ASSERT( strlen(str) < 2048 ); HACD_ASSERT( strlen(key) < 2048 ); char istr[2048]; char ikey[2048]; strncpy(istr,str,2048); strncpy(ikey,key,2048); mystrlwr(istr); mystrlwr(ikey); char *foo = strstr(istr,ikey); if ( foo ) { uint32_t loc = (uint32_t)(foo - istr); foo = (char *)str+loc; } return foo; }
static int emit_code_table(const char *to) { const char *tmp = "vmi.tmp"; FILE *out = fopen(tmp, "w"); int i; fprintf(out, "/* File: %s\n\n", to); fprintf(out, " This file provides a description of the virtual machine instructions\n"); fprintf(out, " and their arguments. It is used by pl-comp.c to facilitate the\n"); fprintf(out, " compiler and decompiler, as well as pl-wic.c to save/reload sequences\n"); fprintf(out, " of virtual machine qinstructions.\n"); fprintf(out, "\n"); fprintf(out, " Note: this file is generated by %s from %s. DO NOT EDIT", program, vmi_file); fprintf(out, " \n"); fprintf(out, "*/\n\n"); fprintf(out, "#include \"pl-incl.h\"\n\n"); fprintf(out, "const code_info codeTable[] = {\n"); fprintf(out, " /* {name, ID, flags, #args, argtype} */\n"); for(i=0; i<vmi_count; i++) { char name[100]; fprintf(out, " {\"%s\", %s, %s, %s, {%s}},\n", mystrlwr(name, vmi_list[i].name), vmi_list[i].name, vmi_list[i].flags, vmi_list[i].argc, vmi_list[i].args[0] ? vmi_list[i].args : "0"); } fprintf(out, " { NULL, 0, 0, 0, {0} }\n"); fprintf(out, "};\n"); fclose(out); return update_file(tmp, to); }
/* _write_toc: * Outputs a .hhc or .hhk file which are needed by the HTML Help compiler * (along with a .hhp and the standard HTML docs) to generate the CHM docs. * is_index is a boolean, and tells if the output file should be a chm * index file. The main difference is that the internal structure is * slightly different, and it doesn't need toc sorting. */ static int _write_toc(const char *filename, int is_index) { BTOC btoc[TOC_SIZE]; FILE *file = fopen(filename, "wt"); TOC *toc; int btoc_prev[TOC_SIZE]; int section_number = -1, prev = 0, num_btoc = 0; int in_chapter = 0; if (!file) return 1; fprintf(file, "<html>\n"); fprintf(file, "<head>\n"); fprintf(file, "<title>\n"); if (is_index) fprintf(file, "Index\n"); else fprintf(file, "Contents\n"); fprintf(file, "</title>\n"); fprintf(file, "</head>\n"); fprintf(file, "<body>\n"); fprintf(file, "<ul>\n"); toc = tochead; if (toc) toc = toc->next; for (; toc; toc = toc->next) { char name[256]; if (toc->htmlable) { if (toc->root) { if (is_index) { fprintf(file, "</li>\n"); } else { _output_btoc(file, btoc, btoc_prev, &num_btoc); if (prev == PREV_SUB) fprintf(file, "</li></ul></li>\n"); if (prev == PREV_ROOT) fprintf(file, "</li>\n"); } if (toc->otherfile) { sprintf(name, "%s.%s", toc->text, html_extension); } else { section_number++; get_section_filename(name, filename, section_number); } prev = PREV_ROOT; _write_object(file, ALT_TEXT(toc), mystrlwr(name)); } else { if (is_index) { fprintf(file, "</li>\n"); } else { btoc_prev[num_btoc] = prev; } get_section_filename(name, filename, section_number); strcat(name, "#"); strcat(name, toc->text); prev = PREV_SUB; if(!is_index) { /* Buffer toc for posterior output */ btoc[num_btoc].local = m_strdup(mystrlwr(name)); btoc[num_btoc++].name = ALT_TEXT(toc); } else _write_object(file, ALT_TEXT(toc), name); } } else if ((toc->root == 2 || toc->root == 3) && !is_index) { _output_btoc(file, btoc, btoc_prev, &num_btoc); if (prev == PREV_SUB) fprintf(file, "</li></ul></li>\n"); if (prev == PREV_ROOT) fprintf(file, "</li>\n"); if (in_chapter) { fprintf(file, "</ul>\n"); in_chapter = 0; } if (toc->root == 2) { fprintf(file, "<li><object type=\"text/sitemap\">\n"); fprintf(file, "<param name=\"Name\" value=\"%s\">\n", ALT_TEXT(toc)); fprintf(file, "</object>\n</li>\n"); fprintf(file, "<ul>\n"); in_chapter = 1; } prev = 0; } } if (in_chapter) { fprintf(file, "</ul>\n"); } _output_btoc(file, btoc, btoc_prev, &num_btoc); if (prev == PREV_SUB) fprintf(file, "</li></ul></li>\n"); if (prev == PREV_ROOT) fprintf(file, "</li>\n"); fprintf(file, "</ul>\n"); fprintf(file, "</body>\n"); fprintf(file, "</html>\n"); fclose(file); return 0; }