exopen.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <stdlib.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. /*
  21. * allocate a new expression program environment
  22. */
  23. Expr_t*
  24. exopen(Exdisc_t* disc)
  25. {
  26. Expr_t* program;
  27. Exid_t* sym;
  28. if (!(program = calloc(1, sizeof(Expr_t))))
  29. return 0;
  30. program->symdisc.key = offsetof(Exid_t, name);
  31. if (!(program->symbols = dtopen(&program->symdisc, Dtset)) ||
  32. !(program->vm = vmopen()) ||
  33. !(program->ve = vmopen()))
  34. {
  35. exclose(program, 1);
  36. return 0;
  37. }
  38. program->id = "libexpr:expr";
  39. program->disc = disc;
  40. setcontext(program);
  41. program->file[0] = stdin;
  42. program->file[1] = stdout;
  43. program->file[2] = stderr;
  44. strcpy(program->main.name, "main");
  45. program->main.lex = PROCEDURE;
  46. program->main.index = PROCEDURE;
  47. dtinsert(program->symbols, &program->main);
  48. for (sym = exbuiltin; *sym->name; sym++)
  49. dtinsert(program->symbols, sym);
  50. if ((sym = disc->symbols))
  51. for (; *sym->name; sym++)
  52. dtinsert(program->symbols, sym);
  53. return program;
  54. }