MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / OpenSees_putsCommand

Function OpenSees_putsCommand

SRC/runtime/commands/interpreter.cpp:84–155  ·  view source on GitHub ↗

revised puts command to send to stderr

Source from the content-addressed store, hash-verified

82// revised puts command to send to stderr
83//
84static int
85OpenSees_putsCommand(ClientData dummy, Tcl_Interp *interp, Tcl_Size objc,
86 Tcl_Obj *const objv[])
87{
88 // Tcl_Channel chan; // The channel to puts on.
89 Tcl_Obj *string; /* String to write. */
90 Tcl_Obj *chanObjPtr = NULL; /* channel object. */
91 int newline; /* Add a newline at end? */
92
93 switch (objc) {
94 case 2: /* [puts $x] */
95 string = objv[1];
96 newline = 1;
97 break;
98
99 case 3: /* [puts -nonewline $x] or [puts $chan $x] */
100 if (strcmp(Tcl_GetString(objv[1]), "-nonewline") == 0) {
101 newline = 0;
102 } else {
103 newline = 1;
104 chanObjPtr = objv[1];
105 }
106 string = objv[2];
107 break;
108
109 case 4: /* [puts -nonewline $chan $x] or [puts $chan $x nonewline] */
110 newline = 0;
111 if (strcmp(Tcl_GetString(objv[1]), "-nonewline") == 0) {
112 chanObjPtr = objv[2];
113 string = objv[3];
114 break;
115
116 } else if (strcmp(Tcl_GetString(objv[3]), "nonewline") == 0) {
117 /*
118 * The code below provides backwards compatibility with an old
119 * form of the command that is no longer recommended or
120 * documented. See also [Bug #3151675]. Will be removed in Tcl 9,
121 * maybe even earlier.
122 */
123 chanObjPtr = objv[1];
124 string = objv[2];
125 break;
126 }
127 /* Fall through */
128 default:
129 /* [puts] or [puts some bad number of arguments...] */
130 Tcl_WrongNumArgs(interp, 1, objv, "?-nonewline? ?channelId? string");
131 return TCL_ERROR;
132 }
133
134 if (chanObjPtr == NULL) {
135 G3_Runtime *rt;
136 if ((rt = G3_getRuntime(interp))) {
137 if (newline == 0)
138 fprintf(rt->streams[1], "%s", Tcl_GetString(string));
139 else
140 fprintf(rt->streams[1], "%s\n", Tcl_GetString(string));
141

Callers

nothing calls this directly

Calls 1

G3_getRuntimeFunction · 0.85

Tested by

no test coverage detected