forked from foone/VGAPride
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.cpp
More file actions
139 lines (131 loc) · 3.07 KB
/
Copy pathflags.cpp
File metadata and controls
139 lines (131 loc) · 3.07 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "graphics.h"
#include "flags.h"
#include "geometry.h"
static int caseCompare(const char *a, const char *b){
while(*a && *b){
int ca=tolower((unsigned char)*a);
int cb=tolower((unsigned char)*b);
if(ca!=cb){
return ca-cb;
}
a++;
b++;
}
return (unsigned char)*a-(unsigned char)*b;
}
int countCommands(GraphicsCommand commands[]){
for(int i=0;i<MAX_COMMANDS;i++){
if(commands[i].shape==EndCommandList){
return i+1;
}
}
return 0;
}
void Flag::flag_setup(const char far *shortname,
const char far *names,
const char far *credit,
const char far *aliases,
GraphicsCommand far *commands
){
this->shortname=shortname;
this->name=names;
this->credit=credit;
this->aliases=aliases;
this->text_color=RGB(255,255,255);
this->text_size=4;
this->text_layout = LAYOUT_CENTER;
this->commands = commands;
}
Flag::Flag(
const char far *shortname,
const char far *names,
const char far *credits,
const char far *aliases,
GraphicsCommand commands[]
){
this->flag_setup(shortname, names, credits, aliases, commands);
}
Flag::Flag(
const char far *shortname,
const char far *names,
const char far *credits,
const char far *aliases,
GraphicsCommand commands[],
RGBCOLOR text_color,
int text_size
){
this->flag_setup(shortname, names, credits, aliases, commands);
this->text_color=text_color;
this->text_size=text_size;
}
Flag::Flag(
const char far *shortname,
const char far *names,
const char far *credits,
const char far *aliases,
GraphicsCommand commands[],
RGBCOLOR text_color,
int text_size,
TextLayout text_layout
){
this->flag_setup(shortname, names, credits, aliases, commands);
this->text_color=text_color;
this->text_size=text_size;
this->text_layout = text_layout;
}
#define ALIASBUFFER_SIZE 200
char ALIASBUFFER[ALIASBUFFER_SIZE];
const char *Flag::listAliases(){
if(aliases==NULL){
return NULL;
}
const char *start=&aliases[0];
const char *next;
next=strchr(start, '|');
if(next==NULL){ // Only one alias.
return aliases;
}
ALIASBUFFER[0]=0;
while(next!=NULL){
strncat(ALIASBUFFER,start,next-start);
strcat(ALIASBUFFER,", ");
start=next+1;
next=strchr(start, '|');
}
strcat(ALIASBUFFER,start);
return ALIASBUFFER;
}
// There is probably a smarter way to marge this with listAliases, but I am not smart today
bool Flag::match(const char *name){
if(caseCompare(name,this->shortname)==0){
return true;
}
if(aliases==NULL){
// We have no aliases, so it's definitely not us
return false;
}
const char *start=&aliases[0];
const char *next;
next=strchr(start, '|');
if(next==NULL){
// Only one alias, so check if it's that one
return caseCompare(name,aliases)==0;
}
while(next!=NULL){
// Temporarily copy just this alias to the buffer
memset(ALIASBUFFER, 0, ALIASBUFFER_SIZE);
strncpy(ALIASBUFFER,start,next-start);
if(caseCompare(name,ALIASBUFFER)==0){
return true;
}
start=next+1;
next=strchr(start, '|');
}
// Check the final alias in the string
strcpy(ALIASBUFFER,start);
return caseCompare(name,ALIASBUFFER)==0;
}