Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Generic-swap/AWK/generic-swap.awk
Normal file
25
Task/Generic-swap/AWK/generic-swap.awk
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# syntax: GAWK -f GENERIC_SWAP.AWK
|
||||
BEGIN {
|
||||
printf("%s version %s\n",ARGV[0],PROCINFO["version"])
|
||||
foo = 1
|
||||
bar = "a"
|
||||
printf("\n%s %s\n",foo,bar)
|
||||
rc = swap("foo","bar") # ok
|
||||
printf("%s %s %s\n",foo,bar,rc?"ok":"ng")
|
||||
printf("\n%s %s\n",foo,bar)
|
||||
rc = swap("FOO","BAR") # ng
|
||||
printf("%s %s %s\n",foo,bar,rc?"ok":"ng")
|
||||
exit(0)
|
||||
}
|
||||
function swap(a1,a2, tmp) { # strings or numbers only; no arrays
|
||||
if (a1 in SYMTAB && a2 in SYMTAB) {
|
||||
if (isarray(SYMTAB[a1]) || isarray(SYMTAB[a2])) {
|
||||
return(0)
|
||||
}
|
||||
tmp = SYMTAB[a1]
|
||||
SYMTAB[a1] = SYMTAB[a2]
|
||||
SYMTAB[a2] = tmp
|
||||
return(1)
|
||||
}
|
||||
return(0)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue