⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parxml.c

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	tree_addData((tree_t *) data, &val, sizeof(unsigned long), PAR_COLOR);	return (data);    }    if (strcmp(prop->value, "bool")) {	fprintf(stderr, "Error - Invalid field type %s\n", prop->value);	return (0);    }    if (*text >= '0' && *text <= '9') {	int val = atoi(text);	bool = ((val == 0) ? 0 : 1);    } else {	int i;	xml_lowerCase(text, size);	for (i = 0; i < 6; i++) {	    if (size < strlen(bools[i].word))		continue;	    if (strncmp(bools[i].word, text, strlen(bools[i].word)) == 0)		bool = bools[i].value;	    break;	}    }    tree_addData((tree_t *) data, &bool, sizeof(unsigned char), PAR_BOOL);    return (data);}/* This is a generic function that handles tags like this: *//* <tagname name="value"> */static void *init_section(xml_token * tag, void *in){    void *out = 0;    xml_prop *prop;    if (!in) {	fprintf(stderr, "Error - No data for tag <%s>\n", tag->tag);	return (0);    }    for (prop = tag->props; prop; prop = prop->next) {	if (strcmp(prop->keyword, "name") == 0) {	    out = (void *) tree_addNode((tree_t *) in, prop->value);	    break;	}    }    return (out);}static void *applet_data(xml_token * tag, void *data, char *text, int size) {  tree_addData((tree_t *) data, text, size, PAR_TEXT);  return data;}static void *applet_init(xml_token *tag, void *in) {    void *out = 0;  xml_prop *prop;  for (prop = tag->props; prop; prop = prop->next) {    if (strcmp(prop->keyword, "name") == 0) {      out = (void *) tree_addNode((tree_t *) in, prop->value);      break;    }  }  return out;}static void *generic_init(xml_token * tag, void *in){    void *out;    /* Make a new node in the tree */    if (!in) {	fprintf(stderr, "Error - No data for tag <%s>\n", tag->tag);	return (0);    }    out = (void *) tree_addNode((tree_t *) in, tag->tag);    return (out);}/* This is the actual parsing function */intparseXML(char *file, tree_t * head){    xml_parser engine;    engine.tags = tagToplevel;    /* Now, start the parser */    return (xml_parseFile(&engine, file, ((void *) head)));}/* These are some generic headers and footers that we use */static voidpar_data_header(FILE * stream, xml_encode * encode, void *data, int indent){    indentLine(stream, indent);    fprintf(stream, "<%s>", encode->tag);}/* This is like some other headers, but without the \n at the end */static voidpar_named_header(FILE * stream, xml_encode * encode, void *data, int indent){    tree_t *node = data;    if (!node)	return;    indentLine(stream, indent);    fprintf(stream, "<%s name=\"%s\">", encode->tag, node->keyword);}static voidpar_data_footer(FILE * stream, xml_encode * encode, void *data, int indent){    fprintf(stream, "</%s>\n", encode->tag);}static voidpar_data(FILE * stream, void *in){    tree_t *node = (tree_t *) in;    if (!node)	return;    switch (node->type) {    case PAR_NONE:	break;    case PAR_TEXT:	fprintf(stream, "%s", (char *) node->data);	break;    case PAR_INT:	fprintf(stream, "%i", *((int *) node->data));	break;    case PAR_BOOL:	fprintf(stream, "%s", ((*((int *) node->data) == 0) ? "Yes" : "No"));	break;    case PAR_FLOAT:	fprintf(stream, "%f", *((double *) node->data));	break;    case PAR_COLOR:	fprintf(stream, "#%6.6lX",		(*((unsigned long *) node->data)) & 0xFFFFFF);	break;    }}static voidpar_color(FILE * stream, void *in){    unsigned long val;    tree_t *node = (tree_t *) in;    if (!node)	return;    if (node->type != PAR_INT)	return;    val = *((unsigned long *) node->data);    fprintf(stream, "#%6.6lX", val & 0xFFFFFF);}static voidprefs_header(FILE * stream, xml_encode * encode, void *data, int indent){    tree_t *node = (tree_t *) data;    if (!node)	return;    indentLine(stream, indent);    fprintf(stream, "<%s key=\"%s\"", encode->tag, node->keyword);    switch (node->type) {    case PAR_NONE:	break;    case PAR_TEXT:	fprintf(stream, " type=STR");	break;    case PAR_INT:	fprintf(stream, " type=INT");	break;    case PAR_BOOL:	fprintf(stream, " type=BOOL");	break;    case PAR_FLOAT:	fprintf(stream, " type=FLOAT");	break;    case PAR_COLOR:	fprintf(stream, " type=COLOR");	break;    }    fprintf(stream, ">");}static voidapp_header(FILE * stream, xml_encode * encode, void *data, int indent){    tree_t *node = data;    if (!node)	return;    indentLine(stream, indent);    fprintf(stream, "<%s name=\"%s\">\n", encode->tag, node->keyword);}static voidcategory_header(FILE * stream, xml_encode * encode, void *data, int indent){    tree_t *node = data;    if (!node)	return;    indentLine(stream, indent);    fprintf(stream, "<%s name=\"%s\">\n", encode->tag, node->keyword);}static voidpar_xml_header(FILE * stream){    char buffer[26];    time_t curtime;    time(&curtime);    strcpy(buffer, ctime(&curtime));    buffer[strlen(buffer) - 1] = 0;    fprintf(stream, "<!-- Pixil Application Registry Database -->\n");    fprintf(stream, "<!-- Written %s -->\n\n", buffer);}static void *par_xml_find(char *keyword, void *in){    tree_t *node = (tree_t *) in;    if (!node)	return (0);    node = node->child;    /* If it is a wildcard, then get the first child */    if (keyword[0] == '*')	return (node);    /* Otherwise, search for the specific keyword */    while (node) {	if (strcmp(keyword, node->keyword) == 0)	    return ((void *) node);	node = node->peer;    }    return (0);}static void *par_xml_next(char *keyword, void *in){    tree_t *node = (tree_t *) in;    if (!node)	return (0);    node = node->peer;    if (keyword[0] == '*')	return (node);    while (node) {	if (strcmp(keyword, node->keyword) == 0)	    return ((void *) node);	node = node->peer;    }    return (0);}intencodeXML(char *filename, tree_t * head){    xml_encoder engine;    engine.header = par_xml_header;    engine.footer = 0;    engine.find = par_xml_find;    engine.next = par_xml_next;    return (xml_encodeFile(&engine, encodeGlobal, filename, (void *) head));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -