static int incoming_priv_cb (char *word[], gpointer userdata) { int priv; if (hexchat_get_prefs (ph, "input_balloon_priv", NULL, &priv) == 3 && priv && should_alert ()) { const char *network = hexchat_get_info (ph, "network"); if (!network) network = hexchat_get_info (ph, "server"); if (userdata != NULL) /* Special event */ { if (GPOINTER_TO_INT (userdata) == 3) { if (!is_ignored (word[2])) show_notificationf (word[1], _("File offer from: %s (%s)"), word[2], network); } else if (GPOINTER_TO_INT (userdata) == 2) { if (!is_ignored (word[2])) show_notificationf (word[1], _("Invited to channel by: %s (%s)"), word[2], network); } else { if (!is_ignored (word[1])) show_notificationf (word[2], _("Notice from: %s (%s)"), word[1], network); } } else show_notificationf (word[2], _("Private message from: %s (%s)"), word[1], network); } return HEXCHAT_EAT_NONE; }
static int set_termios(struct tty_struct * tty, struct termios * termios, int channel) { int i; unsigned short old_cflag = tty->termios->c_cflag; /* If we try to set the state of terminal and we're not in the foreground, send a SIGTTOU. If the signal is blocked or ignored, go ahead and perform the operation. POSIX 7.2) */ if ((current->tty == channel) && (tty->pgrp != current->pgrp)) { if (is_orphaned_pgrp(current->pgrp)) return -EIO; if (!is_ignored(SIGTTOU)) { (void) kill_pg(current->pgrp,SIGTTOU,1); return -ERESTARTSYS; } } for (i=0 ; i< (sizeof (*termios)) ; i++) ((char *)tty->termios)[i]=get_fs_byte(i+(char *)termios); if (IS_A_SERIAL(channel) && tty->termios->c_cflag != old_cflag) change_speed(channel-64); /* puting mpty's into echo mode is very bad, and I think under some situations can cause the kernel to do nothing but copy characters back and forth. -RAB */ if (IS_A_PTY_MASTER(channel)) tty->termios->c_lflag &= ~ECHO; return 0; }
void setup_watches (const char *dir) { DIR *dirfd = opendir(dir); char fullent[PATH_MAX]; int dirlen = strlen(dir); memcpy(fullent, dir, dirlen); fullent[dirlen] = '/'; struct dirent *ent; if (!dirfd) { if (errno == ENOENT || errno == EACCES) return; die_errno("opendir"); } while ((ent = xreaddir(dirfd))) { int entlen = strlen(ent->d_name); if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue; memcpy(fullent+dirlen+1, ent->d_name, entlen); fullent[dirlen+1+entlen] = '\0'; if (is_ignored(fullent)) continue; if (!isdir(fullent)) continue; if (!setup_one_watch(fullent)) setup_watches(fullent); } if (closedir(dirfd)) die_errno("closedir"); }
void handle_event(struct inotify_event *ev) { char *wdp; int i, j; if (ev->wd < 0) return; wdp = wdpaths[ev->wd]; if (!wdp) return; if (ev->mask & IN_ISDIR && ev->mask & IN_CREATE) { char buf[PATH_MAX]; strcpy(buf, wdp); strcat(buf, "/"); strcat(buf, ev->name); if (is_ignored(buf)) return; if (!setup_one_watch(buf)) setup_watches(buf); return; } /* inotify shows directory events in the parent too; ignore them there */ if (ev->len && ev->mask & IN_ISDIR) return; if (ev->mask & IN_IGNORED) { wdpaths[ev->wd] = NULL; for (i = 0; i < HIST; i++) { if (!lru[i]) break; if (strcmp(wdp, lru[i])) continue; for (j = i; j < HIST-1; j++) lru[j] = lru[j+1]; lru[HIST-1] = NULL; break; } free(wdp); return; } #ifdef DEBUG if (ev->mask != IN_ACCESS) fprintf(stdout, "%08x %s %s %s\n", ev->mask, event_msg(ev->mask), wdp, ev->len ? ev->name : "(none)"); #endif for (i = 0; i < HIST; i++) { if (!lru[i]) break; if (strcmp(wdp, lru[i])) continue; if (i == 0) return; for (j = i; j > 0; j--) lru[j] = lru[j-1]; lru[0] = wdp; return; } for (j = HIST-1; j > 0; j--) lru[j] = lru[j-1]; lru[0] = wdp; }
void grid_segment::grow(std::function<grid_segment::ptr(grid_cell_base::label)> segments_accessor) { vector<grid_cell::ptr> tovisit; tovisit.push_back(*cells_.begin()); set_visited(tovisit.front()); grid_cell_base::label label = tovisit.front()->get_label(); while(!tovisit.empty()) { grid_cell::ptr c = tovisit.back(); tovisit.pop_back(); c->set_label(label); cells_.insert(c); for(size_t i=0; i<4; i++) { auto nc = grid_.get_neighbour_cell_4(c,i); if(nc) { if(nc->has_label()) { if(nc->get_label() != label && !nc->is_ignored()) { add_edge(std::static_pointer_cast<graph_node>(segments_accessor(label)), std::static_pointer_cast<graph_node>(segments_accessor(nc->get_label()))); } continue; } if(nc->is_target() && !nc->is_ignored() && nc->is_covered() && !is_visited(nc)) { set_visited(nc); tovisit.push_back(nc); } } } } }
static int walk_tree(const char* path, watch_node* parent, array* ignores) { if (is_ignored(path, ignores)) { return ERR_IGNORE; } DIR* dir = opendir(path); if (dir == NULL) { if (errno == EACCES) { return ERR_IGNORE; } else if (errno == ENOTDIR) { // flat root return add_watch(path, parent); } userlog(LOG_ERR, "opendir(%s): %s", path, strerror(errno)); return ERR_CONTINUE; } int id = add_watch(path, parent); if (id < 0) { closedir(dir); return id; } struct dirent* entry; char subdir[PATH_MAX]; strcpy(subdir, path); if (subdir[strlen(subdir) - 1] != '/') { strcat(subdir, "/"); } char* p = subdir + strlen(subdir); while ((entry = readdir(dir)) != NULL) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } strcpy(p, entry->d_name); if (!is_directory(entry, subdir)) { continue; } int subdir_id = walk_tree(subdir, table_get(watches, id), ignores); if (subdir_id < 0 && subdir_id != ERR_IGNORE) { rm_watch(id, true); id = subdir_id; break; } } closedir(dir); return id; }
static int check_change(struct tty_struct * tty, int channel) { /* If we try to set the state of terminal and we're not in the foreground, send a SIGTTOU. If the signal is blocked or ignored, go ahead and perform the operation. POSIX 7.2) */ if (current->tty != channel) return 0; if (tty->pgrp <= 0 || tty->pgrp == current->pgrp) return 0; if (is_orphaned_pgrp(current->pgrp)) return -EIO; if (is_ignored(SIGTTOU)) return 0; (void) kill_pg(current->pgrp,SIGTTOU,1); return -ERESTARTSYS; }
/* * This only works as the 386 is low-byte-first */ static int set_termio(struct tty_struct * tty, struct termio * termio, int channel) { int i; struct termio tmp_termio; unsigned short old_cflag = tty->termios->c_cflag; if ((current->tty == channel) && (tty->pgrp > 0) && (tty->pgrp != current->pgrp)) { if (is_orphaned_pgrp(current->pgrp)) return -EIO; if (!is_ignored(SIGTTOU)) { (void) kill_pg(current->pgrp,SIGTTOU,1); return -ERESTARTSYS; } } for (i=0 ; i< (sizeof (*termio)) ; i++) ((char *)&tmp_termio)[i]=get_fs_byte(i+(char *)termio); /* take care of the packet stuff. */ if ((tmp_termio.c_iflag & IXON) && ~(tty->termios->c_iflag & IXON)) { tty->status_changed = 1; tty->ctrl_status |= TIOCPKT_DOSTOP; } if (~(tmp_termio.c_iflag & IXON) && (tty->termios->c_iflag & IXON)) { tty->status_changed = 1; tty->ctrl_status |= TIOCPKT_NOSTOP; } *(unsigned short *)&tty->termios->c_iflag = tmp_termio.c_iflag; *(unsigned short *)&tty->termios->c_oflag = tmp_termio.c_oflag; *(unsigned short *)&tty->termios->c_cflag = tmp_termio.c_cflag; *(unsigned short *)&tty->termios->c_lflag = tmp_termio.c_lflag; tty->termios->c_line = tmp_termio.c_line; for(i=0 ; i < NCC ; i++) tty->termios->c_cc[i] = tmp_termio.c_cc[i]; if (IS_A_SERIAL(channel) && tty->termios->c_cflag != old_cflag) change_speed(channel-64); return 0; }
static int job_control(struct tty_struct *tty, struct file *file) { if (file->f_op->write != redirected_tty_write && current->signal->tty == tty) { if (!tty->pgrp) printk(KERN_ERR "n_tty_read: no tty->pgrp!\n"); else if (task_pgrp(current) != tty->pgrp) { if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned()) return -EIO; kill_pgrp(task_pgrp(current), SIGTTIN, 1); set_thread_flag(TIF_SIGPENDING); return -ERESTARTSYS; } } return 0; }
int calc_scaled_pixel_value(ImageStats *stats, float val) { if (is_ignored(stats, val)) return 0; else if (stats->truncate) { if (val < 0) return 0; else if (val > 255) return 255; else return (int)(val+.5); } else if (val < stats->map_min) return 0; else if (val > stats->map_max) return 255; else return (int) round(((val-stats->map_min)/(stats->map_max-stats->map_min))*255); }
static int job_control(struct tty_struct *tty, struct file *file) { /* Job control check -- must be done at start and after every sleep (POSIX.1 7.1.1.4). */ /* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ if (file->f_op->write != redirected_tty_write && current->signal->tty == tty) { if (tty->pgrp <= 0) printk("read_chan: tty->pgrp <= 0!\n"); else if (process_group(current) != tty->pgrp) { if (is_ignored(SIGTTIN) || is_orphaned_pgrp(process_group(current))) return -EIO; kill_pg(process_group(current), SIGTTIN, 1); return -ERESTARTSYS; } } return 0; }
static int tty_read(struct inode * inode, struct file * file, char * buf, int count) { int i, dev; struct tty_struct * tty; dev = file->f_rdev; if (MAJOR(dev) != TTY_MAJOR) { printk("tty_read: bad pseudo-major nr #%d\n", MAJOR(dev)); return -EINVAL; } dev = MINOR(dev); tty = TTY_TABLE(dev); if (!tty || (tty->flags & (1 << TTY_IO_ERROR))) return -EIO; /* This check not only needs to be done before reading, but also whenever read_chan() gets woken up after sleeping, so I've moved it to there. This should only be done for the N_TTY line discipline, anyway. Same goes for write_chan(). -- jlc. */ #if 0 if ((inode->i_rdev != CONSOLE_DEV) && /* don't stop on /dev/console */ (tty->pgrp > 0) && (current->tty == dev) && (tty->pgrp != current->pgrp)) if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp)) return -EIO; else { (void) kill_pg(current->pgrp, SIGTTIN, 1); return -ERESTARTSYS; } #endif if (ldiscs[tty->disc].read) /* XXX casts are for what kernel-wide prototypes should be. */ i = (ldiscs[tty->disc].read)(tty,file,(unsigned char *)buf,(unsigned int)count); else i = -EIO; if (i > 0) inode->i_atime = CURRENT_TIME; return i; }
static int job_control(struct tty_struct *tty, struct file *file) { /* Job control check -- must be done at start and after every sleep (POSIX.1 7.1.1.4). */ /* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ if (file->f_dentry->d_inode->i_rdev != CONSOLE_DEV && file->f_dentry->d_inode->i_rdev != SYSCONS_DEV && current->tty == tty) { if (tty->pgrp <= 0) printk("read_chan: tty->pgrp <= 0!\n"); else if (current->pgrp != tty->pgrp) { if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp)) return -EIO; kill_pg(current->pgrp, SIGTTIN, 1); return -ERESTARTSYS; } } return 0; }
static int tty_write(struct inode * inode, struct file * file, char * buf, int count) { int dev, i, is_console; struct tty_struct * tty; dev = file->f_rdev; is_console = (inode->i_rdev == CONSOLE_DEV); if (MAJOR(dev) != TTY_MAJOR) { printk("tty_write: pseudo-major != TTY_MAJOR\n"); return -EINVAL; } dev = MINOR(dev); if (is_console && redirect) tty = redirect; else tty = TTY_TABLE(dev); if (!tty || !tty->write || (tty->flags & (1 << TTY_IO_ERROR))) return -EIO; #if 0 if (!is_console && L_TOSTOP(tty) && (tty->pgrp > 0) && (current->tty == dev) && (tty->pgrp != current->pgrp)) { if (is_orphaned_pgrp(current->pgrp)) return -EIO; if (!is_ignored(SIGTTOU)) { (void) kill_pg(current->pgrp, SIGTTOU, 1); return -ERESTARTSYS; } } #endif if (ldiscs[tty->disc].write) /* XXX casts are for what kernel-wide prototypes should be. */ i = (ldiscs[tty->disc].write)(tty,file,(unsigned char *)buf,(unsigned int)count); else i = -EIO; if (i > 0) inode->i_mtime = CURRENT_TIME; return i; }
// Now the thumbnail generation is combined with the stats calculations, // to speed things up a little. Both require a pass through the entire // image, so it seems natural, and the stats calculation doesn't add much // overhead. (The user is waiting while the thumbnail is being generated, // so we do want this to be as quick as possible.) unsigned char *generate_thumbnail_data(ImageInfo *ii, int tsx, int tsy) { int i,j; unsigned char *bdata = MALLOC(sizeof(unsigned char)*tsx*tsy*3); ImageStats *stats = &(ii->stats); // we will estimate the stats from the thumbnail data clear_stats(ii); // Here we do the rather ugly thing of making the thumbnail // loading code specific to each supported data type. This is // because we've combined the stats calculation into this... if (ii->data_ci->data_type == GREYSCALE_FLOAT) { // store data used to build the small image pixmap // we will calculate the stats on this subset float *fdata = CALLOC(sizeof(float), tsx*tsy); load_thumbnail_data(ii->data_ci, tsx, tsy, fdata); set_ignores(ii, !g_startup); // split out the case where we have no ignore value -- // should be quite a bit faster... if (have_ignore(stats)) { // Compute stats -- ignore "no data" value int n=0; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { float v = fdata[j+i*tsx]; if (!is_ignored(stats, v) && fabs(v)<999999999) { stats->avg += v; // first valid pixel --> initialize max/min // subsequent pixels --> update max/min if needed if (n==0) { stats->act_max = stats->act_min = v; } else { if (v > stats->act_max) stats->act_max = v; if (v < stats->act_min) stats->act_min = v; } ++n; } } } stats->avg /= (double)n; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { float v = fdata[j+i*tsx]; if (!is_ignored(stats, v) && fabs(v)<999999999) { stats->stddev += (v - stats->avg)*(v - stats->avg); } } } stats->stddev = sqrt(stats->stddev / (double)n); } else { // Compute stats, no ignore (actually, do ignore data that is NaN) stats->act_max = stats->act_min = fdata[0]; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { float v = fdata[j+i*tsx]; // added in the fabs<999... thing... sometimes values // are just ridiculous and we must ignore them if (meta_is_valid_double(v) && fabs(v)<999999999) { stats->avg += v; if (v > stats->act_max) stats->act_max = v; if (v < stats->act_min) stats->act_min = v; } } } stats->avg /= (double)(tsx*tsy); for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { float v = fdata[j+i*tsx]; if (meta_is_valid_double(v) && fabs(v)<999999999) stats->stddev += (v - stats->avg) * (v - stats->avg); } } stats->stddev = sqrt(stats->stddev / (double)(tsx*tsy)); } //printf("Avg, StdDev: %f, %f\n", stats->avg, stats->stddev); set_mapping(ii, !g_startup); // Now actually scale the data, and convert to bytes. // Note that we need 3 values, one for each of the RGB channels. if (have_lut()) { // look up table case -- no scaling, just use the lut // to convert from float to rgb byte for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int index = j+i*tsx; int n = 3*index; float val = fdata[index]; int ival; if (is_ignored(stats, val) || val<0) ival = ignore_grey_value; else ival = (int)val; apply_lut(ival, &bdata[n], &bdata[n+1], &bdata[n+2]); // histogram will appear as if we were scaling // to greyscale byte unsigned char uval = (unsigned char) calc_scaled_pixel_value(stats, val); stats->hist[uval] += 1; } } } else { // normal case -- no lut, apply selected scaling to convert from // floating point to byte for display for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int index = j+i*tsx; float val = fdata[index]; int n = 3*index; unsigned char uval = (unsigned char) calc_scaled_pixel_value(stats, val); if (is_ignored(stats, val)) { bdata[n] = bdata[n+1] = bdata[n+2] = ignore_grey_value; } else { bdata[n] = uval; bdata[n+1] = uval; bdata[n+2] = uval; stats->hist[uval] += 1; } } } } // done with our subset free(fdata); } else if (ii->data_ci->data_type == RGB_BYTE) { // store data used to build the small image pixmap // we will calculate the stats on this subset unsigned char *rgbdata = CALLOC(sizeof(unsigned char), tsx*tsy*3); load_thumbnail_data(ii->data_ci, tsx, tsy, (void*)rgbdata); set_ignores(ii, !g_startup); ImageStatsRGB *stats_r = &ii->stats_r; ImageStatsRGB *stats_g = &ii->stats_g; ImageStatsRGB *stats_b = &ii->stats_b; stats_r->act_min = rgbdata[0]; stats_r->act_max = rgbdata[0]; stats_g->act_min = rgbdata[1]; stats_g->act_max = rgbdata[1]; stats_b->act_min = rgbdata[2]; stats_b->act_max = rgbdata[2]; int nr=0, ng=0, nb=0; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, rgbdata[kk])) { stats_r->avg += rgbdata[kk]; ++nr; if (rgbdata[kk] < stats_r->act_min) stats_r->act_min = rgbdata[kk]; if (rgbdata[kk] > stats_r->act_max) stats_r->act_max = rgbdata[kk]; } if (!is_ignored_rgb(stats_g, rgbdata[kk+1])) { stats_g->avg += rgbdata[kk+1]; ++ng; if (rgbdata[kk+1] < stats_g->act_min) stats_g->act_min = rgbdata[kk+1]; if (rgbdata[kk+1] > stats_g->act_max) stats_g->act_max = rgbdata[kk+1]; } if (!is_ignored_rgb(stats_b, rgbdata[kk+2])) { stats_b->avg += rgbdata[kk+2]; ++nb; if (rgbdata[kk+2] < stats_b->act_min) stats_b->act_min = rgbdata[kk+2]; if (rgbdata[kk+2] > stats_b->act_max) stats_b->act_max = rgbdata[kk+2]; } } } if (nr>1) stats_r->avg /= (double)nr; if (ng>1) stats_g->avg /= (double)ng; if (nb>1) stats_b->avg /= (double)nb; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, rgbdata[kk])) { float d = rgbdata[kk] - stats_r->avg; stats_r->stddev += d*d; } if (!is_ignored_rgb(stats_g, rgbdata[kk+1])) { float d = rgbdata[kk+1] - stats_g->avg; stats_g->stddev += d*d; } if (!is_ignored_rgb(stats_b, rgbdata[kk+2])) { float d = rgbdata[kk+2] - stats_b->avg; stats_b->stddev += d*d; } } } stats_r->stddev = sqrt(stats_r->stddev / (double)nr); stats_g->stddev = sqrt(stats_g->stddev / (double)ng); stats_b->stddev = sqrt(stats_b->stddev / (double)nb); set_mapping(ii, !g_startup); // clear out the stats for the greyscale image - we'll just use // the histogram stats->avg = 0; stats->stddev = 0; // these are used for the axis labels on the histogram, so we put // in the averages of the mins... these are sort of bogus anyway, we // really should have 3 histograms stats->map_min = calc_fake_min(ii); stats->map_max = calc_fake_max(ii); for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, rgbdata[kk]) && !is_ignored_rgb(stats_g, rgbdata[kk+1]) && !is_ignored_rgb(stats_b, rgbdata[kk+2])) { bdata[kk] = (unsigned char)calc_rgb_scaled_pixel_value( stats_r, rgbdata[kk]); bdata[kk+1] = (unsigned char)calc_rgb_scaled_pixel_value( stats_g, rgbdata[kk+1]); bdata[kk+2] = (unsigned char)calc_rgb_scaled_pixel_value( stats_b, rgbdata[kk+2]); } else { bdata[kk] = ignore_red_value; bdata[kk+1] = ignore_green_value; bdata[kk+2] = ignore_blue_value; } } } // Update the histogram -- use greyscale average for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, rgbdata[kk]) && !is_ignored_rgb(stats_g, rgbdata[kk+1]) && !is_ignored_rgb(stats_b, rgbdata[kk+2])) { unsigned char uval = (bdata[kk]+bdata[kk+1]+bdata[kk+2])/3; stats->hist[uval] += 1; } } } free(rgbdata); } else if (ii->data_ci->data_type == GREYSCALE_BYTE) { // this case is very similar to the RGB case, above, except we // have to first grab the data into a greyscale buffer, and // then copy it over to the 3-band buffer we're supposed to return unsigned char *gsdata = MALLOC(sizeof(unsigned char)*tsx*tsy); load_thumbnail_data(ii->data_ci, tsx, tsy, (void*)gsdata); set_ignores(ii, !g_startup); stats->act_max = 0; stats->act_min = 255; stats->map_min = 0; stats->map_max = 255; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { unsigned char uval = gsdata[j+i*tsx]; stats->avg += uval; if (uval > stats->act_max) stats->act_max = uval; if (uval < stats->act_min) stats->act_min = uval; } } stats->avg /= (double)(tsx*tsy); for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { unsigned char uval = gsdata[j+i*tsx]; stats->stddev += (uval - stats->avg) * (uval - stats->avg); } } stats->stddev = sqrt(stats->stddev / (double)(tsx*tsy)); set_mapping(ii, !g_startup); for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { unsigned char uval = gsdata[j+i*tsx]; int kk = 3*(j+i*tsx); if (have_lut()) { apply_lut(uval, &bdata[kk], &bdata[kk+1], &bdata[kk+2]); stats->hist[uval] += 1; } else if (!is_ignored(stats, uval)) { // apply selected scaling to display values unsigned char display_value = (unsigned char) calc_scaled_pixel_value(stats, uval); bdata[kk] = bdata[kk+1] = bdata[kk+2] = display_value; stats->hist[display_value] += 1; } else { bdata[kk] = bdata[kk+1] = bdata[kk+2] = ignore_grey_value; } } } free(gsdata); } else if (ii->data_ci->data_type == RGB_FLOAT) { // store data used to build the small image pixmap // we will calculate the stats on this subset float *fdata = MALLOC(sizeof(float)*tsx*tsy*3); load_thumbnail_data(ii->data_ci, tsx, tsy, fdata); set_ignores(ii, !g_startup); ImageStatsRGB *stats_r = &ii->stats_r; ImageStatsRGB *stats_g = &ii->stats_g; ImageStatsRGB *stats_b = &ii->stats_b; stats_r->act_min = fdata[0]; stats_r->act_max = fdata[0]; stats_g->act_min = fdata[1]; stats_g->act_max = fdata[1]; stats_b->act_min = fdata[2]; stats_b->act_max = fdata[2]; int nr=0, ng=0, nb=0; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, fdata[kk])) { stats_r->avg += fdata[kk]; ++nr; if (fdata[kk] < stats_r->act_min) stats_r->act_min = fdata[kk]; if (fdata[kk] > stats_r->act_max) stats_r->act_max = fdata[kk]; } if (!is_ignored_rgb(stats_g, fdata[kk+1])) { stats_g->avg += fdata[kk+1]; ++ng; if (fdata[kk+1] < stats_g->act_min) stats_g->act_min = fdata[kk+1]; if (fdata[kk+1] > stats_g->act_max) stats_g->act_max = fdata[kk+1]; } if (!is_ignored_rgb(stats_b, fdata[kk+2])) { stats_b->avg += fdata[kk+2]; ++nb; if (fdata[kk+2] < stats_b->act_min) stats_b->act_min = fdata[kk+2]; if (fdata[kk+2] > stats_b->act_max) stats_b->act_max = fdata[kk+2]; } } } if (nr>1) stats_r->avg /= (double)nr; if (ng>1) stats_g->avg /= (double)ng; if (nb>1) stats_b->avg /= (double)nb; for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, fdata[kk])) { float d = fdata[kk] - stats_r->avg; stats_r->stddev += d*d; } if (!is_ignored_rgb(stats_g, fdata[kk+1])) { float d = fdata[kk+1] - stats_g->avg; stats_g->stddev += d*d; } if (!is_ignored_rgb(stats_b, fdata[kk+2])) { float d = fdata[kk+2] - stats_b->avg; stats_b->stddev += d*d; } } } stats_r->stddev = sqrt(stats_r->stddev / (double)nr); stats_g->stddev = sqrt(stats_g->stddev / (double)ng); stats_b->stddev = sqrt(stats_b->stddev / (double)nb); set_mapping(ii, !g_startup); // clear out the stats for the greyscale image - we'll just use // the histogram stats->avg = 0; stats->stddev = 0; // these are used for the axis labels on the histogram, so we put // in the averages of the mins... these are sort of bogus anyway, we // really should have 3 histograms stats->map_min = calc_fake_min(ii); stats->map_max = calc_fake_max(ii); for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, fdata[kk]) && !is_ignored_rgb(stats_g, fdata[kk+1]) && !is_ignored_rgb(stats_b, fdata[kk+2])) { bdata[kk] = (unsigned char)calc_rgb_scaled_pixel_value( stats_r, fdata[kk]); bdata[kk+1] = (unsigned char)calc_rgb_scaled_pixel_value( stats_g, fdata[kk+1]); bdata[kk+2] = (unsigned char)calc_rgb_scaled_pixel_value( stats_b, fdata[kk+2]); } else { bdata[kk] = ignore_red_value; bdata[kk+1] = ignore_green_value; bdata[kk+2] = ignore_blue_value; } } } // Update the histogram -- use greyscale average for (i=0; i<tsy; ++i) { for (j=0; j<tsx; ++j) { int kk = 3*(j+i*tsx); if (!is_ignored_rgb(stats_r, fdata[kk]) && !is_ignored_rgb(stats_g, fdata[kk+1]) && !is_ignored_rgb(stats_b, fdata[kk+2])) { unsigned char uval = (bdata[kk]+bdata[kk+1]+bdata[kk+2])/3; stats->hist[uval] += 1; } } } // done with our subset free(fdata); } else { asfPrintError("Unexpected data type: %d!\n", ii->data_ci->data_type); } return bdata; }
void grid_cell::draw() { static const double df_iso =0.05; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLineWidth(1.0); if(active_survey_param::non_ros::cell_drawing_mode == 0) glColor3f(1-0.8*ground_truth_value_, 1-0.8*ground_truth_value_, 1); else if(active_survey_param::non_ros::cell_drawing_mode == 1) { if(!is_covered()) glColor3f(0.45,0.55,0.4); else glColor3f(1-2*df_iso*ceil(estimated_value_/df_iso), 1-2*df_iso*ceil(estimated_value_/df_iso), 1-2*df_iso*ceil(estimated_value_/df_iso)); } else if(active_survey_param::non_ros::cell_drawing_mode == 3) glColor3f(2*variance_, 2*variance_, 2*variance_); else if(active_survey_param::non_ros::cell_drawing_mode == 4) { bool l = (estimated_value_+ active_survey_param::non_ros::beta*variance_ < active_survey_param::non_ros::target_threshold); bool h = (estimated_value_- active_survey_param::non_ros::beta*variance_ > active_survey_param::non_ros::target_threshold); bool u = !(l||h); glColor3f(l?1:0, h?1:0, u?1:0); // if(is_ignored()) // glColor3f(0,0,0); //glColor4f(estimated_value_+ variance_, estimated_value_+ variance_, // estimated_value_+ variance_,1); } // glColor4f(2*variance_, // ((1-variance_)<0?0:(1-variance_))*estimated_value_, // 2*variance_, ignored_?0.3:1.0); else if(active_survey_param::non_ros::cell_drawing_mode == 5) utility::gl_color(utility::get_altitude_color(label_)); else if(active_survey_param::non_ros::cell_drawing_mode == 2) { double dsc = pow(0.999, sensed_time_); utility::gl_color(sensed_&&is_target()?Vector3f(1-dsc,1-dsc,1-dsc):Vector3f(1,1,1)); //double rt = (sensed_time_>active_survey_param::time_limit)?0:sensed_time_/active_survey_param::time_limit; //utility::gl_color(Vector3f(1-rt, 0 ,rt)); } else { if(is_covered()) glColor3f(0,is_target()?1:0,0); else glColor3f(0.5,0.5,0.5); } glBegin(GL_QUADS); utility::draw_quad(get_rect()); glEnd(); if(ground_truth_value_ > active_survey_param::non_ros::target_threshold) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3f(1,0.95,0.7); glBegin(GL_QUADS); utility::draw_quad(get_rect(), 0.1); glEnd(); } static Vector4f offset{0.1,0.1,-0.1,-0.1}; if(false && is_ignored()) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glColor4f(0.0,0.0,1, 0.2); glBegin(GL_QUADS); utility::draw_quad(get_rect()+offset, 0.15); glEnd(); } }
void cc110x_rx_handler(void) { uint8_t res = 0; // Possible packet received, RX -> IDLE (0.1 us) rflags.CAA = 0; rflags.MAN_WOR = 0; cc110x_statistic.packets_in++; res = receive_packet((uint8_t*)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_packet_t)); if (res) { // If we are sending a burst, don't accept packets. // Only ACKs are processed (for stopping the burst). // Same if state machine is in TX lock. if (radio_state == RADIO_SEND_BURST || rflags.TX) { cc110x_statistic.packets_in_while_tx++; return; } cc110x_rx_buffer[rx_buffer_next].rssi = rflags._RSSI; cc110x_rx_buffer[rx_buffer_next].lqi = rflags._LQI; cc110x_strobe(CC1100_SFRX); // ...for flushing the RX FIFO // Valid packet. After a wake-up, the radio should be in IDLE. // So put CC1100 to RX for WOR_TIMEOUT (have to manually put // the radio back to sleep/WOR). //cc110x_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal cc110x_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME (until end of packet) cc110x_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); radio_state = RADIO_RX; #ifdef DBG_IGNORE if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) { LED_RED_TOGGLE; return; } #endif /* notify transceiver thread if any */ if (transceiver_pid) { msg_t m; m.type = (uint16_t) RCV_PKT_CC1100; m.content.value = rx_buffer_next; msg_send_int(&m, transceiver_pid); } /* shift to next buffer element */ if (++rx_buffer_next == RX_BUF_SIZE) { rx_buffer_next = 0; } return; } else { // No ACK received so TOF is unpredictable rflags.TOF = 0; // CRC false or RX buffer full -> clear RX FIFO in both cases cc110x_strobe(CC1100_SIDLE); // Switch to IDLE (should already be)... cc110x_strobe(CC1100_SFRX); // ...for flushing the RX FIFO // If packet interrupted this nodes send call, // don't change anything after this point. if (radio_state == RADIO_AIR_FREE_WAITING) { cc110x_strobe(CC1100_SRX); hwtimer_wait(IDLE_TO_RX_TIME); return; } // If currently sending, exit here (don't go to RX/WOR) if (radio_state == RADIO_SEND_BURST) { cc110x_statistic.packets_in_while_tx++; return; } // No valid packet, so go back to RX/WOR as soon as possible cc110x_switch_to_rx(); } }
void update_pixel_info(ImageInfo *ii) { // update the left-hand "clicked pixel" information char buf[512]; GtkWidget *img = get_widget_checked("big_image"); GdkPixbuf *shown_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(img)); double x = crosshair_samp; double y = crosshair_line; int nl = ii->meta->general->line_count; int ns = ii->meta->general->sample_count; CachedImage *data_ci = ii->data_ci; meta_parameters *meta = ii->meta; sprintf(buf, "Line: %.1f, Sample: %.1f\n", y, x); if (x < 0 || x >= ns || y < 0 || y >= nl) { // outside of the image sprintf(&buf[strlen(buf)], "Pixel Value: (outside image)\n"); } else { assert(meta); assert(shown_pixbuf); if (data_ci->data_type == GREYSCALE_FLOAT) { float fval = cached_image_get_pixel(data_ci, crosshair_line, crosshair_samp); if (have_lut()) { unsigned char r, g, b; cached_image_get_rgb(data_ci, crosshair_line, crosshair_samp, &r, &g, &b); if (is_ignored(&ii->stats, fval)) { sprintf(&buf[strlen(buf)], "Pixel Value: %f [ignored]\n", fval); } else { sprintf(&buf[strlen(buf)], "Pixel Value: %f -> R:%d G:%d B:%d\n", fval, (int)r, (int)g, (int)b); } } else { int uval = calc_scaled_pixel_value(&(ii->stats), fval); if (is_ignored(&ii->stats, fval)) { sprintf(&buf[strlen(buf)], "Pixel Value: %f [ignored]\n", fval); } else { sprintf(&buf[strlen(buf)], "Pixel Value: %f -> %d\n", fval, uval); } } } else if (data_ci->data_type == RGB_BYTE) { unsigned char r, g, b; float rf, gf, bf; cached_image_get_rgb(data_ci, crosshair_line, crosshair_samp, &r, &g, &b); cached_image_get_rgb_float(data_ci, crosshair_line, crosshair_samp, &rf, &gf, &bf); if (!is_ignored_rgb(&ii->stats_r, rf) && !is_ignored_rgb(&ii->stats_g, gf) && !is_ignored_rgb(&ii->stats_b, bf)) { sprintf(&buf[strlen(buf)], "Pixel Value: R,G,B = %d, %d, %d\n", (int)r, (int)g, (int)b); } else { sprintf(&buf[strlen(buf)], "Pixel Value: R,G,B = %d,%d,%d [ignored]\n", (int)rf, (int)gf, (int)bf); } } else if (data_ci->data_type == GREYSCALE_BYTE) { unsigned char r, g, b; cached_image_get_rgb(data_ci, crosshair_line, crosshair_samp, &r, &g, &b); if (have_lut()) { int gs = (int)cached_image_get_pixel(data_ci, crosshair_line, crosshair_samp); if (is_ignored(&ii->stats, (float)gs)) sprintf(&buf[strlen(buf)], "Pixel Value: %d [ignored]\n", gs); else sprintf(&buf[strlen(buf)], "Pixel Value: %d -> R:%d G:%d B:%d\n", gs, (int)r, (int)g, (int)b); } else { int gs = (int)cached_image_get_pixel(data_ci, crosshair_line, crosshair_samp); if (is_ignored(&ii->stats, gs)) { sprintf(&buf[strlen(buf)], "Pixel Value: %d [ignored]\n", gs); } else if (ii->stats.truncate) { sprintf(&buf[strlen(buf)], "Pixel Value: %d\n", gs); } else { sprintf(&buf[strlen(buf)], "Pixel Value: %d -> %d\n", gs, (int)r); } } } else if (data_ci->data_type == RGB_FLOAT) { unsigned char r, g, b; float rf, gf, bf; cached_image_get_rgb(data_ci, crosshair_line, crosshair_samp, &r, &g, &b); cached_image_get_rgb_float(data_ci, crosshair_line, crosshair_samp, &rf, &gf, &bf); if (is_ignored_rgb(&ii->stats_r, rf)) sprintf(&buf[strlen(buf)], "Red: %f [ignored]\n", rf); else sprintf(&buf[strlen(buf)], "Red: %f -> %d\n", rf, (int)r); if (is_ignored_rgb(&ii->stats_g, gf)) sprintf(&buf[strlen(buf)], "Green: %f [ignored]\n", gf); else sprintf(&buf[strlen(buf)], "Green: %f -> %d\n", gf, (int)g); if (is_ignored_rgb(&ii->stats_b, bf)) sprintf(&buf[strlen(buf)], "Blue: %f [ignored]\n", rf); else sprintf(&buf[strlen(buf)], "Blue: %f -> %d\n", bf, (int)b); } } double lat=0, lon=0; if (meta_supports_meta_get_latLon(meta)) { meta_get_latLon(meta, y, x, 0, &lat, &lon); sprintf(&buf[strlen(buf)], "Lat, Lon: %.5f, %.5f (deg)\n", lat, lon); //double px, py; //latLon2UTM(lat,lon,0,&px,&py); //printf("%14.7f %14.7f --> %13.2f %13.2f\n", lat, lon, px, py); } // skip projection coords if not projected, or lat/long pseudo (since // in that case the projection coords are just the lat/long values // we are already showing) if (meta->projection && meta->projection->type != LAT_LONG_PSEUDO_PROJECTION) { double projX, projY, projZ; latlon_to_proj(meta->projection, 'R', lat*D2R, lon*D2R, 0, &projX, &projY, &projZ); sprintf(&buf[strlen(buf)], "Proj X,Y: %.1f, %.1f m\n", projX, projY); } if (!meta->projection && meta->state_vectors && meta->sar) { double s,t; meta_get_timeSlantDop(meta, y, x, &t, &s, NULL); sprintf(&buf[strlen(buf)], "Incid: %.4f, Look: %.4f (deg)\n" "Slant: %.1f m Time: %.3f s\n" "Yaw: %.4f (deg)\n", R2D*meta_incid(meta,y,x), R2D*meta_look(meta,y,x), s, t, R2D*meta_yaw(meta,y,x)); } if (meta->projection && meta->projection->type != LAT_LONG_PSEUDO_PROJECTION && meta->projection->type != SCANSAR_PROJECTION) { distortion_t d; map_distortions(meta->projection, lat*D2R, lon*D2R, &d); sprintf(&buf[strlen(buf)], "Meridian scale factor: %.6f\n", d.h); sprintf(&buf[strlen(buf)], "Parallel scale factor: %.6f\n", d.k); sprintf(&buf[strlen(buf)], "Areal scale factor: %.6f\n", d.s); sprintf(&buf[strlen(buf)], "Angular distortion: %.4f (deg)\n", d.omega); } if (g_poly->n > 0) { // start distance measure at crosshair coords double cross_x, cross_y, prev_x, prev_y; line_samp_to_proj(ii, y, x, &cross_x, &cross_y); prev_x = cross_x; prev_y = cross_y; // iterate through ctrl-clicked coords int i; double d=0, A=0; // d=distance, A=area for (i=0; i<g_poly->n; ++i) { double proj_x, proj_y; line_samp_to_proj(ii, g_poly->line[i], g_poly->samp[i], &proj_x, &proj_y); d += hypot(proj_x-prev_x, proj_y-prev_y); A += prev_x * proj_y - proj_x * prev_y; prev_x = proj_x; prev_y = proj_y; // for the area calc, we close the polygon automatically if (i==g_poly->n-1) A += prev_x * cross_y - cross_x * prev_y; } A /= 2.; char *units = "m"; if (!meta_supports_meta_get_latLon(meta)) units = "pixels"; if (g_poly->n == 1) sprintf(&buf[strlen(buf)], "Distance to %.1f,%.1f: %.1f %s", g_poly->line[0], g_poly->samp[0], d, units); else sprintf(&buf[strlen(buf)], "Total distance: %.1f %s (%d points)\n" "Area (of closure): %.1f %s^2", d, units, g_poly->n+1, fabs(A), units); } else { sprintf(&buf[strlen(buf)], "Distance: (ctrl-click to measure)"); } put_text_in_textview(buf, "info_textview"); //GtkWidget *lbl = get_widget_checked("upper_label"); //gtk_label_set_text(GTK_LABEL(lbl), buf); }
bool ignore_manager::is_ignored(user_ptr user, user_ptr ignored_user) const { return is_ignored(user->get_session_id(), ignored_user->get_session_id()); }
static int read_chan(struct tty_struct *tty, struct file *file, unsigned char *buf, unsigned int nr) { struct wait_queue wait = { current, NULL }; int c; unsigned char *b = buf; int minimum, time; int retval = 0; int size; do_it_again: if (!tty->read_buf) { printk("n_tty_read_chan: called with read_buf == NULL?!?\n"); return -EIO; } /* Job control check -- must be done at start and after every sleep (POSIX.1 7.1.1.4). */ /* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ if (file->f_inode->i_rdev != CONSOLE_DEV && current->tty == tty) { if (tty->pgrp <= 0) printk("read_chan: tty->pgrp <= 0!\n"); else if (current->pgrp != tty->pgrp) { if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp)) return -EIO; kill_pg(current->pgrp, SIGTTIN, 1); return -ERESTARTSYS; } } if (L_ICANON(tty)) { minimum = time = 0; current->timeout = (unsigned long) -1; } else { time = (HZ / 10) * TIME_CHAR(tty); minimum = MIN_CHAR(tty); if (minimum) { current->timeout = (unsigned long) -1; if (time) tty->minimum_to_wake = 1; else if (!waitqueue_active(&tty->read_wait) || (tty->minimum_to_wake > minimum)) tty->minimum_to_wake = minimum; } else { if (time) { current->timeout = time + jiffies; time = 0; } else current->timeout = 0; tty->minimum_to_wake = minimum = 1; } } add_wait_queue(&tty->read_wait, &wait); while (1) { /* First test for status change. */ if (tty->packet && tty->link->ctrl_status) { if (b != buf) break; put_user(tty->link->ctrl_status, b++); tty->link->ctrl_status = 0; break; } /* This statement must be first before checking for input so that any interrupt will set the state back to TASK_RUNNING. */ current->state = TASK_INTERRUPTIBLE; if (((minimum - (b - buf)) < tty->minimum_to_wake) && ((minimum - (b - buf)) >= 1)) tty->minimum_to_wake = (minimum - (b - buf)); if (!input_available_p(tty, 0)) { if (tty->flags & (1 << TTY_OTHER_CLOSED)) { retval = -EIO; break; } if (tty_hung_up_p(file)) break; if (!current->timeout) break; if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; break; } if (current->signal & ~current->blocked) { retval = -ERESTARTSYS; break; } schedule(); continue; } current->state = TASK_RUNNING; /* Deal with packet mode. */ if (tty->packet && b == buf) { put_user(TIOCPKT_DATA, b++); nr--; } if (L_ICANON(tty)) { while (1) { int eol; disable_bh(TQUEUE_BH); if (!tty->read_cnt) { enable_bh(TQUEUE_BH); break; } eol = clear_bit(tty->read_tail, &tty->read_flags); c = tty->read_buf[tty->read_tail]; tty->read_tail = ((tty->read_tail+1) & (N_TTY_BUF_SIZE-1)); tty->read_cnt--; enable_bh(TQUEUE_BH); if (!eol) { put_user(c, b++); if (--nr) continue; break; } if (--tty->canon_data < 0) { tty->canon_data = 0; } if (c != __DISABLED_CHAR) { put_user(c, b++); nr--; } break; } } else { disable_bh(TQUEUE_BH); copy_from_read_buf(tty, &b, &nr); copy_from_read_buf(tty, &b, &nr); enable_bh(TQUEUE_BH); } /* If there is enough space in the read buffer now, let the low-level driver know. */ if (tty->driver.unthrottle && (tty->read_cnt <= TTY_THRESHOLD_UNTHROTTLE) && clear_bit(TTY_THROTTLED, &tty->flags)) tty->driver.unthrottle(tty); if (b - buf >= minimum || !nr) break; if (time) current->timeout = time + jiffies; } remove_wait_queue(&tty->read_wait, &wait); if (!waitqueue_active(&tty->read_wait)) tty->minimum_to_wake = minimum; current->state = TASK_RUNNING; current->timeout = 0; size = b - buf; if (size && nr) clear_bit(TTY_PUSH, &tty->flags); if (!size && clear_bit(TTY_PUSH, &tty->flags)) goto do_it_again; if (!size && !retval) clear_bit(TTY_PUSH, &tty->flags); return (size ? size : retval); }
static ssize_t read_chan(struct tty_struct *tty, struct file *file, unsigned char *buf, size_t nr) { unsigned char *b = buf; struct wait_queue wait = { current, NULL }; int c; int minimum, time; ssize_t retval = 0; ssize_t size; long timeout; do_it_again: if (!tty->read_buf) { printk("n_tty_read_chan: called with read_buf == NULL?!?\n"); return -EIO; } /* Job control check -- must be done at start and after every sleep (POSIX.1 7.1.1.4). */ /* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ if (file->f_dentry->d_inode->i_rdev != CONSOLE_DEV && file->f_dentry->d_inode->i_rdev != SYSCONS_DEV && current->tty == tty) { if (tty->pgrp <= 0) printk("read_chan: tty->pgrp <= 0!\n"); else if (current->pgrp != tty->pgrp) { if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp)) return -EIO; kill_pg(current->pgrp, SIGTTIN, 1); return -ERESTARTSYS; } } minimum = time = 0; timeout = MAX_SCHEDULE_TIMEOUT; if (!tty->icanon) { time = (HZ / 10) * TIME_CHAR(tty); minimum = MIN_CHAR(tty); if (minimum) { if (time) tty->minimum_to_wake = 1; else if (!waitqueue_active(&tty->read_wait) || (tty->minimum_to_wake > minimum)) tty->minimum_to_wake = minimum; } else { timeout = 0; if (time) { timeout = time; time = 0; } tty->minimum_to_wake = minimum = 1; } } if (file->f_flags & O_NONBLOCK) { if (down_trylock(&tty->atomic_read)) return -EAGAIN; } else { if (down_interruptible(&tty->atomic_read)) return -ERESTARTSYS; } add_wait_queue(&tty->read_wait, &wait); set_bit(TTY_DONT_FLIP, &tty->flags); while (nr) { /* First test for status change. */ if (tty->packet && tty->link->ctrl_status) { unsigned char cs; if (b != buf) break; cs = tty->link->ctrl_status; tty->link->ctrl_status = 0; put_user(cs, b++); nr--; break; } /* This statement must be first before checking for input so that any interrupt will set the state back to TASK_RUNNING. */ current->state = TASK_INTERRUPTIBLE; if (((minimum - (b - buf)) < tty->minimum_to_wake) && ((minimum - (b - buf)) >= 1)) tty->minimum_to_wake = (minimum - (b - buf)); if (!input_available_p(tty, 0)) { if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { retval = -EIO; break; } if (tty_hung_up_p(file)) break; if (!timeout) break; if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; break; } if (signal_pending(current)) { retval = -ERESTARTSYS; break; } clear_bit(TTY_DONT_FLIP, &tty->flags); timeout = schedule_timeout(timeout); set_bit(TTY_DONT_FLIP, &tty->flags); continue; } current->state = TASK_RUNNING; /* Deal with packet mode. */ if (tty->packet && b == buf) { put_user(TIOCPKT_DATA, b++); nr--; } if (tty->icanon) { /* N.B. avoid overrun if nr == 0 */ while (nr && tty->read_cnt) { int eol; eol = test_and_clear_bit(tty->read_tail, &tty->read_flags); c = tty->read_buf[tty->read_tail]; tty->read_tail = ((tty->read_tail+1) & (N_TTY_BUF_SIZE-1)); tty->read_cnt--; if (!eol || (c != __DISABLED_CHAR)) { put_user(c, b++); nr--; } if (eol) { /* this test should be redundant: * we shouldn't be reading data if * canon_data is 0 */ if (--tty->canon_data < 0) tty->canon_data = 0; break; } } } else { int uncopied; uncopied = copy_from_read_buf(tty, &b, &nr); uncopied += copy_from_read_buf(tty, &b, &nr); if (uncopied) { retval = -EFAULT; break; } } /* If there is enough space in the read buffer now, let the * low-level driver know. We use n_tty_chars_in_buffer() to * check the buffer, as it now knows about canonical mode. * Otherwise, if the driver is throttled and the line is * longer than TTY_THRESHOLD_UNTHROTTLE in canonical mode, * we won't get any more characters. */ if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) check_unthrottle(tty); if (b - buf >= minimum) break; if (time) timeout = time; } clear_bit(TTY_DONT_FLIP, &tty->flags); up(&tty->atomic_read); remove_wait_queue(&tty->read_wait, &wait); if (!waitqueue_active(&tty->read_wait)) tty->minimum_to_wake = minimum; current->state = TASK_RUNNING; size = b - buf; if (size) { retval = size; if (nr) clear_bit(TTY_PUSH, &tty->flags); } else if (test_and_clear_bit(TTY_PUSH, &tty->flags)) goto do_it_again; return retval; }
void push_changes(lua_State *l, const char *base_path, const char *full_path) { struct dirent **dir_list = NULL; struct dirent *dir = NULL; int results; int i; int rv; char *path; if (strncmp(base_path, full_path, strlen(base_path)) != 0) die("wtf? %s != %s len %li", base_path, full_path, strlen(base_path)); gettimeofday(&now, NULL); path = strdup(full_path + strlen(base_path) + 1); /* Skip trailing slash in full_path */ log_debug("relative path is %s", path); scandir_baton_t baton; baton.ig = root_ignores; baton.base_path = base_path; baton.level = 0; results = ds_scandir(full_path, &dir_list, &changed_filter, &baton); if (results == -1) { log_debug("Error scanning directory %s: %s", full_path, strerror(errno)); return; } else if (results == 0) { log_debug("No results found in directory %s", full_path); return; } char *file_path; char *file_path_rel; for (i = 0; i < results; i++) { dir = dir_list[i]; ds_asprintf(&file_path, "%s%s", full_path, dir->d_name); ds_asprintf(&file_path_rel, "%s%s", path, dir->d_name); if (is_ignored(file_path)) { /* we triggered this event */ unignore_change(file_path); goto cleanup; } if (is_directory(full_path, dir)) { /* TODO: figure out if we need to recurse */ goto cleanup; } buf_t *buf = get_buf(file_path_rel); if (buf == NULL) { log_err("buf not found for path %s", file_path_rel); goto cleanup; } const char *f2 = file_path; mmapped_file_t *mf; struct stat file_stats; off_t f2_size; rv = lstat(f2, &file_stats); if (rv) { die("Error lstat()ing file %s.", f2); } f2_size = file_stats.st_size; if (f2_size == 0) { log_debug("%s is empty"); goto cleanup; } mf = mmap_file(f2, f2_size, 0, 0); if (is_binary(mf->buf, mf->len)) { log_debug("%s is binary. skipping", file_path); goto diff_cleanup; } char *new_text = strndup(mf->buf, mf->len); char *patch_text = make_patch(l, buf->buf, new_text); free(new_text); if (strlen(patch_text) == 0) { log_debug("no change. not sending patch"); goto diff_cleanup; } char *md5_after = md5(mf->buf, mf->len); send_json( "{s:s s:i s:s s:s s:s s:s}", "name", "patch", "id", buf->id, "patch", patch_text, "path", buf->path, "md5_before", buf->md5, "md5_after", md5_after ); free(md5_after); free(patch_text); buf->buf = realloc(buf->buf, mf->len + 1); buf->len = mf->len; memcpy(buf->buf, mf->buf, buf->len); diff_cleanup:; munmap_file(mf); free(mf); cleanup:; free(file_path); free(file_path_rel); free(dir); } free(dir_list); free(path); }
static int read_chan(struct tty_struct *tty, struct file *file, unsigned char *buf, unsigned int nr) { struct wait_queue wait = { current, NULL }; int c; unsigned char *b = buf; int minimum, time; int retval = 0; /* Job control check -- must be done at start and after every sleep (POSIX.1 7.1.1.4). */ /* NOTE: not yet done after every sleep pending a thorough check of the logic of this change. -- jlc */ /* don't stop on /dev/console */ if (file->f_inode->i_rdev != CONSOLE_DEV && current->tty == tty->line) { if (tty->pgrp <= 0) printk("read_chan: tty->pgrp <= 0!\n"); else if (current->pgrp != tty->pgrp) { if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp)) return -EIO; kill_pg(current->pgrp, SIGTTIN, 1); return -ERESTARTSYS; } } if (L_ICANON(tty)) { minimum = time = 0; current->timeout = (unsigned long) -1; } else { time = (HZ / 10) * TIME_CHAR(tty); minimum = MIN_CHAR(tty); if (minimum) current->timeout = (unsigned long) -1; else { if (time) { current->timeout = time + jiffies; time = 0; } else current->timeout = 0; minimum = 1; } } add_wait_queue(&tty->secondary.proc_list, &wait); while (1) { /* First test for status change. */ if (tty->packet && tty->link->ctrl_status) { if (b != buf) break; put_fs_byte(tty->link->ctrl_status, b++); tty->link->ctrl_status = 0; break; } /* This statement must be first before checking for input so that any interrupt will set the state back to TASK_RUNNING. */ current->state = TASK_INTERRUPTIBLE; if (!input_available_p(tty)) { if (tty->flags & (1 << TTY_SLAVE_CLOSED)) { retval = -EIO; break; } if (tty_hung_up_p(file)) break; if (!current->timeout) break; if (file->f_flags & O_NONBLOCK) { retval = -EAGAIN; break; } if (current->signal & ~current->blocked) { retval = -ERESTARTSYS; break; } schedule(); continue; } current->state = TASK_RUNNING; /* Deal with packet mode. */ if (tty->packet && b == buf) { put_fs_byte(TIOCPKT_DATA, b++); nr--; } while (1) { int eol; cli(); if (EMPTY(&tty->secondary)) { sti(); break; } eol = clear_bit(tty->secondary.tail, &tty->secondary_flags); c = tty->secondary.buf[tty->secondary.tail]; if (!nr) { /* Gobble up an immediately following EOF if there is no more room in buf (this can happen if the user "pushes" some characters using ^D). This prevents the next read() from falsely returning EOF. */ if (eol) { if (c == __DISABLED_CHAR) { tty->canon_data--; INC(tty->secondary.tail); } else { set_bit(tty->secondary.tail, &tty->secondary_flags); } } sti(); break; } INC(tty->secondary.tail); sti(); if (eol) { if (--tty->canon_data < 0) { printk("read_chan: canon_data < 0!\n"); tty->canon_data = 0; } if (c == __DISABLED_CHAR) break; put_fs_byte(c, b++); nr--; break; } put_fs_byte(c, b++); nr--; } /* If there is enough space in the secondary queue now, let the low-level driver know. */ if (tty->throttle && (LEFT(&tty->secondary) >= SQ_THRESHOLD_HW) && clear_bit(TTY_SQ_THROTTLED, &tty->flags)) tty->throttle(tty, TTY_THROTTLE_SQ_AVAIL); if (b - buf >= minimum || !nr) break; if (time) current->timeout = time + jiffies; } remove_wait_queue(&tty->secondary.proc_list, &wait); current->state = TASK_RUNNING; current->timeout = 0; return (b - buf) ? b - buf : retval; }