From 8ef66cee8ccb600510ac8ec39a6e7c5fdca957d7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 3 Apr 2004 20:05:27 +0000 Subject: [PATCH] added natives --- plugins/include/file.inc | 48 +++++++++++++++++++++++++++++++++++++- plugins/include/string.inc | 4 ++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/plugins/include/file.inc b/plugins/include/file.inc index da0c6eb6..a32cad70 100755 --- a/plugins/include/file.inc +++ b/plugins/include/file.inc @@ -32,4 +32,50 @@ native file_exists(const file[]); * When flag is set to 1 returns number of lines in the file, * and when flags is 2, function returns 1 if the file ends * with line feed. If file doesn't exist returns -1. */ -native file_size(const file[], flag=0); \ No newline at end of file +native file_size(const file[], flag=0); + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +// These are C style file access functions +// Code ported from Sanji's File module + +//Open a file +native fopen(filename[],mode[]); +//Close a file +native fclose(file); +//Read a file for ret_size length +native fread(file,ret[],ret_size); +//Write a file +native fwrite(file,const str[],{Float,_}:...); +//Check if at the end of a file +native feof(file); +//Seek a file +native fseek(file,pos,type); +//Rewind a file (reset) +native rewind(file); +//Flush a file +native fflush(file); +//Scan a file by a format +native fscanf(file,const str[],{Float,_}:...); +//Returns the current file position pointer +native ftell(file); +//Return the size of a file +native filesize(const filename[],{Float,_}:...); +//Delete a file (delete_file macro) +native unlink(const filename[],{Float,_}:...); + +//These are type specific file getting and writing commands: +//c=char, s=short, l=long, i=int, f=float +native fgetc(file); //read char (size 1) +native fgets(file); //read short (size 2) +native fgetl(file); //read long (size 4) +native fgeti(file); //read int (size 4) +native Float:fgetf(file); //read float (size 4) + +native fputc(file,num); //write char (size 1) +native fputs(file,num); //write short (size 2) +native fputl(file,num); //write long (size 4) +native fputi(file,num); //write int (size 4) +native fputf(file,Float:num); //write float (size 4) \ No newline at end of file diff --git a/plugins/include/string.inc b/plugins/include/string.inc index cafc0291..0dc0af42 100755 --- a/plugins/include/string.inc +++ b/plugins/include/string.inc @@ -71,8 +71,8 @@ native parse(const text[], ... ); (A left side and right side of the string) Example: to split text: "^"This is^" the best year", split(text, arg1, len1, arg2, len2) - arg1="^"This is^"", arg2="the best year" - This more useful than parse() because you can keep breaking + arg1="This is", arg2=the best year + This is more useful than parse() because you can keep breaking any number of arguments */ native strbreak(const text[], Left[], leftLen, Right[], rightLen);