3 * functions for the array_hdef structure
11 static int rdmc_exists_hdef_tag(const array_hdef_t *p,
12 int ndef, const char *tag);
16 /* Get a unique id for a new defpar object */
17 int rdmc_unique_hdef_id(const array_hdef_t *p, int ndef)
20 for (id = ndef; 1; id++)
21 if (rdmc_get_hdef_id(p, ndef, id) == RDMC_NA )
26 /* get a unique tag for a new defpar object. It is the tag_root itself
27 * as long it is unique, or the tag_root with a number at the end */
28 int rdmc_unique_hdef_tag(char *tag, const array_hdef_t *p
29 , int ndef, const char *tag_root){
32 /* First check if we can use the orginal tag */
33 if (!rdmc_exists_hdef_tag(p, ndef, tag_root)) {
34 strcpy(tag, tag_root);
37 /* now try to construct a new one with "Tag" + "number" */
39 sprintf(tag, "%s%i", tag_root, i);
40 if (!rdmc_exists_hdef_tag(p, ndef, tag))
46 static int rdmc_exists_hdef_tag(const array_hdef_t *p, int ndef, const char *tag){
49 for (i = 0; i < ndef; i++){
50 if (rdmc_get_hdef_tag(p, ndef, tag) != RDMC_NA) {
57 /* add a new initilized header def */
58 int rdmc_add_array_hdef(array_hdef_t **list,
59 int *count, array_hdef_t *new, int ipos){
72 *list = (array_hdef_t *)
73 realloc(*list,sizeof(array_hdef_t)*(*count));
75 for (i = (*count - 1) ; i > ipos ; i-- ){
76 rdmc_cp_hdef( &((*list)[i]), &((*list)[i-1]) );
78 rdmc_cp_hdef( &((*list)[ipos]), new );
84 /* remove header def */
85 int rdmc_del_array_hdef(array_hdef_t **list,
86 int *count, int ipos){
95 for (i = ipos ; i < (*count-1) ; i++ ){
96 rdmc_cp_hdef( &((*list)[i]), &((*list)[i+1]) );
100 *list = (array_hdef_t *)
101 realloc(*list,sizeof(array_hdef_t)*(*count));
111 void rdmc_init_array_hdef(array_hdef_t *def){/*init the structures */
114 strcpy(def->tag,"unknown");
116 for (i =0 ; i < RDMC_MAXTOKEN_PER_LINE ; i++){
117 def->words[i][0] = '\0';
120 for (i =0 ; i < RDMC_MAXTOKEN_PER_LINE ; i++){
121 def->pars[i][0] = '\0';
123 } /* init_array_header_def */
125 void rdmc_clear_array_hdef(array_hdef_t *def){/*init the structures */
126 rdmc_free_array_hdef(def);
127 rdmc_init_array_hdef(def);
128 } /* clear_array_header_def */
130 void rdmc_free_array_hdef(array_hdef_t *def){/*init the structures */
131 } /* free_array_header_def */
134 void rdmc_cp_hdef(array_hdef_t *out, const array_hdef_t *in){
135 memcpy(out,in,sizeof(array_hdef_t));
136 } /* init_array_header_def */
138 /* search an array of ndef array_header_def_t elements */
139 /* find the number of a header definition */
140 /* returns the number 0..(ndef-1) or RDMC_NA */
141 int rdmc_get_hdef_tag(const array_hdef_t *hd, int ndef, const char *tag){
143 for (i=0 ; i < ndef ; i++ ){
145 rdmc_msgprintf("%s:%s",hd[i].tag,tag);
147 if (strcmp(hd[i].tag,tag) == 0)
153 int rdmc_get_hdef_id(const array_hdef_t *hd, int ndef,int id){ /*according to an id */
155 for (i=0 ; i < ndef ; i++ ){
162 /* returns 1 if differetn */
163 int rdmc_comp_array_hdef(const array_hdef_t *d1, const array_hdef_t *d2){
167 if(strcmp(d1->tag,d2->tag))
169 if(d1->nwords != d2->nwords)
171 for ( i =0 ; i < d1->nwords ; i++){
172 if(strcmp(d1->words[i],d2->words[i]))
175 if(d1->npars != d2->npars)
177 for ( i =0 ; i < d1->npars ; i++){
178 if(strcmp(d1->pars[i],d2->pars[i]))
184 /* returns the index of the string token in the list of hdef parameters */
185 /* if the token is not found RDMC_NA is returned */
186 int rdmc_token_in_hdef(const array_hdef_t *p, const char *token){
188 for (i=0 ; i < p->nwords ; i++ ){
189 if (! strcmp(p->words[i],token) )