Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K&R sim/** #392

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sim: constify various APIs
dlmiles committed Jan 31, 2025
commit d6191410becac046a0295d55296c71bf29c814e3
34 changes: 18 additions & 16 deletions sim/SimDBstuff.c
Original file line number Diff line number Diff line change
@@ -94,7 +94,8 @@ SimConnectFunc(
struct conSrArg2 *csa2;
Rect tileArea, *srArea, newarea;
SearchContext *scx = cx->tc_scx;
TileTypeBitMask notConnectMask, *connectMask;
TileTypeBitMask notConnectMask;
const TileTypeBitMask *connectMask;
TileType loctype, ctype;
TileType dinfo = 0;
int i, pNum;
@@ -327,18 +328,18 @@ SimTreeCopyConnect(
* this area. The transform is from
* coords of scx_use to destUse.
*/
TileTypeBitMask *mask, /* Tile types to start from in area. */
const TileTypeBitMask *mask, /* Tile types to start from in area. */
int xMask, /* Information must be expanded in all
* of the windows indicated by this
* mask. Use 0 to consider all info
* regardless of expansion.
*/
TileTypeBitMask *connect, /* Points to table that defines what
const TileTypeBitMask *connect, /* Points to table that defines what
* each tile type is considered to
* connect to. Use DBConnectTbl as
* a default.
*/
Rect *area, /* The resulting information is
const Rect *area, /* The resulting information is
* clipped to this area. Pass
* TiPlaneRect to get everything.
*/
@@ -354,7 +355,7 @@ SimTreeCopyConnect(
{
TerminalPath tpath;
char pathName[MAXPATHNAME];
TileTypeBitMask *newmask;
const TileTypeBitMask *newmask;
struct conSrArg2 csa2;
TileType newtype;

@@ -439,11 +440,11 @@ SimTreeCopyConnect(

bool
efPreferredName(
char *name1,
char *name2)
const char *name1,
const char *name2)
{
int nslashes1, nslashes2;
char *np1, *np2;
const char *np1, *np2;

if( name1[0] == '@' && name1[1] == '=' )
return( TRUE );
@@ -556,20 +557,21 @@ SimSrConnect(
* the connectivity search. Only paint
* in this definition is considered.
*/
Rect *startArea, /* Area to search for an initial tile. Only
const Rect *startArea, /* Area to search for an initial tile. Only
* tiles OVERLAPPING the area are considered.
* This area should have positive x and y
* dimensions.
*/
TileTypeBitMask *mask, /* Only tiles of one of these types are used
const TileTypeBitMask *mask,/* Only tiles of one of these types are used
* as initial tiles.
*/
TileTypeBitMask *connect, /* Pointer to a table indicating what tile
const TileTypeBitMask *connect,
/* Pointer to a table indicating what tile
* types connect to what other tile types.
* Each entry gives a mask of types that
* connect to tiles of a given type.
*/
Rect *bounds, /* Area, in coords of scx->scx_use->cu_def,
const Rect *bounds, /* Area, in coords of scx->scx_use->cu_def,
* that limits the search: only tiles
* overalapping this area will be returned.
* Use TiPlaneRect to search everywhere.
@@ -667,7 +669,7 @@ SimTreeSrTiles(
* coordinates of the cell's def, and a
* transform back to "root" coordinates.
*/
TileTypeBitMask *mask, /* Only tiles with a type for which
const TileTypeBitMask *mask,/* Only tiles with a type for which
* a bit in this mask is on are processed.
*/
int xMask, /* All subcells are visited recursively
@@ -712,7 +714,7 @@ SimTreeSrNMTiles(
TileType dinfo, /* Type containing information about the
* triangular area to search.
*/
TileTypeBitMask *mask, /* Only tiles with a type for which
const TileTypeBitMask *mask,/* Only tiles with a type for which
* a bit in this mask is on are processed.
*/
int xMask, /* All subcells are visited recursively
@@ -862,12 +864,12 @@ SimCellTileSrFunc(
int
SimPutLabel(
CellDef *cellDef, /* Cell in which label is placed */
Rect *rect, /* Location of label, see above for description */
const Rect *rect, /* Location of label, see above for description */
int align, /* Orientation/alignment of text. If this is < 0,
* an orientation will be picked to keep the text
* inside the cell boundary.
*/
char *text, /* Pointer to actual text of label */
const char *text, /* Pointer to actual text of label */
TileType type) /* Type of tile to be labeled */
{
Label *lab;
4 changes: 2 additions & 2 deletions sim/SimExtract.c
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ typedef struct /* return value from SimFindOneNode */
char *
SimTxtorLabel(
int nterm,
Transform *tm,
const Transform *tm,
SimTrans *trans)
{
static char name[30];
@@ -707,7 +707,7 @@ SimGetNodeName(
Tile *tp, /* tile in this cell which is part
* of the node
*/
char *path) /* path name of hierarchy of search */
const char *path) /* path name of hierarchy of search */
{
CellDef *def = sx->scx_use->cu_def;
NodeRegion *nodeList;
16 changes: 8 additions & 8 deletions sim/SimRsim.c
Original file line number Diff line number Diff line change
@@ -98,9 +98,9 @@ void SimStopRsim(void);
*-----------------------------------------------------------------------
*/

char *
const char *
SimGetNodeCommand(
char *cmd)
const char *cmd)
{
/* This table is used to define which Rsim commands are applied to
* each node in the selection. Depending on the command, you
@@ -292,7 +292,7 @@ void
SimConnectRsim(
bool escRsim) /* TRUE if we should escape back to Magic */
{
static char HELLO_MSG[] =
static const char HELLO_MSG[] =
"Type \"q\" to quit simulator or \".\" to escape back to Magic.\n";

char *replyLine; /* used to hold one line of the Rsim reply */
@@ -384,7 +384,7 @@ SimConnectRsim(

bool
InitRsim(
char *hello_msg)
const char *hello_msg)
{
char buff[READBUF_SIZE];
char *last;
@@ -517,7 +517,7 @@ SimStopRsim(void)
void
RsimErrorMsg(void)
{
static char msg[] = "The simulator must be running before this command "
static const char msg[] = "The simulator must be running before this command "
"can be executed. To do\n"
"this enter the command \"rsim <options> <filename>\". "
"To escape back to\n"
@@ -549,8 +549,8 @@ RsimErrorMsg(void)

void
SimRsimIt(
char *cmd,
char *nodeName)
const char *cmd,
const char *nodeName)
{

static char cmdStr[512];
@@ -925,7 +925,7 @@ SimGetReplyLine(
void
SimInit(void)
{
static char *rsimdoc =
static const char *rsimdoc =
"You are currently using the \"rsim\" tool. The button actions are:\n\
left - move the box so its lower-left corner is at cursor position\n\
right - resize box by moving upper-right corner to cursor position\n\
12 changes: 6 additions & 6 deletions sim/SimSelect.c
Original file line number Diff line number Diff line change
@@ -259,7 +259,7 @@ simFreeNodeEntry(

TileListElt *
SimSelectArea(
Rect *rect)
const Rect *rect)
{
int plane;
int SimSelectFunc();
@@ -434,12 +434,12 @@ SimSelectFunc(

bool
SimSelection(
char *cmd) /* rsim command to apply to the selection */
const char *cmd) /* rsim command to apply to the selection */
{
static char Hstring[] = "RSIM=1";
static char Lstring[] = "RSIM=0";
static char Xstring[] = "RSIM=X";
static char QUESTstring[] = "?";
static const char Hstring[] = "RSIM=1";
static const char Lstring[] = "RSIM=0";
static const char Xstring[] = "RSIM=X";
static const char QUESTstring[] = "?";

char timeString[256];
TileListElt *current, *node_list;
24 changes: 12 additions & 12 deletions sim/sim.h
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@
#include "textio/txcommands.h" /* TxCommand */
#include "windows/windows.h" /* MagWindow */

extern char *SimGetNodeCommand(char *cmd);
extern char *SimGetNodeName(SearchContext *sx, Tile *tp, char *path);
extern const char *SimGetNodeCommand(const char *cmd);
extern char *SimGetNodeName(SearchContext *sx, Tile *tp, const char *path);
extern char *SimSelectNode(SearchContext *scx, TileType type, int xMask, char *buffer);
extern bool SimGetReplyLine(char **replyLine);
extern void SimRsimIt(char *cmd, char *nodeName);
extern void SimRsimIt(const char *cmd, const char *nodeName);
extern void SimEraseLabels(void);
extern bool efPreferredName(char *name1, char *name2);
extern bool efPreferredName(const char *name1, const char *name2);
extern void SimRsimHandler(MagWindow *w, TxCommand *cmd);
extern void SimInit(void);

@@ -34,18 +34,18 @@ extern HashTable SimAbortSeenTbl;
extern void SimGetnode(void);
extern void SimGetsnode(void);
extern void SimGetNodeCleanUp(void);
extern int SimPutLabel(CellDef *cellDef, Rect *rect, int align, char *text, TileType type);
extern int SimSrConnect(CellDef *def, Rect *startArea, TileTypeBitMask *mask, TileTypeBitMask *connect,
Rect *bounds, int (*func)(), ClientData clientData);
extern void SimTreeCopyConnect(SearchContext *scx, TileTypeBitMask *mask, int xMask, TileTypeBitMask *connect,
Rect *area, CellUse *destUse, char *Node_Name);
extern int SimTreeSrNMTiles(SearchContext *scx, TileType dinfo, TileTypeBitMask *mask, int xMask, TerminalPath *tpath,
extern int SimPutLabel(CellDef *cellDef, const Rect *rect, int align, const char *text, TileType type);
extern int SimSrConnect(CellDef *def, const Rect *startArea, const TileTypeBitMask *mask, const TileTypeBitMask *connect,
const Rect *bounds, int (*func)(), ClientData clientData);
extern void SimTreeCopyConnect(SearchContext *scx, const TileTypeBitMask *mask, int xMask, const TileTypeBitMask *connect,
const Rect *area, CellUse *destUse, char *Node_Name);
extern int SimTreeSrNMTiles(SearchContext *scx, TileType dinfo, const TileTypeBitMask *mask, int xMask, TerminalPath *tpath,
int (*func)(), ClientData cdarg);
extern int SimTreeSrTiles(SearchContext *scx, TileTypeBitMask *mask, int xMask, TerminalPath *tpath,
extern int SimTreeSrTiles(SearchContext *scx, const TileTypeBitMask *mask, int xMask, TerminalPath *tpath,
int (*func)(), ClientData cdarg);
extern bool SimStartRsim(char *argv[]);
extern void SimConnectRsim(bool escRsim);
extern bool SimSelection(char *cmd);
extern bool SimSelection(const char *cmd);
extern void SimRsimMouse(MagWindow *w);
extern int SimFillBuffer(char *buffHead, char **pLastChar, int *charCount);