This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.hpp
92 lines (58 loc) · 2.16 KB
/
utils.hpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef RPN_UTILS_H
#define RPN_UTILS_H
/// This file really should be called ADHD_tools.h since it's a completely disorganized array of random shit
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stack>
#include <queue>
#include "calc_value.hpp"
#include "terminal_colors.hpp"
#include "win_supp.h"
extern char* progName;
// print help monologue
void displayHelp();
namespace strutils {
// removes char from string
// this is extremely inefficient, but the best way I can think of...
void deleteChar(char* toDelete);
void deleteChars(char* toDelete, const size_t numChars);
char* skipSpaces(char* p);
// remove spaces preceding and following string
char* trimStr(char* string);
// thx @chux http://stackoverflow.com/a/27305359/4475863
char* stristr(const char* haystack, const char* needle);
// find the number of times a certain substring occurs in a string (unused)
unsigned int countOccurances(const char* str, char* sub);
// You must free the result if result is non-NULL.
// thanks: http://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c
// I only translated answer to C++
char* str_replace(char *orig, const char *rep, const char *with);
}
namespace fileutils {
// remember to free()
char* getLineFromFile(const char* filename, size_t lineNumber);
char* getLineFromFile(FILE* file, size_t lineNumber);
char* mktmpPrefix();
FILE* mktmpfile();
extern std::vector<char*> tmp_files;
void delTmpFiles();
}
// strings in quotes (debug)
bool printCalcValue(CalcValue& val, std::vector<UserVar>& var_nodes);
// no quotes on strings (prod)
bool printCalcValueRAW(CalcValue& val, std::vector<UserVar>& var_nodes);
namespace commands {
void debugStack(std::stack<CalcValue> mainStack, std::vector<UserVar>& vars);
}
size_t linesToEnd(FILE* fil);
// variable name mutilator which uses a base 62 counting system to give variables unique names
namespace mutilate {
extern const uint8_t L_REF_MUTILATOR; // number of numberals
extern const char baseNumerals[62]; // base 62 numerals
// makes a variable name unique
char* mutilateVarName(const char *cur_name);
}
#endif