/** * Add a symbol to the lookup table. * * @param name is the symbol name. * @param pri the priority of the symbol. * @param arg the number of arguments. * @param com the RPN command. * @return the symbol index, and negative on error. */ static int add_symbol(const char *name, int pri, int arg, int com) { int len; char cname[100]; if (duplicate_name(name)) return -1; convert(name, cname); len = strlen(cname); if (len < 1) { plintf("Empty parameter - remove spaces\n"); return -1; } ParserSymbol *p = parser_symbols_append(&my_symb); if (!p) return -1; if (len > sizeof(p->name) - 1) len = sizeof(p->name) - 1; strncpy(p->name, cname, len); p->name[len] = '\0'; p->len = len; p->pri = pri; p->arg = arg; p->com = com; return my_symb.len - 1; }
/* * Process a node, adding entries for its children and its properties. */ void proc_device_tree_add_node(struct device_node *np, struct proc_dir_entry *de) { struct property *pp; struct proc_dir_entry *ent; struct device_node *child; const char *p; set_node_proc_entry(np, de); for (child = NULL; (child = of_get_next_child(np, child));) { /* Use everything after the last slash, or the full name */ p = strrchr(child->full_name, '/'); if (!p) p = child->full_name; else ++p; if (duplicate_name(de, p)) p = fixup_name(np, de, p); ent = proc_mkdir(p, de); if (ent == NULL) break; proc_device_tree_add_node(child, ent); } of_node_put(child); for (pp = np->properties; pp != NULL; pp = pp->next) { p = pp->name; if (strchr(p, '/')) continue; if (duplicate_name(de, p)) p = fixup_name(np, de, p); ent = __proc_device_tree_add_prop(de, pp, p); if (ent == NULL) break; } }
static const char *fixup_name(struct device_node *np, struct proc_dir_entry *de, const char *name) { char *fixed_name; int fixup_len = strlen(name) + 2 + 1; /* name + #x + \0 */ int i = 1, size; realloc: fixed_name = kmalloc(fixup_len, GFP_KERNEL); if (fixed_name == NULL) { printk(KERN_ERR "device-tree: Out of memory trying to fixup " "name \"%s\"\n", name); return name; } retry: size = snprintf(fixed_name, fixup_len, "%s#%d", name, i); size++; /* account for NULL */ if (size > fixup_len) { /* We ran out of space, free and reallocate. */ kfree(fixed_name); fixup_len = size; goto realloc; } if (duplicate_name(de, fixed_name)) { /* Multiple duplicates. Retry with a different offset. */ i++; goto retry; } printk(KERN_WARNING "device-tree: Duplicate name in %s, " "renamed to \"%s\"\n", np->full_name, fixed_name); return fixed_name; }
void add_error_element(ERRORVAL *errcon, NAMELIST_TEXT *nltext, LINE_LIST *beamline) { long n_items, n_added, i_start, firstIndexInGroup; ELEMENT_LIST *context; double sMin = -DBL_MAX, sMax = DBL_MAX; log_entry("add_error_element"); if ((n_items = errcon->n_items)==0) { if (errcon->new_data_read) bombElegant("improper sequencing of error specifications and tracking", NULL); errcon->new_data_read = 1; } /* process namelist text */ set_namelist_processing_flags(STICKY_NAMELIST_DEFAULTS); set_print_namelist_flags(0); if (processNamelist(&error, nltext)==NAMELIST_ERROR) bombElegant(NULL, NULL); if (name==NULL) { if (!element_type) bombElegant("element name missing in error namelist", NULL); SDDS_CopyString(&name, "*"); } if (echoNamelists) print_namelist(stdout, &error); /* check for valid input and copy to errcon arrays */ if (item==NULL) bombElegant("item name missing in error namelist", NULL); if (match_string(type, known_error_type, N_ERROR_TYPES, 0)<0) bombElegant("unknown error type specified", NULL); if (bind_number<0) bombElegant("bind_number < 0", NULL); if (!additive && fractional) bombElegant("fractional errors must be additive", NULL); context = NULL; n_added = 0; i_start = n_items; context = NULL; if (after && strlen(after)) { if (!(context=find_element(after, &context, &(beamline->elem)))) { fprintf(stdout, "Element %s not found in beamline.\n", after); exitElegant(1); } sMin = context->end_pos; if (find_element(after, &context, &(beamline->elem))) { fprintf(stdout, "Element %s found in beamline more than once.\n", after); exitElegant(1); } fprintf(stdout, "%s found at s = %le m\n", after, sMin); fflush(stdout); } context = NULL; if (before && strlen(before)) { if (!(context=find_element(before, &context, &(beamline->elem)))) { fprintf(stdout, "Element %s not found in beamline.\n", before); exitElegant(1); } sMax = context->end_pos; if (find_element(before, &context, &(beamline->elem))) { fprintf(stdout, "Element %s found in beamline more than once.\n", after); exitElegant(1); } fprintf(stdout, "%s found at s = %le m\n", before, sMax); fflush(stdout); } if (after && before && sMin>sMax) { fprintf(stdout, "Element %s is not upstream of %s!\n", before, after); exitElegant(1); } if (element_type && has_wildcards(element_type) && strchr(element_type, '-')) element_type = expand_ranges(element_type); if (has_wildcards(name)) { if (strchr(name, '-')) name = expand_ranges(name); str_toupper(name); firstIndexInGroup = -1; while ((context=wfind_element(name, &context, &(beamline->elem)))) { if (element_type && !wild_match(entity_name[context->type], element_type)) continue; if (exclude && wild_match(context->name, exclude)) continue; if (i_start!=n_items && duplicate_name(errcon->name+i_start, n_items-i_start, context->name)) continue; if ((sMin>=0 && context->end_pos<sMin) || (sMax>=0 && context->end_pos>sMax)) continue; errcon->name = trealloc(errcon->name, sizeof(*errcon->name)*(n_items+1)); errcon->item = trealloc(errcon->item, sizeof(*errcon->item)*(n_items+1)); errcon->quan_name = trealloc(errcon->quan_name, sizeof(*errcon->quan_name)*(n_items+1)); errcon->quan_final_index = trealloc(errcon->quan_final_index, sizeof(*errcon->quan_final_index)*(n_items+1)); errcon->quan_unit = trealloc(errcon->quan_unit, sizeof(*errcon->quan_unit)*(n_items+1)); errcon->error_level = trealloc(errcon->error_level, sizeof(*errcon->error_level)*(n_items+1)); errcon->error_cutoff = trealloc(errcon->error_cutoff, sizeof(*errcon->error_cutoff)*(n_items+1)); errcon->error_type = trealloc(errcon->error_type, sizeof(*errcon->error_type)*(n_items+1)); errcon->elem_type = trealloc(errcon->elem_type, sizeof(*errcon->elem_type)*(n_items+1)); errcon->error_value = trealloc(errcon->error_value, sizeof(*errcon->error_value)*(n_items+1)); errcon->unperturbed_value = trealloc(errcon->unperturbed_value, sizeof(*errcon->unperturbed_value)*(n_items+1)); errcon->param_number = trealloc(errcon->param_number, sizeof(*errcon->param_number)*(n_items+1)); errcon->bind_number = trealloc(errcon->bind_number, sizeof(*errcon->bind_number)*(n_items+1)); errcon->flags = trealloc(errcon->flags, sizeof(*errcon->flags)*(n_items+1)); errcon->sMin = trealloc(errcon->sMin, sizeof(*errcon->sMin)*(n_items+1)); errcon->sMax = trealloc(errcon->sMax, sizeof(*errcon->sMax)*(n_items+1)); errcon->boundTo = trealloc(errcon->boundTo, sizeof(*errcon->boundTo)*(n_items+1)); cp_str(errcon->item+n_items, str_toupper(item)); cp_str(errcon->name+n_items, context->name); errcon->error_level[n_items] = amplitude*error_factor; errcon->error_cutoff[n_items] = cutoff; errcon->error_type[n_items] = match_string(type, known_error_type, N_ERROR_TYPES, 0); errcon->quan_name[n_items] = tmalloc(sizeof(char*)*(strlen(context->name)+strlen(item)+4)); errcon->quan_final_index[n_items] = -1; sprintf(errcon->quan_name[n_items], "d%s.%s", context->name, item); errcon->flags[n_items] = (fractional?FRACTIONAL_ERRORS:0); errcon->flags[n_items] += (bind==0?0:(bind==-1?ANTIBIND_ERRORS:BIND_ERRORS)); errcon->flags[n_items] += (post_correction?POST_CORRECTION:PRE_CORRECTION); errcon->flags[n_items] += (additive?0:NONADDITIVE_ERRORS); errcon->bind_number[n_items] = bind_number; /* boundTo must be -1 when there is no cross-name binding or when this element is the * first of a series */ errcon->boundTo[n_items] = bind_across_names?firstIndexInGroup:-1; /* if (errcon->boundTo[n_items]!=-1) fprintf(stdout, "%s bound to %s\n", errcon->name[n_items], errcon->name[errcon->boundTo[n_items]]); */ errcon->sMin[n_items] = sMin; errcon->sMax[n_items] = sMax; errcon->elem_type[n_items] = context->type; if ((errcon->param_number[n_items] = confirm_parameter(item, context->type))<0) { fprintf(stdout, "error: cannot vary %s--no such parameter for %s (wildcard name: %s)\n",item, context->name, name); fflush(stdout); exitElegant(1); } cp_str(&errcon->quan_unit[n_items], errcon->flags[n_items]&FRACTIONAL_ERRORS?"fr": entity_description[errcon->elem_type[n_items]].parameter[errcon->param_number[n_items]].unit ); errcon->unperturbed_value[n_items] = parameter_value(errcon->name[n_items], errcon->elem_type[n_items], errcon->param_number[n_items], beamline); if (errcon->unperturbed_value[n_items]==0 && errcon->flags[n_items]&FRACTIONAL_ERRORS) fprintf(stdout, "***\7\7\7 warning: you've specified fractional errors for %s.%s, but the unperturbed value is zero.\nThis may be an error.\n", errcon->name[n_items], errcon->item[n_items]); fflush(stdout); if (duplicate_name(errcon->quan_name, n_items, errcon->quan_name[n_items])) fprintf(stdout, "***\7\7\7 warning: you've specified errors for %s.%s more than once!\n", errcon->name[n_items], errcon->item[n_items]); fflush(stdout); errcon->n_items = ++n_items; n_added++; if (firstIndexInGroup==-1) firstIndexInGroup = n_items-1; } } else { str_toupper(name); if (!(context=find_element(name, &context, &(beamline->elem)))) { fprintf(stdout, "error: cannot add errors to element %s--not in beamline\n", name); fflush(stdout); exitElegant(1); } errcon->name = trealloc(errcon->name, sizeof(*errcon->name)*(n_items+1)); errcon->item = trealloc(errcon->item, sizeof(*errcon->item)*(n_items+1)); errcon->quan_name = trealloc(errcon->quan_name, sizeof(*errcon->quan_name)*(n_items+1)); errcon->quan_final_index = trealloc(errcon->quan_final_index, sizeof(*errcon->quan_final_index)*(n_items+1)); errcon->quan_unit = trealloc(errcon->quan_unit, sizeof(*errcon->quan_unit)*(n_items+1)); errcon->error_level = trealloc(errcon->error_level, sizeof(*errcon->error_level)*(n_items+1)); errcon->error_cutoff = trealloc(errcon->error_cutoff, sizeof(*errcon->error_cutoff)*(n_items+1)); errcon->error_type = trealloc(errcon->error_type, sizeof(*errcon->error_type)*(n_items+1)); errcon->elem_type = trealloc(errcon->elem_type, sizeof(*errcon->elem_type)*(n_items+1)); errcon->error_value = trealloc(errcon->error_value, sizeof(*errcon->error_value)*(n_items+1)); errcon->unperturbed_value = trealloc(errcon->unperturbed_value, sizeof(*errcon->unperturbed_value)*(n_items+1)); errcon->param_number = trealloc(errcon->param_number, sizeof(*errcon->param_number)*(n_items+1)); errcon->bind_number = trealloc(errcon->bind_number, sizeof(*errcon->bind_number)*(n_items+1)); errcon->flags = trealloc(errcon->flags, sizeof(*errcon->flags)*(n_items+1)); errcon->sMin = trealloc(errcon->sMin, sizeof(*errcon->sMin)*(n_items+1)); errcon->sMax = trealloc(errcon->sMax, sizeof(*errcon->sMax)*(n_items+1)); errcon->boundTo = trealloc(errcon->boundTo, sizeof(*errcon->boundTo)*(n_items+1)); cp_str(errcon->item+n_items, str_toupper(item)); cp_str(errcon->name+n_items, context->name); errcon->error_level[n_items] = amplitude; errcon->error_cutoff[n_items] = cutoff; errcon->error_type[n_items] = match_string(type, known_error_type, N_ERROR_TYPES, 0); errcon->quan_name[n_items] = tmalloc(sizeof(char*)*(strlen(context->name)+strlen(item)+4)); sprintf(errcon->quan_name[n_items], "d%s.%s", context->name, item); errcon->flags[n_items] = (fractional?FRACTIONAL_ERRORS:0); errcon->flags[n_items] += (bind==0?0:(bind==-1?ANTIBIND_ERRORS:BIND_ERRORS)); errcon->flags[n_items] += (post_correction?POST_CORRECTION:PRE_CORRECTION); errcon->flags[n_items] += (additive?0:NONADDITIVE_ERRORS); errcon->bind_number[n_items] = bind_number; errcon->sMin[n_items] = sMin; errcon->sMax[n_items] = sMax; errcon->boundTo[n_items] = -1; /* not used when there are no wildcards */ errcon->elem_type[n_items] = context->type; if ((errcon->param_number[n_items] = confirm_parameter(item, context->type))<0) { fprintf(stdout, "error: cannot vary %s--no such parameter for %s\n",item, name); fflush(stdout); exitElegant(1); } cp_str(&errcon->quan_unit[n_items], errcon->flags[n_items]&FRACTIONAL_ERRORS?"fr": entity_description[errcon->elem_type[n_items]].parameter[errcon->param_number[n_items]].unit ); errcon->unperturbed_value[n_items] = parameter_value(errcon->name[n_items], errcon->elem_type[n_items], errcon->param_number[n_items], beamline); if (errcon->unperturbed_value[n_items]==0 && errcon->flags[n_items]&FRACTIONAL_ERRORS) fprintf(stdout, "***\7\7\7 warning: you've specified fractional errors for %s.%s, but the unperturbed value is zero.\nThis may be an error.\n", errcon->name[n_items], errcon->item[n_items]); fflush(stdout); if (duplicate_name(errcon->quan_name, n_items, errcon->quan_name[n_items])) fprintf(stdout, "***\7\7\7 warning: you've specified errors for %s.%s more than once!\n", errcon->name[n_items], errcon->item[n_items]); fflush(stdout); errcon->n_items = ++n_items; n_added++; } if (!n_added && !allow_missing_elements) { fprintf(stdout, "error: no match for name %s\n", name); fflush(stdout); exitElegant(1); } log_exit("add_error_element"); }