Files
magic/utils/main.h
T
Intubun 8e8fada32f Add WASM entry point and Emscripten build wiring
The pieces that make Magic actually buildable as a WASM library.

* magic/magicWasm.c — new headless entry point exporting four
  functions used by the JS wrapper:
    - magic_wasm_init()           idempotent initialisation
    - magic_wasm_run_command(s)   dispatch one Magic command
    - magic_wasm_source_file(p)   execute a script from the VFS
    - magic_wasm_update()         drive a display-update cycle
  Sets CAD_ROOT=/ if unset, so embedded technology files under
  /magic/sys/ resolve correctly. Centers the command point inside
  GrScreenRect so commands route to the layout window client
  rather than the border/window-management client.

* utils/main.c, utils/main.h — split magicMain() into magicMainInit()
  + the dispatch loop. magicMainInit is idempotent (a static flag
  guards against re-initialisation) so JS callers can call any of
  the four wasm entry points first without sequencing.

* magic/Makefile — adds the WASM link target, gated by MAKE_WASM=1
  set from toolchains/emscripten/defs.mak. Conditionally compiles
  magicWasm.c into the main binary, links to magic.js and runs
  post-build.sh on the result.

* toolchains/emscripten/defs.mak — Emscripten linker flags (WASM=1,
  MODULARIZE, EXPORT_ES6, ALLOW_MEMORY_GROWTH, INITIAL_MEMORY=32M,
  STACK_SIZE=5M), the four EXPORTED_FUNCTIONS, and the embed-file
  bindings for the technology files under /magic/sys/.

* toolchains/emscripten/post-build.sh — patches Emscripten's ESM
  output so it works in pure Node.js ESM: aliases require()
  through createRequire, injects __filename / __dirname shims,
  and resyncs the ___emscripten_embedded_file_data constant from
  the wasm global section if Emscripten emitted a stale value.
  Idempotent and pinned to emsdk 3.1.56 (see WARNING in the
  header).

* toolchains/emscripten/README.md — full build documentation:
  quick-start via npm/build.sh, manual build, list of embedded
  files, exported C API, JavaScript usage example, and notes on
  CAD_ROOT, DISPLAY_SUSPEND, and the signal-API stubs.

* .gitignore — adds the WASM artefacts (magic.js, magic.wasm,
  magic.symbols), tightens the editor/OS cruft list, and keeps
  toolchains/emscripten/defs.mak tracked despite the `defs.mak`
  ignore rule.
2026-05-11 14:20:47 -04:00

106 lines
3.7 KiB
C

/*
* main.h --
*
* Header file containing global variables for all MAGIC modules and a
* couple of global procedures.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*
*
* rcsid="$Header: /usr/cvsroot/magic-8.0/utils/main.h,v 1.2 2009/09/10 20:32:55 tim Exp $"
*/
#ifndef _MAGIC__UTILS__MAIN_H
#define _MAGIC__UTILS__MAIN_H
#include "windows/windows.h"
#include "database/database.h"
/* global data structures */
extern char *Path; /* Search path */
extern char *CellLibPath; /* Library search path for cells */
extern char *SysLibPath; /* Library search path for tech files,
* etc.
*/
extern char *MainMouseFile; /* The filename of the mouse */
extern char *MainGraphicsFile; /* The filename of the display */
extern char *MainDisplayType;
extern char *MainMonType;
extern FILE *mouseStream; /* the mouse file */
extern FILE *graphicsStream; /* the graphics file */
extern short RuntimeFlags; /* A number of flags, defined below */
/*
* RuntimeFlags bits:
*/
#define MAIN_DEBUG 0x1 /* Produce debugging output */
#define MAIN_RECOVER 0x2 /* Recover crash files */
#define MAIN_SILENT 0x4 /* Output as little as possible,
* for batch mode
*/
#define MAIN_MAKE_WINDOW 0x8 /* True if we are to produce a window
* on startup.
*/
#define MAIN_TK_CONSOLE 0x10 /* True if the Tcl version is running
* via the "tkcon" console window.
*/
#define MAIN_TK_PRINTF 0x20 /* Set to 0 to redirect output from the
* console back to the terminal.
*/
/*
* Macros which convert the RuntimeFlags bits to their original use as
* bool types.
*/
#define mainDebug (((RuntimeFlags & MAIN_DEBUG) > 0) ? TRUE : FALSE)
#define mainRecover (((RuntimeFlags & MAIN_RECOVER) > 0) ? TRUE : FALSE)
#define MakeMainWindow (((RuntimeFlags & MAIN_MAKE_WINDOW) > 0) ? TRUE : FALSE)
#define TxTkConsole (((RuntimeFlags & MAIN_TK_CONSOLE) > 0) ? TRUE : FALSE)
#define TxTkOutput (((RuntimeFlags & MAIN_TK_PRINTF) > 0) ? TRUE : FALSE)
#define MainSilent (((RuntimeFlags & MAIN_SILENT) > 0) ? TRUE : FALSE)
/*
* The following information is kept about the Edit cell:
*
* EditCellUse pointer to the CellUse from which the edit
* cell was selected.
* EditRootDef pointer to root def of window in which edit cell
* was selected.
* EditToRootTransform transform from coordinates of the Def of edit cell
* to those of EditRootDef.
* RootToEditTransform transform from coordinates EditRootDef to those
* of the Def of the edit cell.
*/
extern CellUse *EditCellUse;
extern CellDef *EditRootDef;
extern Transform EditToRootTransform;
extern Transform RootToEditTransform;
/* global procedures */
extern void MainExit(int) ATTR_NORETURN; /* a way of exiting that cleans up after itself */
extern void magicMain();
extern int magicMainInit(int argc, char *argv[]);
/* C99 compat */
extern int mainInitBeforeArgs();
extern int mainDoArgs();
extern int mainInitAfterArgs();
extern int mainInitFinal();
#endif /* _MAGIC__UTILS__MAIN_H */