sys.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /* sys.h Copyright (C) 1992 Codemist Ltd */
  2. /* Signature: 25331224 07-Mar-2000 */
  3. /*
  4. * This file should contain a list of all the functions in CSL that have
  5. * to be provided on a per-host basis.
  6. */
  7. #ifndef header_sys_h
  8. #define header_sys_h 1
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /*
  13. * find_image_directory is handed the information that main() sees when
  14. * the application is started up, and it returns a string (in freshly
  15. * malloc'd space) that is the default name for the checkpoint image file
  16. * to be used for this run.
  17. */
  18. extern char *find_image_directory(int argc, char *argv[]);
  19. /*
  20. * open_file accepts a vector of characters (old) and looks at the first
  21. * (n) of them. This is taken as a CSL filename - it is subject (possibly)
  22. * to adjustments, the expanded name is copied to the array (filename) and an
  23. * attempt is made to open a file. (mode) is a string (like "r", "w" or "r+b")
  24. * suitable for handing to the C "fopen" function to specify a mode, and
  25. * if (old_file) is non-NULL we should do an freopen() rather than fopen().
  26. * The main intent in filename conversion as supported here is to allow
  27. * users on all machines to use Unix-like file-names to at least some
  28. * minimal extent, so names like "subdir/file.lsp" should be allowed, even
  29. * if in native mode the computer used uses some quite different way of
  30. * specifying sub-directories and file-extensions.
  31. */
  32. extern FILE *open_file(char *filename, char *old, size_t n,
  33. char *mode, FILE *old_file);
  34. /*
  35. * find if a file exists, and if it does return (as 24 chars) the
  36. * change time for it. See open_file re args.
  37. */
  38. extern CSLbool file_exists(char *filename, char *old, size_t n, char *tt);
  39. /*
  40. * The interfaces to create_directory and delete_file are similar
  41. * to that for open_file. They do what their names suggest! They return
  42. * zero on success, and non-zero on failure. Each does file-name
  43. * conversion so that Unix-style names can be used even with Windows.
  44. */
  45. extern int create_directory(char *filename, char *old, size_t n);
  46. extern int delete_file(char *filename, char *old, size_t n);
  47. extern int rename_file(char *from_name, char *from_old, size_t from_size,
  48. char *to_name, char *to_old, size_t to_size);
  49. /*
  50. * The interfaces to file_readable and file_writable are also similar
  51. * to that for open_file. They return 1 if their argument can be opened
  52. * for reading or writing respectively, and 0 otherwise. directoryp tests
  53. * whether its argument is a directory.
  54. */
  55. extern int file_readable(char *filename, char *old, size_t n);
  56. extern int file_writeable(char *filename, char *old, size_t n);
  57. extern int directoryp(char *filename, char *old, size_t n);
  58. /*
  59. * current_directory() places the name of the current directory in the buffer
  60. * which has the indicated size, and returns 0 for failure or otherwise
  61. * the length of data written.
  62. */
  63. extern int current_directory(char *name, int len);
  64. /*
  65. * The next three are much-like the same... On some operating systems
  66. * they will be pretty meaningless!
  67. */
  68. extern int get_current_directory(char *name, int len);
  69. extern int get_home_directory(char *name, int len);
  70. extern int get_users_home_directory(char *name, int len);
  71. extern int change_directory(char *filename, char *old, size_t n);
  72. /*
  73. * get_truename attempts to get a canonical name for a file or directory.
  74. * It returns a string. If unable to do anything useful it can just
  75. * return a copy of its input, but the result is expected to be a
  76. * freshly allocated block of memory and should be handed to free() after
  77. * it has been used. This interface using malloc() should be changed at
  78. * some stage so that the caller passes down a buffer for the result to
  79. * be placed in (what is arg1 for anyway).
  80. * This comment also needs to be expanded to explain in a little more detail
  81. * what a "canonical" name for a file or directory is - eg whether the
  82. * intent is to allow wildcard inputs or whether this function is
  83. * expected to convert from a relative file-name into a fully rooted one.
  84. */
  85. extern char *get_truename(char *filename, char *old, size_t n);
  86. #ifdef NAG_VERSION
  87. /*
  88. * list_directory_members allocates (using malloc) both a vector
  89. * (of type char **) and a load of strings to go in there, and updates
  90. * filelist to point at it. The caller must free() the space at some
  91. * later stage.
  92. */
  93. extern int list_directory_members(char *filename, char *old, char **filelist[],
  94. size_t n);
  95. #else
  96. /*
  97. * list_directory_members calls the given callback function handing it
  98. * the name of each file in given directory.
  99. */
  100. typedef void directory_callback(char *, int, long int);
  101. extern void list_directory_members(char *filename, char *old,
  102. size_t n, directory_callback *fn);
  103. #endif
  104. /*
  105. * (f) is an open file - truncate it at position (where).
  106. */
  107. extern int truncate_file(FILE *f, long int where);
  108. /*
  109. * If I am to process directories I need a set of routines that will
  110. * scan sub-directories for me. The specification I want is:
  111. * int scan_directory(char *dir,
  112. * void (*proc)(char *name, int why, int32 size));
  113. *
  114. * This is called with a file- or directory-name as its first argument
  115. * and a function as its second.
  116. * It calls the function for every directory and every file that can be found
  117. * rooted from the given place. If the file to scan is specified as NULL
  118. * the current directory is processed.
  119. * When a simple file is found the procedure is called with the name of the
  120. * file, why=0, and the length (in bytes) of the file. For a directory
  121. * the function is called with why=1, then the contents of the directory are
  122. * processed. For directories the size information will be 0. There is no
  123. * guarantee of useful behaviour if some of the files to be scanned are
  124. * flagged as "invisible" or "not readable" or if they are otherwise special.
  125. * The value returned is the number of characters that should be removed
  126. * the start of file-names returned to get rid of any initial directory
  127. * specified. If dir is passed as NULL this will be zero and names will
  128. * come back plain, otherwise it will be 1+strlen(dir)
  129. */
  130. #define SCAN_FILE 0
  131. #define SCAN_STARTDIR 1
  132. #define SCAN_ENDDIR 2
  133. extern void scan_directory(char *dir,
  134. void (*proc)(char *name, int why, long int size));
  135. /*
  136. * When scan_directory calls the procedure it has been passed, it will have
  137. * set scan_leafstart to the offset in the passed filename where the
  138. * original directory ended and the new information starts. Thus if the
  139. * input string was (say) "/usr/users/acn/xxx" and some particular sub-file
  140. * was reported as "/usr/users/acn/xxx/subdir/subfile.ext" then
  141. * (name+scan_leafstart) gives the relative name "subdir/subfile.ext".
  142. */
  143. extern int scan_leafstart;
  144. /*
  145. * scan_files() is just like scan_directory() excepr that it does not
  146. * recurse into sub-directories.
  147. */
  148. extern void scan_files(char *dir,
  149. void (*proc)(char *name, int why, long int size));
  150. extern void unpack_date(unsigned long int r,
  151. int *year, int *mon, int *day,
  152. int *hour, int *min, int *sec);
  153. extern unsigned long int pack_date(int year, int mon, int day,
  154. int hour, int min, int sec);
  155. typedef struct date_and_type
  156. {
  157. unsigned long int date;
  158. unsigned long int type;
  159. } date_and_type;
  160. /* Reinstate date and filetype... */
  161. extern void set_filedate(char *name, unsigned long int datestamp,
  162. unsigned long int ftype);
  163. extern void put_fileinfo(date_and_type *p, char *name);
  164. /*
  165. * my_getenv() is much like the ANSI getenv(), but exists because
  166. * it may be useful to perform mappings on the character string given
  167. * (e.g. to fold case) before calling the built-in getenv().
  168. */
  169. extern char *my_getenv(char *s);
  170. /*
  171. * my_system is just like the ANSI function system() - done this way to
  172. * allow for machines where this is not available or where more work is
  173. * needed.
  174. */
  175. extern int my_system(char *s);
  176. #ifdef PIPES
  177. /*
  178. * my_popen() and my_pclose() are intended to be just like the Unix
  179. * popen() and pclose functions.
  180. */
  181. extern FILE *my_popen(char *command_name, char *direction);
  182. extern void my_pclose(FILE *stream);
  183. #endif
  184. #ifdef SIMULATED_PIPES
  185. /*
  186. * For RISCOS (at least) I send characters to a pipe (possibly
  187. * only used to support the gnuplot package) through a separate
  188. * special function as documented here.
  189. */
  190. extern int my_pipe_putc(int c, FILE *f);
  191. extern int my_pipe_flush(FILE *f);
  192. #else
  193. # define my_pipe_putc(c, f) putc(c, f)
  194. # define my_pipe_flush(f) fflush(f)
  195. #endif
  196. #ifdef PIPES_SOMETIMES
  197. /*
  198. * If I have an operating system where the presence of pipes is
  199. * conditional, this variable is used to keep track.
  200. */
  201. extern int pipes_today;
  202. #endif
  203. /*
  204. * batchp() should return true if stdin is NOT from an interactive
  205. * terminal.
  206. */
  207. extern int batchp(void);
  208. #ifdef UNIX_TIMES
  209. /*
  210. * The intent here is that if UNIX_TIMES is set then the CPU times
  211. * reported to the user will be "user time" and will not include
  212. * "system time", as in using the Unix "times" facility. If UNIX_TIMES
  213. * is not defined no special code in sysxxx.c is needed.
  214. */
  215. extern clock_t read_clock(void);
  216. #else
  217. # define read_clock() clock()
  218. #endif
  219. #ifdef SHOW_COUNTS_AVAILABLE
  220. /*
  221. * show_counts() can be called via mapstore(), and would be expected to
  222. * display some information relating to how many times each chunk of
  223. * C code has been executed - possibly only when the C coded parts of CSL have
  224. * been compiled with some special profile option. write_profile is
  225. * similar in style, but sends output to a file. If you do not have
  226. * statistics gathering facilities you do not need these implemented.
  227. */
  228. extern void show_counts(void);
  229. extern void write_profile(char *filename);
  230. #endif
  231. /*
  232. * Imultiply and Idivide are things that you may want to re-implement in
  233. * machine code - if so here are their signatures, and you should #define
  234. * IMULTIPLY/IDIVIDE in machine.h to say what you have done. See arithXX.c
  235. * for the portable versions.
  236. */
  237. #ifdef _MSC_VER
  238. /*
  239. * Apologies here: For Microsoft VC++ I need to define these as __stdcall
  240. * (and certainly NOT as __fastcall) because Microsoft potentially change
  241. * which registers are used with __fastcall from release to release of
  242. * their compiler.
  243. */
  244. #ifdef IMULTIPLY
  245. extern unsigned32 __stdcall Imultiply(unsigned32 *rlow, unsigned32 a,
  246. unsigned32 b, unsigned32 c);
  247. #endif
  248. #ifdef IDIVIDE
  249. extern unsigned32 __stdcall Idivide(unsigned32 *qp, unsigned32 a,
  250. unsigned32 b, unsigned32 c);
  251. extern unsigned32 __stdcall Idiv10_9(unsigned32 *qp, unsigned32 a, unsigned32 b);
  252. #endif
  253. #else
  254. #ifdef IMULTIPLY
  255. extern unsigned32 Imultiply(unsigned32 *rlow, unsigned32 a,
  256. unsigned32 b, unsigned32 c);
  257. #endif
  258. #ifdef IDIVIDE
  259. extern unsigned32 Idivide(unsigned32 *qp, unsigned32 a,
  260. unsigned32 b, unsigned32 c);
  261. extern unsigned32 Idiv10_9(unsigned32 *qp, unsigned32 a, unsigned32 b);
  262. #endif
  263. #endif
  264. #ifdef TICK_STREAM
  265. /*
  266. * add_ticker() starts a steady(-ish) stream of clock pulses going,
  267. * and causes (indirectly) accept_tick() to be called in a regular basis.
  268. * These are used to help me with interfaces to window systems, and to
  269. * make responses to keyboard interrupts more friendly and reliable.
  270. */
  271. extern void add_ticker(void);
  272. /*
  273. * remove_ticker() switches tick-events off. Best if it is legal to
  274. * call remove_ticker even if ticks are not active.
  275. */
  276. extern void MS_CDECL remove_ticker(void);
  277. extern void accept_tick(void);
  278. #endif
  279. #ifdef POLL_FOR_ATTN
  280. /*
  281. * Used by MSDOS system to check if ^C has been pressed - see gc.c
  282. * and read.c for the only calls. Arg decides if it waits until some
  283. * input is ready.
  284. */
  285. extern void poll_for_attn(void);
  286. #endif
  287. /*
  288. * When the garbage collector observes that memory is tight it can attempt
  289. * to allocate more by going back to malloc(). This function is called with
  290. * an argument that indicates how many pages are in use at present, and it
  291. * is expected to return an indication of how many more might be worth
  292. * allocating. See the code in gc.c for details of usage.
  293. */
  294. int32 ok_to_grab_memory(int32 current_pages);
  295. #ifdef WINDOW_SYSTEM
  296. /*
  297. * start_up_window_manager is called after command-line options have been
  298. * decoded - and hence after any flags that might influence the character
  299. * of windowed use of the system have been set.
  300. */
  301. extern void start_up_window_manager(int use_wimp);
  302. /*
  303. * The next represents the only way in which characters will be
  304. * sent to the screen - in the case of WINDOW_SYSTEM it write to the
  305. * screen. Possibly this is more complicated than just writing to stdout.
  306. */
  307. extern void putc_stdout(int c);
  308. /*
  309. * flush_screen() tries to make sure that the display is up to date.
  310. */
  311. extern void flush_screen(void);
  312. /*
  313. * I may want to redirect stdout to a file, in which case the following
  314. * is the handle that I will use. See "--" decoding in csl.c
  315. */
  316. extern FILE *alternative_stdout;
  317. /*
  318. * Ditto reading from stdin. Reads chars into buffer, returns count.
  319. */
  320. extern int wimpget(char *buf);
  321. /*
  322. * The next two call-backs tell the window manager how much time has
  323. * been spent and how many garbage collections have been done.
  324. */
  325. extern void report_time(int32 t, int32 gct);
  326. extern void report_space(int gccount, double percent);
  327. /*
  328. * pause_for_user() gets called right at the end to give a chance for the
  329. * system to delay before closing the main output window.
  330. */
  331. extern void pause_for_user(void);
  332. #endif
  333. #ifdef WINDOWS_NT
  334. /*
  335. * Am I in Win32S rather than full Win32?
  336. * The values I will use will be
  337. * 0 Windows NT
  338. * 1 win32s on top of Windows 3.x
  339. * 2 Windows 95
  340. */
  341. extern int win32s;
  342. #endif
  343. #ifdef __cplusplus
  344. }
  345. #endif
  346. #endif /* header_sys_h */
  347. /* end of sys.h */