Beispiel #1
0
int main(void)
{
	XmlNode *x, *t;
	/* This is how many tests you plan to run */
	plan_tests(12);

	ok1(x = xml_load("./test/test.xml1"));
	ok1(!xml_find(x, "Doesn't Exist"));
	ok1(t = xml_find(x, "one"));
	ok1(xml_find(t, "two"));
	ok1(!xml_attr(t, "foobar"));
	ok1(!xml_attr(t, "Doesn't Exist"));
	ok1(xml_attr(t, "barfoo"));
	xml_free(x);
	/* Simple thing we expect to succeed */
	ok1(!test_load("does not exist")); /* A file that doesn't exist */
	ok1(test_load("./test/test.xml1")); /* A basic xml file. */
	ok1(test_load("./test/test.xml2")); /* Very small well-formed xml file. */
	ok1(test_load("./test/test.xml3")); /* Smallest well-formed xml file. */
	ok1(test_load("./test/test.xml4")); /* A single unclosed tag. */
	/* Same, with an explicit description of the test. */
//	ok(some_test(), "%s with no args should return 1", "some_test")
	/* How to print out messages for debugging. */
//	diag("Address of some_test is %p", &some_test)
	/* Conditional tests must be explicitly skipped. */

	/* This exits depending on whether all tests passed */
	return exit_status();
}
Beispiel #2
0
static int test_load(const char * filename)
{
	XmlNode *xml = xml_load(filename);
	if(!xml) return 0;

	xml_free(xml);
	return 1;
}
Beispiel #3
0
fmll_som * fmll_som_load(const char * fname_prefix,
		double (* distance_w)(const double *, const double *, const unsigned), double (* distance)(const double *, const double *, const unsigned))
{
	char node_name[4096];
	int map_dim, dim;
	unsigned u, v, num, * N = NULL;
	double ** w;
	fmll_som * som = NULL;
	mxml_node_t * sub_sub_node, * sub_node, * node, * content_node, * main_node = NULL;

	fmll_try;

		fmll_throw_if(xml_load(fname_prefix, TYPE_SOM, & main_node, & content_node));

		fmll_throw_if(xml_get_int(content_node, "map_dim", & map_dim));
		fmll_throw_if(xml_get_int(content_node, "dim", & dim));

		fmll_throw_null(N = fmll_alloc(sizeof(unsigned), 1, map_dim));
		fmll_throw_null(node = mxmlFindElement(content_node, content_node, "N", NULL, NULL, MXML_DESCEND_FIRST));

		for(u = 0, sub_node = mxmlFindElement(node, node, NULL, NULL, NULL, MXML_DESCEND_FIRST); u < map_dim; u++)
		{
			fmll_throw_null(sub_node);
			N[u] = sub_node->child->value.integer;
			sub_node = mxmlFindElement(sub_node, node, NULL, NULL, NULL, MXML_DESCEND);
		}

		fmll_throw_null(som = fmll_som_init(N, map_dim, dim, distance_w, distance));
		fmll_throw_null(node = mxmlFindElement(content_node, content_node, "W", NULL, NULL, MXML_DESCEND_FIRST));

		w = som->w;
		num = som->num;

		for(u = 0; u < num; u++)
		{
			sprintf(node_name, "w_%u", u);
			fmll_throw_null(sub_node = mxmlFindElement(node, node, node_name, NULL, NULL, MXML_DESCEND_FIRST));

			for(v = 0, sub_sub_node = mxmlFindElement(sub_node, sub_node, NULL, NULL, NULL, MXML_DESCEND_FIRST); v < dim; v++)
			{
				w[u][v] = sub_sub_node->child->value.real;
				sub_sub_node = mxmlFindElement(sub_sub_node, sub_node, NULL, NULL, NULL, MXML_DESCEND);
			}
		}


	fmll_catch;

		fmll_som_destroy(som);
		som = NULL;

	fmll_finally;

		fmll_free(N);
		xml_destroy(main_node);

	return som;
}
Beispiel #4
0
    /*
    ==============================
    ==============================
    */
    void IKAModule::Start()
    {
        xml_document<>* doc = new xml_document<>;

        xml_load(doc, defaultFile);

        InitLimb();
        InitCamera();
    }
Beispiel #5
0
/*
 * load a configuration, decrypting it if credentials found
 */
XML *cfg_load (char *path)
{
  XML *xml;
  
  cfg_clean (path);
  if ((xml = xml_load (path)) == NULL)
    return (NULL);
  if (strcmp (xml_root (xml), "Phineas"))
  {
    unsigned char *p;
    xcrypt_decrypt (xml, &p, ConfigCert, NULL, ConfigPass);
    xml_free (xml);
    xml = xml_parse (p);
    free (p);
  }
  return (xml);
}
Beispiel #6
0
void xmlb (FILE *fp, char *fname, int indent)
{
  XML *xml;
  char *ch;

  if ((xml = xml_load (fname)) == NULL)
    return;
  xml_beautify (xml, indent);
  ch = xml_format (xml);
  xml_free (xml);
  if (ch != NULL)
  {
    if (fp == NULL)
      fp = stdout;
    fprintf (fp, "%s", ch);
    free (ch);
  }
}
Beispiel #7
0
fmll_pca * fmll_pca_load(const char * fname_prefix)
{
	int dim, num;
	char node_name[4096];
	unsigned u, v;
	double ** w;
	fmll_pca * pca = NULL;
	mxml_node_t * sub_sub_node, * sub_node, * node, * content_node, * main_node = NULL;

	fmll_try;

		fmll_throw_if(xml_load(fname_prefix, TYPE_PCA, & main_node, & content_node));

		fmll_throw_if(xml_get_int(content_node, "dim", & dim));
		fmll_throw_if(xml_get_int(content_node, "num", & num));

		fmll_throw_null(pca = fmll_pca_init(dim, num));
		fmll_throw_null(node = mxmlFindElement(content_node, content_node, "W", NULL, NULL, MXML_DESCEND_FIRST));

		for(u = 0, w = pca->w; u < num; u++)
		{
			sprintf(node_name, "w_%u", u);
			fmll_throw_null(sub_node = mxmlFindElement(node, node, node_name, NULL, NULL, MXML_DESCEND_FIRST));

			for(v = 0, sub_sub_node = mxmlFindElement(sub_node, sub_node, NULL, NULL, NULL, MXML_DESCEND_FIRST); v < dim; v++)
			{
				w[u][v] = sub_sub_node->child->value.real;
				sub_sub_node = mxmlFindElement(sub_sub_node, sub_node, NULL, NULL, NULL, MXML_DESCEND);
			}
		}

	fmll_catch;

		fmll_pca_destroy(pca);
		pca = NULL;

	fmll_finally;

		xml_destroy(main_node);

	return pca;
}
Beispiel #8
0
fmll_svm_net * fmll_svm_net_load(const char * fname_prefix, double (** K)(const double *, const double *, const unsigned))
{
	int num;
	unsigned u;
	char node_name[4096];
	fmll_svm ** svm = NULL;
	fmll_svm_net * svm_net = NULL;
	mxml_node_t * sub_node, * node, * content_node, * main_node = NULL;

	fmll_try;

		fmll_throw_null(svm_net = fmll_alloc(sizeof(fmll_svm_net), 1, 1));
		fmll_throw_if(xml_load(fname_prefix, TYPE_SVM_NET, & main_node, & content_node));
		fmll_throw_if(xml_get_int(content_node, "num", & num));

		svm_net->num = num;

		fmll_throw_null(svm = svm_net->svm = (fmll_svm **) fmll_alloc(sizeof(fmll_svm *), 1, num));
		fmll_throw_null(node = mxmlFindElement(content_node, content_node, "SVM", NULL, NULL, MXML_DESCEND_FIRST));

		for(u = 0; u < num; u++)
			svm[u] = NULL;

		for(u = 0; u < num; u++)
		{
			sprintf(node_name, "svm_%u", u);
			fmll_throw_null(sub_node = mxmlFindElement(node, node, node_name, NULL, NULL, MXML_DESCEND_FIRST));
			fmll_throw_null(svm[u] = fmll_svm_load_main(sub_node, K[u]));
		}
	
	fmll_catch;

		fmll_svm_net_destroy(svm_net);
		svm_net = NULL;

	fmll_finally;

		xml_destroy(main_node);

	return svm_net;
}
// ---------------------------------
// Find an element string in the <HID_cookie_strings.plist> resource (XML) file
static Boolean xml_search_cookie(const long pVendorID, const long pProductID, const long pCookie, char* pCstr)
{
	static CFPropertyListRef tCFPropertyListRef = NULL;
	Boolean results = false;

	if (NULL == tCFPropertyListRef)
		tCFPropertyListRef = xml_load(CFSTR("HID_cookie_strings"), CFSTR("plist"));
	if (NULL != tCFPropertyListRef)
	{
		if (CFDictionaryGetTypeID() == CFGetTypeID(tCFPropertyListRef))
		{
			CFDictionaryRef vendorCFDictionaryRef;
			CFStringRef	vendorKeyCFStringRef;
			vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pVendorID);

			if (CFDictionaryGetValueIfPresent(tCFPropertyListRef, vendorKeyCFStringRef, (const void**) &vendorCFDictionaryRef))
			{
				CFDictionaryRef productCFDictionaryRef;
				CFStringRef	productKeyCFStringRef;
				CFStringRef	vendorCFStringRef;

				if (CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, CFSTR("Name"), (const void**) &vendorCFStringRef))
				{
					//CFShow(vendorCFStringRef);
				}
				productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pProductID);

				if (CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void**) &productCFDictionaryRef))
				{
					CFStringRef fullCFStringRef = NULL;
					CFStringRef	cookieKeyCFStringRef;
					CFStringRef	productCFStringRef;
					CFStringRef	cookieCFStringRef;

					if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, CFSTR("Name"), (const void**) &productCFStringRef))
					{
						//CFShow(productCFStringRef);
					}
					cookieKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), pCookie);

					if (CFDictionaryGetValueIfPresent(productCFDictionaryRef, cookieKeyCFStringRef, (const void**) &cookieCFStringRef))
					{
						fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ %@"), 
												 vendorCFStringRef, productCFStringRef, cookieCFStringRef);
						// CFShow(cookieCFStringRef);
					}
#if FAKE_IT
					else
					{
						fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ %@ #%@"), 
												 vendorCFStringRef, productCFStringRef, cookieKeyCFStringRef);
					}
#endif
					if (fullCFStringRef)
					{
						// CFShow(fullCFStringRef);
						results = CFStringGetCString(
								   fullCFStringRef, pCstr, CFStringGetLength(fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingMacRoman);
						CFRelease(fullCFStringRef);
					}
					CFRelease(cookieKeyCFStringRef);
				}
				CFRelease(productKeyCFStringRef);
			}
			CFRelease(vendorKeyCFStringRef);
		}
		//++CFRelease(tCFPropertyListRef);	// Leak this!
	}
	return results;
}