about summary refs log blame commit diff stats
path: root/archive/2.transect/ex8.k2
blob: dfef03b0bb5f139c8961447a56ea64a2ac47d7bd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28<
# Example reading commandline arguments: compute length of first arg.

fn main argc : int, argv : (array (ref array char)) -> [
  var tmp : (index char)
  tmp <- index 1, %size(ref array char)
  var tmp2 : (address (ref array char))
  tmp2 <- advance argv, tmp
  var s/EBX : (ref array char)
  s/EBX <- copy *tmp2
  var result/EAX : int
  result/EAX <- ascii_length s/EBX
  call exit, result/EAX
]

fn ascii_length s : (ref array char) -> result : int [
  var result/EBX : int
  result/EBX <- copy 0
  {
    var tmp0/EDI : (offset char)
    tmp0/EDI <- index result/EBX, %size(char)
    var tmp/EDX : (address char)
    tmp/EDX <- advance *s, tmp0/EDI
    var c/ECX : char
    c/ECX <- copy *tmp
    compare c/ECX, 0
    break-if-equal
    loop
  }
  return result/EBX
]

fn exit x : int [
  code/EBX <- copy x
  code/EAX <- copy 1/exit
  syscall
]
ass="nv">$os in # Not sure about uname output on DragonFly BSD. *openbsd* | *linux* | *freebsd* | *netbsd* | *dragonfly* | *dragonflybsd* | *darwin* ) ;; *) echo "Pre-built binary not available for your os" exit 1 ;; esac cpu=`uname -m` cpu=`echo $cpu | tr "[:upper:]" "[:lower:"]` case $cpu in *amd*64* | *x86*64* ) ;; *) echo "Pre-built binary not available for your cpu" exit 1 ;; esac } getURL(){ url="https://archive.org/download/cetus-v0.6.0/cetus-v0.6.0-$os-$cpu" } printURL(){ echo "You can get the Pre-built binary here:" echo "$url" echo echo "Run these commands to install it on your device." echo "# curl -L -o /usr/local/bin/cetus $url" echo "# chmod +x /usr/local/bin/cetus" echo echo "This is sha256 hash for cetus built for: $os $cpu" case $os in *openbsd* ) echo "$openbsdH" ;; *netbsd* ) echo "$netbsdH" ;; *dragonflybsd* | *dragonfly* ) echo "$dragonflyH" ;; *darwin* ) echo "$darwinH" ;; *freebsd* ) echo "$freebsdH" ;; *linux* ) echo "$linuxH" ;; esac echo echo "Verify the hash by running sha256 on cetus binary." echo "$ sha256 /usr/local/bin/cetus" } echo "Cetus v0.6.0" echo earlyCheck getURL printURL