int error_boss(char *map) { char *file; char **tab; int width; int height; if (check_existence(map) == -1 || (file = get_file_content(map)) == NULL || check_integer(file, "ibwsm.lg\n") == -1 || (file = put_return(file)) == NULL || (tab = my_str_to_wordtab(file, '\n')) == NULL || check_largest(tab) == -1 || is_present("i", file) != 1 || is_present("b", file) != 1 || check_tab(tab) == -1) return (puterror("One of Boss map isn't correct.\n")); width = my_strlen(tab[0]) * 29; height = tablen(tab) * 26; if (width > 1300 || height > 750) return (puterror("Error: Dimension are too big in Boss Map.\n")); free(file); free_tab(tab); return (0); }
char *add_existing_tests() { tree *first = NULL; int data[MAX_ELEMENT]; unsigned int result; unsigned int element_in_tree = 0; int i = 0; unsigned long rand_seed = (unsigned long) time(NULL); ILOG("Random seed: %lu", rand_seed); srand(rand_seed); for (i = 0; i < MAX_ELEMENT; i++) { data[i] = rand(); } // Try to allocate a new tree. first = init_dictionnary(data_cmp, data_print, data_delete, NULL); if (first == NULL) { ELOG("Init dictionnary error"); return "Init dictionnary error"; } verif_tree(first); for (i = 0; i < MAX_ELEMENT; i++) { if (!is_present(first, &(data[i]))) { element_in_tree++; } result = insert_elmt(first, &(data[i]), sizeof(int)); if (result != element_in_tree) { ELOG("Wrong result of inserted element"); return "Wrong result of inserted element"; } verif_tree(first); } // Try to add existing data for (i = 0; i < MAX_ELEMENT; i++) { if (!is_present(first, &(data[i]))) { ELOG("Element is not present, it said! F**k"); return "Element is not present"; } result = insert_elmt(first, &(data[i]), sizeof(int)); if (result != element_in_tree) { ELOG("Wrong result of inserted element"); return "Wrong result of inserted element"; } verif_tree(first); } // Try to delete it delete_tree(first); return NULL; }
int check_key_door(char *file) { if (is_present("i", file) != 1) return (puterror("Error: the map must countain one entry.\n")); else if (is_present("o", file) != 1) return (puterror("Error: the map must countain one door.\n")); else if (is_present("k", file) != 1) return (puterror("Error: the map must countain one key.\n")); else return (0); }
int u1db__find_unique_expressions(u1database *db, int n_expressions, const char **expressions, int *n_unique, const char ***unique_expressions) { int i, status, present = 0; const char **tmp = NULL; tmp = (const char **)calloc(n_expressions, sizeof(char*)); if (tmp == NULL) { return U1DB_NOMEM; } status = U1DB_OK; *n_unique = 0; for (i = 0; i < n_expressions; ++i) { if (expressions[i] == NULL) { status = U1DB_INVALID_PARAMETER; goto finish; } status = is_present(db, expressions[i], &present); if (status != SQLITE_OK) { goto finish; } if (!present) { tmp[*n_unique] = expressions[i]; (*n_unique)++; } } finish: if (status == U1DB_OK) { *unique_expressions = tmp; } else { free((void*)tmp); } return status; }
void sysfs_power_meter::measure() { bool got_rate = false; bool got_capacity = false; rate = 0.0; capacity = 0.0; this->set_discharging(false); if (!is_present()) return; /** do not jump over. we may have discharging battery */ if (read_sysfs_string("/sys/class/power_supply/%s/status", name) == "Discharging") this->set_discharging(true); got_rate = set_rate_from_power(); got_capacity = set_capacity_from_energy(); if (!got_rate || !got_capacity) { double voltage = get_voltage(); if (voltage < 0.0) return; if (!got_rate) set_rate_from_current(voltage); if (!got_capacity) set_capacity_from_charge(voltage); } }
PageTable* LongModePaging::allocate_page_directory( unsigned pml4_entry_id , unsigned pdpt_entry_id ) { PageTable* pdp_table = get_next_level_address<PageTable>( pml4 , pml4_entry_id); if( pdp_table ) { if(!is_present(pdp_table , pdpt_entry_id)) { PageTable* table_tmp= gm_memalign<PageTable>( CACHE_LINE_BYTES, 1); PageTable* pd_table = new (table_tmp) PageTable(ENTRY_512); validate_entry(pdp_table , pdpt_entry_id , pd_table); cur_pd_num++; return pd_table; } else { PageTable* table = get_next_level_address<PageTable>( pdp_table, pdpt_entry_id); return table; } } else { if(allocate_page_directory_pointer(pml4_entry_id)) { PageTable* pdpt_table = get_next_level_address<PageTable>(pml4,pml4_entry_id); PageTable* table_tmp= gm_memalign<PageTable>( CACHE_LINE_BYTES, 1); PageTable* pd_table=new (table_tmp)PageTable(ENTRY_512); validate_entry(pdpt_table , pdpt_entry_id , pd_table); cur_pd_num++; return pd_table; } } return NULL; }
void tasks_free( job *pj) { task *tp = (task *)GET_NEXT(pj->ji_tasks); obitent *op; infoent *ip; resizable_array *freed_chans = initialize_resizable_array(30); while (tp != NULL) { op = (obitent *)GET_NEXT(tp->ti_obits); while (op != NULL) { delete_link(&op->oe_next); free(op); op = (obitent *)GET_NEXT(tp->ti_obits); } /* END while (op != NULL) */ ip = (infoent *)GET_NEXT(tp->ti_info); while (ip != NULL) { delete_link(&ip->ie_next); free(ip->ie_name); free(ip->ie_info); free(ip); ip = (infoent *)GET_NEXT(tp->ti_info); } if (tp->ti_chan != NULL) { if (is_present(freed_chans, tp->ti_chan) == FALSE) { insert_thing(freed_chans, tp->ti_chan); close_conn(tp->ti_chan->sock, FALSE); DIS_tcp_cleanup(tp->ti_chan); } tp->ti_chan = NULL; } delete_link(&tp->ti_jobtask); free(tp); tp = (task *)GET_NEXT(pj->ji_tasks); } /* END while (tp != NULL) */ free_resizable_array(freed_chans); return; } /* END tasks_free() */
void push (umlclassnode *node, batch *b) { umlclasslist used_classes, tmpnode; module *m; declaration *d; namelist l_tmp; if (node == NULL || find_class (node) != NULL) { return; } l_tmp = NEW (namenode); l_tmp->name = strdup (node->key->name); l_tmp->next = tmp_classes; tmp_classes = l_tmp; used_classes = list_classes (node, b); /* Make sure all classes that this one depends on are already pushed. */ tmpnode = used_classes; while (tmpnode != NULL) { /* don't push this class !*/ if (! eq (node->key->name, tmpnode->key->name) && ! (is_present (tmp_classes, tmpnode->key->name) ^ b->mask)) { push (tmpnode, b); } tmpnode = tmpnode->next; } if (node->key->package != NULL) { umlpackagelist pkglist = make_package_list (node->key->package); m = find_or_add_module (&decls, pkglist); if (m->contents == NULL) { m->contents = NEW (declaration); d = m->contents; d->prev = NULL; } else { /* We can simply append because all classes that we depend on are already pushed. */ d = append_decl (m->contents); } } else { if (decls == NULL) { decls = NEW (declaration); d = decls; d->prev = NULL; } else { d = append_decl (decls); /* We can simply append because all classes that we depend on are already pushed. */ } } d->decl_kind = dk_class; d->next = NULL; d->u.this_class = NEW (umlclassnode); memcpy (d->u.this_class, node, sizeof(umlclassnode)); if (strncmp (node->key->stereotype, "CORBA", 5) == 0) use_corba = 1; }
PageTable* LongModePaging::allocate_page_table(unsigned pml4_entry_id , unsigned pdpt_entry_id , unsigned pdt_entry_id) { assert( mode == LongMode_Normal); PageTable* pdp_table=get_next_level_address<PageTable>(pml4 , pml4_entry_id); if( pdp_table ) { PageTable* pd_table=get_next_level_address<PageTable>(pdp_table , pdpt_entry_id); if(pd_table) { if(is_present(pd_table , pdt_entry_id)) { PageTable* table = get_next_level_address<PageTable>(pd_table,pdt_entry_id); return table; } else { PageTable* table_tmp= gm_memalign<PageTable>( CACHE_LINE_BYTES, 1); PageTable* table = new (table_tmp)PageTable(ENTRY_512); validate_entry(pd_table , pdt_entry_id ,table ); cur_pt_num++; return table; } } //page_direcory doesn't exist allocate else { if( allocate_page_directory(pml4_entry_id,pdpt_entry_id)) { //get page directory PageTable* page_dir = get_next_level_address<PageTable>( pdp_table , pdpt_entry_id); PageTable* table= gm_memalign<PageTable>( CACHE_LINE_BYTES, 1); PageTable* pg_table=new (table)PageTable(ENTRY_512); validate_entry(page_dir , pdt_entry_id , pg_table ); cur_pt_num++; return pg_table; } } } else { PageTable* g_tables = gm_memalign<PageTable>(CACHE_LINE_BYTES,3); PageTable* pdp_table=new (&g_tables[0])PageTable(ENTRY_512); //std::cout<<"validate pg dir pointer in pml4"<<std::dec<<pml4_entry_id<<std::endl; validate_entry(pml4,pml4_entry_id,pdp_table); cur_pdp_num++; PageTable* pd_table=new (&g_tables[1])PageTable(ENTRY_512); //std::cout<<"validate page directory table in pg dir pointer"<<std::dec<<pdpt_entry_id<<std::endl; validate_entry(pdp_table,pdpt_entry_id , pd_table); cur_pd_num++; PageTable* pg_table=new (&g_tables[2])PageTable(ENTRY_512); //std::cout<<"new page table"<<std::endl; validate_entry(pd_table , pdt_entry_id , pg_table); //std::cout<<"validate: "<<std::dec<<pml4_entry_id<<","<<std::dec<<pdpt_entry_id<<","<<std::dec<<pdt_entry_id<<std::endl; cur_pt_num++; return pg_table; } return NULL; }
/* *@function: remove page table whose address is recorded in page directory's page_table_idth entry *@param page_table_id: entry num of page directory,page table this entry pointed to can be removed if the whole page table is unuseful */ bool NormalPaging::remove_page_table(unsigned pd_entry_id) { bool succeed = false; assert(mode==Legacy_Normal); if( is_present(page_directory , pd_entry_id) ) { invalidate_entry<PageTable>(page_directory, pd_entry_id); cur_page_table_num--; succeed = true; } return succeed; }
bool file_writable (const std::string& filespec) { // a file is writable if it exists as a file and is writable or if it doesn't exist but could be created and would be writable if (is_present(filespec)) { if (!is_file(filespec)) return false; return access(filespec.c_str(),W_OK)==0; } std::string dir = folder_part(filespec); if (dir.empty()) dir = "."; return folder_writable(dir); }
/* pfair_tick - this function is called for every local timer * interrupt. */ static void pfair_tick(struct task_struct* t) { struct pfair_state* state = &__get_cpu_var(pfair_state); quanta_t time, cur; int retry = 10; do { cur = current_quantum(state); PTRACE("q %lu at %llu\n", cur, litmus_clock()); /* Attempt to advance time. First CPU to get here * will prepare the next quantum. */ time = cmpxchg(&pfair_time, cur - 1, /* expected */ cur /* next */ ); if (time == cur - 1) { /* exchange succeeded */ wait_for_quantum(cur - 1, state); schedule_next_quantum(cur); retry = 0; } else if (time_before(time, cur - 1)) { /* the whole system missed a tick !? */ catchup_quanta(time, cur, state); retry--; } else if (time_after(time, cur)) { /* our timer lagging behind!? */ TRACE("BAD pfair_time:%lu > cur:%lu\n", time, cur); retry--; } else { /* Some other CPU already started scheduling * this quantum. Let it do its job and then update. */ retry = 0; } } while (retry); /* Spin locally until time advances. */ wait_for_quantum(cur, state); /* copy assignment */ /* FIXME: what if we race with a future update? Corrupted state? */ state->local = state->linked; /* signal that we are done */ mb(); state->local_tick = state->cur_tick; if (state->local != current && (is_realtime(current) || is_present(state->local))) set_tsk_need_resched(current); }
//allocate PageTable* LongModePaging::allocate_page_directory_pointer( unsigned pml4_entry_id) { assert( pml4_entry_id<512 && cur_pdp_num<ENTRY_512); if( !is_present(pml4, pml4_entry_id)) { PageTable* table_tmp= gm_memalign<PageTable>( CACHE_LINE_BYTES, 1); PageTable* table = new (table_tmp) PageTable(ENTRY_512); validate_entry(pml4 , pml4_entry_id , table); cur_pdp_num++; return table; } PageTable* pg_dir_p = get_next_level_address<PageTable>( pml4,pml4_entry_id); return pg_dir_p; }
/** * Takes in a key and priority and adds them to numsVec * and nums Map. Adds to numsVec as a pair. * * @param key key, integer * @param priority priority, integer */ void priorityqueue62::push(int key, int priority) { //check that key does not exist already in our map assert(!is_present(key)); //increment our queue size priorityqueue62::queue_size++; //add to our vector and percolate up numsVec.push_back(make_pair(key,priority)); percolateUp(numsVec.size() - 1); //add to our map numsMap.insert(make_pair(key,priority)); }
int compute_levels(std::vector<CloudNode> nodes) { std::vector<int>levels; for(int i=0;i<nodes.size();i++) { int level=compute_level(nodes,i); if(!is_present(levels,level)) { levels.push_back(level); } } return levels.size(); }
//remove void LongModePaging::remove_root_directory() { if( pml4) { for( unsigned i=0 ; i<ENTRY_512;i++ ) { if(is_present(pml4,i)) { remove_page_directory_pointer(i); } } delete pml4; pml4=NULL; } }
//delete whole structures of page tables void PAEPaging::remove_root_directory() { assert(page_directory_pointer); for(unsigned i=0 ; i<ENTRY_4 ; i++) { if( is_present(page_directory_pointer , i)) { if( remove_pdt(i)==false ) { debug_printf("remove page directory entry %d of page direcotry pointer pointed to failed", i); } } } delete page_directory_pointer; page_directory_pointer = NULL; }
/** * Reduces of the priority of the pair associated with a given key. * Takes in a key int value and sets it the new_priority value that * the method is called with. */ void priorityqueue62::reduce_priority(int key, int new_priority) { //make sure key is in the map assert(is_present(key)); //make sure new priority is less than old priority assert(get_priority(key) > new_priority); //call find index of to find the index of the pair associated //with the key that is passed in and assign it a variable int reduce_index = findIndexOf(get_priority(key), 0); pair<int,int> reduce_pair = numsVec[reduce_index]; //erase the pair from the map and add in the new one numsMap.erase(key); pushDownRoot(reduce_index); push(key, new_priority); }
static int leap_initialise(struct stk_camera *dev) { struct regval *rv; int ret; if (!is_present(dev)) return -ENODEV; if (is_initialised(dev)) return 0; rv = stk1125_initvals; while (rv->reg != 0xffff) { ret = leap_camera_write_reg(dev, rv->reg, rv->val); if (ret) return ret; rv++; } set_initialised(dev); return 0; }
static int leap_stop_stream(struct stk_camera *dev) { int value; int i; if (is_present(dev)) { leap_camera_read_reg(dev, 0x0100, &value); leap_camera_write_reg(dev, 0x0100, value & ~0x80); if (dev->isobufs != NULL) { for (i = 0; i < MAX_ISO_BUFS; i++) { if (dev->isobufs[i].urb) usb_kill_urb(dev->isobufs[i].urb); } } unset_streaming(dev); if (usb_set_interface(dev->udev, 0, 0)) LEAP_ERROR("usb_set_interface failed !\n"); } return 0; }
static int stk_start_stream(struct stk_camera *dev) { int value; int i, ret; int value_116, value_117; if (!is_present(dev)) return -ENODEV; if (!is_memallocd(dev) || !is_initialised(dev)) { STK_ERROR("FIXME: Buffers are not allocated\n"); return -EFAULT; } ret = usb_set_interface(dev->udev, 0, 5); if (ret < 0) STK_ERROR("usb_set_interface failed !\n"); if (stk_sensor_wakeup(dev)) STK_ERROR("error awaking the sensor\n"); stk_camera_read_reg(dev, 0x0116, &value_116); stk_camera_read_reg(dev, 0x0117, &value_117); stk_camera_write_reg(dev, 0x0116, 0x0000); stk_camera_write_reg(dev, 0x0117, 0x0000); stk_camera_read_reg(dev, 0x0100, &value); stk_camera_write_reg(dev, 0x0100, value | 0x80); stk_camera_write_reg(dev, 0x0116, value_116); stk_camera_write_reg(dev, 0x0117, value_117); for (i = 0; i < MAX_ISO_BUFS; i++) { if (dev->isobufs[i].urb) { ret = usb_submit_urb(dev->isobufs[i].urb, GFP_KERNEL); atomic_inc(&dev->urbs_used); if (ret) return ret; } } set_streaming(dev); return 0; }
bool LongModePaging::remove_page_directory(unsigned pml4_entry_id , unsigned pdp_entry_id) { assert(mode!=LongMode_Huge && pml4_entry_id<512 && pdp_entry_id<512); PageTable* pdp_table = NULL; if( (pdp_table= get_next_level_address<PageTable>(pml4, pml4_entry_id)) ) { PageTable* pd_table = NULL; if( (pd_table=get_next_level_address<PageTable>(pdp_table , pdp_entry_id)) ) { if(mode==LongMode_Normal) { for(unsigned i=0 ; i<ENTRY_512;i++) if( is_present(pd_table , i)) remove_page_table( pml4_entry_id , pdp_entry_id , i); } invalidate_entry<PageTable>(pdp_table,pdp_entry_id); cur_pd_num--; } } return true; }
bool PAEPaging::remove_pdt( unsigned pdp_entry_id) { bool succeed = false; PageTable* page_dir = get_next_level_address<PageTable>(page_directory_pointer , pdp_entry_id); if(page_dir) { if( mode == PAE_Huge) { invalidate_entry<PageTable>( page_directory_pointer,pdp_entry_id); succeed = true; cur_pdt_num--; } else if( mode == PAE_Normal) { unsigned i=0; //delete presented page table for( i=0 ; i<ENTRY_512; i++) { if( is_present( page_dir ,i)) { if(remove_page_table(pdp_entry_id ,i)==false) { debug_printf("remove %d entry of page table failed!",i); succeed = false; } } } if( i== ENTRY_512 ) { cur_pdt_num--; succeed = true; } } } else { debug_printf("entry %d of page direcotry pointer pointed to nothing", pdp_entry_id); } return succeed; }
bool LongModePaging::remove_page_directory_pointer(unsigned pml4_entry_id) { bool succeed = true; PageTable* pdp_table= get_next_level_address<PageTable>(pml4,pml4_entry_id); if(pdp_table) { if( mode!=LongMode_Huge) { for(unsigned i=0;i<ENTRY_512;i++) { if( is_present(pdp_table,i)) { if( remove_page_directory(pml4_entry_id , i)==false) succeed = false; } } } invalidate_entry<PageTable>(pml4,pml4_entry_id); cur_pdp_num--; } return succeed; }
/* *@function: delete page table referred by (pdpt_num[entry id of page directory pointer],pd_num[entry id of page directory]) *@param pdpt_num: entry id of page directory pointer table *@param pd_num: entry id of page directory table */ bool PAEPaging::remove_page_table( unsigned pdpt_num , unsigned pd_num ) { bool succeed = false; assert(pdpt_num<ENTRY_4 && pd_num< ENTRY_512 && mode==PAE_Normal); PageTable *page_dir = get_next_level_address<PageTable>( page_directory_pointer , pdpt_num); if(page_dir) { if( is_present(page_dir , pd_num)) { invalidate_entry<PageTable>( page_dir , pd_num ); cur_pt_num--; succeed = true; } else debug_printf("entry %d of page directory is invalid", pd_num); } else { debug_printf("entry %d of page directory pointer is invalid",pdpt_num); } return succeed; }
int move_cursor_to_file(int start_idx, const char *filename, int win) { void (*f)(int, int); int delta, len; char fullpath[PATH_MAX + 1] = {0}; snprintf(fullpath, PATH_MAX, "%s/%s", ps[win].my_cwd, filename); len = strlen(fullpath); int i = is_present(fullpath, ps[win].nl, ps[win].number_of_files, len, start_idx); if (i != -1) { if (i != ps[win].curr_pos) { if (i < ps[win].curr_pos) { f = scroll_up; delta = ps[win].curr_pos - i; } else { f = scroll_down; delta = i - ps[win].curr_pos; } f(win, delta); } return 1; } return 0; }
char *get_data_tests() { tree *first = NULL; struct _tree_data data[MAX_ELEMENT]; struct _tree_data tmp_elmnt; struct _tree_data current_min; unsigned int result; unsigned int element_in_tree = 0; int i = 0; int j = 0; unsigned long rand_seed = (unsigned long) time(NULL); ILOG("Random seed: %lu", rand_seed); srand(rand_seed); for (i = 0; i < MAX_ELEMENT; i++) { data[i].key = rand(); data[i].value = rand(); } verif_tree(first); // Try to allocate a new tree. first = init_dictionnary(data_cmp, data_print, data_delete, NULL); if (first == NULL) { ELOG("Init dictionnary error"); return "Init dictionnary error"; } // Add data verif_tree(first); for (i = 0; i < MAX_ELEMENT; i++) { tmp_elmnt.key = data[i].key; if (!is_present(first, &(tmp_elmnt))) { element_in_tree++; } result = insert_elmt(first, &(data[i]), sizeof(struct _tree_data)); if (result != element_in_tree) { ELOG("Wrong result of inserted element"); return "Wrong result of inserted element"; } verif_tree(first); } current_min.key = (int) 0x80000000; current_min.value = (int) 0x80000000; for (i = 0; i < MAX_ELEMENT && element_in_tree != 0; i++) { tmp_elmnt.key = (int) 0x7fffffff; tmp_elmnt.value = (int) 0x7fffffff; // Get minimum data for (j = 0; j < MAX_ELEMENT; j++) { if ( data[j].key < tmp_elmnt.key && data[j].key > current_min.key) { tmp_elmnt.key = data[j].key; tmp_elmnt.value = data[j].value; } } current_min.key = tmp_elmnt.key; current_min.value = tmp_elmnt.value; if (!is_present(first, &tmp_elmnt)) { ELOG("Minimum data not in tree"); return "Minimum data not in tree"; } delete_node_min(first); if (is_present(first, &tmp_elmnt)) { ELOG("Minimum element deleted"); return "Minimum element deleted"; } element_in_tree--; verif_tree(first); } // Try to delete it delete_tree(first); return NULL; }
int main( int argc, char **argv ) { int c; int errflag = 0; int orb; int stop = 0; long nrecs; char *match = ".*/pf/st"; char *from = 0; char *statefile = 0; char *pfname = "orb2rrdc"; char *orbname; char *dbcache; char *rrdtool; char command[STRSZ]; char net[STRSZ]; char sta[STRSZ]; char rrdvar[STRSZ]; char key[STRSZ]; char path[FILENAME_MAX]; Dbptr db; Dbptr dbt; Pf *pf; char *Default_network; Tbl *dlslines; Arr *Dls_vars_dsparams; Arr *Dls_vars_rras; Tbl *Dls_vars_keys; char *line; char *dls_var; char *dsparams; Tbl *rras; int i; int j; OrbreapThr *ort; int pktid; char srcname[ORBSRCNAME_SIZE]; double time = 0; char *packet = 0; int nbytes = 0; int bufsize = 0; Packet *pkt = 0; int rc; char *s; Pf *dlspf; Tbl *dlspfkeys; char *element; Tbl *parts; double val; Pf *pfval = 0; elog_init( argc, argv ); while( ( c = getopt( argc, argv, "vVd:s:p:m:f:" ) ) != -1 ) { switch( c ) { case 'd': CacheDaemon = optarg; break; case 'f': from = optarg; break; case 'm': match = optarg; break; case 'p': pfname = optarg; break; case 's': statefile = optarg; break; case 'v': Verbose++; break; case 'V': VeryVerbose++; Verbose++; break; default: elog_complain( 0, "Unknown option '%c'\n", c ); errflag++; break; } } if( errflag || argc - optind != 2 ) { usage(); } if( Verbose ) { elog_notify( 0, "Starting at %s (%s $Revision$ $Date$)\n", zepoch2str( str2epoch( "now" ), "%D %T %Z", "" ), Program_Name ); } orbname = argv[optind++]; dbcache = argv[optind++]; pfread( pfname, &pf ); rrdtool = pfget_string( pf, "rrdtool" ); if( rrdtool == NULL || ! strcmp( rrdtool, "" ) ) { elog_die( 0, "Error: no rrdtool executable name specified in parameter file\n" ); } else if( ( rrdtool[0] == '/' && ! is_present( rrdtool ) ) || ( rrdtool[0] != '/' && ! datafile( "PATH", rrdtool ) ) ) { elog_die( 0, "Error: can't find rrdtool executable by name of '%s' (check PATH environment " "variable, or absolute path name if given)\n", rrdtool ); } else if( rrdtool[0] == '/' ) { sprintf( command, "%s -", rrdtool ); } else { sprintf( command, "rrdtool -" ); } Suppress_egrep = pfget_string( pf, "suppress_egrep" ); if( Suppress_egrep != NULL && strcmp( Suppress_egrep, "" ) ) { if( ! datafile( "PATH", "egrep" ) ) { elog_complain( 0, "Ignoring suppress_egrep parameter: can't find egrep on path\n" ); } else { sprintf( command, "%s 2>&1 | egrep -v '%s'", command, Suppress_egrep ); } } if( VeryVerbose ) { elog_notify( 0, "Executing command: %s\n", command ); } Rrdfp = popen( command, "w" ); if( Rrdfp == (FILE *) NULL ) { elog_die( 0, "Failed to open socket to rrdtool command\n" ); } orb = orbopen( orbname, "r&" ); if( orb < 0 ) { elog_die( 0, "Failed to open orb '%s' for reading. Bye.\n", orbname ); } orbselect( orb, match ); if( from != NULL && statefile == NULL ) { pktid = orbposition( orb, from ); if( Verbose ) { elog_notify( 0, "Positioned to packet %d\n", pktid ); } } else if( from != NULL ) { elog_complain( 0, "Ignoring -f in favor of existing state file\n" ); } if( statefile != NULL ) { stop = 0; exhume( statefile, &stop, 15, 0 ); orbresurrect( orb, &pktid, &time ); if( Verbose ) { elog_notify( 0, "Resurrecting state to pktid %d, time %s\n", pktid, s = strtime( time ) ); free( s ); } orbseek( orb, pktid ); } dbopen( dbcache, "r+", &db ); if( db.database < 0 ) { elog_die( 0, "Failed to open cache database '%s'. Bye.\n", dbcache ); } else { db = dblookup( db, "", "rrdcache", "", "" ); if( db.table < 0 ) { elog_die( 0, "Failed to lookup 'rrdcache' table in '%s'. Bye.\n", dbcache ); } } dbcrunch( db ); dbt = dbsubset( db, "endtime == NULL", NULL ); Rrd_files = newarr( 0 ); dbquery( dbt, dbRECORD_COUNT, &nrecs ); for( dbt.record = 0; dbt.record < nrecs; dbt.record++ ) { dbgetv( dbt, 0, "net", &net, "sta", &sta, "rrdvar", &rrdvar, NULL ); dbfilename( dbt, (char *) &path ); sprintf( key, "%s:%s:%s", net, sta, rrdvar ); if( ! is_present( path ) ) { elog_complain( 0, "WARNING: rrd file '%s', listed in database, does not exist. " "Removing database entry.\n", path ); dbmark( dbt ); } else { setarr( Rrd_files, key, strdup( path ) ); if( VeryVerbose ) { elog_notify( 0, "Re-using rrd file '%s' for '%s'\n", path, key ); } } } Rrdfile_pattern = pfget_string( pf, "rrdfile_pattern" ); Status_stepsize_sec = pfget_double( pf, "status_stepsize_sec" ); Default_network = pfget_string( pf, "default_network" ); dlslines = pfget_tbl( pf, "dls_vars" ); Dls_vars_dsparams = newarr( 0 ); Dls_vars_rras = newarr( 0 ); for( i = 0; i < maxtbl( dlslines ); i++ ) { line = gettbl( dlslines, i ); strtr( line, "\t", " " ); rras = split( line, ' ' ); dls_var = shifttbl( rras ); dsparams = shifttbl( rras ); setarr( Dls_vars_dsparams, dls_var, dsparams ); setarr( Dls_vars_rras, dls_var, rras ); } ort = orbreapthr_new( orb, -1., 0 ); for( ; stop == 0; ) { orbreapthr_get( ort, &pktid, srcname, &time, &packet, &nbytes, &bufsize ); if( statefile ) { rc = bury(); if( rc < 0 ) { elog_complain( 0, "Unexpected failure of bury command! " "(are there two orb2rrdc's running with the same state" "file?)\n" ); clear_register( 1 ); } } rc = unstuffPkt( srcname, time, packet, nbytes, &pkt ); if( rc == Pkt_pf ) { if( VeryVerbose ) { /* Parameter files generally too big for elog */ fprintf( stderr, "Received a parameter-file '%s' at %s\n%s\n\n", srcname, s = strtime( time ), pf2string( pkt->pf ) ); free( s ); } else if( Verbose ) { elog_notify( 0, "Received a parameter-file '%s' at %s\n", srcname, s = strtime( time ) ); free( s ); } pfmorph( pkt->pf ); if( VeryVerbose ) { fprintf( stderr, "Morphed parameter-file '%s' to interpret 'opt':\n%s\n\n", srcname, pf2string( pkt->pf ) ); } pfget( pkt->pf, "dls", (void **) &dlspf ); dlspfkeys = pfkeys( dlspf ); Dls_vars_keys = keysarr( Dls_vars_dsparams ); for( i = 0; i < maxtbl( dlspfkeys ); i++ ) { element = gettbl( dlspfkeys, i ); if( strcontains( element, "_", 0, 0, 0 ) ) { parts = split( (s = strdup( element )), '_' ); sprintf( net, "%s", (char *) gettbl( parts, 0 ) ); sprintf( sta, "%s", (char *) gettbl( parts, 1 ) ); free( s ); freetbl( parts, 0 ); } else { sprintf( net, "%s", Default_network ); sprintf( sta, "%s", element ); } for( j = 0; j < maxtbl( Dls_vars_keys ); j++ ) { dls_var = gettbl( Dls_vars_keys, j ); sprintf( key, "%s{%s}", element, dls_var ); if( pfresolve( dlspf, key, 0, &pfval ) < 0 ) { elog_complain( 0, "Unable to extract variable '%s' " "(not present or wrong type) from element '%s' " "in packet from '%s', timestamped '%s'; Skipping\n", key, element, srcname, s = strtime( time ) ); free( s ); pfval = 0; continue; } else if( pfval != (Pf *) NULL && pfval->value.s != (char *) NULL && ! strcmp( pfval->value.s, "-" ) ) { if( VeryVerbose ) { elog_notify( 0, "Non-floating point value '-' in variable '%s', " "in packet from '%s', timestamped '%s'; Skipping data point\n", key, srcname, s = strtime( time ) ); free( s ); } continue; } else { val = pfget_double( dlspf, key ); } archive_dlsvar( db, net, sta, dls_var, (char *) getarr( Dls_vars_dsparams, dls_var ), (Tbl *) getarr( Dls_vars_rras, dls_var ), time, val ); } } freetbl( dlspfkeys, 0 ); freetbl( Dls_vars_keys, 0 ); } else if( rc == Pkt_stash ) { ; /* Do nothing */ } else { if( Verbose ) { elog_notify( 0, "Received a packet that's not a parameter file " "(type '%d' from unstuffPkt); skipping\n", rc ); } } } }
void generate_code_shp(batch *b) { /* umlclasslist tmplist,parents,dependencies; umlassoclist associations; namelist used_classes,tmpnamelist; int tmpv; umlattrlist umla,tmpa; umloplist umlo; */ umlclasslist tmplist; umlclasslist parentlist, parentlist2; umlattrlist umla; int tmpv; char *tmpname; char outfilename[BIG_BUFFER]; FILE * outfileshp, *dummyfile; int tmpdirlgth, tmpfilelgth; if (b->outdir == NULL) { b->outdir = "."; } tmpdirlgth = strlen(b->outdir); tmplist = b->classlist; while ( tmplist != NULL ) { if ( ! ( is_present(b->classes, tmplist->key->name) ^ b->mask ) ) { tmpname = strtolower(tmplist->key->name); /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } sprintf(outfilename, "%s/createshapefiles.bat", b->outdir); dummyfile = fopen(outfilename, "r"); if ( b->clobber || ! dummyfile ) { outfileshp = fopen(outfilename, "a"); if ( outfileshp == NULL ) { fprintf(stderr, "Can't open file %s for writing\n", outfilename); exit(3); } /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } free(tmpname); tmpv = -1; if(tmplist->key->isabstract == 0) { /* create attribute table */ umla = tmplist->key->attributes; parentlist = tmplist; fprintf(outfileshp, "dbfcreate %s", tmplist->key->name); while ( umla != NULL) { if((strcmp(umla->key.name,"Shape") != 0)&& (umla->key.visibility != 1)) { if(strcmp(umla->key.type,"String") == 0) { fprintf(outfileshp, " -s %s 255", umla->key.name); } else if((strcmp(umla->key.type, "CodedValue") == 0)|| strcmp(umla->key.type, "Integer") ==0 ) { fprintf(outfileshp, " -n %s 16 0", umla->key.name); } else if(strcmp(umla->key.type, "Float") == 0) { fprintf(outfileshp, " -n %s 16 3", umla->key.name); } } umla = umla->next; if((umla == NULL)&&(parentlist != NULL)) { parentlist = parentlist->parents; if(parentlist != NULL) { umla = parentlist->key->attributes; parentlist2 = b->classlist; while((strcmp(parentlist->key->name, parentlist2->key->name) != 0)&& (parentlist2 != NULL)) parentlist2 = parentlist2->next; parentlist = parentlist2; } } } fprintf(outfileshp, "\n"); /* create shp file */ umla = tmplist->key->attributes; parentlist = tmplist; while ( umla != NULL) { if(strcmp(umla->key.name,"Shape") == 0) { if(strcmp(strtolower(umla->key.type), "polyline") == 0) { strcpy(umla->key.type, "arc"); } fprintf(outfileshp, "shpcreate %s %s\n\n", tmplist->key->name, strtolower(umla->key.type)); break; } umla = umla->next; if((umla == NULL)&&(parentlist != NULL)) { parentlist = parentlist->parents; if(parentlist != NULL) { umla = parentlist->key->attributes; parentlist2 = b->classlist; while((strcmp(parentlist->key->name, parentlist2->key->name) != 0)&& (parentlist2 != NULL)) parentlist2 = parentlist2->next; parentlist = parentlist2; } } } } } fclose(outfileshp); } tmplist = tmplist->next; } }
void generate_code_python(batch *b) { umlclasslist tmplist, parents; umlattrlist umla, tmpa; umloplist umlo; char *tmpname; char outfilename[90]; FILE * outfile, *dummyfile, *licensefile = NULL; namelist used_classes, tmpnamelist; int tmpdirlgth, tmpfilelgth; int interface, abstract; if (b->outdir == NULL) { b->outdir = "."; } tmpdirlgth = strlen(b->outdir); tmplist = b->classlist; /* open license file */ if ( b->license != NULL ) { licensefile = fopen(b->license, "r"); if(!licensefile) { fprintf(stderr, "Can't open the license file.\n"); exit(2); } } while ( tmplist != NULL ) { if ( ! ( is_present(b->classes, tmplist->key->name) ^ b->mask ) ) { tmpname = tmplist->key->name; /* This prevents buffer overflows */ tmpfilelgth = strlen(tmpname); if (tmpfilelgth + tmpdirlgth > sizeof(*outfilename) - 2) { fprintf(stderr, "Sorry, name of file too long ...\nTry a smaller dir name\n"); exit(4); } sprintf(outfilename, "%s/%s.py", b->outdir, tmplist->key->name); dummyfile = fopen(outfilename, "r"); if ( b->clobber || ! dummyfile ) { outfile = fopen(outfilename, "w"); if ( outfile == NULL ) { fprintf(stderr, "Can't open file %s for writing\n", outfilename); exit(3); } /* add license to the header */ if(b->license != NULL){ char lc; rewind(licensefile); while((lc = fgetc(licensefile)) != EOF){ fprintf(outfile,"%c",lc); } } used_classes = find_classes(tmplist, b); tmpnamelist = used_classes; while (tmpnamelist != NULL) { fprintf(outfile, "from %s import %s\n", tmpnamelist->name, tmpnamelist->name); tmpnamelist = tmpnamelist->next; } fprintf(outfile, "\n"); tmpname = strtolower(tmplist->key->stereotype); interface = !strcmp("interface", tmpname); abstract = tmplist->key->isabstract; free(tmpname); fprintf(outfile, "class %s", tmplist->key->name); parents = tmplist->parents; if (parents != NULL) { fprintf(outfile, "("); while ( parents != NULL ) { fprintf(outfile, "%s", parents->key->name); parents = parents->next; if (parents != NULL) fprintf(outfile, ", "); } fprintf(outfile, ")"); } fprintf(outfile, ":\n"); if (abstract) { fprintf(outfile, " \"\"\"Abstract class %s\n \"\"\"\n", tmplist->key->name); } else if (interface) { fprintf(outfile, " \"\"\"Interface %s\n \"\"\"\n", tmplist->key->name); } else { fprintf(outfile, " \"\"\"Class %s\n \"\"\"\n", tmplist->key->name); } fprintf(outfile, " # Attributes:\n"); umla = tmplist->key->attributes; while ( umla != NULL) { switch (umla->key.visibility) { case '0': fprintf (outfile, " "); break; case '1': fprintf (outfile, " __"); break; case '2': fprintf (outfile, " _"); break; } fprintf(outfile, "%s", umla->key.name); if ( umla->key.value[0] != 0 ) { fprintf(outfile, " = %s", umla->key.value); } else { fprintf(outfile, " = None"); } fprintf(outfile, " # (%s) \n", umla->key.type); umla = umla->next; } fprintf(outfile, " \n"); umlo = tmplist->key->operations; fprintf(outfile, " # Operations\n"); while ( umlo != NULL) { switch (umlo->key.attr.visibility) { case '0': fprintf (outfile, " def %s(self", umlo->key.attr.name); break; case '1': fprintf (outfile, " def __%s(self", umlo->key.attr.name); break; case '2': fprintf (outfile, " def _%s(self", umlo->key.attr.name); break; } tmpa = umlo->key.parameters; while (tmpa != NULL) { fprintf(outfile, ", %s", tmpa->key.name); if ( tmpa->key.value[0] != 0 ) { fprintf(outfile, " = %s", tmpa->key.value); } tmpa = tmpa->next; } fprintf(outfile, "):\n"); fprintf(outfile, " \"\"\"function %s\n", umlo->key.attr.name); tmpa = umlo->key.parameters; if (tmpa) fprintf(outfile, " \n"); while (tmpa != NULL) { fprintf(outfile, " %s: %s\n", tmpa->key.name, tmpa->key.type); tmpa = tmpa->next; } fprintf(outfile, " \n"); fprintf(outfile, " returns %s\n", umlo->key.attr.type); fprintf(outfile, " \"\"\"\n"); if (abstract || interface) { fprintf(outfile, " raise NotImplementedError()\n \n"); } else { fprintf(outfile, " return None # should raise NotImplementedError()\n \n"); } umlo = umlo->next; } fprintf(outfile, "\n"); fclose(outfile); } } tmplist = tmplist->next; } }