Annotation of coherent/f/etc/conf/bin/src/stune.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *-IMPORTS:
                      3:  *     <sys/compat.h>
                      4:  *             CONST
                      5:  *             USE_PROTO
                      6:  *             ARGS ()
                      7:  *     <stdlib.h>
                      8:  *             NULL
                      9:  *             malloc ()
                     10:  *             free ()
                     11:  */
                     12: 
                     13: #include <sys/compat.h>
                     14: #include <stdlib.h>
                     15: 
                     16: #include "ehand.h"
                     17: #include "symbol.h"
                     18: #include "read.h"
                     19: #include "mtune.h"
                     20: #include "input.h"
                     21: 
                     22: #include "stune.h"
                     23: 
                     24: LOCAL stune_t *        _stunes;
                     25: 
                     26: 
                     27: /*
                     28:  * Regenerate an 'stune' line from the stored record.
                     29:  */
                     30: 
                     31: #if    USE_PROTO
                     32: void (write_stune) (stune_t * stunep, input_t * input)
                     33: #else
                     34: void
                     35: write_stune ARGS ((stunep, input))
                     36: stune_t              * stunep;
                     37: input_t              * input;
                     38: #endif
                     39: {
                     40:        if ((* input->in_filter) (input, "%s<2>%ld\n",
                     41:                                  stunep->st_name->s_data,
                     42:                                  stunep->st_value) < 0) {
                     43: 
                     44:                throw_error ("Output error");
                     45:        }
                     46: }
                     47: 
                     48: 
                     49: /*
                     50:  * Read lines from an "stune" file.
                     51:  */
                     52: 
                     53: #if    USE_PROTO
                     54: LOCAL stune_t * (read_stune) (input_t * input, lex_t * lexp, int * end_char)
                     55: #else
                     56: LOCAL stune_t *
                     57: read_stune ARGS ((input, lexp, end_char))
                     58: input_t              * input;
                     59: lex_t        * lexp;
                     60: int          * end_char;
                     61: #endif
                     62: {
                     63:        VOLATILE int    ch = '\n';
                     64:        stune_t * VOLATILE stunep;
                     65:        ehand_t         err;
                     66: 
                     67:        if ((stunep = (stune_t *) malloc (sizeof (* stunep))) == NULL)
                     68:                throw_error ("out of memory in read_stune ()");
                     69: 
                     70:        if (PUSH_HANDLER (err) == 0) {
                     71:                /*
                     72:                 * If the first thing on the line works out to be an EOF,
                     73:                 * then bail out without an error.
                     74:                 */
                     75: 
                     76:                ch = read_symbol (input, lexp, & stunep->st_name);
                     77: 
                     78:                if (stunep->st_name == NULL) {
                     79:                        /*
                     80:                         * We allow an EOF at the beginning of a line and we
                     81:                         * also allow a blank line.
                     82:                         */
                     83: 
                     84:                        free (stunep);
                     85:                        stunep = NULL;
                     86:                        goto at_eof;
                     87:                }
                     88:                check_not_eol (ch);
                     89: 
                     90:                /*
                     91:                 * Pull in the parameter value
                     92:                 */
                     93: 
                     94:                ch = read_longs (input, lexp, & stunep->st_value, NO_RANGE);
                     95: 
                     96:                ch = expect_eol (input, lexp, ch);
                     97:        } else {
                     98:                free (stunep);
                     99:                CHAIN_ERROR (err);
                    100:        }
                    101: 
                    102: at_eof:
                    103:        POP_HANDLER (err);
                    104: 
                    105:        * end_char = ch;
                    106:        return stunep;
                    107: }
                    108: 
                    109: 
                    110: /*
                    111:  * This function is passed as a parameter to read_dev_string () to read an
                    112:  * 'mtune' entry (usually a program argument) and hook it into a global list.
                    113:  */
                    114: 
                    115: #if    USE_PROTO
                    116: LOCAL int _read_stune_string (input_t * input, lex_t * lexp,
                    117:                              stune_t ** stlistp)
                    118: #else
                    119: LOCAL int
                    120: _read_stune_string (input, lexp, stlistp)
                    121: input_t              * input;
                    122: lex_t        * lexp;
                    123: stune_t             ** stlistp;
                    124: #endif
                    125: {
                    126:        stune_t       * stunep;
                    127:        int             ch;
                    128: 
                    129:        if ((stunep = read_stune (input, lexp, & ch)) != NULL) {
                    130:                stunep->st_next = * stlistp;
                    131:                * stlistp = stunep;
                    132:        }
                    133: 
                    134:        return ch;
                    135: }
                    136: 
                    137: 
                    138: /*
                    139:  * This function is called from _read_stune_file () to link an 'stune' entry
                    140:  * into the global lists and check it.
                    141:  */
                    142: 
                    143: #if    USE_PROTO
                    144: LOCAL void (link_stune) (stune_t * stunep, input_t * input)
                    145: #else
                    146: LOCAL void
                    147: link_stune ARGS ((stunep, input))
                    148: stune_t              * stunep;
                    149: input_t              * input;
                    150: #endif
                    151: {
                    152:        if ((stunep->st_mtune = find_mtune (stunep->st_name)) == NULL)
                    153:                throw_error ("Parameter name not in 'mtune' file");
                    154: 
                    155:        if (stunep->st_mtune->mt_stune != NULL)
                    156:                throw_error ("Two values configured for parameter");
                    157: 
                    158:        if (stunep->st_value < stunep->st_mtune->mt_min ||
                    159:            stunep->st_value > stunep->st_mtune->mt_max)
                    160:                throw_error ("Parameter value outside configurable range");
                    161: 
                    162:        stunep->st_mtune->mt_stune = stunep;
                    163: 
                    164:        stunep->st_next = _stunes;
                    165:        _stunes = stunep;
                    166: 
                    167:        write_stune (stunep, input);
                    168: }
                    169: 
                    170: 
                    171: /*
                    172:  * This function is passed as a pointer to read_sdev_file () to read an
                    173:  * 'stune' entry and link it into the global lists.
                    174:  */
                    175: 
                    176: #if    USE_PROTO
                    177: LOCAL int _read_stune_file (input_t * input, lex_t * lexp,
                    178:                            stune_t ** changes)
                    179: #else
                    180: LOCAL int
                    181: _read_stune_file (input, lexp, changes)
                    182: input_t              * input;
                    183: lex_t        * lexp;
                    184: stune_t              **changes;
                    185: #endif
                    186: {
                    187:        stune_t       * stunep;
                    188:        int             ch;
                    189: 
                    190:        if ((stunep = read_stune (input, lexp, & ch)) == NULL) {
                    191:                if (ch == READ_EOF) {
                    192:                        /*
                    193:                         * Blow remaining changes out as new entries.
                    194:                         */
                    195: 
                    196:                        while ((stunep = * changes) != NULL) {
                    197:                                * changes = stunep->st_next;
                    198:                                link_stune (stunep, input);
                    199:                        }
                    200:                }
                    201:                return ch;
                    202:        }
                    203: 
                    204: 
                    205:        /*
                    206:         * Link the freshly-read entry into the global lists.
                    207:         */
                    208: 
                    209:        if (changes) {
                    210:                stune_t      ** scan;
                    211: 
                    212:                for (scan = changes ; * scan != NULL ;
                    213:                     scan = & (* scan)->st_next) {
                    214: 
                    215:                        if ((* scan)->st_name == stunep->st_name) {
                    216:                                /*
                    217:                                 * Our current entry is being replaced by a
                    218:                                 * new one; unlink the new entry from the
                    219:                                 * change list and discard the old entry.
                    220:                                 */
                    221: 
                    222:                                free (stunep);
                    223: 
                    224:                                if (report_mode ())
                    225:                                        return ch;
                    226: 
                    227:                                stunep = * scan;
                    228:                                * scan = stunep->st_next;
                    229:                                break;
                    230:                        }
                    231:                }
                    232:        }
                    233: 
                    234:        link_stune (stunep, input);
                    235:        return ch;
                    236: }
                    237: 
                    238: 
                    239: /*
                    240:  * Read in an "mtune" entry from a string and add it to a list.
                    241:  */
                    242: 
                    243: #if    USE_PROTO
                    244: void read_stune_string (CONST char * string, VOID * extra)
                    245: #else
                    246: void
                    247: read_stune_string (string, extra)
                    248: CONST char    *        string;
                    249: VOID         * extra;
                    250: #endif
                    251: {
                    252:        read_dev_string (string, (dev_func_p) _read_stune_string, extra);
                    253: }
                    254: 
                    255: 
                    256: /*
                    257:  * Suck in a complete 'stune' file.
                    258:  */
                    259: 
                    260: #if    USE_PROTO
                    261: void (read_stune_file) (CONST char * inname, CONST char * outname,
                    262:                        VOID * extra)
                    263: #else
                    264: void
                    265: read_stune_file ARGS ((inname, outname, extra))
                    266: CONST char    *        inname;
                    267: CONST char    *        outname;
                    268: VOID         * extra;
                    269: #endif
                    270: {
                    271:        read_dev_file (inname, outname, (dev_func_p) _read_stune_file, extra);
                    272: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.