git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: exon@op5.se (Andreas Ericsson)
To: git@vger.kernel.org
Subject: [PATCH 1/2] Use light stacking for non-option arguments.
Date: Wed, 11 Jan 2006 21:42:36 +0100 (CET)	[thread overview]
Message-ID: <20060111204236.187A95BEC0@nox.op5.se> (raw)

This patch adds some simple library code that can help C-programs
in the git suite ignore argument ordering without interfering
with the current argument parsing code too much.

Signed-off-by: Andreas Ericsson <ae@op5.se>

---

 Makefile |    4 ++--
 stack.c  |   42 ++++++++++++++++++++++++++++++++++++++++++
 stack.h  |    9 +++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 stack.c
 create mode 100644 stack.h

5ebd4cbfef1a2c369f763eb3a98f079ffb4f6b5d
diff --git a/Makefile b/Makefile
index c9c15b5..ba861fb 100644
--- a/Makefile
+++ b/Makefile
@@ -165,7 +165,7 @@ LIB_FILE=libgit.a
 LIB_H = \
 	blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
 	diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \
-	run-command.h strbuf.h tag.h tree.h git-compat-util.h
+	run-command.h stack.h strbuf.h tag.h tree.h git-compat-util.h
 
 DIFF_OBJS = \
 	diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
@@ -176,7 +176,7 @@ LIB_OBJS = \
 	date.o diff-delta.o entry.o ident.o index.o \
 	object.o pack-check.o patch-delta.o path.o pkt-line.o \
 	quote.o read-cache.o refs.o run-command.o \
-	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
+	server-info.o setup.o sha1_file.o sha1_name.o stack.o strbuf.o \
 	tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 	fetch-clone.o \
 	$(DIFF_OBJS)
diff --git a/stack.c b/stack.c
new file mode 100644
index 0000000..e76a197
--- /dev/null
+++ b/stack.c
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <string.h>
+#include "stack.h"
+#include "git-compat-util.h"
+
+struct stack *stack_push(struct stack *s, const void *ptr)
+{
+	if (!s)
+		s = xcalloc(1, sizeof(struct stack));
+
+	if (s) {
+		s->stack = xrealloc(s->stack, sizeof(void *) * s->ents + 1);
+		s->stack[s->ents++] = (void *)ptr;
+	}
+
+	return s;
+}
+
+/* pull is from top, pop from bottom */
+void *stack_pull(struct stack *s)
+{
+	if (s && s->next < s->ents)
+		return s->stack[s->next++];
+
+	return NULL;
+}
+
+void *stack_pop(struct stack *s)
+{
+	if (s && s->ents)
+		return s->stack[--s->ents];
+
+	return NULL;
+}
+
+void stack_destroy(struct stack *s)
+{
+	if (s && s->stack) {
+		free(s->stack);
+		memset(s, 0, sizeof(struct stack));
+	}
+}
diff --git a/stack.h b/stack.h
new file mode 100644
index 0000000..5682559
--- /dev/null
+++ b/stack.h
@@ -0,0 +1,9 @@
+struct stack {
+	void **stack;
+	unsigned ents, next;
+};
+
+struct stack *stack_push(struct stack *s, const void *ptr);
+void *stack_pull(struct stack *s);
+void *stack_pop(struct stack *s);
+void stack_destroy(struct stack *s);
-- 
1.1.0

                 reply	other threads:[~2006-01-11 20:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060111204236.187A95BEC0@nox.op5.se \
    --to=exon@op5.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).