- ULONG ComponentId, Level;
- BOOLEAN State;
- PCHAR pend;
-
- if (Argc < 2)
- {
- KdbpPrint("filter: component name argument required!\n");
- return TRUE;
- }
- if (!KdbpGetComponentId(Argv[1], &ComponentId))
- {
- KdbpPrint("filter: '%s' is not a valid component name!\n", Argv[1]);
- return TRUE;
- }
-
- if (Argc < 3)
- {
- KdbpPrint("filter: level argument required!\n");
- return TRUE;
- }
- if (_stricmp(Argv[2], "error") == 0)
- Level = DPFLTR_ERROR_LEVEL;
- else if (_stricmp(Argv[2], "warning") == 0)
- Level = DPFLTR_WARNING_LEVEL;
- else if (_stricmp(Argv[2], "trace") == 0)
- Level = DPFLTR_TRACE_LEVEL;
- else if (_stricmp(Argv[2], "info") == 0)
- Level = DPFLTR_INFO_LEVEL;
- else
- {
- Level = strtoul(Argv[2], &pend, 0);
- if (Argv[2] == pend || *pend != '\0')
- {
- KdbpPrint("filter: '%s' is not a valid level!\n", Argv[2]);
- return TRUE;
- }
- }
+ ULONG i, j, ComponentId, Level;
+ ULONG set = DPFLTR_MASK, clear = DPFLTR_MASK;
+ PCHAR pend;
+ LPCSTR opt, p;
+ static struct {
+ LPCSTR Name;
+ ULONG Level;
+ } debug_classes[] = {
+ { "error", 1 << DPFLTR_ERROR_LEVEL },
+ { "warning", 1 << DPFLTR_WARNING_LEVEL },
+ { "trace", 1 << DPFLTR_TRACE_LEVEL },
+ { "info", 1 << DPFLTR_INFO_LEVEL },
+ };
+
+ for (i = 1; i < Argc; i++)
+ {
+ opt = Argv[i];
+ p = opt + strcspn(opt, "+-");
+ if (!p[0]) p = opt; /* assume it's a debug channel name */
+
+ if (p > opt)
+ {
+ for (j = 0; j < sizeof(debug_classes) / sizeof(debug_classes[0]); j++)
+ {
+ SIZE_T len = strlen(debug_classes[j].Name);
+ if (len != (p - opt))
+ continue;
+ if (_strnicmp(opt, debug_classes[j].Name, len) == 0) /* found it */
+ {
+ if (*p == '+')
+ set |= debug_classes[j].Level;
+ else
+ clear |= debug_classes[j].Level;
+ break;
+ }
+ }
+ if (j == sizeof(debug_classes) / sizeof(debug_classes[0]))
+ {
+ Level = strtoul(opt, &pend, 0);
+ if (pend != p)
+ {
+ KdbpPrint("filter: bad class name '%.*s'\n", p - opt, opt);
+ continue;
+ }
+ if (*p == '+')
+ set |= Level;
+ else
+ clear |= Level;
+ }
+ }
+ else
+ {
+ if (*p == '-')
+ clear = ~0;
+ else
+ set = ~0;
+ }
+ if (*p == '+' || *p == '-')
+ p++;
+
+ if (!KdbpGetComponentId(p, &ComponentId))
+ {
+ KdbpPrint("filter: '%s' is not a valid component name!\n", p);
+ return TRUE;
+ }