static ExpressionValue EvalTokenAsClass(const char *classname, void *param) { const EvalContext *ctx = ((EvalTokenAsClassContext *)param)->ctx; const char *ns = ((EvalTokenAsClassContext *)param)->ns; char qualified_class[CF_MAXVARSIZE]; if (strcmp(classname, "any") == 0) { return true; } if (strchr(classname, ':')) { if (strncmp(classname, "default:", strlen("default:")) == 0) { snprintf(qualified_class, CF_MAXVARSIZE, "%s", classname + strlen("default:")); } else { snprintf(qualified_class, CF_MAXVARSIZE, "%s", classname); } } else if (ns != NULL && strcmp(ns, "default") != 0) { snprintf(qualified_class, CF_MAXVARSIZE, "%s:%s", ns, (char *)classname); } else { snprintf(qualified_class, CF_MAXVARSIZE, "%s", classname); } if (EvalContextHeapContainsNegated(ctx, qualified_class)) { return false; } if (EvalContextStackFrameContainsNegated(ctx, qualified_class)) { return false; } if (EvalContextHeapContainsHard(ctx, classname)) // Hard classes are always unqualified { return true; } if (EvalContextHeapContainsSoft(ctx, qualified_class)) { return true; } if (EvalContextStackFrameContainsSoft(ctx, qualified_class)) { return true; } return false; }
void SaveClassEnvironment(EvalContext *ctx, Writer *writer) { { SetIterator it = EvalContextHeapIteratorHard(ctx); const char *context = NULL; while ((context = SetIteratorNext(&it))) { if (!EvalContextHeapContainsNegated(ctx, context)) { WriterWriteF(writer, "%s\n", context); } } } { SetIterator it = EvalContextHeapIteratorSoft(ctx); const char *context = NULL; while ((context = SetIteratorNext(&it))) { if (!EvalContextHeapContainsNegated(ctx, context)) { WriterWriteF(writer, "%s\n", context); } } } { SetIterator it = EvalContextStackFrameIteratorSoft(ctx); const char *context = NULL; while ((context = SetIteratorNext(&it))) { if (!EvalContextHeapContainsNegated(ctx, context)) { WriterWriteF(writer, "%s\n", context); } } } }
static void ShowContext(EvalContext *ctx) { { Writer *w = NULL; if (LEGACY_OUTPUT) { w = FileWriter(stdout); WriterWriteF(w, "%s> -> Hard classes = {", VPREFIX); } else { w = StringWriter(); WriterWrite(w, "Discovered hard classes:"); } Seq *hard_contexts = SeqNew(1000, NULL); SetIterator it = EvalContextHeapIteratorHard(ctx); char *context = NULL; while ((context = SetIteratorNext(&it))) { if (!EvalContextHeapContainsNegated(ctx, context)) { SeqAppend(hard_contexts, context); } } SeqSort(hard_contexts, (SeqItemComparator)strcmp, NULL); for (size_t i = 0; i < SeqLength(hard_contexts); i++) { const char *context = SeqAt(hard_contexts, i); WriterWriteF(w, " %s", context); } if (LEGACY_OUTPUT) { WriterWrite(w, "}\n"); FileWriterDetach(w); } else { Log(LOG_LEVEL_VERBOSE, "%s", StringWriterData(w)); WriterClose(w); } SeqDestroy(hard_contexts); } { Writer *w = NULL; if (LEGACY_OUTPUT) { w = FileWriter(stdout); WriterWriteF(w, "%s> -> Additional classes = {", VPREFIX); } else { w = StringWriter(); WriterWrite(w, "Additional classes:"); } Seq *soft_contexts = SeqNew(1000, NULL); SetIterator it = EvalContextHeapIteratorSoft(ctx); char *context = NULL; while ((context = SetIteratorNext(&it))) { if (!EvalContextHeapContainsNegated(ctx, context)) { SeqAppend(soft_contexts, context); } } SeqSort(soft_contexts, (SeqItemComparator)strcmp, NULL); for (size_t i = 0; i < SeqLength(soft_contexts); i++) { const char *context = SeqAt(soft_contexts, i); WriterWriteF(w, " %s", context); } if (LEGACY_OUTPUT) { WriterWrite(w, "}\n"); FileWriterDetach(w); } else { if (SeqLength(soft_contexts) > 0) { Log(LOG_LEVEL_VERBOSE, "%s", StringWriterData(w)); } WriterClose(w); } SeqDestroy(soft_contexts); } { bool have_negated_classes = false; Writer *w = NULL; if (LEGACY_OUTPUT) { w = FileWriter(stdout); WriterWriteF(w, "%s> -> Negated classes = {", VPREFIX); } else { w = StringWriter(); WriterWrite(w, "Negated classes:"); } StringSetIterator it = EvalContextHeapIteratorNegated(ctx); const char *context = NULL; while ((context = StringSetIteratorNext(&it))) { WriterWriteF(w, " %s", context); have_negated_classes = true; } if (LEGACY_OUTPUT) { WriterWrite(w, "}\n"); FileWriterDetach(w); } else { if (have_negated_classes) { Log(LOG_LEVEL_VERBOSE, "%s", StringWriterData(w)); } WriterClose(w); } } }