-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathutils.h
More file actions
123 lines (88 loc) · 3.06 KB
/
utils.h
File metadata and controls
123 lines (88 loc) · 3.06 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef __UTILS__H__
#define __UTILS__H__
#include <stdio.h>
#include <signal.h>
#include <assert.h>
#include <string>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
#define KB *1024
#define MB *1024 KB
#define GB *1024 MB
#define TB *1024 GB
#define ALIGN(v,a) ((((unsigned int)(v)) + (((unsigned int)(a))-1)) & (~(((unsigned int)(a))-1)))
template<class T> struct Local{
T *object;
T *attach(T *p){if(object!=NULL) delete object; object=p; return p; };
T *detach(){T *p=object; object=NULL; return p;};
operator T*(){ return object; }
Local(T *o){object=o;}
Local(){object=NULL;}
~Local(){ if(object!=NULL) delete object; }
};
template<class T> struct Locala{
T *object;
int count;
operator T*(){ return object; }
T *operator [](int index){ if(count!=-1 && index>=count) return NULL; return &object[index]; }
void alloc(int c){if(object!=NULL) delete object;object=new T[c];count=c;}
Locala(int c){object=new T[c];count=c;}
Locala(T *o){object=o;count=-1;}
Locala(){object=NULL;count=-1;}
~Locala(){ delete [] object; }
};
template<class T> struct Localc{
T *object;
T *attach(T *p){if(object!=NULL) free(object); object=p; return p; };
T *detach(){T *p=object; object=NULL; return p;};
operator T*(){ return object; }
T *operator [](int index){ return &object[index]; }
Localc(T *o){object=o;}
Localc(){object=NULL;}
~Localc(){ if(object!=NULL) free(object); }
};
struct Strings{
char **data;
int count;
char *add(char *str);
char *get(int index);
void remove(int index);
void clear();
int index(char *str);
Strings();
~Strings();
void spit(char *filename);
void slurp(char *filename);
private:
int size;
void expand();
};
/* I can't breathe without this. */
#define elems(v) (sizeof(v)/sizeof((v)[0]))
bool exists(const char *filename);
/* This is a safe version of snprintf that guarantees \0 at
* the end of string (windows doesn't even have snprintf...) */
int lprintf(char *s,size_t length,const char *fmt,...);
void dumpSjisLines(char *filename,int memStart,int memEnd);
void readSjisLines(char *filename);
char *escapeString(char *src,char *dst,size_t dstLength);
char *unescapeString(char *src,char *dst,size_t dstLength);
char *slurp(const char *filename,char *text,size_t size);
void spit(const char *filename,const char *text);
int alert(const char *s);
int editInplace(const char *filename,char *(*update)(char *line,void *p,int last),void *p);
int updateConfig(const char *key,const char *value);
bool isYes(const char *s);
void stolower(char *s);
std::string <rim(std::string &s);
std::string &rtrim(std::string &s);
std::string &trim(std::string &s);
void split(std::string input,int separator,std::string & a,std::string & b);
const unsigned char *
boyermoore_horspool_memmem(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen);
#endif