[hackers] [scc] [lib][driver] move newitem() + related struct to lib || Quentin Rameau
commit e06d5bda89394fa97fb77af7816129685b27899f
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jun 16 16:17:37 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Jun 17 21:41:10 2016 +0200
[lib][driver] move newitem() + related struct to lib
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 70d5dd0..603b063 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -46,14 +46,9 @@ static struct tool {
[STRIP] = { .bin = "strip", .cmd = "strip", },
};
-struct objects {
- char **f;
- int n;
-};
-
char *argv0;
static char *arch, *outfile;
-static struct objects objtmp, objout;
+static struct items objtmp, objout;
static int Eflag, Sflag, cflag, kflag, sflag;
static void
_AT_@ -75,20 +70,10 @@ terminate(void)
if (!kflag) {
for (i = 0; i < objtmp.n; ++i)
- unlink(objtmp.f[i]);
+ unlink(objtmp.s[i]);
}
}
-static char **
-newitem(char **array, int num, char *item)
-{
- char **ar = xrealloc(array, (num + 1) * sizeof(char **));
-
- ar[num] = item;
-
- return ar;
-}
-
static void
addarg(int tool, char *arg)
{
_AT_@ -212,14 +197,14 @@ settool(int tool, char *infile, int nexttool)
break;
case LD:
for (i = 0; i < objtmp.n; ++i)
- addarg(tool, xstrdup(objtmp.f[i]));
+ addarg(tool, xstrdup(objtmp.s[i]));
for (i = 0; i < objout.n; ++i)
- addarg(tool, xstrdup(objout.f[i]));
+ addarg(tool, xstrdup(objout.s[i]));
break;
case STRIP:
if (cflag || kflag) {
for (i = 0; i < objout.n; ++i)
- addarg(tool, xstrdup(objout.f[i]));
+ addarg(tool, xstrdup(objout.s[i]));
}
if (!cflag && tools[LD].outfile)
addarg(tool, tools[LD].outfile);
_AT_@ -322,7 +307,7 @@ static void
build(char *file)
{
int tool = toolfor(file), nexttool;
- struct objects *objs = (tool == LD || cflag || kflag) ?
+ struct items *objs = (tool == LD || cflag || kflag) ?
&objout : &objtmp;
for (; tool < LAST_TOOL; tool = nexttool) {
_AT_@ -364,7 +349,7 @@ build(char *file)
validatetools();
- objs->f = newitem(objs->f, objs->n++, outfilename(file, "o"));
+ objs->s = newitem(objs->s, objs->n++, outfilename(file, "o"));
}
static void
diff --git a/inc/cc.h b/inc/cc.h
index e801a3f..33f5bca 100644
--- a/inc/cc.h
+++ b/inc/cc.h
_AT_@ -1,4 +1,6 @@
/* See LICENSE file for copyright and license details. */
+#include <sys/types.h>
+
#ifndef NDEBUG
extern int debug;
#define DBG(fmt, ...) dbg(fmt, __VA_ARGS__)
_AT_@ -12,8 +14,14 @@ extern int debug;
#define PREFIX "/usr/local/"
#endif
+struct items {
+ char **s;
+ int n;
+};
+
extern void die(const char *fmt, ...);
extern void dbg(const char *fmt, ...);
+extern char **newitem(char **array, int num, char *item);
extern void *xmalloc(size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern char *xstrdup(const char *s);
diff --git a/lib/Makefile b/lib/Makefile
index 061384a..892c732 100644
--- a/lib/Makefile
+++ b/lib/Makefile
_AT_@ -2,7 +2,7 @@
.POSIX:
include ../config.mk
-OBJS = die.o xcalloc.o xmalloc.o xrealloc.o xstrdup.o debug.o
+OBJS = debug.o die.o newitem.o xcalloc.o xmalloc.o xrealloc.o xstrdup.o
all: libcc.a
diff --git a/lib/newitem.c b/lib/newitem.c
new file mode 100644
index 0000000..97a2560
--- /dev/null
+++ b/lib/newitem.c
_AT_@ -0,0 +1,12 @@
+#include "../inc/cc.h"
+
+char **
+newitem(char **array, int num, char *item)
+{
+ char **ar = xrealloc(array, (num + 1) * sizeof(char **));
+
+ ar[num] = item;
+
+ return ar;
+}
+
Received on Fri Jun 17 2016 - 21:45:13 CEST
This archive was generated by hypermail 2.3.0
: Fri Jun 17 2016 - 21:48:34 CEST