exexpr.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. /*
  11. * Glenn Fowler
  12. * AT&T Research
  13. *
  14. * expression library
  15. */
  16. #include <expr/exlib.h>
  17. #include <stddef.h>
  18. /*
  19. * return the expression for name or sym coerced to type
  20. */
  21. Exnode_t*
  22. exexpr(Expr_t* ex, const char* name, Exid_t* sym, int type)
  23. {
  24. if (ex)
  25. {
  26. if (!sym)
  27. sym = name ? dtmatch(ex->symbols, name) : &ex->main;
  28. if (sym && sym->lex == PROCEDURE && sym->value)
  29. {
  30. if (type != DELETE_T)
  31. return excast(ex, sym->value->data.procedure.body, type, NULL, 0);
  32. exfreenode(ex, sym->value);
  33. sym->lex = NAME;
  34. sym->value = 0;
  35. }
  36. }
  37. return 0;
  38. }
  39. /**
  40. * @dir lib/expr
  41. * @brief expression library for lib/gvpr/, API expr.h
  42. */