home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2001 January / LCD_01_2001.iso / develop / agnus143 / agnus / src / oc_test / cpy.m < prev    next >
Encoding:
Text File  |  1998-04-29  |  1.2 KB  |  68 lines

  1. /*
  2.    EXAMPLE 5: cpy.m -- Cpy etc. for the classes Cstr & Pstr
  3.  
  4.    Methods: cpy(Obj obj, Char_ptr str) obj = str
  5.             len(Obj obj, Int_ptr len)  len = lenght of obj-string
  6.             ocpy(Obj obj, Obj src)     obj = src
  7.             print(Obj obj)          print obj
  8. */
  9.  
  10. #include <oc.h>
  11. #include "module.h"  
  12. #include "d_module.h"
  13.  
  14.  
  15. $meth print (Obj obj)
  16.    $support(Cstr, Pstr);
  17.    $call(obj)
  18. $class Cstr
  19.    printf(..value);
  20. $class Pstr
  21.    ..value[..len] = 0;
  22.    printf(..value);
  23. $
  24.  
  25. $meth cpy (Obj obj, Char_ptr str)
  26.    $support(Cstr, Pstr);
  27.    $call(obj);
  28. $class Cstr
  29.    CPY(..value, str);   /* We always have a strcpy, so wy don't use it */
  30. $class Pstr
  31.    CPY(..value, str);
  32.    ..len = LEN(str);
  33. $
  34.  
  35.  
  36. $meth len (Obj obj, Int_ptr len)
  37.    $support(Cstr, Pstr);
  38.    $call(obj);
  39. $class Cstr
  40.    *len = LEN(..value);
  41. $class Pstr
  42.    *len = ..len;
  43. $
  44.  
  45.  
  46. $meth ocpy (Obj obj, Obj src)
  47.    $par( Char_ptr str);     /* additional local parameter */
  48.    $support(Cstr, Pstr);
  49.  
  50.    /* Set str to string of src   */
  51.    $switchp(src)
  52.    $case(Cstr)
  53.       str = srcp->value;
  54.    $case(Pstr)
  55.       str = srcp->value;
  56.       str[srcp->len] = 0;
  57.    $
  58.  
  59.    $call(obj)
  60.  
  61. /* Now we can use the parameter str */
  62. $class Cstr
  63.    CPY(..value, str);
  64. $class Pstr
  65.    CPY(..value, str);
  66.    ..len = LEN(str);
  67. $
  68.