]> Shamusworld >> Repos - ardour-manual-diverged/blobdiff - munge.cpp
Merge branch 'master' of http://shamusworld.gotdns.org/git/ardour-manual
[ardour-manual-diverged] / munge.cpp
index 81bc38d2cf2ffa00aef7cc289d346d4a799680cf..61e1a6b7f5e1569c79a2e62d0f01b57dd94cebf0 100644 (file)
--- a/munge.cpp
+++ b/munge.cpp
@@ -11,7 +11,6 @@
 #include <string.h>
 #include <sys/stat.h>          // For mkdir()
 #include <sys/types.h>
-//#include <unistd.h>
 
 
 void MakeFilename(char * fn)
@@ -26,6 +25,8 @@ void MakeFilename(char * fn)
                        fn[i] |= 0x20;
                else if (fn[i] >= 'a' && fn[i] <= 'z')
                        ;
+               else if (fn[i] >= '0' && fn[i] <= '9')
+                       ;
                else
                        fn[i] = '_';
        }
@@ -40,22 +41,32 @@ int main(int argc, char * argv[])
 
        if (master == NULL)
        {
-               printf("Could not open master doc file!\n");
+               printf("Could not open master doc (master-doc.txt) file!\n");
                return -1;
        }
 
-       // Remove contents of _manual before writing into it...
-//     remove("./_manual/*.html");
-//     return 0;
+       FILE * toc = fopen("_manual/00_toc.html", "w");
+
+       if (toc == NULL)
+       {
+               printf("Could not open TOC file!\n");
+               fclose(master);
+               return -1;
+       }
+
+       fprintf(toc, "---\n");
+       fprintf(toc, "title: Ardour Table of Contents\n");
+       fprintf(toc, "---\n\n");
 
        char buffer[1024000], keyword[1024], token[1024];
        char title[1024], shortTitle[1024], inclFile[1024], style[1024];
-       int level = 0;
+       int level = 0, lastLevel = -1;
        int lineCount = 0, startLine, sectionLineCount;
        int part = 0, chapter = 0, subchapter = 0;
        bool first = true;
        FILE * newFile = NULL;
        char level1File[1024], level2File[1024], level3File[1024], temp[1024];
+       char partFN[1024], chapterFN[1024], scLink[4096];
 
        while (!feof(master))
        {
@@ -73,7 +84,7 @@ int main(int argc, char * argv[])
                                printf(" (%d lines)\n", sectionLineCount);
                        }
 
-                       // Reset the "short" title
+                       // Reset the "short" title, include file & sytle
                        shortTitle[0] = 0;
                        inclFile[0] = 0;
                        style[0] = 0;
@@ -93,6 +104,7 @@ int main(int argc, char * argv[])
                                        }
                                        else if (strcmp(keyword, "part") == 0)
                                        {
+                                               lastLevel = level;
                                                int len = strlen(token);
 
                                                if (len == 4)
@@ -123,9 +135,6 @@ int main(int argc, char * argv[])
                                {
                                        // We hit the end of our keyword block, now do something
                                        // about it... :-P
-//                                     for(int i=0; i<level; i++)
-//                                             printf("\t");
-
                                        if (level == 0)
                                                printf("\nPart %s: ", roman[part]);
                                        else if (level == 1)
@@ -140,6 +149,19 @@ int main(int argc, char * argv[])
 
                                        startLine = lineCount;
 
+                                       // Cleanup our chapter content
+                                       if (lastLevel == 1)
+                                       {
+                                               if (newFile != NULL)
+                                               {
+                                                       if (level == 2)
+                                                               fprintf(newFile, "\n{%% children %%}\n\n");
+
+                                                       fclose(newFile);
+                                                       newFile = NULL;
+                                               }
+                                       }
+
                                        if (level == 0)
                                        {
                                                // Parts & chapters don't have any content...
@@ -147,6 +169,11 @@ int main(int argc, char * argv[])
                                                MakeFilename(temp);
                                                sprintf(level1File, "_manual/%02d_%s", part, temp);
                                                mkdir(level1File, 0777);
+
+                                               // Set up the "part" level of TOC link
+                                               sprintf(partFN, "%s", temp);
+                                               fprintf(toc, "<h2>Part %s: %s</h2>\n", roman[part], title);
+
                                                // Make the file expected at this level...
                                                sprintf(temp, "%s.html", level1File);
                                                FILE * tfp = fopen(temp, "w");
@@ -166,18 +193,23 @@ int main(int argc, char * argv[])
                                                MakeFilename(temp);
                                                sprintf(level2File, "%s/%02d_%s", level1File, chapter, temp);
                                                mkdir(level2File, 0777);
+
+                                               // Set up the "chapter" part of the TOC link
+                                               sprintf(chapterFN, "%s", temp);
+                                               fprintf(toc, "  <p id=chapter>Ch. %d:&nbsp;&nbsp;<a href=\"/%s/%s/\">%s</a></p>\n", chapter, partFN, chapterFN, title);
+
                                                // Make the file expected at this level...
                                                sprintf(temp, "%s.html", level2File);
-                                               FILE * tfp = fopen(temp, "w");
-                                               fprintf(tfp, "---\n");
-                                               fprintf(tfp, "title: %s\n", title);
+                                               newFile = fopen(temp, "w");
+                                               fprintf(newFile, "---\n");
+                                               fprintf(newFile, "title: %s\n", title);
 
                                                if (strlen(shortTitle) > 0)
-                                                       fprintf(tfp, "menu_title: %s\n", shortTitle);
+                                                       fprintf(newFile, "menu_title: %s\n", shortTitle);
 
-                                               fprintf(tfp, "---\n");
-                                               fprintf(tfp, "\n{%% children %%}\n\n");
-                                               fclose(tfp);
+                                               fprintf(newFile, "---\n\n");
+//                                             fprintf(tfp, "\n{%% children %%}\n\n");
+//                                             fclose(tfp);
                                        }
                                        else if (level == 2)
                                        {
@@ -189,6 +221,10 @@ int main(int argc, char * argv[])
                                                if (newFile != NULL)
                                                        fclose(newFile);
 
+                                               // Make the link
+                                               sprintf(scLink, "/%s/%s/%s/", partFN, chapterFN, temp);
+                                               fprintf(toc, "    <a id=subchapter href=\"%s\">%s</a><br />\n", scLink, title);
+
                                                if (strlen(inclFile) > 0)
                                                {
                                                        // Copy the include file to the appropriate spot...
@@ -228,14 +264,15 @@ int main(int argc, char * argv[])
                }
                else
                {
-                       if ((level == 2) && (newFile != NULL))
-                               fprintf(newFile, "%s\n", buffer);//*/
+                       if (((level == 1) || (level == 2)) && (newFile != NULL))
+                               fprintf(newFile, "%s\n", buffer);
                }
        }
 
        printf("\n\nProcessed %i lines.\n", lineCount);
 
        fclose(master);
+       fclose(toc);
 
        if (newFile)
                fclose(newFile);