| | 1 | /* |
| | 2 | $Header: d:/cvsroot/tads/TADS2/LINF.H,v 1.3 1999/07/11 00:46:30 MJRoberts Exp $ |
| | 3 | */ |
| | 4 | |
| | 5 | /* |
| | 6 | * Copyright (c) 1991, 2002 Michael J. Roberts. All Rights Reserved. |
| | 7 | * |
| | 8 | * Please see the accompanying license file, LICENSE.TXT, for information |
| | 9 | * on using and copying this software. |
| | 10 | */ |
| | 11 | /* |
| | 12 | Name |
| | 13 | linf.h - line source File |
| | 14 | Function |
| | 15 | Defines the file line source |
| | 16 | Notes |
| | 17 | The file line source reads lines from an OS file. |
| | 18 | Modified |
| | 19 | 08/14/91 MJRoberts - creation |
| | 20 | */ |
| | 21 | |
| | 22 | #ifndef LINF_INCLUDED |
| | 23 | #define LINF_INCLUDED |
| | 24 | |
| | 25 | #include <stdio.h> |
| | 26 | |
| | 27 | #ifndef STD_INCLUDED |
| | 28 | #include "std.h" |
| | 29 | #endif |
| | 30 | #ifndef OS_INCLUDED |
| | 31 | #include "os.h" |
| | 32 | #endif |
| | 33 | #ifndef LIN_INCLUDED |
| | 34 | #include "lin.h" |
| | 35 | #endif |
| | 36 | #ifndef OBJ_INCLUDED |
| | 37 | #include "obj.h" |
| | 38 | #endif |
| | 39 | #ifndef MCM_INCLUDED |
| | 40 | #include "mcm.h" |
| | 41 | #endif |
| | 42 | #ifndef TOK_INCLUDED |
| | 43 | #include "tok.h" |
| | 44 | #endif |
| | 45 | |
| | 46 | #ifdef __cplusplus |
| | 47 | extern "C" { |
| | 48 | #endif |
| | 49 | |
| | 50 | /* maximum number of pages of debugging records we can keep */ |
| | 51 | #define LINFPGMAX 128 |
| | 52 | |
| | 53 | /* |
| | 54 | * executable line information structure: this record relates one |
| | 55 | * executable line to the object containing the p-code, and the offset |
| | 56 | * in the object of the p-code for the start of the line |
| | 57 | */ |
| | 58 | struct linfinfo |
| | 59 | { |
| | 60 | /* |
| | 61 | * OPCLINE data (file seek position or line number, depending on how |
| | 62 | * the game was compiled: -ds -> file seek offset, -ds2 -> line |
| | 63 | * number) |
| | 64 | */ |
| | 65 | ulong fpos; |
| | 66 | |
| | 67 | /* object number */ |
| | 68 | objnum objn; |
| | 69 | |
| | 70 | /* offset from start of code */ |
| | 71 | uint ofs; |
| | 72 | }; |
| | 73 | |
| | 74 | /* |
| | 75 | * file line source |
| | 76 | */ |
| | 77 | struct linfdef |
| | 78 | { |
| | 79 | lindef linflin; /* superclass data */ |
| | 80 | osfildef *linffp; /* file pointer for this line source */ |
| | 81 | char linfbuf[100]; /* buffer for the line contents */ |
| | 82 | int linfbufnxt; /* offset in buffer of start of next line */ |
| | 83 | int linfnxtlen; /* length of data after linfbufnxt */ |
| | 84 | ulong linfnum; /* current line number */ |
| | 85 | ulong linfseek; /* seek position of current line */ |
| | 86 | mcmcxdef *linfmem; /* memory manager context */ |
| | 87 | mcmon linfpg[LINFPGMAX]; /* pages for debugging records */ |
| | 88 | ulong linfcrec; /* number of debugger records written so far */ |
| | 89 | char linfnam[1]; /* name of file being read */ |
| | 90 | }; |
| | 91 | typedef struct linfdef linfdef; |
| | 92 | |
| | 93 | /* initialize a file line source, opening the file for the line source */ |
| | 94 | linfdef *linfini(mcmcxdef *mctx, errcxdef *errctx, char *filename, |
| | 95 | int flen, struct tokpdef *path, int must_find_file, |
| | 96 | int new_line_records); |
| | 97 | |
| | 98 | /* initialize a pre-allocated linfdef, skipping debugger page setup */ |
| | 99 | void linfini2(mcmcxdef *mctx, linfdef *linf, |
| | 100 | char *filename, int flen, osfildef *fp, int new_line_records); |
| | 101 | |
| | 102 | /* get next line from line source */ |
| | 103 | int linfget(lindef *lin); |
| | 104 | |
| | 105 | /* generate printable rep of current position in source (for errors) */ |
| | 106 | void linfppos(lindef *lin, char *buf, uint bufl); |
| | 107 | |
| | 108 | /* close line source */ |
| | 109 | void linfcls(lindef *lin); |
| | 110 | |
| | 111 | /* generate source-line debug instruction operand */ |
| | 112 | void linfglop(lindef *lin, uchar *buf); |
| | 113 | |
| | 114 | /* generate new-style source-line debug instructino operand */ |
| | 115 | void linfglop2(lindef *lin, uchar *buf); |
| | 116 | |
| | 117 | /* save line source to binary (.gam) file */ |
| | 118 | int linfwrt(lindef *lin, osfildef *fp); |
| | 119 | |
| | 120 | /* load a file-line-source from binary (.gam) file */ |
| | 121 | int linfload(osfildef *fp, struct dbgcxdef *dbgctx, errcxdef *ec, |
| | 122 | struct tokpdef *path); |
| | 123 | |
| | 124 | /* add a debugger line record for the current line */ |
| | 125 | void linfcmp(lindef *lin, uchar *buf); |
| | 126 | |
| | 127 | /* find nearest line record to a file seek location */ |
| | 128 | void linffind(lindef *lin, char *buf, objnum *objp, uint *ofsp); |
| | 129 | |
| | 130 | /* activate line source for debugging */ |
| | 131 | void linfact(lindef *lin); |
| | 132 | |
| | 133 | /* disactivate line source */ |
| | 134 | void linfdis(lindef *lin); |
| | 135 | |
| | 136 | /* get current seek position */ |
| | 137 | void linftell(lindef *lin, uchar *pos); |
| | 138 | |
| | 139 | /* seek */ |
| | 140 | void linfseek(lindef *lin, uchar *pos); |
| | 141 | |
| | 142 | /* read */ |
| | 143 | int linfread(lindef *lin, uchar *buf, uint siz); |
| | 144 | |
| | 145 | /* add a signed delta to a seek positon */ |
| | 146 | void linfpadd(lindef *lin, uchar *pos, long delta); |
| | 147 | |
| | 148 | /* query whether at top of file */ |
| | 149 | int linfqtop(lindef *lin, uchar *pos); |
| | 150 | |
| | 151 | /* read one line at current seek position */ |
| | 152 | int linfgets(lindef *lin, uchar *buf, uint bufsiz); |
| | 153 | |
| | 154 | /* get name of line source */ |
| | 155 | void linfnam(lindef *lin, char *buf); |
| | 156 | |
| | 157 | /* get the current line number */ |
| | 158 | ulong linflnum(lindef *lin); |
| | 159 | |
| | 160 | /* go to top or bottom */ |
| | 161 | void linfgoto(lindef *lin, int where); |
| | 162 | |
| | 163 | /* return the current offset in the line source */ |
| | 164 | long linfofs(lindef *lin); |
| | 165 | |
| | 166 | /* renumber an object */ |
| | 167 | void linfren(lindef *lin, objnum oldnum, objnum newnum); |
| | 168 | |
| | 169 | /* delete an object */ |
| | 170 | void linfdelnum(lindef *lin, objnum objn); |
| | 171 | |
| | 172 | /* copy line records to an array of linfinfo structures */ |
| | 173 | void linf_copy_linerecs(linfdef *linf, struct linfinfo *info); |
| | 174 | |
| | 175 | /* debugging echo */ |
| | 176 | #ifdef DEBUG |
| | 177 | # define LINFDEBUG(x) x |
| | 178 | #else /* DEBUG */ |
| | 179 | # define LINFDEBUG(x) |
| | 180 | #endif /* DEBUG */ |
| | 181 | |
| | 182 | #ifdef __cplusplus |
| | 183 | } |
| | 184 | #endif |
| | 185 | |
| | 186 | #endif /* LINF_INCLUDED */ |