You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/23 13:08:16 UTC
svn commit: r806951 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr_ini.h shared/ini.c test/PrintManifest.java
test/PrintProperties.java test/PrintSystemProperties.java test/sample.conf
test/sample.properties test/testsuite.c
Author: mturk
Date: Sun Aug 23 11:08:15 2009
New Revision: 806951
URL: http://svn.apache.org/viewvc?rev=806951&view=rev
Log:
Add more ini code and suport test files
Added:
commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java (with props)
commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java (with props)
commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java (with props)
commons/sandbox/runtime/trunk/src/main/native/test/sample.conf
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr_ini.h
commons/sandbox/runtime/trunk/src/main/native/shared/ini.c
commons/sandbox/runtime/trunk/src/main/native/test/sample.properties
commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_ini.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_ini.h?rev=806951&r1=806950&r2=806951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_ini.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_ini.h Sun Aug 23 11:08:15 2009
@@ -49,6 +49,7 @@
char *attr;
ini_node_t *nodes;
ini_section_t *child;
+ ini_section_t *parent;
};
/**
@@ -67,9 +68,31 @@
/**
* Load the Java properties style configuration file.
* @param env Current JNI environment.
- * @param fname INI file to load.
+ * @param fname Properties file to load.
+ * @param allowdup If nonzero duplicate keys are allowed
+ */
+ACR_DECLARE(ini_section_t *) ACR_IniLoadProperties(JNIEnv *env,
+ const char *fname,
+ int allowdups);
+
+/**
+ * Load the Java properties style configuration file.
+ * @param env Current JNI environment.
+ * @param fname Properties file to load.
+ * @param section separator character.
+ * @param allowdup If nonzero duplicate keys are allowed
+ */
+ACR_DECLARE(ini_section_t *) ACR_IniLoadPropertiesTree(JNIEnv *env,
+ const char *fname,
+ int separator,
+ int allowdups);
+
+/**
+ * Load the Apache Httpd style configuration file.
+ * @param env Current JNI environment.
+ * @param fname Conf file to load.
*/
-ACR_DECLARE(ini_section_t *) ACR_IniLoadProps(JNIEnv *_E, const char *fname);
+ACR_DECLARE(ini_section_t *) ACR_IniLoadConf(JNIEnv *env, const char *fname);
#ifdef __cplusplus
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/ini.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/ini.c?rev=806951&r1=806950&r2=806951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/ini.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/ini.c Sun Aug 23 11:08:15 2009
@@ -70,7 +70,7 @@
}
else
ini->last = &ini->next;
-
+ ini->parent = top;
return ini;
}
@@ -86,6 +86,7 @@
ini->last = &ini->next;
parent->child = ini;
}
+ ini->parent = parent;
return ini;
}
@@ -109,12 +110,28 @@
if (!ini)
return NULL;
for (p = ini; p; p = p->next) {
- if (p->name && !strcasecmp(p->name, name))
+ if (name && p->name && !strcasecmp(p->name, name))
+ return p;
+ else if (name == NULL && p->name == NULL)
return p;
}
return NULL;
}
+static ini_node_t *ini_node_get(ini_section_t *ini, const char *key)
+{
+ ini_node_t *n;
+ if (!ini)
+ return NULL;
+ for (n = ini->nodes; n; n = n->next) {
+ if (key && n->key && !strcasecmp(n->key, key))
+ return n;
+ else if (key == NULL && n->key == NULL)
+ return n;
+ }
+ return NULL;
+}
+
static char *rtrim(char *s)
{
size_t i;
@@ -127,16 +144,25 @@
return s;
}
-static char *ltrim(char *s)
+static char *ltrim(const char *s)
{
size_t i;
+ /* check for empty strings */
+ if (!s)
+ return (char *)s;
for (i = 0; s[i] != '\0' && acr_isspace(s[i]); i++)
;
- return s + i;
+ return (char *)(s + i);
}
-static char *rltrim(char *s)
+/**
+ * Remove all leading and trailing space characters
+ * from the string.
+ * @return pointer to the first non space character.
+ * @note String is modified in place
+ */
+static char *strtrim(char *s)
{
size_t i;
/* check for empty strings */
@@ -151,22 +177,79 @@
return s + i;
}
-static char *rltrim_p(char *s)
+/**
+ * Like strtrim but it allows ':' and '=' as single left space characters.
+ * After the first ':' or '=' character is found the function stops
+ * on first non space character.
+ */
+static char *strtrim_p(char *s)
{
size_t i;
+ int c = 0;
/* check for empty strings */
- if (!(i = strlen(s)))
+ if (!s || !(i = strlen(s)))
return s;
for (i = i - 1; i >= 0 && acr_isspace(s[i]); i--)
;
s[i + 1] = '\0';
+ /* Beside spaces use ':' and '=' as blanks
+ * but only once
+ */
for (i = 0; s[i] != '\0' &&
- (acr_isspace(s[i]) || s[i] == ':' || s[i] == '='); i++)
+ (acr_isspace(s[i]) || ((s[i] == ':' || s[i] == '=') && c++ == 0)); i++)
;
return s + i;
}
+/**
+ * Just like strpbrk but it doesn't break if the char
+ * is escaped by backslash
+ */
+static char *strpbrk_q(const char *s1, const char *s2)
+{
+ const char *scanp;
+ int c, sc, pc = *s1;
+
+ /* Some early sanity check */
+ if (!s1 || !*s1)
+ return NULL;
+ while ((c = *s1++) != 0) {
+ for (scanp = s2; (sc = *scanp++) != 0;) {
+ if (sc == c && pc != '\\')
+ return (char *)(s1 - 1);
+ }
+ /* Don't update the previous marker if it was '\\' already
+ * In that case we have escaped backslash.
+ */
+ if (pc == '\\' && c == '\\')
+ pc = 0;
+ else
+ pc = c;
+ }
+ return NULL;
+}
+
+static char *strunesc(char *s)
+{
+ char *saved = s;
+ int c;
+
+ /* Some early sanity check */
+ if (!s || !*s)
+ return s;
+ while ((c = *s++) != 0) {
+ if (c == '\\') {
+ char *sd = s - 1;
+ char *ss = s;
+ while (*sd) {
+ *(sd++) = *(ss++);
+ }
+ }
+ }
+ return saved;
+}
+
static char *expand_envars(char *s)
{
/* TODO: Implement ${ENV} expansion.
@@ -205,7 +288,7 @@
while (fgets(buffer, ACR_PBUFF_SIZ, fp)) {
char *section;
char *line;
- /* Trim readed line */
+ /* Always right trim the readed line */
counter++;
line = rtrim(buffer);
if (!started) {
@@ -243,7 +326,7 @@
goto cleanup;
}
*ends = '\0';
- section = rltrim(line);
+ section = strtrim(line);
if (!(ini = ini_section_get(top, section))) {
ini = ini_section_new(top);
ini->name = ACR_StrdupA(_E, THROW_NMARK, section);
@@ -257,7 +340,7 @@
equ++;
if ((equ = strchr(equ, '='))) {
*equ++ = '\0';
- val = rltrim(equ);
+ val = strtrim(equ);
if (val[strlen(val) - 1] == '\\') {
val[strlen(val) - 1] = '\0';
nextline = 1;
@@ -265,7 +348,7 @@
if (!*val)
val = NULL;
}
- line = rltrim(line);
+ line = strtrim(line);
if (!*line) {
/* Skip entries without keys **/
nextline = 0;
@@ -288,7 +371,10 @@
return NULL;
}
-ACR_DECLARE(ini_section_t *) ACR_IniLoadProps(JNIEnv *_E, const char *fname)
+ACR_DECLARE(ini_section_t *) ACR_IniLoadPropertiesTree(JNIEnv *_E,
+ const char *fname,
+ int separator,
+ int allowdups)
{
FILE *fp;
ini_section_t *top = NULL;
@@ -297,17 +383,24 @@
char buffer[ACR_PBUFF_SIZ];
int counter = 0;
int nextline = 0;
+ char seps[5] = { '.', ' ', '=', ':', '\0'};
+ size_t slen;
if (!(fp = fopen(fname, STD_FOPEN_RDFLAGS))) {
ACR_THROW_IO_ERRNO();
return NULL;
}
+ if (separator > 0)
+ seps[0] = separator;
ini = top = ini_section_new(NULL);
while (fgets(buffer, ACR_PBUFF_SIZ, fp)) {
char *section;
char *line;
char *ssep;
- /* Trim readed line */
+ char *equ;
+ char *key;
+ char *val = NULL;
+ /* Always right trim the readed line */
counter++;
line = rtrim(buffer);
if (nextline) {
@@ -318,8 +411,9 @@
if (!node || *line == '\0')
continue;
node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, line);
- if (node->val[strlen(node->val) - 1] == '\\') {
- node->val[strlen(node->val) - 1] = '\0';
+ slen = strlen(node->val);
+ if (node->val[slen - 1] == '\\') {
+ node->val[slen - 1] = '\0';
nextline = 1;
}
if (!nextline) {
@@ -331,31 +425,27 @@
/* Skip comments and empty lines */
if (*line == '\0' || *line == '#' || *line == '!')
continue;
- /* TODO: Use strpbrk that understands quoted char's
- */
- ssep = strpbrk(line, ". :=");
- if (ssep && *ssep == '.') {
- char *val = NULL;
- char *equ;
+ ssep = strpbrk_q(line, seps);
+ if (ssep && *ssep == seps[0]) {
char *sub;
*(ssep++) = '\0';
/* Get root subsection */
- section = line;
+ section = strunesc(line);
if (!(ini = ini_section_get(top, section))) {
ini = ini_section_new(top);
ini->name = ACR_StrdupA(_E, THROW_NMARK, section);
}
- while ((sub = strpbrk(ssep, ". :="))) {
+ while ((sub = strpbrk_q(ssep, seps))) {
ini_section_t *sec = ini;
/* Check for '=' char */
- if (*sub != '.') {
+ if (*sub != seps[0]) {
/* We have found a '.' after '='
* The dot is part of value. bail out
*/
break;
}
*(sub++) = '\0';
- section = ssep;
+ section = strunesc(ssep);
if (!(ini = ini_section_get(sec, section))) {
ini = ini_child_new(sec);
ini->name = ACR_StrdupA(_E, THROW_NMARK, section);
@@ -364,52 +454,294 @@
}
if (*ssep == '=' || *ssep == ':')
ssep++;
- if ((equ = strpbrk(ssep, " =:"))) {
+ if ((equ = strpbrk_q(ssep, " :="))) {
*equ++ = '\0';
- val = rltrim_p(equ);
- if (val[strlen(val) - 1] == '\\') {
- val[strlen(val) - 1] = '\0';
+ val = strtrim_p(equ);
+ slen = strlen(val);
+ if (slen && val[slen - 1] == '\\') {
+ val[slen - 1] = '\0';
+ nextline = 1;
+ }
+ if (!*val)
+ val = NULL;
+ }
+ key = strunesc(strtrim(ssep));
+ if (!*key) {
+ /* Skip entries without keys **/
+ nextline = 0;
+ continue;
+ }
+ if (allowdups) {
+ node = ini_node_new(ini);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
+ node->val = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ else {
+ if (!(node = ini_node_get(ini, key))) {
+ node = ini_node_new(ini);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
+ }
+ if (val && *val) {
+ if (node->val) {
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, ", ");
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, val);
+ }
+ else
+ node->val = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ }
+ if (node->val && !nextline) {
+ node->val = expand_envars(node->val);
+ }
+ }
+ else {
+ if ((equ = strpbrk_q(line, " :="))) {
+ *equ++ = '\0';
+ val = strtrim_p(equ);
+ slen = strlen(val);
+ if (slen && val[slen - 1] == '\\') {
+ val[slen - 1] = '\0';
nextline = 1;
}
if (!*val)
val = NULL;
}
- ssep = rltrim(ssep);
- if (!*ssep) {
+ key = strunesc(strtrim(line));
+ if (!*key) {
/* Skip entries without keys **/
nextline = 0;
continue;
}
+ if (allowdups) {
+ node = ini_node_new(top);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
+ node->val = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ else {
+ if (!(node = ini_node_get(top, key))) {
+ node = ini_node_new(top);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
+ }
+ if (val && *val) {
+ if (node->val) {
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, ", ");
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, val);
+ }
+ else
+ node->val = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ }
+ if (node->val && !nextline) {
+ node->val = expand_envars(node->val);
+ }
+ }
+ }
+ fclose(fp);
+ return top;
+
+}
+
+ACR_DECLARE(ini_section_t *) ACR_IniLoadProperties(JNIEnv *_E,
+ const char *fname,
+ int allowdups)
+{
+ FILE *fp;
+ ini_section_t *ini = NULL;
+ ini_node_t *node = NULL;
+ char buffer[ACR_PBUFF_SIZ];
+ int counter = 0;
+ int nextline = 0;
+ size_t slen;
+
+ if (!(fp = fopen(fname, STD_FOPEN_RDFLAGS))) {
+ ACR_THROW_IO_ERRNO();
+ return NULL;
+ }
+ ini = ini_section_new(NULL);
+ while (fgets(buffer, ACR_PBUFF_SIZ, fp)) {
+ char *val = NULL;
+ char *key;
+ char *equ;
+ char *line;
+ /* Always right trim the readed line */
+ counter++;
+ line = rtrim(buffer);
+ if (nextline) {
+ nextline = 0;
+ /* Java props are left trimmed
+ */
+ line = ltrim(line);
+ if (!node || *line == '\0')
+ continue;
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, line);
+ slen = strlen(node->val);
+ if (node->val[slen - 1] == '\\') {
+ node->val[slen - 1] = '\0';
+ nextline = 1;
+ }
+ if (!nextline) {
+ node->val = expand_envars(node->val);
+ }
+ continue;
+ }
+ line = ltrim(buffer);
+ /* Skip comments and empty lines */
+ if (*line == '\0' || *line == '#' || *line == '!')
+ continue;
+ if ((equ = strpbrk_q(line, " :="))) {
+ *equ++ = '\0';
+ val = strtrim_p(equ);
+ slen = strlen(val);
+ if (slen && val[slen - 1] == '\\') {
+ val[slen - 1] = '\0';
+ nextline = 1;
+ }
+ if (!*val)
+ val = NULL;
+ }
+ line = strtrim(line);
+ if (!*line) {
+ /* Skip entries without keys **/
+ nextline = 0;
+ continue;
+ }
+ key = strunesc(line);
+ if (allowdups) {
node = ini_node_new(ini);
- node->key = ACR_StrdupA(_E, THROW_NMARK, ssep);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
node->val = ACR_StrdupA(_E, THROW_NMARK, val);
- if (node->val && !nextline) {
+ }
+ else {
+ if (!(node = ini_node_get(ini, key))) {
+ node = ini_node_new(ini);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
+ }
+ x_free(node->val);
+ node->val = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ if (node->val && !nextline) {
+ node->val = expand_envars(node->val);
+ }
+ }
+ fclose(fp);
+ return ini;
+}
+
+ACR_DECLARE(ini_section_t *) ACR_IniLoadConf(JNIEnv *_E, const char *fname)
+{
+ FILE *fp;
+ ini_section_t *top = NULL;
+ ini_section_t *ini = NULL;
+ ini_node_t *node = NULL;
+ char buffer[ACR_PBUFF_SIZ];
+ int counter = 0;
+ int nextline = 0;
+ size_t slen;
+
+ if (!(fp = fopen(fname, STD_FOPEN_RDFLAGS))) {
+ ACR_THROW_IO_ERRNO();
+ return NULL;
+ }
+ ini = top = ini_section_new(NULL);
+ while (fgets(buffer, ACR_PBUFF_SIZ, fp)) {
+ char *section;
+ char *line;
+ char *key;
+ char *val = NULL;
+ char *equ;
+ /* Trim readed line */
+ counter++;
+ line = rtrim(buffer);
+ if (nextline) {
+ nextline = 0;
+ /* Java props are left trimmed
+ */
+ line = ltrim(line);
+ if (!node || *line == '\0')
+ continue;
+ node->val = ACR_StrcatA(_E, THROW_NMARK, node->val, line);
+ slen = strlen(node->val);
+ if (node->val[slen - 1] == '\\') {
+ node->val[slen - 1] = '\0';
+ nextline = 1;
+ }
+ if (!nextline) {
node->val = expand_envars(node->val);
}
+ continue;
+ }
+ line = ltrim(buffer);
+ /* Skip comments and empty lines */
+ if (*line == '\0' || *line == '#' || *line == ';')
+ continue;
+ if (*line == '<' && *(line + 1) == '/') {
+ /* Terminate section
+ */
+ char *ends = strpbrk_q(line + 2, ">");
+ if (!ends) {
+ sprintf(buffer, "Unterminated section at line %d", counter);
+ ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EINVAL, buffer);
+ goto cleanup;
+ }
+ *ends = '\0';
+ section = strunesc(strtrim(line + 2));
+ if (!ini->name || strcasecmp(section, ini->name)) {
+ sprintf(buffer, "Found </%s> while expecting </%s> at line %d",
+ section, ini->name ? ini->name : "(null)",
+ counter);
+ ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EINVAL, buffer);
+ goto cleanup;
+ }
+ ini = ini->parent;
+ if (!ini)
+ ini = top;
+ }
+ else if (*line == '<') {
+ /* New section
+ */
+ ini_section_t *sec;
+ char *ends = strpbrk_q(++line, ">");
+ if (!ends) {
+ sprintf(buffer, "Unterminated section at line %d", counter);
+ ACR_ThrowExceptionA(_E, THROW_NMARK, ACR_EX_EINVAL, buffer);
+ goto cleanup;
+ }
+ *ends = '\0';
+ section = strtrim(line);
+ if ((equ = strpbrk_q(section, " ="))) {
+ *equ++ = '\0';
+ val = strtrim_p(equ);
+ if (!*val)
+ val = NULL;
+ }
+ section = strunesc(section);
+ if (!(sec = ini_section_get(ini, section))) {
+ sec = ini_child_new(ini);
+ sec->name = ACR_StrdupA(_E, THROW_NMARK, section);
+ sec->attr = ACR_StrdupA(_E, THROW_NMARK, val);
+ }
+ ini = sec;
}
else {
- char *val = NULL;
- char *equ;
- if (*line == '=' || *line == ':')
- line++;
- if ((equ = strpbrk(line, " =:"))) {
+ if ((equ = strpbrk_q(line, " ="))) {
*equ++ = '\0';
- val = rltrim_p(equ);
- if (val[strlen(val) - 1] == '\\') {
- val[strlen(val) - 1] = '\0';
+ val = strtrim_p(equ);
+ slen = strlen(val);
+ if (slen && val[slen - 1] == '\\') {
+ val[slen - 1] = '\0';
nextline = 1;
}
if (!*val)
val = NULL;
}
- line = rltrim(line);
- if (!*line) {
+ key = strunesc(strtrim(line));
+ if (!*key) {
/* Skip entries without keys **/
nextline = 0;
continue;
}
- node = ini_node_new(top);
- node->key = ACR_StrdupA(_E, THROW_NMARK, line);
+ node = ini_node_new(ini);
+ node->key = ACR_StrdupA(_E, THROW_NMARK, key);
node->val = ACR_StrdupA(_E, THROW_NMARK, val);
if (node->val && !nextline) {
node->val = expand_envars(node->val);
@@ -419,5 +751,9 @@
fclose(fp);
return top;
+cleanup:
+ fclose(fp);
+ ini_section_free(top);
+ return NULL;
}
Added: commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java?rev=806951&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java (added)
+++ commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java Sun Aug 23 11:08:15 2009
@@ -0,0 +1,50 @@
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+
+/**
+ * Print properties contained in .MF file.
+ */
+public class PrintManifest
+{
+
+ private PrintManifest()
+ {
+ // No instance
+ }
+
+ public static void main(String args[])
+ {
+ if (args.length < 1) {
+ System.err.println("Usage: PrintProperies <file.properties>");
+ System.exit(1);
+ }
+ try {
+ FileInputStream file = new FileInputStream(args[0]);
+ Manifest mf = new Manifest(file);
+
+ System.out.println("Main Attributes:");
+ Attributes attributes = mf.getMainAttributes();
+ for (Object a : attributes.keySet()) {
+ Attributes.Name n = (Attributes.Name)a;
+ System.out.println(n + " -> " + attributes.get(n));
+ }
+
+ System.out.println();
+ System.out.println("Entries:");
+ Map <String,Attributes> entries = mf.getEntries();
+ for (String e : entries.keySet()) {
+ System.out.println("Entry : " + e);
+ attributes = entries.get(e);
+ for (Object a : attributes.keySet()) {
+ Attributes.Name n = (Attributes.Name)a;
+ System.out.println(n + " -> " + attributes.get(n));
+ }
+ }
+ }
+ catch (Throwable ex) {
+ ex.printStackTrace();
+ }
+ }
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/test/PrintManifest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java?rev=806951&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java (added)
+++ commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java Sun Aug 23 11:08:15 2009
@@ -0,0 +1,53 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Print properties contained in file.
+ */
+public class PrintProperties
+{
+
+ private PrintProperties()
+ {
+ // No instance
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length < 1) {
+ System.err.println("Usage: PrintProperies <file.properties>");
+ System.exit(1);
+ }
+ try {
+ FileInputStream file = new FileInputStream(args[0]);
+ Properties props = new Properties();
+ props.load(file);
+ TreeSet ts = new TreeSet(props.keySet());
+ for (Iterator<String> i = ts.iterator(); i.hasNext();) {
+ String n = (String)i.next();
+ System.out.println(n + " -> " + props.get(n));
+ }
+
+ }
+ catch (Throwable ex) {
+ ex.printStackTrace();
+ }
+ }
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/test/PrintProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java?rev=806951&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java (added)
+++ commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java Sun Aug 23 11:08:15 2009
@@ -0,0 +1,42 @@
+import java.io.*;
+import java.util.*;
+
+/**
+ * Print all system properties
+ */
+public class PrintSystemProperties
+{
+
+ private PrintSystemProperties()
+ {
+ // No Instance
+ }
+
+ public static void main(String args[])
+ {
+ System.out.println("Program arguments: ");
+ for (int i = 0; i < args.length; i ++) {
+ System.out.println("argv[" + i + "] -> " + args[i]);
+ }
+ System.out.println();
+ System.out.println("Program environment: ");
+
+ Map em = System.getenv();
+ TreeSet es = new TreeSet(em.keySet());
+ for (Iterator<String> i = es.iterator(); i.hasNext();) {
+ String n = (String)i.next();
+ System.out.println(n + " -> " + em.get(n));
+ }
+
+ System.out.println();
+ System.out.println("System properties: ");
+ Properties ps = System.getProperties();
+ TreeSet ts = new TreeSet(ps.keySet());
+ for (Iterator<String> i = ts.iterator(); i.hasNext();) {
+ String n = (String)i.next();
+ System.out.println(n + " -> " + ps.get(n));
+ }
+ System.out.println();
+ }
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/test/PrintSystemProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/test/sample.conf
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/sample.conf?rev=806951&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/sample.conf (added)
+++ commons/sandbox/runtime/trunk/src/main/native/test/sample.conf Sun Aug 23 11:08:15 2009
@@ -0,0 +1,44 @@
+# Apache Httpd style configuration
+; Comments can be eith # or ;
+#
+
+Some value
+Second = value
+<Section>
+ some section value
+
+ </ sEcTIon >
+
+<ANother Section with attributes >
+
+</another>
+<root>
+ <level1.1>
+ XML1 = based like data
+ </level1.1>
+ <level1.2>
+ XML1 = based like data
+ <level2.1>
+ XML2 = based like data
+ <level3.1>
+ XML3 = based like data \
+ that goes over multiple lines
+ </level3.1>
+ </level2.1>
+ </level1.2>
+
+</root>
+
+Root value
+
+<\\section\ with\\\ quoted\ spaces\\>
+ note not very much \
+usable, but it's possible.
+</ \\section\ with\\\ quoted\ spaces\\ >
+
+<and\>is\ possible as quoted char>
+ also not very much usable, but somone might find it's purpose
+</and\>is\ possible>
+
+The End
+
Modified: commons/sandbox/runtime/trunk/src/main/native/test/sample.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/sample.properties?rev=806951&r1=806950&r2=806951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/sample.properties (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/sample.properties Sun Aug 23 11:08:15 2009
@@ -2,7 +2,8 @@
! It behaves like java properties
foo=level0
-section.name =:level1
+section.name = : level1
+section.name2 : =level1
section.subsection.name = level2a
section.subsection.name
section.subsection.name is:level2b
@@ -29,6 +30,7 @@
.missing section has empty name (different then NULL)
key\ with\ quoted\ chars\=: value
+section\ with\ quoted\=chars\..name=value
some wired sequences
=a
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=806951&r1=806950&r2=806951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Sun Aug 23 11:08:15 2009
@@ -278,7 +278,8 @@
{
while (ini) {
ini_node_t *node = ini->nodes;
- fprintf(stdout, "%*sSection [%s]\n", level, "", ini->name);
+ fprintf(stdout, "%*sSection [%s]%s\n", level, "", ini->name,
+ ini->attr ? ini->attr : "");
while (node) {
fprintf(stdout, "%*s%s -> %s\n", level + 2, "", node->key, node->val);
node = node->next;
@@ -295,10 +296,39 @@
{
ini_section_t *ini;
ini_section_t *top;
+ int allowdups = 0;
+
+ if (argv[0][0] == '+') {
+ allowdups = 1;
+ --argc;
+ ++argv;
+ }
+ if (argc < 1)
+ return 1;
+ ini = ACR_IniLoadProperties(NULL, argv[0], allowdups);
+ fprintf(stdout, "Using Property `%s\'\n", argv[0]);
+ top = ini;
+ dump_ini_section(ini, 0);
+ ACR_IniTableFree(top);
+
+ return 0;
+}
+
+static int test_ptree(int argc, const char *const argv[])
+{
+ ini_section_t *ini;
+ ini_section_t *top;
+ int allowdups = 0;
+
+ if (argv[0][0] == '+') {
+ allowdups = 1;
+ --argc;
+ ++argv;
+ }
if (argc < 1)
return 1;
- ini = ACR_IniLoadProps(NULL, argv[0]);
+ ini = ACR_IniLoadPropertiesTree(NULL, argv[0], '.', allowdups);
fprintf(stdout, "Using Property `%s\'\n", argv[0]);
top = ini;
dump_ini_section(ini, 0);
@@ -307,6 +337,22 @@
return 0;
}
+static int test_conf(int argc, const char *const argv[])
+{
+ ini_section_t *ini;
+ ini_section_t *top;
+ if (argc < 1)
+ return 1;
+
+ ini = ACR_IniLoadConf(NULL, argv[0]);
+ fprintf(stdout, "Using Conf `%s\'\n", argv[0]);
+ top = ini;
+ dump_ini_section(ini, 0);
+ ACR_IniTableFree(top);
+
+ return 0;
+}
+
int main(int argc, const char *const argv[])
{
int rv = 0;
@@ -372,6 +418,12 @@
else if (!strcasecmp(run_test, "props")) {
rv = test_props(argc, argv);
}
+ else if (!strcasecmp(run_test, "ptree")) {
+ rv = test_ptree(argc, argv);
+ }
+ else if (!strcasecmp(run_test, "conf")) {
+ rv = test_conf(argc, argv);
+ }
}
cleanup: