/*
   EXAMPLE 5: cpy.m -- Cpy etc. for the classes Cstr & Pstr

   Methods: cpy(Obj obj, Char_ptr str) obj = str
            len(Obj obj, Int_ptr len)  len = lenght of obj-string
            ocpy(Obj obj, Obj src)     obj = src
            print(Obj obj)          print obj
*/

#include <oc.h>
#include "module.h"  
#include "d_module.h"


$meth print (Obj obj)
   $support(Cstr, Pstr);
   $call(obj)
$class Cstr
   printf(..value);
$class Pstr
   ..value[..len] = 0;
   printf(..value);
$

$meth cpy (Obj obj, Char_ptr str)
   $support(Cstr, Pstr);
   $call(obj);
$class Cstr
   CPY(..value, str);   /* We always have a strcpy, so wy don't use it */
$class Pstr
   CPY(..value, str);
   ..len = LEN(str);
$


$meth len (Obj obj, Int_ptr len)
   $support(Cstr, Pstr);
   $call(obj);
$class Cstr
   *len = LEN(..value);
$class Pstr
   *len = ..len;
$


$meth ocpy (Obj obj, Obj src)
   $par( Char_ptr str);     /* additional local parameter */
   $support(Cstr, Pstr);

   /* Set str to string of src   */
   $switchp(src)
   $case(Cstr)
      str = srcp->value;
   $case(Pstr)
      str = srcp->value;
      str[srcp->len] = 0;
   $

   $call(obj)

/* Now we can use the parameter str */
$class Cstr
   CPY(..value, str);
$class Pstr
   CPY(..value, str);
   ..len = LEN(str);
$
