argument parsing in main()

This commit is contained in:
timerix 2023-02-10 13:01:14 +06:00
parent 322b70bc29
commit 6ad607ef15
3 changed files with 44 additions and 4 deletions

2
cbuild

@ -1 +1 @@
Subproject commit 15a9661c467facf65b2155eab3fad1ecf5f0c945 Subproject commit 1b38b43c547246ca358a676cee5eda85598ab949

2
kerep

@ -1 +1 @@
Subproject commit 40d1828f2cfa68e03cccaa2b3658eba07c146b02 Subproject commit 609dfcf3ed6d454599165e8dd443ba30b95771b2

View File

@ -1,9 +1,46 @@
#include "cb2c.h"
#include "../../kerep/src/kprint/kprint.h" #include "../../kerep/src/kprint/kprint.h"
#include "../../kerep/src/Filesystem/filesystem.h"
#include "cb2c.h"
#include "../lexer/lexer.h"
int main(){ Autoarr(Token)* parseFile(char* filename){
tryLast(file_open(filename, FileOpenMode_Read), m_srcfile)
File* srcfile=m_srcfile.value.VoidPtr;
char* src;
tryLast(file_readAll(srcfile, &src), m_srcLen)
uint64 srcLen=m_srcLen.value.UInt64;
kprintf("srclen: %lu\n", srcLen);
src[srcLen]='\0';
tryLast(lexan(src, filename), m_tokens)
Autoarr(Token)* tokens=m_tokens.value.VoidPtr;
return tokens;
}
int main(const int argc, const char* const* argv){
if(!setlocale(LC_ALL, "C.UTF8")) if(!setlocale(LC_ALL, "C.UTF8"))
kprintf("\e[93msetlocale failed\n"); kprintf("\e[93msetlocale failed\n");
bool compile=0, translate=0;
char *compiler=NULL, *tranlation_out_dir=NULL;
for(int argi=1; argi<argc; argi++){
char* a=argv[argi];
kprintf("%s ", a);
if(cptr_compare(a, "-c") || cptr_compare(a, "--compiler")){
compile=1;
if(argi+1>=argc || argv[argi+1][0]=='-')
throw("after argument --compiler must be compiler name");
compiler=argv[++argi];
}
else if(cptr_compare(a, "-t") || cptr_compare(a, "--tranlation-out-dir")){
translate=1;
if(argi+1>=argc || argv[argi+1][0]=='-')
throw("after argument --translation-out-dir must be directory path");
tranlation_out_dir=argv[argi+1];
if(!dir_exists(tranlation_out_dir))
dir_create(tranlation_out_dir);
}
}
kprintf("\n"); return 0;
// kerep type system // kerep type system
ktDescriptors_beginInit(); ktDescriptors_beginInit();
ktDescriptors_initKerepTypes(); ktDescriptors_initKerepTypes();
@ -12,6 +49,9 @@ int main(){
// keywords search tree // keywords search tree
init_keywordsSearchTree(); init_keywordsSearchTree();
kprint(kp_s|kp_fgGray, "keywordsSearchTree: ", kp_h|kp_pre, keywordsSearchTree, kp_c, '\n'); kprint(kp_s|kp_fgGray, "keywordsSearchTree: ", kp_h|kp_pre, keywordsSearchTree, kp_c, '\n');
Autoarr(Token)* tokens=parseFile("src.cb");
kprintf("tokens: %u\n", Autoarr_length(tokens));
Autoarr_foreach(tokens, tok, kprintf("%u %s\n",tok.id, tok.value));
STNode_free(keywordsSearchTree); STNode_free(keywordsSearchTree);
return 0; return 0;
} }