01: /*
02: * @(#)printf.java 1.2 04/12/06
03: *
04: * Copyright (c) 2002-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.text;
10:
11: import pnuts.lang.*;
12:
13: public class printf extends PnutsFunction {
14:
15: public printf() {
16: super ("printf");
17: }
18:
19: public boolean defined(int nargs) {
20: return nargs > 0;
21: }
22:
23: protected Object exec(Object[] args, Context context) {
24: int nargs = args.length;
25: if (nargs == 0) {
26: undefined(args, context);
27: return null;
28: }
29: Object[] fargs = new Object[nargs - 1];
30: System.arraycopy(args, 1, fargs, 0, nargs - 1);
31: PnutsFunction print = (PnutsFunction) context
32: .resolveSymbol("print");
33: if (print == null) {
34: throw new RuntimeException();
35: }
36: print.call(new Object[] { new PrintfFormat((String) args[0])
37: .sprintf(fargs) }, context);
38: return null;
39: }
40: }
|