-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflags.cpp
125 lines (118 loc) · 2.79 KB
/
flags.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "graphics.h"
#include "flags.h"
#include "geometry.h"
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(stricmp(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 stricmp(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(stricmp(name,ALIASBUFFER)==0){
return true;
}
start=next+1;
next=strchr(start, '|');
}
// Check the final alias in the string
strcpy(ALIASBUFFER,start);
return stricmp(name,ALIASBUFFER)==0;
}