pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:1:
/* -*- c -*- || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: builtin.cmod,v 1.
171
2004/
09
/28
16
:
58
:
23
grubba Exp $
+
|| $Id: builtin.cmod,v 1.
172
2004/
10
/28
12
:
51
:
53
grubba Exp $
*/ #include "global.h" #include "interpret.h" #include "svalue.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h" #include "pike_error.h"
pike.git/src/builtin.cmod:3187:
/*! @decl int(0..) _sizeof() *! *! Returns the number of elements in the list. */ PIKEFUN int(0..) _sizeof() flags ID_STATIC; { push_int(THIS->num_elems); }
+
/*! @decl string _sprintf(int c, mapping(string:mixed)|void attr)
+
*!
+
*! Describe the list.
+
*!
+
*! @seealso
+
*! @[sprintf()], @[lfun::_sprintf()]
+
*/
+
PIKEFUN string _sprintf(int c, mapping(string:mixed)|void attr)
+
flags ID_STATIC;
+
{
+
if (!THIS->num_elems) {
+
push_constant_text("ADT.List(/* empty */)");
+
} else if (c == 'O') {
+
struct list_node *node = THIS->head;
+
if (THIS->num_elems == 1) {
+
push_constant_text("ADT.List(/* 1 element */\n");
+
} else {
+
push_constant_text("ADT.List(/* %d elements */\n");
+
push_int(THIS->num_elems);
+
f_sprintf(2);
+
}
+
while (node->next) {
+
if (node->next->next) {
+
push_constant_text(" %O,\n");
+
} else {
+
push_constant_text(" %O\n");
+
}
+
push_svalue(&node->val);
+
f_sprintf(2);
+
node = node->next;
+
}
+
push_constant_text(")");
+
f_add(THIS->num_elems + 2);
+
} else {
+
if (THIS->num_elems == 1) {
+
push_constant_text("ADT.List(/* 1 element */)");
+
} else {
+
push_constant_text("ADT.List(/* %d elements */)");
+
push_int(THIS->num_elems);
+
f_sprintf(2);
+
}
+
}
+
stack_pop_n_elems_keep_top(args);
+
}
+
/*! @decl mixed head() *! *! Get the element at the head of the list. *! *! @throws *! Throws an error if the list is empty. *! *! @seealso *! @[is_empty()], @[tail()], @[pop()] */