Files
magic/tcltk/magicdnull.c
T
Darryl L. MilesandClaude Opus 4.8 aab3361858 tcltk: honor CAD_ROOT for the Tcl runtime dir, not just the baked TCL_DIR
magicexec.c, magicdnull.c and tclmagic.c hardwired the compile-time TCL_DIR
(the install location) when locating magic.tcl (tcl_rcFileName) and the Tcl
auto_path.  So even with CAD_ROOT set -- the documented relocation knob, already
honored by the sys-file search and by tcltk/magic.sh's
TCL_MAG_DIR=${CAD_ROOT}/magic/tcl -- the C launchers still looked in the baked
install path, which is why magic could not source its startup from a relocated
install or a build tree.

Add tcltk/tcldir.h with a MagicTclDir() helper: $CAD_ROOT/magic/tcl when CAD_ROOT
is set and non-empty, else the compile-time TCL_DIR.  Use it in all three sites.
This makes the C side consistent with the shell wrappers and with how magic.tcl
itself already derives its own directory (from `info script`).

Verified: default (no CAD_ROOT) resolves to TCL_DIR as before (build rc=0); with
CAD_ROOT pointed at a staged build tree, `magicdnull -dnull` sources magic.tcl
from there and runs (tech load scmos -> 13 planes).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-26 14:54:11 -04:00

62 lines
1.8 KiB
C

/*----------------------------------------------------------------------*/
/* magicdnull.c */
/* */
/* See comments for "magicexec.c". This has the same function as */
/* magicexec.c, but does not initialize the Tk package. This avoids */
/* bringing up a default window when "magic -dnull -noconsole" is */
/* called, running more efficiently when used in batch mode. */
/*----------------------------------------------------------------------*/
#include <stdio.h>
#include <tcl.h>
#include "tcltk/tcldir.h"
/*----------------------------------------------------------------------*/
/* Application initiation. This is exactly like the AppInit routine */
/* for "wish", minus the cruft, but with "tcl_rcFileName" set to */
/* "magic.tcl" instead of "~/.wishrc". */
/*----------------------------------------------------------------------*/
int
magic_AppInit(interp)
Tcl_Interp *interp;
{
if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "Tcl", Tcl_Init, Tcl_Init);
/* This is where we replace the home ".tclshrc" file with */
/* magic's startup script. */
{
char rc[PATH_MAX];
size_t rlen;
rlen = MagicTclDir(rc, sizeof(rc), "magic.tcl");
assert(rlen < sizeof(rc));
Tcl_SetVar(interp, "tcl_rcFileName", rc, TCL_GLOBAL_ONLY);
}
/* Additional variable can be used to tell if magic is in batch mode */
Tcl_SetVar(interp, "batch_mode", "true", TCL_GLOBAL_ONLY);
return TCL_OK;
}
/*----------------------------------------------------------------------*/
/* The main procedure; replacement for "tclsh". */
/*----------------------------------------------------------------------*/
int
main(argc, argv)
int argc;
char **argv;
{
Tcl_Main(argc, argv, magic_AppInit);
return 0;
}
/*----------------------------------------------------------------------*/