]> 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 e8c095d10dbc2dea323101dd4ffccc962d497933..493cdbd7cb8f1cf21ec8b77fc01b4f8309040a06 100644 (file)
--- a/munge.cpp
+++ b/munge.cpp
@@ -60,7 +60,7 @@ int main(int argc, char * argv[])
 
        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;
@@ -104,6 +104,7 @@ int main(int argc, char * argv[])
                                        }
                                        else if (strcmp(keyword, "part") == 0)
                                        {
+                                               lastLevel = level;
                                                int len = strlen(token);
 
                                                if (len == 4)
@@ -148,6 +149,17 @@ int main(int argc, char * argv[])
 
                                        startLine = lineCount;
 
+                                       // Cleanup our chapter content
+                                       if (lastLevel == 1)
+                                       {
+                                               if (newFile != NULL)
+                                               {
+                                                       fprintf(newFile, "\n{%% children %%}\n\n");
+                                                       fclose(newFile);
+                                                       newFile = NULL;
+                                               }
+                                       }
+
                                        if (level == 0)
                                        {
                                                // Parts & chapters don't have any content...
@@ -186,16 +198,16 @@ int main(int argc, char * argv[])
 
                                                // 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)
                                        {
@@ -250,7 +262,7 @@ int main(int argc, char * argv[])
                }
                else
                {
-                       if ((level == 2) && (newFile != NULL))
+                       if (((level == 1) || (level == 2)) && (newFile != NULL))
                                fprintf(newFile, "%s\n", buffer);
                }
        }