//===================
//======= MAIN ======
//===================
int main(int argc, const char * argv[]) {
    //Create seed for  rand() "random" num generation
    srand((unsigned int)time(NULL));
    
    //Calls function to generate new directory, return name of dir
    char* myDirName = makeMyDir();
    //Returns a 'string array' of file names, pass in directory name.
    char** roomNames= generateRoomFiles(myDirName);
    //Input game info from file, pass in file names and directory name.
    readFromFile(roomNames,myDirName);
    //Main driver of game, after game information extracted
    middleEarthAdventure(myDirName);
    
    
    
    
    //FREE UP ALLOCATED MEMORY
    int freeIt;
    for(freeIt=0;freeIt<7; freeIt++)
    {free(roomNames[freeIt]);}
    free(roomNames);
    free(myDirName);
    //---

    return 0;
}
void gitReports()
/* Generate code-review reports from git repo */
{
int totalChangedLines = 0;
int totalChangedFiles = 0;

int userChangedLines = 0;
int userChangedFiles = 0;

tempMakeDiffName = cloneString(rTempName("/tmp", "makeDiff", ".tmp"));

/* read the commits */
struct commit *commits = getCommits(), *c = NULL;
/* make the user list */
for(c = commits; c; c = c->next)
    {
    
    if (!hashLookup(userHash, c->author))
	{
	hashStore(userHash, c->author);
	struct slName *name = newSlName(c->author);
	slAddHead(&users, name);
	}
    }
slNameSort(&users);

/* create prefix dir */
char path[256];
safef(path, sizeof(path), "%s/%s", outDir, outPrefix);
makeMyDir(path);

/* create file dir */
safef(path, sizeof(path), "%s/%s/%s", outDir, outPrefix, "file");
makeMyDir(path);

/* create user dir */
safef(path, sizeof(path), "%s/%s/%s", outDir, outPrefix, "user");
makeMyDir(path);


char usersPath[1024];
safef(usersPath, sizeof(usersPath), "%s/%s/%s/index.html", outDir, outPrefix, "user");

FILE *h = mustOpen(usersPath, "w");
fprintf(h, "<html>\n<head>\n<title>Changes By User</title>\n</head>\n</body>\n");
fprintf(h, "<h1>Changes By User</h1>\n");

fprintf(h, "<h2>%s to %s (%s to %s) %s</h2>\n", startTag, endTag, startDate, endDate, title);

fprintf(h, "<ul>\n");



struct slName*u;
for(u = users; u; u = u->next)
    {
    printf("user: %s\n", u->name);

    /* create user/name dir */
    safef(path, sizeof(path), "%s/%s/%s/%s", outDir, outPrefix, "user", u->name);
    makeMyDir(path);

    /* create user/name/context dir */
    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u->name, "context");
    makeMyDir(path);

    /* create user/name/full dir */
    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u->name, "full");
    makeMyDir(path);

    userChangedLines = 0;
    userChangedFiles = 0;

    /* make user's reports */
    doUserCommits(u->name, commits, &userChangedLines, &userChangedFiles);

    doUserFiles(u->name, commits);

    char relPath[1024];
    safef(relPath, sizeof(relPath), "%s/index.html", u->name);
    fprintf(h, "<li> <A href=\"%s\">%s</A> - changed lines: %d, files: %d</li>\n", relPath, u->name, userChangedLines, userChangedFiles);

    totalChangedLines += userChangedLines;
    totalChangedFiles += userChangedFiles;  

    }

fprintf(h, "</ul>\n");
if (u)
    {
    fprintf(h, "switch to <A href=\"index.html\">commits view</A>, <A href=\"../index.html\">user index</A>");
    }
else
    {
    fprintf(h, "<ul>\n");
    fprintf(h, "<li>  lines changed: %d</li>\n", totalChangedLines);
    fprintf(h, "<li>  files changed: %d</li>\n", totalChangedFiles);
    fprintf(h, "</ul>\n");
    }
fprintf(h, "</body>\n</html>\n");

fclose(h);

// make index of all files view
doUserFiles(NULL, commits);

// make main index page
doMainIndex();

// tidying up
unlink(tempMakeDiffName);
freez(&tempMakeDiffName);
}