summaryrefslogtreecommitdiff
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
parent9be94a9a9cf3a7946171994c97bcf4041dd8dd48 (diff)
Added ConfigReader::EnumValues() (requested by Craig)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@456 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/inspircd_io.h1
-rw-r--r--include/modules.h7
-rw-r--r--src/InspIRCd.layout70
-rw-r--r--src/inspircd_io.cpp86
-rw-r--r--src/modules.cpp4
5 files changed, 133 insertions, 35 deletions
diff --git a/include/inspircd_io.h b/include/inspircd_io.h
index df64228a4..a6403e7ec 100644
--- a/include/inspircd_io.h
+++ b/include/inspircd_io.h
@@ -28,4 +28,5 @@ int ConfValue(char* tag, char* var, int index, char *result, std::stringstream *
int ReadConf(std::stringstream *config_f,const char* tag, const char* var, int index, char *result);
int ConfValueEnum(char* tag,std::stringstream *config);
int EnumConf(std::stringstream *config_f,const char* tag);
+int EnumValues(std::stringstream *config, const char* tag, int index);
diff --git a/include/modules.h b/include/modules.h
index c93e565fb..691e6eda1 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -510,6 +510,13 @@ class ConfigReader : public classbase
* file does not exist or could not be opened.
*/
bool Verify();
+
+ /** Returns the number of items within a tag.
+ * For example if the tag was &lt;test tag="blah" data="foo"&gt; then this
+ * function would return 2. Spaces and newlines both qualify as valid seperators
+ * between values.
+ */
+ int EnumerateValues(std::string tag, int index);
};
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout
index 3af24613b..5cb0f7780 100644
--- a/src/InspIRCd.layout
+++ b/src/InspIRCd.layout
@@ -1,9 +1,9 @@
[Editors]
-Focused=2
-Order=7,3,2,6,25,24,4,5,1,0,-1
+Focused=4
+Order=1,2,-1,4
[Editor_0]
-Open=1
+Open=0
Top=0
CursorCol=20
CursorRow=57
@@ -14,20 +14,20 @@ LeftChar=1
Open=1
Top=0
CursorCol=1
-CursorRow=4808
-TopLine=4662
+CursorRow=5694
+TopLine=5640
LeftChar=1
[Editor_2]
Open=1
-Top=1
-CursorCol=28
-CursorRow=306
-TopLine=281
+Top=0
+CursorCol=8
+CursorRow=278
+TopLine=221
LeftChar=1
[Editor_3]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
@@ -36,14 +36,14 @@ LeftChar=1
[Editor_4]
Open=1
-Top=0
-CursorCol=1
-CursorRow=119
-TopLine=113
+Top=1
+CursorCol=38
+CursorRow=354
+TopLine=324
LeftChar=1
[Editor_5]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
@@ -51,7 +51,7 @@ TopLine=1
LeftChar=1
[Editor_6]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=36
@@ -59,7 +59,7 @@ TopLine=1
LeftChar=1
[Editor_7]
-Open=1
+Open=0
Top=0
CursorCol=20
CursorRow=15
@@ -67,7 +67,7 @@ TopLine=6
LeftChar=1
[Editor_8]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=33
@@ -83,7 +83,7 @@ TopLine=1
LeftChar=1
[Editor_10]
-Open=1
+Open=0
Top=0
CursorCol=31
CursorRow=75
@@ -147,10 +147,10 @@ TopLine=51
LeftChar=1
[Editor_18]
-Open=0
+Open=1
Top=0
-CursorCol=5
-CursorRow=22
+CursorCol=69
+CursorRow=31
TopLine=1
LeftChar=1
@@ -163,11 +163,11 @@ TopLine=1
LeftChar=1
[Editor_20]
-Open=0
+Open=1
Top=0
-CursorCol=6
-CursorRow=553
-TopLine=514
+CursorCol=20
+CursorRow=517
+TopLine=472
LeftChar=1
[Editor_21]
@@ -179,7 +179,7 @@ TopLine=1
LeftChar=1
[Editor_22]
-Open=1
+Open=0
Top=0
CursorCol=25
CursorRow=116
@@ -195,14 +195,14 @@ TopLine=1
LeftChar=1
[Editor_24]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
TopLine=1
LeftChar=1
[Editor_25]
-Open=1
+Open=0
Top=0
CursorCol=6
CursorRow=10
@@ -223,14 +223,14 @@ CursorRow=34
TopLine=1
LeftChar=1
[Editor_28]
-Open=0
+Open=1
Top=0
CursorCol=87
CursorRow=20
TopLine=5
LeftChar=1
[Editor_29]
-Open=0
+Open=1
Top=0
CursorCol=49
CursorRow=9
@@ -261,11 +261,11 @@ LeftChar=1
Open=0
Top=0
[Editor_34]
-Open=0
+Open=1
Top=0
-CursorCol=26
-CursorRow=155
-TopLine=113
+CursorCol=1
+CursorRow=86
+TopLine=32
LeftChar=1
[Editor_35]
Open=0
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)
diff --git a/src/modules.cpp b/src/modules.cpp
index bbea0d412..93e2d7850 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -349,6 +349,10 @@ int ConfigReader::Enumerate(std::string tag)
return EnumConf(cache,tag.c_str());
}
+int ConfigReader::EnumerateValues(std::string tag, int index)
+{
+ return EnumValues(cache, tag.c_str(), index);
+}
bool ConfigReader::Verify()
{