示例#1
0
void UserDictionaryDecoder::Read(IBitStream *bstr) {
    int len = bstr->read(32);
    _prefix = readUnicodeString(bstr, len, true);
    _articleSymbols = readSymbols(bstr);
    _headingSymbols = readSymbols(bstr);
    _ltArticles.Read(*bstr);
    _ltHeadings.Read(*bstr);
    _ltPrefixLengths.Read(*bstr);
    _ltPostfixLengths.Read(*bstr);
    _huffman1Number = bstr->read(32);
    _huffman2Number = bstr->read(32);
}
示例#2
0
S52References::S52References(QString file_name) {
  QFile file(file_name);
  file.open(QFile::ReadOnly);
  QXmlStreamReader* xml = new QXmlStreamReader(&file);

  while (!xml->atEnd()) {
    switch (xml->readNext()) {
    case QXmlStreamReader::StartElement:
      if (xml->name() == "color-tables")
        readColorTables(xml);

      if (xml->name() == "lookups")
        readLookUps(xml);

      if (xml->name() == "line-styles")
        readLineStyles(xml);

      if (xml->name() == "patterns")
        readPatterns(xml);

      if (xml->name() == "symbols")
        readSymbols(xml);

      break;

    default:
      break;
    }
  }

  //print();

  file.close();
  fillColorTables2();
}
  bool
internalizeOneObjectFile(objectFileListType *objectFile)
{
	FILE		*objectFildes;
	int		 magic;
	int		 mode;
	addressType	 startAddress;
	addressType	 endAddress;

	currentFileName = objectFile->name;
	if ((objectFildes = fopen(objectFile->name, "r")) == NULL) {
		error(CANT_OPEN_OBJECT_FILE_ERROR, objectFile->name);
		perror("Unix says");
		return(FALSE);
	}
	if (verbose)
		printf("internalizing %s:\n", objectFile->name);
	if ((magic = readWord(objectFildes, objectFile->name)) != 0xFFFF) {
		error(BAD_OBJECT_FILE_ERROR, objectFile->name);
		return(FALSE);
	}
	mode = MODE_ABSOLUTE;
	for (;;) {
		startAddress = readWord(objectFildes, objectFile->name);
		if (startAddress == 0xFFFF) {
			if (mode == MODE_ABSOLUTE) {
				mode = MODE_RELOCATABLE;
				continue;
			} else {
				break;
			}
		}
		endAddress = readWord(objectFildes, objectFile->name);
		readCode(startAddress, endAddress, mode, objectFile,
			objectFildes);
	}
	readReservations(objectFile, objectFildes);
	readReferences(objectFile, objectFildes);
	readSymbols(objectFile, objectFildes);
	readExpressions(objectFile, objectFildes);
	readFunctions(objectFile, objectFildes);
	instantiateExpressionAndSymbolPointers(objectFile);
	if (readExpressionEntryPoint) {
		pc = entryPointExpression;
		putSymbolPointersIntoExpression();
		readExpressionEntryPoint = FALSE;
		haveExpressionEntryPoint = TRUE;
	}
	qsort(objectFile->symbolTable, objectFile->symbolCount,
		sizeof(symbolType *), compareSymbolValues);
	fclose(objectFildes);
	return(TRUE);
}
示例#4
0
void MachOObject::load()
{
	if (isLoaded())
		throw std::logic_error("Module already loaded");
	if (strcmp(m_file->platform(), ARCH_NAME) != 0)
	{
		std::stringstream ss;
		ss << "This version of Darling dyld cannot load binaries for " << m_file->platform() << ".";
		throw std::runtime_error(ss.str());
	}
	
	loadSegments();
	transitionState(dyld_image_state_mapped);
	
	if (m_slide > 0)
		rebase();
	transitionState(dyld_image_state_rebased);
	
	readSymbols();
	readExports();

	MachOMgr::instance()->add(this, isMainModule());

	loadDependencies();
	
	performRelocations();
	performBinds();
	transitionState(dyld_image_state_bound);
	transitionState(dyld_image_state_dependents_initialized);
	
	// registerEHSection();
	
	if (isMainModule())
		fillInProgramVars();
	fillInDyldData();
	
	setInitialSegmentProtection();
	setupTLS();
	
	MachOMgr::instance()->notifyAdd(this);
	runInitializers();

	transitionState(dyld_image_state_initialized);
	
	m_file->closeFd();
	
	if (MachOMgr::instance()->printLibraries())
		std::cerr << "dyld: Loaded " << this->path() << std::endl;
}
示例#5
0
文件: main.cpp 项目: hoangt/tool_axe
static void readSymbols(Elf *e, unsigned low, unsigned high,
                        std::auto_ptr<CoreSymbolInfo> &SI)
{
  Elf_Scn *scn = NULL;
  GElf_Shdr shdr;
  while ((scn = elf_nextscn(e, scn)) != NULL) {
    if (gelf_getshdr(scn, &shdr) == NULL) {
      continue;
    }
    if (shdr.sh_type == SHT_SYMTAB) {
      // Found the symbol table
      break;
    }
  }
  
  if (scn != NULL) {
    readSymbols(e, scn, shdr, low, high, SI);
  }
}
示例#6
0
bool NAmigaHunkDecoder::readNodes()
{
  unsigned int hunkType=0;
  unsigned int hunkSize=0;
  bool reading=true;
  unsigned int hunkCount=0;
  ULONG loc=0;
  NBinaryNode *n=(NBinaryNode *)NULL;
  nextHunk=0;
  while(reading) {
    hunkType=map->read32(offset+getImageOffset(),LSB);
    offset+=4;
#ifdef DEBUG_VERBOSE
    DEBUG_OUT<<hunkType<<" ";
#endif // DEBUG_VERBOSE
    switch(hunkType) {
      case 0x3e7:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_unit\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"nameLen="<<hunkSize<<"\n";
#endif // DEBUG_VERBOSE
        offset+=hunkSize*4;
        break;
      case 0x3e8:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_name\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"nameLen="<<hunkSize<<"\n";
#endif // DEBUG_VERBOSE
        offset+=hunkSize*4;
        break;
      case 0x3e9:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_code\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
        loc=offset;
        n=new NBinaryNode("code",hunkCount,N_BIN_PROGBITS,loc,hunkSize*4,offset,E_MEM_ALL);
        if(n) ld->getModule()->getNodes()->append(n);
        else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); }
        offset+=hunkSize*4;
        hunkCount++; nextHunk++;
        break;
      case 0x3ea:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_data\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
        loc=offset;
        n=new NBinaryNode("data",hunkCount,N_BIN_PROGBITS,loc,hunkSize*4,offset,E_MEM_READ|E_MEM_WRITE);
        if(n) ld->getModule()->getNodes()->append(n);
        else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); }
        offset+=hunkSize*4;
        hunkCount++; nextHunk++;
        break;
      case 0x3eb:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_bss\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
        loc=offset;
        n=new NBinaryNode("bss",hunkCount,N_BIN_NOBITS,loc,hunkSize*4,0,E_MEM_READ|E_MEM_WRITE);
        if(n) ld->getModule()->getNodes()->append(n);
        else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); }
        hunkCount++; nextHunk++;
        break;
      case 0x3ec:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_reloc32\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        readReloc(32);
        break;
      case 0x3ed:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_reloc16\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        readReloc(16);
        break;
      case 0x3ee:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_reloc8\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        readReloc(8);
        break;
      case 0x3ef:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_ext\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        readSymbols(true);
        break;
      case 0x3f0:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_symbol\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        readSymbols(false);
        break;
      case 0x3f1:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_debug\n";
#endif // DEBUG_VERBOSE
        hunkSize=map->read32(offset+getImageOffset(),LSB); offset+=4;
        hunkSize&=0x3fffffff;  // strip any "ATOM" bits if any...
        loc=offset;
        n=new NBinaryNode("debug",0,N_BIN_NOBITS,loc,hunkSize*4,0,E_MEM_READ|E_MEM_WRITE);
        if(n) ld->getModule()->getNodes()->append(n);
        else { std::cerr<<"Didn't get NBinaryNode!\n"; exit(5); }
        offset+=hunkSize*4;
        break;
      case 0x3f2:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_end\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        numHunks--;
        break;
      case 0x3f6:
#ifdef DEBUG_VERBOSE
        DEBUG_OUT<<"hunk_break\n";
#endif // DEBUG_VERBOSE
        hunkSize=1;  // not really, but it can't be zero
        break;
      default:
        DEBUG_OUT<<"unknown hunk type...bailing!\n";
        reading=false;
        break;
    }
    if(!numHunks) reading=false;
  }
  return true;
}
示例#7
0
文件: main.cpp 项目: hoangt/tool_axe
static void readElf(const char *filename, const XEElfSector *elfSector,
                    Core &core, std::auto_ptr<CoreSymbolInfo> &SI,
                    std::map<Core*,uint32_t> &entryPoints)
{
  uint64_t ElfSize = elfSector->getElfSize();
  const scoped_array<char> buf(new char[ElfSize]);
  if (!elfSector->getElfData(buf.get())) {
    std::cerr << "Error reading elf data from \"" << filename << "\"" << std::endl;
    std::exit(1);
  }

  if (elf_version(EV_CURRENT) == EV_NONE) {
    std::cerr << "ELF library intialisation failed: "
              << elf_errmsg(-1) << std::endl;
    std::exit(1);
  }
  Elf *e;
  if ((e = elf_memory(buf.get(), ElfSize)) == NULL) {
    std::cerr << "Error reading ELF: " << elf_errmsg(-1) << std::endl;
    std::exit(1);
  }
  if (elf_kind(e) != ELF_K_ELF) {
    std::cerr << filename << " is not an ELF object" << std::endl;
    std::exit(1);
  }
  GElf_Ehdr ehdr;
  if (gelf_getehdr(e, &ehdr) == NULL) {
    std::cerr << "Reading ELF header failed: " << elf_errmsg(-1) << std::endl;
    std::exit(1);
  }
  if (ehdr.e_machine != XCORE_ELF_MACHINE) {
    std::cerr << "Not a XCore ELF" << std::endl;
    std::exit(1);
  }
  if (ehdr.e_entry != 0) {
    entryPoints.insert(std::make_pair(&core, (uint32_t)ehdr.e_entry));
  }
  unsigned num_phdrs = ehdr.e_phnum;
  if (num_phdrs == 0) {
    std::cerr << "No ELF program headers" << std::endl;
    std::exit(1);
  }
  core.resetCaches();
  uint32_t ram_base = core.ram_base;
  uint32_t ram_size = core.getRamSize();
  for (unsigned i = 0; i < num_phdrs; i++) {
    GElf_Phdr phdr;
    if (gelf_getphdr(e, i, &phdr) == NULL) {
      std::cerr << "Reading ELF program header " << i << " failed: " << elf_errmsg(-1) << std::endl;
      std::exit(1);
    }
    if (phdr.p_filesz == 0) {
      continue;
    }
    if (phdr.p_offset > ElfSize) {
    	std::cerr << "Invalid offet in ELF program header" << i << std::endl;
    	std::exit(1);
    }
    if (!core.isValidAddress(phdr.p_paddr) ||
        !core.isValidAddress(phdr.p_paddr + phdr.p_memsz)) {
      std::cerr << "Error data from ELF program header " << i;
      std::cerr << " does not fit in memory" << std::endl;
      std::exit(1);
    }
    core.writeMemory(phdr.p_paddr, &buf[phdr.p_offset], phdr.p_filesz);
  }

  readSymbols(e, ram_base, ram_base + ram_size, SI);

  elf_end(e);
}
int main( int argc, char** argv )
{
	int err = 0;
	std::string argOutputDir; 
	std::string symbolFile;
	std::string configFile;
	std::string password;
	bool printDebug; 
    

    (void) signal(SIGINT, sighandler);
    (void) signal(SIGTERM, sighandler);
    (void) signal(SIGHUP, sighandler);


	try {
		po::options_description desc("Allowed options");
		desc.add_options()
			("help", "produce help message")
			("s", po::value<std::string>(), "<symbol file>")
			("c", po::value<std::string>(), "<config file>")
			("d", "debug info")
		;
		
		po::variables_map vm;        
		po::store(po::parse_command_line(argc, argv, desc), vm);
		po::notify(vm);    

		
		if (vm.count("help")) {
			std::cout << desc << "\n";
			return 1;
		}
		
		if (vm.count("s")) {
			std::cout << "Symbol file: " << vm["s"].as<std::string>() << "\n";
			symbolFile = vm["s"].as<std::string>();
		} else {
			// use default name for symbols file name 
			symbolFile = "symbols.cfg"; 
			std::cout << "Using default symbols file: symbols.cfg\n"; 
		}
		if (vm.count("c")) {
			std::cout << "Config file: " << vm["c"].as<std::string>() << ".\n";
			configFile = vm["c"].as<std::string>();
		} else {
			std::cout << "Config file was not set.\n";
			err++;
		}
		printDebug = vm.count("d") > 0; 
			
	}
	catch(std::exception& e) {
		std::cerr << "EXCEPTION:" << e.what();
		return 1;
	}
	if (err > 0) {
		std::cout << "Usage: validate_symbols --c <config_file> --s <symbol_file> \n";
		std::cout << "Will save files to MIC.validated-symbols";
		return 1;
	}
	
	/* 
 	* @see http://www.boost.org/doc/libs/1_41_0/doc/html/program_options.html
 	*/
	
	std::vector<std::string> symbols = readSymbols(symbolFile);
	try
	{
		FIX::SessionSettings settings(configFile);
                std::set<FIX::SessionID> sessions = settings.getSessions ();
		assert(sessions.size() == 1); 
		FIX::SessionID sessionId = *(sessions.begin()); 
		const FIX::Dictionary& dict = settings.get(sessionId);
		ApplicationConfig config;  
        // MIC code for adding to output filename 
		config.mic_code = dict.has("MIC") ? dict.getString("MIC") : ""; 

        // Username and password settings
		config.username = dict.has("Username") ? dict.getString("Username") : ""; 
		config.password = dict.has("Password") ? dict.getString("Password") : ""; 
		config.sendPasswordInRawDataField = dict.has("SendPasswordInRawData") && 
		    dict.getBool("SendPasswordInRawData");

        // Fix Version string
		config.version = dict.has("FIXVersion") ? (FIXVersion)atoi(dict.getString("FIXVersion").c_str()) : FIX_42;
		std::cout << "Using FIX version: " << config.version << std::endl;

        // Reset sequence numbers? 
		bool bReset = dict.has("ResetSeqNo") ? dict.getBool("ResetSeqNo") : false;
		std::cout << "Resetting sequence numbers: " << bReset << std::endl;

        // Debug settings
		config.printDebug = printDebug; 
        
		Application application(bReset, config);
        papplication = &application;
		application.addSymbols(symbols);
    
        // if user specified an output dir, then put files into date-sorted
        // subdirectories, otherwise put into the default dirs specified in 
        // config file 
        std::string orderBooksOutputDir = ".";
        std::string logOutputDir = dict.has("FileLogPath") ? dict.getString("FileLogPath") : "."; 
        std::string storeOutputDir = dict.has("FileStorePath") ? dict.getString("FileStorePath") : ".";

        if (argOutputDir.length() > 0) { 
            orderBooksOutputDir = argOutputDir; 
            fs::path argPath = fs::path(argOutputDir); 
            if (!fs::exists(argPath)) { fs::create_directories(argPath); }
            
            /* put both order books and message logs in subdirs, 
               but put the store at the root dir 
            */ 
            fs::path logOutputPath = argPath / fs::path("log");  
			if (!fs::exists(logOutputPath)) { fs::create_directory(logOutputPath); } 
			logOutputDir = logOutputPath.string(); 

            fs::path storeOutputPath = argPath / fs::path("store"); 
			if (!fs::exists(storeOutputPath)) { fs::create_directory(storeOutputPath); }
			storeOutputDir = storeOutputPath.string(); 
        }

        
		FIX::FileStoreFactory storeFactory(storeOutputDir);         
		FIX::FileLogFactory logFactory(logOutputDir);

		FIX::SocketInitiator initiator(application, storeFactory, settings, logFactory);
        pinitiator = &initiator;
		std::cout << "Starting initiator" << std::endl; 
		initiator.start();
        //application.run();

		char x;
		while(std::cin >> x) {
            std::cout << " Press 'q' to quit" << std::endl;
			if (x == 'q') {
				break;
			}
		}
		std::cout << "Stopping initiator..." << std::endl;
		initiator.stop();
		return 0;
	}
	catch ( FIX::Exception & e )
	{
		std::cout << e.what();
		return 1;
	}
    
}
示例#9
0
int main( int argc, char** argv )
{
	int err = 0;
	std::string argOutputDir; 
	std::string symbolFile;
	std::string configFile;
	std::string password;
	bool printDebug; 
    bool isLogging;
    int zero = 0;  

    (void) signal(SIGINT, sighandler);
    (void) signal(SIGTERM, sighandler);
    (void) signal(SIGHUP, sighandler);

	g_zmq_context = zmq_init(1);
	assert(g_zmq_context);
	pub_socket = zmq_socket(g_zmq_context, ZMQ_PUB);
    zmq_setsockopt(pub_socket, ZMQ_LINGER, &zero, sizeof(zero));
	assert(pub_socket);


    GOOGLE_PROTOBUF_VERIFY_VERSION;


	try {
		po::options_description desc("Allowed options");
		desc.add_options()
			("help", "produce help message")
			("c", po::value<std::string>(), "<config file>")
			("s", po::value<std::string>(), "<symbol file>")
			("o", po::value<std::string>(), "<output path>")
			("nolog", po::value<int>()->implicit_value(0), "disable logging (FIX and tick)")
			("d", "debug info")
		;
		
		po::variables_map vm;        
		po::store(po::parse_command_line(argc, argv, desc), vm);
		po::notify(vm);    

		if (vm.count("nolog")) {
            std::cout << "Logging disabled" << std::endl;
            //isLogging = (vm["nolog"].as<int>() == 1 ? false : true);
            isLogging = false;
		}
        else { 
            std::cout << "Logging enabled" << std::endl;
            isLogging = true;
        }
		if (vm.count("help")) {
			std::cout << desc << "\n";
			return 1;
		}
		if (vm.count("o")) {
			std::cout << "Output path: " << vm["o"].as<std::string>() << "\n";
            argOutputDir = vm["o"].as<std::string>();
		} else {
			// set default
			std::cout << "Output path file was not set \n";
		}
		if (vm.count("s")) {
			std::cout << "Symbol file: " << vm["s"].as<std::string>() << "\n";
			symbolFile = vm["s"].as<std::string>();
		} else {
			// use default name for symbols file name 
			symbolFile = "symbols.cfg"; 
			std::cout << "Using default symbols file: symbols.cfg\n"; 
		}
		if (vm.count("c")) {
			std::cout << "Config file: " << vm["c"].as<std::string>() << ".\n";
			configFile = vm["c"].as<std::string>();
		} else {
			std::cout << "Config file was not set.\n";
			err++;
		}
		printDebug = vm.count("d") > 0; 
			
		/* moved passwords to cfg files 
		if (vm.count("p")) {
			std::cout << "Pass: "******"p"].as<std::string>() << ".\n";
			password = vm["p"].as<std::string>();
		} else {
			std::cout << "Password was not set.\n";
			err++;
		}
		*/ 
	}
	catch(std::exception& e) {
		std::cerr << "EXCEPTION:" << e.what();
		return 1;
	}
	if (err > 0) {
		std::cout << "Aborting due to missing parameters.\n";
		return 1;
	}
	
	/* 
 	* @see http://www.boost.org/doc/libs/1_41_0/doc/html/program_options.html
 	*/
	
	std::vector<std::string> symbols = readSymbols(symbolFile);
	try
	{
		FIX::SessionSettings settings(configFile);
                std::set<FIX::SessionID> sessions = settings.getSessions ();
		assert(sessions.size() == 1); 
		FIX::SessionID sessionId = *(sessions.begin()); 
		const FIX::Dictionary& dict = settings.get(sessionId);
		ApplicationConfig config;  

        // MIC code for adding to output filename 
		config.mic_string = dict.has("MIC") ? dict.getString("MIC") : ""; 
        std::cout << "My MIC is: " << config.mic_string << std::endl;


        capk::get_config_params(g_zmq_context, "tcp://127.0.0.1:11111", &all_venue_config);
        capkproto::venue_configuration my_config = capk::get_venue_config(&all_venue_config, config.mic_string.c_str());
        std::cout << "Received config:\n" << my_config.DebugString() << std::endl;

        // venue id as for protobuf usage to identify venue
        if (my_config.venue_id() == "") {
            std::cerr << "venue_id not set!" << std::endl;
            exit(-1);
        }
        else {
            // boost version of atoi
            if (qi::parse(my_config.venue_id().begin(), my_config.venue_id().end(),  qi::int_, config.venue_id) == false) {
                std::cout << "Can't parse venue_id"  << std::endl;
                exit(-1); 
            }
            if (config.venue_id == 0) {
                std::cerr << "venue_id can not be 0" << std::endl;
                exit(-1);
            }
            std::cout << "Set venue_id to: " << config.venue_id << std::endl;
        }

        // Username and password settings
		config.username = dict.has("Username") ? dict.getString("Username") : ""; 
		config.password = dict.has("Password") ? dict.getString("Password") : ""; 
		config.sendPasswordInRawDataField = dict.has("SendPasswordInRawData") && 
		    dict.getBool("SendPasswordInRawData");

        // Should use aggregated book?  
        config.aggregatedBook = dict.has("AggregatedBook") && dict.getBool("AggregatedBook");
        std::cout << "Aggregated book: " << config.aggregatedBook << std::endl;

        // Should we reset sequence numbers? 
		bool bReset = dict.has("ResetSeqNo") && dict.getBool("ResetSeqNo");  
		std::cout << "Resetting sequence numbers: " << bReset << std::endl; 

        // How to send market data requests - bulk or multiple messages
		config.sendIndividualMarketDataRequests = 
            dict.has("SendIndividualMarketDataRequests") && dict.getBool("SendIndividualMarketDataRequests");
		std::cout << "Send individual market data requests: " 
            << config.sendIndividualMarketDataRequests << std::endl;

        // Fix Version string
		config.version = dict.has("FIXVersion") ? (FIXVersion)atoi(dict.getString("FIXVersion").c_str()) : FIX_42;
		std::cout << "Using FIX version: " << config.version << std::endl;

        // Market depth 
		std::string depth = dict.has("MarketDepth") ? dict.getString("MarketDepth") : ""; 
        config.marketDepth = atoi(depth.c_str());
		std::cout << "Setting market depth: " << config.marketDepth << std::endl;

        // Update Type 
		long updateType = dict.has("MDUpdateType") ? dict.getLong("MDUpdateType") : -1; 
		std::cout << "Setting update type: " << updateType << std::endl;

        // Debug settings
		config.printDebug = printDebug; 

		Application application(bReset, config);
        papplication = &application;
		application.addSymbols(symbols);
    
        // if user specified an output dir, then put files into date-sorted
        // subdirectories, otherwise put into the default dirs specified in 
        // config file 
        std::string orderBooksOutputDir = ".";
        std::string logOutputDir = dict.has("FileLogPath") ? dict.getString("FileLogPath") : "."; 
        std::string storeOutputDir = dict.has("FileStorePath") ? dict.getString("FileStorePath") : ".";

        if (argOutputDir.length() > 0) { 
            orderBooksOutputDir = argOutputDir; 
            fs::path argPath = fs::path(argOutputDir); 
            if (!fs::exists(argPath)) { fs::create_directories(argPath); }
            
            /* put both order books and message logs in subdirs, 
               but put the store at the root dir 
            */ 
            fs::path logOutputPath = argPath / fs::path("log");  
			if (!fs::exists(logOutputPath)) { fs::create_directory(logOutputPath); } 
			logOutputDir = logOutputPath.string(); 

            fs::path storeOutputPath = argPath / fs::path("store"); 
			if (!fs::exists(storeOutputPath)) { fs::create_directory(storeOutputPath); }
			storeOutputDir = storeOutputPath.string(); 
        }

        pid_t pid = getpid();
        pid_t ppid = getppid();
        
        printf("pid: %d, ppid: %d\n", pid, ppid);
        std::string pidFileName = std::string(argv[0]) + "." +  config.mic_string + std::string(".pid");
        std::ofstream pidFile(pidFileName);
        if (pidFile.is_open()) {
            pidFile << pid;
            pidFile.flush();
        }
        else {
            std::cerr << "Can't write pid file - exiting";
            exit(-1);
        }

        // Get the bind address for zmq sockets
        bool isPublishing = dict.has("should_publish_prices") && dict.getBool("should_publish_prices");
        if (isPublishing) {
            std::cout << "Collector is publishing prices to: " << my_config.market_data_broadcast_addr() << std::endl;
        }
        else {
            std::cout << "Collector is NOT publishing prices" << std::endl;
        }

        // ZMQ initialization
        if (isPublishing) {
            zmq_bind(pub_socket, my_config.market_data_broadcast_addr().c_str());
            application.setZMQContext(g_zmq_context);
            application.setZMQSocket(pub_socket);
        }
        application.setPublishing(isPublishing);
        application.setLogging(isLogging);

		// Set MDUpdateType
		application.setUpdateType(updateType);
        
        // orderbook output setup
		application.setDataPath(orderBooksOutputDir);
        // fix logging params

        if (isLogging) {
            std::cout << "Logging with FileStoreFactory" << std::endl;
		    FIX::FileStoreFactory fileStoreFactory(storeOutputDir);         
		    FIX::FileLogFactory logFactory(logOutputDir);
		    pinitiator = new FIX::SocketInitiator(application, fileStoreFactory, settings, logFactory);
        }
        else {
            std::cout << "Logging with NullStoreFactory" << std::endl;
            FIX::NullStoreFactory nullStoreFactory;
		    pinitiator = new FIX::SocketInitiator(application, nullStoreFactory, settings);
        }
        //pinitiator = &initiator;
		std::cout << "Starting initiator" << std::endl; 
		pinitiator->start();

		char x;
		while(std::cin >> x) {
			if (x == 'q') {
				break;
			}
		}
		std::cout << "Stopping initiator..." << std::endl;
		pinitiator->stop();
		return 0;
	}
	catch ( FIX::Exception & e )
	{
		std::cout << e.what();
		return 1;
	}
    
}