/******************************************************************************/ /* */ /* rxqueue.rex - The RXQUEUE filter of the RVM */ /* =========================================== */ /* */ /* Usage: rxqueue [queuename] [/FIFO | /LIFO | /CLEAR] */ /* */ /* The queues of the RVM are its own, not rxapi's: ooRexx's rxqueue cannot */ /* reach them. An RVM shares them with the commands it runs through a file */ /* (RVM_QUEUES: see RVM.CommandHost~run and the JavaScript host's run), and */ /* puts the directory of its launcher of this program (rxqueue/rxqueue, or */ /* js/rxqueue/rxqueue) first in the PATH of the command; this program, run */ /* by the same RVM, takes the queues from that file and writes them back. */ /* */ /* As ooRexx's rxqueue (utilities/rxqueue/platform/unix/rxqueue.cpp): the */ /* options start with "/" or "-", caseless, one of them; the queue is the */ /* one named, else the one in the environment variable RXQUEUE, else */ /* SESSION. The lines of the standard input go to the queue, FIFO (the */ /* default) or LIFO, one by one; /CLEAR empties it. A line ends at "0a"x, at */ /* "0d"x (and a "0a"x that follows it; another character after a "0d"x is */ /* the first of the next line, whatever it is), and at the end; a "1a"x ends */ /* the input (the line before it is lost, unless it is empty: an empty line */ /* is queued). Only the first 65472 characters of a line are kept. An error */ /* writes its message on the standard output and ends with its code: a bad */ /* invocation (0), a name that is not a valid queue name (5), a queue that */ /* does not exist (9). */ /* */ /* Divergence: the arguments are the words of the program's argument string, */ /* not the shell's words ('a b' is two of them). */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* This file is derived from the ooRexx interpreter: rxqueue (rxqueue.cpp). */ /* It is therefore distributed under the Common Public License v1.0, not */ /* under the Apache License 2.0 that covers the rest of the RVM (see NOTICE). */ /* */ /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */ /* Copyright (c) 2005-2026 Rexx Language Association. All rights reserved. */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* This program and the accompanying materials are made available under the */ /* terms of the Common Public License v1.0 which accompanies this */ /* distribution. A copy is also available at the following address: */ /* https://www.oorexx.org/license.html */ /* */ /******************************************************************************/ Parse Arg arguments mode = "" name = "" Do word Over arguments~makeArray( " " ) If word == "" Then Iterate If Left( word, 1 ) == "/" | Left( word, 1 ) == "-" Then Do option = Upper( SubStr( word, 2 ) ) If mode \== "" | WordPos( option, "FIFO LIFO CLEAR" ) == 0 Then Call Fail 0, name mode = option End Else If name == "" Then name = word Else Call Fail 0, name End If mode == "" Then mode = "FIFO" If name == "" Then name = Value( "RXQUEUE", , "ENVIRONMENT" ) If name == "" Then name = "SESSION" -- RexxQueryQueue: a name that is not valid, a queue that is not there. If Length( name ) > 250 | Length( name ) == 0 Then Call Fail 5, name If Verify( name, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - || "0123456789.!?_" ) > 0 Then Call Fail 5, name If \ .RexxQueue~exists( name ) Then Call Fail 9, name queue = .RexxQueue~new( name ) If mode == "CLEAR" Then Do queue~empty Exit 0 End -- The standard input, all of it, and its lines as get_line makes them. data = .MutableBuffer~new Do Forever chunk = CharIn( , , 65536 ) If chunk == "" Then Leave data~append( chunk ) End data = data~string maxLength = 65472 ends = "0d0a1a"x size = Length( data ) pos = 1 afterCR = 0 Do While pos <= size -- A character after a "0d"x (not a "0a"x) is data, whatever it is. from = pos If afterCR == 1 Then from = pos + 1 afterCR = 0 e = Verify( data, ends, "Match", from ) If e == 0 Then Do Call Add SubStr( data, pos, Min( size - pos + 1, maxLength ) ) Leave End line = SubStr( data, pos, Min( e - pos, maxLength ) ) Select Case SubStr( data, e, 1 ) When "0a"x Then Do Call Add line pos = e + 1 End When "0d"x Then Do Call Add line pos = e + 1 If pos <= size Then Do If SubStr( data, pos, 1 ) == "0a"x Then pos += 1 Else afterCR = 1 End End Otherwise -- "1a"x: the end If line == "" Then Call Add line Leave End End Exit 0 Add: If mode == "LIFO" Then queue~push( Arg( 1 ) ) Else queue~queue( Arg( 1 ) ) Return -- The message of an error, on the standard output, and its code. Fail: Procedure Use Arg code, name Select Case code When 5 Then message = "The name" name "is not a valid queue name." When 9 Then message = "The queue" name "does not exist." Otherwise message = "The syntax of the command is incorrect." End .output~lineOut( message ) Exit code