void fitstable_copy_columns(const fitstable_t* src, fitstable_t* dest) { int i; for (i=0; i<ncols(src); i++) { fitscol_t* col = getcol(src, i); fitscol_t* newcol = fitstable_add_column(dest, col); // fix string fields... newcol->colname = strdup_safe(newcol->colname); newcol->units = strdup_safe(newcol->units); } }
NODE *make_node(char *name, NETWORK *net, ARC *from_arc, ARC *to_arc, int *highest_nnode_name, int *perr) /************************************************************/ /* Makes a new node, returns a pointer to it. */ /* The new node is initialized with name, from_arc, to_arc. */ /* Set to be neither start not stop state. */ /* All boolean flags are initialized to F. */ /* If name is NULL, uses a char string version of bumped */ /* *highest_nnode_name for the new node name. */ /************************************************************/ { char *proc = "make_node"; char sxx[LINE_LENGTH], *sx = &sxx[0]; NODE *p; /* code */ db_enter_msg(proc,1); /* debug only */ p = (NODE *)malloc_safe(sizeof(NODE),proc); *perr = 0; if (name != NULL) { p->name = strdup_safe(name,proc); } else { /* make name from node number */ *highest_nnode_name += 1; sprintf(sx,"%d",*highest_nnode_name); p->name = strdup_safe(sx,proc); } p->net = net ; p->in_arcs = NULL; p->out_arcs = NULL; p->start_state = F; p->stop_state = F; p->flag1 = F; p->flag2 = F; if (from_arc != NULL) { p->in_arcs = add_to_arc_list(p->in_arcs,from_arc,perr); if (*perr > 0) { printf("%s:*ERR: add_to_arc_list() returns %d\n",proc,*perr); return((NODE *)0); } } if (to_arc != NULL) { p->out_arcs = add_to_arc_list(p->out_arcs,to_arc,perr); if (*perr > 0) { printf("%s:*ERR: add_to_arc_list() returns %d\n",proc,*perr); return((NODE *)0); } } db_leave_msg(proc,1); /* debug only */ return p; } /* end make_node() */
void fitstable_add_write_column_array_convert(fitstable_t* tab, tfits_type fits_type, tfits_type c_type, int arraysize, const char* name, const char* units) { fitscol_t col; memset(&col, 0, sizeof(fitscol_t)); col.colname = strdup_safe(name); col.units = strdup_safe(units); col.fitstype = fits_type; col.ctype = c_type; col.arraysize = arraysize; col.in_struct = FALSE; fitstable_add_column(tab, &col); }
static fitstable_t* _fitstable_open(const char* fn) { fitstable_t* tab; tab = fitstable_new(); if (!tab) { ERROR("Failed to allocate new FITS table structure"); goto bailout; } tab->extension = 1; tab->fn = strdup_safe(fn); tab->anq = anqfits_open(fn); if (!tab->anq) { ERROR("Failed to open FITS file \"%s\"", fn); goto bailout; } tab->primheader = anqfits_get_header(tab->anq, 0); if (!tab->primheader) { ERROR("Failed to read primary FITS header from %s", fn); goto bailout; } return tab; bailout: if (tab) { fitstable_close(tab); } return NULL; }
struct ratbag_device* ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device, const char *name, const struct input_id *id) { struct ratbag_device *device = NULL; device = zalloc(sizeof(*device)); device->name = strdup_safe(name); device->ratbag = ratbag_ref(ratbag); device->refcount = 1; device->udev_device = udev_device_ref(udev_device); device->ids = *id; device->data = ratbag_device_data_new_for_id(ratbag, id); list_init(&device->profiles); list_insert(&ratbag->devices, &device->link); /* We assume that most devices have this capability, so let's set it * by default. The few devices that miss this capability should * unset it instead. */ ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_QUERY_CONFIGURATION); return device; }
void fitstable_add_column_struct(fitstable_t* tab, tfits_type c_type, int arraysize, int structoffset, tfits_type fits_type, const char* name, const char* units, anbool required) { fitscol_t col; memset(&col, 0, sizeof(fitscol_t)); col.colname = strdup_safe(name); col.units = strdup_safe(units); col.fitstype = fits_type; col.ctype = c_type; col.arraysize = arraysize; col.in_struct = TRUE; col.coffset = structoffset; col.required = required; fitstable_add_column(tab, &col); }
static fitstable_t* open_for_writing(const char* fn, const char* mode, FILE* fid) { fitstable_t* tab; tab = fitstable_new(); if (!tab) goto bailout; tab->fn = strdup_safe(fn); if (fid) tab->fid = fid; else { tab->fid = fopen(fn, mode); if (!tab->fid) { SYSERROR("Couldn't open output file %s for writing", fn); goto bailout; } } return tab; bailout: if (tab) { fitstable_close(tab); } return NULL; }
static int str_to_macro(const char *action_arg, struct macro *m) { char *str, *s; enum ratbag_macro_event_type type; int code; int idx = 0; int rc = ERR_USAGE; /* FIXME: handle per-device maximum lengths of macros */ if (!action_arg) return -EINVAL; str = strdup_safe(action_arg); s = str; m->name = "<cmdline>"; while (idx < ARRAY_LENGTH(m->events)) { char *token; token = strsep(&s, " "); if (!token) break; if (strlen(token) == 0) continue; switch(token[0]) { case '+': type = RATBAG_MACRO_EVENT_KEY_PRESSED; token++; break; case '-': type = RATBAG_MACRO_EVENT_KEY_RELEASED; token++; break; case 't': type = RATBAG_MACRO_EVENT_WAIT; token++; break; default: type = RATBAG_MACRO_EVENT_NONE; break; } if (type == RATBAG_MACRO_EVENT_WAIT) { char *endptr; code = strtol(token, &endptr, 10); if (*endptr != '\0') { error("Invalid token name: %s\n", token); goto out; } } else { code = libevdev_event_code_from_name(EV_KEY, token); if (code == -1) { error("Invalid token name: %s\n", token); goto out; } } if (type == RATBAG_MACRO_EVENT_NONE) { m->events[idx].type = RATBAG_MACRO_EVENT_KEY_PRESSED; m->events[idx].data = code; type = RATBAG_MACRO_EVENT_KEY_RELEASED; idx++; } m->events[idx].data = code; m->events[idx].type = type; idx++; } rc = SUCCESS; out: free(str); return rc; }
void plot_xy_set_filename(plotxy_t* args, const char* fn) { free(args->fn); args->fn = strdup_safe(fn); }
void plot_xy_set_ycol(plotxy_t* args, const char* col) { free(args->ycol); args->ycol = strdup_safe(col); }
void plot_radec_set_deccol(plotradec_t* args, const char* col) { free(args->deccol); args->deccol = strdup_safe(col); }