void pdc_register_errtab( pdc_core *pdc, int et, const pdc_error_info *ei, int n_entries) { int i; int n = (et / 1000) - 1; if (n < 0 || N_ERRTABS <= n || et % 1000 != 0) pdc_panic(pdc, "tried to register unknown error table %d", et); /* ignore multiple registrations of the same table. */ if (pdc->pr->err_tables[n].ei != (pdc_error_info *) 0) return; pdc->pr->err_tables[n].ei = ei; pdc->pr->err_tables[n].n_entries = n_entries; check_parms(pdc, &ei[0]); for (i = 1; i < n_entries; ++i) { if (ei[i].errnum <= ei[i-1].errnum) { pdc_panic(pdc, "duplicate or misplaced error number %d", ei[i].errnum); } /* an error table may span several blocks. */ if ((ei[i].errnum / 1000) - 1 > n) { pdc->pr->err_tables[n].n_entries = i; /* correct old block size */ n = (ei[i].errnum / 1000) - 1; /* new block number */ if (N_ERRTABS <= n) pdc_panic(pdc, "invalid error number %d", ei[i].errnum); ei += i; /* start of new block */ n_entries -= i; /* size of new block */ i = 0; pdc->pr->err_tables[n].ei = ei; pdc->pr->err_tables[n].n_entries = n_entries; } check_parms(pdc, &ei[i]); } } /* pdc_register_errtab */
static int set_param_str(const char *val, struct kernel_param *kp) { action_fn fn = (action_fn) kp->arg; int rv = 0; const char *end; char valcp[16]; int len; /* Truncate leading and trailing spaces. */ while (isspace(*val)) val++; end = val + strlen(val) - 1; while ((end >= val) && isspace(*end)) end--; len = end - val + 1; if (len > sizeof(valcp) - 1) return -EINVAL; memcpy(valcp, val, len); valcp[len] = '\0'; down_read(®ister_sem); rv = fn(valcp, NULL); if (rv) goto out_unlock; check_parms(); if (watchdog_user) rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY); out_unlock: up_read(®ister_sem); return rv; }
static int set_param_str(const char *val, struct kernel_param *kp) { action_fn fn = (action_fn) kp->arg; int rv = 0; char *dup, *s; dup = kstrdup(val, GFP_KERNEL); if (!dup) return -ENOMEM; s = strstrip(dup); down_read(®ister_sem); rv = fn(s, NULL); if (rv) goto out_unlock; check_parms(); if (watchdog_user) rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY); out_unlock: up_read(®ister_sem); kfree(dup); return rv; }
static int set_param_str(const char *val, struct kernel_param *kp) { action_fn fn = (action_fn) kp->arg; int rv = 0; char valcp[16]; char *s; strncpy(valcp, val, 16); valcp[15] = '\0'; s = strstrip(valcp); down_read(®ister_sem); rv = fn(s, NULL); if (rv) goto out_unlock; check_parms(); if (watchdog_user) rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY); out_unlock: up_read(®ister_sem); return rv; }
/* special internal entry point. input is a single open stream pointer, * which can't be closed. the caller has to ensure the file stream * is a valid open file or pipe, and the default object will be imported * and the format MUST be follows (can't seek on pipes, so can't look * for forward references to data). */ Object _dxfImportDX_FD(FILE *fptr) { struct finfo f; Object o = NULL; int rc; /* setup finfo struct */ /* clear struct to be sure all pointers are NULL, and set stuff which * we know the value of now. then call the init subroutine to finish * the rest of the initialization. */ memset(&f, '\0', sizeof(f)); rc = check_parms(&f.gb, NULL, NULL, NULL, NULL, NULL); if (!rc) goto done; f.fd = fptr; f.fname = "<NULL>"; f.recurse = 0; f.onepass = 1; rc = _dxfinitfinfo(&f); if (!rc) { DXFree((Pointer)f.gb.gbuf); return NULL; } /* read the file and construct the requested object */ rc = _dxfparse_file(&f, &o); if (!rc) goto done; done: DXFree((Pointer)f.gb.gbuf); _dxffreefinfo(&f); /* special routine which decrements ref count without deleting the object. * the object was referenced when added to the dictionary, so that * cleanup could delete all things not being returned. */ if (o) DXUnreference(o); return o; }
int main (int argc, char *argv[]) { struct GModule *module; struct { struct Option *input; /* name of input site map */ struct Option *output; /* name of output site map */ struct Option *type; struct Option *where; struct Option *size; /* size of sample (%input) */ struct Option *map; /* optional raster to check for NULL */ struct Option *cachesize; } parm; struct { struct Flag *quiet; struct Flag *all; /* disregard region settings */ } flag; int processing_mode = 0; int vect_types; /* setup some basic GIS stuff */ G_gisinit (argv[0]); module = G_define_module (); module->description = "Generates a random sample from a map of vector objects"; /* do not pause after a warning message was displayed */ G_sleep_on_error (0); /* Module Parameters: */ parm.input = G_define_standard_option (G_OPT_V_INPUT); parm.input->key = "input"; parm.input->type = TYPE_STRING; parm.input->required = YES; parm.input->description = "Vector map to draw sample from"; /* name of output map */ parm.output = G_define_standard_option (G_OPT_V_OUTPUT); parm.output->key = "output"; parm.output->type = TYPE_STRING; parm.output->required = YES; parm.output->description = "Vector map to store random sample in"; /* type of objects */ parm.type = G_define_standard_option (G_OPT_V_TYPE); /* filter objects by sql statement */ parm.where = G_define_standard_option (G_OPT_WHERE); /* percentage of input objects to include for random sample */ parm.size = G_define_option (); parm.size->key = "size"; parm.size->type = TYPE_DOUBLE; parm.size->required = YES; parm.size->description = "Size of the sample (% of input vector objects)"; parm.size->options = "0-100"; /* map = an optional raster map. Samples will not be generated */ /* in cells where this map fprintf (stderr, "HI\n");is NULL */ parm.map = G_define_standard_option (G_OPT_R_INPUT); parm.map->key = "raster"; parm.map->type = TYPE_STRING; parm.map->required = NO; parm.map->description = "Sampling cannot be done on NULL cells in this raster map"; /* number of lines to store in cache */ parm.cachesize = G_define_option (); parm.cachesize->key = "cachesize"; parm.cachesize->type = TYPE_INTEGER; parm.cachesize->answer = "-1"; parm.cachesize->required = NO; parm.cachesize->description = "Number of raster rows to store in cache (-1 for auto)"; flag.all = G_define_flag (); flag.all->key = 'a'; flag.all->description = "Sample outside the current region's limits"; flag.quiet = G_define_flag (); flag.quiet->key = 'q'; flag.quiet->description = "Quiet operation: no progress display"; /* parse command line */ if (G_parser (argc, argv)) { exit (-1); } vect_types = Vect_option_to_types (parm.type); /* check if given parameters are valid */ processing_mode = check_parms (parm.map->answer, parm.input->answer, parm.output->answer, flag.all->answer); if ( parm.map->answer != NULL ) { /* set cachesize */ cachesize = atoi (parm.cachesize->answer); if ( (cachesize<-1) || (cachesize > G_window_rows ()) ) { /* if cache size is invalid, just set to auto-mode (-1) */ G_warning ("Invalid cache size requested (must be between 0 and %i or -1).\n", G_window_rows()); cachesize = -1; } } do_split_sample ( parm.input->answer, parm.output->answer, vect_types, atof (parm.size->answer), parm.map->answer, flag.all->answer, processing_mode, flag.quiet->answer ); return (EXIT_SUCCESS); }
Object DXImportDX(char *filename, char **namelist, int *start, int *end, int *delta) { struct finfo f; Object o = NULL; char needfree = 1; int rc; /* setup finfo struct */ /* clear struct to be sure all pointers are NULL, and set stuff which * we know the value of now. then call the init subroutine to finish * the rest of the initialization. */ memset(&f, '\0', sizeof(f)); f.fd = _dxfopen_dxfile(filename, NULL, &f.fname,".dx"); if (!f.fd) goto done; rc = check_parms(&f.gb, NULL, namelist, start, end, delta); if (!rc) goto done; if (!f.fname) { f.fname = "<NULL>"; needfree = 0; } f.recurse = 0; f.onepass = filename[0]=='!' ? 1 : 0; rc = _dxfinitfinfo(&f); if (!rc) { if (needfree) DXFree((Pointer)f.fname); DXFree((Pointer)f.gb.gbuf); return NULL; } /* read the file and construct the requested object */ rc = _dxfparse_file(&f, &o); if (!rc) goto done; done: #if DXD_POPEN_OK _dxfclose_dxfile(f.fd, filename); /* original filename possibly w/ ! */ #else _dxfclose_dxfile(f.fd, filename); #endif if (needfree) DXFree((Pointer)f.fname); DXFree((Pointer)f.gb.gbuf); _dxffreefinfo(&f); /* special routine which decrements ref count without deleting the object. * the object was referenced when added to the dictionary, so that * cleanup could delete all things not being returned. */ if (o) DXUnreference(o); return o; }