/** * Checks that an element has non-empty values for required attributes. * Increments the error count for each missing attribute. * * @param context the parsing context * @param elem the element being checked * @param atts the attribute list for the element * @param req_atts the required attributes (NULL terminated list, or NULL) * @return whether the required attributes are present */ static int check_req_attributes(ploader_context_t *plcontext, const XML_Char *elem, const XML_Char * const *atts, const XML_Char * const *req_atts) { const XML_Char * const *a; int error = 0; // Check that required attributes have non-empty values for (a = req_atts; a != NULL && *a != NULL; a++) { const XML_Char * const *av; if ((av = contains_str(atts, *a, 2)) != NULL) { if ((*(av + 1))[0] == '\0') { descriptor_errorf(plcontext, 0, _("required attribute %s for element %s has an empty value"), *a, elem); error = 1; } } else { descriptor_errorf(plcontext, 0, _("required attribute %s missing for element %s"), *a, elem); error = 1; } } return !error; }
int compare_answer(char * evaled, char * answer){ int ret = 1; char temp_evaled[strlen(evaled)]; strcpy(temp_evaled, evaled); char * expr = strtok (temp_evaled,"\n"); //test if all of the expression are in the answer while (expr != NULL){ ret*=contains_str(answer, expr); expr = strtok (NULL,"\n"); } //also test that all of the answers are in the expression char * ans_expr = strtok (answer,"\n"); while (ans_expr != NULL){ ret*=contains_str(evaled, ans_expr); ans_expr = strtok (NULL,"\n"); } return ret; }
/** * Checks that an element has non-empty values for required attributes and * warns if there are unknown attributes. Increments the error count for * each missing required attribute. * * @param context the parsing context * @param elem the element being checked * @param atts the attribute list for the element * @param req_atts the required attributes (NULL terminated list, or NULL) * @param opt_atts the optional attributes (NULL terminated list, or NULL) * @return whether the required attributes are present */ static int check_attributes(ploader_context_t *plcontext, const XML_Char *elem, const XML_Char * const *atts, const XML_Char * const *req_atts, const XML_Char * const *opt_atts) { int error = 0; // Check required attributes error = !check_req_attributes(plcontext, elem, atts, req_atts); // Warn if there are unknown attributes for (; *atts != NULL; atts += 2) { if (contains_str(req_atts, *atts, 1) == NULL && contains_str(opt_atts, *atts, 1) == NULL) { descriptor_errorf(plcontext, 1, _("ignoring unknown attribute %s for element %s"), *atts, elem); } } return !error; }