summaryrefslogtreecommitdiff
path: root/src/inspircd_io.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-04-08 18:10:27 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2004-04-08 18:10:27 +0000
commit498a8eb5c38c86d41c088c8c1308b3520c993c7f (patch)
treefbbbb977c9aa8eaa685d20984ce0776e5b521b7b /src/inspircd_io.cpp
parent9be94a9a9cf3a7946171994c97bcf4041dd8dd48 (diff)
Added ConfigReader::EnumValues() (requested by Craig)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@456 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspircd_io.cpp')
-rw-r--r--src/inspircd_io.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp
index 18bee1f18..c69ba3b17 100644
--- a/src/inspircd_io.cpp
+++ b/src/inspircd_io.cpp
@@ -220,6 +220,92 @@ int EnumConf(std::stringstream *config, const char* tag)
return idx;
}
+/* Counts the number of values within a certain tag */
+
+int EnumValues(std::stringstream *config, const char* tag, int index)
+{
+ int ptr = 0;
+ char buffer[MAXBUF], c_tag[MAXBUF], c, lastc;
+ int in_token, in_quotes, tptr, j, idx = 0;
+ char* key;
+
+ bool correct_tag = false;
+ int num_items = 0;
+
+ const char* buf = config->str().c_str();
+ long bptr = 0;
+ long len = strlen(buf);
+
+ ptr = 0;
+ in_token = 0;
+ in_quotes = 0;
+ lastc = '\0';
+ while (bptr<len)
+ {
+ lastc = c;
+ c = buf[bptr++];
+ if ((c == '#') && (lastc == '\n'))
+ {
+ while ((c != '\n') && (bptr<len))
+ {
+ lastc = c;
+ c = buf[bptr++];
+ }
+ }
+ if ((c == '<') && (!in_quotes))
+ {
+ tptr = 0;
+ in_token = 1;
+ do {
+ c = buf[bptr++];
+ if (c != ' ')
+ {
+ c_tag[tptr++] = c;
+ c_tag[tptr] = '\0';
+
+ if ((!strcmp(c_tag,tag)) && (idx == index))
+ {
+ correct_tag = true;
+ }
+ }
+ } while (c != ' ');
+ }
+ if (c == '"')
+ {
+ in_quotes = (!in_quotes);
+ }
+
+ if ( (correct_tag) && (!in_quotes) && ( (c == ' ') || (c == '\n') || (c == '\r') ) )
+ {
+ num_items++;
+ }
+ if ((c == '>') && (!in_quotes))
+ {
+ in_token = 0;
+ if (correct_tag)
+ correct_tag = false;
+ if (!strcmp(c_tag,tag))
+ {
+ /* correct tag, but wrong index */
+ idx++;
+ }
+ c_tag[0] = '\0';
+ buffer[0] = '\0';
+ ptr = 0;
+ tptr = 0;
+ }
+ if (c != '>')
+ {
+ if ((in_token) && (c != '\n') && (c != '\r'))
+ {
+ buffer[ptr++] = c;
+ buffer[ptr] = '\0';
+ }
+ }
+ }
+ return num_items+1;
+}
+
int ConfValueEnum(char* tag, std::stringstream* config)