Index: /trunk/src/kmk/function.c
===================================================================
--- /trunk/src/kmk/function.c	(revision 2151)
+++ /trunk/src/kmk/function.c	(revision 2152)
@@ -2406,4 +2406,6 @@
         return math_int_to_variable_buffer (o, 0);
     }
+  else if (funcname[0] == 'l')
+    start = haystack_len - 1;
 
   /* do the searching */
@@ -2546,7 +2548,7 @@
 func_translate (char *o, char **argv, const char *funcname UNUSED)
 {
-  const unsigned char *str     = argv[0];
-  const unsigned char *new_set = argv[1];
-  const char          *old_set = argv[2];
+  const unsigned char *str     = (const unsigned char *)argv[0];
+  const unsigned char *new_set = (const unsigned char *)argv[1];
+  const char          *old_set = argv[2] != NULL ? argv[2] : "";
   char                 trans_tab[1 << CHAR_BIT];
   int                  i;
@@ -4887,5 +4889,5 @@
   { STRING_SIZE_TUPLE("length"),        1,  1,  1,  func_length},
   { STRING_SIZE_TUPLE("length-var"),    1,  1,  1,  func_length_var},
-  { STRING_SIZE_TUPLE("insert"),        3,  3,  1,  func_insert},
+  { STRING_SIZE_TUPLE("insert"),        2,  5,  1,  func_insert},
   { STRING_SIZE_TUPLE("pos"),           2,  3,  1,  func_pos},
   { STRING_SIZE_TUPLE("lastpos"),       2,  3,  1,  func_pos},
Index: /trunk/src/kmk/tests/scripts/functions/insert
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/insert	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/insert	(revision 2152)
@@ -0,0 +1,106 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(insert in, str[, n[, length[, pad]]])
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(insert ) function";
+
+$details = "Testing edges and some simple stuff.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(insert a,b),ab)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+ifneq ($(insert a,b,1),ab)
+$(error sub-test 0 failed)
+endif
+ifneq ($(insert a,b,2),ba)
+$(error sub-test 1 failed)
+endif
+ifneq ($(insert a,b,3),b a)
+$(error sub-test 2 failed)
+endif
+ifneq ($(insert a,b,0),ba)
+$(error sub-test 3 failed)
+endif
+ifneq ($(insert a,b,-1),ab)
+$(error sub-test 4 failed)
+endif
+ifneq ($(insert a,b,-2),ab)
+$(error sub-test 5 failed)
+endif
+ifneq ($(insert a,b,-10),ab)
+$(error sub-test 6 failed)
+endif
+
+ifneq ($(insert a,b,-10,0),b)
+$(error sub-test 10 failed)
+endif
+ifneq ($(insert aAAA,b,4,1),b  a)
+$(error sub-test 11 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4),bBba   BbBb)
+$(error sub-test 12 failed)
+endif
+
+ifneq ($(insert a,bBbBbBb,4,4,z),bBbazzzBbBb)
+$(error sub-test 20 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xy),bBbaxyxBbBb)
+$(error sub-test 21 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xyz),bBbaxyzBbBb)
+$(error sub-test 22 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,xyzXYZ),bBbaxyzBbBb)
+$(error sub-test 23 failed)
+endif
+ifneq ($(insert a,bBbBbBb,4,4,),bBba   BbBb)
+$(error sub-test 24 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
Index: /trunk/src/kmk/tests/scripts/functions/lastpos
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/lastpos	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/lastpos	(revision 2152)
@@ -0,0 +1,118 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(lastpos needle, haystack[, start])
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(lastpos ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(lastpos b,abc),2)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+ifneq ($(lastpos t,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 0 failed)
+endif
+ifneq ($(lastpos tu,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 1 failed)
+endif
+ifneq ($(lastpos tuv,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 2 failed)
+endif
+ifneq ($(lastpos tuvw,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 3 failed)
+endif
+ifneq ($(lastpos tuvwx,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 4 failed)
+endif
+ifneq ($(lastpos tuvwxy,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 5 failed)
+endif
+ifneq ($(lastpos tuvwxyz,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 6 failed)
+endif
+ifneq ($(lastpos tuvwxyz!,abcdefghijklmnopqrstuvwxyz),0)
+$(error sub-test 7 failed)
+endif
+
+ifneq ($(lastpos a,ababababab),9)
+$(error sub-test 10 failed)
+endif
+ifneq ($(lastpos a,ababababab,8),7)
+$(error sub-test 11 failed)
+endif
+ifneq ($(lastpos a,ababababab,7),7)
+$(error sub-test 12 failed)
+endif
+ifneq ($(lastpos a,ababababab,4),3)
+$(error sub-test 13 failed)
+endif
+ifneq ($(lastpos a,ababababab,3),3)
+$(error sub-test 14 failed)
+endif
+ifneq ($(lastpos a,ababababab,2),1)
+$(error sub-test 15 failed)
+endif
+ifneq ($(lastpos a,ababababab,1),1)
+$(error sub-test 16 failed)
+endif
+ifneq ($(lastpos a,ababababab,-1),9)
+$(error sub-test 17 failed)
+endif
+ifneq ($(lastpos a,ababababab,-2),9)
+$(error sub-test 18 failed)
+endif
+ifneq ($(lastpos a,ababababab,-10),1)
+$(error sub-test 19 failed)
+endif
+ifneq ($(lastpos a,ababababab,-11),0)
+$(error sub-test 20 failed)
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
Index: /trunk/src/kmk/tests/scripts/functions/length
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/length	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/length	(revision 2152)
@@ -0,0 +1,71 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(length text)
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(length ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(length abcd),4)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+ifneq ($(length   asdf),4)
+$(error sub-test 0 failed)
+endif
+ifneq ($(length a),1)
+$(error sub-test 1 failed)
+endif
+ifneq ($(length 0123456789),10)
+$(error sub-test 2 failed)
+endif
+ifneq ($(length 0123456789 ),11)
+$(error sub-test 3 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
Index: /trunk/src/kmk/tests/scripts/functions/length-var
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/length-var	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/length-var	(revision 2152)
@@ -0,0 +1,75 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(length-var var)
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(length-var ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(length-var non-existing-variable),0)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+VAR0 := asdf
+ifneq ($(length-var VAR0),4)
+$(error sub-test 0 failed)
+endif
+VAR1 = a
+ifneq ($(length-var VAR1),1)
+$(error sub-test 1 failed)
+endif
+VAR2 = 0123456789
+ifneq ($(length-var VAR2),10)
+$(error sub-test 2 failed)
+endif
+VAR2 = $(VAR1) $(VAR0)
+ifneq ($(length-var VAR2),15)
+$(error sub-test 3 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
Index: /trunk/src/kmk/tests/scripts/functions/pos
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/pos	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/pos	(revision 2152)
@@ -0,0 +1,118 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(pos needle, haystack[, start])
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(pos ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(pos b,abc),2)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+ifneq ($(pos t,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 0 failed)
+endif
+ifneq ($(pos tu,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 1 failed)
+endif
+ifneq ($(pos tuv,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 2 failed)
+endif
+ifneq ($(pos tuvw,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 3 failed)
+endif
+ifneq ($(pos tuvwx,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 4 failed)
+endif
+ifneq ($(pos tuvwxy,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 5 failed)
+endif
+ifneq ($(pos tuvwxyz,abcdefghijklmnopqrstuvwxyz),20)
+$(error sub-test 6 failed)
+endif
+ifneq ($(pos tuvwxyz!,abcdefghijklmnopqrstuvwxyz),0)
+$(error sub-test 7 failed)
+endif
+
+ifneq ($(pos a,ababababab),1)
+$(error sub-test 10 failed)
+endif
+ifneq ($(pos a,ababababab,2),3)
+$(error sub-test 11 failed)
+endif
+ifneq ($(pos a,ababababab,3),3)
+$(error sub-test 12 failed)
+endif
+ifneq ($(pos a,ababababab,8),9)
+$(error sub-test 13 failed)
+endif
+ifneq ($(pos a,ababababab,8),9)
+$(error sub-test 14 failed)
+endif
+ifneq ($(pos a,ababababab,9),9)
+$(error sub-test 15 failed)
+endif
+ifneq ($(pos a,ababababab,10),0)
+$(error sub-test 16 failed)
+endif
+ifneq ($(pos a,ababababab,-1),0)
+$(error sub-test 17 failed)
+endif
+ifneq ($(pos a,ababababab,-2),9)
+$(error sub-test 18 failed)
+endif
+ifneq ($(pos a,ababababab,-10),1)
+$(error sub-test 19 failed)
+endif
+ifneq ($(pos a,ababababab,-11),0)
+$(error sub-test 20 failed)
+endif
+
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
Index: /trunk/src/kmk/tests/scripts/functions/printf
===================================================================
--- /trunk/src/kmk/tests/scripts/functions/printf	(revision 2152)
+++ /trunk/src/kmk/tests/scripts/functions/printf	(revision 2152)
@@ -0,0 +1,79 @@
+# $Id$                                        -*-perl-*-
+## @file
+# $(printf fmt[,args...])
+#
+
+#
+# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
+#
+# This file is part of kBuild.
+#
+# kBuild is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# kBuild is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+#
+#
+
+$description = "Tests the $(printf ) function";
+
+$details = "A few simple tests, nothing spectacular.";
+
+if ($is_kmk) {
+
+   # TEST #0 - check that the feature is present.
+   # --------------------------------------------
+   run_make_test('
+ifneq ($(printf abcd),abcd)
+$(error sub-test 0 failed)
+endif
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+
+   # TEST #1 - the real test.
+   # ------------------------
+   run_make_test('
+ifneq ($(printf %s,abcde),abcde)
+$(error sub-test 0 failed)
+endif
+ifneq ($(printf %.4s,abcde),abcd)
+$(error sub-test 1 failed)
+endif
+ifneq ($(printf %.8s,abc),abc)
+$(error sub-test 2 failed)
+endif
+ifneq ($(printf %.2s%.3s,abc,zde),abzde)
+$(error sub-test 3 failed)
+endif
+
+ifneq ($(printf %#x,127),0x7f)
+$(error sub-test 4 failed)
+endif
+
+ifneq ($(printf %#X,127),0X7F)
+$(error sub-test 5 failed)
+endif
+
+.PHONY: all
+all: ; @:
+',
+'',
+'');
+}
+
+
+
+# Indicate that we're done.
+1;
+
