aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Brooksby2012-10-26 17:04:30 +0100
committerRichard Brooksby2012-10-26 17:04:30 +0100
commit5ee7e6dd8472934384abda6281a09f63da8be323 (patch)
tree08a8f1debb5474fbcabfbe2f00b20a87e41e8847 /mps/code
parentd48d96f15ec9f10f468e5c4a1a93f78f7ce7ad5b (diff)
downloademacs-5ee7e6dd8472934384abda6281a09f63da8be323.tar.gz
emacs-5ee7e6dd8472934384abda6281a09f63da8be323.zip
Tidying up case-insensitive mps_telemetry_control implementation a bit.
Copied from Perforce Change: 180109 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/mpsliban.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/mps/code/mpsliban.c b/mps/code/mpsliban.c
index f966df6f4f2..012e5363e86 100644
--- a/mps/code/mpsliban.c
+++ b/mps/code/mpsliban.c
@@ -113,6 +113,20 @@ mps_clock_t mps_clocks_per_sec(void)
113#pragma warning( disable : 4996 ) 113#pragma warning( disable : 4996 )
114#endif 114#endif
115 115
116/* Simple case-insensitive string comparison */
117static int striequal(const char *s0, const char *s1)
118{
119 int c;
120 do {
121 c = *s0;
122 if (tolower(c) != tolower(*s1)) /* note: works for '\0' */
123 return 0;
124 ++s0;
125 ++s1;
126 } while (c != '\0');
127 return 1;
128}
129
116unsigned long mps_lib_telemetry_control(void) 130unsigned long mps_lib_telemetry_control(void)
117{ 131{
118 char *s; 132 char *s;
@@ -120,9 +134,7 @@ unsigned long mps_lib_telemetry_control(void)
120 unsigned long mask; 134 unsigned long mask;
121 char buf[256]; 135 char buf[256];
122 char *word; 136 char *word;
123 char *p;
124 char *sep = " "; 137 char *sep = " ";
125 char rowName[256];
126 138
127 s = getenv("MPS_TELEMETRY_CONTROL"); 139 s = getenv("MPS_TELEMETRY_CONTROL");
128 if (s == NULL) 140 if (s == NULL)
@@ -136,26 +148,20 @@ unsigned long mps_lib_telemetry_control(void)
136 /* copy the envar to a buffer so we can mess with it. */ 148 /* copy the envar to a buffer so we can mess with it. */
137 strncpy(buf, s, sizeof(buf) - 1); 149 strncpy(buf, s, sizeof(buf) - 1);
138 buf[sizeof(buf) - 1] = '\0'; 150 buf[sizeof(buf) - 1] = '\0';
139 /* downcase it */
140 for (p = buf; *p != '\0'; ++p)
141 *p = (char)tolower(*p);
142 151
143 /* Split the value at spaces and try to match the words against the names 152 /* Split the value at spaces and try to match the words against the names
144 of event kinds, enabling them if there's a match. */ 153 of event kinds, enabling them if there's a match. */
145 for (word = strtok(buf, sep); word != NULL; word = strtok(NULL, sep)) { 154 for (word = strtok(buf, sep); word != NULL; word = strtok(NULL, sep)) {
146 if (strcmp(word, "all") == 0) { 155 if (striequal(word, "all")) {
147 mask = (unsigned long)-1; 156 mask = (unsigned long)-1;
148 printf("All events."); 157 printf("All events.");
149 return mask; 158 return mask;
150 } 159 }
151#define TELEMATCH(X, name, rowDoc) \ 160#define TELEMATCH(X, name, rowDoc) \
152 strncpy(rowName, #name, sizeof(rowName) - 1); \ 161 if (striequal(word, #name)) { \
153 rowName[sizeof(rowName) - 1] = '\0'; \
154 for (p = rowName; *p != '\0'; ++p) \
155 *p = (char)tolower(*p); \
156 if (strcmp(word, rowName) == 0) { \
157 mask |= (1ul << EventKind##name); \ 162 mask |= (1ul << EventKind##name); \
158 printf("Events to include " rowDoc "\n"); } 163 printf("Events to include " rowDoc "\n"); \
164 }
159 EventKindENUM(TELEMATCH, X) 165 EventKindENUM(TELEMATCH, X)
160 } 166 }
161 167