static void show_files(struct dir_struct *dir, const char *prefix) { int i; /* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) { const char *path = ".", *base = ""; int baselen = prefix_len; if (baselen) path = base = prefix; read_directory(dir, path, base, baselen, pathspec); if (show_others) show_other_files(dir); if (show_killed) show_killed_files(dir); } if (show_cached | show_stage) { for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; int dtype = ce_to_dtype(ce); if (excluded(dir, ce->name, &dtype) != dir->show_ignored) continue; if (show_unmerged && !ce_stage(ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce); } } if (show_deleted | show_modified) { for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; struct stat st; int err; int dtype = ce_to_dtype(ce); if (excluded(dir, ce->name, &dtype) != dir->show_ignored) continue; if (ce->ce_flags & CE_UPDATE) continue; err = lstat(ce->name, &st); if (show_deleted && err) show_ce_entry(tag_removed, ce); if (show_modified && ce_modified(ce, &st, 0)) show_ce_entry(tag_modified, ce); } } }
static void show_files(struct dir_struct *dir, const char *prefix) { int i; /* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) { fill_directory(dir, pathspec); if (show_others) show_other_files(dir); if (show_killed) show_killed_files(dir); } if (show_cached | show_stage) { for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; int dtype = ce_to_dtype(ce); if (dir->flags & DIR_SHOW_IGNORED && !excluded(dir, ce->name, &dtype)) continue; if (show_unmerged && !ce_stage(ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; show_ce_entry(ce_stage(ce) ? tag_unmerged : (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce); } } if (show_deleted | show_modified) { for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; struct stat st; int err; int dtype = ce_to_dtype(ce); if (dir->flags & DIR_SHOW_IGNORED && !excluded(dir, ce->name, &dtype)) continue; if (ce->ce_flags & CE_UPDATE) continue; if (ce_skip_worktree(ce)) continue; err = lstat(ce->name, &st); if (show_deleted && err) show_ce_entry(tag_removed, ce); if (show_modified && ce_modified(ce, &st, 0)) show_ce_entry(tag_modified, ce); } } }
bool ARMarkerTracking::spotted(double younger_than, const ar_track_alvar_msgs::AlvarMarkers& including, const ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarkers& spotted) { if (spotted_markers_.markers.size() == 0) return false; if ((ros::Time::now() - spotted_markers_.markers[0].header.stamp).toSec() >= younger_than) { return false; } spotted.header = spotted_markers_.header; spotted.markers.clear(); for (unsigned int i = 0; i < spotted_markers_.markers.size(); i++) { if ((included(spotted_markers_.markers[i].id, including) == true) && (excluded(spotted_markers_.markers[i].id, excluding) == true)) { spotted.markers.push_back(spotted_markers_.markers[i]); } } return (spotted.markers.size() > 0); }
static void border(int *b,int i,int j,double d0,double d1, double cut,double *cutp,int dirmode) { int t; t=excluded(i,j,dirmode); switch (t) { case 0: if (((d0>=cut)&&(d1<cut))||((d0<cut)&&(d1>=cut))) { set_exclude(i,j,dirmode,3); *cutp=(cut-d0)/(d1-d0); *b=4; } else { *b=0; } break; case 1: *cutp=(cut-d0)/(d1-d0); *b=5; break; case 3: *cutp=(cut-d0)/(d1-d0); *b=3; break; default : /* printf("Error in contour b=%d encountered\n",t);*/ *b=0; } }
bool ARMarkerTracking::spotted(double younger_than, double min_confidence, ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarkers& spotted) { if (spotted_markers_.markers.size() == 0) return false; if ((ros::Time::now() - spotted_markers_.markers[0].header.stamp).toSec() >= younger_than) { // We must check the timestamp from an element in the markers list, as the one on message's header is always zero! // WARNING: parameter younger_than must be high enough, as ar_track_alvar publish at Kinect rate but only updates // timestamps about every 0.1 seconds (and now we can set it to run slower, as frequency is a dynamic parameter!) ROS_WARN("Spotted markers too old: %f >= %f", (ros::Time::now() - spotted_markers_.markers[0].header.stamp).toSec(), younger_than); return false; } spotted.header = spotted_markers_.header; spotted.markers.clear(); for(unsigned int i = 0; i < spotted_markers_.markers.size(); i++) { ar_track_alvar_msgs::AlvarMarker m = spotted_markers_.markers[i]; if ((tracked_markers_[m.id].confidence >= min_confidence) &&(excluded(m.id, excluding))) { spotted.markers.push_back(m); } } return (spotted.markers.size() > 0); }
static enum path_treatment treat_one_path(struct dir_struct *dir, char *path, int *len, const struct path_simplify *simplify, int dtype, struct dirent *de) { int exclude = excluded(dir, path, &dtype); if (exclude && (dir->flags & DIR_COLLECT_IGNORED) && exclude_matches_pathspec(path, *len, simplify)) dir_add_ignored(dir, path, *len); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & DIR_SHOW_IGNORED)) return path_ignored; if (dtype == DT_UNKNOWN) dtype = get_dtype(de, path, *len); /* * Do we want to see just the ignored files? * We still need to recurse into directories, * even if we don't ignore them, since the * directory may contain files that we do.. */ if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) { if (dtype != DT_DIR) return path_ignored; } switch (dtype) { default: return path_ignored; case DT_DIR: memcpy(path + *len, "/", 2); (*len)++; switch (treat_directory(dir, path, *len, simplify)) { case show_directory: if (exclude != !!(dir->flags & DIR_SHOW_IGNORED)) return path_ignored; break; case recurse_into_directory: return path_recurse; case ignore_directory: return path_ignored; } break; case DT_REG: case DT_LNK: break; } return path_handled; }
/* * Is this name excluded? This is for a caller like show_files() that * do not honor directory hierarchy and iterate through paths that are * possibly in an ignored directory. * * A path to a directory known to be excluded is left in check->path to * optimize for repeated checks for files in the same excluded directory. */ int path_excluded(struct path_exclude_check *check, const char *name, int namelen, int *dtype) { int i; struct strbuf *path = &check->path; /* * we allow the caller to pass namelen as an optimization; it * must match the length of the name, as we eventually call * excluded() on the whole name string. */ if (namelen < 0) namelen = strlen(name); if (path->len && path->len <= namelen && !memcmp(name, path->buf, path->len) && (!name[path->len] || name[path->len] == '/')) return 1; strbuf_setlen(path, 0); for (i = 0; name[i]; i++) { int ch = name[i]; if (ch == '/') { int dt = DT_DIR; if (excluded(check->dir, path->buf, &dt)) return 1; } strbuf_addch(path, ch); } /* An entry in the index; cannot be a directory with subentries */ strbuf_setlen(path, 0); return excluded(check->dir, name, dtype); }
static int append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) { struct archive_entry *in_entry; int e; while (0 == archive_read_next_header(ina, &in_entry)) { if (!new_enough(bsdtar, archive_entry_pathname(in_entry), archive_entry_stat(in_entry))) continue; if (excluded(bsdtar, archive_entry_pathname(in_entry))) continue; if (bsdtar->option_interactive && !yes("copy '%s'", archive_entry_pathname(in_entry))) continue; if (bsdtar->verbose) safe_fprintf(stderr, "a %s", archive_entry_pathname(in_entry)); siginfo_setinfo(bsdtar, "copying", archive_entry_pathname(in_entry), archive_entry_size(in_entry)); siginfo_printinfo(bsdtar, 0); e = archive_write_header(a, in_entry); if (e != ARCHIVE_OK) { if (!bsdtar->verbose) bsdtar_warnc(bsdtar, 0, "%s: %s", archive_entry_pathname(in_entry), archive_error_string(a)); else fprintf(stderr, ": %s", archive_error_string(a)); } if (e == ARCHIVE_FATAL) exit(1); if (e >= ARCHIVE_WARN) { if (archive_entry_size(in_entry) == 0) archive_read_data_skip(ina); else if (copy_file_data(bsdtar, a, ina)) exit(1); } if (bsdtar->verbose) fprintf(stderr, "\n"); } /* Note: If we got here, we saw no write errors, so return success. */ return (0); }
static void mode_list(struct cpio *cpio) { struct archive *a; struct archive_entry *entry; unsigned long blocks; int r; a = archive_read_new(); if (a == NULL) cpio_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_compression_all(a); archive_read_support_format_all(a); if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) cpio_errc(1, archive_errno(a), archive_error_string(a)); for (;;) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { cpio_errc(1, archive_errno(a), archive_error_string(a)); } if (excluded(cpio, archive_entry_pathname(entry))) continue; if (cpio->verbose) list_item_verbose(cpio, entry); else fprintf(stdout, "%s\n", archive_entry_pathname(entry)); } r = archive_read_close(a); if (r != ARCHIVE_OK) cpio_errc(1, 0, archive_error_string(a)); if (!cpio->quiet) { blocks = (archive_position_uncompressed(a) + 511) / 512; fprintf(stderr, "%lu %s\n", blocks, blocks == 1 ? "block" : "blocks"); } archive_read_finish(a); exit(0); }
bool ARMarkerTracking::closest(const ar_track_alvar_msgs::AlvarMarkers& including, const ar_track_alvar_msgs::AlvarMarkers& excluding, ar_track_alvar_msgs::AlvarMarker& closest) { double closest_dist = std::numeric_limits<double>::max(); for (unsigned int i = 0; i < spotted_markers_.markers.size(); i++) { if ((included(spotted_markers_.markers[i].id, including) == true) && (excluded(spotted_markers_.markers[i].id, excluding) == true)) { double d = mtk::distance2D(spotted_markers_.markers[i].pose.pose.position); if (d < closest_dist) { closest_dist = d; closest = spotted_markers_.markers[i]; } } } return (closest_dist < std::numeric_limits<double>::max()); }
static int traverse_dir_enter( void *arg, const char *path, const struct stat *st, void *pcontinuation, void **continuation ) { const char *rel_path; if(g_one_file_system && g_dev != st->st_dev) return 0; rel_path = path + *((size_t *) arg); if(*rel_path) { ++rel_path; } else { rel_path = "."; } return !excluded(g_exclude, g_exclude_count, rel_path, 1); }
void ChunkManager::exclude(Uint32 from,Uint32 to) { if (from > to) std::swap(from,to); Uint32 i = from; while (i <= to && i < (Uint32)d->chunks.size()) { Chunk* c = d->chunks[i]; c->setExclude(true); excluded_chunks.set(i,true); only_seed_chunks.set(i,false); d->todo.set(i,false); bitset.set(i,false); i++; } d->recalc_chunks_left = true; excluded(from,to); updateStats(); }
void reorder(struct nlist *st1, struct nlist *st2, int entries) { struct nlist *p; int i, n; for (p = st1, n = entries; --n >= 0; ++p) if (inlist(p) != -1) ++symfound; for (p = st2 + symfound, n = entries; --n >= 0; ++st1) { if (excluded(st1)) continue; i = inlist(st1); if (i == -1) *p++ = *st1; else st2[i] = *st1; ++symkept; } }
static void InitializeToolTipImages(ChunkBar* bar) { static bool images_initialized = false; if (images_initialized) return; images_initialized = true; Q3MimeSourceFactory* factory = Q3MimeSourceFactory::defaultFactory(); QImage excluded(16, 16, QImage::Format_RGB32); FillAndFrameBlack(&excluded, bar->palette().color(QPalette::Active, QPalette::Mid), 16); factory->setImage("excluded_color", excluded); QImage available(16, 16, QImage::Format_RGB32); FillAndFrameBlack(&available, bar->palette().color(QPalette::Active, QPalette::Highlight), 16); factory->setImage("available_color", available); QImage unavailable(16, 16, QImage::Format_RGB32); FillAndFrameBlack(&unavailable, bar->palette().color(QPalette::Active, QPalette::Base), 16); factory->setImage("unavailable_color", unavailable); }
static void * traverse_file( void *arg, const char *path, const struct stat *st, void *continuation ) { const char *rel_path; struct file_data *data; size_t size; rel_path = path + *((size_t *) arg); if(*rel_path) { ++rel_path; } else { const char *p; p = rel_path = path; while(*p) { if(*p++ == '/') rel_path = p; } } if(excluded(g_exclude, g_exclude_count, rel_path, 0)) return NULL; if(g_apparent_size) { size = st->st_size; } else { size = st->st_blocks * DEV_BSIZE; } if(g_all_files) { print_size(size, path); } data = malloc(sizeof(struct file_data)); data->size = size; return data; }
/* * Handle 'x' and 't' modes. */ static void read_archive(struct bsdtar *bsdtar, char mode) { FILE *out; struct archive *a; struct archive_entry *entry; const struct stat *st; int r; while (*bsdtar->argv) { include(bsdtar, *bsdtar->argv); bsdtar->argv++; } if (bsdtar->names_from_file != NULL) include_from_file(bsdtar, bsdtar->names_from_file); a = archive_read_new(); if (bsdtar->compress_program != NULL) archive_read_support_compression_program(a, bsdtar->compress_program); else archive_read_support_compression_all(a); archive_read_support_format_all(a); if (archive_read_open_file(a, bsdtar->filename, bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : DEFAULT_BYTES_PER_BLOCK)) bsdtar_errc(bsdtar, 1, 0, "Error opening archive: %s", archive_error_string(a)); do_chdir(bsdtar); for (;;) { /* Support --fast-read option */ if (bsdtar->option_fast_read && unmatched_inclusions(bsdtar) == 0) break; r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r < ARCHIVE_OK) bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a)); if (r <= ARCHIVE_WARN) bsdtar->return_value = 1; if (r == ARCHIVE_RETRY) { /* Retryable error: try again */ bsdtar_warnc(bsdtar, 0, "Retrying..."); continue; } if (r == ARCHIVE_FATAL) break; /* * Exclude entries that are too old. */ st = archive_entry_stat(entry); if (bsdtar->newer_ctime_sec > 0) { if (st->st_ctime < bsdtar->newer_ctime_sec) continue; /* Too old, skip it. */ if (st->st_ctime == bsdtar->newer_ctime_sec && ARCHIVE_STAT_CTIME_NANOS(st) <= bsdtar->newer_ctime_nsec) continue; /* Too old, skip it. */ } if (bsdtar->newer_mtime_sec > 0) { if (st->st_mtime < bsdtar->newer_mtime_sec) continue; /* Too old, skip it. */ if (st->st_mtime == bsdtar->newer_mtime_sec && ARCHIVE_STAT_MTIME_NANOS(st) <= bsdtar->newer_mtime_nsec) continue; /* Too old, skip it. */ } /* * Note that pattern exclusions are checked before * pathname rewrites are handled. This gives more * control over exclusions, since rewrites always lose * information. (For example, consider a rewrite * s/foo[0-9]/foo/. If we check exclusions after the * rewrite, there would be no way to exclude foo1/bar * while allowing foo2/bar.) */ if (excluded(bsdtar, archive_entry_pathname(entry))) continue; /* Excluded by a pattern test. */ /* * Modify the pathname as requested by the user. We * do this for -t as well to give users a way to * preview the effects of their rewrites. We also do * this before extraction security checks (including * leading '/' removal). Note that some rewrite * failures prevent extraction. */ if (edit_pathname(bsdtar, entry)) continue; /* Excluded by a rewrite failure. */ if (mode == 't') { /* Perversely, gtar uses -O to mean "send to stderr" * when used with -t. */ out = bsdtar->option_stdout ? stderr : stdout; if (bsdtar->verbose < 2) safe_fprintf(out, "%s", archive_entry_pathname(entry)); else list_item_verbose(bsdtar, out, entry); fflush(out); r = archive_read_data_skip(a); if (r == ARCHIVE_WARN) { fprintf(out, "\n"); bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a)); } if (r == ARCHIVE_RETRY) { fprintf(out, "\n"); bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a)); } if (r == ARCHIVE_FATAL) { fprintf(out, "\n"); bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a)); bsdtar->return_value = 1; break; } fprintf(out, "\n"); } else { if (bsdtar->option_interactive && !yes("extract '%s'", archive_entry_pathname(entry))) continue; /* * Format here is from SUSv2, including the * deferred '\n'. */ if (bsdtar->verbose) { safe_fprintf(stderr, "x %s", archive_entry_pathname(entry)); fflush(stderr); } if (bsdtar->option_stdout) r = archive_read_data_into_fd(a, 1); else r = archive_read_extract(a, entry, bsdtar->extract_flags); if (r != ARCHIVE_OK) { if (!bsdtar->verbose) safe_fprintf(stderr, "%s", archive_entry_pathname(entry)); safe_fprintf(stderr, ": %s", archive_error_string(a)); if (!bsdtar->verbose) fprintf(stderr, "\n"); bsdtar->return_value = 1; } if (bsdtar->verbose) fprintf(stderr, "\n"); if (r == ARCHIVE_FATAL) break; } } if (bsdtar->verbose > 2) fprintf(stdout, "Archive Format: %s, Compression: %s\n", archive_format_name(a), archive_compression_name(a)); archive_read_finish(a); }
static int next_contour(double *data,double cut, int *i,int *j, int dir[2],double *x, double *y, int *charac, int periodic,int *boundary) { double d0,d1,d2,d3,cutp[4]; int k,dirmode,finish=0,dird[2],b[3],bsum,dirt,side,orient; /* Check if contour is runing on the boundary. If that is the case run on the boundary until new contour line or corner encountered. For the exclusion the contours run along -1 rather than 0.*/ if (periodic==0){ if ((dir[0] ==0)&&((*i==lattx-1)||(*i==-1))){ *charac+=1; dirmode=vertical; if (*i==-1) {side=1;} else {side=0;} if (dir[1]==-1){ for(*j-=1;(*j>=0)&&(data[(*ind)(*i+side,*j)]>cut);(*j)--); if (*j<0){ *i+=side; *x=*i; *y=0; if (*i==0) dir[0]=1; else dir[0]=-1; dir[1]=0; return 0; } } else{ for((*j)++;(*j<latty)&&(data[(*ind)(*i+side,*j)]>cut);(*j)++); if (*j>=latty) { *i+=side; *j=latty-1; *x=*i; *y=*j; if (*i==0) dir[0]=1; else dir[0]=-1; dir[1]=0; return 0; } } d0=data[(*ind)(*i+side,*j)]; d1=data[(*ind)(*i+side,*j-dir[1])]; *x=*i+side; *y=*j-dir[1]*(cut-d0)/(d1-d0); *i+=side; if (dir[1]==1) (*j)--; if (*i==0) dir[0]=1; else dir[0]=-1; dir[1]=0; if (excluded(*i,*j,dirmode^1)==1) { set_exclude(*i,*j,dirmode^1,3); return 1; } else set_exclude(*i,*j,dirmode^1,3); /* was 2...*/ return 0; } if ((dir[1]==0)&&((*j==latty-1)||(*j==-1))){ *charac+=1; dirmode=horizontal; if (*j==-1) {side=1;} else {side=0;} if (dir[0]==-1){ for((*i)--;(*i>=0)&&(data[(*ind)(*i,*j+side)]>cut);(*i)--); if (*i<0) { *j+=side; *x=0; *y=*j; if (*j==0) dir[1]=1; else dir[1]=-1; dir[0]=0; return 0; } } else { for((*i)++;(*i<lattx)&&(data[(*ind)(*i,*j+side)]>cut);(*i)++); if (*i>=lattx) { *j+=side; *i=lattx-1; *x=*i; *y=*j; if (*j==0) dir[1]=1; else dir[1]=-1; dir[0]=0; return 0; } } d0=data[(*ind)(*i,*j+side)]; d1=data[(*ind)(*i-dir[0],*j+side)]; *x=*i-dir[0]*(cut-d0)/(d1-d0); *y=*j+side; *j+=side; if (dir[0]==1) (*i)--; if (*j==0) dir[1]=1; else dir[1]=-1; dir[0]=0; if (excluded(*i,*j,dirmode^1)==1) { set_exclude(*i,*j,dirmode^1,3); return 1; } else set_exclude(*i,*j,dirmode^1,3);/* was 2...*/ return 0; } } if (dir[0]==0) dirmode=vertical; else dirmode=horizontal; if (dir[0]<0) dird[0]=-1; else dird[0]=0; if (dir[1]<0) dird[1]=-1; else dird[1]=0; d0=data[(*ind)(*i,*j)]; d1=data[(*ind)(*i+dir[0],*j+dir[1])]; d2=data[(*ind)(*i+dir[0]+abs(dir[1]),*j+dir[1]+abs(dir[0]))]; d3=data[(*ind)(*i+abs(dir[1]),*j+abs(dir[0]))]; if (d0>d3) orient=1; else orient=-1; border(b,*i+dird[0],*j+dird[1],d0,d1,cut,cutp,dirmode^1); border(b+1,*i+dir[0],*j+dir[1],d1,d2,cut,cutp+1,dirmode); border(b+2,*i+abs(dir[1])+dird[0],*j+abs(dir[0])+dird[1], d3,d2,cut,cutp+2,dirmode^1); bsum=(b[0]&4)+(b[1]&4)+(b[2]&4); if ((12==bsum)) { /* cutp[3]=(cut-d3)/(d0-d3); if (cutp[0]+cutp[2]<cutp[1]+cutp[3])*/ if ((((d0+d1+d2+d3)/4-cut)*(d3-d0)>0)) { if (!(b[1]&1)) set_exclude(*i+dir[0],*j+dir[1],dirmode,0); b[1]=0; if (!(b[2]&1)) set_exclude(*i+abs(dir[1])+dird[0], *j+abs(dir[0])+dird[1],dirmode^1,0); b[2]=0; if (b[0]==5) {finish=1; b[0]=4;} set_exclude(*i+dird[0],*j+dird[1],dirmode^1,3); } else { if (!(b[0]&1)) set_exclude(*i+dird[0],*j+dird[1],dirmode^1,0); b[0]=0; if (!(b[1]&1)) set_exclude(*i+dir[0],*j+dir[1],dirmode,0); b[1]=0; if (b[2]==5){ finish=1;b[2]=4;} set_exclude(*i+abs(dir[1])+dird[0], *j+abs(dir[0])+dird[1],dirmode^1,3); } } if (bsum==8) {for (k=0;k<3;k++) {if (b[k]==5) b[k]=0;}} if (bsum==0) printf("Error in contour: could not close contour: bsum=0"); if (b[0]&4) { *charac+=orient; if (b[0]&1) { set_exclude(*i+dird[0],*j+dird[1],dirmode^1,3); finish=1; } *x=*i+dir[0]*cutp[0]; *y=*j+dir[1]*cutp[0]; *i+=dird[0]; *j+=dird[1]; dirt=dir[0]; dir[0]=-abs(dir[1]); dir[1]=-abs(dirt); } else if (b[1]&4) { if (b[1]&1) { set_exclude(*i+dir[0],*j+dir[1],dirmode,3); finish=1; } *x=*i+dir[0]+abs(dir[1])*cutp[1]; *y=*j+dir[1]+abs(dir[0])*cutp[1]; *i+=dir[0]; *j+=dir[1]; } else if (b[2]&4) { *charac-=orient; if (b[2]&1) { set_exclude(*i+abs(dir[1])+dird[0], *j+abs(dir[0])+dird[1],dirmode^1,3); finish=1; } *x=*i+abs(dir[1])+dir[0]*cutp[2]; *y=*j+abs(dir[0])+dir[1]*cutp[2]; *i+=abs(dir[1])+dird[0]; *j+=abs(dir[0])+dird[1]; dirt=dir[0]; dir[0]=abs(dir[1]); dir[1]=abs(dirt); } else { fprintf(stderr,"Error in contour: could not close contour:bsum=%d\n", bsum); return 1; } /* This condition checks */ /* wether the contour runs */ /* into the boundary. */ if(periodic==0){ if (((dir[0]==1)&&(*i==lattx-1))||((dir[0]==-1)&&(*i==0))){ *boundary=1; *charac+=1; dir[0]=0; if (data[(*ind)(*i,*j)]>cut) dir[1]=-1; else dir[1]=1; if (*i==0) *i=-1; } else if (((dir[1]==1)&&(*j==latty-1))||((dir[1]==-1)&&(*j==0))){ *boundary=1; *charac+=1; dir[1]=0; if (data[(*ind)(*i,*j)]>cut) dir[0]=-1; else dir[0]=1; if (*j==0) *j=-1; } } return finish; }
int main(int argc, char **argv) { char spin[] = "-\\|/", SequenceCount = 'a'; char Message[65], Data[100], upload_exclude[200], Command[200], Telemetry[100], *Bracket, *Start; int Bytes, Sentence_Count, sc = 0; double Latitude, Longitude; unsigned int Altitude; uint8_t opmode, flags1, flags2, old_opmode = 0, old_flags1 = 0, old_flags2 = 0; const char *inifile = "gateway.ini"; // FIXME float node_lat, node_lon; time_t next_beacon; bool bmp085, xap; /* load configuration */ ini_gets("node", "id", "", node_id, sizeof(node_id), inifile); node_lat = ini_getf("node", "lat", 999, inifile); node_lon = ini_getf("node", "lon", 999, inifile); bmp085 = ini_getbool("sensors", "bmp085", false, inifile); xap = ini_getbool("xap", "enabled", false, inifile); ini_gets("upload", "exclude", "", upload_exclude, sizeof(upload_exclude), inifile); if (strlen(node_id) == 0) { puts("Node ID has not been specified"); exit(1); } printf("Upload exclude list is \"%s\"\n", upload_exclude); if (xap) { xapInit(); } if (node_lat < 900 && node_lon < 900) { /* put the gateway on the map */ sprintf(Message,"0aL%f,%f:%s[%s]", node_lat, node_lon, GIT_VER, node_id); } else { sprintf(Message,"0a:%s[%s]", GIT_VER, node_id); } UploadPacket(Message,0); if (xap) { xapSendPacket(Message, 0); } if (bmp085) { next_beacon = time(NULL) + 10; printf("Initialising BMP085\n"); bmp085_Calibration(); } printf("Initialising RFM69\n"); setupRFM69(); printf("Starting main loop ...\n"); Sentence_Count = 0; while (1) { if (rfm69_available()) { Bytes = rfmM69_recv(Message, sizeof(Message)); printf ("%s Data available - %d bytes\n", Now(), Bytes); printf ("rx: %s|%d\n", Message,RFM69_lastRssi()); if (Bytes > 0) { if (!excluded(Message, upload_exclude)) { // UKHASNet upload UploadPacket(Message, RFM69_lastRssi()); } if (xap) { // xAP broadcast xapSendPacket(Message, RFM69_lastRssi()); } #if 0 // Habitat upload // 3dL51.95023,-2.54445,155[DA1] if (strstr(Message, "DA1")) { if (Start = strchr(Message, 'L')) { // DA1,2,19:35:37,51.95023,-2.54445,160*05%0A if (sscanf(Start+1, "%lf,%lf,%u[", &Latitude, &Longitude, &Altitude)) { printf("Altitude = %u\n", Altitude); sprintf(Telemetry, "%s,%d,%s,%lf,%lf,%u", "DA1", ++Sentence_Count, Now(), Latitude, Longitude, Altitude); sprintf(Command, "wget -O habitat.txt \"http://habitat.habhub.org/transition/payload_telemetry\" --post-data \"callsign=DA0&string=\\$\\$%s*%s%s&string_type=ascii&metadata={}\"", Telemetry, Checksum(Telemetry), "\%0A"); printf("%s\n", Command); system(Command); } } } #endif } } else {
void leaky::analyze(int thread) { int *countArray = new int[usefulSymbols]; int *flagArray = new int[usefulSymbols]; //Zero our function call counter memset(countArray, 0, sizeof(countArray[0])*usefulSymbols); // reset hit counts for(int i=0; i<usefulSymbols; i++) { externalSymbols[i]->timerHit = 0; externalSymbols[i]->regClear(); } // The flag array is used to prevent counting symbols multiple times // if functions are called recursively. In order to keep from having // to zero it on each pass through the loop, we mark it with the value // of stacks on each trip through the loop. This means we can determine // if we have seen this symbol for this stack trace w/o having to reset // from the prior stacktrace. memset(flagArray, -1, sizeof(flagArray[0])*usefulSymbols); if (cleo) fprintf(outputfd,"m-Start\n"); // This loop walks through all the call stacks we recorded // --last, --start and --end can restrict it, as can excludes/includes stacks = 0; for(malloc_log_entry* lep=firstLogEntry; lep < lastLogEntry; lep = reinterpret_cast<malloc_log_entry*>(&lep->pcs[lep->numpcs])) { if ((thread != 0 && lep->thread != thread) || excluded(lep) || !included(lep)) { continue; } ++stacks; // How many stack frames did we collect u_int n = (lep->numpcs < stackDepth) ? lep->numpcs : stackDepth; char** pcp = &lep->pcs[n-1]; int idx=-1, parrentIdx=-1; // Init idx incase n==0 if (cleo) { // This loop walks through every symbol in the call stack. By walking it // backwards we know who called the function when we get there. char type = 's'; for (int i=n-1; i>=0; --i, --pcp) { idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if(idx>=0) { // Skip over bogus __restore_rt frames that realtime profiling // can introduce. if (i > 0 && !strcmp(externalSymbols[idx]->name, "__restore_rt")) { --pcp; --i; idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if (idx < 0) { continue; } } Symbol **sp=&externalSymbols[idx]; char *symname = htmlify((*sp)->name); fprintf(outputfd,"%c-%s\n",type,symname); delete [] symname; } // else can't find symbol - ignore type = 'c'; } } else { // This loop walks through every symbol in the call stack. By walking it // backwards we know who called the function when we get there. for (int i=n-1; i>=0; --i, --pcp) { idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if(idx>=0) { // Skip over bogus __restore_rt frames that realtime profiling // can introduce. if (i > 0 && !strcmp(externalSymbols[idx]->name, "__restore_rt")) { --pcp; --i; idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if (idx < 0) { continue; } } // If we have not seen this symbol before count it and mark it as seen if(flagArray[idx]!=stacks && ((flagArray[idx]=stacks) || true)) { ++countArray[idx]; } // We know who we are and we know who our parrent is. Count this if(parrentIdx>=0) { externalSymbols[parrentIdx]->regChild(idx); externalSymbols[idx]->regParrent(parrentIdx); } // inside if() so an unknown in the middle of a stack won't break // the link! parrentIdx=idx; } } // idx should be the function that we were in when we received the signal. if(idx>=0) { ++externalSymbols[idx]->timerHit; } } } if (!cleo) generateReportHTML(outputfd, countArray, stacks, thread); }
void contour(double *data,int nox, int noy, double cut, double **cont,int **length,int periodic, long (*newind)(int, int),int *boundary) { int i,j,L,dir[2],index=0,index_old,charact; if (newind==NULL) ind = &stdind; else ind = newind; lattx=nox; latty=noy; excl=(short*) malloc(lattx*latty*sizeof(short)); if (excl==NULL) { fprintf(stderr,"Error in malloc in contour() for excl\n"); exit(1);} memset(excl,0,lattx*latty*sizeof(short)); /* for (i=0;i<lattx*latty;i++) excl[i]=0;*/ *length= (int*) malloc(11*2*sizeof(int)); /* ??? */ if (*length==NULL) { fprintf(stderr,"Error in malloc in contour() for *length\n"); exit(1);} (*length)[0]=0; indexmax=contl; *cont=(double*) malloc((indexmax*2+10)*sizeof(double)); if (*cont==NULL) { fprintf(stderr,"Error in malloc in contour() for *cont\n"); exit(1);} /* purely vertical Contours */ dir[0]=1; dir[1]=0; for (i=0;i<noy-1;i++) { if (!excluded(0,i,horizontal)&& (((data[(*ind)(0,i)]>=cut)&&(data[(*ind)(0,i+1)]<cut)) ||((data[(*ind)(0,i)]<cut)&&(data[(*ind)(0,i+1)]>=cut)))) { index_old=index; startcontour(data,0,i,cut,cont,&index,dir,&charact,periodic, boundary); L=++(*length)[0]; if (L%10==0) *length=realloc(*length,(L+11)*2*sizeof(int)); if (*length==NULL) { fprintf(stderr,"Error in realloc in contour() for *length\n"); exit(1);} (*length)[L*2]=index-index_old; (*length)[L*2+1]=charact; } else set_exclude(0,i,horizontal,2); } /* Now we look for contours in the bulk (Only need horizontal, since there are no purely vertical contours left... ) */ dir[0]=0; dir[1]=1; for (i=0;i<lattx-1;i++) for (j=0;j<latty-1;j++) { if (!excluded(i,j,vertical)&& (((data[(*ind)(i,j)]>=cut)&&(data[(*ind)(i+1,j)]<cut)) ||((data[(*ind)(i,j)]<cut)&&(data[(*ind)(i+1,j)]>=cut)))) { index_old=index; startcontour(data,i,j,cut,cont,&index,dir,&charact,periodic, boundary); L=++(*length)[0]; if (L%10==0) *length=realloc(*length,(L+11)*2*sizeof(int)); if (*length==NULL) { fprintf(stderr, "Error in realloc in contour() for *length\n"); exit(1);} (*length)[L*2]=index-index_old; (*length)[L*2+1]=charact; } else set_exclude(i,j,vertical,2); } free(excl); }
void ChunkManager::downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority) { if (newpriority == EXCLUDED) { downloadStatusChanged(tf, false); return; } if (oldpriority == EXCLUDED) { downloadStatusChanged(tf, true); return; } savePriorityInfo(); Uint32 first = tf->getFirstChunk(); Uint32 last = tf->getLastChunk(); // first and last chunk may be part of multiple files // so we can't just exclude them QValueList<Uint32> files; // get list of files where first chunk lies in tor.calcChunkPos(first,files); Chunk* c = chunks[first]; // if one file in the list needs to be downloaded,increment first for (QValueList<Uint32>::iterator i = files.begin();i != files.end();i++) { Priority np = tor.getFile(*i).getPriority(); if (np > newpriority && *i != tf->getIndex()) { // make sure we don't go past last if (first == last) return; first++; break; } } files.clear(); // get list of files where last chunk lies in tor.calcChunkPos(last,files); c = chunks[last]; // if one file in the list needs to be downloaded,decrement last for (QValueList<Uint32>::iterator i = files.begin();i != files.end();i++) { Priority np = tor.getFile(*i).getPriority(); if (np > newpriority && *i != tf->getIndex()) { // make sure we don't wrap around if (last == 0 || last == first) return; last--; break; } } // last smaller then first is not normal, so just return if (last < first) { return; } prioritise(first,last,newpriority); if (newpriority == ONLY_SEED_PRIORITY) excluded(first,last); }
/* * Add the file or dir hierarchy named by 'path' to the archive */ static void write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) { struct archive_entry *entry = NULL, *spare_entry = NULL; struct tree *tree; char symlink_mode = bsdtar->symlink_mode; dev_t first_dev = 0; int dev_recorded = 0; int tree_ret; dev_t last_dev = 0; char * fstype; tree = tree_open(path); if (!tree) { bsdtar_warnc(bsdtar, errno, "%s: Cannot open", path); bsdtar->return_value = 1; return; } while ((tree_ret = tree_next(tree))) { int r; const char *name = tree_current_path(tree); const struct stat *st = NULL; /* info to use for this entry */ const struct stat *lst = NULL; /* lstat() information */ int descend; if (truncate_archive(bsdtar)) break; if (checkpoint_archive(bsdtar, 0)) exit(1); disk_pause(bsdtar); if (network_select(0)) exit(1); if (tree_ret == TREE_ERROR_FATAL) bsdtar_errc(bsdtar, 1, tree_errno(tree), "%s: Unable to continue traversing directory tree", name); if (tree_ret == TREE_ERROR_DIR) { bsdtar_warnc(bsdtar, errno, "%s: Couldn't visit directory", name); bsdtar->return_value = 1; } if (tree_ret != TREE_REGULAR) continue; /* * If this file/dir is excluded by a filename * pattern, skip it. */ if (excluded(bsdtar, name)) continue; /* * Get lstat() info from the tree library. */ lst = tree_current_lstat(tree); if (lst == NULL) { /* Couldn't lstat(); must not exist. */ bsdtar_warnc(bsdtar, errno, "%s: Cannot stat", name); /* Return error if files disappear during traverse. */ bsdtar->return_value = 1; continue; } /* * Distinguish 'L'/'P'/'H' symlink following. */ switch(symlink_mode) { case 'H': /* 'H': After the first item, rest like 'P'. */ symlink_mode = 'P'; /* 'H': First item (from command line) like 'L'. */ /* FALLTHROUGH */ case 'L': /* 'L': Do descend through a symlink to dir. */ descend = tree_current_is_dir(tree); /* 'L': Follow symlinks to files. */ archive_read_disk_set_symlink_logical(bsdtar->diskreader); /* 'L': Archive symlinks as targets, if we can. */ st = tree_current_stat(tree); if (st != NULL) break; /* If stat fails, we have a broken symlink; * in that case, don't follow the link. */ /* FALLTHROUGH */ default: /* 'P': Don't descend through a symlink to dir. */ descend = tree_current_is_physical_dir(tree); /* 'P': Don't follow symlinks to files. */ archive_read_disk_set_symlink_physical(bsdtar->diskreader); /* 'P': Archive symlinks as symlinks. */ st = lst; break; } if (bsdtar->option_no_subdirs) descend = 0; /* * If user has asked us not to cross mount points, * then don't descend into a dir on a different * device. */ if (!dev_recorded) { last_dev = first_dev = lst->st_dev; dev_recorded = 1; } if (bsdtar->option_dont_traverse_mounts) { if (lst->st_dev != first_dev) descend = 0; } /* * If the user did not specify --insane-filesystems, do not * cross into a new filesystem which is known to be synthetic. * Note that we will archive synthetic filesystems if we are * explicitly told to do so. */ if ((bsdtar->option_insane_filesystems == 0) && (descend != 0) && (lst->st_dev != last_dev)) { fstype = getfstype(tree_current_access_path(tree)); if (fstype == NULL) bsdtar_errc(bsdtar, 1, errno, "%s: Error getting filesystem type", name); if (getfstype_issynthetic(fstype)) { if (!bsdtar->option_quiet) bsdtar_warnc(bsdtar, 0, "Not descending into filesystem of type %s: %s", fstype, name); descend = 0; } else { /* This device is ok to archive. */ last_dev = lst->st_dev; } free(fstype); } /* * In -u mode, check that the file is newer than what's * already in the archive; in all modes, obey --newerXXX flags. */ if (!new_enough(bsdtar, name, st)) { if (!descend) continue; if (bsdtar->option_interactive && !yes("add '%s'", name)) continue; tree_descend(tree); continue; } archive_entry_free(entry); entry = archive_entry_new(); archive_entry_set_pathname(entry, name); archive_entry_copy_sourcepath(entry, tree_current_access_path(tree)); /* Populate the archive_entry with metadata from the disk. */ /* XXX TODO: Arrange to open a regular file before * calling this so we can pass in an fd and shorten * the race to query metadata. The linkify dance * makes this more complex than it might sound. */ r = archive_read_disk_entry_from_file(bsdtar->diskreader, entry, -1, st); if (r != ARCHIVE_OK) bsdtar_warnc(bsdtar, archive_errno(bsdtar->diskreader), "%s", archive_error_string(bsdtar->diskreader)); if (r < ARCHIVE_WARN) continue; /* XXX TODO: Just use flag data from entry; avoid the * duplicate check here. */ /* * If this file/dir is flagged "nodump" and we're * honoring such flags, skip this file/dir. */ #if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP) /* BSD systems store flags in struct stat */ if (bsdtar->option_honor_nodump && (lst->st_flags & UF_NODUMP)) continue; #endif #if defined(EXT2_NODUMP_FL) /* Linux uses ioctl to read flags. */ if (bsdtar->option_honor_nodump) { unsigned long fflags, dummy; archive_entry_fflags(entry, &fflags, &dummy); if (fflags & EXT2_NODUMP_FL) continue; } #endif /* * Don't back up the cache directory or any files inside it. */ if ((lst->st_ino == bsdtar->cachedir_ino) && (lst->st_dev == bsdtar->cachedir_dev)) { if (!bsdtar->option_quiet) bsdtar_warnc(bsdtar, 0, "Not adding cache directory to archive: %s", name); continue; } /* * If the user vetoes this file/directory, skip it. * We want this to be fairly late; if some other * check would veto this file, we shouldn't bother * the user with it. */ if (bsdtar->option_interactive && !yes("add '%s'", name)) continue; /* Note: if user vetoes, we won't descend. */ if (descend) tree_descend(tree); /* * Rewrite the pathname to be archived. If rewrite * fails, skip the entry. */ if (edit_pathname(bsdtar, entry)) continue; /* * If this is a socket, skip the entry: POSIX requires that * pax(1) emit a "diagnostic message" (i.e., warning) that * sockets cannot be archived, but this can make backups of * running systems very noisy. */ if (S_ISSOCK(st->st_mode)) continue; /* Display entry as we process it. * This format is required by SUSv2. */ if (bsdtar->verbose) safe_fprintf(stderr, "a %s", archive_entry_pathname(entry)); /* * If the user hasn't specifically asked to have the access * time stored, zero it. At the moment this usually only * matters for files which have flags set, since the "posix * restricted" format doesn't store access times for most * other files. */ if (bsdtar->option_store_atime == 0) archive_entry_set_atime(entry, 0, 0); /* Non-regular files get archived with zero size. */ if (!S_ISREG(st->st_mode)) archive_entry_set_size(entry, 0); /* Record what we're doing, for SIGINFO / SIGUSR1. */ siginfo_setinfo(bsdtar, "adding", archive_entry_pathname(entry), archive_entry_size(entry)); archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry); /* Handle SIGINFO / SIGUSR1 request if one was made. */ siginfo_printinfo(bsdtar, 0); while (entry != NULL) { write_entry_backend(bsdtar, a, entry, st, tree_current_realpath(tree)); archive_entry_free(entry); entry = spare_entry; spare_entry = NULL; } if (bsdtar->verbose) fprintf(stderr, "\n"); } archive_entry_free(entry); if (tree_close(tree)) bsdtar_errc(bsdtar, 1, 0, "Error traversing directory tree"); }
void leaky::analyze() { int *countArray = new int[usefulSymbols]; int *flagArray = new int[usefulSymbols]; //Zero our function call counter memset(countArray, 0, sizeof(countArray[0])*usefulSymbols); // The flag array is used to prevent counting symbols multiple times // if functions are called recursively. In order to keep from having // to zero it on each pass through the loop, we mark it with the value // of stacks on each trip through the loop. This means we can determine // if we have seen this symbol for this stack trace w/o having to reset // from the prior stacktrace. memset(flagArray, -1, sizeof(flagArray[0])*usefulSymbols); // This loop walks through all the call stacks we recorded stacks = 0; for(malloc_log_entry* lep=firstLogEntry; lep < lastLogEntry; lep = reinterpret_cast<malloc_log_entry*>(&lep->pcs[lep->numpcs])) { if (excluded(lep) || !included(lep)) continue; ++stacks; // How many stack frames did we collect // This loop walks through every symbol in the call stack. By walking it // backwards we know who called the function when we get there. u_int n = (lep->numpcs < stackDepth) ? lep->numpcs : stackDepth; char** pcp = &lep->pcs[n-1]; int idx=-1, parrentIdx=-1; // Init idx incase n==0 for(int i=n-1; i>=0; --i, --pcp, parrentIdx=idx) { idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if(idx>=0) { // Skip over bogus __restore_rt frames that realtime profiling // can introduce. if (i > 0 && !strcmp(externalSymbols[idx].name, "__restore_rt")) { --pcp; --i; idx = findSymbolIndex(reinterpret_cast<u_long>(*pcp)); if (idx < 0) { continue; } } // If we have not seen this symbol before count it and mark it as seen if(flagArray[idx]!=stacks && ((flagArray[idx]=stacks) || true)) { ++countArray[idx]; } // We know who we are and we know who our parrent is. Count this if(parrentIdx>=0) { externalSymbols[parrentIdx].regChild(idx); externalSymbols[idx].regParrent(parrentIdx); } } } // idx should be the function that we were in when we recieved the signal. if(idx>=0) { ++externalSymbols[idx].timerHit; } } generateReportHTML(stdout, countArray, stacks); }
/* * Add the file or dir hierarchy named by 'path' to the archive */ static void write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) { struct archive_entry *entry = NULL, *spare_entry = NULL; struct tree *tree; char symlink_mode = bsdtar->symlink_mode; dev_t first_dev = 0; int dev_recorded = 0; int tree_ret; tree = tree_open(path); if (!tree) { bsdtar_warnc(bsdtar, errno, "%s: Cannot open", path); bsdtar->return_value = 1; return; } while ((tree_ret = tree_next(tree))) { int r; const char *name = tree_current_path(tree); const struct stat *st = NULL; /* info to use for this entry */ const struct stat *lst = NULL; /* lstat() information */ int descend; if (tree_ret == TREE_ERROR_FATAL) bsdtar_errc(bsdtar, 1, tree_errno(tree), "%s: Unable to continue traversing directory tree", name); if (tree_ret == TREE_ERROR_DIR) { bsdtar_warnc(bsdtar, errno, "%s: Couldn't visit directory", name); bsdtar->return_value = 1; } if (tree_ret != TREE_REGULAR) continue; /* * If this file/dir is excluded by a filename * pattern, skip it. */ if (excluded(bsdtar, name)) continue; /* * Get lstat() info from the tree library. */ lst = tree_current_lstat(tree); if (lst == NULL) { /* Couldn't lstat(); must not exist. */ bsdtar_warnc(bsdtar, errno, "%s: Cannot stat", name); /* Return error if files disappear during traverse. */ bsdtar->return_value = 1; continue; } /* * Distinguish 'L'/'P'/'H' symlink following. */ switch(symlink_mode) { case 'H': /* 'H': After the first item, rest like 'P'. */ symlink_mode = 'P'; /* 'H': First item (from command line) like 'L'. */ /* FALLTHROUGH */ case 'L': /* 'L': Do descend through a symlink to dir. */ descend = tree_current_is_dir(tree); /* 'L': Follow symlinks to files. */ archive_read_disk_set_symlink_logical(bsdtar->diskreader); /* 'L': Archive symlinks as targets, if we can. */ st = tree_current_stat(tree); if (st != NULL) break; /* If stat fails, we have a broken symlink; * in that case, don't follow the link. */ /* FALLTHROUGH */ default: /* 'P': Don't descend through a symlink to dir. */ descend = tree_current_is_physical_dir(tree); /* 'P': Don't follow symlinks to files. */ archive_read_disk_set_symlink_physical(bsdtar->diskreader); /* 'P': Archive symlinks as symlinks. */ st = lst; break; } /* * If user has asked us not to cross mount points, * then don't descend into into a dir on a different * device. */ if (!dev_recorded) { first_dev = lst->st_dev; dev_recorded = 1; } if (bsdtar->option_dont_traverse_mounts) { if (lst->st_dev != first_dev) descend = 0; } /* * In -u mode, check that the file is newer than what's * already in the archive; in all modes, obey --newerXXX flags. */ if (!new_enough(bsdtar, name, st)) continue; archive_entry_free(entry); entry = archive_entry_new(); archive_entry_set_pathname(entry, name); archive_entry_copy_sourcepath(entry, tree_current_access_path(tree)); /* Populate the archive_entry with metadata from the disk. */ /* XXX TODO: Arrange to open a regular file before * calling this so we can pass in an fd and shorten * the race to query metadata. The linkify dance * makes this more complex than it might sound. */ r = archive_read_disk_entry_from_file(bsdtar->diskreader, entry, -1, st); if (r != ARCHIVE_OK) bsdtar_warnc(bsdtar, archive_errno(bsdtar->diskreader), archive_error_string(bsdtar->diskreader)); if (r < ARCHIVE_WARN) continue; /* XXX TODO: Just use flag data from entry; avoid the * duplicate check here. */ /* * If this file/dir is flagged "nodump" and we're * honoring such flags, skip this file/dir. */ #ifdef HAVE_STRUCT_STAT_ST_FLAGS /* BSD systems store flags in struct stat */ if (bsdtar->option_honor_nodump && (lst->st_flags & UF_NODUMP)) continue; #endif #if defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL) /* Linux uses ioctl to read flags. */ if (bsdtar->option_honor_nodump) { int fd = open(name, O_RDONLY | O_NONBLOCK); if (fd >= 0) { unsigned long fflags; int r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags); close(fd); if (r >= 0 && (fflags & EXT2_NODUMP_FL)) continue; } } #endif /* * If the user vetoes this file/directory, skip it. * We want this to be fairly late; if some other * check would veto this file, we shouldn't bother * the user with it. */ if (bsdtar->option_interactive && !yes("add '%s'", name)) continue; /* Note: if user vetoes, we won't descend. */ if (descend && !bsdtar->option_no_subdirs) tree_descend(tree); /* * Rewrite the pathname to be archived. If rewrite * fails, skip the entry. */ if (edit_pathname(bsdtar, entry)) continue; /* Display entry as we process it. * This format is required by SUSv2. */ if (bsdtar->verbose) safe_fprintf(stderr, "a %s", archive_entry_pathname(entry)); /* Non-regular files get archived with zero size. */ if (!S_ISREG(st->st_mode)) archive_entry_set_size(entry, 0); /* Record what we're doing, for SIGINFO / SIGUSR1. */ siginfo_setinfo(bsdtar, "adding", archive_entry_pathname(entry), archive_entry_size(entry)); archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry); /* Handle SIGINFO / SIGUSR1 request if one was made. */ siginfo_printinfo(bsdtar, 0); while (entry != NULL) { write_entry_backend(bsdtar, a, entry); archive_entry_free(entry); entry = spare_entry; spare_entry = NULL; } if (bsdtar->verbose) fprintf(stderr, "\n"); } archive_entry_free(entry); tree_close(tree); }
/* * Read a directory tree. We currently ignore anything but * directories, regular files and symlinks. That's because git * doesn't handle them at all yet. Maybe that will change some * day. * * Also, we ignore the name ".git" (even if it is not a directory). * That likely will not change. */ static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify) { DIR *fdir = opendir(path); int contents = 0; if (fdir) { struct dirent *de; char fullname[PATH_MAX + 1]; memcpy(fullname, base, baselen); while ((de = readdir(fdir)) != NULL) { int len, dtype; int exclude; if (is_dot_or_dotdot(de->d_name) || !strcmp(de->d_name, ".git")) continue; len = strlen(de->d_name); /* Ignore overly long pathnames! */ if (len + baselen + 8 > sizeof(fullname)) continue; memcpy(fullname + baselen, de->d_name, len+1); if (simplify_away(fullname, baselen + len, simplify)) continue; dtype = DTYPE(de); exclude = excluded(dir, fullname, &dtype); if (exclude && (dir->flags & DIR_COLLECT_IGNORED) && in_pathspec(fullname, baselen + len, simplify)) dir_add_ignored(dir, fullname, baselen + len); /* * Excluded? If we don't explicitly want to show * ignored files, ignore it */ if (exclude && !(dir->flags & DIR_SHOW_IGNORED)) continue; if (dtype == DT_UNKNOWN) dtype = get_dtype(de, fullname); /* * Do we want to see just the ignored files? * We still need to recurse into directories, * even if we don't ignore them, since the * directory may contain files that we do.. */ if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) { if (dtype != DT_DIR) continue; } switch (dtype) { default: continue; case DT_DIR: memcpy(fullname + baselen + len, "/", 2); len++; switch (treat_directory(dir, fullname, baselen + len, simplify)) { case show_directory: if (exclude != !!(dir->flags & DIR_SHOW_IGNORED)) continue; break; case recurse_into_directory: contents += read_directory_recursive(dir, fullname, fullname, baselen + len, 0, simplify); continue; case ignore_directory: continue; } break; case DT_REG: case DT_LNK: break; } contents++; if (check_only) goto exit_early; else dir_add_name(dir, fullname, baselen + len); } exit_early: closedir(fdir); } return contents; }
void ChunkManager::downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority) { if (newpriority == EXCLUDED) { d->downloadStatusChanged(tf, false); // dumpPriority(tf); return; } if (oldpriority == EXCLUDED) { d->downloadStatusChanged(tf, true); } d->savePriorityInfo(); Uint32 first = tf->getFirstChunk(); Uint32 last = tf->getLastChunk(); if (oldpriority == ONLY_SEED_PRIORITY) include(first,last); if (first == last) { if (d->isBorderChunk(first)) d->setBorderChunkPriority(first,newpriority); else prioritise(first,first,newpriority); if (newpriority == ONLY_SEED_PRIORITY) excluded(first,last); } else { // if the first one is a border chunk use setBorderChunkPriority and make the range smaller if (d->isBorderChunk(first)) { d->setBorderChunkPriority(first,newpriority); first++; } // if the last one is a border chunk use setBorderChunkPriority and make the range smaller if (d->isBorderChunk(last)) { d->setBorderChunkPriority(last,newpriority); last--; } // if we still have a valid range, prioritise it if (first <= last) { prioritise(first,last,newpriority); if (newpriority == ONLY_SEED_PRIORITY) excluded(first,last); } } // if it is a multimedia file, make sure we haven't overridden preview priority if (tf->isMultimedia()) { d->doPreviewPriority(*tf); } //dumpPriority(tf); }
KWBoolean check_sys(NEWS_SYS *entry, char *groups, char *distrib, char *path) { printmsg(5, "check_sys: node: %s", entry->sysname); printmsg(5, "check_sys: groups: %s", groups); printmsg(5, "check_sys: distrib: %s", distrib); printmsg(5, "check_sys: path: %s", path); /*--------------------------------------------------------------------*/ /* Through out this processing, we keep the copies of the */ /* strings used for this system clean by copying them before */ /* passing them to the routines which want to tokenize them. */ /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ /* Never send a post from where it came */ /*--------------------------------------------------------------------*/ if (excluded(strcpy( cache, entry->sysname ), path)) return KWFalse; /*--------------------------------------------------------------------*/ /* Never send to a post to a system which explicitly listed */ /* in the system exclusion list (normally because it's an */ /* alias of the system name we know the system by. */ /*--------------------------------------------------------------------*/ if (entry->exclude ) { printmsg(3, "check_sys: checking exclusions"); if (excluded(strcpy( cache, entry->exclude ), path)) return KWFalse; } /*--------------------------------------------------------------------*/ /* Determine if the message has gone too hops to be forwarded */ /*--------------------------------------------------------------------*/ if ( (entry->maximumHops < USHRT_MAX) && (hops( path ) > entry->maximumHops )) { printmsg(3, "check_sys: Too many hops to be accepted" ); return KWFalse; } /*--------------------------------------------------------------------*/ /* Determine if we accept the distribution for this system */ /*--------------------------------------------------------------------*/ if (entry->distribution) { printmsg(3, "check_sys: checking distributions"); if (!distributions(strcpy( cache, entry->distribution ), distrib)) return KWFalse; } /*--------------------------------------------------------------------*/ /* Determine if the remote system wants this group */ /*--------------------------------------------------------------------*/ if (entry->groups) { printmsg(3, "check_sys: checking groups"); if (!newsgroups(strcpy( cache, entry->groups ), groups)) return KWFalse; } /*--------------------------------------------------------------------*/ /* The article passed our filters, report acceptance to caller */ /*--------------------------------------------------------------------*/ return KWTrue; } /* check_sys */
int cmd_add(int argc, const char **argv, const char *prefix) { int exit_status = 0; int newfd; const char **pathspec; struct dir_struct dir; int flags; int add_new_files; int require_pathspec; char *seen = NULL; git_config(add_config, NULL); argc = parse_options(argc, argv, prefix, builtin_add_options, builtin_add_usage, PARSE_OPT_KEEP_ARGV0); if (patch_interactive) add_interactive = 1; if (add_interactive) exit(interactive_add(argc - 1, argv + 1, prefix)); if (edit_interactive) return(edit_patch(argc, argv, prefix)); argc--; argv++; if (addremove && take_worktree_changes) die("-A and -u are mutually incompatible"); if (!show_only && ignore_missing) die("Option --ignore-missing can only be used together with --dry-run"); if ((addremove || take_worktree_changes) && !argc) { static const char *here[2] = { ".", NULL }; argc = 1; argv = here; } add_new_files = !take_worktree_changes && !refresh_only; require_pathspec = !take_worktree_changes; newfd = hold_locked_index(&lock_file, 1); flags = ((verbose ? ADD_CACHE_VERBOSE : 0) | (show_only ? ADD_CACHE_PRETEND : 0) | (intent_to_add ? ADD_CACHE_INTENT : 0) | (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) | (!(addremove || take_worktree_changes) ? ADD_CACHE_IGNORE_REMOVAL : 0)); if (require_pathspec && argc == 0) { fprintf(stderr, "Nothing specified, nothing added.\n"); fprintf(stderr, "Maybe you wanted to say 'git add .'?\n"); return 0; } pathspec = validate_pathspec(argc, argv, prefix); if (read_cache() < 0) die("index file corrupt"); treat_gitlinks(pathspec); if (add_new_files) { int baselen; /* Set up the default git porcelain excludes */ memset(&dir, 0, sizeof(dir)); if (!ignored_too) { dir.flags |= DIR_COLLECT_IGNORED; setup_standard_excludes(&dir); } /* This picks up the paths that are not tracked */ baselen = fill_directory(&dir, pathspec); if (pathspec) seen = prune_directory(&dir, pathspec, baselen); } if (refresh_only) { refresh(verbose, pathspec); goto finish; } if (pathspec) { int i; if (!seen) seen = find_used_pathspec(pathspec); for (i = 0; pathspec[i]; i++) { if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i])) { if (ignore_missing) { if (excluded(&dir, pathspec[i], DT_UNKNOWN)) dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i])); } else die("pathspec '%s' did not match any files", pathspec[i]); } } free(seen); } exit_status |= add_files_to_cache(prefix, pathspec, flags); if (add_new_files) exit_status |= add_files(&dir, flags); finish: if (active_cache_changed) { if (write_cache(newfd, active_cache, active_nr) || commit_locked_index(&lock_file)) die("Unable to write new index file"); } return exit_status; }
static void mode_in(struct cpio *cpio) { struct archive *a; struct archive_entry *entry; struct archive *ext; const char *destpath; unsigned long blocks; int r; ext = archive_write_disk_new(); if (ext == NULL) cpio_errc(1, 0, "Couldn't allocate restore object"); r = archive_write_disk_set_options(ext, cpio->extract_flags); if (r != ARCHIVE_OK) cpio_errc(1, 0, archive_error_string(ext)); a = archive_read_new(); if (a == NULL) cpio_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_compression_all(a); archive_read_support_format_all(a); if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) cpio_errc(1, archive_errno(a), archive_error_string(a)); for (;;) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { cpio_errc(1, archive_errno(a), archive_error_string(a)); } if (excluded(cpio, archive_entry_pathname(entry))) continue; if (cpio->option_rename) { destpath = cpio_rename(archive_entry_pathname(entry)); archive_entry_set_pathname(entry, destpath); } else destpath = archive_entry_pathname(entry); if (destpath == NULL) continue; if (cpio->verbose) fprintf(stdout, "%s\n", destpath); if (cpio->uid_override >= 0) archive_entry_set_uid(entry, cpio->uid_override); if (cpio->gid_override >= 0) archive_entry_set_gid(entry, cpio->gid_override); r = archive_write_header(ext, entry); if (r != ARCHIVE_OK) { fprintf(stderr, "%s: %s\n", archive_entry_pathname(entry), archive_error_string(ext)); } else if (archive_entry_size(entry) > 0) { r = copy_data(a, ext); } } r = archive_read_close(a); if (r != ARCHIVE_OK) cpio_errc(1, 0, archive_error_string(a)); r = archive_write_close(ext); if (r != ARCHIVE_OK) cpio_errc(1, 0, archive_error_string(ext)); if (!cpio->quiet) { blocks = (archive_position_uncompressed(a) + 511) / 512; fprintf(stderr, "%lu %s\n", blocks, blocks == 1 ? "block" : "blocks"); } archive_read_finish(a); archive_write_finish(ext); exit(0); }
static int append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina, void * cookie) { struct archive_entry *in_entry; int e; while (0 == archive_read_next_header(ina, &in_entry)) { if (truncate_archive(bsdtar)) break; if (checkpoint_archive(bsdtar, 0)) exit(1); if (cookie == NULL) disk_pause(bsdtar); if (network_select(0)) exit(1); if (!new_enough(bsdtar, archive_entry_pathname(in_entry), archive_entry_stat(in_entry))) continue; if (excluded(bsdtar, archive_entry_pathname(in_entry))) continue; if (bsdtar->option_interactive && !yes("copy '%s'", archive_entry_pathname(in_entry))) continue; if (bsdtar->verbose) safe_fprintf(stderr, "a %s", archive_entry_pathname(in_entry)); siginfo_setinfo(bsdtar, "copying", archive_entry_pathname(in_entry), archive_entry_size(in_entry)); siginfo_printinfo(bsdtar, 0); if (MODE_HEADER(bsdtar, a)) goto err_fatal; e = archive_write_header(a, in_entry); if (e != ARCHIVE_OK) { if (!bsdtar->verbose) bsdtar_warnc(bsdtar, 0, "%s: %s", archive_entry_pathname(in_entry), archive_error_string(a)); else fprintf(stderr, ": %s", archive_error_string(a)); } if (e == ARCHIVE_FATAL) exit(1); if (e < ARCHIVE_WARN) goto done; if (MODE_DATA(bsdtar, a)) goto err_fatal; if (archive_entry_size(in_entry) == 0) archive_read_data_skip(ina); else if (cookie == NULL) { if (copy_file_data(bsdtar, a, ina)) exit(1); } else { switch (archive_multitape_copy(ina, cookie, a, bsdtar->write_cookie)) { case -1: goto err_fatal; case -2: goto err_read; } } done: if (MODE_DONE(bsdtar, a)) goto err_fatal; if (bsdtar->verbose) fprintf(stderr, "\n"); continue; err_read: bsdtar->return_value = 1; if (MODE_DONE(bsdtar, a)) goto err_fatal; if (bsdtar->verbose) fprintf(stderr, "\n"); break; err_fatal: bsdtar_warnc(bsdtar, archive_errno(a), "%s", archive_error_string(a)); exit(1); } /* Note: If we got here, we saw no write errors, so return success. */ return (0); }