AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   read_file (const file[], line, text[], len, &txtLen); (https://forums.alliedmods.net/showthread.php?t=113636)

Dygear 12-28-2009 21:00

read_file (const file[], line, text[], len, &txtLen);
 
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.

ConnorMcLeod 12-28-2009 21:08

Re: read_file (const file[], line, text[], len, &txtLen);
 
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.

Mxnn 12-28-2009 21:10

Re: read_file (const file[], line, text[], len, &txtLen);
 
PHP Code:

while ((line =(read_file(flpathlinetextlentxtLen)))) 


Arkshine 12-28-2009 21:10

Re: read_file (const file[], line, text[], len, &txtLen);
 
See file.inc, it's new file natives, the same as in C. So better to handle file with them.

Dygear 12-29-2009 01:26

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

Originally Posted by ConnorMcLeod (Post 1034700)
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 (Post 1034703)
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 (Post 1034704)
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.

stupok 12-29-2009 02:21

Re: read_file (const file[], line, text[], len, &txtLen);
 
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

Mxnn 12-29-2009 14:34

Re: read_file (const file[], line, text[], len, &txtLen);
 
With my stuff it works..
If line = 0 (the end of the file) the while breaks.. Try it, it works

ConnorMcLeod 12-29-2009 14:36

Re: read_file (const file[], line, text[], len, &txtLen);
 
It works, but read_file is deprecated.

fysiks 12-29-2009 19:10

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

Originally Posted by Mxnn (Post 1035503)
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.

Dygear 12-31-2009 18:15

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

Originally Posted by ConnorMcLeod (Post 1035507)
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.


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

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