changeset 9:6eed14cccac9

Switched lwar to lw_cmdline and brought in lwlib
author lost@l-w.ca
date Sat, 22 Jan 2011 10:04:32 -0700
parents fdc11ef4115b
children 127e5b1e01c0
files Makefile lwar/lwar.c lwar/main.c lwar/rules.make lwar/util.c lwar/util.h
diffstat 6 files changed, 17 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Jan 22 09:58:24 2011 -0700
+++ b/Makefile	Sat Jan 22 10:04:32 2011 -0700
@@ -38,8 +38,8 @@
 lwlink/lwobjdump: $(lwobjdump_objs) lwlib lwlink/rules.make
 	$(CC) -o $@ $(lwobjdump_objs) $(LDFLAGS)
 
-lwar/lwar: $(lwar_objs) lwar/rules.make
-	$(CC) -o $@ $(lwar_objs)
+lwar/lwar: $(lwar_objs) lwlib lwar/rules.make
+	$(CC) -o $@ $(lwar_objs) $(LDFLAGS)
 
 test: test.c lwlib
 	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ test.c $(LDFLAGS)
--- a/lwar/lwar.c	Sat Jan 22 09:58:24 2011 -0700
+++ b/lwar/lwar.c	Sat Jan 22 10:04:32 2011 -0700
@@ -28,9 +28,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <lw_alloc.h>
+
 #define __lwar_c_seen__
 #include "lwar.h"
-#include "util.h"
 
 typedef struct
 {
--- a/lwar/main.c	Sat Jan 22 09:58:24 2011 -0700
+++ b/lwar/main.c	Sat Jan 22 10:04:32 2011 -0700
@@ -22,7 +22,6 @@
 
 */
 
-#include <argp.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,14 +29,15 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <lw_cmdline.h>
+
 #include "lwar.h"
 
 // command line option handling
-const char *argp_program_version = "LWAR from " PACKAGE_STRING;
-const char *argp_program_bug_address = PACKAGE_BUGREPORT;
+#define PROGVER "lwar from " PACKAGE_STRING
 char *program_name;
 
-static error_t parse_opts(int key, char *arg, struct argp_state *state)
+static int parse_opts(int key, char *arg, void *state)
 {
 	switch (key)
 	{
@@ -75,7 +75,7 @@
 		operation = LWAR_OP_EXTRACT;
 		break;
 
-	case ARGP_KEY_ARG:
+	case lw_cmdline_key_arg:
 		if (archive_file)
 		{
 			// add archive member to list
@@ -86,12 +86,12 @@
 		break;
 		
 	default:
-		return ARGP_ERR_UNKNOWN;
+		return lw_cmdline_err_unknown;
 	}
 	return 0;
 }
 
-static struct argp_option options[] =
+static struct lw_cmdline_options options[] =
 {
 	{ "replace",	'r',	0,		0,
 				"Add or replace archive members" },
@@ -110,12 +110,13 @@
 	{ 0 }
 };
 
-static struct argp argp =
+static struct lw_cmdline_parser argparser =
 {
 	options,
 	parse_opts,
-	"<archive> [<file> ...]",
-	"LWAR, a library file manager for LWLINK"
+	"ARCHIVE [FILE ...]",
+	"lwar, a library file manager for lwlink",
+	PROGVER
 };
 
 extern void do_list(void);
@@ -129,7 +130,7 @@
 int main(int argc, char **argv)
 {
 	program_name = argv[0];
-	argp_parse(&argp, argc, argv, 0, 0, NULL);
+	lw_cmdline_parse(&argparser, argc, argv, 0, 0, NULL);
 	if (archive_file == NULL)
 	{
 		fprintf(stderr, "You must specify an archive file.\n");
--- a/lwar/rules.make	Sat Jan 22 09:58:24 2011 -0700
+++ b/lwar/rules.make	Sat Jan 22 10:04:32 2011 -0700
@@ -1,5 +1,5 @@
 dirname := $(dir $(lastword $(MAKEFILE_LIST)))
 
-lwar_srcs_local := add.c extract.c list.c lwar.c main.c remove.c replace.c util.c
+lwar_srcs_local := add.c extract.c list.c lwar.c main.c remove.c replace.c
 
 lwar_srcs := $(lwar_srcs) $(addprefix $(dirname),$(lwar_srcs_local))
--- a/lwar/util.c	Sat Jan 22 09:58:24 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/*
-util.c
-Copyright © 2009 William Astle
-
-This file is part of LWAR.
-
-LWAR is free software: you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation, either version 3 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-more details.
-
-You should have received a copy of the GNU General Public License along with
-this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/*
-Utility functions
-*/
-
-#define __util_c_seen__
-
-#include <malloc.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "util.h"
-
-void *lw_malloc(int size)
-{
-	void *ptr;
-	
-	ptr = malloc(size);
-	if (!ptr)
-	{
-		// bail out; memory allocation error
-		fprintf(stderr, "lw_malloc(): Memory allocation error\n");
-		exit(1);
-	}
-	return ptr;
-}
-
-void *lw_realloc(void *optr, int size)
-{
-	void *ptr;
-	
-	if (size == 0)
-	{
-		lw_free(optr);
-		return NULL;
-	}
-	
-	ptr = realloc(optr, size);
-	if (!ptr)
-	{
-		fprintf(stderr, "lw_realloc(): memory allocation error\n");
-		exit(1);
-	}
-	return ptr;
-}
-
-void lw_free(void *ptr)
-{
-	if (ptr)
-		free(ptr);
-}
-
-char *lw_strdup(const char *s)
-{
-	char *d;
-	
-	if (!s)
-		return NULL;
-
-	d = strdup(s);
-	if (!d)
-	{
-		fprintf(stderr, "lw_strdup(): memory allocation error\n");
-		exit(1);
-	}
-	
-	return d;
-}
--- a/lwar/util.h	Sat Jan 22 09:58:24 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
-util.h
-Copyright © 2009 William Astle
-
-This file is part of LWAR.
-
-LWAR is free software: you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation, either version 3 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-more details.
-
-You should have received a copy of the GNU General Public License along with
-this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/*
-Utility functions
-*/
-
-#ifndef __util_h_seen__
-#define __util_h_seen__
-
-#ifndef __util_c_seen__
-#define __util_E__ extern
-#else
-#define __util_E__
-#endif
-
-// allocate memory
-__util_E__ void *lw_malloc(int size);
-__util_E__ void lw_free(void *ptr);
-__util_E__ void *lw_realloc(void *optr, int size);
-
-// string stuff
-__util_E__ char *lw_strdup(const char *s);
-
-#undef __util_E__
-
-#endif // __util_h_seen__