Renemed all variables to fit into a namespace

Basically, all Toy varaibles, functions, etc. are prepended with "Toy_",
and macros are prepended with "TOY_". This is to reduce namespace
pollution, which was an issue pointed out to be - blame @GyroVorbis.

I've also bumped the minor version number - theoretically I should bump
the major number, but I'm not quite ready for 1.0 yet.
This commit is contained in:
2023-01-25 12:52:07 +00:00
parent 047ccc5f16
commit 2e2bee4fa3
55 changed files with 4837 additions and 4707 deletions

130
tools/uptown.cpp Normal file
View File

@@ -0,0 +1,130 @@
//UPTOWN: Utility to Prepend Text Of Whatever Next
#include <iostream>
#include <fstream>
#include <string>
#include <map>
//protip: This gets more efficient the more files passed in
//protip: pass in the headers first
bool is_alpha(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
}
int main(int argc, char** argv) {
if (argc <= 1) {
return -1;
}
//cache replacements for all files
std::map<std::string, std::string> replacements;
for (int fileCounter = 1; fileCounter < argc; fileCounter++) {
std::ifstream is; //input stream
std::string buffer; //store file
//open
is.open(argv[fileCounter]);
if (!is.is_open()) {
return -1;
}
while (!is.eof()) {
char c = is.peek();
//skip comments (make it easier)
if (c == '/') {
buffer += is.get();
//single lines
if (is.peek() == '/') {
do {
buffer += is.get();
} while(is.peek() != '\n');
continue;
}
//multi-line
if (is.peek() == '*') {
while (true) {
do {
buffer += is.get();
} while(is.peek() != '*');
if (is.eof()) { //just in case
return -1;
} else {
buffer += is.get();
if (is.peek() == '/') {
buffer += is.get();
break;
}
}
}
continue;
}
}
//skip strings (causes issues)
if (c == '"') {
do {
buffer += is.get();
} while (is.peek() != '"');
buffer += is.get();
continue;
}
//skip non-words
if (!is_alpha(c)) {
buffer += is.get();
continue;
}
//read word
std::string word = "";
while(is_alpha(is.peek())) {
word += is.get();
}
//get replacement word, if it doesn't exist
if (replacements.find(word) == replacements.end()) {
std::cout << word << " : ";
std::string prepend = "";
getline(std::cin, prepend);
if (prepend.length() == 0) {
replacements[word] = word;
}
else {
replacements[word] = prepend + word;
}
}
//append the replacement
buffer += replacements[word];
}
//finally
is.close();
std::ofstream os;
os.open(argv[fileCounter]);
if (!os.is_open()) {
return -1;
}
//bugfix
if (!buffer.empty()) {
buffer.pop_back();
}
os << buffer;
os.close();
}
return 0;
}