-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (55 loc) · 2.05 KB
/
main.cpp
File metadata and controls
63 lines (55 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <assembler_driver.h>
void split_extension(const std::string& str,std::string& name, std::string& extension) {
std::size_t found = str.find_last_of(".");
name = str.substr(0, found);
extension = str.substr(found + 1);
}
/**
* takes full file path and split it into path, name, extension and store them in the given parameters.
* @param str: the original string
* @param path: will store the file path.
* @param name: will store the file name.
* @param extension: will store the file extension.
*/
void split_file_name(const std::string& str, std::string& path, std::string& name, std::string& extension) {
std::size_t found = str.find_last_of("/\\");
path = str.substr(0, found + 1); // +1 to take the seperator with the path
split_extension(str.substr(found + 1), name, extension);
}
/**
* Method to check the type of OS
* __WIN32 macro checks both win32 and win64
* Usefull tip:
* http://web.archive.org/web/20160306052035/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
*/
void check_os() {
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
// UNIX STYLE OS
std::cout << "This is UNIX sytle OS" << std::endl;
// do something
#elif defined(__WIN32)
// __WIN32 check for both 32 and 64 so no need to check for for __WIN64
std::cout << "This is Windows OS" << std::endl;
// do something
#endif
}
int main(int argc, char **argv) {
// check_os();
std::string file_name;
std::string path;
std::string extension;
// if no argument is passed
if (argc <= 1) {
std::cout << "please spicify file as argument" << std::endl;
return 0;
}
split_file_name(std::string(argv[1]), path, file_name, extension);
if (extension != "asm") {
std::cout << "no valid file specified, must be .asm file" << std::endl;
return 0;
}
assembler_driver assembler(path, file_name);
assembler.assemble();
return 0;
}