|
|
1.1 ! root 1: /* ! 2: *-IMPORTS: ! 3: * <sys/compat.h> ! 4: * CONST ! 5: * LOCAL ! 6: * USE_PROTO ! 7: * ARGS () ! 8: * <stdlib.h> ! 9: * NULL ! 10: * malloc () ! 11: * free () ! 12: */ ! 13: ! 14: #include <sys/compat.h> ! 15: #include <stdlib.h> ! 16: ! 17: #include "ehand.h" ! 18: #include "symbol.h" ! 19: #include "read.h" ! 20: #include "input.h" ! 21: ! 22: #include "mtune.h" ! 23: ! 24: LOCAL mtune_t * _mtunes; ! 25: ! 26: ! 27: /* ! 28: * Locate a parameter definition by symbol. ! 29: */ ! 30: ! 31: #if USE_PROTO ! 32: mtune_t * (find_mtune) (symbol_t * sym) ! 33: #else ! 34: mtune_t * ! 35: find_mtune ARGS ((sym)) ! 36: symbol_t * sym; ! 37: #endif ! 38: { ! 39: mtune_t * scan; ! 40: ! 41: for (scan = _mtunes ; scan != NULL ; scan = scan->mt_next) { ! 42: ! 43: if (scan->mt_name == sym) ! 44: return scan; ! 45: } ! 46: ! 47: return NULL; ! 48: } ! 49: ! 50: ! 51: /* ! 52: * Regenerate an 'mtune' line from the stored record. ! 53: */ ! 54: ! 55: #if USE_PROTO ! 56: void (write_mtune) (mtune_t * mtunep, input_t * input) ! 57: #else ! 58: void ! 59: write_mtune ARGS ((mtunep, input)) ! 60: mtune_t * mtunep; ! 61: input_t * input; ! 62: #endif ! 63: { ! 64: if ((* input->in_filter) (input, "%s<2>%ld<3>%ld<4>%ld\n", ! 65: mtunep->mt_name->s_data, mtunep->mt_min, ! 66: mtunep->mt_default, mtunep->mt_max) < 0) { ! 67: ! 68: throw_error ("Output error"); ! 69: } ! 70: } ! 71: ! 72: ! 73: /* ! 74: * Read lines from an "mtune" file. ! 75: */ ! 76: ! 77: #if USE_PROTO ! 78: LOCAL mtune_t * (read_mtune) (input_t * input, lex_t * lexp, int * end_char) ! 79: #else ! 80: LOCAL mtune_t * ! 81: read_mtune ARGS ((input, lexp, end_char)) ! 82: input_t * input; ! 83: lex_t * lexp; ! 84: int * end_char; ! 85: #endif ! 86: { ! 87: VOLATILE int ch = '\n'; ! 88: mtune_t * VOLATILE mtunep; ! 89: ehand_t err; ! 90: ! 91: if ((mtunep = (mtune_t *) malloc (sizeof (* mtunep))) == NULL) ! 92: throw_error ("out of memory in read_mtune ()"); ! 93: ! 94: if (PUSH_HANDLER (err) == 0) { ! 95: /* ! 96: * If the first thing on the line works out to be an EOF, ! 97: * then bail out without an error. ! 98: */ ! 99: ! 100: ch = read_symbol (input, lexp, & mtunep->mt_name); ! 101: ! 102: if (mtunep->mt_name == NULL) { ! 103: /* ! 104: * We allow an EOF at the beginning of a line and we ! 105: * also allow a blank line. ! 106: */ ! 107: ! 108: free (mtunep); ! 109: mtunep = NULL; ! 110: goto at_eof; ! 111: } ! 112: check_not_eol (ch); ! 113: ! 114: if (mtunep->mt_name->s_size > MAX_PARAMNAME) ! 115: throw_error ("parameter name must be <= %d characters", ! 116: MAX_PARAMNAME); ! 117: ! 118: /* ! 119: * Pull in the parameter values ! 120: */ ! 121: ! 122: ch = read_longs (input, lexp, & mtunep->mt_min, NO_RANGE); ! 123: check_not_eol (ch); ! 124: ! 125: ch = read_longs (input, lexp, & mtunep->mt_default, NO_RANGE); ! 126: check_not_eol (ch); ! 127: ! 128: ch = read_longs (input, lexp, & mtunep->mt_max, NO_RANGE); ! 129: ch = expect_eol (input, lexp, ch); ! 130: ! 131: mtunep->mt_stune = NULL; ! 132: } else { ! 133: ! 134: free (mtunep); ! 135: CHAIN_ERROR (err); ! 136: } ! 137: ! 138: at_eof: ! 139: POP_HANDLER (err); ! 140: ! 141: * end_char = ch; ! 142: return mtunep; ! 143: } ! 144: ! 145: ! 146: /* ! 147: * This function is passed as a parameter to read_dev_string () to read an ! 148: * 'mtune' entry (usually a program argument) and hook it into a global list. ! 149: */ ! 150: ! 151: #if USE_PROTO ! 152: LOCAL int _read_mtune_string (input_t * input, lex_t * lexp, ! 153: mtune_t ** mtlistp) ! 154: #else ! 155: LOCAL int ! 156: _read_mtune_string (input, lexp, mtlistp) ! 157: input_t * input; ! 158: lex_t * lexp; ! 159: mtune_t ** mtlistp; ! 160: #endif ! 161: { ! 162: mtune_t * mtunep; ! 163: int ch; ! 164: ! 165: if ((mtunep = read_mtune (input, lexp, & ch)) != NULL) { ! 166: mtunep->mt_next = * mtlistp; ! 167: * mtlistp = mtunep; ! 168: } ! 169: ! 170: return ch; ! 171: } ! 172: ! 173: ! 174: /* ! 175: * This function is used by _read_mtune_file () to link an mtune entry into ! 176: * the global lists and check it. ! 177: */ ! 178: ! 179: #if USE_PROTO ! 180: LOCAL void (link_mtune) (mtune_t * mtunep, input_t * input) ! 181: #else ! 182: LOCAL void ! 183: link_mtune ARGS ((mtunep, input)) ! 184: mtune_t * mtunep; ! 185: input_t * input; ! 186: #endif ! 187: { ! 188: if (find_mtune (mtunep->mt_name) != NULL) ! 189: throw_error ("tunable parameter name must be unique"); ! 190: ! 191: mtunep->mt_next = _mtunes; ! 192: _mtunes = mtunep; ! 193: ! 194: write_mtune (mtunep, input); ! 195: } ! 196: ! 197: ! 198: /* ! 199: * This function is passed as a parameter to read_dev_file () to read an ! 200: * 'mtune' entry and link it in to the global list. ! 201: */ ! 202: ! 203: #if USE_PROTO ! 204: LOCAL int _read_mtune_file (input_t * input, lex_t * lexp, ! 205: mtune_t ** changes) ! 206: #else ! 207: LOCAL int ! 208: _read_mtune_file (input, lexp, changes) ! 209: input_t * input; ! 210: lex_t * lexp; ! 211: mtune_t ** changes; ! 212: #endif ! 213: { ! 214: mtune_t * mtunep; ! 215: int ch; ! 216: ! 217: if ((mtunep = read_mtune (input, lexp, & ch)) == NULL) { ! 218: if (ch == READ_EOF) { ! 219: /* ! 220: * Blow remaining changes out as new entries ! 221: */ ! 222: ! 223: while ((mtunep = * changes) != NULL) { ! 224: * changes = mtunep->mt_next; ! 225: link_mtune (mtunep, input); ! 226: } ! 227: } ! 228: return ch; ! 229: } ! 230: ! 231: ! 232: /* ! 233: * Link in the newly-read entry. ! 234: */ ! 235: ! 236: if (changes) { ! 237: mtune_t ** scan; ! 238: ! 239: for (scan = changes ; * scan != NULL ; ! 240: scan = & (* scan)->mt_next) { ! 241: ! 242: if ((* scan)->mt_name == mtunep->mt_name) { ! 243: /* ! 244: * Our current entry is being replaced by a ! 245: * new one; unlink the new entry from the ! 246: * change list and discard the old entry. ! 247: */ ! 248: ! 249: free (mtunep); ! 250: ! 251: if (report_mode ()) ! 252: return ch; ! 253: ! 254: mtunep = * scan; ! 255: * scan = mtunep->mt_next; ! 256: break; ! 257: } ! 258: } ! 259: } ! 260: ! 261: link_mtune (mtunep, input); ! 262: return ch; ! 263: } ! 264: ! 265: ! 266: /* ! 267: * Return the head of the list of all tuneable parameters. ! 268: */ ! 269: ! 270: #if USE_PROTO ! 271: mtune_t * (mtunes) (void) ! 272: #else ! 273: mtune_t * ! 274: mtunes ARGS (()) ! 275: #endif ! 276: { ! 277: return _mtunes; ! 278: } ! 279: ! 280: ! 281: /* ! 282: * Read in an "mtune" entry from a string and add it to a list. ! 283: */ ! 284: ! 285: #if USE_PROTO ! 286: void read_mtune_string (CONST char * string, VOID * extra) ! 287: #else ! 288: void ! 289: read_mtune_string (string, extra) ! 290: CONST char * string; ! 291: VOID * extra; ! 292: #endif ! 293: { ! 294: read_dev_string (string, (dev_func_p) _read_mtune_string, extra); ! 295: } ! 296: ! 297: ! 298: /* ! 299: * Suck in a complete 'mtune' file. ! 300: */ ! 301: ! 302: #if USE_PROTO ! 303: void (read_mtune_file) (CONST char * inname, CONST char * outname, ! 304: VOID * extra) ! 305: #else ! 306: void ! 307: read_mtune_file ARGS ((inname, outname, extra)) ! 308: CONST char * inname; ! 309: CONST char * outname; ! 310: VOID * extra; ! 311: #endif ! 312: { ! 313: read_dev_file (inname, outname, (dev_func_p) _read_mtune_file, extra); ! 314: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.