home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / runtime / def.r < prev    next >
Text File  |  2000-07-29  |  4KB  |  169 lines

  1. /*
  2.  * def.r -- defaulting conversion routines.
  3.  */
  4.  
  5. /*
  6.  * DefConvert - macro for general form of defaulting conversion.
  7.  */
  8. #begdef DefConvert(default, dftype, destype, converter, body)
  9. int default(s,df,d)
  10. dptr s;
  11. dftype df;
  12. destype d;
  13.    {
  14.    if (is:null(*s)) {
  15.       body
  16.       return 1;
  17.       }
  18.    else
  19.       return converter(s,d); /* I really mean cnv:type */
  20.    }
  21. #enddef
  22.  
  23. /*
  24.  * def_c_dbl - def:C_double(*s, df, *d), convert to C double with a
  25.  *  default value. Default is of type C double; if used, just copy to
  26.  *  destination.
  27.  */
  28.  
  29. #begdef C_DblAsgn
  30.    *d = df;
  31. #enddef
  32.  
  33. DefConvert(def_c_dbl, double, double *, cnv_c_dbl, C_DblAsgn)
  34.  
  35. /*
  36.  * def_c_int - def:C_integer(*s, df, *d), convert to C_integer with a
  37.  *  default value. Default type C_integer; if used, just copy to
  38.  *  destination.
  39.  */
  40. #begdef C_IntAsgn
  41.    *d = df;
  42. #enddef
  43.  
  44. DefConvert(def_c_int, C_integer, C_integer *, cnv_c_int, C_IntAsgn)
  45.  
  46. /*
  47.  * def_c_str - def:C_string(*s, df, *d), convert to (tended) C string with
  48.  *  a default value. Default is of type "char *"; if used, point destination
  49.  *  descriptor to it.
  50.  */
  51.  
  52. #begdef C_StrAsgn
  53.    StrLen(*d) = strlen(df);
  54.    StrLoc(*d) = (char *)df;
  55. #enddef
  56.  
  57. DefConvert(def_c_str, char *, dptr, cnv_c_str, C_StrAsgn)
  58.  
  59. /*
  60.  * def_cset - def:cset(*s, *df, *d), convert to cset with a default value.
  61.  *  Default is of type "struct b_cset *"; if used, point destination descriptor
  62.  *  to it.
  63.  */
  64.  
  65. #begdef CsetAsgn
  66.    d->dword = D_Cset;
  67.    BlkLoc(*d) = (union block *)df;
  68. #enddef
  69.  
  70. DefConvert(def_cset, struct b_cset *, dptr, cnv_cset, CsetAsgn)
  71.  
  72. /*
  73.  * def_ec_int - def:(exact)C_integer(*s, df, *d), convert to C Integer
  74.  *  with a default value, but disallow conversions from reals. Default
  75.  *  is of type C_Integer; if used, just copy to destination.
  76.  */
  77.  
  78. #begdef EC_IntAsgn
  79.    *d = df;
  80. #enddef
  81.  
  82. DefConvert(def_ec_int, C_integer, C_integer *, cnv_ec_int, EC_IntAsgn)
  83.  
  84. /*
  85.  * def_eint - def:(exact)integer(*s, df, *d), convert to C_integer
  86.  *  with a default value, but disallow conversions from reals. Default
  87.  *  is of type C_Integer; if used, assign it to the destination descriptor.
  88.  */
  89.  
  90. #begdef EintAsgn
  91.    d->dword = D_Integer;
  92.    IntVal(*d) = df;
  93. #enddef
  94.  
  95. DefConvert(def_eint, C_integer, dptr, cnv_eint, EintAsgn)
  96.  
  97. /*
  98.  * def_int - def:integer(*s, df, *d), convert to integer with a default
  99.  *  value. Default is of type C_integer; if used, assign it to the
  100.  *  destination descriptor.
  101.  */
  102.  
  103. #begdef IntAsgn
  104.    d->dword = D_Integer;
  105.    IntVal(*d) = df;
  106. #enddef
  107.  
  108. DefConvert(def_int, C_integer, dptr, cnv_int, IntAsgn)
  109.  
  110. /*
  111.  * def_real - def:real(*s, df, *d), convert to real with a default value.
  112.  *  Default is of type double; if used, allocate real block and point
  113.  *  destination descriptor to it.
  114.  */
  115.  
  116. #begdef RealAsgn
  117.    Protect(BlkLoc(*d) = (union block *)alcreal(df), fatalerr(0,NULL));
  118.    d->dword = D_Real;
  119. #enddef
  120.  
  121. DefConvert(def_real, double, dptr, cnv_real, RealAsgn)
  122.  
  123. /*
  124.  * def_str - def:string(*s, *df, *d), convert to string with a default
  125.  *  value. Default is of type "struct descrip *"; if used, copy the
  126.  *  decriptor value to the destination.
  127.  */
  128.  
  129. #begdef StrAsgn
  130.    *d = *df;
  131. #enddef
  132.  
  133. DefConvert(def_str, dptr, dptr, cnv_str, StrAsgn)
  134.  
  135. /*
  136.  * def_tcset - def:tmp_cset(*s, *df, *d), conversion to temporary cset with
  137.  *  a default value. Default is of type "struct b_cset *"; if used,
  138.  *  point destination descriptor to it. Note that this routine needs
  139.  *  a cset buffer (cset block) to perform an actual conversion.
  140.  */
  141. int def_tcset(cbuf, s, df, d)
  142. struct b_cset *cbuf, *df;
  143. dptr s, d;
  144. {
  145.    if (is:null(*s)) {
  146.       d->dword = D_Cset;
  147.       BlkLoc(*d) = (union block *)df;
  148.       return 1;
  149.       }
  150.    return cnv_tcset(cbuf, s, d);
  151.    }
  152.  
  153. /*
  154.  * def_tstr - def:tmp_string(*s, *df, *d), conversion to temporary string
  155.  *  with a default value. Default is of type "struct descrip *"; if used,
  156.  *  copy it to destination descriptor. Note that this routine needs
  157.  *  a string buffer to perform an actual conversion.
  158.  */
  159. int def_tstr(sbuf, s, df, d)
  160. char *sbuf;
  161. dptr s, df, d;
  162.    {
  163.    if (is:null(*s)) {
  164.       *d = *df;
  165.       return 1;
  166.       }
  167.    return cnv_tstr(sbuf, s, d);
  168.    }
  169.