Raised This Month: $ Target: $400
 0% 

read_file (const file[], line, text[], len, &txtLen);


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 12-28-2009 , 21:00   read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #1

The correct way to call this function would be to do this?

PHP Code:
#define file "filename.ext";

// Get File Location.
new cfgdir[256], flpath[256];
get_configsdir(cfgdir255);
format(flpath255"%s/%s"cfgdirfile);
if (
file_exists(flpath) == 1) {
    
// Read From File.
    
new line 0text[128][32], len 32txtLen 32;
    while (
read_file(flpathlinetextlentxtLen) != && line != 128) {
        
text[line] = text;
        
line++;
    }
} else {
    
// Can't Load From File! Throw Warning & Unload Plugin.

The file name limit, and path limit. If I can remember correctly, some Windows installs had a problem with file names over 64 characters, and the path could not be greater then 255 (with the 256'th place holding the zero terminator.) I was wondering if anyone had this information on hand for AMX plugins.

Sources: Microsoft: Path to long error & Joel Spolsky: Back to Basics.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-28-2009 , 21:08   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #2

If you plain to read more than 1 line from a file, use rather :

fopen

fgets // your loop with that native (consider feof)

fclose

Example here, but there are many examples on the forums.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-28-2009 , 21:10   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #3

PHP Code:
while ((line =(read_file(flpathlinetextlentxtLen)))) 

Last edited by Mxnn; 12-29-2009 at 14:43.
Mxnn is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-28-2009 , 21:10   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #4

See file.inc, it's new file natives, the same as in C. So better to handle file with them.
__________________
Arkshine is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 12-29-2009 , 01:26   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
If you plain to read more than 1 line from a file, use rather :

fopen

fgets // your loop with that native (consider feof)

fclose

Example here, but there are many examples on the forums.
Thank you, that was very helpful. Your implementation was very interesting.

Quote:
Originally Posted by Mxnn View Post
PHP Code:
while (line =(read_file(flpathlinetextlentxtLen)) 
Good point. But I should also make sure I don't go over the array limit, buffer overflow, bad. On a side note, I already miss foreach.

Quote:
Originally Posted by Arkshine View Post
See file.inc, it's new file natives, the same as in C. So better to handle file with them.
I have no idea what you mean by that.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
stupok
Veteran Member
Join Date: Feb 2006
Old 12-29-2009 , 02:21   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #6

arkshine means file.inc, one of the files inside the include folder (amxmodx/scripting/include)

The file contains the "new" file natives. They are just newer than read_file() and such, not really new anymore.

You can also look up the functions on amxmodx.org:
http://www.amxmodx.org/funcwiki.php?go=inc&id=3
__________________
stupok is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-29-2009 , 14:34   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #7

With my stuff it works..
If line = 0 (the end of the file) the while breaks.. Try it, it works
Mxnn is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-29-2009 , 14:36   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #8

It works, but read_file is deprecated.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-29-2009 , 19:10   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #9

Quote:
Originally Posted by Mxnn View Post
With my stuff it works..
If line = 0 (the end of the file) the while breaks.. Try it, it works
As Connor implied, you should prefer the newer file natives.
__________________
fysiks is offline
Dygear
SourceMod Donor
Join Date: Apr 2004
Location: Levittown, NY
Old 12-31-2009 , 18:15   Re: read_file (const file[], line, text[], len, &txtLen);
Reply With Quote #10

Quote:
Originally Posted by ConnorMcLeod View Post
It works, but read_file is deprecated.
Thank you, I did not know that. I'll be sure to poke around the file.inc and see what's in vogue.
__________________
Dygear is offline
Send a message via AIM to Dygear Send a message via MSN to Dygear Send a message via Skype™ to Dygear
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode