@@ -237,97 +237,52 @@ OMsymRecord.meta := rec(
237
237
# # [ ["call_id", "user007" ], ["option_runtime", 300000] ]
238
238
# # This is a counterpart of the function OMGetObject from OpenMath package .
239
239
# #
240
+ # # TODO: This should be somehow replaced by OMGetObject from the OpenMath package
240
241
InstallGlobalFunction( OMGetObjectWithAttributes,
241
242
function ( stream )
242
- local return_tree,
243
- fromgap, # string
244
- firstbyte,
245
- gap_obj,
246
- success, # whether PipeOpenMathObject worked
247
- readline;
248
-
249
- if IsClosedStream( stream ) then
250
- Error( " closed stream" );
251
- elif IsEndOfStream( stream ) then
252
- Error( " end of stream" );
253
- fi ;
254
-
255
- if ValueOption(" return_tree" ) <> fail then
256
- return_tree := true ;
257
- else
258
- return_tree := false ;
243
+ local ReadUntil, tree;
244
+
245
+ ReadUntil := function (stream, string )
246
+ local readline;
247
+ repeat
248
+ readline := ReadLine(stream);
249
+ if readline = fail then
250
+ return fail ;
251
+ fi ;
252
+ NormalizeWhitespace( readline );
253
+ if Length(readline) > 0 then
254
+ Info ( InfoSCSCP, 2 , readline );
255
+ fi ;
256
+ until readline = string;
257
+ return true ;
258
+ end ;
259
+
260
+ if IsClosedStream(stream) then
261
+ Error(" <stream> is closed" );
262
+ elif IsEndOfStream(stream) then
263
+ Error(" <stream> is in state end of stream" );
259
264
fi ;
260
265
261
266
# read new line until <?scscp start ?>
262
- repeat
263
- readline:= ReadLine(stream);
264
- if readline= fail then
265
- return fail ;
266
- fi ;
267
- NormalizeWhitespace( readline );
268
- if Length( readline ) > 0 then
269
- Info ( InfoSCSCP, 2 , readline );
270
- fi ;
271
- until readline= " <?scscp start ?>" ;
272
-
273
- firstbyte := ReadByte(stream);
274
-
275
- if firstbyte = 24 then
276
- # Reading binary encoding => set reply mode to binary
277
- IN_SCSCP_BINARY_MODE:= true ;
278
- gap_obj := GetNextObject( stream, firstbyte );
279
- gap_obj := OMParseXmlObj( gap_obj.content[ 1 ] );
280
- return rec ( object := gap_obj, attributes := OMParseXmlObj( OMTempVars.OMATTR ) );
281
- else
282
-
283
- if firstbyte = fail then
284
- Info ( InfoSCSCP, 2 , " OpenMath object not retrieved by PipeOpenMathObject" );
285
- return fail ;
286
- fi ;
287
-
288
- # Reading XML encoding => set reply mode to XML
289
- IN_SCSCP_BINARY_MODE:= false ;
290
- fromgap := " " ;
291
- # Get one OpenMath object from 'stream' and put into 'fromgap',
292
- # using PipeOpenMathObject
293
-
294
- success := PipeOpenMathObject( stream, fromgap, firstbyte );
295
-
296
- if success <> true then
297
- Info ( InfoSCSCP, 2 , " OpenMath object not retrieved by PipeOpenMathObject" );
298
- return fail ;
299
- fi ;
300
-
301
- # Now 'fromgap' is the string with OpenMath encoding
302
-
303
- if InfoLevel( InfoSCSCP ) > 2 then
304
- Print(" #I Received message: \n " );
305
- Print( fromgap );
306
- Print( " \n " );
307
- fi ;
308
-
309
- # read new line until <?scscp end ?>
310
- repeat
311
- readline:= ReadLine(stream);
312
- if readline= fail then
313
- return fail ;
314
- fi ;
315
- NormalizeWhitespace( readline );
316
- if Length( readline ) > 0 then
317
- Info ( InfoSCSCP, 2 , readline );
318
- fi ;
319
- until readline= " <?scscp end ?>" ;
320
-
321
- # convert the OpenMath string into a Gap object using an appropriate
322
- # function
323
-
324
- if return_tree then
325
- return OMgetObjectXMLTreeWithAttributes( fromgap : return_tree );
326
- else
327
- return OMgetObjectXMLTreeWithAttributes( fromgap );
328
- fi ;
267
+ # TODO: How to switch binary/nonbinary?
268
+ # previously this code had this switch:
269
+ # IN_SCSCP_BINARY_MODE:=true;
270
+ # IN_SCSCP_BINARY_MODE:=false;
271
+ # (again state in global variables...)
272
+ # TODO: Handle attributes, they seem to end up
273
+ # in temp vars for some reason, are then
274
+ # extracted to attributes in the returned record?
275
+ # TODO: Need to return fail if ReadUntil fails
276
+
277
+ ReadUntil(" <?scscp start ?>" );
278
+ tree := OMGetTree(stream);
279
+ ReadUntil(" <?scscp end ?>" );
280
+
281
+ if ValueOption(" return_tree" ) = fail then
282
+ return OMParseXmlObj( tree.content[ 1 ] );
329
283
fi ;
330
- end );
284
+ return tree;
285
+ end );
331
286
332
287
333
288
# ############################################################################
0 commit comments