]>
jfr.im git - irc/quakenet/newserv.git/blob - lib/flags.c
7 * Applies a "+x-y+zab" style string to the inflags value.
9 * The "flagmask" input restricts the flags that can be changed.
10 * The "reject" input specifies whether to silently drop or actively reject if:
11 * REJECT_UNKNOWN: An unknown flag was specified
12 * REJECT_DISALLOWED: An attempt was made to manipute a flag disallowed by flagmask
15 int setflags(flag_t
*inflags
, flag_t flagmask
, char *flagstr
, const flag
*flagslist
, short reject
) {
20 /* Work with a temporary copy */
23 /* Default is to add flags */
26 for(ch
=flagstr
;*ch
;ch
++) {
37 for(i
=0;flagslist
[i
].flagchar
!='\0';i
++) {
38 if (*ch
==flagslist
[i
].flagchar
) {
39 /* Check that the change is allowed */
40 if (flagmask
& flagslist
[i
].flagbit
) {
42 newflags
&= (~flagslist
[i
].flagbit
);
44 newflags
|= flagslist
[i
].flagbit
;
47 if (reject
& REJECT_DISALLOWED
) {
48 return REJECT_DISALLOWED
;
51 /* We matched, stop looking */
56 if (flagslist
[i
].flagchar
=='\0') {
57 /* We didn't match anything */
58 if (reject
& REJECT_UNKNOWN
) {
59 return REJECT_UNKNOWN
;
64 /* We reached the end without bailing out; assign the flag changes */
71 * Prints out which flags are currently set in a flag block
73 char *printflags(flag_t inflags
, const flag
*flaglist
) {
80 for (i
=0;flaglist
[i
].flagchar
!='\0' && i
<16;i
++) {
81 if (inflags
&flaglist
[i
].flagbit
) {
82 *ch
++=flaglist
[i
].flagchar
;
92 * Prints out which flags are currently set in a flag block, or return "none"
94 char *printflagsornone(flag_t inflags
, const flag
*flaglist
) {
101 for (i
=0;flaglist
[i
].flagchar
!='\0' && i
<16;i
++) {
102 if (inflags
&flaglist
[i
].flagbit
) {
103 *ch
++=flaglist
[i
].flagchar
;
108 if (ch
==(buf
+1)) /* No flags set */
115 char *printflags_noprefix(flag_t inflags
, const flag
*flaglist
) {
120 for (i
=0;flaglist
[i
].flagchar
!='\0' && i
<16;i
++) {
121 if (inflags
&flaglist
[i
].flagbit
) {
122 *ch
++=flaglist
[i
].flagchar
;
134 * Prints the flag changes needed to change "oldflags" into "newflags"
137 char *printflagdiff(flag_t oldflags
, flag_t newflags
, const flag
*flaglist
) {
145 for (i
=0;flaglist
[i
].flagchar
!='\0' && i
<16;i
++) {
146 if ((oldflags
& flaglist
[i
].flagbit
) && !(newflags
& flaglist
[i
].flagbit
)) {
151 *ch
++=flaglist
[i
].flagchar
;
158 for (i
=0;flaglist
[i
].flagchar
!='\0' && i
<16;i
++) {
159 if (!(oldflags
& flaglist
[i
].flagbit
) && (newflags
& flaglist
[i
].flagbit
)) {
164 *ch
++=flaglist
[i
].flagchar
;