// (C) 2017 Underground Software
//
+// still need a fix for titles with the same name...
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int part = 0, chapter = 0, subchapter = 0;
bool first = true;
bool nomove = false;
-FILE * newFile = NULL;
+FILE * newFile = NULL, * master = NULL, * exp = NULL;
char level1File[1024], level2File[1024], level3File[1024], temp[1024];
char partFN[1024], chapterFN[1024], scLink[4096];
}
+//
+// Restore the master document back to its pre-run state
+//
+void HandleFailure(void)
+{
+ // Close open files...
+ fclose(master);
+ fclose(exp);
+
+ if (newFile)
+ fclose(newFile);
+
+ // Remove our work, and restore the backup of the master document
+ remove("master-doc.txt");
+ rename("master-doc.bak", "master-doc.txt");
+}
+
+
int main(int argc, char * argv[])
{
// First, check to see if this has been run here already.
rename("master-doc.txt", "master-doc.bak");
// Then open the .bak file
- FILE * master = fopen("master-doc.bak", "r");
+ master = fopen("master-doc.bak", "r");
if (master == NULL)
{
}
// Create new master document
- FILE * exp = fopen("master-doc.txt", "w");
+ exp = fopen("master-doc.txt", "w");
if (exp == NULL)
{
if (strncmp(buffer, "---", 3) == 0)
{
// Reset the "short" title, include file & sytle
+ title[0] = 0;
shortTitle[0] = 0;
inclFile[0] = 0;
style[0] = 0;
if (!ParseHeader(master))
{
printf("Something went horribly wrong with the header parsing! Aborting!\n");
- break;
+ HandleFailure();
+ return -1;
+ }
+
+ if (strlen(title) == 0)
+ {
+ printf("Header is missing a 'title:' section, aborting!\n");
+ HandleFailure();
+ return -1;
}
// Close any previously opened files...