Browse Source

lub/argv use single source file

Serj Kalichev 8 years ago
parent
commit
9658706ce5

+ 106 - 1
lub/argv/argv_new.c → lub/argv/argv.c

@@ -1,5 +1,5 @@
 /*
- * argv_new.c
+ * argv.c
  */
 #include "private.h"
 #include "lub/string.h"
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 
 /*--------------------------------------------------------- */
 static void lub_argv_init(lub_argv_t * this, const char *line, size_t offset)
@@ -92,3 +93,107 @@ void lub_argv_delete(lub_argv_t * this)
 }
 
 /*--------------------------------------------------------- */
+char *lub_argv__get_line(const lub_argv_t * this)
+{
+	int space = 0;
+	const char *p;
+	unsigned i;
+	char *line = NULL;
+
+	for (i = 0; i < this->argc; i++) {
+		if (i != 0)
+			lub_string_cat(&line, " ");
+		space = 0;
+		/* Search for spaces */
+		for (p = this->argv[i].arg; *p; p++) {
+			if (isspace(*p)) {
+				space = 1;
+				break;
+			}
+		}
+		if (space)
+			lub_string_cat(&line, "\"");
+		lub_string_cat(&line, this->argv[i].arg);
+		if (space)
+			lub_string_cat(&line, "\"");
+	}
+
+	return line;
+}
+
+/*--------------------------------------------------------- */
+char **lub_argv__get_argv(const lub_argv_t * this, const char *argv0)
+{
+	char **result = NULL;
+	unsigned i;
+	unsigned a = 0;
+
+	if (argv0)
+		a = 1;
+
+	result = malloc(sizeof(char *) * (this->argc + 1 + a));
+
+	if (argv0)
+		result[0] = strdup(argv0);
+	for (i = 0; i < this->argc; i++)
+		result[i + a] = strdup(this->argv[i].arg);
+	result[i + a] = NULL;
+
+	return result;
+}
+
+/*--------------------------------------------------------- */
+void lub_argv__free_argv(char **argv)
+{
+	unsigned i;
+
+	if (!argv)
+		return;
+
+	for (i = 0; argv[i]; i++)
+		free(argv[i]);
+	free(argv);
+}
+
+/*--------------------------------------------------------- */
+const char *lub_argv__get_arg(const lub_argv_t *this, unsigned int index)
+{
+	const char *result = NULL;
+
+	if (!this)
+		return NULL;
+	if (this->argc > index)
+		result = this->argv[index].arg;
+
+	return result;
+}
+
+/*--------------------------------------------------------- */
+unsigned lub_argv__get_count(const lub_argv_t * this)
+{
+	return this->argc;
+}
+
+/*--------------------------------------------------------- */
+size_t lub_argv__get_offset(const lub_argv_t * this, unsigned index)
+{
+	size_t result = 0;
+
+	if (this->argc > index)
+		result = this->argv[index].offset;
+
+	return result;
+}
+
+/*--------------------------------------------------------- */
+bool_t lub_argv__get_quoted(const lub_argv_t * this, unsigned index)
+{
+	bool_t result = BOOL_FALSE;
+
+	if (this->argc > index)
+		result = this->argv[index].quoted;
+
+	return result;
+}
+
+/*--------------------------------------------------------- */

+ 0 - 19
lub/argv/argv__get_arg.c

@@ -1,19 +0,0 @@
-/*
- * argv__get_arg.c
- */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-const char *lub_argv__get_arg(const lub_argv_t *this, unsigned int index)
-{
-	const char *result = NULL;
-
-	if (!this)
-		return NULL;
-	if (this->argc > index)
-		result = this->argv[index].arg;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 75
lub/argv/argv__get_argv.c

@@ -1,75 +0,0 @@
-/*
- * argv__get_argv.c
- */
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "lub/string.h"
-#include "private.h"
-
-/*--------------------------------------------------------- */
-char *lub_argv__get_line(const lub_argv_t * this)
-{
-	int space = 0;
-	const char *p;
-	unsigned i;
-	char *line = NULL;
-
-	for (i = 0; i < this->argc; i++) {
-		if (i != 0)
-			lub_string_cat(&line, " ");
-		space = 0;
-		/* Search for spaces */
-		for (p = this->argv[i].arg; *p; p++) {
-			if (isspace(*p)) {
-				space = 1;
-				break;
-			}
-		}
-		if (space)
-			lub_string_cat(&line, "\"");
-		lub_string_cat(&line, this->argv[i].arg);
-		if (space)
-			lub_string_cat(&line, "\"");
-	}
-
-	return line;
-}
-
-/*--------------------------------------------------------- */
-char **lub_argv__get_argv(const lub_argv_t * this, const char *argv0)
-{
-	char **result = NULL;
-	unsigned i;
-	unsigned a = 0;
-
-	if (argv0)
-		a = 1;
-
-	result = malloc(sizeof(char *) * (this->argc + 1 + a));
-
-	if (argv0)
-		result[0] = strdup(argv0);
-	for (i = 0; i < this->argc; i++)
-		result[i + a] = strdup(this->argv[i].arg);
-	result[i + a] = NULL;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */
-void lub_argv__free_argv(char **argv)
-{
-	unsigned i;
-
-	if (!argv)
-		return;
-
-	for (i = 0; argv[i]; i++)
-		free(argv[i]);
-	free(argv);
-}
-
-/*--------------------------------------------------------- */

+ 0 - 11
lub/argv/argv__get_count.c

@@ -1,11 +0,0 @@
-/*
- * argv__get_count.c
- */
-#include "private.h"
-/*--------------------------------------------------------- */
-unsigned lub_argv__get_count(const lub_argv_t * this)
-{
-	return this->argc;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 17
lub/argv/argv__get_offset.c

@@ -1,17 +0,0 @@
-/*
- * argv__get_offset.c
- */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-size_t lub_argv__get_offset(const lub_argv_t * this, unsigned index)
-{
-	size_t result = 0;
-
-	if (this->argc > index)
-		result = this->argv[index].offset;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 17
lub/argv/argv__get_quoted.c

@@ -1,17 +0,0 @@
-/*
- * argv__get_quoted.c
- */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-bool_t lub_argv__get_quoted(const lub_argv_t * this, unsigned index)
-{
-	bool_t result = BOOL_FALSE;
-
-	if (this->argc > index)
-		result = this->argv[index].quoted;
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 1 - 6
lub/argv/module.am

@@ -1,10 +1,5 @@
 liblub_la_SOURCES += \
-	lub/argv/argv__get_arg.c \
-	lub/argv/argv__get_argv.c \
-	lub/argv/argv__get_count.c \
-	lub/argv/argv__get_offset.c \
-	lub/argv/argv__get_quoted.c \
-	lub/argv/argv_new.c \
+	lub/argv/argv.c \
 	lub/argv/private.h