Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Real Programmers think better when playing Adventure or Rogue.


programming / comp.lang.tcl / Re: proposal: a command to check if object is an channel and writeable

SubjectAuthor
* proposal: a command to check if object is an channel and writeableaotto1968
+- Re: proposal: a command to check if object is an channel and writeableSchelte
`* Re: proposal: a command to check if object is an channel and writeableRalf Fassel
 `* Re: proposal: a command to check if object is an channel andaotto1968
  `- Re: proposal: a command to check if object is an channel and writeableRalf Fassel

1
Subject: proposal: a command to check if object is an channel and writeable
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 16 May 2022 10:07 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: aotto1...@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: proposal: a command to check if object is an channel and writeable
Date: Mon, 16 May 2022 12:07:10 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <t5t7of$ak5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 16 May 2022 10:07:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c6a38f8014f23a76553d707cb695263";
logging-data="10885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dsHu9dXLrG1dLXsUQ4OEXPiMReap4c4E="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:yZ+NnncbnK448CHWdE83/YoomLE=
Content-Language: en-US
View all headers

hi,

to implement a "puts" like command with:

 > PrintFile ?channel? ....

I require something to check if first argument is a channel and writeable.

I don't have found such a "command" in tcl.

possible command:

 > chan writeable $FH → result boolean yes/no

today I use something like:

# usage: PrintFile ?chan? filename1 filename2 …
proc PrintFile { args } {
   set outH [lindex $args 0]
   if { [ catch { flush $outH } ] } {      set outH stderr    } else {
     set args [lrange $args 1 end]    }
   foreach fn $args {
     set FH [ open $fn r+ ]      puts $outH [read $FH]      close $FH    } }

to test if string is a channel I use "flush $outH" on error


mfg.




Subject: Re: proposal: a command to check if object is an channel and writeable
From: Schelte
Newsgroups: comp.lang.tcl
Organization: KPN B.V.
Date: Mon, 16 May 2022 10:22 UTC
References: 1
Date: Mon, 16 May 2022 12:22:44 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0
Subject: Re: proposal: a command to check if object is an channel and writeable
Content-Language: nl-NL
Newsgroups: comp.lang.tcl
References: <t5t7of$ak5$1@dont-email.me>
From: nos...@wanadoo.nl (Schelte)
In-Reply-To: <t5t7of$ak5$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$4ab91986$745a19b0@2bef9fe6044d259d>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.eu1.usenetexpress.com!94.232.112.244.MISMATCH!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 12
Injection-Date: Mon, 16 May 2022 12:22:44 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
View all headers
On 16/05/2022 12:07, aotto1968 wrote:
I require something to check if first argument is a channel and writeable.

This should work:

if {[catch {chan event $outH writable}]} {
     error "$outH is not a writable channel"
}


Schelte


Subject: Re: proposal: a command to check if object is an channel and writeable
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Mon, 16 May 2022 11:48 UTC
References: 1
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: proposal: a command to check if object is an channel and writeable
Date: Mon, 16 May 2022 13:48:01 +0200
Lines: 24
Message-ID: <ygaa6bhy9zi.fsf@akutech.de>
References: <t5t7of$ak5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net UxPwv9HVOBOFZOqrFh4NcwxzldEvaSqZp8upNmqpFuaB2/Dlw=
Cancel-Lock: sha1:oG++ouE2bMK0wpBUbSd2bHLZfZs= sha1:jiiQgKgwEK0/25TODv4nwL2jfeM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
View all headers
* aotto1968 <aotto1968@t-online.de>
| hi,

| to implement a "puts" like command with:

| > PrintFile ?channel? ....

| I require something to check if first argument is a channel and writeable.

Check whether FH is known as a channel could be
  if {$FH in [chan names]} {
    # FH is a known channel
  }

Check whether FH is Writeable:

  chan pending output $FH
  - returns -1 if FH was not opened for writing

Whether the channel is actually writeable (i.e. does not block on
'puts') depends on too many factors (buffersize, blocking mode etc), so
there is no generic answer.

R'


Subject: Re: proposal: a command to check if object is an channel and writeable
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 17 May 2022 07:53 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: aotto1...@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: proposal: a command to check if object is an channel and
writeable
Date: Tue, 17 May 2022 09:53:29 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <t5vk9p$tbj$1@dont-email.me>
References: <t5t7of$ak5$1@dont-email.me> <ygaa6bhy9zi.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 17 May 2022 07:53:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="bf9d819f708186926df0f4db20ef96c1";
logging-data="30067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AD7lDk9eIQoGo6z0dAOpWGVFEpQhPkQ8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:avmSE8p8FbZqPs2+jIZOjAVbYWI=
In-Reply-To: <ygaa6bhy9zi.fsf@akutech.de>
Content-Language: en-US
View all headers
On 16.05.22 13:48, Ralf Fassel wrote:
* aotto1968 <aotto1968@t-online.de>
| hi,

| to implement a "puts" like command with:

| > PrintFile ?channel? ....

| I require something to check if first argument is a channel and writeable.

Check whether FH is known as a channel could be
   if {$FH in [chan names]} {
     # FH is a known channel
   }

Check whether FH is Writeable:

   chan pending output $FH
   - returns -1 if FH was not opened for writing

Whether the channel is actually writeable (i.e. does not block on
'puts') depends on too many factors (buffersize, blocking mode etc), so
there is no generic answer.

R'

thanks, I understand that real "writeable" is complicated but at least I want distinguish between stdin and stout so that

 > PrintFile stdin …

is not possible

example:

puts stdin aaaaaaaaa
channel "stdin" wasn't opened for writing

→ something check the stdin.

mfg ao


Subject: Re: proposal: a command to check if object is an channel and writeable
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Tue, 17 May 2022 13:20 UTC
References: 1 2 3
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: proposal: a command to check if object is an channel and writeable
Date: Tue, 17 May 2022 15:20:35 +0200
Lines: 27
Message-ID: <yga5ym4xplo.fsf@akutech.de>
References: <t5t7of$ak5$1@dont-email.me> <ygaa6bhy9zi.fsf@akutech.de>
<t5vk9p$tbj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net V1d6uzyrZ4x/Pco5JjIypwNJxGSqFNdNL6NMA4ImqBw2pR2Ws=
Cancel-Lock: sha1:KbdDlZh4NZtabIcy6Cbmmh7BdKk= sha1:EFWQLlKhCTctis7Mp+DvUG/ZMDc=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
View all headers
* aotto1968 <aotto1968@t-online.de>
| thanks, I understand that real "writeable" is complicated but at least
| I want distinguish between stdin and stout so that

| > PrintFile stdin …

| is not possible

| example:

| puts stdin aaaaaaaaa
| channel "stdin" wasn't opened for writing

| → something check the stdin.

    % chan pending output stdin
    -1
    % chan pending output stdout
    0

https://www.tcl.tk/man/tcl/TclCmd/chan.html

   chan pending mode channelId
   --<snip-snip>--
   Returns -1 if  the channel was not opened for the mode in question.

R'


1
rocksolid light 0.7.2
clearneti2ptor