home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1821.lha / XDME / vars.c < prev    next >
C/C++ Source or Header  |  1993-03-25  |  19KB  |  787 lines

  1.  
  2. /*
  3. **  VARS.C
  4. **
  5. **    Variable Support for [X]DME
  6. **
  7. **  (C)Copyright 1992 by Bernd Noll for null/zero-soft
  8. **  All Rights Reserved
  9. **
  10. **  RCS Header: $Id: vars.c,v 1.65 92/11/09 12:47:10 b_noll Exp $
  11. **
  12. **  compiling with
  13. **  "#define PATCH_NULL"
  14. **  "#define PATCH_VARS"
  15. **  "#define PATCH_FLAGS"
  16. **  causes that module to be used (and var.c not to be used)
  17. **
  18. *!***************************************************************
  19. *!
  20. *!  PATCH_VARS - OVERVIEW
  21. *!
  22. *!
  23. *!  the vars-module shall support access to different types of
  24. *!  variables
  25. *!  which are currently "global" vars/flags, "textlocal" vars/flags,
  26. *!  "macrolocal" vars and "env" vars
  27. **  (there are some other types used for DME, but not for XDME yet)
  28. *!
  29. *!
  30. *!  WARNING:
  31. *!    as this module is written very close
  32. *!    to DME's internal hierachy, it will be object of major changes,
  33. *!    as soon as Packages are introduced as a new concept for management
  34. *!    of macros, menues, keys, flags and variables
  35. *!
  36. **
  37. **
  38. **  GetTypedVar / SetTypedVar / VAR_...types/prefixes
  39. **
  40. **  the "Highlevel" interface to most other variable modules,
  41. **  which should most times be used in Programming -
  42. **  Cleanest Possiblility of Access to Variables of any Type.
  43. **
  44. **  We have put all variable functions, which do not need access
  45. **  to certain structures (rexx.../argstack...), together in that
  46. **  module and try to export only a very small interface, which
  47. **  should allow information hiding
  48. **
  49. **  this module should completely cover the "old" module var.c
  50. **  so I put var.c into '#ifndef PATCH_VARS'
  51. **
  52. *****************************************************************
  53. **
  54. **  Implementor's note
  55. **
  56. **    The module looks pretty ugly,
  57. **    I am not ready documenting and porting all
  58. **    functions which had been written for DME
  59. **    into XDME partly as many differences have occurred
  60. **    partly as I have started designing a Packages-concept
  61. **
  62. **  XDME NOTE - the flags - routines are not used yet for XDME
  63. */
  64.  
  65. /**************************************
  66.         Includes
  67. **************************************/
  68. #include "defs.h"
  69.  
  70.  
  71. /**************************************
  72.        Internal Prototypes
  73. **************************************/
  74. Prototype void        init_variables  (void);
  75. Prototype char *    GetTypedVar     (char *, int *);
  76. Prototype void        SetTypedVar     (char *, char *, int);
  77. extern      void        SetDMEVar        (char *, char *);   /* Proto'd for access from scanf.c */
  78. extern      void        SetTextVar        (char *, char *);
  79. extern      void        SetDEnv        (char *, char *);
  80. extern      char *    GetDMEVar        (char *);
  81. extern      char *    GetTextVar        (char *);
  82. extern      char *    GetEnvVar        (char *);
  83. extern      char *    GetDEnv        (char *);
  84. Prototype void        do_set        (void);
  85. Prototype void        do_unset        (void);
  86. Prototype void        do_setenv        (void);
  87. Prototype void        do_unsetenv     (void);
  88. Prototype void        do_settvar        (void);
  89. Prototype void        do_unsettvar    (void);
  90. Prototype int        is_tflagset     (int);              /* Proto'd for access from control.c */
  91. Prototype int        is_gflagset     (int);              /* Proto'd for access from control.c */
  92. extern      char *    GetTextFlag     (char *);
  93. extern      char *    GetGlobalFlag   (char *);
  94. extern      char        SetAnyFlag        (char *, char *);
  95. extern      char        SetGlobalFlag   (char *, char *);
  96. extern      char        SetTextFlag     (char *, char *);
  97. Prototype void        do_flag        (void);
  98. Prototype void        do_toggleflag   (void);
  99. Prototype char *    getvar        (char *);
  100.  
  101.  
  102. /**************************************
  103.         Internal Variables
  104. **************************************/
  105. #ifndef VAR_NUM
  106. #define VAR_NUM 8
  107. #endif
  108.  
  109. #ifndef SIGN_LOCAL_FLAG
  110. # define SIGN_LOCAL_FLAG 't'
  111. #endif
  112.  
  113. #ifdef DBASE
  114. # define SList      DmeBase.SList
  115. # define VarsTree DmeBase.SList
  116. #else
  117. APTR    VarsTree = NULL;
  118. #endif
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /*
  126. **  init_variables()
  127. **    initialize the "global" variables structures
  128. **    call that function from main or make it '__autoinit'
  129. */
  130.  
  131. void
  132. init_variables (void)
  133. {
  134.     VarsTree = NULL;
  135. } /* init_variables */
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. /***************************************************************
  143. **
  144. **  Access to the different kinds of Named Variables
  145. **
  146. ***************************************************************/
  147.  
  148.  
  149.  
  150. /**************************************
  151. **  Handling of DME "global" Variables
  152. ** (if we are using Packages "global" might be the wrong name)
  153. **************************************/
  154.  
  155. char *
  156. GetDMEVar (char * name)
  157. {
  158.     return (GetVarFromTree(&VarsTree, name));
  159. } /* GetDMEVar */
  160.  
  161.  
  162.  
  163. void
  164. SetDMEVar (char * name, char * value)
  165. {
  166.     SetVarIntoTree (&VarsTree, name, value);
  167. } /* SetDMEVar */
  168.  
  169.  
  170.  
  171. /*
  172. *! >SET name value
  173. *! >UNSET name
  174. *!
  175. *!  set a std DME variable to a new value or drop it and its contents
  176. *!  if the name is only a number, set the according dme std flag
  177. *!
  178. *!  NOTE that if packages are ready, SET should default to PVars/PFlags,
  179. *!    not to GVars/GFlags
  180. *!
  181. */
  182.  
  183. void
  184. do_set (void)
  185. {
  186.     if (!SetGlobalFlag(av[1], av[2]))
  187.     SetDMEVar (av[1],av[2]);
  188. } /* do_set */
  189.  
  190.  
  191.  
  192. void
  193. do_unset (void)
  194. {
  195.     DelVarFromTree (&VarsTree, av[1]);
  196. } /* do_unset */
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. /**************************************
  204. **  Handling of Text Local Variables
  205. **************************************/
  206.  
  207. char *
  208. GetTextVar (char * name)
  209. {
  210.     return (GetVarFromTree (&Ep->textvars, name));
  211. } /* GetTextVar */
  212.  
  213.  
  214.  
  215. void
  216. SetTextVar (char * name, char * value)
  217. {
  218.     SetVarIntoTree (&Ep->textvars, name, value);
  219. } /* SetTextVar */
  220.  
  221.  
  222.  
  223. /*
  224. *! >SETTVAR name value
  225. *! >UNSETTVAR name
  226. *!
  227. *!  set a text local variable to a new value or drop it and its contents
  228. *!  if the name is only a "t"number, set the according text local flag
  229. *!
  230. */
  231.  
  232. void
  233. do_settvar (void)
  234. {
  235.     if (!SetTextFlag(av[1], av[2]))
  236.     SetTextVar (av[1],av[2]);
  237. } /* do_settvar */
  238.  
  239.  
  240.  
  241. void
  242. do_unsettvar (void)
  243. {
  244.     DelVarFromTree (&Ep->textvars, av[1]);
  245. } /* do_unsettvar */
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252. /***************************************************************
  253. **
  254. **  Access to Environment variables
  255. **
  256. ***************************************************************/
  257.  
  258.  
  259.  
  260. char *
  261. GetDEnv (char * ename)
  262. {
  263.     long   envLock = Lock("env:", SHARED_LOCK);
  264.     char * str       = NULL;
  265.  
  266.     if (envLock)
  267.     {
  268.     long  oldLock = CurrentDir (envLock);
  269.     FILE * fi     = fopen (ename, "r");
  270.     long   siz;
  271.  
  272.     if (fi)
  273.     {
  274.         fseek (fi, 0L, 2);
  275.         siz = ftell (fi);
  276.         fseek (fi, 0L, 0);
  277.  
  278.         if (siz > 0 && (str = malloc (siz + 1)))
  279.         {
  280.         fread (str, siz, 1, fi);
  281.         str[siz] = 0;
  282.         } /* if malloced */
  283.         fclose (fi);
  284.     } /* if opened */
  285.     UnLock (CurrentDir (oldLock));
  286.     } /* if locked */
  287.     return (str);
  288. } /* GetDEnv */
  289.  
  290.  
  291.  
  292. void
  293. SetDEnv (char * ename, char * econt)
  294. {
  295.     long envLock = Lock ("env:", SHARED_LOCK);
  296.  
  297.     if (envLock)
  298.     {
  299.     long   oldLock = CurrentDir (envLock);
  300.     FILE * fi      = fopen (ename, "w");
  301.  
  302.     if (fi)
  303.     {
  304.         fwrite (econt, strlen(econt), 1, fi);
  305.         fclose (fi);
  306.     } /* if opened */
  307.     UnLock (CurrentDir(oldLock));
  308.     } /* if locked */
  309. } /* SetDEnv */
  310.  
  311.  
  312.  
  313. char *
  314. GetEnvVar(char * name)
  315. {
  316.     char * str;
  317.  
  318.     mountrequest(0);
  319.     str = GetDEnv(name);
  320.     mountrequest(1);
  321.     return(str);
  322. } /* GetEnvVar */
  323.  
  324.  
  325.  
  326. /*
  327. *! >SETENV name value
  328. *! >UNSETENV name
  329. *!
  330. *!  set an Environment variable to a new value or drop it and its contents
  331. */
  332.  
  333. void do_setenv (void)
  334. {
  335.     SetDEnv ((char *)av[1], (char *)av[2]);
  336. } /* do_setenv */
  337.  
  338.  
  339.  
  340. void do_unsetenv (void)
  341. {
  342.     char * tmp = malloc(4+1+strlen(av[1]));
  343.  
  344.     if (tmp)
  345.     {
  346.     strcpy(tmp, "ENV:");
  347.     strcat(tmp, av[1]);
  348.  
  349.     mountrequest (0);
  350.     DeleteFile ((STRPTR)tmp);
  351.     mountrequest (1);
  352.  
  353.     free (tmp);
  354.     } /* if */
  355. } /* do_unsetenv */
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362. /***************************************************************
  363. **
  364. **  Access to the different kinds of Flags
  365. **
  366. ***************************************************************/
  367.  
  368.  
  369. /**************************************
  370. **  Handling of TEXT Local Flags
  371. **************************************/
  372.  
  373. int is_tflagset(int num)
  374. {
  375.     return (IsFlagSet(Ep->textflags, num, 32));
  376. } /* is_tflagset */
  377.  
  378.  
  379.  
  380. char SetTextFlag(char * name, char *  value)
  381. {
  382.     return (SetFlag(Ep->textflags, name, value, 32, "t"));
  383. } /* SetTextFlag */
  384.  
  385.  
  386.  
  387. /*
  388.  *  GetTextFlag: get a variable of a text's internal flags
  389.  */
  390.  
  391. char * GetTextFlag (char * name)
  392. {
  393.     return (GetFlag(Ep->textflags, name, 32, "t"));
  394. } /* GetTextFlag */
  395.  
  396.  
  397.  
  398.  
  399.  
  400. #ifdef DBASE
  401. # define tg DmeBase.gflags
  402. #else
  403. char tg[MAXTOGGLE/8]; /* test purposes */
  404. #endif /* DBASE */
  405.  
  406. /**************************************
  407. **  Handling of DME Global Flags
  408. **************************************/
  409.  
  410. int is_gflagset (int num)
  411. {
  412.     return(IsFlagSet(tg, num, MAXTOGGLE));
  413. } /* is_gflagset */
  414.  
  415.  
  416.  
  417. /*
  418.  *  GetGlobalFlag : get a variable from dme's flag-list
  419.  */
  420.  
  421. char SetGlobalFlag(char * name, char * value)
  422. {
  423.     return(SetFlag(tg, name, value, MAXTOGGLE, "")); /* "g" */
  424. } /* SetGlobalFlag */
  425.  
  426.  
  427.  
  428. char * GetGlobalFlag (char * name)
  429. {
  430.     return(GetFlag(tg, name, MAXTOGGLE, ""));   /* "g" */
  431. } /* GetGlobalFlag */
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438. /**************************************
  439. **  Interface to come around with all types of flags
  440. **************************************/
  441.  
  442. char
  443. SetAnyFlag(char * name, char * qual)
  444. {
  445.     if (name && qual)
  446.     {
  447.     if (is_number(name))
  448.     {
  449.         return(SetGlobalFlag(name, qual));
  450.  
  451.     /* } if (!is_digit(name[1]))
  452.     {           // Commented out for XDME */
  453.     //     return(SetSpecialFlag(name, qual));  /* Commented out for XDME */
  454.  
  455.     } else if (name[0] == SIGN_LOCAL_FLAG)
  456.     {
  457.         return(SetTextFlag(name, qual));
  458.  
  459.     } else
  460.     {
  461.         /* abort(); */
  462.         return(0);
  463.     } /* if */
  464.     } else
  465.     {
  466.     abort(0);
  467.     } /* if */
  468. } /* SetAnyFlag */
  469.  
  470.  
  471.  
  472. /*
  473. *! >FLAG flagname on/off/toggle/switch/0/1/set/reset/true/false
  474. *!
  475. *!  set any flag that is controlled by DME
  476. *!  with flagname is number, "t"number or specialflagname
  477. *!
  478. */
  479.  
  480. void
  481. do_flag (void)
  482. {
  483.     if (!SetAnyFlag(av[1],av[2]))
  484.     abort();
  485. } /* do_flag */
  486.  
  487.  
  488.  
  489. /*
  490. *! >[[RE]SET]TOGGLE flagname
  491. *!
  492. *!  modify any flag, that is controlled by DME
  493. *!  with flagname is number, "i"number or specialflag
  494. *!
  495. */
  496.  
  497. void
  498. do_toggleflag (void)
  499. {
  500.     SetAnyFlag(av[1], av[0]);
  501. } /* do_toggleflag */
  502.  
  503.  
  504.  
  505. /***************************************************************
  506. **
  507. **  Interface to be used for external functions and commands
  508. **
  509. ***************************************************************/
  510.  
  511.  
  512.  
  513. /*
  514. ** the different types of "variables",
  515. ** which seem to be possible to be recognized
  516. **
  517. ** these definitions must be visible to all modules
  518. */
  519.  
  520. // #define VAR_NEX 0  /* not existing variable */
  521. // #define VAR_FPK 1  /* explicite access to another ("foreign") package */
  522. // #define VAR_SF  2  /* dme special flags */
  523. // #define VAR_SI  3  /* dme special integer variable */
  524. // #define VAR_SV  4  /* dme special vars scanf/filename/... */
  525. // #define VAR_MF  5  /* dme macro   flag */
  526. // #define VAR_TF  6  /* dme text    flag */
  527. // #define VAR_PF  7  /* dme package flag */
  528. // #define VAR_GF  8  /* dme global  flag */
  529. // #define VAR_TV  9  /* dme text    variable */
  530. // #define VAR_MV  10 /* dme macro   variable */
  531. // #define VAR_PV  11 /* dme package variable */
  532. // #define VAR_GV  12 /* dme global  variable */
  533. // #define VAR_ARG 13 /* dme macro   parameter */
  534. // #define VAR_ENV 14 /* CBM env: variable */
  535. // #define VAR_SH  15 /* CBM local shell-var            (FUTURE) */
  536. // #define VAR_CLP 16 /* rexx cliplist - entry */
  537. // #define VAR_RXX 17 /* rexx variable via RVI */
  538. // #define VAR_RXF 18 /* rexx result of functioncall */
  539. // #define VAR_MAP 19 /* dme package key-mapping */
  540. // #define VAR_MEN 20 /* dme package menu */
  541. // #define VAR_MNX 21 /* Arp shell-var                (FUTURE) */
  542.  
  543. // #define VAR_DME VAR_GV /* alias */
  544.  
  545. #define VF_COP    1  /* duplicate the result */
  546. #define VF_PAW    2  /* Prefix AlWays: dont use without Prefix (FUTURE) */
  547.  
  548.  
  549. typedef struct _vtype
  550. {
  551.     const char * name;    /* prefix */
  552.     int     id;     /* number for communication */
  553.     int     len;    /* size of prefix for comparison */
  554.     int     offset;    /* offset to cut prefix */
  555.     int     flags;    /* flags (e.g. duplicate result ...) */
  556.     char*   replace;    /* if prefix matches, replace w/that prefix */
  557.     void    (*do_set)(char*,char*); /* set-function */
  558.     char*   (*do_get)(char*);       /* get-function */
  559. } VTYPE;
  560.  
  561.  
  562. static CONST VTYPE vartypes[] =
  563. {
  564. #ifdef N_DEF
  565.     {"SHVAR_",  VAR_SH , 6, 6,     0, NULL, NULL, NULL},
  566.     {"ARP_",    VAR_MNX, 4, 4,     0, NULL, NULL, NULL},
  567.     {"RXFUNC ", VAR_RXF, 7, 7,     0, NULL, NULL, getQ},
  568.     {"RXSFUNC ",VAR_RXF, 8, 8,     0, NULL, NULL, getQ},
  569. #endif
  570.     {"SFLAG_",  VAR_SF,  6, 6,     0, NULL,     SetSpecialFlag, GetSpecialFlag},    /* we need 3 names */
  571.     {"SINT_",   VAR_SI,  5, 5,     0, NULL,     SetSpecialInt,  GetSpecialInt},     /* for the 3 different types (or we have to put them together) */
  572.     {"SPC_",    VAR_SV,  4, 4,     0, NULL,     SetSpecialVar,  GetSpecialVar},     /* of special vars else there are big problems */
  573.     {"TFLAG_",  VAR_TF,  6, 6,     0, "t%s",    SetTextFlag,    GetTextFlag},
  574.     {"GFLAG_",  VAR_GF,  6, 6,     0, NULL,     SetGlobalFlag,  GetGlobalFlag},  /* ifdef PATCH_PACK set replace to "g%s" */
  575.     {"ARG_",    VAR_ARG, 4, 4,     0, "arg%s",  NULL,           getmacroarg},
  576.     {"arg",     VAR_ARG, 3, 0,     0, NULL,     NULL,           getmacroarg},
  577.     {"MVAR_",   VAR_MV,  5, 5,     0, NULL,     SetMacroVar,    getmacrovar},
  578.     {"TVAR_",   VAR_TV,  5, 5,     0, NULL,     SetTextVar,     GetTextVar},
  579.     {"GVAR_",   VAR_GV,  5, 5,     0, NULL,     SetDMEVar,      GetDMEVar},
  580.     {"ENV_",    VAR_ENV, 4, 4,     0, NULL,     SetDEnv,        GetEnvVar},
  581. #ifdef PATCH_RXCLIPS
  582.     {"RXCLP_",  VAR_CLP, 6, 6,     0, NULL,     SetRexxClip,    GetRexxClip},
  583. #endif /* PATCH_RXCLIPS */
  584. #ifdef PATCH_RXVARS
  585.     {"RXVAR_",  VAR_RXX, 6, 6,     0, NULL,     setrexxvar,     getrexxvar},
  586. #endif /* PATCH_RXVARS */
  587.     {"KEY_",    VAR_MAP, 4, 4,VF_COP, NULL,     mapkey,         keyspectomacro},
  588.     {"MENU_",   VAR_MEN, 5, 5,VF_COP, NULL,     NULL,           menutomacro},
  589.     {NULL,    VAR_NEX, 0, 0,       0, NULL,    NULL, NULL}
  590. };
  591.  
  592.  
  593.  
  594. /*
  595. **  GetTypedVar()
  596. **    this function is nearly the same as getvar from cmd2.c
  597. **    major differences:
  598. **    * it tells where it has found a variable;
  599. **    * first we check if the search-name matches a certain
  600. **      type-prefix and if it does, we use that type and its
  601. **      result (w/out respect if result != NULL)
  602. **    * then we check all types until we get a non-NULL result
  603. **      or an abortion
  604. **    * the end of the vartypes-list means - there is no variable
  605. **      of that name
  606. **    (type may be NULL)
  607. */
  608.  
  609. char *
  610. GetTypedVar (char * find, int *  type)
  611. {
  612.     char  * found    = NULL;
  613.     int     itype    = VAR_NEX;
  614.     VTYPE * vt;
  615.     char    inter_abort = globalflags.Abortcommand;
  616.  
  617.     if (type)
  618.     *type = VAR_NEX;
  619.  
  620.     if (find == NULL)
  621.     {        /* is there a name ? */
  622.     abort (NULL);
  623.     } else
  624.     if (find[0] == '\0')
  625.     { /* is it really a name ? */
  626.     return (NULL);
  627.     } /* if name corrupt */
  628.  
  629.     globalflags.Abortcommand = 0;
  630.  
  631. /* if (globalflags.debug) printf("\tgetvar %s ? prefix...", find); */
  632.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  633.     {
  634. /* if (globalflags.debug) printf("p"); */
  635.     if (strncmp(find, vt->name, vt->len) == 0)
  636.     {
  637.         char* ptr = find+vt->offset;
  638.         if (vt->replace)
  639.         {
  640.         sprintf(tmp_buffer, vt->replace, ptr);
  641.         ptr = tmp_buffer;
  642.         } /* if prefix replacement */
  643.         itype = vt->id;
  644.         found = (*vt->do_get)(ptr);
  645.         if (found)
  646.         {
  647. /* if (globalflags.debug) printf(" found prefix %s\n", vt->name); */
  648.         if (vt->flags & VF_COP)
  649.         {
  650.             found = strdup(found);
  651.         } /* if dup'd */
  652.         } else
  653.         {
  654. /* if (globalflags.debug) printf ("Aborting\n"); */
  655.         globalflags.Abortcommand = 1;
  656.         } /* if res(!)=0 */
  657.         goto gv_quit;
  658.     } /* if matching prefix */
  659.     } /* for all types */
  660.  
  661. /* if (globalflags.debug) printf(" direct..."); */
  662.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  663.     {
  664. /* if (globalflags.debug) printf("c"); */
  665.     if (vt->do_get)
  666.     {
  667.         if (found = (*vt->do_get)(find))
  668.         {
  669. /* if (globalflags.debug) printf("found type %s\n", vt->name); */
  670.         itype = vt->id;
  671.         if (vt->flags & VF_COP)
  672.         {
  673.             found = strdup(found);
  674.         } /* if dup'd */
  675.         goto gv_quit;
  676.         } /* if res#0 */
  677.     } /* if ex det-func */
  678.     } /* for all types */
  679.  
  680. gv_quit:
  681.  
  682. /* if (globalflags.debug) printf("\tgetvar:prefix/err/oerr/val == %s/%d/%d/%s\n",vt->name, (int)Abortcommand, (int)inter_abort, found); */
  683.  
  684.     globalflags.Abortcommand |= inter_abort;
  685.     if (type)
  686.     {
  687.     *type = itype;
  688.     }
  689.     return(found);
  690. } /* GetTypedVar */
  691.  
  692.  
  693.  
  694. /*
  695. **  Set a Variable
  696. **    if it has a known type, use the associated set-command
  697. **    else check if there is a matching prefix
  698. **    if nothing fits - abort
  699. */
  700.  
  701. void
  702. SetTypedVar (char * name, char * value, int type)
  703. {
  704.     VTYPE* vt;
  705.  
  706.     if ((name == NULL) || (name[0] == '\0'))
  707.     { /* is it a name ? */
  708.     abort ();
  709.     } /* if name corrupt */
  710.  
  711.     if (type == VAR_NEX)
  712.     {
  713.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  714.     {
  715.         if (strncmp(name, vt->name, vt->len) == 0)
  716.         {
  717.         char* ptr = name+vt->offset;
  718. /* printf("setting ano type %s\n", vt->name); */
  719.         if (vt->do_set != NULL && name[vt->offset] != 0)
  720.         {
  721.             if (vt->replace)
  722.             {
  723.             sprintf(tmp_buffer, vt->replace, ptr);
  724.             ptr = tmp_buffer;
  725.             } /* if prefix replacement */
  726.             (*vt->do_set)(ptr, value);
  727.             return;
  728.         } else
  729.         {
  730.             abort();
  731.         } /* if (no) set-function */
  732.         } /* if matching prefix */
  733.     } /* for all types */
  734.     abort();
  735.     } /* if unknown type */
  736.  
  737.     for (vt = vartypes; vt->id != VAR_NEX; vt++)
  738.     {
  739.     if (vt->id == type)
  740.     {
  741.         if (vt->do_set)
  742.         {
  743. /* printf("setting ok type %s\n", vt->name); */
  744.         if (strncmp(name, vt->name, vt->len) == 0)
  745.         {
  746.             char* ptr = name+vt->offset;
  747.             if (vt->replace)
  748.             {
  749.             sprintf(tmp_buffer, vt->replace, ptr);
  750.             ptr = tmp_buffer;
  751.             } /* if prefix replacement */
  752.             (*vt->do_set)(ptr, value);
  753.         } else
  754.         {
  755.             (*vt->do_set)(name, value);
  756.         } /* if (no) matching prefix */
  757.         return;
  758.         } else
  759.         {
  760.         abort();
  761.         } /* if (no) set-function */
  762.     } /* if id found */
  763.     } /* for all types */
  764.  
  765.     abort();
  766. } /* SetTypedVar */
  767.  
  768.  
  769.  
  770. /*
  771. **  Search
  772. **  (1) special Variables (2) Flags (3) macro's list,
  773. **  (4) text's list, (5) internal list, (6) enviroment,
  774. **  (7) Rexx cliplist (8) macros.  The variable is allocated
  775. **  with malloc().  NULL if not found.  ENV: need not exist.
  776. */
  777.  
  778. char * getvar (char * find)
  779. {
  780.     return (GetTypedVar(find,NULL));
  781. } /* getvar */
  782.  
  783.  
  784. /******************************************************************************
  785. *****  END vars.c
  786. ******************************************************************************/
  787.