Skip to content

Commit

Permalink
Update the library source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jleffler committed Jul 27, 2024
1 parent 695d34c commit f454b84
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 142 deletions.
4 changes: 2 additions & 2 deletions etc/soq-head.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ IFLAG1 = -I${INCDIR}
IFLAG2 = #-I${HOME}/inc
IFLAGS = ${IFLAG1} ${IFLAG2}
OFLAGS = -O3
SFLAGS = -std=c11 # -pedantic
SFLAGS = -std=c18 # -pedantic
TFLAGS = # Set to -DTEST (or similar) when needed
UFLAGS = # Set on command line
WFLAG1 = -Wall
Expand All @@ -60,7 +60,7 @@ DXXFLAGS = #-DHAVE_CONFIG_H
GXXFLAGS = -g
IXXFLAGS = ${IFLAGS}
OXXFLAGS = -O3
SXXFLAGS = -std=c++11
SXXFLAGS = -std=c++20
TXXFLAGS = # Set to -DTEST (or similar) when needed
UXXFLAGS = # Set on comand line
WXXFLAG1 = -Wall
Expand Down
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ include etc/soq-head.mk

BASEDIR = .

CC = clang -Wno-nullability-completeness

default:
@echo "You must specify a target to build"

Expand Down
6 changes: 3 additions & 3 deletions src/libsoq/aomcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@(#)File: aomcopy.h
@(#)Purpose: Array of Memory Blocks - Copy Semantics
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 2017-2023
@(#)Derivation: aomcopy.h 1.6 2023/01/16 20:34:13
@(#)Copyright: (C) JLSS 2017-2024
@(#)Derivation: aomcopy.h 1.7 2024/05/20 14:43:13
*/

/*TABSTOP=4*/
Expand All @@ -16,7 +16,7 @@ extern "C" {
#endif

#include <stdbool.h> /* bool */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply, AoM_PrintData */

/*
** The AoM_Copy structure is for an array of memory blocks which makes a
Expand Down
6 changes: 3 additions & 3 deletions src/libsoq/aommngd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@(#)File: aommngd.h
@(#)Purpose: Array of Memory Blocks - Memory Managed Data
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 2018-2023
@(#)Derivation: aommngd.h 1.4 2023/01/16 20:33:37
@(#)Copyright: (C) JLSS 2018-2024
@(#)Derivation: aommngd.h 1.5 2024/05/20 14:43:13
*/

/*TABSTOP=4*/
Expand All @@ -16,7 +16,7 @@ extern "C" {
#endif

#include <stdbool.h> /* bool */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply, AoM_PrintData */

/*
** The AoM_Managed structure is for an array of memory blocks which
Expand Down
6 changes: 3 additions & 3 deletions src/libsoq/aomptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@(#)File: aomptr.h
@(#)Purpose: Array of Memory Blocks - Pointer Semantics
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 2017-2023
@(#)Derivation: aomptr.h 1.4 2023/01/16 20:33:02
@(#)Copyright: (C) JLSS 2017-2024
@(#)Derivation: aomptr.h 1.5 2024/05/20 14:43:13
*/

/*TABSTOP=4*/
Expand All @@ -16,7 +16,7 @@ extern "C" {
#endif

#include <stdbool.h> /* bool */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply */
#include "aomcore.h" /* (FILE, size_t), AoM_Block, AoM_SimpleApply, AoM_ContextApply, AoM_PrintData */

/*
** The AoM_Pointer structure is for an array of memory blocks which
Expand Down
6 changes: 3 additions & 3 deletions src/libsoq/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@(#)Purpose: Support for Debugging Printing
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 1990-2023
@(#)Derivation: debug.c 4.1 2023/03/13 17:14:56
@(#)Derivation: debug.c 4.2 2024/05/31 19:53:09
*/

/*TABSTOP=4*/
Expand Down Expand Up @@ -196,8 +196,8 @@ int db_setdebug(int level)
static void db_test(void)
{
fprintf(stderr, "Should appear at indent = %d\n", db_newindent() + 1);
TRACE((1, "This should have appeared at debug level %d; %d %f\n",
1, 3, 3.141593));
DB_TRACE(1, "This should have appeared at debug level %d; %d %f\n",
1, 3, 3.141593);
DB_TRACE(2, "This should have appeared at debug level %d; %d %f\n",
2, 3, 3.141593);
DB_TRACELOC(3, "This should have appeared at debug level %d; %d %f\n",
Expand Down
15 changes: 13 additions & 2 deletions src/libsoq/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@(#)File: debug.h
@(#)Purpose: Support for Debugging Printing
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 1990-2023
@(#)Derivation: debug.h 4.1 2023/03/13 17:14:56
@(#)Copyright: (C) JLSS 1990-2024
@(#)Derivation: debug.h 4.2 2024/05/21 04:48:42
*/

#ifndef DEBUG_H
Expand Down Expand Up @@ -48,6 +48,17 @@
#define DB_CALL(level, ...)\
do { if (DB_ACTIVE && db_getdebug() >= (level)) { __VA_ARGS__; } } while (0)

/*
** Usage: DB_BEGIN(level);
** ...conditional code...
** DB_END();
** The semicolon after DB_BEGIN is optional, but harmless.
** If DB_BEGIN/DB_END are not properly matched, all hell will break loose.
*/

#define DB_BEGIN(level) do { if (DB_ACTIVE && db_getdebug() >= (level)) {
#define DB_END() } } while (0)

/*
** DB_TRACKING(); uses the FEATURE_FILE macro from klduge.h to embed a
** string in a function identifying that the file is compiled with debug
Expand Down
30 changes: 24 additions & 6 deletions src/libsoq/gcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@(#)File: gcd.h
@(#)Purpose: GCD - Greatest Common Denominator
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 2005-2017
@(#)Derivation: gcd.h 1.5 2017/08/25 22:50:04
@(#)Copyright: (C) JLSS 2005-2024
@(#)Derivation: gcd.h 1.6 2024/02/08 05:19:55
*/

/*TABSTOP=4*/
Expand All @@ -29,16 +29,34 @@ extern "C" {
**
** (A trailing semicolon creates an empty declaration after the
** function; it isn't the end of the world, but it isn't right.)
**
** A recursive GCD function looks like:
** int gcd_recursive(int x, int y)
** {
** if (y == 0)
** return x;
** return gcd_recursive(y, x % y);
** }
** There is no good reason to use recursion; the iterative
** solution is more sensible.
*/

#define DECLARE_GCD_FUNCTION(storage_class, type, name) \
storage_class type name(type x, type y)

#define DEFINE_GCD_FUNCTION(storage_class, type, name) \
storage_class type name(type x, type y) { type r; \
if (x <= 0 || y <= 0) return(0); \
while ((r = x % y) != 0) { x = y; y = r; } \
return(y); }
storage_class type name(type x, type y) \
{ \
if (x <= 0 || y <= 0) \
return(0); \
type r; \
while ((r = x % y) != 0) \
{ \
x = y; \
y = r; \
} \
return(y); \
}

DECLARE_GCD_FUNCTION(extern, int, gcd);
DECLARE_GCD_FUNCTION(extern, unsigned long long, gcd_ull);
Expand Down
2 changes: 1 addition & 1 deletion src/libsoq/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include ../../etc/soq-head.mk
#TFLAGS = -DTEST
CP = cp
CPFLAGS = -fp
CFLAGS += -DHAVE_CONFIG_H
CFLAGS += -DHAVE_NANOSLEEP

# FILES.c lists source files for which there is a matching header
FILES.c = \
Expand Down
33 changes: 13 additions & 20 deletions src/libsoq/mddebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@
@(#)File: mddebug.c
@(#)Purpose: Support for Debugging Printing with Multiple Subsystems
@(#)Author: J Leffler
@(#)Copyright: (C) JLSS 1990-2023
@(#)Derivation: mddebug.c 4.1 2023/03/13 17:14:56
@(#)Copyright: (C) JLSS 1990-2024
@(#)Derivation: mddebug.c 4.3 2024/05/31 19:53:22
*/

/*TABSTOP=4*/
#include "posixver.h"
#undef DEBUG
#define DEBUG
#include "mddebug.h" /* SSC: Self-sufficiency check */
#include "debug.h"
#include "stderr.h"

#include "posixver.h"
#include "mddebug.h" /* SSC: Self-sufficiency check */
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define USE_JLSS_GETSUBOPT
#define USE_JLSS_GETOPT
#include "getopt.h"
#include "strtoint.h" /* strtoi() */

#ifndef GETSUBOPT
#define GETSUBOPT(opt, tokens, value) getsubopt(opt, tokens, value)
#endif
#include "debug.h"
#include "jlss-getopt.h"
#include "stderr.h"
#include "strtoint.h" /* strtoi() */

#define DB_ON 3
#define DB_OFF 0
Expand Down Expand Up @@ -89,7 +82,7 @@ void db_mdsubsysnames(char * const *names)
/*
** Parse the value of an argument (eg -D subsys1=3,subsys2=9),
** setting the relevant subsystems to the relevant debug levels.
** NB: argument is destroyed by getsubopt().
** NB: argument is destroyed by jlss_getsubopt().
** Returns: 0 OK, -1 some fault occurred.
*/
int db_mdparsearg(char *arg)
Expand Down Expand Up @@ -146,7 +139,7 @@ int db_mdparsearg(char *arg)
/*
** Print debug information if subsys_debug[subsys] set at or above level.
*/
void db_mdprint(int subsys, int level, const char *fmt,...)
void db_mdprint(int subsys, int level, const char *fmt, ...)
{
if (subsys >= 0 && subsys < subsys_max && subsys_debug[subsys] >= level)
{
Expand All @@ -170,7 +163,7 @@ void db_mdprint(int subsys, int level, const char *fmt,...)
** Print debug information if subsys_debug[subsys] set at or above level.
*/
void db_mdprintloc(int subsys, int level, const char *file, int line,
const char *func, const char *fmt,...)
const char *func, const char *fmt, ...)
{
if (subsys >= 0 && subsys < subsys_max && subsys_debug[subsys] >= level)
{
Expand Down Expand Up @@ -207,8 +200,8 @@ static char * const ss_names[] =
static void db_test(void)
{
fprintf(stderr, "Should appear at indent = %d\n", db_newindent() + 1);
MDTRACE((TRACE, 1, "This should have appeared at debug level %d; %d %f\n",
1, 3, 3.141593));
DB_MDTRACE(TRACE, 1, "This should have appeared at debug level %d; %d %f\n",
1, 3, 3.141593);
DB_MDTRACE(SUBSYS_1, 2, "This should have appeared at debug level %d; %d %f\n",
2, 3, 3.141593);
DB_MDTRACE(SUBSYS_2, 3, "This should have appeared at debug level %d; %d %f\n",
Expand Down
Loading

0 comments on commit f454b84

Please sign in to comment.