home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Education / RLaB / examples / dltest1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  1.6 KB  |  69 lines  |  [TEXT/ttxt]

  1. /* **************************************************************
  2.  * dltest1.c: A dynamic linking example (1). Rather trivial, since
  3.  *            it just re-implements strtod, but it does illustrate
  4.  *            a few points, such as how to get arguments, in
  5.  *            particular how to deal with string arguments.
  6.  * ************************************************************** */
  7.  
  8. #include "rlab.h"
  9. #include "symbol.h"
  10. #include "mem.h"
  11. #include "list.h"
  12. #include "btree.h"
  13. #include "bltin.h"
  14. #include "scop1.h"
  15. #include "matop1.h"
  16. #include "matop2.h"
  17. #include "r_string.h"
  18. #include "util.h"
  19. #include "mathl.h"
  20. #include "function.h"
  21.  
  22. #include <math.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <errno.h>
  26.  
  27. #define TARG_DESTROY(arg, targ)   if (targ.u.ent != arg.u.ent) \
  28.                                     remove_tmp_destroy (targ.u.ent);
  29. void
  30. RStrtod (return_ptr, n_args, d_arg)
  31.      VPTR *return_ptr;
  32.      int n_args;
  33.      Datum *d_arg;
  34. {
  35.   int i, nel;
  36.   Datum arg, targ;
  37.   Matrix *m, *new = 0;
  38.  
  39.   /* Check n_args */
  40.   if (n_args != 1)
  41.     error_1 ("strtod: requires 1 argument", 0);
  42.  
  43.   arg = get_bltin_arg ("strtod", d_arg, 1, 0);
  44.   targ = convert_all_to_matrix (arg);
  45.   m = (Matrix *) e_data (targ.u.ent);
  46.  
  47.   switch (MTYPE (m))
  48.   {
  49.   case REAL:
  50.   case COMPLEX:
  51.     error_1 ("strtod: input must be string", matrix_GetName (m));
  52.     break;
  53.   case STRING:
  54.     new = matrix_Create (MNR (m), MNC (m));
  55.     nel = MNR (m) * MNC (m);
  56.     for (i = 0; i < nel; i++)
  57.       MATrv (new, i) = strtod (MATsv (m, i), (char **) 0);
  58.     break;
  59.   default:
  60.     error_1 ("strtod: invalid matrix type", 0);
  61.     break;
  62.   }
  63.  
  64.   TARG_DESTROY (arg, targ);
  65.   *return_ptr = (VPTR) new;
  66.   return;
  67. }
  68.  
  69.