machdep.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <stdlib.h>
  17. #include <string.h>
  18. # include "types.h"
  19. # ifndef NORCSID
  20. static string rcsid5 = "$Id$";
  21. # endif
  22. /* In this file the following routines are defined: */
  23. extern UNLINK();
  24. extern RENAME();
  25. extern string libpath();
  26. UNLINK(x) string x; {
  27. /* Must remove the file "x" */
  28. #ifdef USE_SYS
  29. sys_remove(x); /* systemcall to remove file */
  30. #else
  31. unlink(x);
  32. #endif
  33. }
  34. RENAME(x,y) string x,y; {
  35. /* Must move the file "x" to the file "y" */
  36. #ifdef USE_SYS
  37. if(! sys_rename(x,y)) fatal(1,"Cannot rename to %s",y);
  38. #else
  39. unlink(y);
  40. if (link(x,y) != 0) fatal(1,"Cannot rename to %s",y);
  41. unlink(x);
  42. #endif
  43. }
  44. string
  45. libpath(s) string s; {
  46. /* Must deliver a full pathname to the library file "s" */
  47. register string p;
  48. register length;
  49. p_mem alloc();
  50. string strcpy(), strcat();
  51. char* libdir = getenv("LLGEN_LIB_DIR");
  52. if (!libdir)
  53. libdir = LIBDIR;
  54. length = strlen(libdir) + strlen(s) + 2;
  55. p = (string) alloc((unsigned) length);
  56. strcpy(p,libdir);
  57. strcat(p,"/");
  58. strcat(p,s);
  59. return p;
  60. }