Commit Graph

129 Commits

Author SHA1 Message Date
Darryl L. Miles 3fc1c7e452 gcc11 -Wall -Wpedantic document for the next person 2025-01-06 16:33:22 +00:00
Darryl L. Miles 48c99a7b1d gcc11 -Wall -Wpedantic cleanup (post TCL9) FUN2CD() CD2FUN()
FUN2CD() on a function pointer still raises -Wpedantic warning due to the
officially undefined behaviour as defined by C standards.

So added FUN2CD() and CD2FUN() to at least mark the call-sites to help
with identification and ignoring -Wpedantic based on the source file
context given in the compiler output.
2025-01-06 16:25:15 +00:00
Darryl L. Miles 7e9d4cc15e ihash.c: cleanup warning use of void* with pointer arithmetic
Use of (void*) with pointer arithmetic warning removal.

But more so as it is in a macro (all be it local to file) which will
take on the form of the type passed as argument when the 'offset' looks
to be always be specified in bytes.
2025-01-06 16:21:22 +00:00
Darryl L. Miles ff9487de1f hash.c: K&R conversion to ANSI and constify arguments / callback
cb_heap_kill_t callback typedef created

Invoked from HeapKill()

No active callback implementation in the codebase.

callback interface (from hash.h):
  marked @invoke call-site
2025-01-06 16:15:58 +00:00
Darryl L. Miles d9cfd64d60 utils/*.c: K&R conversion to ANSI 2025-01-06 16:14:34 +00:00
Darryl L. Miles 07f9bbe1fb gcc11 -Wall -Wpedantic cleanup 2025-01-06 16:12:11 +00:00
Darryl L. Miles 7e5d0b0688 TCL9: FIXME OPTIONAL magic.h ClientData
This did not work as expected.  Maybe that indicate this should have
a slighlt restructure so the tcl.h definition is always given a chance
to provide type.

Or maybe autoconf should detect the type and provide in config.h ?
2025-01-04 11:08:01 -05:00
Darryl L. Miles 272dda3c84 TCL9: TxResetTerminal(bool force) added arguments
This seems like it has 2 use cases.

Internal console management around reprinting command prompt, but many
 modes of operation delegate the prompt processing to tkcon or readline.
Process termination to restore the termios.
2025-01-04 11:08:01 -05:00
Darryl L. Miles 77a7afc8e2 TCL9: Tcl_SetExitProc() API was removed
The Tcl_Exit() replacement proc takes charge of calling exit()

So this function can be easily migrated to libc atexit() which will
now run during exit() not just before.  Which seems ok for the purpose
of restoring the termios state of the tty.

This solution seems compatible with TCL8 as well so all calls to this
removed API are removed.

Note this patch also removes the invalidation (of the callback so
the deefault use of Tcl_Exit() is restored) before returning from
this function.  atexit() usage can not be invalidated after
registration but that can be controlled with application flag
checked inside the callback function if needed.
I have observed scenarios where I need to issue 'reset' manually
after exiting magic, still understanding better the build types
and scenarios that triggers this.
2025-01-04 11:08:01 -05:00
Darryl L. Miles 0ce8265570 TCL9: ClientData macro assignment and access usage 2025-01-04 11:08:01 -05:00
Darryl L. Miles 93c16c8431 TCL9: magic.h ClientData type change helper macros
Now a (void *) but previously an integer.

These macros resolve the codebase allowing it to be built against both
tcl8 (8.5, 8.6) and tcl9 (9.0).

tar -zxvf tcl9.0.0-src.tar.gz
cd tcl9.0.0/unix
./configure --enable-symbols --prefix=/opt/tktcl9
make install

tar -zxvf tk9.0.0-src.tar.gz
cd tk9.0.0/unix
./configure --enable-symbols --prefix=/opt/tktcl9 --with-tcl=/opt/tktcl9/lib
make install

cd magic
./configure --with-tk=/opt/tktcl9/lib --with-tcl=/opt/tktcl9/lib
2025-01-04 11:08:01 -05:00
Darryl Miles c4373d74aa LIBtextio.c: printf style constify fmt call-site 2025-01-03 09:08:14 +00:00
Darryl L. Miles 5770da2abd geometry.c: TxError() constify call-site 2025-01-03 09:08:14 +00:00
Darryl Miles 1aee10ef4d utils/magic.h: ANALYSER_xxxxxxxxxx __attribute__ 2025-01-03 09:08:14 +00:00
Darryl Miles 2fcd024bdb utils/magic.h: ATTR_SENTINEL __attribute__ ((sentinel)) 2025-01-03 09:08:14 +00:00
Darryl L. Miles c8974ed2ec utils/main.h: MainExit() add ATTR_NORETURN hint 2025-01-03 09:08:14 +00:00
Darryl L. Miles 31d7130833 utils/magic.h: ATTR_UNREACHABLE ATTR_NORETURN
Add optional compiler support for these attribute hints.
2025-01-03 09:08:14 +00:00
Darryl L. Miles fc02f57d73 magic.h: add macro __unused__
__attribute__((unused))

use like:

void myFunc(int arg0, __unused__(arg1)) { ... }
2025-01-03 09:08:14 +00:00
Darryl Miles bf96348502 printf: vararg functions use 'const' for format string 2025-01-03 09:08:14 +00:00
Darryl Miles 94ec5cf98f printf: use compiler __attribute__((format (printf,fff,aaa))) 2025-01-03 09:08:14 +00:00
Tim Edwards 8371d797ad Revised some code from PR#352 in response to questions from Darryl
Miles.  Updated the version number to go along with the merge of
a number of pull requests done today.
2024-12-26 15:29:54 -05:00
Darryl L. Miles bbc52ecd41 util/hash.c: fix use after free (not quite)
Dereference of 'h' after calling freeMagic(h)
Found while putting in cast.

Initially this is what was thought however....

freeMagic() has this one allocation to free latency, which is a matter
to resolve another day.
2024-12-26 15:20:58 -05:00
Darryl L. Miles fd5050b2b5 util/lookup*.c: fix integer pointer arithmetic not using pointertype
This would be a bug on WIN64 and other LLP64 models.
2024-12-26 15:20:58 -05:00
Darryl L. Miles f22ecda44a set.c: SetNoisyBool() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 2b69b07860 set.c: SetNoisyDI() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles f51ad56aea set.c: SetNoisyInt() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 5b97638ac7 port.c: MagAtof() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 14a8409e40 utils.h: Wait()/WaitPid() add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 265ace5c9f path.c: PaEnum() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 6bccbef0d4 path.c: PaSubsWD() constify and no prototype exists
This function does not appear used across the codebase.
No prototype exists in utils.h
2024-12-26 15:20:58 -05:00
Darryl L. Miles c77d3852d5 path.c: PaOpen() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles fd7eab2193 path.c: PaZOpen() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles d077368436 path.c: PaLockOpen() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 875d825afb path.c: PaLockZOpen() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles bfb411d19f path.c: nextName() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles feef9730f3 path.c: PaExpand() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 6a6f85862e path.c: PaAppend() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles fca164715e PaCheckCompressed() constify implementation 2024-12-26 15:20:58 -05:00
Darryl L. Miles e22e5d63b9 PaCheckCompressed() removed API quirkiness
When constifying there is this inconsistent quirk in this API returning
'filename' or a malloced storage.  When special handling needs to be
made by the caller to detect this to decide if it needs a free.

This appears to done to save a strdup().

Make it always return a malloc block so the API contract is
strightforward to the caller.  A non-NULL return requires
free() by the caller.
2024-12-26 15:20:58 -05:00
Darryl L. Miles e7bfa72298 args.c: ArgStr() constify and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 2ba1d20ab4 utils/match.c constify Match() and add prototype 2024-12-26 15:20:58 -05:00
Darryl L. Miles 14b6453707 LookupStruct() constify call-site
irouter/irTestCmd.c: LookupStruct() constify call-site
irouter/irCommand.c: LookupStruct() constify call-site
mzrouter/mzTestCmd.c: LookupStruct() constify call-site
mzrouter/mzTech.c: LookupStruct() constify call-site
router/rtrCmd.c: LookupStruct() constify call-site
plow/PlowTest.c: LookupStruct() constify call-site
plow/PlowTech.c: LookupStruct() constify call-site
plot/plotVers.c: LookupStruct() constify call-site
grouter/grouteTest.c: LookupStruct() constify call-site
garouter/gaTest.c: LookupStruct() constify call-site
extract/ExtTest.c: LookupStruct() constify call-site
extract/ExtTech.c: LookupStruct() constify call-site
extflat/EFread.c: LookupStruct() constify call-site
DRCtech.c: LookupStruct() constify call-site
debugFlags.c: LookupStruct() constify call-site
CmdSubrs.c: LookupStruct() constify call-site
geometry.c: LookupStruct() constify call-site
set.c: LookupStruct() constify call-site
2024-12-26 15:20:58 -05:00
Darryl L. Miles f5b41a06d6 utils/lookup*.c: constify the API
extern int Lookup(const char *str, const char * const *table);
extern int LookupAny(char, const char * const *);
extern int LookupFull(const char *, const char **);
extern int LookupStruct(const char *str, const LookupTable *table_start, int size);
extern int LookupStructFull(const char *str, const char * const *table, int size);
2024-12-26 15:20:58 -05:00
Darryl L. Miles aa43cc164e geometry.h: constify global wellknown Geometry data values
This then rippled through into callers

Fixed merge conflicts in cif/CIFrdutils.c and cif/CIFread.h
2024-12-26 15:20:39 -05:00
Darryl L. Miles fd6c30a380 geometry.c: constify and add prototypes 2024-12-26 15:10:35 -05:00
Darryl L. Miles efb5d9001c util/hash.[ch]: const hash 'key' for API and internal type
This is mainly to modify the function signature to accept const
data pointers to keys.

Patch required to ease use of const by API consumers.
2024-12-26 15:10:35 -05:00
Darryl L. Miles 91da638579 utils/strdup.c: StrDup() and mode constifiy impl 2024-12-26 15:10:35 -05:00
Darryl L. Miles bfc82e43db MacOS: FREAD rename to magicFREAD due to sys/fcntl.h definition
Example build issue using MacOS 12 (Xcode 14.2 from MacOSX.platform).

In file included from grTk1.c:23:
In file included from ../utils/main.h:26:
In file included from ../windows/windows.h:26:
../utils/magic.h:143:13: warning: 'FREAD' macro redefined [-Wmacro-redefined]
    #define FREAD(a,b,c,d)    gzread(d,a,b*c)
            ^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/fcntl.h:110:9: note: previous definition is here
 #define FREAD           0x00000001
2024-12-26 12:52:25 -05:00
Darryl L. Miles 2f22ec6293 set.c: warning: variable 'result' is used uninitialized
set.c:124:9: warning: variable 'result' is used uninitialized whenever 'if' condition is false

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles ea41b21f67 macros.c: warning: variable 'kc' is used uninitialized
macros.c:557:12: warning: variable 'kc' is used uninitialized whenever 'if' condition is false

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00