#include "main.h"
#include <regex.h>
#include <fcntl.h>

// maindump.C
// this file is used as the core of textdb ... this utility would allow
// you to convert a binary database to a text one ... therefore, it will
// be more portable.
// to make this, just type    make textdb
// then to use it, type   textdb db
// if you have files db.pag and db.dir that you want textified.
// will overwrite existing db.txt if such a beast exists.


Object_Store* db;
Mud_Sockets all_sockets;
Scheduler   all_processes;

main(int argc, char* argv[]){
  char filename[100];
  int fd;
  
#ifdef LINUX
  re_syntax_options = RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CHAR_CLASSES;
#else
  obscure_syntax = RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CHAR_CLASSES;  
#endif
  
  if (argc != 2)
    {cout << "Syntax:  main <filename>  -- do not add suffix (.dir or .pag)\n";
     exit (1);}
  db = new Object_Store (argv[1]);
  sprintf (filename, "%s.txt", argv[1]);
  fd = creat (filename , 0666);
  if (fd<0)
    {cerr << "File " << filename << " could not be created\n";}
  else
    {close (1);  // closes stdout so the next file descriptor will go there
     dup(fd);
     db->dump_to_stdout();
     close (fd);}
}