scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 750c66982ba283716d843cf986373ddba4d89633
parent 186c076403b545365d3c8b1a9bfd8fa9d24fcac5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Aug 2017 17:39:37 +0100

[lib] Change libcc to libscc

After moving all the libraries together it was a bit confusing to have
a c and cc libraries. Naming cc as scc removes any confusion.

Diffstat:
Mcc1/Makefile | 6+++---
Mcc1/builtin.c | 2+-
Mcc1/code.c | 2+-
Mcc1/cpp.c | 2+-
Mcc1/decl.c | 2+-
Mcc1/error.c | 2+-
Mcc1/expr.c | 2+-
Mcc1/fold.c | 2+-
Mcc1/gendep.sh | 4++--
Mcc1/init.c | 2+-
Mcc1/lex.c | 2+-
Mcc1/main.c | 2+-
Mcc1/stmt.c | 2+-
Mcc1/symbol.c | 2+-
Mcc1/target/amd64-sysv/arch.c | 2+-
Mcc1/target/i386-sysv/arch.c | 2+-
Mcc1/target/z80-scc/arch.c | 2+-
Mcc1/types.c | 2+-
Mcc2/Makefile | 6+++---
Mcc2/code.c | 2+-
Mcc2/gendep.sh | 4++--
Mcc2/main.c | 2+-
Mcc2/node.c | 2+-
Mcc2/optm.c | 2+-
Mcc2/parser.c | 2+-
Mcc2/peep.c | 2+-
Mcc2/symbol.c | 2+-
Mcc2/target/amd64-sysv/cgen.c | 2+-
Mcc2/target/amd64-sysv/code.c | 2+-
Mcc2/target/amd64-sysv/optm.c | 2+-
Mcc2/target/amd64-sysv/types.c | 2+-
Mcc2/target/i386-sysv/cgen.c | 2+-
Mcc2/target/i386-sysv/code.c | 2+-
Mcc2/target/i386-sysv/optm.c | 2+-
Mcc2/target/i386-sysv/types.c | 2+-
Mcc2/target/qbe_amd64-sysv/cgen.c | 2+-
Mcc2/target/qbe_amd64-sysv/code.c | 2+-
Mcc2/target/qbe_amd64-sysv/optm.c | 2+-
Mcc2/target/qbe_amd64-sysv/types.c | 2+-
Mcc2/target/z80-scc/cgen.c | 2+-
Mcc2/target/z80-scc/code.c | 2+-
Mcc2/target/z80-scc/optm.c | 2+-
Mcc2/target/z80-scc/types.c | 2+-
Mdriver/posix/Makefile | 6+++---
Mdriver/posix/scc.c | 2+-
Rinc/cc.h -> inc/scc.h | 0
Mlib/Makefile | 2+-
Dlib/cc/Makefile | 19-------------------
Dlib/cc/debug.c | 21---------------------
Dlib/cc/die.c | 21---------------------
Dlib/cc/newitem.c | 12------------
Dlib/cc/xcalloc.c | 14--------------
Dlib/cc/xmalloc.c | 14--------------
Dlib/cc/xrealloc.c | 14--------------
Dlib/cc/xstrdup.c | 13-------------
Alib/scc/Makefile | 19+++++++++++++++++++
Alib/scc/debug.c | 21+++++++++++++++++++++
Alib/scc/die.c | 21+++++++++++++++++++++
Rlib/cc/libdep.mk -> lib/scc/libdep.mk | 0
Alib/scc/newitem.c | 12++++++++++++
Alib/scc/xcalloc.c | 14++++++++++++++
Alib/scc/xmalloc.c | 14++++++++++++++
Alib/scc/xrealloc.c | 14++++++++++++++
Alib/scc/xstrdup.c | 13+++++++++++++
64 files changed, 182 insertions(+), 182 deletions(-)

diff --git a/cc1/Makefile b/cc1/Makefile @@ -4,7 +4,7 @@ # Makefile is only used as a template for makefile. # If you modify Makefile remember to run make dep -LIBDIR = ../lib/cc +LIBDIR = ../lib/scc include ../config.mk include $(LIBDIR)/libdep.mk @@ -13,7 +13,7 @@ MOREFLAGS = -I../inc/$(STD) OBJ = types.o decl.o lex.o error.o symbol.o main.o expr.o \ code.o stmt.o cpp.o fold.o init.o builtin.o -HDR = cc1.h ../inc/cc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h +HDR = cc1.h ../inc/scc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h all: mkdir -p ../rootdir/libexec/scc/ @@ -21,7 +21,7 @@ all: cpp.o: stallman.msg -$(LIBDIR)/libcc.a: +$(LIBDIR)/libscc.a: cd $(LIBDIR) && $(MAKE) dep: diff --git a/cc1/builtin.c b/cc1/builtin.c @@ -3,7 +3,7 @@ static char sccsid[] = "@(#) ./cc1/builtin.c"; #include <stdio.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" static Node * diff --git a/cc1/code.c b/cc1/code.c @@ -5,7 +5,7 @@ static char sccsid[] = "@(#) ./cc1/code.c"; #include <stdlib.h> #include <stdarg.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" static void emitbin(unsigned, void *), diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -8,7 +8,7 @@ static char sccsid[] = "@(#) ./cc1/cpp.c"; #include <time.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" static char *argp, *macroname; diff --git a/cc1/decl.c b/cc1/decl.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc1/decl.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define NOSCLASS 0 diff --git a/cc1/error.c b/cc1/error.c @@ -4,7 +4,7 @@ static char sccsid[] = "@(#) ./cc1/error.c"; #include <stdio.h> #include <stdlib.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define MAXERRNUM 10 diff --git a/cc1/expr.c b/cc1/expr.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc1/expr.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define XCHG(lp, rp, np) (np = lp, lp = rp, rp = np) diff --git a/cc1/fold.c b/cc1/fold.c @@ -4,7 +4,7 @@ static char sccsid[] = "@(#) ./cc1/fold.c"; #include <stdio.h> #include <stdlib.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" diff --git a/cc1/gendep.sh b/cc1/gendep.sh @@ -19,8 +19,8 @@ do all: cc1-$i OBJ-$i= \$(OBJ) target/$i/arch.o \$(OBJ-$i): \$(HDR) -cc1-$i: \$(OBJ-$i) \$(LIBDIR)/libcc.a - \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$i) -lcc -o \$@ +cc1-$i: \$(OBJ-$i) \$(LIBDIR)/libscc.a + \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$i) -lscc -o \$@ EOF echo diff --git a/cc1/init.c b/cc1/init.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc1/init.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" diff --git a/cc1/lex.c b/cc1/lex.c @@ -10,7 +10,7 @@ static char sccsid[] = "@(#) ./cc1/lex.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" unsigned yytoken; diff --git a/cc1/main.c b/cc1/main.c @@ -7,7 +7,7 @@ static char sccsid[] = "@(#) ./cc1/main.c"; #include <errno.h> #include "../inc/arg.h" -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" char *argv0, *infile; diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -5,7 +5,7 @@ static char sccsid[] = "@(#) ./cc1/stmt.c"; #include <stdio.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define NEGATE 1 diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -7,7 +7,7 @@ static char sccsid[] = "@(#) ./cc1/symbol.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define NR_SYM_HASH 64 diff --git a/cc1/target/amd64-sysv/arch.c b/cc1/target/amd64-sysv/arch.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc1/arch/amd64-sysv/arch.c"; #include <stdio.h> -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc1.h" #define RANK_BOOL 0 diff --git a/cc1/target/i386-sysv/arch.c b/cc1/target/i386-sysv/arch.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc1/arch/i386-sysv/arch.c"; #include <stdio.h> -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc1.h" #define RANK_BOOL 0 diff --git a/cc1/target/z80-scc/arch.c b/cc1/target/z80-scc/arch.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc1/arch/z80/arch.c"; #include <stdio.h> -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc1.h" #define RANK_BOOL 0 diff --git a/cc1/types.c b/cc1/types.c @@ -7,7 +7,7 @@ static char sccsid[] = "@(#) ./cc1/types.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc1.h" #define NR_TYPE_HASH 16 diff --git a/cc2/Makefile b/cc2/Makefile @@ -4,14 +4,14 @@ # Makefile is only used as a template for makefile. # If you modify Makefile remember to run make dep -LIBDIR = ../lib/cc +LIBDIR = ../lib/scc include ../config.mk include $(LIBDIR)/libdep.mk MOREFLAGS = -I../inc/$(STD) OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o -HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/cc.h +HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/scc.h all: mkdir -p ../rootdir/libexec/scc/ @@ -20,7 +20,7 @@ all: dep: MKQBE=${MKQBE} ./gendep.sh $(TARGETS) -$(LIBDIR)/libcc.a: +$(LIBDIR)/libscc.a: cd $(LIBDIR) && $(MAKE) main.o: error.h diff --git a/cc2/code.c b/cc2/code.c @@ -3,7 +3,7 @@ static char sccsid[] = "@(#) ./cc2/code.c"; #include <stdlib.h> #include <string.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" Inst *pc, *prog; diff --git a/cc2/gendep.sh b/cc2/gendep.sh @@ -7,8 +7,8 @@ gentarget() include target/$1/target.mk \$(OBJ-$1): \$(HDR) all: cc2-$1 -cc2-$1: \$(OBJ-$1) \$(LIBDIR)/libcc.a - \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$1) -lcc -o \$@ +cc2-$1: \$(OBJ-$1) \$(LIBDIR)/libscc.a + \$(CC) \$(SCC_LDFLAGS) \$(OBJ-$1) -lscc -o \$@ EOF } diff --git a/cc2/main.c b/cc2/main.c @@ -4,7 +4,7 @@ static char sccsid[] = "@(#) ./cc2/main.c"; #include <stdio.h> #include <stdlib.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" #include "error.h" diff --git a/cc2/node.c b/cc2/node.c @@ -3,7 +3,7 @@ static char sccsid[] = "@(#) ./cc2/node.c"; #include <stdlib.h> #include <string.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" diff --git a/cc2/optm.c b/cc2/optm.c @@ -1,5 +1,5 @@ -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" Node * diff --git a/cc2/parser.c b/cc2/parser.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc2/parser.c"; #include <string.h> #include <cstd.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" diff --git a/cc2/peep.c b/cc2/peep.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/peep.c"; -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" void diff --git a/cc2/symbol.c b/cc2/symbol.c @@ -5,7 +5,7 @@ static char sccsid[] = "@(#) ./cc2/symbol.c"; #include <stdlib.h> #include <string.h> -#include "../inc/cc.h" +#include "../inc/scc.h" #include "cc2.h" diff --git a/cc2/target/amd64-sysv/cgen.c b/cc2/target/amd64-sysv/cgen.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/cgen.c"; #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/amd64-sysv/code.c b/cc2/target/amd64-sysv/code.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/code.c"; #include <cstd.h> #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" enum segment { diff --git a/cc2/target/amd64-sysv/optm.c b/cc2/target/amd64-sysv/optm.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/optm.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/amd64-sysv/types.c b/cc2/target/amd64-sysv/types.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/amd64-sysv/types.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" diff --git a/cc2/target/i386-sysv/cgen.c b/cc2/target/i386-sysv/cgen.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/cgen.c"; #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/i386-sysv/code.c b/cc2/target/i386-sysv/code.c @@ -5,7 +5,7 @@ static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/code.c"; #include <cstd.h> #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" enum segment { diff --git a/cc2/target/i386-sysv/optm.c b/cc2/target/i386-sysv/optm.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/optm.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/i386-sysv/types.c b/cc2/target/i386-sysv/types.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/i386-sysv/types.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" diff --git a/cc2/target/qbe_amd64-sysv/cgen.c b/cc2/target/qbe_amd64-sysv/cgen.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc2/arch/qbe/cgen.c"; #include <cstd.h> #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" enum sflags { diff --git a/cc2/target/qbe_amd64-sysv/code.c b/cc2/target/qbe_amd64-sysv/code.c @@ -7,7 +7,7 @@ static char sccsid[] = "@(#) ./cc2/arch/qbe/code.c"; #include <cstd.h> #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" #define ADDR_LEN (INTIDENTSIZ+64) diff --git a/cc2/target/qbe_amd64-sysv/optm.c b/cc2/target/qbe_amd64-sysv/optm.c @@ -3,7 +3,7 @@ static char sccsid[] = "@(#) ./cc2/arch/qbe/optm.c"; #include <stddef.h> -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/qbe_amd64-sysv/types.c b/cc2/target/qbe_amd64-sysv/types.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/qbe/types.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" diff --git a/cc2/target/z80-scc/cgen.c b/cc2/target/z80-scc/cgen.c @@ -2,7 +2,7 @@ static char sccsid[] = "@(#) ./cc2/arch/z80/cgen.c"; #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/z80-scc/code.c b/cc2/target/z80-scc/code.c @@ -6,7 +6,7 @@ static char sccsid[] = "@(#) ./cc2/arch/z80/code.c"; #include <cstd.h> #include "arch.h" -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" enum segment { diff --git a/cc2/target/z80-scc/optm.c b/cc2/target/z80-scc/optm.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/z80/optm.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" Node * diff --git a/cc2/target/z80-scc/types.c b/cc2/target/z80-scc/types.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc2/arch/z80/types.c"; -#include "../../../inc/cc.h" +#include "../../../inc/scc.h" #include "../../cc2.h" diff --git a/driver/posix/Makefile b/driver/posix/Makefile @@ -1,13 +1,13 @@ # See LICENSE file for copyright and license details. .POSIX: -LIBDIR = ../../lib/cc +LIBDIR = ../../lib/scc include ../../config.mk include $(LIBDIR)/libdep.mk OBJ = scc.o HDR = config.h \ - ../../inc/cc.h \ + ../../inc/scc.h \ ../../inc/arg.h \ ../../inc/syslibs.h \ ../../inc/ldflags.h @@ -22,7 +22,7 @@ dep: $(OBJ): $(HDR) scc: $(OBJ) $(LIBDIR)/libcc.a - $(CC) $(SCC_LDFLAGS) $(OBJ) -lcc -o $@ + $(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@ scpp: cpp.sh config.h set -x ;\ diff --git a/driver/posix/scc.c b/driver/posix/scc.c @@ -16,7 +16,7 @@ static char sccsid[] = "@(#) ./driver/posix/scc.c"; #include "config.h" #include "../../inc/arg.h" -#include "../../inc/cc.h" +#include "../../inc/scc.h" #include "../../inc/syslibs.h" #include "../../inc/ldflags.h" diff --git a/inc/cc.h b/inc/scc.h diff --git a/lib/Makefile b/lib/Makefile @@ -3,7 +3,7 @@ include ../config.mk -DIRS = cc +DIRS = scc all dep clean distclean: @pwd=$$PWD; \ diff --git a/lib/cc/Makefile b/lib/cc/Makefile @@ -1,19 +0,0 @@ -# See LICENSE file for copyright and license details. -.POSIX: - -LIBDIR = ./ -include ../../config.mk -include libdep.mk - -all: libcc.a - -libcc.a: $(LIB-OBJ) - ar $(ARFLAGS) $@ $? - ranlib $@ - -dep: - -clean: - rm -f *.o *.a - -distclean: clean diff --git a/lib/cc/debug.c b/lib/cc/debug.c @@ -1,21 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/debug.c"; -#include <stdarg.h> -#include <stdio.h> - -#include "../../inc/cc.h" - -int debug; - -void -dbg(const char *fmt, ...) -{ - if (!debug) - return; - va_list va; - va_start(va, fmt); - vfprintf(stderr, fmt, va); - putc('\n', stderr); - va_end(va); - return; -} diff --git a/lib/cc/die.c b/lib/cc/die.c @@ -1,21 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/die.c"; -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> - -#include "../../inc/cc.h" - -int failure; - -void -die(const char *fmt, ...) -{ - failure = 1; - va_list va; - va_start(va, fmt); - vfprintf(stderr, fmt, va); - putc('\n', stderr); - va_end(va); - exit(1); -} diff --git a/lib/cc/newitem.c b/lib/cc/newitem.c @@ -1,12 +0,0 @@ -#include "../../inc/cc.h" - -void -newitem(struct items *items, char *item) -{ - if ((items->n + 1) < items->n) - die("newitem: overflow (%u + 1)", items->n); - - items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **)); - items->s[items->n++] = item; -} - diff --git a/lib/cc/xcalloc.c b/lib/cc/xcalloc.c @@ -1,14 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/xcalloc.c"; -#include <stdlib.h> -#include "../../inc/cc.h" - -void * -xcalloc(size_t n, size_t size) -{ - void *p = calloc(n, size); - - if (!p) - die("out of memory"); - return p; -} diff --git a/lib/cc/xmalloc.c b/lib/cc/xmalloc.c @@ -1,14 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/xmalloc.c"; -#include <stdlib.h> -#include "../../inc/cc.h" - -void * -xmalloc(size_t size) -{ - void *p = malloc(size); - - if (!p) - die("out of memory"); - return p; -} diff --git a/lib/cc/xrealloc.c b/lib/cc/xrealloc.c @@ -1,14 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/xrealloc.c"; -#include <stdlib.h> -#include "../../inc/cc.h" - -void * -xrealloc(void *buff, size_t size) -{ - void *p = realloc(buff, size); - - if (!p) - die("out of memory"); - return p; -} diff --git a/lib/cc/xstrdup.c b/lib/cc/xstrdup.c @@ -1,13 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -static char sccsid[] = "@(#) ./lib/xstrdup.c"; -#include <string.h> -#include "../../inc/cc.h" - -char * -xstrdup(const char *s) -{ - size_t len = strlen(s) + 1; - char *p = xmalloc(len); - - return memcpy(p, s, len); -} diff --git a/lib/scc/Makefile b/lib/scc/Makefile @@ -0,0 +1,19 @@ +# See LICENSE file for copyright and license details. +.POSIX: + +LIBDIR = ./ +include ../../config.mk +include libdep.mk + +all: libscc.a + +libscc.a: $(LIB-OBJ) + ar $(ARFLAGS) $@ $? + ranlib $@ + +dep: + +clean: + rm -f *.o *.a + +distclean: clean diff --git a/lib/scc/debug.c b/lib/scc/debug.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/debug.c"; +#include <stdarg.h> +#include <stdio.h> + +#include "../../inc/scc.h" + +int debug; + +void +dbg(const char *fmt, ...) +{ + if (!debug) + return; + va_list va; + va_start(va, fmt); + vfprintf(stderr, fmt, va); + putc('\n', stderr); + va_end(va); + return; +} diff --git a/lib/scc/die.c b/lib/scc/die.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/die.c"; +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> + +#include "../../inc/scc.h" + +int failure; + +void +die(const char *fmt, ...) +{ + failure = 1; + va_list va; + va_start(va, fmt); + vfprintf(stderr, fmt, va); + putc('\n', stderr); + va_end(va); + exit(1); +} diff --git a/lib/cc/libdep.mk b/lib/scc/libdep.mk diff --git a/lib/scc/newitem.c b/lib/scc/newitem.c @@ -0,0 +1,12 @@ +#include "../../inc/scc.h" + +void +newitem(struct items *items, char *item) +{ + if ((items->n + 1) < items->n) + die("newitem: overflow (%u + 1)", items->n); + + items->s = xrealloc(items->s, (items->n + 1) * sizeof(char **)); + items->s[items->n++] = item; +} + diff --git a/lib/scc/xcalloc.c b/lib/scc/xcalloc.c @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/xcalloc.c"; +#include <stdlib.h> +#include "../../inc/scc.h" + +void * +xcalloc(size_t n, size_t size) +{ + void *p = calloc(n, size); + + if (!p) + die("out of memory"); + return p; +} diff --git a/lib/scc/xmalloc.c b/lib/scc/xmalloc.c @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/xmalloc.c"; +#include <stdlib.h> +#include "../../inc/scc.h" + +void * +xmalloc(size_t size) +{ + void *p = malloc(size); + + if (!p) + die("out of memory"); + return p; +} diff --git a/lib/scc/xrealloc.c b/lib/scc/xrealloc.c @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/xrealloc.c"; +#include <stdlib.h> +#include "../../inc/scc.h" + +void * +xrealloc(void *buff, size_t size) +{ + void *p = realloc(buff, size); + + if (!p) + die("out of memory"); + return p; +} diff --git a/lib/scc/xstrdup.c b/lib/scc/xstrdup.c @@ -0,0 +1,13 @@ +/* See LICENSE file for copyright and license details. */ +static char sccsid[] = "@(#) ./lib/xstrdup.c"; +#include <string.h> +#include "../../inc/scc.h" + +char * +xstrdup(const char *s) +{ + size_t len = strlen(s) + 1; + char *p = xmalloc(len); + + return memcpy(p, s, len); +}