mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-29 05:11:00 +00:00
@@ -1617,7 +1617,7 @@ Perl6:
|
|||||||
Pike:
|
Pike:
|
||||||
type: programming
|
type: programming
|
||||||
color: "#066ab2"
|
color: "#066ab2"
|
||||||
lexer: C
|
lexer: Pike
|
||||||
extensions:
|
extensions:
|
||||||
- .pike
|
- .pike
|
||||||
- .pmod
|
- .pmod
|
||||||
|
|||||||
@@ -440,6 +440,10 @@
|
|||||||
".php",
|
".php",
|
||||||
".script!"
|
".script!"
|
||||||
],
|
],
|
||||||
|
"Pike": [
|
||||||
|
".pike",
|
||||||
|
".pmod"
|
||||||
|
],
|
||||||
"Pod": [
|
"Pod": [
|
||||||
".pod"
|
".pod"
|
||||||
],
|
],
|
||||||
@@ -769,8 +773,8 @@
|
|||||||
"exception.zep.php"
|
"exception.zep.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"tokens_total": 641416,
|
"tokens_total": 643251,
|
||||||
"languages_total": 834,
|
"languages_total": 836,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
"ABAP": {
|
"ABAP": {
|
||||||
"*/**": 1,
|
"*/**": 1,
|
||||||
@@ -53143,6 +53147,258 @@
|
|||||||
"config": 3,
|
"config": 3,
|
||||||
"application": 2
|
"application": 2
|
||||||
},
|
},
|
||||||
|
"Pike": {
|
||||||
|
"#pike": 2,
|
||||||
|
"__REAL_VERSION__": 2,
|
||||||
|
"constant": 13,
|
||||||
|
"Generic": 1,
|
||||||
|
"__builtin.GenericError": 1,
|
||||||
|
";": 149,
|
||||||
|
"Index": 1,
|
||||||
|
"__builtin.IndexError": 1,
|
||||||
|
"BadArgument": 1,
|
||||||
|
"__builtin.BadArgumentError": 1,
|
||||||
|
"Math": 1,
|
||||||
|
"__builtin.MathError": 1,
|
||||||
|
"Resource": 1,
|
||||||
|
"__builtin.ResourceError": 1,
|
||||||
|
"Permission": 1,
|
||||||
|
"__builtin.PermissionError": 1,
|
||||||
|
"Decode": 1,
|
||||||
|
"__builtin.DecodeError": 1,
|
||||||
|
"Cpp": 1,
|
||||||
|
"__builtin.CppError": 1,
|
||||||
|
"Compilation": 1,
|
||||||
|
"__builtin.CompilationError": 1,
|
||||||
|
"MasterLoad": 1,
|
||||||
|
"__builtin.MasterLoadError": 1,
|
||||||
|
"ModuleLoad": 1,
|
||||||
|
"__builtin.ModuleLoadError": 1,
|
||||||
|
"//": 85,
|
||||||
|
"Returns": 2,
|
||||||
|
"an": 2,
|
||||||
|
"Error": 2,
|
||||||
|
"object": 5,
|
||||||
|
"for": 1,
|
||||||
|
"any": 1,
|
||||||
|
"argument": 2,
|
||||||
|
"it": 2,
|
||||||
|
"receives.": 1,
|
||||||
|
"If": 1,
|
||||||
|
"the": 4,
|
||||||
|
"already": 1,
|
||||||
|
"is": 2,
|
||||||
|
"or": 1,
|
||||||
|
"empty": 1,
|
||||||
|
"does": 1,
|
||||||
|
"nothing.": 1,
|
||||||
|
"mkerror": 1,
|
||||||
|
"(": 218,
|
||||||
|
"mixed": 8,
|
||||||
|
"error": 14,
|
||||||
|
")": 218,
|
||||||
|
"{": 51,
|
||||||
|
"if": 35,
|
||||||
|
"UNDEFINED": 1,
|
||||||
|
"return": 41,
|
||||||
|
"objectp": 1,
|
||||||
|
"&&": 2,
|
||||||
|
"-": 50,
|
||||||
|
"is_generic_error": 1,
|
||||||
|
"arrayp": 2,
|
||||||
|
"Error.Generic": 3,
|
||||||
|
"@error": 1,
|
||||||
|
"stringp": 1,
|
||||||
|
"sprintf": 3,
|
||||||
|
"}": 51,
|
||||||
|
"A": 2,
|
||||||
|
"string": 20,
|
||||||
|
"wrapper": 1,
|
||||||
|
"that": 1,
|
||||||
|
"pretends": 1,
|
||||||
|
"to": 7,
|
||||||
|
"be": 3,
|
||||||
|
"a": 6,
|
||||||
|
"@": 36,
|
||||||
|
"[": 45,
|
||||||
|
"Stdio.File": 32,
|
||||||
|
"]": 45,
|
||||||
|
"in": 1,
|
||||||
|
"addition": 1,
|
||||||
|
"some": 1,
|
||||||
|
"features": 1,
|
||||||
|
"of": 3,
|
||||||
|
"Stdio.FILE": 4,
|
||||||
|
"object.": 2,
|
||||||
|
"This": 1,
|
||||||
|
"can": 2,
|
||||||
|
"used": 1,
|
||||||
|
"distinguish": 1,
|
||||||
|
"FakeFile": 3,
|
||||||
|
"from": 1,
|
||||||
|
"real": 1,
|
||||||
|
"is_fake_file": 1,
|
||||||
|
"protected": 12,
|
||||||
|
"data": 34,
|
||||||
|
"int": 31,
|
||||||
|
"ptr": 27,
|
||||||
|
"r": 10,
|
||||||
|
"w": 6,
|
||||||
|
"mtime": 4,
|
||||||
|
"function": 21,
|
||||||
|
"read_cb": 5,
|
||||||
|
"read_oob_cb": 5,
|
||||||
|
"write_cb": 5,
|
||||||
|
"write_oob_cb": 5,
|
||||||
|
"close_cb": 5,
|
||||||
|
"@seealso": 33,
|
||||||
|
"close": 2,
|
||||||
|
"void": 25,
|
||||||
|
"|": 14,
|
||||||
|
"direction": 5,
|
||||||
|
"lower_case": 2,
|
||||||
|
"||": 2,
|
||||||
|
"cr": 2,
|
||||||
|
"has_value": 4,
|
||||||
|
"cw": 2,
|
||||||
|
"@decl": 1,
|
||||||
|
"create": 3,
|
||||||
|
"type": 11,
|
||||||
|
"pointer": 1,
|
||||||
|
"_data": 3,
|
||||||
|
"_ptr": 2,
|
||||||
|
"time": 3,
|
||||||
|
"else": 5,
|
||||||
|
"make_type_str": 3,
|
||||||
|
"+": 19,
|
||||||
|
"dup": 2,
|
||||||
|
"this_program": 3,
|
||||||
|
"Always": 3,
|
||||||
|
"returns": 4,
|
||||||
|
"errno": 2,
|
||||||
|
"size": 3,
|
||||||
|
"and": 1,
|
||||||
|
"creation": 1,
|
||||||
|
"string.": 2,
|
||||||
|
"Stdio.Stat": 3,
|
||||||
|
"stat": 1,
|
||||||
|
"st": 6,
|
||||||
|
"sizeof": 21,
|
||||||
|
"ctime": 1,
|
||||||
|
"atime": 1,
|
||||||
|
"line_iterator": 2,
|
||||||
|
"String.SplitIterator": 3,
|
||||||
|
"trim": 2,
|
||||||
|
"id": 3,
|
||||||
|
"query_id": 2,
|
||||||
|
"set_id": 2,
|
||||||
|
"_id": 2,
|
||||||
|
"read_function": 2,
|
||||||
|
"nbytes": 2,
|
||||||
|
"lambda": 1,
|
||||||
|
"read": 3,
|
||||||
|
"peek": 2,
|
||||||
|
"float": 1,
|
||||||
|
"timeout": 1,
|
||||||
|
"query_address": 2,
|
||||||
|
"is_local": 1,
|
||||||
|
"len": 4,
|
||||||
|
"not_all": 1,
|
||||||
|
"<": 3,
|
||||||
|
"start": 1,
|
||||||
|
"zero_type": 1,
|
||||||
|
"start..ptr": 1,
|
||||||
|
"gets": 2,
|
||||||
|
"ret": 7,
|
||||||
|
"sscanf": 1,
|
||||||
|
"getchar": 2,
|
||||||
|
"c": 4,
|
||||||
|
"catch": 1,
|
||||||
|
"unread": 2,
|
||||||
|
"s": 5,
|
||||||
|
"..ptr": 2,
|
||||||
|
"ptr..": 1,
|
||||||
|
"seek": 2,
|
||||||
|
"pos": 8,
|
||||||
|
"mult": 2,
|
||||||
|
"add": 2,
|
||||||
|
"pos*mult": 1,
|
||||||
|
"strlen": 2,
|
||||||
|
"sync": 2,
|
||||||
|
"tell": 2,
|
||||||
|
"truncate": 2,
|
||||||
|
"length": 2,
|
||||||
|
"..length": 1,
|
||||||
|
"write": 2,
|
||||||
|
"array": 1,
|
||||||
|
"str": 12,
|
||||||
|
"...": 2,
|
||||||
|
"extra": 2,
|
||||||
|
"str*": 1,
|
||||||
|
"@extra": 1,
|
||||||
|
"..": 1,
|
||||||
|
"set_blocking": 3,
|
||||||
|
"set_blocking_keep_callbacks": 3,
|
||||||
|
"set_nonblocking": 1,
|
||||||
|
"rcb": 2,
|
||||||
|
"wcb": 2,
|
||||||
|
"ccb": 2,
|
||||||
|
"rocb": 2,
|
||||||
|
"wocb": 2,
|
||||||
|
"set_nonblocking_keep_callbacks": 1,
|
||||||
|
"set_close_callback": 2,
|
||||||
|
"cb": 10,
|
||||||
|
"set_read_callback": 2,
|
||||||
|
"set_read_oob_callback": 2,
|
||||||
|
"set_write_callback": 2,
|
||||||
|
"set_write_oob_callback": 2,
|
||||||
|
"query_close_callback": 2,
|
||||||
|
"query_read_callback": 2,
|
||||||
|
"query_read_oob_callback": 2,
|
||||||
|
"query_write_callback": 2,
|
||||||
|
"query_write_oob_callback": 2,
|
||||||
|
"_sprintf": 1,
|
||||||
|
"t": 2,
|
||||||
|
"casted": 1,
|
||||||
|
"cast": 1,
|
||||||
|
"switch": 1,
|
||||||
|
"case": 2,
|
||||||
|
"this": 5,
|
||||||
|
"Sizeof": 1,
|
||||||
|
"on": 1,
|
||||||
|
"its": 1,
|
||||||
|
"contents.": 1,
|
||||||
|
"_sizeof": 1,
|
||||||
|
"@ignore": 1,
|
||||||
|
"#define": 1,
|
||||||
|
"NOPE": 20,
|
||||||
|
"X": 2,
|
||||||
|
"args": 1,
|
||||||
|
"#X": 1,
|
||||||
|
"assign": 1,
|
||||||
|
"async_connect": 1,
|
||||||
|
"connect": 1,
|
||||||
|
"connect_unix": 1,
|
||||||
|
"open": 1,
|
||||||
|
"open_socket": 1,
|
||||||
|
"pipe": 1,
|
||||||
|
"tcgetattr": 1,
|
||||||
|
"tcsetattr": 1,
|
||||||
|
"dup2": 1,
|
||||||
|
"lock": 1,
|
||||||
|
"We": 4,
|
||||||
|
"could": 4,
|
||||||
|
"implement": 4,
|
||||||
|
"mode": 1,
|
||||||
|
"proxy": 1,
|
||||||
|
"query_fd": 1,
|
||||||
|
"read_oob": 1,
|
||||||
|
"set_close_on_exec": 1,
|
||||||
|
"set_keepalive": 1,
|
||||||
|
"trylock": 1,
|
||||||
|
"write_oob": 1,
|
||||||
|
"@endignore": 1
|
||||||
|
},
|
||||||
"Pod": {
|
"Pod": {
|
||||||
"Id": 1,
|
"Id": 1,
|
||||||
"contents.pod": 1,
|
"contents.pod": 1,
|
||||||
@@ -69384,6 +69640,7 @@
|
|||||||
"Perl": 17979,
|
"Perl": 17979,
|
||||||
"Perl6": 372,
|
"Perl6": 372,
|
||||||
"PHP": 20724,
|
"PHP": 20724,
|
||||||
|
"Pike": 1835,
|
||||||
"Pod": 658,
|
"Pod": 658,
|
||||||
"PogoScript": 250,
|
"PogoScript": 250,
|
||||||
"PostScript": 107,
|
"PostScript": 107,
|
||||||
@@ -69579,6 +69836,7 @@
|
|||||||
"Perl": 15,
|
"Perl": 15,
|
||||||
"Perl6": 3,
|
"Perl6": 3,
|
||||||
"PHP": 9,
|
"PHP": 9,
|
||||||
|
"Pike": 2,
|
||||||
"Pod": 1,
|
"Pod": 1,
|
||||||
"PogoScript": 1,
|
"PogoScript": 1,
|
||||||
"PostScript": 1,
|
"PostScript": 1,
|
||||||
@@ -69647,5 +69905,5 @@
|
|||||||
"Zephir": 5,
|
"Zephir": 5,
|
||||||
"Zimpl": 1
|
"Zimpl": 1
|
||||||
},
|
},
|
||||||
"md5": "3d4fd4559b0894a35d55efc3986095f8"
|
"md5": "dac5efdbb630ce51506df095cd2a6e40"
|
||||||
}
|
}
|
||||||
38
samples/Pike/Error.pmod
Normal file
38
samples/Pike/Error.pmod
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pike __REAL_VERSION__
|
||||||
|
|
||||||
|
constant Generic = __builtin.GenericError;
|
||||||
|
|
||||||
|
constant Index = __builtin.IndexError;
|
||||||
|
|
||||||
|
constant BadArgument = __builtin.BadArgumentError;
|
||||||
|
|
||||||
|
constant Math = __builtin.MathError;
|
||||||
|
|
||||||
|
constant Resource = __builtin.ResourceError;
|
||||||
|
|
||||||
|
constant Permission = __builtin.PermissionError;
|
||||||
|
|
||||||
|
constant Decode = __builtin.DecodeError;
|
||||||
|
|
||||||
|
constant Cpp = __builtin.CppError;
|
||||||
|
|
||||||
|
constant Compilation = __builtin.CompilationError;
|
||||||
|
|
||||||
|
constant MasterLoad = __builtin.MasterLoadError;
|
||||||
|
|
||||||
|
constant ModuleLoad = __builtin.ModuleLoadError;
|
||||||
|
|
||||||
|
//! Returns an Error object for any argument it receives. If the
|
||||||
|
//! argument already is an Error object or is empty, it does nothing.
|
||||||
|
object mkerror(mixed error)
|
||||||
|
{
|
||||||
|
if (error == UNDEFINED)
|
||||||
|
return error;
|
||||||
|
if (objectp(error) && error->is_generic_error)
|
||||||
|
return error;
|
||||||
|
if (arrayp(error))
|
||||||
|
return Error.Generic(@error);
|
||||||
|
if (stringp(error))
|
||||||
|
return Error.Generic(error);
|
||||||
|
return Error.Generic(sprintf("%O", error));
|
||||||
|
}
|
||||||
360
samples/Pike/FakeFile.pike
Normal file
360
samples/Pike/FakeFile.pike
Normal file
@@ -0,0 +1,360 @@
|
|||||||
|
#pike __REAL_VERSION__
|
||||||
|
|
||||||
|
//! A string wrapper that pretends to be a @[Stdio.File] object
|
||||||
|
//! in addition to some features of a @[Stdio.FILE] object.
|
||||||
|
|
||||||
|
|
||||||
|
//! This constant can be used to distinguish a FakeFile object
|
||||||
|
//! from a real @[Stdio.File] object.
|
||||||
|
constant is_fake_file = 1;
|
||||||
|
|
||||||
|
protected string data;
|
||||||
|
protected int ptr;
|
||||||
|
protected int(0..1) r;
|
||||||
|
protected int(0..1) w;
|
||||||
|
protected int mtime;
|
||||||
|
|
||||||
|
protected function read_cb;
|
||||||
|
protected function read_oob_cb;
|
||||||
|
protected function write_cb;
|
||||||
|
protected function write_oob_cb;
|
||||||
|
protected function close_cb;
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->close()]
|
||||||
|
int close(void|string direction) {
|
||||||
|
direction = lower_case(direction||"rw");
|
||||||
|
int cr = has_value(direction, "r");
|
||||||
|
int cw = has_value(direction, "w");
|
||||||
|
|
||||||
|
if(cr) {
|
||||||
|
r = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cw) {
|
||||||
|
w = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Close callback
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @decl void create(string data, void|string type, void|int pointer)
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->create()]
|
||||||
|
void create(string _data, void|string type, int|void _ptr) {
|
||||||
|
if(!_data) error("No data string given to FakeFile.\n");
|
||||||
|
data = _data;
|
||||||
|
ptr = _ptr;
|
||||||
|
mtime = time();
|
||||||
|
if(type) {
|
||||||
|
type = lower_case(type);
|
||||||
|
if(has_value(type, "r"))
|
||||||
|
r = 1;
|
||||||
|
if(has_value(type, "w"))
|
||||||
|
w = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
r = w = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string make_type_str() {
|
||||||
|
string type = "";
|
||||||
|
if(r) type += "r";
|
||||||
|
if(w) type += "w";
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->dup()]
|
||||||
|
this_program dup() {
|
||||||
|
return this_program(data, make_type_str(), ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Always returns 0.
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->errno()]
|
||||||
|
int errno() { return 0; }
|
||||||
|
|
||||||
|
//! Returns size and the creation time of the string.
|
||||||
|
Stdio.Stat stat() {
|
||||||
|
Stdio.Stat st = Stdio.Stat();
|
||||||
|
st->size = sizeof(data);
|
||||||
|
st->mtime=st->ctime=mtime;
|
||||||
|
st->atime=time();
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->line_iterator()]
|
||||||
|
String.SplitIterator line_iterator(int|void trim) {
|
||||||
|
if(trim)
|
||||||
|
return String.SplitIterator( data-"\r", '\n' );
|
||||||
|
return String.SplitIterator( data, '\n' );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected mixed id;
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_id()]
|
||||||
|
mixed query_id() { return id; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_id()]
|
||||||
|
void set_id(mixed _id) { id = _id; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->read_function()]
|
||||||
|
function(:string) read_function(int nbytes) {
|
||||||
|
return lambda() { return read(nbytes); };
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->peek()]
|
||||||
|
int(-1..1) peek(int|float|void timeout) {
|
||||||
|
if(!r) return -1;
|
||||||
|
if(ptr >= sizeof(data)) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Always returns 0.
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_address()]
|
||||||
|
string query_address(void|int(0..1) is_local) { return 0; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->read()]
|
||||||
|
string read(void|int(0..) len, void|int(0..1) not_all) {
|
||||||
|
if(!r) return 0;
|
||||||
|
if (len < 0) error("Cannot read negative number of characters.\n");
|
||||||
|
int start=ptr;
|
||||||
|
ptr += len;
|
||||||
|
if(zero_type(len) || ptr>sizeof(data))
|
||||||
|
ptr = sizeof(data);
|
||||||
|
|
||||||
|
// FIXME: read callback
|
||||||
|
return data[start..ptr-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.FILE()->gets()]
|
||||||
|
string gets() {
|
||||||
|
if(!r) return 0;
|
||||||
|
string ret;
|
||||||
|
sscanf(data,"%*"+(string)ptr+"s%[^\n]",ret);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
ptr+=sizeof(ret)+1;
|
||||||
|
if(ptr>sizeof(data))
|
||||||
|
{
|
||||||
|
ptr=sizeof(data);
|
||||||
|
if(!sizeof(ret))
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: read callback
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.FILE()->getchar()]
|
||||||
|
int getchar() {
|
||||||
|
if(!r) return 0;
|
||||||
|
int c;
|
||||||
|
if(catch(c=data[ptr]))
|
||||||
|
c=-1;
|
||||||
|
else
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
// FIXME: read callback
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.FILE()->unread()]
|
||||||
|
void unread(string s) {
|
||||||
|
if(!r) return;
|
||||||
|
if(data[ptr-sizeof(s)..ptr-1]==s)
|
||||||
|
ptr-=sizeof(s);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data=s+data[ptr..];
|
||||||
|
ptr=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->seek()]
|
||||||
|
int seek(int pos, void|int mult, void|int add) {
|
||||||
|
if(mult)
|
||||||
|
pos = pos*mult+add;
|
||||||
|
if(pos<0)
|
||||||
|
{
|
||||||
|
pos = sizeof(data)+pos;
|
||||||
|
if( pos < 0 )
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
ptr = pos;
|
||||||
|
if( ptr > strlen( data ) )
|
||||||
|
ptr = strlen(data);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Always returns 1.
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->sync()]
|
||||||
|
int(1..1) sync() { return 1; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->tell()]
|
||||||
|
int tell() { return ptr; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->truncate()]
|
||||||
|
int(0..1) truncate(int length) {
|
||||||
|
data = data[..length-1];
|
||||||
|
return sizeof(data)==length;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->write()]
|
||||||
|
int(-1..) write(string|array(string) str, mixed ... extra) {
|
||||||
|
if(!w) return -1;
|
||||||
|
if(arrayp(str)) str=str*"";
|
||||||
|
if(sizeof(extra)) str=sprintf(str, @extra);
|
||||||
|
|
||||||
|
if(ptr==sizeof(data)) {
|
||||||
|
data += str;
|
||||||
|
ptr = sizeof(data);
|
||||||
|
}
|
||||||
|
else if(sizeof(str)==1)
|
||||||
|
data[ptr++] = str[0];
|
||||||
|
else {
|
||||||
|
data = data[..ptr-1] + str + data[ptr+sizeof(str)..];
|
||||||
|
ptr += sizeof(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: write callback
|
||||||
|
return sizeof(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_blocking]
|
||||||
|
void set_blocking() {
|
||||||
|
close_cb = 0;
|
||||||
|
read_cb = 0;
|
||||||
|
read_oob_cb = 0;
|
||||||
|
write_cb = 0;
|
||||||
|
write_oob_cb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_blocking_keep_callbacks]
|
||||||
|
void set_blocking_keep_callbacks() { }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_blocking]
|
||||||
|
void set_nonblocking(function rcb, function wcb, function ccb,
|
||||||
|
function rocb, function wocb) {
|
||||||
|
read_cb = rcb;
|
||||||
|
write_cb = wcb;
|
||||||
|
close_cb = ccb;
|
||||||
|
read_oob_cb = rocb;
|
||||||
|
write_oob_cb = wocb;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_blocking_keep_callbacks]
|
||||||
|
void set_nonblocking_keep_callbacks() { }
|
||||||
|
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_close_callback]
|
||||||
|
void set_close_callback(function cb) { close_cb = cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_read_callback]
|
||||||
|
void set_read_callback(function cb) { read_cb = cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_read_oob_callback]
|
||||||
|
void set_read_oob_callback(function cb) { read_oob_cb = cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_write_callback]
|
||||||
|
void set_write_callback(function cb) { write_cb = cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->set_write_oob_callback]
|
||||||
|
void set_write_oob_callback(function cb) { write_oob_cb = cb; }
|
||||||
|
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_close_callback]
|
||||||
|
function query_close_callback() { return close_cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_read_callback]
|
||||||
|
function query_read_callback() { return read_cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_read_oob_callback]
|
||||||
|
function query_read_oob_callback() { return read_oob_cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_write_callback]
|
||||||
|
function query_write_callback() { return write_cb; }
|
||||||
|
|
||||||
|
//! @seealso
|
||||||
|
//! @[Stdio.File()->query_write_oob_callback]
|
||||||
|
function query_write_oob_callback() { return write_oob_cb; }
|
||||||
|
|
||||||
|
string _sprintf(int t) {
|
||||||
|
return t=='O' && sprintf("%O(%d,%O)", this_program, sizeof(data),
|
||||||
|
make_type_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FakeFile specials.
|
||||||
|
|
||||||
|
//! A FakeFile can be casted to a string.
|
||||||
|
mixed cast(string to) {
|
||||||
|
switch(to) {
|
||||||
|
case "string": return data;
|
||||||
|
case "object": return this;
|
||||||
|
}
|
||||||
|
error("Can not cast object to %O.\n", to);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Sizeof on a FakeFile returns the size of its contents.
|
||||||
|
int(0..) _sizeof() {
|
||||||
|
return sizeof(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @ignore
|
||||||
|
|
||||||
|
#define NOPE(X) mixed X (mixed ... args) { error("This is a FakeFile. %s is not available.\n", #X); }
|
||||||
|
NOPE(assign);
|
||||||
|
NOPE(async_connect);
|
||||||
|
NOPE(connect);
|
||||||
|
NOPE(connect_unix);
|
||||||
|
NOPE(open);
|
||||||
|
NOPE(open_socket);
|
||||||
|
NOPE(pipe);
|
||||||
|
NOPE(tcgetattr);
|
||||||
|
NOPE(tcsetattr);
|
||||||
|
|
||||||
|
// Stdio.Fd
|
||||||
|
NOPE(dup2);
|
||||||
|
NOPE(lock); // We could implement this
|
||||||
|
NOPE(mode); // We could implement this
|
||||||
|
NOPE(proxy); // We could implement this
|
||||||
|
NOPE(query_fd);
|
||||||
|
NOPE(read_oob);
|
||||||
|
NOPE(set_close_on_exec);
|
||||||
|
NOPE(set_keepalive);
|
||||||
|
NOPE(trylock); // We could implement this
|
||||||
|
NOPE(write_oob);
|
||||||
|
|
||||||
|
//! @endignore
|
||||||
Reference in New Issue
Block a user