Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat Feb 07, 2009 1:35 am   

Problems using #READ (and %read()) on a file. [Solved]
 
I have a text file which I placed in CMUD's execution folder. I can open the file (using #FILE) with no problem. However, when I try to read the file, I get a back a NULL. This happens when I assign the file to a numbers in the range 1-5. When I assign it to 6, for instance, the read will return a line of garbage.
_________________
Sic itur ad astra.

Last edited by Anaristos on Sun Feb 08, 2009 7:04 pm; edited 2 times in total
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Feb 07, 2009 3:57 am   
 
Are you using a file in slot six that was created by writing to a file in slots 6-10? Those slots use a special record-based file format (the help has more info) and if you open a plain-text file in those slots, you'll get garbage, yes.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat Feb 07, 2009 4:51 am   
 
I opened it in slot 6 to prove to myself that the file could be read. I understand about the garbage. What I was trying to say was that if I open the file in slot 1, for instance, the #READ or %read() will retrieve nothing. I get a NULL back. It doesn't matter, whether, I specify a record number or not. I am supposing that the record markers are not to CMUD's liking, so the question is. What does a CMUD EOR marker looks like?
That would be one place to start looking for the problem. If CMUD's EOR matches the EOR from the file, then that's not the problem.
_________________
Sic itur ad astra.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Feb 07, 2009 5:08 am   
 
Tell me exactly what it is you're doing, pressing, running or whatever to create this file, and then exactly what you're doing to make it not work when you try to read it. At the moment I have no idea if you created this file yourself, if you used slots 1-5 or 6-10, what sort of data you put in it (if any) and I have no idea how you're trying to get it back out. With so little information, I can't really help you.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat Feb 07, 2009 5:48 am   
 
I didn't create the file. The file is a CSV file which I want to use to create a database. I wrote a script that opened the file in slot 1, and attempted to read it record by record, but it never reads anything. The first record has the column list, and the rest of the records have the data for the database file in the form <columndata1>,....,<columndataN> for each row. One row per record. The file was created by MySQL.

EDIT: A CSV file is a text file, so if you are not using it to populate a database there is nothing special about it.
_________________
Sic itur ad astra.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Feb 07, 2009 6:02 am   
 
Okay, you definitely shouldn't be assigning it to slots 6-10 then. CMUD's format for those slots has nothing to do with CSV.

Beyond that, there's no reason why it should return null unless there's something strange about the file - like, say, it has lines ending in only LF or CR and CMUD expects both. Can you post the file somewhere?
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sat Feb 07, 2009 7:11 am   
 
I'm reading a CSV file here just fine. As Fang mentioned, be sure each line ends in a CR and LF character (char 13 and char 10). That's the standard newline for Windows text files. You might try opening the file in some sort of editor that will show you any control codes in the file to see if there is any other problem with it. But CMUD is using CR/LF as the end-of-record line marker. If there is a NULL character (char 0) in the file, that will also cause trouble. But a standard CSV file written from Excel, for example, should work fine.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Sat Feb 07, 2009 4:32 pm   
 
Anaristos wrote:
The file was created by MySQL.

If this was done on a linux based system then the file will definitely not have lines ending with CR LF, I think on linux they just end LF. Anyway there is a program called unix2dos.exe that you can download if you do a web search that will convert the file or if you have a high end text editor like notepad++ or ultraedit it should ask you if you want to convert when you open the file.
_________________
Taz :)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sat Feb 07, 2009 7:46 pm   
 
I loaded the CSV file into notepad++ and it shows that the EOL marker is CRLF. However, the following sample code just echoes NULLs.
Code:

#FILE 1 data.csv
;;
#LOOP 10 {#ECHO %read( 1, %i)}
;;
#CLOSE 1

The following code adds nothing to the stringlist variable:
Code:

#FILE 1 data.csv
;;
#LOOP 10 {csvdump = %additem( %read( 1, %i), @csvdump)}
;;
#CLOSE 1

So obviously I am doing something wrong. I'd appreciate your help.
_________________
Sic itur ad astra.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sun Feb 08, 2009 12:38 am   
 
Can you PM one of us the files so we can try it.
_________________
Asati di tempari!
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Sun Feb 08, 2009 6:37 pm   
 
The documentation for the#FILE command contains the following statement:

The filename given in name is restricted to the current directory containing CMUD.EXE and cannot refer to a EXE, HLP, or MUD file.

This is incorrect. The file must be in the directory that contains the session folders.

I discovered this when I found that CMUD had created a file (of 0 length) in said directory with the same name as the file that I used above. Evidently, if the file doesn't exist, CMUD creates one (which makes sense, if one wants to write to a new file. However, this is not documented).

The appended post by Jed is partly incorrect. He states that the file must be in the directory containing the default package, when in fact, it is the parent directory of the one containing the default package (i.e. The directory containing the Packages directory).
Of course, if one has everything in a single master directory (not recommended for Vista users if they use the default Program Files directory) then this problem won't appear.
_________________
Sic itur ad astra.
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: Sun Feb 08, 2009 7:22 pm   
 
Anaristos wrote:
The file must be in the directory that contain the session folders.

CMUD creates files in the session folder since 2.13, almost 1,5 year from now. And yes, the documentation has not been updated since then. Guess there was no time for that in the beta rush.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Feb 08, 2009 11:46 pm   
 
Fixed.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net