Welcome to iraf.net Thursday, March 28 2024 @ 09:55 AM GMT


 Forum Index > Help Desk > Applications New Topic Post Reply
 Problems with using cl.ukey in case statement
   
pskoda
 01/12/2010 12:23AM (Read 2277 times)  
++---
Junior

Status: offline


Registered: 12/20/2005
Posts: 23
Hi Mike,several years ago we have discussed the interactive prompting using cl.ukey in loop here:
https://iraf.net/phpBB2/viewtopic.php?p=136735I have written some script using it but today I have realized by a mistake in input that in fact it does not work correctly. After more detailed investigation it seems that there is something strange about the handling of the special characters in the solution you have suggested.I have extracted the core of the logic in following test program[code:1:4ef8e145fe]
1 procedure testukey.cl
2
3 begin
4 string ch
5 for (ch = "c"; ch != "z"; ch = cl.ukey) {
6 if (ch < "a") {
7 print (ch)
8 print ("got a newline")
9 } else {
10 print (ch)
11 switch (ch) {
12 case "?": print ("help for commands here...")
13 case "h": print ("imheader (imname, long+)")
14 case "e": print ("imexamine (imname, 1)")
15 case "d": print ("display (imname, 1, fill+)")
16 case "n": break # next image
17 case "q": goto cleanup
18 case "s": print ("imstat (imname)")
19 }
20 printf ("Command? ")
21 }
22 }
23 print('finishing loop')
24 cleanup:
25 printf("\nfinished \n-------------\n")
26 end
[/code:1:4ef8e145fe]For most letters it works correctly but it does not react to '?' as expected - as it is in ASCII table before 'a' so it is trapped as well as ENTER (\015) and more other codes (it is not desired effect anyway).But when I change the trap condition for characters lower (in ASCII code position) then 'a' the system prints an error when entering
ENTER (\015) and SPACE (\040)After some experiments it seems that the critical boundary is the '\' character - but it may not be put in the test at line 6 (complaining
immediately :[code:1:4ef8e145fe]
ERROR on line 6: Newline while processing string
testukey ()
[/code:1:4ef8e145fe]If giving the ']' character (next higher than backslash)
it works - it prints [code:1:4ef8e145fe]
\015
got a newline
[/code:1:4ef8e145fe]
(for ENTER)or
[code:1:4ef8e145fe]
\040
got a newline
[/code:1:4ef8e145fe]
for SPACE barIf giving the first lower char that backslash - the '[' - it starts to complain[code:1:4ef8e145fe]
c
Command? \015
ERROR on line 26: Illegal switch value.
testukey ()
[/code:1:4ef8e145fe]So it is clean that the condition on line 6 does not trap the special characters and it somehow intrudes the second part after else It does not help even the condition
[code:1:4ef8e145fe]
if (ch =="\015")
[/code:1:4ef8e145fe]Can you explain this strange behaviour ? Is there some solution for trapping fully the control characters (like ENTER SPACE) ?Is there some function in IRAF that would allow to make the scancode number from the ukey input - so I could compare just integer numbers without the strange side effects ?
Thanks Petr Skoda

 
Profile Email
 Quote
fitz
 01/12/2010 12:23AM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
The thing to remember is that the backslash is used as an escape, and so it needs to be escaped itself. Its a kludge, but try something like[code:1:6fb705230a]
begin
char ch while (yes) {
ch = cl.ukey if (substr(ch,1,4) == "\\015") {
print ("do newline")
} else if (substr(ch,1,4) == "\\040") {
print ("do spacebar")
} else {
switch (ch) {
case "q": break
case "a": print ("got an 'a'")
case "?": print ("do help")
case "\\": print ("do backslash")
}
}
}
end
[/code:1:6fb705230a]-Mike

 
Profile Email
 Quote
pskoda
 01/12/2010 12:23AM  
++---
Junior

Status: offline


Registered: 12/20/2005
Posts: 23
Thanks Mike!
It works nicely for me - I did not realize the representation of a scancode is really a normal string - I was thinking about a special treatment of control codes...Petr Skoda

 
Profile Email
 Quote
   
Content generated in: 0.08 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login