diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | src/argparser.c | 19 | ||||
-rw-r--r-- | src/test.c | 10 |
3 files changed, 19 insertions, 14 deletions
@@ -3,8 +3,8 @@ JAVA_OPTIMISE = -O all: @mkdir -p bin - $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -fPIC -shared src/argparser.c -o bin/argparser.so - $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -c src/argparser.c -o bin/argparser.o + $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -fPIC -c src/argparser.c -o bin/argparser.o + $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -shared bin/argparser.o -o bin/argparser.so $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic src/test.c bin/argparser.o -o bin/test javac $(JAVA_OPTIMISE) -cp src -s src -d bin src/argparser/ArgParser.java javac $(JAVA_OPTIMISE) -cp src -s src -d bin src/Test.java diff --git a/src/argparser.c b/src/argparser.c index 427a4b7..13ab1b7 100644 --- a/src/argparser.c +++ b/src/argparser.c @@ -205,7 +205,7 @@ args_Option args_new_argumentless(int standard, char* alternatives, ...) va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -243,7 +243,7 @@ args_Option args_new_argumented(char* argument, int standard, char* alternatives va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -281,7 +281,7 @@ args_Option args_new_variadic(char* argument, int standard, char* alternatives, va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -693,6 +693,7 @@ char* args_parent_name(long levels) data = (char*)malloc(2048 * sizeof(char)); while (lvl > 0) { + long found = false; i = 0; for (j = 0; *("/proc/" + j); j++) *(buf + i++) = *("/proc/" + j); for (j = 0; *(pid + j); j++) *(buf + i++) = *(pid + j); @@ -726,15 +727,19 @@ char* args_parent_name(long levels) *(pid + i) = *(buf + off + i); *(pid + j) = 0; lvl--; + found = true; break; } j = 0; } - if (j < 35) - *(buf + j) = c; + else if (j < 35) + *(buf + j++) = c; + } + if (found == false) + { + free(data); + return null; } - free(data); - return null; } free(data); i = 0; @@ -43,12 +43,12 @@ int main(int argc, char** argv) "You should have received a copy of the GNU General Public License\n" "along with this library. If not, see <http://www.gnu.org/licenses/>.", 0, 1); - args_add_option(args_new_argumentless(0, "-h", "-?", "--help"), "Prints this help message\n(and exits)"); - args_add_option(args_new_argumentless(0, "--hello"), "Prints the text: hello world'"); - args_add_option(args_new_argumentless(0, "++hidden"), 0); + args_add_option(args_new_argumentless(0, "-h", "-?", "--help", NULL), "Prints this help message\n(and exits)"); + args_add_option(args_new_argumentless(0, "--hello", NULL), "Prints the text: hello world'"); + args_add_option(args_new_argumentless(0, "++hidden", NULL), 0); - args_add_option(args_new_argumented("LINE", 0, "-l", "--line"), "Prints the choosen line"); - args_add_option(args_new_variadic("LINE", 0, "--l", "--lines"), "Prints the choosen lines"); + args_add_option(args_new_argumented("LINE", 0, "-l", "--line", NULL), "Prints the choosen line"); + args_add_option(args_new_variadic("LINE", 0, "--l", "--lines", NULL), "Prints the choosen lines"); args_parse(argc, argv); args_support_alternatives(); |