Exemple #1
0
static void read_loop(int fd) {

  struct sockaddr_in from;
  struct sockaddr_in to;
  socklen_t fromlen = sizeof(from);
  socklen_t tolen = sizeof(to);
  int ifindex = -1;
  uint8_t buf[10000];
  int rd;

  char str_from[100];
  char str_to[100];
  char ifname[100];

  for (;;) {
    rd = recvfromto(fd, buf, sizeof buf,
		    &from, &fromlen,
		    &to, &tolen,
		    &ifindex);
    if (rd < 0) {
      fprintf(stderr,
	      "%s: error: errno=%d: %s\n",
	      prog_name, errno, strerror(errno));
      continue;
    }

    inet_ntop(AF_INET, &from.sin_addr, str_from, sizeof str_from);
    inet_ntop(AF_INET, &to.sin_addr, str_to, sizeof str_to);
    index_to_name(ifindex, ifname, sizeof ifname);
    
    printf("%s: read %d bytes from %s:%d to %s:%d on %s ifindex=%d\n",
	   prog_name, rd, str_from, ntohs(from.sin_port), str_to, ntohs(to.sin_port),
	   ifname, ifindex);
  }
  
}
Exemple #2
0
static void x_reset_modifier_mapping(Display * display)
{
	int modifier_index, modifier_key, column, mkpm;
	int meta_bit = 0;
	int hyper_bit = 0;
	int super_bit = 0;
	int alt_bit = 0;
	int mode_bit = 0;
	XModifierKeymap *x_modifier_keymap;

#define modwarn(name,old,other)							\
    wwarning(_("%s (0x%x) generates %s which is generated by %s"),		\
    name, code, index_to_name (old), other)

#define modbarf(name,other)							\
    wwarning(_("%s (0x%x) generates %s which is nonsensical"),			\
    name, code, other)

#define check_modifier(name,mask)						\
    if ((1<<modifier_index) != mask)						\
    wwarning(_("%s (0x%x) generates %s which is nonsensical"),			\
    name, code, index_to_name (modifier_index))

#define store_modifier(name,old)						\
    if (old && old != modifier_index)						\
    wwarning(_("%s (0x%x) generates both %s and %s which is nonsensical"),	\
    name, code, index_to_name (old),						\
    index_to_name (modifier_index));						\
    if (modifier_index == ShiftMapIndex) modbarf (name,"ModShift");		\
    else if (modifier_index == LockMapIndex) modbarf (name,"ModLock");		\
    else if (modifier_index == ControlMapIndex) modbarf (name,"ModControl");	\
    else if (sym == XK_Mode_switch)						\
    mode_bit = modifier_index; /* Mode_switch is special, see below... */	\
    else if (modifier_index == meta_bit && old != meta_bit)			\
    modwarn (name, meta_bit, "Meta");						\
    else if (modifier_index == super_bit && old != super_bit)			\
    modwarn (name, super_bit, "Super");						\
    else if (modifier_index == hyper_bit && old != hyper_bit)			\
    modwarn (name, hyper_bit, "Hyper");						\
    else if (modifier_index == alt_bit && old != alt_bit)			\
    modwarn (name, alt_bit, "Alt");						\
    else									\
    old = modifier_index;

	x_modifier_keymap = XGetModifierMapping(display);
	if (x_modifier_keymap == NULL) {
		wwarning(_("XGetModifierMapping returned NULL, there is no modifier or no memory"));
		return;
	}

	mkpm = x_modifier_keymap->max_keypermod;
	for (modifier_index = 0; modifier_index < 8; modifier_index++)
		for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
			KeySym last_sym = 0;
			for (column = 0; column < 4; column += 2) {
				KeyCode code = x_modifier_keymap->modifiermap[modifier_index * mkpm
									      + modifier_key];
				KeySym sym;

				if (code) {
					if (xext_xkb_supported)
						sym = XkbKeycodeToKeysym(display, code, 0, column);
					else
						sym = XKeycodeToKeysym(display, code, column);
				} else {
					sym = NoSymbol;
				}

				if (sym == last_sym)
					continue;
				last_sym = sym;
				switch (sym) {
				case XK_Mode_switch:
					store_modifier("Mode_switch", mode_bit);
					break;
				case XK_Meta_L:
					store_modifier("Meta_L", meta_bit);
					break;
				case XK_Meta_R:
					store_modifier("Meta_R", meta_bit);
					break;
				case XK_Super_L:
					store_modifier("Super_L", super_bit);
					break;
				case XK_Super_R:
					store_modifier("Super_R", super_bit);
					break;
				case XK_Hyper_L:
					store_modifier("Hyper_L", hyper_bit);
					break;
				case XK_Hyper_R:
					store_modifier("Hyper_R", hyper_bit);
					break;
				case XK_Alt_L:
					store_modifier("Alt_L", alt_bit);
					break;
				case XK_Alt_R:
					store_modifier("Alt_R", alt_bit);
					break;
				case XK_Control_L:
					check_modifier("Control_L", ControlMask);
					break;
				case XK_Control_R:
					check_modifier("Control_R", ControlMask);
					break;
				case XK_Shift_L:
					check_modifier("Shift_L", ShiftMask);
					break;
				case XK_Shift_R:
					check_modifier("Shift_R", ShiftMask);
					break;
				case XK_Shift_Lock:
					check_modifier("Shift_Lock", LockMask);
					break;
				case XK_Caps_Lock:
					check_modifier("Caps_Lock", LockMask);
					break;

					/* It probably doesn't make any sense for a modifier bit to be
					   assigned to a key that is not one of the above, but OpenWindows
					   assigns modifier bits to a couple of random function keys for
					   no reason that I can discern, so printing a warning here would
					   be annoying. */
				}
			}
		}
#undef store_modifier
#undef check_modifier
#undef modwarn
#undef modbarf

	/* If there was no Meta key, then try using the Alt key instead.
	   If there is both a Meta key and an Alt key, then the Alt key
	   is not disturbed and remains an Alt key. */
	if (!meta_bit && alt_bit)
		meta_bit = alt_bit, alt_bit = 0;

	/* mode_bit overrides everything, since it's processed down inside of
	   XLookupString() instead of by us.  If Meta and Mode_switch both
	   generate the same modifier bit (which is an error), then we don't
	   interpret that bit as Meta, because we can't make XLookupString()
	   not interpret it as Mode_switch; and interpreting it as both would
	   be totally wrong. */
	if (mode_bit) {
		const char *warn = 0;
		if (mode_bit == meta_bit)
			warn = "Meta", meta_bit = 0;
		else if (mode_bit == hyper_bit)
			warn = "Hyper", hyper_bit = 0;
		else if (mode_bit == super_bit)
			warn = "Super", super_bit = 0;
		else if (mode_bit == alt_bit)
			warn = "Alt", alt_bit = 0;
		if (warn) {
			wwarning(_("%s is being used for both %s and %s"),
			         index_to_name(mode_bit), "Mode_switch", warn);
		}
	}

	MetaIndex = meta_bit;
	HyperIndex = hyper_bit;
	SuperIndex = super_bit;
	AltIndex = alt_bit;
	ModeIndex = mode_bit;

	XFreeModifiermap(x_modifier_keymap);
}
/*---------------------------------------------------------------*/
int main(int argc, char *argv[]) {
  int nargs, nthlabel, n, vtxno, ano, index, nunhit;

  nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $");
  if (nargs && argc - nargs == 1) exit (0);
  argc -= nargs;
  cmdline = argv2cmdline(argc,argv);
  uname(&uts);
  getcwd(cwd,2000);

  Progname = argv[0] ;
  argc --;
  argv++;
  ErrorInit(NULL, NULL, NULL) ;
  DiagInit(NULL, NULL, NULL) ;
  if (argc == 0) usage_exit();
  parse_commandline(argc, argv);
  check_options();
  if (checkoptsonly) return(0);
  dump_options(stdout);

  // Make sure subject exists
  sprintf(tmpstr,"%s/%s",SUBJECTS_DIR,subject);
  if (!fio_IsDirectory(tmpstr)) {
    printf("ERROR: cannot find %s\n",tmpstr);
    exit(1);
  }

  if(AnnotPath == NULL){
    // Get path to annot, make sure it does not exist
    sprintf(tmpstr,"%s/%s/label/%s.%s.annot",
	    SUBJECTS_DIR,subject,hemi,AnnotName);
    if (fio_FileExistsReadable(tmpstr)) {
      printf("ERROR: %s already exists\n",tmpstr);
      exit(1);
    }
    AnnotPath = strcpyalloc(tmpstr);
  }

  // Read the surf
  sprintf(tmpstr,"%s/%s/surf/%s.orig",SUBJECTS_DIR,subject,hemi);
  printf("Loading %s\n",tmpstr);
  mris = MRISread(tmpstr);
  if (mris == NULL) exit(1);

  // Set up color table
  set_atable_from_ctable(ctab);
  mris->ct = ctab;

  // Set up something to keep track of nhits
  nhits = MRIalloc(mris->nvertices,1,1,MRI_INT);

  // Set up something to keep track of max stat for that vertex
  if (maxstatwinner) maxstat = MRIalloc(mris->nvertices,1,1,MRI_FLOAT);

  // Go thru each label
  for (nthlabel = 0; nthlabel < nlabels; nthlabel ++) {
    label = LabelRead(subject,LabelFiles[nthlabel]);
    if (label == NULL) {
      printf("ERROR: reading %s\n",LabelFiles[nthlabel]);
      exit(1);
    }
    index = nthlabel;
    if (MapUnhitToUnknown) index ++;
    ano = index_to_annotation(index);
    printf("%2d %2d %s\n",index,ano,index_to_name(index));

    for (n = 0; n < label->n_points; n++) {
      vtxno = label->lv[n].vno;
      if (vtxno < 0 || vtxno > mris->nvertices) {
        printf("ERROR: %s, n=%d, vertex %d out of range\n",
               LabelFiles[nthlabel],n,vtxno);
        exit(1);
      }
      if(DoLabelThresh && label->lv[n].stat < LabelThresh) continue;

      if (maxstatwinner) {
        float stat = MRIgetVoxVal(maxstat,vtxno,0,0,0);
        if (label->lv[n].stat < stat) {
          if (verbose) {
            printf("Keeping prior label for vtxno %d "
                   "(old_stat=%f > this_stat=%f)\n",
                   vtxno,stat,label->lv[n].stat);
          }
          continue;
        }
        MRIsetVoxVal(maxstat,vtxno,0,0,0,label->lv[n].stat);
      }

      if (verbose) {
        if (MRIgetVoxVal(nhits,vtxno,0,0,0) > 0) {
          printf
            ("WARNING: vertex %d maps to multiple labels! (overwriting)\n",
             vtxno);
        }
      }
      MRIsetVoxVal(nhits,vtxno,0,0,0,MRIgetVoxVal(nhits,vtxno,0,0,0)+1);

      mris->vertices[vtxno].annotation = ano;
      //printf("%5d %2d %2d %s\n",vtxno,segid,ano,index_to_name(segid));
    } // label ponts
    LabelFree(&label);
  }// Label

  nunhit = 0;
  if (MapUnhitToUnknown) {
    printf("Mapping unhit to unknown\n");
    for (vtxno = 0; vtxno < mris->nvertices; vtxno++) {
      if (MRIgetVoxVal(nhits,vtxno,0,0,0) == 0) {
        ano = index_to_annotation(0);
        mris->vertices[vtxno].annotation = ano;
        nunhit ++;
      }
    }
    printf("Found %d unhit vertices\n",nunhit);
  }

  if (dilate_label_name)
  {
    dilate_label_into_unknown(mris, dilate_label_annot) ;
  }
  printf("Writing annot to %s\n",AnnotPath);
  MRISwriteAnnotation(mris, AnnotPath);

  if (NHitsFile != NULL) MRIwrite(nhits,NHitsFile);

  return 0;
}