Hi!

----

Attached (as "astksh20130503_typeset_copy_operator001.diff.txt") is a
small patch which provides a type-independent copy-by-name operator.

Usage example:
-- snip --
# 1. copy float by name
$ ksh -c 'float i=5.5 ; typeset -c j=i ; print $i $j'
5.5 5.5

# 2. copy associative array by name
$ ksh -c 'compound c=( typeset -A i=( [1]=4 [3]=5 [7]=6 ) ) ; typeset
-c c.j=c.i ; print -v c'
(
        typeset -A i=(
                [1]=4
                [3]=5
                [7]=6
        )
        typeset -A j=(
                [1]=4
                [3]=5
                [7]=6
        )
)
-- snip --

The idea is to have a _generic_ and type-independent facility to
_copy_ variables by _name_ (instead of j="$i" ... which is copy by
value and doesn't work the same way for all objects).

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
diff -r -u original/src/cmd/ksh93/bltins/typeset.c 
build_i386_64bit_debug/src/cmd/ksh93/bltins/typeset.c
--- src/cmd/ksh93/bltins/typeset.c      2013-03-28 14:30:54.000000000 +0100
+++ src/cmd/ksh93/bltins/typeset.c      2013-05-20 19:04:50.602843902 +0200
@@ -53,6 +53,7 @@
        char            *help;
        short           aflag;
        short           pflag;
+       bool            cflag; /* copy flag */
        int             argnum;
        int             scanmask;
        Dt_t            *scanroot;
@@ -270,6 +271,8 @@
                        case 'b':
                                flag |= NV_BINARY;
                                break;
+                       case 'c':
+                               tdata.cflag=true;
                        case 'm':
                                flag |= NV_MOVE;
                                break;
@@ -717,6 +720,8 @@
                        }
                        if(flag&NV_MOVE)
                        {
+                               if(tp->cflag)
+                                       flag &= ~NV_MOVE;
                                nv_rename(np, flag);
                                nv_close(np);
                                continue;
diff -r -u original/src/cmd/ksh93/data/builtins.c 
build_i386_64bit_debug/src/cmd/ksh93/data/builtins.c
--- src/cmd/ksh93/data/builtins.c       2013-05-03 22:23:11.000000000 +0200
+++ src/cmd/ksh93/data/builtins.c       2013-05-20 15:10:58.659183988 +0200
@@ -1674,6 +1674,9 @@
 "[m?Move.  The value is the name of a variable whose value will be "
        "moved to \aname\a.  The orignal variable will be unset.  Cannot be "
        "used with any other options.]"
+"[c?Copy.  The value is the name of a variable whose value will be "
+       "copied to \aname\a.  The orignal variable will not be unset.  Cannot 
be "
+       "used with any other options.]"
 "[n?Name reference.  The value is the name of a variable that \aname\a "
        "references.  \aname\a cannot contain a \b.\b.  Cannot be use with "
        "any other options.]"
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to