Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 put chars(n) bug?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dan




PostPosted: Fri Jun 02, 2006 6:25 pm   Post subject: put chars(n) bug?

Hello my name is Hacker Dan and this is my 1st post asking for turing help Razz

Anyhow last night for some reason i was working on an API (module) for turing that whould allow for access, use and comincation with MySql servers.

In theroy it should work, since all you have to do is fallow the MySql protical and make shure to tell the server that we do not suport SSL or any other nice secruity features. And i did get it partly working in that i could get the servers infromation and start talking to it.

But this is where the problem came in....the mysql protical needs some staments to be null termated with a value of 0. As some of you know packets are mainly a colection of chars witch can either repersent there ascii repersation or there numerical value. Turings method to output a packet is using it's put method and a netStream.

So far every thing was good, i started by making a char array witch most langs use with there net output methods but then i found out that turings put staments can not output a char array made by somthing like var somearray: array 1..5 of char. So my next thougth was a string, but as i found out in a few seconds that whould not work since some values that need to be sent are like chr(0) with whould termante the string and give an error in turing.

So i came to the right soltion witch was the char(n) type. Witch realy is just a char array that is recgovized as such by turings put and get stamnets and can be used with strings and chars.

Now as the turing documation says:

tom west wrote:

Values of the char(n) type can be read and written by get and put statements.


Now to me this means that i can out a char(n) value with a put statment but apreantly that is not the case. For example this code:

code:

var test:char(4) := 'dan'
put "-",test,"-"


Out puts "- -". It replaces every char in the char(n) with chr(20) (witch is a white space). Also when i used it with netsteams and put it outed a packet of white spaces rather then what is in the char(n).

Now i know that the data in the char(n) is there becuases you can do a put test(1) and it will output a 'd'. So whats going on here?

Is outputing a char(n) with put bugged in turing? or am i missing somthing?

I have tested this with turing 4.1 and 4.0.4 and both have the same issue, witch makes compicated net comincations imposiable. I whould e-mail tom west about this but that never goses over well.[/code]
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Fri Jun 02, 2006 7:53 pm   Post subject: (No subject)

The comma isn't going to work. You gotta use the + sign to join togther strings, chars, and char(n). So it would look something like this:
code:
var test:char(3) := 'dan'
put "-" + test + "-"

However, when I tried to output the char(n) by itself, it wouldn't show up. I don't know why that is. It seems only to work if you include the char(n) with other chars or strings. So if you wanted the char(n) to show by itself, you would need something like:
code:
put "" + test

However, in Java this type of command automatically typecasts the test to a String object, and I don't know if Turing does the same.
Dan




PostPosted: Fri Jun 02, 2006 8:35 pm   Post subject: (No subject)

I don't think you understand the problem. I need to out put a char(n) type not a string type.

Using + will conver the char(n) to a string. This will not work since it is not a string we are trying to output but an array of chars.

How this differs is that a char array CAN HAVE a chr(0) charticher well if you where to try to do this in a string it whould cause an error.

See this example for why a string type will not work:

code:

var test:char(4) := 'dan_'
test(4) := chr(0)

put "-" + test + "-"
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
[Gandalf]




PostPosted: Fri Jun 02, 2006 10:12 pm   Post subject: Re: put chars(n) bug?

Hacker Dan wrote:
Hello my name is Hacker Dan and this is my 1st post asking for turing help Razz

Oh my! Surprised

Hmm... Interesting problem. I can't say that I've worked with variables of type char(n) much, but here are some alternatives you might try:
1. You can work with string data throughout the program, and on the recieving end concatenate a '\0' to it. This is a bit arduous though, so..
2. You can use an array of characters and send that through the net stream every time, and create your own output function which just puts every character in that array while in Turing:
code:
proc print (str : char (*))
    for i : 1 .. upper (str)
        put str (i) ..
    end for
end print
var test : char (4) := 'dan\0'
print (test)

3. You can use the char(n) approach, and when outputting the variable, ignore the null character:
code:
var test : char (4) := 'dan\0'
put "-", test (1 .. 3), "-"


Hope at least one of these solves the problem, good luck with this little project. Smile
Dan




PostPosted: Sat Jun 03, 2006 12:05 am   Post subject: Re: put chars(n) bug?

[Gandalf] wrote:
1. You can work with string data throughout the program, and on the recieving end concatenate a '\0' to it. This is a bit arduous though, so..


Any time and i mean any time in turing you have a chr(0) in a string, try to add it to a string or do anything with it and a string it generates an error.

[Gandalf] wrote:

2. You can use an array of characters and send that through the net stream every time, and create your own output function which just puts every character in that array while in Turing:
code:
proc print (str : char (*))
    for i : 1 .. upper (str)
        put str (i) ..
    end for
end print
var test : char (4) := 'dan\0'
print (test)



I was thinking about somthing like this but dose .. work on a netSteram? This all has to be in one packet affter all. I will do some tests and see if it sends it has many packets or just one.

[Gandalf] wrote:

3. You can use the char(n) approach, and when outputting the variable, ignore the null character:
code:
var test : char (4) := 'dan\0'
put "-", test (1 .. 3), "-"



The chr(0) is part of the mysql protical, it is used for null termanting stametens as well as giving a value of 0. Simpley it has to be sent.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
[Gandalf]




PostPosted: Sat Jun 03, 2006 12:18 am   Post subject: Re: put chars(n) bug?

Hacker Dan wrote:
Any time and i mean any time in turing you have a chr(0) in a string, try to add it to a string or do anything with it and a string it generates an error.

Indeed, but in this case you wouldn't be adding the chr(0) to the string in Turing, you would be doing it on the recieving end (ie. the MySQL server).

Hacker Dan wrote:
I was thinking about somthing like this but dose .. work on a netSteram? This all has to be in one packet affter all. I will do some tests and see if it sends it has many packets or just one.

I'm not sure, you'll have to try it out, but if a chr(n) is indeed just an array of characters then it will have to send every element of the array, including the null character. If not, then I don't think there's much to do about it since it's sending each element in a seperate packet. Another possibility for this solution is to use a real array:
code:
proc print (str : array 1 .. * of char)
    for i : 1 .. upper (str)
        put str (i) ..
    end for
end print
var test : array 1 .. * of char := init ('d', 'a', 'n', '\0')
print (test)

Though I'm not sure that'll make any difference.

Hacker Dan wrote:
The chr(0) is part of the mysql protical, it is used for null termanting stametens as well as giving a value of 0. Simpley it has to be sent.

In this example, you would be sending the full test variable to the stream, because you need the null character, but you would only be excluding the null character when outputting to Turing. I'm pretty sure this is what you are asking, though I'm not certain.
Dan




PostPosted: Sat Jun 03, 2006 12:28 am   Post subject: Re: put chars(n) bug?

[Gandalf] wrote:
Hacker Dan wrote:
Any time and i mean any time in turing you have a chr(0) in a string, try to add it to a string or do anything with it and a string it generates an error.

Indeed, but in this case you wouldn't be adding the chr(0) to the string in Turing, you would be doing it on the recieving end (ie. the MySQL server).


Ummm.....i do not think MySql servers are open sorce and even if they where that whould mean it whould only work with my MySql server and it whould not realy be a MySql server any more....

The idea is to make an API in turing to talk to a noraml MySql server not make a new MySql server....

Quote:

Hacker Dan wrote:
I was thinking about somthing like this but dose .. work on a netSteram? This all has to be in one packet affter all. I will do some tests and see if it sends it has many packets or just one.

I'm not sure, you'll have to try it out, but if a chr(n) is indeed just an array of characters then it will have to send every element of the array, including the null character. If not, then I don't think there's much to do about it since it's sending each element in a seperate packet. Another possibility for this solution is to use a real array:
code:
proc print (str : array 1 .. * of char)
    for i : 1 .. upper (str)
        put str (i) ..
    end for
end print
var test : array 1 .. * of char := init ('d', 'a', 'n', '\0')
print (test)

Though I'm not sure that'll make any difference.


I just tested this and it sends 1 packet for each char in the char(n) witch is very bad and dose not work at all. 1 packet has to conatian the hole char(n) or it simmpley will not work as it is not fallowing the mysql protical.

Quote:

Hacker Dan wrote:
The chr(0) is part of the mysql protical, it is used for null termanting stametens as well as giving a value of 0. Simpley it has to be sent.

In this example, you would be sending the full test variable to the stream, because you need the null character, but you would only be excluding the null character when outputting to Turing. I'm pretty sure this is what you are asking, though I'm not certain.


How whould geting ride of any part of the protical that is 0 work? The problem is not that i am geting 0s but that i can not send them.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
[Gandalf]




PostPosted: Sat Jun 03, 2006 12:39 am   Post subject: Re: put chars(n) bug?

Hacker Dan wrote:
Ummm.....i do not think MySql servers are open sorce and even if they where that whould mean it whould only work with my MySql server and it whould not realy be a MySql server any more....

The idea is to make an API in turing to talk to a noraml MySql server not make a new MySql server....

Alright, sorry, but I know next to nothing about MySQL. Wink

Hacker Dan wrote:
I just tested this and it sends 1 packet for each char in the char(n) witch is very bad and dose not work at all. 1 packet has to conatian the hole char(n) or it simmpley will not work as it is not fallowing the mysql protical.

Same with the array of chars? I'm afraid that's your only option as far as I am aware... If you can't send an array of characters or a var of type char(n) as one packet, and you can't use a string to send it in one packet, then I don't think you're left with very many options.

Hacker Dan wrote:
How whould geting ride of any part of the protical that is 0 work? The problem is not that i am geting 0s but that i can not send them.

Ahh, I thought you wanted it to be able to be outputted onto the screen in Turing properly, not to the net stream. It shouldn't give you an error sending a variable of type char(n) to a net stream, does it? Confused
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sat Jun 03, 2006 12:55 am   Post subject: (No subject)

The main point being: You asked if you could use put on char(n) in Turing, but that won't help since it sends each character as a seperate packet. Therefore you have a problem which you can't really do much about. Wink
Dan




PostPosted: Sat Jun 03, 2006 2:26 am   Post subject: (No subject)

[Gandalf] wrote:
The main point being: You asked if you could use put on char(n) in Turing, but that won't help since it sends each character as a seperate packet. Therefore you have a problem which you can't really do much about. Wink


Well put char(n) dose not put each one in a difrent packet it sends n white spaces. And my question was is this a bug or am i using it wrong Wink

The awswer as far as i can see is that it is a bug Razz

Thanks for trying tho, i am very dispointed in turing for this one. It means now that not everything is posiable in turing.

I will keep sreach for work arounds tho....
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
[Gandalf]




PostPosted: Sat Jun 03, 2006 4:53 pm   Post subject: (No subject)

No problem, it's too bad none of those works in practice...

Here's one last quick effort, if this doesn't work then I'm out of ideas.
What would happen if you sent just a normal string with the \0 in text? I'm far from sure, but it might get interpreted by the MySQL server as a null character. For example:
code:
put "dan\\0" % or in your code...
put : netStream, "dan\\0"

This would really be sending the \ and the 0 as two different characters, which is why I'm doubting it'll work, but in theory it would still create a null character. Maybe. Don't know, though it's worth one final try. Smile
Dan




PostPosted: Sat Jun 03, 2006 9:51 pm   Post subject: (No subject)

Good idea but it will not work as it will send then ascii value of '\' and the ascii value of '0'.

I also tryed using the cheat function/keyword and was able to get it to aucatly output a string with a null in it but as string nioramly dose it stops at the null char and stops sending.

Simpley this bug makes complicated proticals in turing imposibale.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: