pcb 4.1.1
An interactive printed circuit board layout editor.

xmlout.h

Go to the documentation of this file.
00001 #ifndef _XMLOUT
00002 #define _XMLOUT 1
00003 
00004 #include <stdio.h>
00005 
00006 struct s_xmlout
00007 {
00008   FILE* fd;
00009   int count;
00010 };
00011 
00012 struct s_xmlout xmlout;
00013 
00014 char* indent[] =
00015 {
00016   "\n",
00017   "\n\t",
00018   "\n\t\t",
00019   "\n\t\t\t",
00020   "\n\t\t\t\t",
00021   "\n\t\t\t\t\t",
00022   "\n\t\t\t\t\t\t",
00023   "\n\t\t\t\t\t\t\t"
00024 };
00025 
00026 #define XPUTS fputs
00027 
00028 #define XPRINTF fprintf
00029 
00030 #define XNEWLINE indent[xmlout.count]
00031 
00032 #define XOUT_DETENT() if(xmlout.count) xmlout.count--
00033 
00034 #define XOUT_INDENT() xmlout.count++
00035 
00036 #define XOUT_ELEMENT_2ATTR_START(name, id1, val1, id2, val2) XPRINTF(xmlout.fd, "<%s %s=\"%s\" %s=\"%s\">", name, id1, val1, id2, val2);
00037 
00038 #define XOUT_ELEMENT_ATTR_START(name, id, val) XPRINTF(xmlout.fd, "<%s %s=\"%s\">", name, id, val);
00039 
00040 #define XOUT_ELEMENT_START(name) XPRINTF(xmlout.fd, "<%s>", name);
00041 
00042 #define XOUT_ELEMENT_END(name) XPRINTF(xmlout.fd, "</%s>", name);
00043 
00044 #define XOUT_ELEMENT_EMPTY(name) XPRINTF(xmlout.fd, "<%s/>", name)
00045 
00046 #define XOUT_ELEMENT_ATTR_EMPTY(name, id, val) XPRINTF(xmlout.fd, "<%s %s=\"%s\"/>", name, id, val)
00047 
00048 #define XOUT_ELEMENT_DATA(data) XPRINTF(xmlout.fd, "%s", data)
00049 
00050 #define XOUT_NEWLINE() XPUTS( XNEWLINE, xmlout.fd)
00051 
00052 #define XOUT_ELEMENT(name, data) XOUT_ELEMENT_START(name);\
00053                 XOUT_ELEMENT_DATA(data);\
00054                 XOUT_ELEMENT_END(name);
00055 
00056 #define XOUT_ELEMENT_ATTR(name, id, val, data) XOUT_ELEMENT_ATTR_START(name, id, val);\
00057                 XOUT_ELEMENT_DATA(data);\
00058                 XOUT_ELEMENT_END(name);
00059 
00060 #define XOUT_HEADER() XPRINTF(xmlout.fd, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
00061 
00062 #define XOUT_INIT(filename) xmlout.count=0;\
00063                 xmlout.fd = fopen(filename, "w")
00064 
00065 #define XOUT_CLOSE() xmlout.count=0;\
00066                 fclose(xmlout.fd); \
00067                 xmlout.fd = NULL
00068 
00069 #endif