Compare commits

..

No commits in common. "master" and "CPP_0-0-3" have entirely different histories.

26 changed files with 180 additions and 1031 deletions

View File

@ -1,27 +0,0 @@
name: DeforaOS C CI (ubuntu-latest)
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: bootstrap libSystem
run: git clone https://github.com/DeforaOS/libSystem.git libSystem && for dir in include data src; do (cd libSystem/$dir && make PREFIX="$HOME/opt/DeforaOS" install); done
- name: bootstrap configure
run: git clone https://github.com/DeforaOS/configure.git configure && (cd configure/src && PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make PREFIX="$HOME/opt/DeforaOS" install)
- name: configure
run: $HOME/opt/DeforaOS/bin/configure -p "$HOME/opt/DeforaOS"
- name: make
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make CCSHARED="cc -shared"
- name: make tests
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make CCSHARED="cc -shared" tests
- name: make distcheck
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make CCSHARED="cc -shared" distcheck

1
.gitignore vendored
View File

@ -5,6 +5,5 @@ Makefile
*.so
*.so.*
*.so.*.*
/config.ent
/config.h
/config.sh

View File

@ -1,44 +0,0 @@
DeforaOS CPP
============
About CPP
---------
CPP is a macro preprocessor for the C programming language. It provides the
ability for the inclusion of header files, macro expansions, conditional
compilation, and line control.
CPP depends on the DeforaOS libSystem library (version 0.4.3 or above),
which is found on the website for the DeforaOS Project:
<https://www.defora.org/>.
Compiling CPP
-------------
CPP depends on the following components:
* DeforaOS libSystem
* An implementation of `make`
* GTK-Doc for the API documentation
With GCC, this should then be enough to compile and install CPP:
$ make install
To install CPP in a dedicated directory, like `/path/to/CPP`:
$ make PREFIX="/path/to/CPP" install
Distributing CPP
----------------
DeforaOS CPP is subject to the terms of the GNU LGPL license (version 3).
Please see the `COPYING` file for more information.
Known issues
------------
* The cpp(1) binary may conflict with the system's own version.
* Macro expansions are not fully supported yet.

View File

@ -1,6 +1,6 @@
#!/bin/sh
#$Id$
#Copyright (c) 2011-2022 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2011-2015 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
@ -25,116 +25,19 @@
#variables
CONFIGSH="${0%/pkgconfig.sh}/../config.sh"
PREFIX="/usr/local"
[ -f "../config.sh" ] && . "../config.sh"
DEBUG="_debug"
DEVNULL="/dev/null"
PROGNAME="pkgconfig.sh"
#executables
DEBUG="_debug"
INSTALL="install"
INSTALL="install -m 0644"
MKDIR="mkdir -m 0755 -p"
RM="rm -f"
SED="sed"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions
#pkgconfig
_pkgconfig()
{
#check the variables
if [ -z "$PACKAGE" ]; then
_error "The PACKAGE variable needs to be set"
return $?
fi
if [ -z "$VERSION" ]; then
_error "The VERSION variable needs to be set"
return $?
fi
[ -z "$BINDIR" ] && BINDIR="$PREFIX/bin"
[ -z "$DATADIR" ] && DATADIR="$PREFIX/share"
[ -z "$INCLUDEDIR" ] && INCLUDEDIR="$PREFIX/include"
[ -z "$LIBDIR" ] && LIBDIR="$PREFIX/lib"
[ -z "$LIBEXECDIR" ] && LIBEXECDIR="$PREFIX/libexec"
[ -z "$MANDIR" ] && MANDIR="$DATADIR/man"
[ -z "$SBINDIR" ] && SBINDIR="$PREFIX/sbin"
if [ -z "$SYSCONFDIR" ]; then
SYSCONFDIR="$PREFIX/etc"
[ "$PREFIX" = "/usr" ] && SYSCONFDIR="/etc"
fi
PKGCONFIG="$PREFIX/lib/pkgconfig"
while [ $# -gt 0 ]; do
target="$1"
shift
#clean
[ "$clean" -ne 0 ] && continue
#uninstall
if [ "$uninstall" -eq 1 ]; then
$DEBUG $RM -- "$PKGCONFIG/$target" || return 2
continue
fi
#install
if [ "$install" -eq 1 ]; then
source="${target#$OBJDIR}"
$DEBUG $MKDIR -- "$PKGCONFIG" || return 2
mode="-m 0644"
basename="$source"
if [ "${source##*/}" != "$source" ]; then
basename="${source##*/}"
fi
$DEBUG $INSTALL $mode "$target" "$PKGCONFIG/$basename" \
|| return 2
continue
fi
#portability
RPATH=
if [ "$PREFIX" != "/usr" ]; then
RPATH="-Wl,-rpath-link,\${libdir} -Wl,-rpath,\${libdir}"
case $(uname -s) in
"Darwin")
RPATH="-Wl,-rpath,\${libdir}"
;;
"SunOS")
RPATH="-Wl,-R\${libdir}"
;;
esac
fi
#create
source="${target#$OBJDIR}"
source="${source}.in"
([ -z "$OBJDIR" ] || $DEBUG $MKDIR -- "${target%/*}") \
|| return 2
$DEBUG $SED -e "s;@VENDOR@;$VENDOR;g" \
-e "s;@PACKAGE@;$PACKAGE;g" \
-e "s;@VERSION@;$VERSION;g" \
-e "s;@PREFIX@;$PREFIX;g" \
-e "s;@BINDIR@;$BINDIR;g" \
-e "s;@DATADIR@;$DATADIR;g" \
-e "s;@INCLUDEDIR@;$INCLUDEDIR;g" \
-e "s;@LIBDIR@;$LIBDIR;g" \
-e "s;@LIBEXECDIR@;$LIBEXECDIR;g" \
-e "s;@MANDIR@;$MANDIR;g" \
-e "s;@PWD@;$PWD;g" \
-e "s;@RPATH@;$RPATH;g" \
-e "s;@SBINDIR@;$SBINDIR;g" \
-e "s;@SYSCONFDIR@;$SYSCONFDIR;g" \
-- "$source" > "$target"
if [ $? -ne 0 ]; then
$RM -- "$target" 2> "$DEVNULL"
return 2
fi
done
return 0
}
#debug
_debug()
{
@ -163,7 +66,7 @@ _usage()
clean=0
install=0
uninstall=0
while getopts "ciuO:P:" name; do
while getopts "ciuP:" name; do
case $name in
c)
clean=1
@ -176,9 +79,6 @@ while getopts "ciuO:P:" name; do
install=0
uninstall=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
PREFIX="$OPTARG"
;;
@ -189,10 +89,72 @@ while getopts "ciuO:P:" name; do
esac
done
shift $(($OPTIND - 1))
if [ $# -lt 1 ]; then
if [ $# -eq 0 ]; then
_usage
exit $?
fi
#check the variables
if [ -z "$PACKAGE" ]; then
_error "The PACKAGE variable needs to be set"
exit $?
fi
if [ -z "$VERSION" ]; then
_error "The VERSION variable needs to be set"
exit $?
fi
PKGCONFIG="$PREFIX/lib/pkgconfig"
exec 3>&1
_pkgconfig "$@"
while [ $# -gt 0 ]; do
target="$1"
shift
#clean
[ "$clean" -ne 0 ] && continue
#uninstall
if [ "$uninstall" -eq 1 ]; then
$DEBUG $RM -- "$PKGCONFIG/$target" || exit 2
continue
fi
#install
if [ "$install" -eq 1 ]; then
source="${target#$OBJDIR}"
$DEBUG $MKDIR -- "$PKGCONFIG" || exit 2
basename="$source"
if [ "${source##*/}" != "$source" ]; then
basename="${source##*/}"
fi
$DEBUG $INSTALL "$target" "$PKGCONFIG/$basename"|| exit 2
continue
fi
#portability
RPATH=
if [ "$PREFIX" != "/usr" ]; then
RPATH="-Wl,-rpath-link,\${libdir} -Wl,-rpath,\${libdir}"
case $(uname -s) in
Darwin)
RPATH="-Wl,-rpath,\${libdir}"
;;
SunOS)
RPATH="-Wl,-R\${libdir}"
;;
esac
fi
#create
source="${target#$OBJDIR}"
source="${source}.in"
$DEBUG $SED -e "s;@PACKAGE@;$PACKAGE;" \
-e "s;@VERSION@;$VERSION;" \
-e "s;@PREFIX@;$PREFIX;" \
-e "s;@RPATH@;$RPATH;" \
-- "$source" > "$target"
if [ $? -ne 0 ]; then
$DEBUG $RM -- "$target"
exit 2
fi
done

5
doc/.gitignore vendored
View File

@ -1,5 +0,0 @@
/gtkdoc/html
/gtkdoc/html.stamp
/gtkdoc/CPP.types
/gtkdoc/tmpl.stamp
/gtkdoc/xml.stamp

View File

@ -1,6 +1,6 @@
#!/bin/sh
#$Id$
#Copyright (c) 2012-2020 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2012-2015 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
@ -25,7 +25,6 @@
#variables
CONFIGSH="${0%/gtkdoc.sh}/../config.sh"
PREFIX="/usr/local"
PROGNAME="gtkdoc.sh"
#executables
@ -39,10 +38,9 @@ GTKDOC_SCAN="gtkdoc-scan"
INSTALL="install -m 0644"
MKDIR="mkdir -m 0755 -p"
RM="rm -f"
RMDIR="rmdir"
TOUCH="touch"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
[ -f "../config.sh" ] && . "../config.sh"
#functions
@ -62,77 +60,6 @@ _error()
}
#gtkdoc_fixxref
_gtkdoc_fixxref()
{
module="$1"
moduledir="$2"
htmldir="$3"
outputdir="$4"
(cd "$outputdir" &&
$DEBUG $GTKDOC_FIXXREF \
--module="$module" \
--module-dir="$moduledir" \
--html-dir="$htmldir") || exit 2
}
#gtkdoc_mkdb
_gtkdoc_mkdb()
{
module="$1"
sourcedir="$2"
outputdir="$3"
(cd "$sourcedir" &&
$DEBUG $GTKDOC_MKDB --module="$module" \
--output-dir="$outputdir" \
--output-format="xml" --tmpl-dir="tmpl")
}
#gtkdoc_mkhtml
_gtkdoc_mkhtml()
{
module="$1"
path="$2"
driver="$3"
outputdir="$4"
(cd "$outputdir" &&
$DEBUG $GTKDOC_MKHTML --path "$path" "$module" "$driver")
}
#gtkdoc_mktmpl
_gtkdoc_mktmpl()
{
module="$1"
sourcedir="$2"
outputdir="$3"
(cd "$sourcedir" &&
$DEBUG $GTKDOC_MKTMPL --module="$module" \
--output-dir="$outputdir")
}
#gtkdoc_scan
_gtkdoc_scan()
{
module="$1"
sourcedir="$2"
outputdir="$3"
(cd ".." &&
$DEBUG $GTKDOC_SCAN --module="$module" \
--source-dir="$sourcedir" \
--output-dir="$outputdir")
# --rebuild-types
}
#usage
_usage()
{
@ -145,7 +72,7 @@ _usage()
clean=0
install=0
uninstall=0
while getopts "ciO:uP:" name; do
while getopts "ciuP:" name; do
case "$name" in
c)
clean=1
@ -154,9 +81,6 @@ while getopts "ciO:uP:" name; do
uninstall=0
install=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
u)
install=0
uninstall=1
@ -171,7 +95,7 @@ while getopts "ciO:uP:" name; do
esac
done
shift $((OPTIND - 1))
if [ $# -lt 1 ]; then
if [ $# -eq 0 ]; then
_usage
exit $?
fi
@ -202,28 +126,23 @@ while [ $# -gt 0 ]; do
file="${i##*/}"
$DEBUG $RM -- "$instdir/$MODULE/$file" || exit 2
done
if [ -d "$instdir/$MODULE" ]; then
$DEBUG $RMDIR -- "$instdir/$MODULE" || exit 2
fi
continue
fi
#create
case "$target" in
gtkdoc/html.stamp)
driver="../$MODULE-docs.xml"
if [ -n "$OBJDIR" ]; then
driver="gtkdoc/$MODULE-docs.xml"
$DEBUG $CP -- "$driver" "${OBJDIR}gtkdoc" \
|| exit 2
fi
output="${OBJDIR}gtkdoc/html"
$DEBUG $MKDIR -- "$output" || exit 2
driver="$MODULE-docs.xml"
oldpath="$PWD"
[ -n "$OBJDIR" ] && for file in \
"gtkdoc/$driver" \
"gtkdoc/xml/gtkdocentities.ent"; do
[ -f "$file" ] || continue
$DEBUG $CP -- "$file" \
"${OBJDIR}$file" || exit 2
done
_gtkdoc_mkhtml "$MODULE" "${oldpath%/*}" "../$driver" \
"$output"
(cd "$output" &&
$DEBUG $GTKDOC_MKHTML "$MODULE" \
"${OBJDIR}$driver")
#detect when gtk-doc is not available
res=$?
if [ $res -eq 127 ]; then
@ -234,7 +153,24 @@ while [ $# -gt 0 ]; do
exit 2
fi
output="${OBJDIR}gtkdoc"
_gtkdoc_fixxref "$MODULE" "html" "$instdir" "$output"
(cd "$output" &&
$DEBUG $GTKDOC_FIXXREF \
--module="$MODULE" \
--module-dir="html" \
--html-dir="$instdir") || exit 2
;;
gtkdoc/sgml.stamp)
output="xml"
if [ -n "$OBJDIR" ]; then
output="${OBJDIR}gtkdoc/xml"
$DEBUG $MKDIR -- "$output" || exit 2
fi
(cd "${OBJDIR}gtkdoc" &&
$DEBUG $GTKDOC_MKDB \
--module="$MODULE" \
--output-dir="$output" \
--output-format="xml" \
--tmpl-dir="tmpl")
;;
gtkdoc/tmpl.stamp)
output="tmpl"
@ -242,28 +178,22 @@ while [ $# -gt 0 ]; do
output="${OBJDIR}gtkdoc/tmpl"
$DEBUG $MKDIR -- "$output" || exit 2
fi
_gtkdoc_mktmpl "$MODULE" "${OBJDIR}gtkdoc" "$output"
;;
gtkdoc/xml.stamp)
output="xml"
if [ -n "$OBJDIR" ]; then
output="${OBJDIR}gtkdoc"
sections="gtkdoc/$MODULE-sections.txt"
$DEBUG $MKDIR -- "$output/xml" || exit 2
$DEBUG $CP -- "$sections" "$output" \
|| exit 2
_gtkdoc_scan "$MODULE" "include" "$output"
output="${OBJDIR}gtkdoc/xml"
fi
_gtkdoc_mkdb "$MODULE" "${OBJDIR}gtkdoc" "$output"
(cd "${OBJDIR}gtkdoc" &&
$DEBUG $GTKDOC_MKTMPL \
--module="$MODULE" \
--output-dir="$output")
;;
gtkdoc/*.types)
output="$PWD/gtkdoc" || exit 2
output="doc/gtkdoc" || exit 2
if [ -n "$OBJDIR" ]; then
output="${OBJDIR}gtkdoc"
$DEBUG $MKDIR -- "$output" || exit 2
fi
_gtkdoc_scan "$MODULE" "include" "$output"
(cd ".." &&
$DEBUG $GTKDOC_SCAN \
--module="$MODULE" \
--source-dir="include" \
--output-dir="$output")
;;
*)
_error "$target: Unknown type"
@ -275,7 +205,7 @@ while [ $# -gt 0 ]; do
_error "$target: Could not create documentation"
install=0
fi
$TOUCH "${OBJDIR}$target"
$TOUCH "$target"
#install
if [ "$install" -eq 1 ]; then

View File

@ -3,32 +3,25 @@
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
%gtkdocentities;
<!ENTITY % configentities SYSTEM "config.ent">
%configentities;
<!ENTITY server "www.defora.org/doc/gtk-doc/html">
<!ENTITY title "DeforaOS CPP">
<!ENTITY version "0.0.1">
]>
<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
<book id="index">
<bookinfo>
<title>&vendor; &package; &title;</title>
<title>CPP Reference Manual</title>
<releaseinfo>
for &vendor; &package; &version;.
for CPP &version;.
The latest version of this documentation can be found on-line at
<ulink role="online-location" url="https://&server;/&package;/">https://&server;/&package;/</ulink>.
<ulink role="online-location" url="http://&server;/CPP/index.html">http://&server;/CPP/</ulink>.
</releaseinfo>
</bookinfo>
<chapter>
<title>&vendor; &package;</title>
<title>&title;</title>
<xi:include href="xml/CPP.xml"/>
</chapter>
<!-- enable this when you use gobject types
<chapter id="object-tree">
<title>Object Hierarchy</title>
<xi:include href="xml/tree_index.sgml"/>
</chapter>
-->
<index id="api-index-full">
<title>API Index</title>
<xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
@ -37,7 +30,6 @@
<title>Index of deprecated API</title>
<xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
</index>
<!-- enable this when you use gobject introspection annotations
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
-->
</book>

View File

@ -1,21 +0,0 @@
<SECTION>
<FILE>CPP</FILE>
CPP_CODE_COUNT
CPP_CODE_LAST
CPP_CODE_META_FIRST
CPP_CODE_META_LAST
Cpp
CppCode
CppFilter
CppOption
cpp_define_add
cpp_define_get
cpp_define_remove
cpp_delete
cpp_get_filename
cpp_new
cpp_new_string
cpp_path_add
cpp_scan
</SECTION>

View File

@ -1,2 +1,2 @@
subdirs=tmpl
dist=Makefile,CPP-docs.xml,CPP-sections.txt,xml/gtkdocentities.ent
dist=Makefile,CPP-docs.xml

View File

@ -1,2 +0,0 @@
<!ENTITY server "www.defora.org/doc/gtk-doc/html">
<!ENTITY title "Reference Manual">

View File

@ -1,25 +1,23 @@
subdirs=gtkdoc
targets=gtkdoc/CPP.types,gtkdoc/html.stamp,gtkdoc/tmpl.stamp,gtkdoc/xml.stamp
targets=gtkdoc/CPP.types,gtkdoc/tmpl.stamp,gtkdoc/sgml.stamp,gtkdoc/html.stamp
dist=Makefile,gtkdoc.sh
#targets
[gtkdoc/CPP.types]
type=script
script=./gtkdoc.sh
depends=gtkdoc.sh
[gtkdoc/html.stamp]
type=script
script=./gtkdoc.sh
depends=gtkdoc/CPP-docs.xml,$(OBJDIR)gtkdoc/xml.stamp,gtkdoc/xml/gtkdocentities.ent,gtkdoc.sh,../config.ent,../config.sh
install=
[gtkdoc/tmpl.stamp]
type=script
script=./gtkdoc.sh
depends=$(OBJDIR)gtkdoc/CPP.types,gtkdoc.sh,../config.sh
depends=$(OBJDIR)gtkdoc/CPP.types,gtkdoc/tmpl/cpp.sgml
[gtkdoc/xml.stamp]
[gtkdoc/sgml.stamp]
type=script
script=./gtkdoc.sh
depends=$(OBJDIR)gtkdoc/tmpl.stamp,gtkdoc.sh
depends=$(OBJDIR)gtkdoc/tmpl.stamp
[gtkdoc/html.stamp]
type=script
script=./gtkdoc.sh
depends=gtkdoc/CPP-docs.xml,$(OBJDIR)gtkdoc/sgml.stamp
install=

View File

@ -1,30 +1,6 @@
package=CPP
version=0.0.6
vendor=Devel
config=ent,h,sh
version=0.0.3
config=h,sh
subdirs=data,doc,include,src,tests
targets=tests
dist=Makefile,COPYING,README.md,config.ent,config.h,config.sh
#modes
[mode::debug]
title=Debug
[mode::release]
title=Release
#targets
[tests]
type=command
command=cd tests && (if [ -n "$(OBJDIR)" ]; then $(MAKE) OBJDIR="$(OBJDIR)tests/" "$(OBJDIR)tests/clint.log" "$(OBJDIR)tests/distcheck.log" "$(OBJDIR)tests/fixme.log"; else $(MAKE) clint.log distcheck.log fixme.log; fi)
depends=all
enabled=0
phony=1
#dist
[COPYING]
install=$(PREFIX)/share/doc/$(PACKAGE)
[README.md]
install=$(PREFIX)/share/doc/$(PACKAGE)
dist=Makefile,COPYING,config.h,config.sh

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2006-2022 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2006-2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel cpp */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -75,7 +75,7 @@ Cpp * cpp_new(CppPrefs * prefs)
/* cpp_new_string */
Cpp * cpp_new_string(CppPrefs * prefs, char const * string)
{
/* FIXME really implement */
/* FIXME really implement (and refactor) */
Cpp * cpp;
String * p;
int r = 0;

View File

@ -1,31 +0,0 @@
targets=libcpp
cppflags_force=-I../../include
cppflags=
cflags_force=`pkg-config --cflags libSystem` -fPIC
cflags=-W -Wall -g -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
ldflags_force=`pkg-config --libs libSystem`
ldflags=
dist=Makefile,common.h,parser.h
#modes
[mode::debug]
[mode::release]
cppflags_force=-I../../include -DNDEBUG
cflags=-W -Wall -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
#targets
[libcpp]
type=library
sources=cpp.c,parser.c,scanner.c
install=$(LIBDIR)
#sources
[cpp.c]
depends=common.h,../../include/CPP.h
[parser.c]
depends=parser.h,../../include/CPP.h
[scanner.c]
depends=common.h,../../include/CPP.h

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2007-2022 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2007-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel cpp */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,10 +24,6 @@
#include <errno.h>
#include "CPP.h"
#ifndef PROGNAME_CPP
# define PROGNAME_CPP "cpp"
#endif
/* cpp */
/* private */
@ -66,13 +62,13 @@ static int _cpp(Prefs * prefs, int filec, char * filev[])
if(prefs->outfile == NULL)
fp = stdout;
else if((fp = fopen(prefs->outfile, "w")) == NULL)
return error_set_print(PROGNAME_CPP, 1, "%s: %s",
prefs->outfile, strerror(errno));
return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
strerror(errno));
for(i = 0; i < filec; i++)
ret |= _cpp_do(prefs, fp, filev[i]);
if(fclose(fp) != 0)
return error_set_print(PROGNAME_CPP, 1, "%s: %s",
prefs->outfile, strerror(errno));
return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
strerror(errno));
return ret;
}
@ -147,7 +143,7 @@ static void _do_print_token(FILE * fp, Token * token)
/* cpp_error */
static int _cpp_error(void)
{
return error_print(PROGNAME_CPP);
return error_print("cpp");
}
@ -155,7 +151,7 @@ static int _cpp_error(void)
/* FIXME -E prints metadata? */
static int _usage(void)
{
fputs("Usage: " PROGNAME_CPP " [-D name[=value]]...[-I directory][-o file][-t][-U name]... input...\n"
fputs("Usage: cpp [-D name[=value]]...[-I directory][-o file][-t][-U name]... input...\n"
" -D Add a substitution\n"
" -I Add a directory to the search path\n"
" -o Write output to a file\n"
@ -222,7 +218,7 @@ static int _main_add_define(Prefs * prefs, char * define)
value = strtok(define, "=");
if((p = realloc(prefs->defines, sizeof(*p) * (prefs->defines_cnt + 1)))
== NULL)
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
return error_set_print("cpp", 1, "%s", strerror(errno));
prefs->defines = p;
prefs->defines[prefs->defines_cnt++] = define;
return 0;
@ -234,7 +230,7 @@ static int _main_add_path(Prefs * prefs, char const * path)
if((p = realloc(prefs->paths, sizeof(*p) * (prefs->paths_cnt + 1)))
== NULL)
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
return error_set_print("cpp", 1, "%s", strerror(errno));
prefs->paths = p;
prefs->paths[prefs->paths_cnt++] = path;
return 0;
@ -248,7 +244,7 @@ static int _main_add_undefine(Prefs * prefs, char const * undefine)
return 1;
if((p = realloc(prefs->undefines, sizeof(*p)
* (prefs->undefines_cnt + 1))) == NULL)
return error_set_print(PROGNAME_CPP, 1, "%s", strerror(errno));
return error_set_print("cpp", 1, "%s", strerror(errno));
prefs->undefines = p;
prefs->undefines[prefs->undefines_cnt++] = undefine;
return 0;

View File

@ -850,7 +850,6 @@ static int _cpp_callback_unknown(Parser * parser, Token * token, int c,
CppParser * cppparser_new(Cpp * cpp, CppParser * parent, char const * filename,
int filters)
{
/* FIXME factor code */
CppParser * cp;
if((cp = object_new(sizeof(*cp))) == NULL)
@ -906,6 +905,7 @@ CppParser * cppparser_new(Cpp * cpp, CppParser * parent, char const * filename,
CppParser * cppparser_new_string(Cpp * cpp, CppParser * parent,
char const * string, int filters)
{
/* FIXME refactor */
CppParser * cp;
if((cp = object_new(sizeof(*cp))) == NULL)

View File

@ -1,30 +1,34 @@
subdirs=lib
targets=cpp
targets=libcpp,cpp
cppflags_force=-I ../include
cppflags=
cflags_force=`pkg-config --cflags libSystem` -fPIE
cflags=-W -Wall -g -O2 -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector
cflags_force=`pkg-config --cflags libSystem`
cflags=-W -Wall -g -O2 -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector-all
ldflags_force=`pkg-config --libs libSystem`
ldflags=-pie -Wl,-z,relro -Wl,-z,now
dist=Makefile
ldflags=
dist=Makefile,common.h,parser.h
#modes
[mode::debug]
[libcpp]
type=library
sources=cpp.c,parser.c,scanner.c
cflags=-fPIC
install=$(LIBDIR)
[mode::release]
cppflags_force=-I ../include -DNDEBUG
cflags=-W -Wall -O2 -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector
[cpp.c]
depends=common.h,../include/CPP.h
[parser.c]
depends=parser.h,../include/CPP.h
[scanner.c]
depends=common.h,../include/CPP.h
#targets
[cpp]
type=binary
sources=main.c
#XXX should really use this (race condition with "make -k")
depends=$(OBJDIR)lib/libcpp$(SOEXT)
depends=$(OBJDIR)lib/libcpp.a
ldflags=-L$(OBJDIR)lib -L$(LIBDIR) -Wl,-rpath,$(LIBDIR) -lcpp
depends=$(OBJDIR)libcpp.so
cflags=-fPIE
ldflags=-L$(OBJDIR). -L$(LIBDIR) -Wl,-rpath,$(LIBDIR) -lcpp
install=$(BINDIR)
#sources
[main.c]
depends=../include/CPP.h

3
tests/.gitignore vendored
View File

@ -1,3 +0,0 @@
/clint.log
/distcheck.log
/fixme.log

View File

@ -1,192 +0,0 @@
#!/bin/sh
#$Id$
#Copyright (c) 2016-2021 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
CONFIGSH="${0%/clint.sh}/../config.sh"
CFLAGS=
CPPFLAGS=
PROGNAME="clint.sh"
PROJECTCONF="../project.conf"
#executables
DATE="date"
DEBUG="_debug"
ECHO="/bin/echo"
FIND="find"
GREP="grep"
LINT="lint -g"
MKDIR="mkdir -p"
SORT="sort -n"
TR="tr"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions
#clint
_clint()
{
res=0
subdirs=
$DATE
while read line; do
case "$line" in
"["*)
break
;;
"subdirs="*)
subdirs=${line#subdirs=}
subdirs=$(echo "$subdirs" | $TR ',' ' ')
;;
esac
done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do
[ -d "../$subdir" ] || continue
while read filename; do
[ -n "$filename" ] || continue
r=0
case "$filename" in
*.c)
echo
_clint_lint "$filename" || r=$?
_clint_rtrim "$filename"|| r=$?
;;
*.h)
echo
echo "$filename:"
_clint_rtrim "$filename"|| r=$?
;;
*)
continue
;;
esac
if [ $r -eq 0 ]; then
echo " OK"
echo "$PROGNAME: $filename: OK" 1>&2
else
echo "FAIL"
echo "$PROGNAME: $filename: FAIL" 1>&2
res=2
fi
done << EOF
$($FIND "../$subdir" -type f | $SORT)
EOF
done
return $res
}
_clint_lint()
{(
filename="$1"
$ECHO -n "${filename%/*}/"
$DEBUG $LINT $CPPFLAGS $CFLAGS "$filename" 2>&1
ret=$?
if [ $ret -eq 127 ]; then
#XXX ignore errors when $LINT is not available
ret=0
fi
return $ret
)}
_clint_rtrim()
{
filename="$1"
regex="[ ]\\+\$"
$DEBUG $GREP -vq "$regex" "$filename" 2>&1
}
#debug
_debug()
{
echo "$@" 1>&3
"$@"
}
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-c] target..." 1>&2
return 1
}
#main
clean=0
while getopts "cO:P:" name; do
case "$name" in
c)
clean=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
CPPFLAGS="$CPPFLAGS -I$OPTARG/include"
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -lt 1 ]; then
_usage
exit $?
fi
#clean
[ $clean -ne 0 ] && exit 0
exec 3>&1
ret=0
while [ $# -gt 0 ]; do
target="$1"
dirname="${target%/*}"
shift
if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_clint > "$target" || ret=$?
done
exit $ret

View File

@ -1,6 +1,6 @@
#!/bin/sh
#$Id$
#Copyright (c) 2013-2022 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2013-2014 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
@ -27,7 +27,8 @@
#variables
PROGNAME="cpp.sh"
#executables
CPP="$OBJDIR../src/cpp"
CPP="../src/cpp"
[ -n "$OBJDIR" ] && CPP="${OBJDIR}../src/cpp"
#functions
@ -63,14 +64,14 @@ fi
if [ $# -eq 1 -a -n "$output" ]; then
target="$1"
LD_LIBRARY_PATH="$OBJDIR../src/lib" $CPP "$target" > "$output"
LD_LIBRARY_PATH="../src" $CPP "$target" > "$output"
elif [ $# -ge 1 -a -z "$output" ]; then
while [ $# -gt 0 ]; do
target="$1"
output="${target%.cpp}.o"
shift
LD_LIBRARY_PATH="$OBJDIR../src/lib" $CPP "$target" > "$output"
LD_LIBRARY_PATH="../src" $CPP "$target" > "$output"
done
else
_usage

View File

@ -1,102 +0,0 @@
#!/bin/sh
#$Id$
#Copyright (c) 2020 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
CONFIGSH="${0%/distcheck.sh}/../config.sh"
CFLAGS=
LDFLAGS=
PROGNAME="distcheck.sh"
TARGET="tests.log"
#executables
DATE="date"
[ -n "$MAKE" ] || MAKE="make"
MKDIR="mkdir -p"
MKTEMP="mktemp"
RM="rm -f"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#distcheck
_distcheck()
{
(cd .. && $MAKE distcheck)
}
#date
_date()
{
if [ -n "$SOURCE_DATE_EPOCH" ]; then
TZ=UTC $DATE -d "@$SOURCE_DATE_EPOCH" '+%a %b %d %T %Z %Y'
else
$DATE
fi
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-c] target..." 1>&2
return 1
}
#main
clean=0
while getopts "cO:P:" name; do
case "$name" in
c)
clean=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
#XXX ignored
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then
_usage
exit $?
fi
while [ $# -ne 0 ]; do
target="$1"
shift
[ "$clean" -eq 0 ] || break
(_date; echo; _distcheck) > "$target" || exit 2
done
exit 0

View File

@ -1,261 +0,0 @@
#!/bin/sh
#$Id$
#Copyright (c) 2017-2022 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
CONFIGSH="${0%/fixme.sh}/../config.sh"
PROGNAME="fixme.sh"
PROJECTCONF="../project.conf"
REGEXP_ERROR="FIXME"
REGEXP_WARNING="\\(TODO\|XXX\\)"
#executables
DATE="date"
DEBUG="_debug"
FIND="find"
GREP="grep"
HEAD="head"
MKDIR="mkdir -p"
SORT="sort -n"
TR="tr"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions
#fixme
_fixme()
{
res=0
subdirs=
$DATE
echo
while read line; do
case "$line" in
"["*)
break
;;
"subdirs="*)
subdirs=${line#subdirs=}
subdirs=$(echo "$subdirs" | $TR ',' ' ')
;;
esac
done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do
[ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f | $SORT); do
callback=$(_fixme_callback "$filename")
[ -n "$callback" ] || continue
($callback "$filename") 2>&1
if [ $? -ne 0 ]; then
echo "$PROGNAME: $filename: FAIL" 1>&2
res=2
fi
done
done
return $res
}
_fixme_callback()
{
filename="$1"
ext=${filename##*/}
ext=${ext%.in}
ext=${ext##*.}
callback=
case "$ext" in
asm|S)
echo "_fixme_callback_asm"
return 0
;;
c|cc|cpp|cxx|go|h|js|v)
echo "_fixme_callback_c"
return 0
;;
conf|sh)
echo "_fixme_callback_sh"
return 0
;;
py)
echo "_fixme_callback_python"
return 0
;;
htm|html|xml|xsl)
echo "_fixme_callback_xml"
return 0
;;
esac
case $($HEAD -n 1 "$filename") in
"#!/bin/sh"*|"#! /bin/sh"*|\
"#!/usr/bin/env bash"*|"#! /usr/bin/env bash"*)
echo "_fixme_callback_sh"
return 0
;;
"#!/usr/bin/env python"*|"#! /usr/bin/env python"*)
echo "_fixme_callback_python"
return 0
;;
"<!DOCTYPE"*|"<!doctype"*|"<HTML"*|"<html"*|"<?xml"*)
echo "_fixme_callback_xml"
return 0
;;
esac
return 2
}
_fixme_callback_asm()
{
res=0
filename="$1"
#warnings
$GREP -nH "/\\*.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "/\\*.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_callback_c()
{
res=0
filename="$1"
#warnings
$GREP -nH "/\\(/\\|\\*\\).*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "/\\(/\\|\\*\\).*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_callback_python()
{
res=0
filename="$1"
comment="#"
#warnings
$GREP -nH "$comment.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "$comment.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_callback_sh()
{
res=0
filename="$1"
comment="#"
#warnings
$GREP -nH "$comment.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "$comment.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_callback_xml()
{
res=0
filename="$1"
#XXX limited to a single line
#warnings
$GREP -nH "<!--.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "<!--.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
#debug
_debug()
{
echo "$@" 1>&3
"$@"
}
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-c] target..." 1>&2
return 1
}
#main
clean=0
while getopts "cO:P:" name; do
case "$name" in
c)
clean=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
#XXX ignored for compatibility
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -lt 1 ]; then
_usage
exit $?
fi
#clean
[ $clean -ne 0 ] && exit 0
exec 3>&1
ret=0
while [ $# -gt 0 ]; do
target="$1"
dirname="${target%/*}"
shift
if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_fixme > "$target" || ret=$?
done
exit $ret

View File

@ -1,49 +1,28 @@
targets=clint.log,define.o,distcheck.log,fixme.log,if.o,include.o
targets=define.o,if.o,include.o
cxx=./cpp.sh
cxxflags=
dist=Makefile,clint.sh,cpp.sh,distcheck.sh,fixme.sh,include-define.cpp
#targets
[clint.log]
type=script
script=./clint.sh
flags=-O CPPFLAGS="-I../include"
depends=clint.sh
enabled=0
dist=Makefile,cpp.sh,include-define.cpp
[define.o]
type=object
sources=define.cpp
depends=../src/cpp
[distcheck.log]
type=script
script=./distcheck.sh
depends=distcheck.sh
enabled=0
[fixme.log]
type=script
script=./fixme.sh
depends=fixme.sh
enabled=0
[define.cpp]
depends=cpp.sh
[if.o]
type=object
sources=if.cpp
depends=../src/cpp
[if.cpp]
depends=cpp.sh
[include.o]
type=object
sources=include.cpp
depends=../src/cpp
#sources
[define.cpp]
depends=cpp.sh
[if.cpp]
depends=cpp.sh
[include.cpp]
depends=cpp.sh