sysvms.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #error No longer supported
  2. /* sysvms.c Copyright (C) 1989-92 Codemist Ltd */
  3. /*
  4. * Things that may usefully be rewritten in assembly code, or
  5. * that are heavily dependent on some particular computer
  6. * architecture or operating system. This file may need some
  7. * extension or adjustment (especially as regards optional compilation)
  8. * when new computers are tried.
  9. *
  10. */
  11. /* Signature: 0544d1a1 03-Feb-1999 */
  12. #include "machine.h"
  13. #include <stdarg.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include "tags.h"
  17. #include "externs.h"
  18. #ifdef TIMEOUT
  19. #include "timeout.h"
  20. #endif
  21. static void get_home_directory(char *b, int length);
  22. static void get_users_home_directory(char *b, int length);
  23. #include "filename.c"
  24. /*
  25. * This is a dummy definition of get_truename, here so that everything
  26. * will link. Both the calling convention used here and the exact
  27. * meaning and implementation may be under gentle review!
  28. */
  29. char *get_truename(char *filename, char *old, size_t n)
  30. {
  31. char *w;
  32. process_file_name(filename, old, n);
  33. if (*filename == 0)
  34. { aerror("truename");
  35. return NULL;
  36. }
  37. w = (char *)malloc(1+strlen(filename));
  38. if (w == NULL) return w;
  39. strcpy(w, filename);
  40. return w;
  41. }
  42. char *my_getenv(char *s)
  43. {
  44. return getenv(s);
  45. }
  46. int my_system(char *s)
  47. {
  48. return system(s);
  49. }
  50. /*
  51. * I do not expect that the following will work exactly unchanged
  52. * on all possible versions of Unix - e.g. header file names may need
  53. * altering and suchlike mess. But the idea should be reasonable and
  54. * changes when needed ought to be small.
  55. */
  56. static void get_home_directory(char *b, int length)
  57. {
  58. strcpy(b, getenv("HOME")); /* Probably works with most shells */
  59. }
  60. static void get_users_home_directory(char *b, int length)
  61. {
  62. strcpy(b, "."); /* use current directory if getpwnam() no available */
  63. }
  64. /*
  65. * This is a BSD-style clock facility, possibly giving a resolution of
  66. * only 1/100 second. I believe that Portable Standard Lisp typically
  67. * reports user time, which is why I do this. A further nasty here
  68. * is that I am probably compiling this file in ANSI mode, and on
  69. * at least some computers this makes #includ <sys/times.h> fairly
  70. * ineffective (ugh), so I declare all the structures and functions I
  71. * want directly (ugh ugh) and hope they are as needed. Consider this
  72. * when you port to a new machine.
  73. */
  74. unsigned long int read_clock(void)
  75. {
  76. struct my_tms {
  77. clock_t tms_utime;
  78. clock_t tms_stime;
  79. clock_t tms_cutime;
  80. clock_t tms_cstime;
  81. } tmsbuf;
  82. extern void times(/*struct my_tms * */);
  83. times(&tmsbuf);
  84. /*
  85. * Another dodgy assumption here - that times() reports in units of 1/100
  86. * second or 1/60 sec (as set up in the UNIX_TIMES macro). The curious
  87. * division here either does t/10/10 or t/6/10 but in either case ought not
  88. * to mangle the rounding too much.
  89. */
  90. return (tmsbuf.tms_utime*((10*UNIX_TIMES)/100))/10;
  91. }
  92. int batchp()
  93. {
  94. return !isatty(fileno(stdin));
  95. }
  96. /*
  97. * The next procedure is responsible for establishing information about
  98. * where the main checkpoint image should be recovered from, and where
  99. * and fasl files should come from.
  100. */
  101. char *find_image_directory(int argc, char *argv[])
  102. {
  103. char image[LONGEST_LEGAL_FILENAME];
  104. char pgmname[LONGEST_LEGAL_FILENAME];
  105. char *w;
  106. if (argc > 0 && argv[0] != NULL)
  107. { int i;
  108. strcpy(image, argv[0]);
  109. w = &image;
  110. i = strlen(w);
  111. while (i > 0 && w[i] != ']') i--;
  112. if (i <= 0)
  113. { printf("argv[0] contains no ']' character\n");
  114. exit(EXIT_FAILURE);
  115. }
  116. w[i] = '.';
  117. do i++; while (w[i] != '.');
  118. sprintf(&w[i], "img]");
  119. }
  120. else sprintf(image, "[cslimg]");
  121. /*
  122. * I copy from local vectors into malloc'd space to hand my
  123. * answer back.
  124. */
  125. w = (char *)malloc(1+strlen(image));
  126. /*
  127. * The error exit here seem unsatisfactory...
  128. */
  129. if (w == NULL)
  130. { fprintf(stderr, "\n+++ Panic - run out of space\n");
  131. exit(EXIT_FAILURE);
  132. }
  133. strcpy(w, image);
  134. return w;
  135. }
  136. int truncate_file(FILE *f, long int where)
  137. {
  138. if (fflush(f) != 0) return 1;
  139. return ftruncate(fileno(f), where); /* Returns zero if successs */
  140. }
  141. /* end of sysvms.c */