machdep.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (c) 1991 by the Vrije Universiteit, Amsterdam, the Netherlands.
  2. * For full copyright and restrictions on use see the file COPYING in the top
  3. * level of the LLgen tree.
  4. */
  5. /*
  6. * L L G E N
  7. *
  8. * An Extended LL(1) Parser Generator
  9. *
  10. * Author : Ceriel J.H. Jacobs
  11. */
  12. /*
  13. * machdep.c
  14. * Machine dependant things
  15. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. # include "types.h"
  21. #include "LLgen.h"
  22. /* In this file the following routines are defined: */
  23. void UNLINK(string x)
  24. {
  25. /* Must remove the file "x" */
  26. #ifdef USE_SYS
  27. sys_remove(x); /* systemcall to remove file */
  28. #else
  29. unlink(x);
  30. #endif
  31. }
  32. void RENAME(char *x, char *y) {
  33. /* Must move the file "x" to the file "y" */
  34. #ifdef USE_SYS
  35. if(! sys_rename(x,y)) fatal(1,"Cannot rename to %s",y);
  36. #else
  37. if (rename(x, y) == -1)
  38. fatal(1, "Cannot rename to %s", y, NULL);
  39. #endif
  40. }
  41. string
  42. libpath(s) string s; {
  43. /* Must deliver a full pathname to the library file "s" */
  44. register string p;
  45. int length;
  46. p_mem alloc();
  47. /* string strcpy(), strcat(); */
  48. char* libdir = getenv("LLGEN_LIB_DIR");
  49. if (!libdir)
  50. libdir = LIBDIR;
  51. length = strlen(libdir) + strlen(s) + 2;
  52. p = (string) alloc((unsigned) length);
  53. strcpy(p,libdir);
  54. strcat(p,"/");
  55. strcat(p,s);
  56. return p;
  57. }