2 To add a new resource -- as an example, the BAZ resource,
3 which will have foo record which is an integer,
4 a storage record, which is the name of a storage
5 resource, and a special time field.
7 1. Define the Resource type (R_xxx) in dir_config.h
8 Be sure to update the R_LAST define.
10 update R_LAST to be R_BAZ
12 2. Add a new definition of the resource in dir_config.h
13 The first three are mandatory (will soon be changed
14 to a header structure).
18 struct s_res_baz *next;
21 struct res_store *storage;
25 3. In dir_config.c add the new resource to the table
26 of resources (resources[])
28 {"baz", baz_items, R_BAZ, NULL},
30 4. Create a baz_items, which defines the records that
31 can appear within the BAZ resource:
33 static struct res_items bas_items[] = {
34 name, store sub, where to store, extra info
35 {"name", store_name, ITEM(res_baz.name), 0}, /* manditory */
36 {"foo", store_int, ITEM(res_baz.foo), 0},
37 {"storage", stor_res, ITEM(res_baz.storage), 0},
38 {"time", store_time, ITME(res_baz.time), 0},
41 5. Update the dump_resource() subroutine to handle printing
44 6. Update the free_resource() subroutine to handle releasing
47 7. Check for any special initialization in init_resource().
48 Normally, everything is just zeroed.
50 8. Update the new_resource() subroutine to handle the two
51 passes of the configurator to be able to create your
52 resource. Pass 2 is used only for finding a reference
53 to a resource and stuffing its address. In the above example,
54 you will need to include the storage resource. See the
55 example for the Job Resource.
57 Add an entry so that the correct size of your resource is
58 allocated for pass one.
60 9. Write any new store routines that you may need. In this case,
61 we used the store_int and store_res, which are already defined,
62 but we need to add the new special routine store_time().
63 Note, the store subroutine gets control when the parser has
64 identified the record. Everything after the record name
65 must be scanned in the store routine.
68 To add a new resource record:
70 1. Add the new record definition to the resource structure definition.
71 See step 2 above. In this case, however, we only add a new field
72 to the existing structure.
74 2. Add the new record to the existing res_items structure. See
75 step 4 above. In this case, however, we only add a new record
76 definition to the exising structure.
78 3. Update the dump_resource() routine to dump the new record.
80 4. Update the free_resource() routine if you allocated any memory.
82 5. Update init_resource() if you have any special requirements (not
85 6. Update the new_resource() routine if necessary (not normally the
88 7. Write any new store routine that you may have created to store
90 Note, the store subroutine gets control when the parser has
91 identified the record. Everything after the record name
92 must be scanned in the store routine. See the examples of
93 store routines that exist.
95 Note, the core parsing code is in lib/parse_config.c and lib/parse_config.h.
96 lib/parse_config.c provides the following store routines:
98 store_name stores a resource name
99 store_str stores a string
100 store_res stores a resource
101 store_int stores an integer
103 and the following utilities:
105 scan_to_eol causes the lexical scanner to scan to the end of the line
106 scan_error prints an error message
107 GetResWithName returns the resource of a specified type and name
108 GetNextRes returns the next resource of a specified type
109 parse_config parses the configuration file
110 free_config_resources frees all the resources allocated.
112 Note: when your store routine gets control, the parser will have already
113 scanned the record name (i.e. "baz =") before calling your routine.
114 The lexical scanner is by default in a mode where spaces will be
115 compressed out of unquoted strings. Consequently if you want to scan
117 baz = full backup every sunday
119 and you do not want to get "full backup every sunday" as a single token
120 "fullbackupeverysunday", you must set the no identifier option in the
121 lexical scanner options field:
123 int options = lc->options;
125 lc->options |= LOPT_NO_IDENT; /* don't eat spaces */
130 lc->options = options;