📄 parxml.c
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */#include <stdlib.h>#include <string.h>#include <ctype.h>#include <time.h>#include <par/pardb.h>#include "database.h"#include <xml/xml.h>static void *generic_init(xml_token *, void *);/* These are the local decoding functions */static void *init_key(xml_token *, void *);static void *data_key(xml_token *, void *, char *, int);static void *init_section(xml_token *, void *);static void *data_caplist(xml_token *, void *, char *, int);static void *generic_textlist(xml_token *, void *, char *, int);static void *data_color(xml_token *, void *, char *, int);static void *data_text(xml_token *, void *, char *, int);static void *data_value(xml_token *, void *, char *, int);static void * applet_init(xml_token *tag, void *in);static void *applet_data(xml_token *tag, void *data, char *text, int size);/* These are the local encoding functions */static void prefs_header(FILE *, xml_encode *, void *, int);static void app_header(FILE *, xml_encode *, void *, int);static void par_named_header(FILE * stream, xml_encode * encode, void *data, int indent);static void par_data_header(FILE *, xml_encode *, void *, int);static void par_data_footer(FILE *, xml_encode *, void *, int);static void par_data(FILE *, void *);static void par_color(FILE *, void *);static void category_header(FILE *, xml_encode *, void *, int);/* The tags are defined here for readabilty */#include "partags.h"static void *init_key(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, "key") == 0) { out = (void *) tree_addNode((tree_t *) in, prop->value); break; } } return (out);}/* This is a generic function that will take a item and append it to an *//* ever growing list */static void *generic_textlist(xml_token * tag, void *data, char *text, int size){ tree_t *node; if (!data) { fprintf(stderr, "Error - No data for tag <%s>\n", tag->tag); return (0); } /* First, we need to see if this node already exists in the tree */ node = tree_findChildNode((tree_t *) data, tag->tag); if (node) { char *ndata = alloca(node->size + strlen(text) + 2); sprintf(ndata, "%s %s", (char *) node->data, text); tree_addData(node, ndata, strlen(ndata), PAR_TEXT); } else { node = tree_addNode((tree_t *) data, tag->tag); tree_addData(node, text, size, PAR_TEXT); } return ((void *) node);}static void *data_caplist(xml_token * tag, void *data, char *text, int size){ char *lname = 0; tree_t *node; xml_prop *prop; if (!data) { fprintf(stderr, "No data for tag %s\n", tag->tag); return (0); } for (prop = tag->props; prop; prop = prop->next) { if (strcmp(prop->keyword, "name") == 0) { lname = prop->value; break; } } if (!lname) { fprintf(stderr, "Couldn't find the keyword 'name' in %s\n", tag->tag); return (0); } printf("Adding / Modifying %s\n", lname); /* First, we need to see if this node already exists in the tree */ node = tree_findChildNode((tree_t *) data, lname); if (node) { char *ndata = alloca(node->size + strlen(text) + 2); sprintf(ndata, "%s %s", (char *) node->data, text); tree_addData(node, ndata, strlen(ndata), PAR_TEXT); } else { node = tree_addNode((tree_t *) data, lname); tree_addData(node, text, size, PAR_TEXT); } return ((void *) node);}/* Generic function to add an integer to the par database */static void *data_value(xml_token * tag, void *data, char *text, int size){ int val; tree_t *node; if (!data) { fprintf(stderr, "Error - No data for tag <%s>\n", tag->tag); return (0); } if (!text) return (0); /* If the first char is not a digit, then error */ if (!isdigit(*text)) return (0); val = atoi(text); node = tree_addNode((tree_t *) data, tag->tag); tree_addData(node, (void *) &val, sizeof(int), PAR_INT); return ((void *) node);}/* This is a generic function that will add a text item to the database */static void *data_text(xml_token * tag, void *data, char *text, int size){ tree_t *node; if (!data) { fprintf(stderr, "Error - No data for tag <%s>\n", tag->tag); return (0); } node = tree_addNode((tree_t *) data, tag->tag); tree_addData(node, text, size, PAR_TEXT); return ((void *) node);}/* This is a generic function that adds a color to the database */static void *data_color(xml_token * tag, void *data, char *text, int size){ tree_t *node = 0; unsigned long val; xml_prop *prop; if (!data || !text) return (0); for (prop = tag->props; prop; prop = prop->next) { if (strcmp(prop->keyword, "name") == 0) { node = (void *) tree_addNode((tree_t *) data, prop->value); break; } } if (!node) return (0); if (xml_parseColor(text, &val, size) == -1) { fprintf(stderr, "Error - Unable to parse the color\n"); return (0); } tree_addData(node, &val, sizeof(unsigned long), PAR_INT); return ((void *) node);}/* This is a specific function that handles a preference value */static void *data_key(xml_token * tag, void *data, char *text, int size){ struct bool_list { char word[5]; char value; } bools[] = { { "yes", 1} , { "no", 0} , { "true", 1} , { "false", 0} , { "on", 1} , { "off", 0} }; xml_prop *prop; char bool = 0; /* Default to false */ if (!data) { 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, "type") == 0) break; /* If no keyword was specified, then assume text */ if (!prop) { tree_addData((tree_t *) data, text, size, PAR_TEXT); return (data); } /* Set the keyword to lower case */ xml_lowerCase(prop->value, -1); if (strcmp(prop->value, "str") == 0) { tree_addData((tree_t *) data, text, size, PAR_TEXT); return (data); } if (strcmp(prop->value, "int") == 0) { int ival; /* Check to see if this is a hex by chance */ if ((size > 2) && (strncmp(text, "0x", 2) == 0)) ival = strtol(text, 0, 16); else ival = atoi(text); tree_addData((tree_t *) data, &ival, sizeof(int), PAR_INT); return (data); } if (strcmp(prop->value, "float") == 0) { double fval = atof(text); tree_addData((tree_t *) data, &fval, sizeof(double), PAR_FLOAT); return (data); } if (strcmp(prop->value, "color") == 0) { unsigned long val; if (xml_parseColor(text, &val, size) == -1) { fprintf(stderr, "Error - Unable to parse the color\n"); return (0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -