first commit

This commit is contained in:
Your Name
2022-10-20 20:29:11 +08:00
commit 4d531f8044
3238 changed files with 1387862 additions and 0 deletions

7
utils/xmlgrep/README Normal file
View File

@@ -0,0 +1,7 @@
All utilities in this directory rely on the ZeroXML library.
The xmlgrep utility is part op the ZeroXML package which is now hosted at:
http://www.adalin.com
Any further development on ZeroXML will take place there.

View File

@@ -0,0 +1,124 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <malloc.h>
#include <assert.h>
#include "xml.h"
#define ROOTNODE "/PropertyList/generic"
#define BUFLEN 4096
#define PRINT_ERROR_AND_EXIT(id) \
if (xmlErrorGetNo(id, 0) != XML_NO_ERROR) { \
const char *errstr = xmlErrorGetString(id, 0); \
size_t column = xmlErrorGetColumnNo(id, 0); \
size_t lineno = xmlErrorGetLineNo(id, 1); \
printf("Error at line %i, column %i: %s\n", lineno, column, errstr); \
exit(-1); \
}
void print_binary_protocol(void *, char *, char *);
int main(int argc, char **argv)
{
void *root_id, *protocol_id = 0;
char *filename;
if (argc != 2)
{
printf("Usage: %s <filename>\n", argv[0]);
exit(-1);
}
filename = argv[1];
root_id = xmlOpen(filename);
if (root_id) protocol_id = xmlNodeGet(root_id, ROOTNODE);
if (protocol_id)
{
void *dir_id;
dir_id = xmlNodeGet(protocol_id, "input");
if (dir_id)
{
if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) {
print_binary_protocol(dir_id, filename, "input");
} else {
printf("Only binary mode support is implemented at the moment.\n");
}
free(dir_id);
}
dir_id = xmlNodeGet(protocol_id, "output");
if (dir_id)
{
if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) {
print_binary_protocol(dir_id, filename, "output");
} else {
printf("Only binary mode support is implemented at the moment.\n");
}
free(dir_id);
}
free(protocol_id);
}
if (root_id)
{
xmlClose(root_id);
}
return 0;
}
/* -------------------------------------------------------------------------- */
void print_binary_protocol(void *id, char *filename, char *dir)
{
unsigned int i, num, pos = 0;
void *xid;
printf("\n%s\n", filename);
printf("Generic binary %s protocol packet description:\n\n", dir);
printf(" pos | size | type | factor | description\n");
printf("-----|------|--------|------------|------------------------\n");
xid = xmlMarkId(id);
num = xmlNodeGetNum(xid, "chunk");
for (i=0; i<num; i++)
{
if (xmlNodeGetPos(id, xid, "chunk", i) != 0)
{
char factor[11];
char *name, *type;
int size;
type = xmlNodeGetString(xid, "type");
if (!strcasecmp(type, "bool")) {
size = 1;
} else if (!strcasecmp(type, "float")) {
size = 4;
} else if (!strcasecmp(type, "double")) {
size = 8;
} else if (!strcasecmp(type, "int")) {
size = 4;
} else {
printf("Unsupported type sepcified: '%s'\n\n", type);
free(type);
free(xid);
return;
}
xmlNodeCopyString(xid, "factor", (char *)&factor, 10);
name = xmlNodeGetString(xid, "name");
printf("%4i | %4i | %6s | %10s | %s\n", pos, size, type, factor, name);
pos += size;
free(type);
free(name);
}
}
printf("\ntotal package size: %i bytes\n\n", pos);
free(xid);
}

1074
utils/xmlgrep/metadata.c Normal file

File diff suppressed because it is too large Load Diff

157
utils/xmlgrep/recenter.c Normal file
View File

@@ -0,0 +1,157 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <xml.h>
char *
getCommandLineOption(int argc, char **argv, char const *option)
{
int slen = strlen(option);
char *rv = 0;
int i;
for (i=0; i<argc; i++)
{
if (strncmp(argv[i], option, slen) == 0)
{
rv = "";
i++;
if (i<argc) rv = argv[i];
}
}
return rv;
}
void
show_help()
{
printf("Usage: recenter <file>\n");
printf("Calculates the center location of all models in a file,\n");
printf("recenters all models around (0, 0, 0) and reports the\n");
printf("center location.\n");
exit(-1);
}
const char *delimiter = " ";
void print_xml(void *id, double x, double y, double z, char offsets, char* name)
{
static int level = 1;
void *xid = xmlMarkId(id);
unsigned int num;
num = xmlNodeGetNum(xid, "*");
if (num == 0)
{
if (offsets && strcasecmp(name, "offsets"))
{
double val = xmlGetDouble(id);
if (!strcasecmp(name, "x-m")) {
printf("%.3f", val-x);
} else if (!strcasecmp(name, "y-m")) {
printf("%.3f", val-y);
} else if (!strcasecmp(name, "z-m")) {
printf("%.3f", val-z);
} else {
printf("%.3f", val);
}
}
else
{
char *s;
s = xmlGetString(xid);
if (s)
{
printf("%s", s);
free(s);
}
}
}
else
{
unsigned int i, q;
for (i=0; i<num; i++)
{
if (xmlNodeGetPos(id, xid, "*", i) != 0)
{
char name[256];
xmlNodeCopyName(xid, (char *)&name, 256);
printf("\n");
for(q=0; q<level; q++) printf("%s", delimiter);
printf("<%s>", name);
level++;
if (!offsets) offsets = !strcasecmp(name, "offsets");
print_xml(xid, x, y, z, offsets, name);
level--;
printf("</%s>", name);
}
else printf("error\n");
}
printf("\n");
for(q=1; q<level; q++) printf("%s", delimiter);
}
}
int
main(int argc, char **argv)
{
const char *fname;
void *rid;
if (argc != 2) {
show_help();
}
fname = argv[1];
rid = xmlOpen(fname);
if (rid)
{
void *pid = xmlNodeGet(rid, "PropertyList");
if (pid)
{
double x, y, z;
int i, num;
void *mid;
x = y = z = 0.0;
mid = xmlMarkId(pid);
num = xmlNodeGetNum(pid, "model");
for (i=0; i<num; i++)
{
if (xmlNodeGetPos(pid, mid, "model", i) != 0)
{
void *oid = xmlNodeGet(mid, "offsets");
if (oid)
{
x += xmlNodeGetDouble(oid, "x-m");
y += xmlNodeGetDouble(oid, "y-m");
z += xmlNodeGetDouble(oid, "z-m");
xmlFree(oid);
}
}
}
xmlFree(mid);
x /= (double)num;
y /= (double)num;
z /= (double)num;
printf("<!--\n");
printf(" center: x-m: %5.3f\n", x);
printf(" center: y-m: %5.3f\n", y);
printf(" center: z-m: %5.3f\n", z);
printf("-->\n");
print_xml(rid, x, y, z, 0, "");
xmlFree(pid);
}
xmlClose(rid);
}
return 0;
}