sysvms.c 5.0 KB

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