Skip to content

Commit fe6ce6f

Browse files
author
Matthilde
committed
working on
1 parent 114847a commit fe6ce6f

8 files changed

Lines changed: 113 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
bin/*
1+
bin/*
2+
tests/*

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"string": "cpp"
4+
}
5+
}

compile.bat

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
@echo off
22
title MicrowaveBASIC Epic Compiler
33

4-
if not exist bin\ mkdir bin
4+
if not exist bin\ (
5+
echo bin/ folder not detected! Creating directory...
6+
mkdir bin
7+
)
8+
if not exist bin\programs\ (
9+
echo bin/programs/ folder not detected! Creating directory...
10+
mkdir bin\programs
11+
)
12+
13+
echo !!! It is recommended to not compile
14+
echo !!! the software yourself and use the
15+
echo !!! pre-built binary instead.
16+
echo.
517
echo Compiling MicrowaveBASIC for Windows...
618
g++ *.cpp libs\*.cpp -o .\bin\microwavebasic.exe
719
echo Done! Press any key to commit exit

compile.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
echo "Compiling MicrowaveBASIC Interpreter..."
2+
13
if [ ! -d "$bin" ]; then
4+
echo "bin/ does not exist. Creating directory..."
25
mkdir bin
36
fi
47

5-
echo "Compiling MicrowaveBASIC Interpreter..."
8+
if [ ! -d "$bin/programs" ]; then
9+
echo "bin/programs/ does not exist. Creating directory..."
10+
mkdir bin/programs
11+
fi
12+
13+
614
g++ *.cpp libs/*.cpp -o bin/microwavebasic
715
echo "Done!"

libs/fileman.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <cstring>
4+
#include <string>
5+
6+
#include "fileman.h"
7+
using namespace std;
8+
9+
inline bool file_exists (const std::string& name) {
10+
ifstream f(name.c_str());
11+
return f.good();
12+
}
13+
14+
// File managing functions to save/load BAS Files
15+
int saveFile(string name, string* prgmArray, bool overwrite) {
16+
string fpname = "programs/" + name;
17+
18+
19+
if (file_exists(fpname)) {
20+
if (overwrite) {
21+
cout << "[fileman.cpp] " << name << " exists! Overwriting it..." << endl;
22+
int rem = remove(fpname.c_str());
23+
24+
if (rem != 0) {
25+
cout << "[fileman.cpp] File Error! " << name << "Couldn't be deleted/overwritten." << endl;
26+
return 1;
27+
}
28+
} else {
29+
cout << "[fileman.cpp] " << name << " exists! Program couldn't be saved." << endl;
30+
return 1;
31+
}
32+
}
33+
34+
cout << "Done!" << endl;
35+
ofstream basfile;
36+
basfile.open(fpname);
37+
38+
for (int i = 0; i < 999999; ++i) {
39+
if (prgmArray[i] == "")
40+
continue;
41+
42+
basfile << to_string(i) << " " << prgmArray[i] << "\n";
43+
}
44+
45+
return 0;
46+
}

libs/fileman.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef FILEMAN_H
2+
#define FILEMAN_H
3+
4+
int saveFile(std::string, std::string*, bool);
5+
#endif

main.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
#include <iostream>
22
#include <string>
33
#include <ctype.h>
4+
5+
/*
6+
Source files map :
7+
- engine.cpp
8+
The core of this program, will interpret the program.
9+
- main.cpp
10+
The interpreter, contains the program where you can type commands and your program.
11+
- utils.cpp
12+
Contains some general purpose useful commands.
13+
- libs/fileman.cpp
14+
Contains function to manage BASIC program files (save/load/delete).
15+
- libs/stringadd.cpp
16+
Contains simple string manipulation.
17+
- libs/stringcond.cpp
18+
Contains the condition system.
19+
-libs/stringop.cpp
20+
Contains simple math eval functions.
21+
*/
422
#include "engine.h"
523
#include "utils.h"
24+
625
#include "libs/stringop.h"
26+
#include "libs/fileman.h"
27+
728
using namespace std;
829

930
/*
@@ -28,12 +49,12 @@ developer.
2849
BootScreen();
2950
cout << endl;
3051
string cmd;
52+
string co;
3153
int o;
3254
int* dummylol = new int[26];
3355
while (true) {
3456
getline(cin, cmd);
3557
string cmdu = to_upper(cmd);
36-
3758
if (cmdu == "EXIT")
3859
break;
3960
else if (is_number(trimString(cmd, 0, searchChar(' ', cmd) - 1))) {
@@ -49,7 +70,16 @@ developer.
4970
for (int i = 0; i < 999999; ++i) {
5071
PrgmMem[i] = "";
5172
}
52-
} else if (cmdu == "RUN") {
73+
}
74+
else if (starts_with(cmdu, "SAVE")) {
75+
co = cmdu.erase(0, 4);
76+
77+
if (co == "")
78+
cout << "!!SYNTAX ERROR" << endl;
79+
else
80+
saveFile(co, PrgmMem, true);
81+
}
82+
else if (cmdu == "RUN") {
5383
ExecuteCode(PrgmMem);
5484
}
5585
else

utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UTILS_H
33

44
bool is_number(const std::string);
5-
std::string* splitSpaces(std::string line);
5+
std::string* splitSpaces(std::string);
66
int searchChar(char, std::string);
77
std::string trimString(std::string, int, int);
88
bool starts_with(const std::string, const std::string);

0 commit comments

Comments
 (0)