byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
Functions
byteman.cpp File Reference
#include <iostream>
#include <stdexcept>
#include <fstream>
#include "byteman.h"
#include "Common/str.h"
#include "Common/Coords.h"
Include dependency graph for byteman.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function for byteman. Parses command line arguments and eventual streamed script files as individual commands (instructions) and feeds them into parse(). Catches any thrown exceptions by the subsystems in byteman.

  • argc argv[] Command line arguments

Definition at line 35 of file byteman.cpp.

36 {
37  byteman bytemanInstance;
38  string command;
39  if(argc <= 1)
40  bytemanInstance.help("", 1);//show usage and terminate with an error code
41  try {
42  bool readSTDIN = false;
43  for(int argi = 1 ; argi < argc ; argi++) {
44  if(argv[argi][0] == '-' && !command.empty()){ //new cmd and old cmd not empty
45  bytemanInstance.parse(command);
46  command.clear();
47  }
48  if(command.empty())
49  command.append(argv[argi]);
50  else
51  command.append(" ").append(argv[argi]);
52  if(command == "-stdin" || command == "-s"){
53  readSTDIN = true;
54  command.clear();
55  }
56  }
57  if(!command.empty())
58  bytemanInstance.parse(command);
59  while(readSTDIN){
60  getline(cin, command);
61  if(!cin.good())
62  return 0;
63  if(command != "" && command.at(command.find_first_not_of(" \t")) != '#'){//parse the command only if it doesnt start with '#' or if not empty
64  if(string::npos != command.find("#"))
65  command = command.substr(0, command.find("#"));//if there is a comment in the current line, remove it
66  bytemanInstance.parse(command);
67  }
68  }
69  } catch (const exception &e){
70  cout << "The program was terminated with message: \n\t'" << e.what() << "'\nWhile trying to execute command: \n\t'" << command << "'" << endl;
71  return 1;
72  }
73  return 0;
74 }
void help(std::string, int)
Definition: help.cpp:31
void parse(std::string)
Definition: byteman.cpp:96

References byteman::help(), and byteman::parse().

Here is the call graph for this function: