Beispiel #1
0
void exec(char *str)
{
	char *lhs = (char *) allocs(strlen(str));
	char *rhs = (char *) allocs(strlen(str));
	char *sptr = NULL;

	/* here the rhs & lhs are obtained */
	for(sptr=lhs;*str!='\0'&&*str!='=';str++)
	*sptr++ = *str;
	*sptr = '\0';
	if(*str=='=')
	for(sptr=rhs,str++;*str!='\0';str++) {
    *sptr++ = *str;
	*sptr = '\0'; }
	else *rhs = '\0';
	printf("%s",lhs);

	int32 *value= NULL;
	if(*rhs=='\0') /* rhs is empty */
	{
		/* no assignment involved */
		value = getint(lhs);
		if(value!=NULL)
		printf(" = %ld\n",*value);
	}
	else  /* rhs exists */
	{
		int32 rvalue=0;
		rvalue = atoi(rhs);
		printf(" = %ld\n",rvalue);
		value = newint(lhs);
		*value = rvalue;
	}

	free(lhs);
	free(rhs);
}
Beispiel #2
0
/*
 * process the option at 'argv[i]'
 * Params:
 * 	*table	the element to process
 *	arg	the argument if any
 *
 * returns <0 on error
 */
static int
process( optionT *table, const char *arg )
{	int nRet=0;
	typedef void (*callbackT)(void);

	assert( table );
	if( !table->data )
		return -1;

	/* TODO: next time do the questions on a table! */
	switch( table->type )
	{	case OPT_T_FLAG:
		case OPT_T_NFLAG:
			*((int *)table->data) = table->type == OPT_T_FLAG;
			break;
		case OPT_T_INT:
			nRet = getint(arg,table->data);
			break;
		case OPT_T_LONG:
			nRet = getlong(arg,table->data);
			break;
		case OPT_T_REAL:
			nRet = getreal(arg,table->data);
			break;
		case OPT_T_FUNCT:
			(*(callbackT)table->data)();
			break;
		case OPT_T_GENER:
			*((const char **)table->data) = arg;
			break;
		default:
			assert( 0 );
	}
	
	return nRet;	
}
int main(void)
{
  int fd;
  int cmd, finish;

  if ((fd = open(PHONEBOOK, O_RDWR|O_CREAT, 0666)) < 0) {
    perror("open");
    exit(1);
  }

  finish = 0;
  while (!finish) {
    cmd = getint("command (0=show, 1=input, 2=end)? ");
    switch (cmd) {
      case 0:
        show(fd);
        break;
      case 1:
        input(fd);
        break;
      case 2:
        finish = 1;
        break;
      default:
        fprintf(stderr, "unknown command %d\n", cmd);
        break;
    }
  }

  if (close(fd) == -1) {
    perror("close");
    exit(1);
  }

  return 0;
}
Beispiel #4
0
Datei: 7-4.c Projekt: 1sps/knr
/* pscanf: minimal scanf */
void pscanf(char *fmt, ...)
{
	va_list ap;
	int *iptr;
	float *fptr;
	char *cptr, *sptr, *p;

	va_start(ap, fmt);
	for (p=fmt; *p != '\0'; p++)
	{
		if (*p != '%')
			continue;
		switch (*++p)
		{
		case 'c':
			cptr = va_arg(ap, char *);
			*cptr = getch();
			break;
		case 'd':
			iptr = va_arg(ap, int *);
			*iptr = getint();
			break;
		case 'f':
			fptr = va_arg(ap, float *);
			*fptr = getflt();
			break;
		case 's':
			sptr = va_arg(ap, char *);
			sptr = getstr(sptr);
			break;
		default:
			break;
		}
	}
	va_end(ap);
}
void string_getcolor(avm *vm)
{

     word w;
     long off = newtable(vm, ZEN_INITIALTABLESIZE);
     long tindex = TOTinsert(vm, off);
     ctable* tbl = (ctable*)getdata(vm->hp.heap, off);
     word index, source;
     sfColor col = sfString_GetColor(getint(vm, 0));
     sets(&index, newstring(vm, "R"));
     sets(&source, newstring(vm, col.r));
     IA(vm, tbl, tindex, &index, &source);
     sets(&index, newstring(vm, "G"));
     sets(&source, newstring(vm, col.g));
     IA(vm, tbl, tindex, &index, &source);
     sets(&index, newstring(vm, "B"));
     sets(&source, newstring(vm, col.b));
     IA(vm, tbl, tindex, &index, &source);
     sets(&index, newstring(vm, "A"));
     sets(&source, newstring(vm, col.a));
     IA(vm, tbl, tindex, &index, &source);
     sett(&w, tindex);
     returnv(vm, &w);
}
Beispiel #6
0
/* convert a given time in t1 and date in t2 into struct tm */
int conv_time(char *t1, char *t2, struct tm *tt) {
	int h, m, s, d, mm, y;
	char *t;

	/* hh:mm[:ss] */
	t = t1;
	h = getint(t, &t);
	if ((h < 0) || (h > 23) || (*t++ != ':'))	return 0;
	m = getint(t, &t);
	if ((m < 0) || (m > 59))			return 0;
	if (*t) {
		if (*t++ != ':')			return 0;
		s = getint(t, &t);
		if ((s < 0) || (s > 59) || (*t != 0))	return 0;
	}
	else	s = 0;

	/* dd/mm/yy[yy] */
	t = t2;
	d = getint(t, &t);
	if ((d < 1) || (d > 31) || (*t++ != '/'))	return 0;
	mm = getint(t, &t);
	if ((mm < 1) || (mm > 12) || (*t++ != '/'))	return 0;
	y = getint(t, &t);
	if (y < 100) {
		if (y < 80)
			y += 100;
	}
	else	y -= 1900;
	if ((y < 0) || (*t != 0))			return 0;
	tt->tm_hour = h;
	tt->tm_min = m;
	tt->tm_sec = s;
	tt->tm_year = y;
	tt->tm_mon = mm - 1;
	tt->tm_mday = d;
	return 1;
}
Beispiel #7
0
int getuint(void)
{
    int n = getint();
    return (n < 0) ? 0 : n;
}
Beispiel #8
0
static PyObject *
sp_CreateProcess(PyObject* self, PyObject* args)
{
	BOOL result;
	PROCESS_INFORMATION pi;
	STARTUPINFO si;
	PyObject* environment;

	char* application_name;
	char* command_line;
	PyObject* process_attributes; /* ignored */
	PyObject* thread_attributes; /* ignored */
	int inherit_handles;
	int creation_flags;
	PyObject* env_mapping;
	char* current_directory;
	PyObject* startup_info;

	if (! PyArg_ParseTuple(args, "zzOOiiOzO:CreateProcess",
			       &application_name,
			       &command_line,
			       &process_attributes,
			       &thread_attributes,
			       &inherit_handles,
			       &creation_flags,
			       &env_mapping,
			       &current_directory,
			       &startup_info))
		return NULL;

	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);

	/* note: we only support a small subset of all SI attributes */
	si.dwFlags = getint(startup_info, "dwFlags");
	si.wShowWindow = getint(startup_info, "wShowWindow");
	si.hStdInput = gethandle(startup_info, "hStdInput");
	si.hStdOutput = gethandle(startup_info, "hStdOutput");
	si.hStdError = gethandle(startup_info, "hStdError");

	if (PyErr_Occurred())
		return NULL;

	if (env_mapping == Py_None)
		environment = NULL;
	else {
		environment = getenvironment(env_mapping);
		if (! environment)
			return NULL;
	}

	Py_BEGIN_ALLOW_THREADS
	result = CreateProcess(application_name,
			       command_line,
			       NULL,
			       NULL,
			       inherit_handles,
			       creation_flags,
			       environment ? PyString_AS_STRING(environment) : NULL,
			       current_directory,
			       &si,
			       &pi);
	Py_END_ALLOW_THREADS

	Py_XDECREF(environment);

	if (! result)
		return PyErr_SetFromWindowsErr(GetLastError());

	return Py_BuildValue("NNii",
			     sp_handle_new(pi.hProcess),
			     sp_handle_new(pi.hThread),
			     pi.dwProcessId,
			     pi.dwThreadId);
}
Beispiel #9
0
void readcommands(int argc, char **argv) 

{
  int i ;
  phandle *ph ;
  int t ;

  while ((i = getopt (argc, argv, "p:vV")) != -1) {

    switch (i)
      {

      case 'p':
	parname = strdup(optarg) ;
	break;

      case 'v':
	printf("version: %s\n", WVERSION) ; 
	break; 

      case 'V':
	verbose = YES ;
	break; 

      case '?':
	printf ("Usage: bad params.... \n") ;
	fatalx("bad params\n") ;
      }
  }

         
   if (parname==NULL) { 
    fprintf(stderr, "no parameters\n") ;
    return ;
   }

   pcheck(parname,'p') ;
   printf("parameter file: %s\n", parname) ;
   ph = openpars(parname) ;
   dostrsub(ph) ;

   getstring(ph, "genotypename:", &genotypename) ;
   getstring(ph, "snpname:", &snpname) ;
   getstring(ph, "indivname:", &indivname) ;
   getstring(ph, "poplistname:", &poplistname) ;
   getstring(ph, "snpeigname:", &snpeigname) ;
   getstring(ph, "snpweightoutname:", &snpeigname) ; /* changed 09/18/07 */
   getstring(ph, "output:", &outputname) ;
   getstring(ph, "outputvecs:", &outputname) ;
   getstring(ph, "evecoutname:", &outputname) ; /* changed 11/02/06 */
   getstring(ph, "outputvals:", &outputvname) ;
   getstring(ph, "evaloutname:", &outputvname) ; /* changed 11/02/06 */
   getstring(ph, "badsnpname:", &badsnpname) ;
   getstring(ph, "outliername:", &outliername) ;
   getstring(ph, "outlieroutname:", &outliername) ; /* changed 11/02/06 */
   getstring(ph, "phylipname:", &phylipname) ;
   getstring(ph, "phylipoutname:", &phylipname) ; /* changed 11/02/06 */
   getstring(ph, "weightname:", &weightname) ;
   getstring(ph, "fstdetailsname:", &fstdetailsname) ;
   getdbl(ph, "relthresh:",  &relthresh) ;
   getint(ph, "numeigs:", &numeigs) ;
   getint(ph, "numoutevec:", &numeigs) ; /* changed 11/02/06 */
   getint(ph, "markerscore:", &markerscore) ; 
   getint(ph, "chisqmode:", &chisqmode) ; 
   getint(ph, "missingmode:", &missingmode) ; 
   getint(ph, "fancynorm:", &fancynorm) ; 
   getint(ph, "usenorm:", &fancynorm) ;  /* changed 11/02/06 */
   getint(ph, "dotpopsmode:", &dotpopsmode) ; 
   getint(ph, "pcorrmode:", &pcorrmode) ;  /* print correlations */
   getint(ph, "pcpopsonly:", &pcpopsonly) ;  /* but only within population */
   getint(ph, "altnormstyle:", &altnormstyle) ;  
   getint(ph, "hashcheck:", &hashcheck) ;
   getint(ph, "popgenmode:", &altnormstyle) ;  
   getint(ph, "noxdata:", &noxdata) ; 
   t = -1 ;        
   getint(ph, "xdata:", &t) ; if (t>=0) noxdata = 1-t ;
   getint(ph, "nostatslim:", &nostatslim) ; 
   getint(ph, "popsizelimit:", &popsizelimit) ; 
   getint(ph, "minallelecnt:", &minallelecnt) ; 
   getint(ph, "chrom:", &xchrom) ;  
   getint(ph, "lopos:", &lopos) ;  
   getint(ph, "hipos:", &hipos) ;  
   getint(ph, "checksizemode:", &checksizemode) ;  
   getint(ph, "pubmean:", &pubmean) ;
   getint(ph, "fstonly:", &fstonly) ;
   getint(ph, "fsthiprecision:", &fsthiprec) ;

   getint(ph, "ldregress:", &ldregress) ;
   getint(ph, "nsnpldregress:", &ldregress) ; /* changed 11/02/06 */
   getdbl(ph, "ldlimit:", &ldlimit) ;  /* in morgans */
   getdbl(ph, "maxdistldregress:", &ldlimit) ;  /* in morgans */ /* changed 11/02/06 */
   getint(ph, "minleneig:", &nostatslim) ;
   getint(ph, "malexhet:", &malexhet) ;
   getint(ph, "nomalexhet:", &malexhet) ; /* changed 11/02/06 */
   getint(ph, "familynames:", &familynames) ;

   getint(ph, "numoutliter:", &numoutliter) ;
   getint(ph, "numoutlieriter:", &numoutliter) ; /* changed 11/02/06 */
   getint(ph, "numoutleigs", &numoutleigs) ;
   getint(ph, "numoutlierevec:", &numoutleigs) ; /* changed 11/02/06 */
   getdbl(ph, "outlthresh:", &outlthresh) ;
   getdbl(ph, "outliersigmathresh:", &outlthresh) ; /* changed 11/02/06 */
   getdbl(ph, "blgsize:", &blgsize) ; 

   getstring(ph, "indoutfilename:", &indoutfilename) ;
   getstring(ph, "indivoutname:", &indoutfilename) ; /* changed 11/02/06 */
   getstring(ph, "snpoutfilename:", &snpoutfilename) ;
   getstring(ph, "snpoutname:", &snpoutfilename) ; /* changed 11/02/06 */
   getstring(ph, "genooutfilename:", &genooutfilename) ;
   getstring(ph, "genotypeoutname:", &genooutfilename) ; /* changed 11/02/06 */
   getstring(ph, "outputformat:", &omode) ;
   getstring(ph, "outputmode:", &omode) ;
   getint(ph, "outputgroup:", &ogmode) ;
   getint(ph, "packout:", &packout) ; /* now obsolete 11/02/06 */
   getstring(ph, "twxtabname:", &twxtabname) ;

   getdbl(ph, "r2thresh:", &r2thresh) ;
   getdbl(ph, "r2genlim:", &r2genlim) ;
   getdbl(ph, "r2physlim:", &r2physlim) ;
   getint(ph, "killr2:",  &killr2) ;
   getint(ph, "numchrom:",  &numchrom) ;

   printf("### THE INPUT PARAMETERS\n");
   printf("##PARAMETER NAME: VALUE\n");
   writepars(ph);

}
Beispiel #10
0
int main(int argc, char *argv[]) {
  unsigned i, narg;
  unsigned sym_stdout = 0;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s <random-seed> <argument-types>\n", argv[0]);
    fprintf(stderr, "       If <random-seed> is 0, time(NULL)*getpid() is used as a seed\n");
    fprintf(stderr, "       <argument-types> are the ones accepted by KLEE: --sym-args, --sym-files etc.\n");
    fprintf(stderr, "   Ex: %s 100 --sym-args 0 2 2 --sym-files 1 8\n", argv[0]);
    exit(1);
  }

  unsigned seed = atoi(argv[1]);
  if (seed)
    srandom(seed);
  else srandom(time(NULL) * getpid());

  KTest b;
  b.numArgs = argc;
  b.args = argv;
  b.symArgvs = 0;
  b.symArgvLen = 0;

  b.numObjects = 0;
  b.objects = (KTestObject *)malloc(MAX * sizeof *b.objects);

  for(i = 2; i < (unsigned)argc; i++) {
    if(strcmp(argv[i], "--sym-args") == 0) {
      unsigned lb = getint(argv[++i]);
      unsigned ub = getint(argv[++i]);
      unsigned nbytes = getint(argv[++i]);

      narg = random() % (ub - lb) + lb;
      push_range(&b, "range", narg);

      while(narg-- > 0) {
        unsigned x = random() % (nbytes + 1);

        // A little different than how klee does it but more natural
        // for random.
        static int total_args;
        char arg[1024];

        sprintf(arg, "arg%d", total_args++);
        push_obj(&b, arg, x, nbytes+1);
      }
    } else if(strcmp(argv[i], "--sym-stdout") == 0) {
      if(!sym_stdout) {
        sym_stdout = 1;
        push_obj(&b, "stdout", 1024, 1024);
        push_obj(&b, "stdout-stat", sizeof(struct stat64), 
                 sizeof(struct stat64));
      }
    } else if(strcmp(argv[i], "--sym-files") == 0) {
      unsigned nfiles = getint(argv[++i]);
      unsigned nbytes = getint(argv[++i]);

      while(nfiles-- > 0) {
        push_obj(&b, "file", nbytes, nbytes);
        push_obj(&b, "file-stat", sizeof(struct stat64), sizeof(struct stat64));
      }

      push_obj(&b, "stdin", nbytes, nbytes);
      push_obj(&b, "stdin-stat", sizeof(struct stat64), sizeof(struct stat64));
    } else {
      fprintf(stderr, "unexpected option <%s>\n", argv[i]);
      assert(0);
    }
  }

  if (!kTest_toFile(&b, "file.bout"))
    assert(0);
  return 0;
}
Beispiel #11
0
void readcommands(int argc, char **argv) 

{
  int i,haploid=0;
  phandle *ph ;
  char str[5000]  ;
  char *tempname ;
  int n, t ;

  while ((i = getopt (argc, argv, "f:b:p:g:s:o:vVx")) != -1) {

    switch (i)
      {

      case 'p':
	parname = strdup(optarg) ;
	break;

      case 'f':
	snpdetailsname = strdup(optarg) ;
	break;

      case 'g':
	graphname = strdup(optarg) ;
	break;

      case 'o':
	graphoutname = strdup(optarg) ;
	break;

      case 's':
	seed = atoi(optarg) ;
	break;

      case 'b':
	baseval = atof(optarg) ;
	break;

      case 'v':
	printf("version: %s\n", WVERSION) ; 
	break; 

      case 'x':
	doanalysis = NO ; 
	break; 

      case 'V':
	verbose = YES ;
	break; 

      case '?':
	printf ("Usage: bad params.... \n") ;
	fatalx("bad params\n") ;
      }
  }

         
   if (parname==NULL) { 
    fprintf(stderr, "no parameters\n") ;
    return ;
   }

   pcheck(parname,'p') ;
   printf("parameter file: %s\n", parname) ;
   ph = openpars(parname) ;
   dostrsub(ph) ;

   getstring(ph, "genotypename:", &genotypename) ;
   getstring(ph, "snpname:", &snpname) ;
   getstring(ph, "indivname:", &indivname) ;
   getstring(ph, "graphname:", &graphname) ;
   getstring(ph, "graphoutname:", &graphoutname) ;
  int numeg = 4 ;
   getstring(ph, "snpdetailsname:", &snpdetailsname) ;
   getstring(ph, "outpop:", &outpop) ;
   getstring(ph, "output:", &outputname) ;
   getstring(ph, "badsnpname:", &badsnpname) ;
   getstring(ph, "popfilename:", &popfilename) ;
   getstring(ph, "f3log:", &f3name) ;
   getstring(ph, "root:", &rootname) ;
   getdbl(ph, "blgsize:", &blgsize) ;
   getdbl(ph, "diag:", &diag) ;
   getdbl(ph, "f2diag:", &f2diag) ;
   getdbl(ph, "minvar:", &minvar) ;
   getint(ph, "bigiter:", &bigiter) ;
   getint(ph, "inbreed:", &inbreed) ;
   getint(ph, "startiter:", &startiter) ;
   getint(ph, "fancynorm:", &fancynorm) ;

   getint(ph, "noxdata:", &noxdata) ; 
   t = -1 ;
   getint(ph, "xdata:", &t) ; if (t>=0) noxdata = 1-t ;
   getint(ph, "chrom:", &xchrom) ;
   getint(ph, "nochrom:", &zchrom) ;
   getint(ph, "doanalysis:", &doanalysis) ; 
   getint(ph, "quartet:", &quartet) ; 

   getint(ph, "nostatslim:", &nostatslim) ; 
   getint(ph, "popsizelimit:", &popsizelimit) ; 
   getint(ph, "gfromp:", &gfromp) ;  // gen dis from phys
   getint(ph, "seed:", &seed) ;  
   getint(ph, "details:", &details) ;  
   getint(ph, "forcezmode:", &forcezmode) ;  
   getint(ph, "dzeromode:", &dzeromode) ;  
   getdbl(ph, "baseval:", &baseval) ;  
   getdbl(ph, "jackquart:", &jackquart) ; 
   getint(ph, "jackweight:", &jackweight) ;
   getint(ph, "pubjack:", &pubjack) ;
   getstring(ph, "dumpname:", &dumpname) ;
   getstring(ph, "loadname:", &loadname) ;

   printf("### THE INPUT PARAMETERS\n");
   printf("##PARAMETER NAME: VALUE\n");
   writepars(ph);

}
Beispiel #12
0
/*
 * Process keyboard input during the main loop
 */
void do_key(char c)
{
    int numinput, i;
    char rcfile[MAXNAMELEN];
    FILE *fp;

    /*
     * First the commands which don't require a terminal mode switch.
     */
    if (c == 'q')
	sig_end(0);
    else if (c == ' ')
        return;
    else if (c == 12) {
	clear_screen();
	return;
    } else if (c == 'I') {
	Irixmode=(Irixmode) ? 0 : 1;
	return;
    }

    /*
     * Switch the terminal to normal mode.  (Will the original
     * attributes always be normal?  Does it matter?  I suppose the
     * shell will be set up the way the user wants it.)
     */
    if (!Batch) tcsetattr(0, TCSANOW, &Savetty);

    /*
     * Handle the rest of the commands.
     */
    switch (c) {
      case '?':
      case 'h':
	PUTP(cl); PUTP(ho); putchar('\n'); PUTP(mr);
	printf("Proc-Top Revision 1.2");
	PUTP(me); putchar('\n');
	printf("Secure mode ");
	PUTP(md);
	fputs(Secure ? "on" : "off", stdout);
	PUTP(me);
	fputs("; cumulative mode ", stdout);
	PUTP(md);
	fputs(Cumulative ? "on" : "off", stdout);
	PUTP(me);
	fputs("; noidle mode ", stdout);
	PUTP(md);
	fputs(Noidle ? "on" : "off", stdout);
	PUTP(me);
	fputs("\n\n", stdout);
	printf("%s\n\nPress any key to continue", Secure ? SECURE_HELP_SCREEN : HELP_SCREEN);
	if (!Batch) tcsetattr(0, TCSANOW, &Rawtty);
	(void) getchar();
	break;
      case 'i':
	Noidle = !Noidle;
	SHOWMESSAGE(("No-idle mode %s", Noidle ? "on" : "off"));
	break;
      case 'u':
	SHOWMESSAGE(("Which User (Blank for All): "));
	strcpy(CurrUser,getstr());
	break;
      case 'k':
	if (Secure)
	    SHOWMESSAGE(("\aCan't kill in secure mode"));
	else {
	    int pid, signal;
	    PUTP(md);
	    SHOWMESSAGE(("PID to kill: "));
	    pid = getint();
	    if (pid == BAD_INPUT)
		break;
	    PUTP(top_clrtoeol);
	    SHOWMESSAGE(("Kill PID %d with signal [15]: ", pid));
	    PUTP(me);
	    signal = getsig();
	    if (signal == -1)
		signal = SIGTERM;
	    if (kill(pid, signal))
		SHOWMESSAGE(("\aKill of PID %d with %d failed: %s",
			     pid, signal, strerror(errno)));
	}
	break;
      case 'l':
	SHOWMESSAGE(("Display load average %s", !show_loadav ? "on" : "off"));
	if (show_loadav) {
	    show_loadav = 0;
	    header_lines--;
	} else {
	    show_loadav = 1;
	    header_lines++;
	}
	Numfields = make_header();
	break;
      case 'm':
	SHOWMESSAGE(("Display memory information %s", !show_memory ? "on" : "off"));
	if (show_memory) {
	    show_memory = 0;
	    header_lines -= 2;
	} else {
	    show_memory = 1;
	    header_lines += 2;
	}
	Numfields = make_header();
	break;
      case 'M':
        SHOWMESSAGE(("Sort by memory usage"));
	sort_type = S_MEM;
	reset_sort_options();
	register_sort_function(-1, (cmp_t)mem_sort);
	break;
      case 'n':
      case '#':
	printf("Processes to display (0 for unlimited): ");
	numinput = getint();
	if (numinput != BAD_INPUT) {
	    Display_procs = numinput;
	    window_size(0);
	}
	break;
      case 'r':
	if (Secure)
	    SHOWMESSAGE(("\aCan't renice in secure mode"));
	else {
	    int pid, val;

	    printf("PID to renice: ");
	    pid = getint();
	    if (pid == BAD_INPUT)
		break;
	    PUTP(tgoto(cm, 0, header_lines - 2));
	    PUTP(top_clrtoeol);
	    printf("Renice PID %d to value: ", pid);
	    val = getint();
	    if (val == BAD_INPUT)
		val = 10;
	    if (setpriority(PRIO_PROCESS, pid, val))
		SHOWMESSAGE(("\aRenice of PID %d to %d failed: %s",
			     pid, val, strerror(errno)));
	}
	break;
      case 'P':
        SHOWMESSAGE(("Sort by CPU usage"));
	sort_type = S_PCPU;
	reset_sort_options();
	register_sort_function(-1, (cmp_t)pcpu_sort);
	break;
      case 'A':
	SHOWMESSAGE(("Sort by age"));
	sort_type = S_AGE;
	reset_sort_options();
	register_sort_function(-1, (cmp_t)age_sort);
	break;
      case 'N':
	SHOWMESSAGE(("Sort numerically by pid"));
	sort_type = S_NONE;
	reset_sort_options();
	break;
    case 'c':
        show_cmd = !show_cmd;
	SHOWMESSAGE(("Show %s", show_cmd ? "command names" : "command line"));
	break;
      case 'S':
	Cumulative = !Cumulative;
	SHOWMESSAGE(("Cumulative mode %s", Cumulative ? "on" : "off"));
	if (Cumulative)
	    headers[22][1] = 'C';
	else
	    headers[22][1] = ' ';
	Numfields = make_header();
	break;
      case 's':
	if (Secure)
	    SHOWMESSAGE(("\aCan't change delay in secure mode"));
	else {
	    double tmp;
	    printf("Delay between updates: ");
	    tmp = getfloat();
	    if (!(tmp < 0))
		Sleeptime = tmp;
	}
	break;
      case 't':
	SHOWMESSAGE(("Display summary information %s", !show_stats ? "on" : "off"));
	if (show_stats) {
	    show_stats = 0;
	    header_lines -= 2;
	} else {
	    show_stats = 1;
	    header_lines += 2;
	}
	Numfields = make_header();
	break;
      case 'T':
	SHOWMESSAGE(("Sort by %stime", Cumulative ? "cumulative " : ""));
	sort_type = S_TIME;
	reset_sort_options();
	register_sort_function( -1, (cmp_t)time_sort);	
	break;
      case 'f':
      case 'F':
	change_fields();
	break;
      case 'o':
      case 'O':
	change_order();
	break;
      case 'W':
	if (getenv("HOME")) {
	    strcpy(rcfile, getenv("HOME"));
	    strcat(rcfile, "/");
	    strcat(rcfile, RCFILE);
	    fp = fopen(rcfile, "w");
	    if (fp != NULL) {
		fprintf(fp, "%s\n", Fields);
		i = (int) Sleeptime;
		if (i < 2)
		    i = 2;
		if (i > 9)
		    i = 9;
		fprintf(fp, "%d", i);
		if (Secure)
		    fprintf(fp, "%c", 's');
		if (Cumulative)
		    fprintf(fp, "%c", 'S');
		if (!show_cmd)
		    fprintf(fp, "%c", 'c');
		if (Noidle)
		    fprintf(fp, "%c", 'i');
		if (!show_memory)
		    fprintf(fp, "%c", 'm');
		if (!show_loadav)
		    fprintf(fp, "%c", 'l');
		if (!show_stats)
		    fprintf(fp, "%c", 't');
		if (!Irixmode)
		    fprintf(fp, "%c", 'I');
		fprintf(fp, "\n");
		fclose(fp);
		SHOWMESSAGE(("Wrote configuration to %s", rcfile));
	    } else {
		SHOWMESSAGE(("Couldn't open %s", rcfile));
	    }
	} else {
	    SHOWMESSAGE(("Couldn't get $HOME -- not saving"));
	}
	break;
      default:
	SHOWMESSAGE(("\aUnknown command `%c' -- hit `h' for help", c));
    }

    /*
     * Return to raw mode.
     */
    if (!Batch) tcsetattr(0, TCSANOW, &Rawtty);
    return;
}
Beispiel #13
0
VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value)
{
	char		*p, *s=0;
	const char	*cp, *cs;
	int		x;
	size_t		length;
	DICT_VALUE	*dval;

	if (!value) return NULL;

	/*
	 *	Even for integers, dates and ip addresses we
	 *	keep the original string in vp->vp_strvalue.
	 */
	if (vp->type != PW_TYPE_TLV) {
		strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
		vp->length = strlen(vp->vp_strvalue);
	}

	switch(vp->type) {
		case PW_TYPE_STRING:
			/*
			 *	Do escaping here
			 */
			p = vp->vp_strvalue;
			cp = value;
			length = 0;

			while (*cp && (length < (sizeof(vp->vp_strvalue) - 1))) {
				char c = *cp++;

				if (c == '\\') {
					switch (*cp) {
					case 'r':
						c = '\r';
						cp++;
						break;
					case 'n':
						c = '\n';
						cp++;
						break;
					case 't':
						c = '\t';
						cp++;
						break;
					case '"':
						c = '"';
						cp++;
						break;
					case '\'':
						c = '\'';
						cp++;
						break;
					case '\\':
						c = '\\';
						cp++;
						break;
					case '`':
						c = '`';
						cp++;
						break;
					case '\0':
						c = '\\'; /* no cp++ */
						break;
					default:
						if ((cp[0] >= '0') &&
						    (cp[0] <= '9') &&
						    (cp[1] >= '0') &&
						    (cp[1] <= '9') &&
						    (cp[2] >= '0') &&
						    (cp[2] <= '9') &&
						    (sscanf(cp, "%3o", &x) == 1)) {
							c = x;
							cp += 3;
						} /* else just do '\\' */
					}
				}
				*p++ = c;
				length++;
			}
			vp->vp_strvalue[length] = '\0';
			vp->length = length;
			break;

		case PW_TYPE_IPADDR:
			/*
			 *	It's a comparison, not a real IP.
			 */
			if ((vp->operator == T_OP_REG_EQ) ||
			    (vp->operator == T_OP_REG_NE)) {
				break;
			}

			/*
			 *	FIXME: complain if hostname
			 *	cannot be resolved, or resolve later!
			 */
			s = NULL;
			if ((p = strrchr(value, '+')) != NULL && !p[1]) {
				cs = s = strdup(value);
				if (!s) return NULL;
				p = strrchr(s, '+');
				*p = 0;
				vp->flags.addport = 1;
			} else {
				p = NULL;
				cs = value;
			}

			{
				fr_ipaddr_t ipaddr;

				if (ip_hton(cs, AF_INET, &ipaddr) < 0) {
					fr_strerror_printf("Failed to find IP address for %s", cs);
					free(s);
					return NULL;
				}

				vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
			}
			free(s);
			vp->length = 4;
			break;

		case PW_TYPE_BYTE:
			vp->length = 1;

			/*
			 *	Note that ALL integers are unsigned!
			 */
			vp->vp_integer = getint(value, &p);
			if (!*p) {
				if (vp->vp_integer > 255) {
					fr_strerror_printf("Byte value \"%s\" is larger than 255", value);
					return NULL;
				}
				break;
			}
			if (check_for_whitespace(p)) break;
			goto check_for_value;

		case PW_TYPE_SHORT:
			/*
			 *	Note that ALL integers are unsigned!
			 */
			vp->vp_integer = getint(value, &p);
			vp->length = 2;
			if (!*p) {
				if (vp->vp_integer > 65535) {
					fr_strerror_printf("Byte value \"%s\" is larger than 65535", value);
					return NULL;
				}
				break;
			}
			if (check_for_whitespace(p)) break;
			goto check_for_value;

		case PW_TYPE_INTEGER:
			/*
			 *	Note that ALL integers are unsigned!
			 */
			vp->vp_integer = getint(value, &p);
			vp->length = 4;
			if (!*p) break;
			if (check_for_whitespace(p)) break;

	check_for_value:
			/*
			 *	Look for the named value for the given
			 *	attribute.
			 */
			if ((dval = dict_valbyname(vp->attribute, value)) == NULL) {
				fr_strerror_printf("Unknown value %s for attribute %s",
					   value, vp->name);
				return NULL;
			}
			vp->vp_integer = dval->value;
			break;

		case PW_TYPE_DATE:
		  	{
				/*
				 *	time_t may be 64 bits, whule vp_date
				 *	MUST be 32-bits.  We need an
				 *	intermediary variable to handle
				 *	the conversions.
				 */
				time_t date;

				if (gettime(value, &date) < 0) {
					fr_strerror_printf("failed to parse time string "
						   "\"%s\"", value);
					return NULL;
				}

				vp->vp_date = date;
			}
			vp->length = 4;
			break;

		case PW_TYPE_ABINARY:
#ifdef ASCEND_BINARY
			if (strncasecmp(value, "0x", 2) == 0) {
				vp->type = PW_TYPE_OCTETS;
				goto do_octets;
			}

		  	if (ascend_parse_filter(vp) < 0 ) {
				char buffer[256];

				snprintf(buffer, sizeof(buffer), "failed to parse Ascend binary attribute: %s", fr_strerror());
				fr_strerror_printf("%s", buffer);
				return NULL;
			}
			break;

			/*
			 *	If Ascend binary is NOT defined,
			 *	then fall through to raw octets, so that
			 *	the user can at least make them by hand...
			 */
	do_octets:
#endif
			/* raw octets: 0x01020304... */
		case PW_TYPE_OCTETS:
			if (strncasecmp(value, "0x", 2) == 0) {
				uint8_t *us;
				cp = value + 2;
				us = vp->vp_octets;
				vp->length = 0;


				/*
				 *	There is only one character,
				 *	die.
				 */
				if ((strlen(cp) & 0x01) != 0) {
					fr_strerror_printf("Hex string is not an even length string.");
					return NULL;
				}


				while (*cp &&
				       (vp->length < MAX_STRING_LEN)) {
					unsigned int tmp;

					if (sscanf(cp, "%02x", &tmp) != 1) {
						fr_strerror_printf("Non-hex characters at %c%c", cp[0], cp[1]);
						return NULL;
					}

					cp += 2;
					*(us++) = tmp;
					vp->length++;
				}
			}
			break;

		case PW_TYPE_IFID:
			if (ifid_aton(value, (void *) &vp->vp_ifid) == NULL) {
				fr_strerror_printf("failed to parse interface-id "
					   "string \"%s\"", value);
				return NULL;
			}
			vp->length = 8;
			break;

		case PW_TYPE_IPV6ADDR:
			{
				fr_ipaddr_t ipaddr;

				if (ip_hton(value, AF_INET6, &ipaddr) < 0) {
					char buffer[1024];

					strlcpy(buffer, fr_strerror(), sizeof(buffer));

					fr_strerror_printf("failed to parse IPv6 address "
                                                           "string \"%s\": %s", value, buffer);
					return NULL;
				}
				vp->vp_ipv6addr = ipaddr.ipaddr.ip6addr;
				vp->length = 16; /* length of IPv6 address */
			}
			break;

		case PW_TYPE_IPV6PREFIX:
			p = strchr(value, '/');
			if (!p || ((p - value) >= 256)) {
				fr_strerror_printf("invalid IPv6 prefix "
					   "string \"%s\"", value);
				return NULL;
			} else {
				unsigned int prefix;
				char buffer[256], *eptr;

				memcpy(buffer, value, p - value);
				buffer[p - value] = '\0';

				if (inet_pton(AF_INET6, buffer, vp->vp_octets + 2) <= 0) {
					fr_strerror_printf("failed to parse IPv6 address "
						   "string \"%s\"", value);
					return NULL;
				}

				prefix = strtoul(p + 1, &eptr, 10);
				if ((prefix > 128) || *eptr) {
					fr_strerror_printf("failed to parse IPv6 address "
						   "string \"%s\"", value);
					return NULL;
				}
				vp->vp_octets[1] = prefix;
			}
			vp->vp_octets[0] = '\0';
			vp->length = 16 + 2;
			break;

		case PW_TYPE_ETHERNET:
			{
				const char *c1, *c2;

				length = 0;
				cp = value;
				while (*cp) {
					if (cp[1] == ':') {
						c1 = hextab;
						c2 = memchr(hextab, tolower((int) cp[0]), 16);
						cp += 2;
					} else if ((cp[1] != '\0') &&
						   ((cp[2] == ':') ||
						    (cp[2] == '\0'))) {
						   c1 = memchr(hextab, tolower((int) cp[0]), 16);
						   c2 = memchr(hextab, tolower((int) cp[1]), 16);
						   cp += 2;
						   if (*cp == ':') cp++;
					} else {
						c1 = c2 = NULL;
					}
					if (!c1 || !c2 || (length >= sizeof(vp->vp_ether))) {
						fr_strerror_printf("failed to parse Ethernet address \"%s\"", value);
						return NULL;
					}
					vp->vp_ether[length] = ((c1-hextab)<<4) + (c2-hextab);
					length++;
				}
			}
			vp->length = 6;
			break;

		case PW_TYPE_COMBO_IP:
			if (inet_pton(AF_INET6, value, vp->vp_strvalue) > 0) {
				vp->type = PW_TYPE_IPV6ADDR;
				vp->length = 16; /* length of IPv6 address */
				vp->vp_strvalue[vp->length] = '\0';

			} else {
				fr_ipaddr_t ipaddr;

				if (ip_hton(value, AF_INET, &ipaddr) < 0) {
					fr_strerror_printf("Failed to find IPv4 address for %s", value);
					return NULL;
				}

				vp->type = PW_TYPE_IPADDR;
				vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
				vp->length = 4;
			}
			break;

		case PW_TYPE_SIGNED: /* Damned code for 1 WiMAX attribute */
			vp->vp_signed = (int32_t) strtol(value, &p, 10);
			vp->length = 4;
			break;

		case PW_TYPE_TLV: /* don't use this! */
			if (strncasecmp(value, "0x", 2) != 0) {
				fr_strerror_printf("Invalid TLV specification");
				return NULL;
			}
			length = strlen(value + 2) / 2;
			if (vp->length < length) {
				free(vp->vp_tlv);
				vp->vp_tlv = NULL;
			}
			vp->vp_tlv = malloc(length);
			if (!vp->vp_tlv) {
				fr_strerror_printf("No memory");
				return NULL;
			}
			if (fr_hex2bin(value + 2, vp->vp_tlv,
				       length) != length) {
				fr_strerror_printf("Invalid hex data in TLV");
				return NULL;
			}
			vp->length = length;
			break;

			/*
			 *  Anything else.
			 */
		default:
			fr_strerror_printf("unknown attribute type %d", vp->type);
			return NULL;
	}

	return vp;
}
Beispiel #14
0
// UpDownWndProc:
//
LRESULT CALLBACK UpDownWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    RECT rc;
    int i;
    PUDSTATE np = (PUDSTATE)GetWindowInt(hwnd, 0);

    if (np) {
        if ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST) &&
            (np->ci.style & UDS_HOTTRACK) && !np->fTrackSet) {

            TRACKMOUSEEVENT tme;

            np->fTrackSet = TRUE;

            tme.cbSize = sizeof(tme);
            tme.hwndTrack = np->ci.hwnd;
            tme.dwFlags = TME_LEAVE;

            TrackMouseEvent(&tme);
        }
    }

    switch (uMsg)
    {

    case WM_MOUSEMOVE:
        UD_OnMouseMove(np, lParam);
        break;

    case WM_MOUSELEAVE:
        np->fTrackSet = FALSE;
        UD_Invalidate(np, np->uHot, FALSE);
        np->uHot = UD_HITNOWHERE;
        break;

    case WM_LBUTTONDOWN:
    {
        // Don't set a timer if on the middle border
        BOOL bTimeIt = TRUE;

        if (np->hwndBuddy && !IsWindowEnabled(np->hwndBuddy))
            break;

        SetCapture(hwnd);
        getint(np);

        switch (np->uClass)
        {
        case CLASS_EDIT:
        case CLASS_LISTBOX:
            SetFocus(np->hwndBuddy);
            break;
        }

        switch(UD_HitTest(np, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
        case UD_HITDOWN:
            np->bDown = TRUE;
            squish(np, FALSE, TRUE);
            break;

        case UD_HITUP:
            np->bDown = FALSE;
            squish(np, TRUE, FALSE);
            break;

        case UD_HITNOWHERE:
            bTimeIt = FALSE;
            break;
        }

        if (bTimeIt)
        {
            SetTimer(hwnd, 1, GetProfileInt(TEXT("windows"), TEXT("CursorBlinkRate"), 530), NULL);
            bump(np);
        }
        break;
    }

    case WM_TIMER:
    {
        POINT pt;

        if (GetCapture() != hwnd)
        {
            goto EndScroll;
        }

        SetTimer(hwnd, 1, 100, NULL);

        GetWindowRect(hwnd, &rc);
        if (np->ci.style & UDS_HORZ) {
            i = (rc.left + rc.right) / 2;
            if (np->bDown)
            {
                rc.right = i;
            }
            else
            {
                rc.left = i;
            }
        } else {
            i = (rc.top + rc.bottom) / 2;
            if (np->bDown)
            {
                rc.top = i;
            }
            else
            {
                rc.bottom = i;
            }
        }
        InflateRect(&rc, (g_cxFrame+1)/2, (g_cyFrame+1)/2);
        GetCursorPos(&pt);
        if (PtInRect(&rc, pt))
        {
            squish(np, !np->bDown, np->bDown);
            bump(np);
        }
        else
        {
            squish(np, FALSE, FALSE);
        }
        break;
    }

    case WM_LBUTTONUP:
        if (np->hwndBuddy && !IsWindowEnabled(np->hwndBuddy))
            break;

        if (GetCapture() == hwnd)
        {
EndScroll:
            squish(np, FALSE, FALSE);
            ReleaseCapture();
            KillTimer(hwnd, 1);

            if (np->uClass == CLASS_EDIT)
                Edit_SetSel(np->hwndBuddy, 0, -1);

                        if (np->ci.style & UDS_HORZ)
                            FORWARD_WM_HSCROLL(np->ci.hwndParent, np->ci.hwnd,
                                      SB_ENDSCROLL, np->nPos, SendMessage);
                        else
                            FORWARD_WM_VSCROLL(np->ci.hwndParent, np->ci.hwnd,
                                      SB_ENDSCROLL, np->nPos, SendMessage);
        }
        break;

    case WM_ENABLE:
        InvalidateRect(hwnd, NULL, TRUE);
        break;

    case WM_WININICHANGE:
        if (np && (!wParam ||
            (wParam == SPI_SETNONCLIENTMETRICS) ||
            (wParam == SPI_SETICONTITLELOGFONT))) {
            InitGlobalMetrics(wParam);
            unachor(np);
            anchor(np);
        }
        break;

    case WM_PRINTCLIENT:
    case WM_PAINT:
        PaintUpDownControl(np, (HDC)wParam);
        break;

    case UDM_SETRANGE:
        np->nUpper = GET_X_LPARAM(lParam);
        np->nLower = GET_Y_LPARAM(lParam);
        nudge(np);
        break;

    case UDM_GETRANGE:
        return MAKELONG(np->nUpper, np->nLower);

    case UDM_SETBASE:
        // wParam: new base
        // lParam: not used
        // return: 0 if invalid base is specified,
        //         previous base otherwise
        return (LRESULT)setbase(np, (UINT)wParam);

    case UDM_GETBASE:
        return np->nBase;

    case UDM_SETPOS:
    {
        int iNewPos = GET_X_LPARAM(lParam);
        if (compare(np, np->nLower, np->nUpper, DONTCARE) < 0) {

            if (compare(np, iNewPos, np->nUpper, DONTCARE) > 0) {
                iNewPos = np->nUpper;
            }

            if (compare(np, iNewPos, np->nLower, DONTCARE) < 0) {
                iNewPos = np->nLower;
            }
        } else {
            if (compare(np, iNewPos, np->nUpper, DONTCARE) < 0) {
                iNewPos = np->nUpper;
            }

            if (compare(np, iNewPos, np->nLower, DONTCARE) > 0) {
                iNewPos = np->nLower;
            }
        }

        i = np->nPos;
        np->nPos = iNewPos;
        setint(np);
#ifdef ACTIVE_ACCESSIBILITY
        MyNotifyWinEvent(EVENT_OBJECT_VALUECHANGE, np->ci.hwnd, OBJID_CLIENT, 0);
#endif
        return (LRESULT)i;
    }

    case UDM_GETPOS:
        return getint(np);

    case UDM_SETBUDDY:
        return setbuddy(np, (HWND)wParam);

    case UDM_GETBUDDY:
        return (LRESULT)(int)np->hwndBuddy;

    case UDM_SETACCEL:
            if (wParam == 0)
                return(FALSE);
            if (wParam >= NUM_UDACCELS)
            {
                HANDLE npPrev = (HANDLE)np;
                np = (PUDSTATE)LocalReAlloc((HLOCAL)np, sizeof(UDSTATE)+(wParam-NUM_UDACCELS)*sizeof(UDACCEL),
                    LMEM_MOVEABLE);
                if (!np)
                {
                    return(FALSE);
                }
                else
                {
                    SetWindowInt(hwnd, 0, (int)np);

                    if ((np->ci.style & UDS_ARROWKEYS) && np->hwndBuddy)
                    {
                        SetWindowSubclass(np->hwndBuddy, ArrowKeyProc, 0,
                            (DWORD)np);
                    }
                }
            }

            np->nAccel = wParam;
        for (i=0; i<(int)wParam; ++i)
        {
                np->udAccel[i] = ((LPUDACCEL)lParam)[i];
        }
        return(TRUE);

    case UDM_GETACCEL:
        if (wParam > np->nAccel)
        {
            wParam = np->nAccel;
        }
        for (i=0; i<(int)wParam; ++i)
        {
            ((LPUDACCEL)lParam)[i] = np->udAccel[i];
        }
        return(np->nAccel);

    case WM_NOTIFYFORMAT:
        return CIHandleNotifyFormat(&np->ci, lParam);

    case WM_CREATE:
        // Allocate the instance data space.
        np = (PUDSTATE)LocalAlloc(LPTR, sizeof(UDSTATE));
        if (!np)
            return -1;

        SetWindowInt(hwnd, 0, (int)np);

            #define lpCreate ((CREATESTRUCT FAR *)lParam)

        CIInitialize(&np->ci, hwnd, lpCreate);

        // np->fUp =
        // np->fDown =
            // np->fUnsigned =
            // np->fSharedBorder =
            // np->fSunkenBorder =
        //  FALSE;

        if (lpCreate->dwExStyle & WS_EX_CLIENTEDGE)
            np->fSunkenBorder = TRUE;

        np->nBase = BASE_DECIMAL;
        np->nUpper = 0;
        np->nLower = 100;
        np->nPos = 0;
        np->hwndBuddy = NULL;
        np->uClass = CLASS_UNKNOWN;

            np->nAccel = NUM_UDACCELS;
            np->udAccel[0].nSec = 0;
            np->udAccel[0].nInc = 1;
        np->udAccel[1].nSec = 2;
            np->udAccel[1].nInc = 5;
            np->udAccel[2].nSec = 5;
            np->udAccel[2].nInc = 20;

        /* This does the pickbuddy and anchor
         */
        setbuddy(np, NULL);
        setint(np);
        break;

    case WM_DESTROY:
        if (np) {
            if (np->hwndBuddy)
            {
                // Make sure that our buddy is unsubclassed.
                DebugMsg(DM_ERROR, TEXT("UpDown Destroyed while buddy subclassed"));
                np->fUpDownDestroyed = TRUE;
            }
            else
                LocalFree((HLOCAL)np);
            SetWindowInt(hwnd, 0, 0);
        }
        break;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0L;
}
Beispiel #15
0
int main(void) {
	int numero = getint("Introduce un numero en binario: ");
	printf("%d", sizeof(numero));
}
Beispiel #16
0
// Sets the caption of the buddy if appropriate.
//
void NEAR PASCAL setint(PUDSTATE np)
{
    static int cReenter = 0;

    TCHAR szInt[MAX_INTLENGTH];
    TCHAR szThousand[2];
    int pos = np->nPos;
    LPTSTR p = szInt;

    isgoodbuddy(np);
    if (np->hwndBuddy && np->ci.style & UDS_SETBUDDYINT)
    {
        /* If we have reentered, then maybe the app has set up a loop.
         * Check to see if the value really needs to be set.
         */
        if (cReenter && (LRESULT)pos==getint(np))
        {
            return;
        }
        np->nPos = pos;

        ++cReenter;

        if (np->uClass == CLASS_LISTBOX)
        {
            SendMessage(np->hwndBuddy, LB_SETCURSEL, pos, 0L);
            FORWARD_WM_COMMAND(GetParent(np->hwndBuddy),
                                GetDlgCtrlID(np->hwndBuddy),
                np->hwndBuddy, LBN_SELCHANGE, SendMessage);
        }
        else
        {
            switch (np->nBase)
            {
                case BASE_HEX:
                    wsprintf(p, TEXT("0x%04X"), pos);
                    break;

                case BASE_DECIMAL:
        default:
                    if (pos < 0)
                    {
                        *p++ = TEXT('-');
                        pos = -pos;
                    }

                    if (pos >= 1000 && !(np->ci.style & UDS_NOTHOUSANDS))
                    {
                        getthousands(szThousand);
                        p += wsprintf(p, TEXT("%d"), pos / 1000);
                        if (szThousand[0])
                            *p++ = szThousand[0];
                        wsprintf(p, TEXT("%03d"), pos % 1000);
                    }
                    else
                    {
                        wsprintf(p, TEXT("%d"), pos);
                    }
                    break;
            }

            SetWindowText(np->hwndBuddy, szInt);
        }

        --cReenter;
    }
}
Beispiel #17
0
LRESULT CALLBACK ArrowKeyProc(HWND hWnd, UINT uMsg, WPARAM wParam,
    LPARAM lParam, UINT uIdSubclass, DWORD dwRefData)
{
    PUDSTATE    np = (PUDSTATE)dwRefData;
    int         cDetants;

    switch (uMsg)
    {
    case WM_NCDESTROY:
        RemoveWindowSubclass(hWnd, ArrowKeyProc, 0);
        np->hwndBuddy = NULL;
        if (np->fUpDownDestroyed)
        {
            // The buddy was destroyed after updown so free the memory now
            // And pass off to the message to who we subclassed...
            LocalFree((HLOCAL)np);
        }
        break;

    case WM_GETDLGCODE:
        return (DefSubclassProc(hWnd, uMsg, wParam, lParam) | DLGC_WANTARROWS);

    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_UP:
        case VK_DOWN:
            if (GetCapture() != np->ci.hwnd)
            {
                /* Get the value from the buddy if this is the first key down
                 */
                if (!(lParam&(1L<<30)))
                {
                    getint(np);
                }

                /* Update the visuals and bump the value
                 */
                np->bDown = (wParam == VK_DOWN);
                squish(np, !np->bDown, np->bDown);
                bump(np);
            }
            return(0L);

        default:
            break;
        }
        break;

    case WM_KEYUP:
        switch (wParam)
        {
        case VK_UP:
        case VK_DOWN:
            if (GetCapture() != np->ci.hwnd)
            {
                squish(np, FALSE, FALSE);
            }
            return(0L);

        default:
            break;
        }
        break;

        // this is dumb.
        // wm_char's aren't sent for arrow commands..
        // what you're really eating here is & and (.
#if 0
    case WM_CHAR:
        switch (wParam)
        {
        case VK_UP:
        case VK_DOWN:
            return(0L);

        default:
            break;
        }
        break;
#endif

    case WM_KILLFOCUS:
        // Reset wheel scroll amount
        gcWheelDelta = 0;
        break;

    case WM_SETFOCUS:
        Assert(gcWheelDelta == 0);
        break;

    default:
        if (uMsg == g_msgMSWheel && GetCapture() != np->ci.hwnd) {

#if defined(WINNT) && defined(WM_MOUSEWHEEL)
            int iWheelDelta = (int)(short)HIWORD(wParam);
#else
            int iWheelDelta = (int)wParam;
#endif

            // Update count of scroll amount
            gcWheelDelta -= iWheelDelta;
            cDetants = gcWheelDelta / WHEEL_DELTA;

            if (cDetants != 0) {
                gcWheelDelta %= WHEEL_DELTA;

#if defined(WINNT) && defined(WM_MOUSEWHEEL)
                if (wParam & (MK_SHIFT | MK_CONTROL)) {
                    break;
                }
#else
                if (GetKeyState(VK_SHIFT) < 0 || GetKeyState(VK_CONTROL) < 0) {
                    break;
                }
#endif

                getint(np);
                np->bDown = (cDetants > 0);
                cDetants = abs(cDetants);
                while (cDetants-- > 0) {
                    squish(np, !np->bDown, np->bDown);
                    bump(np);
                }
                squish(np, FALSE, FALSE);
            }

            return 1;
        }

        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
void testPositionUpdater()
{
    for (int i = 0; i < 20000; i++)
    {
        // Create an entity with some random data

        fpsent d;

        d.clientnum = i;

        #define RANDCOORD ( float( (i % 2048*32) - rnd(2048*32) ) / 32.0f )
        d.o = vec(RANDCOORD, RANDCOORD, RANDCOORD);

        d.yaw = rnd(720);
        d.pitch = rnd(720) - 360;
        d.roll = rnd(720) - 360;

        #define RANDVELCOORD ( float( (i % 2048) - rnd(2048) ) / 128.0f )
        d.vel = vec(RANDVELCOORD, RANDVELCOORD, RANDVELCOORD);

        d.physstate = rnd(8);

        d.lifesequence = rnd(2);

        d.falling = vec(RANDVELCOORD, RANDVELCOORD, RANDVELCOORD);

        d.move = rnd(3) - 1;

        d.strafe = rnd(3) - 1;

        // Generate Info

        NetworkSystem::PositionUpdater::QuantizedInfo info;
        info.generateFrom(&d);

        // Extract from Info into an appropriate other entity

        fpsent d2;
        d2.clientnum = i;
        d2.lifesequence = d.lifesequence;

        info.applyToEntity(&d2);

        // Ensure the extracted info is equal to the original

        compareEntities("original to Info", d, d2);

        // Write out to a buffer

        int maxLength = 200; // TODO: Sync with production code
        unsigned char data[maxLength];
        ucharbuf q(data, maxLength);
        info.applyToBuffer(q);

        // Initialize the the buffer and read the protocol code, which should be SV_POS
        q.len = 0;
        assert(getint(q) == SV_POS);

        // Read into another Info, and apply to another entity

        NetworkSystem::PositionUpdater::QuantizedInfo info2;
        info2.generateFrom(q);

        // Ensure Infos are the same after reconstruction
        compareInfos(info, info2);

        fpsent d3;
        d3.clientnum = i;
        d3.lifesequence = d.lifesequence;

        info2.applyToEntity(&d3);

        // Ensure the extracted info is equal to the original

        compareEntities("original to network reconstruction", d, d3);
    }
}
/* Derefer a dynamic library. */
void ldlclose(avm* vm)
{
	void* handle = (void*)getint(vm, 0);
	if (handle) dlclose(handle);
}
Beispiel #20
0
preprocess() {
  int k;
  char c;
  if(ccode) {
    line = mline;
    ifline();
    if(eof) return;
    }
  else {
    in_line();
    return;
    }
  pptr = -1;
  while(ch != NEWLINE && ch) {
    if(white()) {
      keepch(' ');
      while(white()) gch();
      }
    else if(ch == '"') {
      keepch(ch);
      gch();
      while(ch != '"' || (*(lptr-1) == 92 && *(lptr-2) != 92)) {
        if(ch == NULL) {
          error("no quote");
          break;
          }
        keepch(gch());
        }
      gch();
      keepch('"');
      }
    else if(ch == 39) {
      keepch(39);
      gch();
      while(ch != 39 || (*(lptr-1) == 92 && *(lptr-2) != 92)) {
        if(ch == NULL) {
          error("no apostrophe");
          break;
          }
        keepch(gch());
        }
      gch();
      keepch(39);
      }
    else if(ch == '/' && nch == '*') {
      bump(2);
      while((ch == '*' && nch == '/') == 0) {
        if(ch) bump(1);
        else {
          ifline();
          if(eof) break;
          }
        }
      bump(2);
      }
    else if(an(ch)) {
      k = 0;
      while(an(ch) && k < NAMEMAX) {
        msname[k++] = ch;
        gch();
        }
      msname[k] = NULL;
      if(search(msname, macn, NAMESIZE+2, MACNEND, MACNBR, 0)) {
        k = getint(cptr+NAMESIZE, 2);
        while(c = macq[k++]) keepch(c);
        while(an(ch)) gch();
        }
      else {
        k = 0;
        while(c = msname[k++]) keepch(c);
        }
      }
    else keepch(gch());
    }
  if(pptr >= LINEMAX) error("line too long");
  keepch(NULL);
  line = pline;
  bump(0);
  }
Beispiel #21
0
/*
 * Преобразование даты в стандарт RFC 1036.
 */
char *rfcdate (char *ctim)
{
#define skip(p) while (*(p)==' ' || *(p)=='\t') ++(p)
	int wday, day, mon, year, h, m, s, tz;

	skip (ctim);
	if (ctim[3]==' ' && ctim[7]==' ' && ctim[10]==' ' &&
	    ctim[13]==':' && ctim[16]==':' && ctim[19]==' ' &&
	    (ctim[20]=='1' || ctim[20]=='2' || ctim[24]=='1' || ctim[24]=='2'))
		return (ctim2rfc (ctim, 0));

	/* [Wdy,] DD Mon YY HH:MM[:SS] TIMEZONE */

	if ((*ctim>='A' && *ctim<='Z') || (*ctim>='a' && *ctim<='z')) {
		wday = getkeyword (&ctim, daytab, KEYSIZE (daytab));
		if (wday == ERROR)
			return (0);
		if (*ctim == ',')
			++ctim;
		skip (ctim);
	} else
		wday = -1;

	day = getint (&ctim);
	if (day < 0)
		return (0);

	skip (ctim);
	mon = getkeyword (&ctim, monthtab, KEYSIZE (monthtab));
	if (mon == ERROR)
		return (0);

	skip (ctim);
	year = getint (&ctim);
	if (year < 0)
		return (0);
	if (year < 70)
		year += 2000;
	else if (year < 100)
		year += 1900;
	if (year <= 1981)               /* ancient date */
		return (0);

	skip (ctim);
	if (*ctim>='0' && *ctim<='9') {
		h = getint (&ctim);
		if (h<0 || *ctim!=':')
			return (0);
		++ctim;

		skip (ctim);
		m = getint (&ctim);
		if (m < 0)
			return (0);

		if (*ctim == ':') {
			++ctim;
			skip (ctim);
			s = getint (&ctim);
			if (s < 0)
				return (0);
		} else
			s = 0;

		skip (ctim);
	} else {
		h = 12;
		m = s = 0;
	}
	if (*ctim=='+' || *ctim=='-') {
		int sign = (*ctim == '+');
		++ctim;
		skip (ctim);
		tz = getint (&ctim);
		if (tz < 0)
			return (0);
		tz = tz / 100 * 60 + tz % 100;
		if (sign)
			tz = -tz;
	} else if (*ctim) {
		tz = getkeyword (&ctim, zonetab, KEYSIZE (zonetab));
		if (tz == ERROR)
			return (0);
	} else
		tz = 0;

	if (wday < 0)
		wday = weekday (day, mon, year);

	sprintf (buf, "%s, %02d %s %02d %02d:%02d:%02d *HHMM",
		dayname [wday], day, monthname [mon-1],
		year % 100, h, m, s);
	settz (buf, tz);
	return (buf);
}
Beispiel #22
0
int
mit_prop_dump(void *arg, const char *file)
{
    krb5_error_code ret;
    char line [2048];
    FILE *f;
    int lineno = 0;
    struct hdb_entry_ex ent;

    struct prop_data *pd = arg;

    f = fopen(file, "r");
    if(f == NULL)
	return errno;

    while(fgets(line, sizeof(line), f)) {
	char *p = line, *q;

	int i;

	int num_tl_data;
	int num_key_data;
	int high_kvno;
	int attributes;

	int tmp;

	lineno++;

	memset(&ent, 0, sizeof(ent));

	q = nexttoken(&p);
	if(strcmp(q, "kdb5_util") == 0) {
	    int major;
	    q = nexttoken(&p); /* load_dump */
	    if(strcmp(q, "load_dump"))
		errx(1, "line %d: unknown version", lineno);
	    q = nexttoken(&p); /* load_dump */
	    if(strcmp(q, "version"))
		errx(1, "line %d: unknown version", lineno);
	    q = nexttoken(&p); /* x.0 */
	    if(sscanf(q, "%d", &major) != 1)
		errx(1, "line %d: unknown version", lineno);
	    if(major != 4 && major != 5 && major != 6)
		errx(1, "unknown dump file format, got %d, expected 4-6",
		     major);
	    continue;
	} else if(strcmp(q, "policy") == 0) {
	    continue;
	} else if(strcmp(q, "princ") != 0) {
	    warnx("line %d: not a principal", lineno);
	    continue;
	}
	tmp = getint(&p);
	if(tmp != 38) {
	    warnx("line %d: bad base length %d != 38", lineno, tmp);
	    continue;
	}
	nexttoken(&p); /* length of principal */
	num_tl_data = getint(&p); /* number of tl-data */
	num_key_data = getint(&p); /* number of key-data */
	getint(&p);  /* length of extra data */
	q = nexttoken(&p); /* principal name */
	krb5_parse_name(pd->context, q, &ent.entry.principal);
	attributes = getint(&p); /* attributes */
	attr_to_flags(attributes, &ent.entry.flags);
	tmp = getint(&p); /* max life */
	if(tmp != 0) {
	    ALLOC(ent.entry.max_life);
	    *ent.entry.max_life = tmp;
	}
	tmp = getint(&p); /* max renewable life */
	if(tmp != 0) {
	    ALLOC(ent.entry.max_renew);
	    *ent.entry.max_renew = tmp;
	}
	tmp = getint(&p); /* expiration */
	if(tmp != 0 && tmp != 2145830400) {
	    ALLOC(ent.entry.valid_end);
	    *ent.entry.valid_end = tmp;
	}
	tmp = getint(&p); /* pw expiration */
	if(tmp != 0) {
	    ALLOC(ent.entry.pw_end);
	    *ent.entry.pw_end = tmp;
	}
	nexttoken(&p); /* last auth */
	nexttoken(&p); /* last failed auth */
	nexttoken(&p); /* fail auth count */
	for(i = 0; i < num_tl_data; i++) {
	    unsigned long val;
	    int tl_type, tl_length;
	    unsigned char *buf;
	    krb5_principal princ;

	    tl_type = getint(&p); /* data type */
	    tl_length = getint(&p); /* data length */

#define mit_KRB5_TL_LAST_PWD_CHANGE	1
#define mit_KRB5_TL_MOD_PRINC		2
	    switch(tl_type) {
	    case mit_KRB5_TL_LAST_PWD_CHANGE:
		buf = malloc(tl_length);
		if (buf == NULL)
		    errx(ENOMEM, "malloc");
		getdata(&p, buf, tl_length); /* data itself */
		val = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
		free(buf);
		ALLOC(ent.entry.extensions);
		ALLOC_SEQ(ent.entry.extensions, 1);
		ent.entry.extensions->val[0].mandatory = 0;
		ent.entry.extensions->val[0].data.element
		    = choice_HDB_extension_data_last_pw_change;
		ent.entry.extensions->val[0].data.u.last_pw_change = val;
		break;
	    case mit_KRB5_TL_MOD_PRINC:
		buf = malloc(tl_length);
		if (buf == NULL)
		    errx(ENOMEM, "malloc");
		getdata(&p, buf, tl_length); /* data itself */
		val = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
		ret = krb5_parse_name(pd->context, (char *)buf + 4, &princ);
		if (ret)
		    krb5_err(pd->context, 1, ret,
			     "parse_name: %s", (char *)buf + 4);
		free(buf);
		ALLOC(ent.entry.modified_by);
		ent.entry.modified_by->time = val;
		ent.entry.modified_by->principal = princ;
		break;
	    default:
		nexttoken(&p);
		break;
	    }
	}
	ALLOC_SEQ(&ent.entry.keys, num_key_data);
	high_kvno = -1;
	for(i = 0; i < num_key_data; i++) {
	    int key_versions;
	    int kvno;
	    key_versions = getint(&p); /* key data version */
	    kvno = getint(&p);

	    /*
	     * An MIT dump file may contain multiple sets of keys with
	     * different kvnos.  Since the Heimdal database can only represent
	     * one kvno per principal, we only want the highest set.  Assume
	     * that set will be given first, and discard all keys with lower
	     * kvnos.
	     */
	    if (kvno > high_kvno && high_kvno != -1)
		errx(1, "line %d: high kvno keys given after low kvno keys",
		     lineno);
	    else if (kvno < high_kvno) {
		nexttoken(&p); /* key type */
		nexttoken(&p); /* key length */
		nexttoken(&p); /* key */
		if (key_versions > 1) {
		    nexttoken(&p); /* salt type */
		    nexttoken(&p); /* salt length */
		    nexttoken(&p); /* salt */
		}
		ent.entry.keys.len--;
		continue;
	    }
	    ent.entry.kvno = kvno;
	    high_kvno = kvno;
	    ALLOC(ent.entry.keys.val[i].mkvno);
	    *ent.entry.keys.val[i].mkvno = 1;
	
	    /* key version 0 -- actual key */
	    ent.entry.keys.val[i].key.keytype = getint(&p); /* key type */
	    tmp = getint(&p); /* key length */
	    /* the first two bytes of the key is the key length --
	       skip it */
	    krb5_data_alloc(&ent.entry.keys.val[i].key.keyvalue, tmp - 2);
	    q = nexttoken(&p); /* key itself */
	    hex_to_octet_string(q + 4, &ent.entry.keys.val[i].key.keyvalue);

	    if(key_versions > 1) {
		/* key version 1 -- optional salt */
		ALLOC(ent.entry.keys.val[i].salt);
		ent.entry.keys.val[i].salt->type = getint(&p); /* salt type */
		tmp = getint(&p); /* salt length */
		if(tmp > 0) {
		    krb5_data_alloc(&ent.entry.keys.val[i].salt->salt, tmp - 2);
		    q = nexttoken(&p); /* salt itself */
		    hex_to_octet_string(q + 4,
					&ent.entry.keys.val[i].salt->salt);
		} else {
		    ent.entry.keys.val[i].salt->salt.length = 0;
		    ent.entry.keys.val[i].salt->salt.data = NULL;
		    getint(&p);	/* -1, if no data. */
		}
		fix_salt(pd->context, &ent.entry, i);
	    }
	}
	nexttoken(&p); /* extra data */
	v5_prop(pd->context, NULL, &ent, arg);
    }
    fclose(f);
    return 0;
}
Beispiel #23
0
void set_list_pen_pattern(NODE *arg) {
    NODE *temp;

    temp = cnv_node_to_numnode(car(arg));
    ztc_linepattern = getint(temp);
}
Beispiel #24
0
void help_size()
{
int c = '\0';
int break_loop;
int total_size;
int task_stacks;
int interrupt_stack;
int maximum_tasks, size_tasks;
int maximum_sems, size_sems;
int maximum_timers, size_timers;
int maximum_msgqs, size_msgqs;
int maximum_msgs, size_msgs_overhead;
int maximum_regns, size_regns;
int maximum_parts, size_parts;
int maximum_ports, size_ports;
int maximum_periods, size_periods;
int maximum_extensions, size_extensions;
int maximum_drvs, size_drvs;
int maximum_fps, size_fps;
int maximum_nodes, size_nodes;
int maximum_gobjs, size_gobjs;
int maximum_proxies, size_proxies;

total_size = sys_req;    /* Fixed Overhead */
printf( "What is maximum_tasks? " );
maximum_tasks = getint();
size_tasks = PER_TASK * maximum_tasks;
total_size += size_tasks;

printf( "What is maximum_semaphores? " );
maximum_sems = getint();
size_sems = PER_SEMAPHORE * maximum_sems;
total_size += size_sems;

printf( "What is maximum_timers? " );
maximum_timers = getint();
size_timers = PER_TIMER * maximum_timers;
total_size += size_timers;

printf( "What is maximum_message_queues? " );
maximum_msgqs = getint();
size_msgqs = PER_MSGQ * maximum_msgqs;
total_size += size_msgqs;

printf( "What is maximum_messages?  XXXX " );
maximum_msgs = getint();
size_msgs_overhead = 0;
total_size += size_msgs_overhead;

printf( "What is maximum_regions? " );
maximum_regns = getint();
size_regns = PER_REGN * maximum_regns;
total_size += size_regns;

printf( "What is maximum_partitions? " );
maximum_parts = getint();
size_parts = PER_PART * maximum_parts;
total_size += size_parts;

printf( "What is maximum_ports? " );
maximum_ports = getint();
size_ports = PER_PORT * maximum_ports;
total_size += size_ports;

printf( "What is maximum_periods? " );
maximum_periods = getint();
size_periods = PER_PORT * maximum_periods;
total_size += size_periods;

printf( "What is maximum_extensions? " );
maximum_extensions = getint();
size_extensions = PER_EXTENSION * maximum_extensions;
total_size += size_extensions;

printf( "What is number_of_device_drivers? " );
maximum_drvs = getint();
size_drvs = PER_DRV  * maximum_drvs;
total_size += size_drvs;

printf( "What will be total stack requirement for all tasks? " );
task_stacks = getint();
total_size += task_stacks;

printf( "What is the size of the interrupt stack? " );
interrupt_stack = getint();
total_size += interrupt_stack;

printf( "How many tasks will be created with the FP flag? " );
maximum_fps = getint();
size_fps = PER_FPTASK  * maximum_fps;
total_size += size_fps;

printf( "Is this a single processor system? " );
for ( break_loop=0 ; !break_loop; c = getchar() ) {
  switch ( c ) {
    case 'Y':  case 'y':
    case 'N':  case 'n':
      break_loop = 1;
      break;
  }
}
printf( "%c\n", c );
if ( c == 'n' || c == 'N' ) {
  printf( "What is maximum_nodes? " );
  maximum_nodes = getint();
  size_nodes = PER_NODE * maximum_nodes;
  total_size += size_nodes;
  printf( "What is maximum_global_objects? " );
  maximum_gobjs = getint();
  size_gobjs = PER_GOBJECT * maximum_gobjs;
  total_size += size_gobjs;
  printf( "What is maximum_proxies? " );
  maximum_proxies = getint();
  size_proxies = PER_PROXY * maximum_proxies;
  total_size += size_proxies;
} else {
  maximum_nodes = 0;
  size_nodes = PER_NODE * 0;
  maximum_gobjs = 0;
  size_gobjs = PER_GOBJECT * 0;
  maximum_proxies = 0;
  size_proxies = PER_PROXY * 0;
}

printf( "\n\n" );
printf( " ************** EXECUTIVE WORK SPACE REQUIRED **************\n" );
printf( " Tasks                - %03d * %03ld            =  %ld\n",
          maximum_tasks, PER_TASK, (long) size_tasks );
printf( " Semaphores           - %03d * %03ld            =  %ld\n",
          maximum_sems, PER_SEMAPHORE, (long) size_sems );
printf( " Timers               - %03d * %03ld            =  %ld\n",
          maximum_timers, PER_TIMER, (long) size_timers );
printf( " Msg Queues           - %03d * %03ld            =  %ld\n",
          maximum_msgqs, PER_MSGQ, (long) size_msgqs );
printf( " Messages Overhead    - %03d * %03d            =  %ld\n",
          maximum_msgs, 0 /* PER_MSG_OVERHEAD */, (long) size_msgs_overhead );
printf( " Regions              - %03d * %03ld            =  %ld\n",
          maximum_regns, PER_REGN, (long) size_regns);
printf( " Partitions           - %03d * %03ld            =  %ld\n",
          maximum_parts, PER_PART, (long) size_parts );
printf( " Periods              - %03d * %03ld            =  %ld\n",
          maximum_periods, PER_PERIOD, (long) size_periods );
printf( " Extensions           - %03d * %03ld            =  %ld\n",
          maximum_extensions, PER_EXTENSION, (long) size_extensions );
printf( " Device Drivers       - %03d * %03ld            =  %ld\n",
          maximum_drvs, PER_DRV, (long) size_drvs );

printf( " System Requirements  - %04" PRIu32 "                 =  %"PRIu32 "\n",
          sys_req, sys_req );

printf( " Floating Point Tasks - %03d * %03ld            =  %ld\n",
          maximum_fps, PER_FPTASK, (long) size_fps );
printf( " Application Task Stacks -                     =  %d\n",
          task_stacks );
printf( " Interrupt Stacks -                            =  %d\n",
          task_stacks );
printf( " \n" );
printf( " Global object tables - %03d * %03ld            =  %ld\n",
          maximum_nodes, PER_NODE, (long) size_nodes );
printf( " Global objects       - %03d * %03ld            =  %ld\n",
          maximum_gobjs, PER_GOBJECT, (long) size_gobjs );
printf( " Proxies              - %03d * %03ld            =  %ld\n",
          maximum_proxies, PER_PROXY, (long) size_proxies );
printf( "\n\n" );
printf( " TOTAL                                       = %d bytes\n",
      total_size );
}
Beispiel #25
0
int main() {
	int n, array[SIZE], getint(int *);

	for (n = 0; n < SIZE && getint(&array[n]) != EOF; n++)
		printf("%d\n", array[n]);
}
Beispiel #26
0
command()
{
double tval;
int i,echeck;
int pmin,pmax,pstep;

while (echeck = getstring(": ")) {
	if (echeck == EOF) {
		fileinput(EOF);
	}
	else if (in[0] == '\0') {
		errprint("");
	}
	else if (startsame(in,"cycle")) {
		cycle();
	}
	else if (startsame(in,"clear")) {
		clear();
	}
	else if (startsame(in,"coarticulation")) {
		getint(&coartflag);
	}
	else if (startsame(in,"rc")) {
		zarrays();
		cycle();
	}
	else if (startsame(in,"wordacts")) {
		scr_words(printmin,printmax,3,0,"MAX");
	}
	else if (startsame(in,"wtacts")) {
		scr_words(printmin,printmax,3,0,"ALL");
	}
	else if (startsame(in,"owtacts")) {
		getstring("word: ");
		scr_words(printmin,printmax,3,0,in);
	}
	else if (startsame(in,"phonacts")) {
		scr_phonemes(printmin,printmax,3,0);
	}
	else if (startsame(in,"featacts")) {
		scr_features();
	}
	else if (startsame(in,"sfeatacts")) {
		getstring("fname: ");
		sfeatacts(in);
	}
	else if (startsame(in,"memo")) {
		getstring("string: ");
		strcpy(memo,in);
	}
	else if (startsame(in,"expr")) {
		setex();
	}
	else if (startsame(in,"fcopt")) {
	    getint(&fcflag);
	}
	else if (startsame(in,"fpcyc")) {
	    getint(&fpcyc);
	}
	else if (startsame(in,"finput")) {
		fileinput(NONSTD);
	}
	else if (startsame(in,"inoise")) {
		getval(&inoise);
	}
	else if (startsame(in,"inspecs")) {
		getstring("File name (- = stdin): ");
		inspecs(in);
	}
	else if (startsame(in,"infeatures")) {
		getstring("File name: ");
		infeats(in);
	}
	/* NOT PRESENTLY OPERATIVE -- JLM 10-5-82
	else if (startsame(in,"wsubset")) {
		wordsubset();
	}
	*/
	else if (startsame(in,"test")) {
		getstring("test string: ");
		strcpy(memo,in);
		test(in);
	}
	else if (startsame(in,"topdown")) {
		topdown();
	}
	else if (startsame(in,"output")) {
		setout();
	}
	else if (startsame(in,"ofile")) {
		getstring("give filename (or - for none): ");
		setoutfile(in);
	}
	else if (in[0] == '?') {
		help();
	}
	else if (startsame(in,"help")) {
		help();
	}
	else if (startsame(in,"lexicon")) {
		getlex();
	}
	else if (startsame(in,"params")) {
		getpars();
	}
	else if (startsame(in,"quit")) {
		quit();
	}
	else if (startsame(in,"decay")) {
		getdouble(decay,NLEVS,levlabs);
	}
	else if (startsame(in,"alpha")) {
		getdouble(alpha,NPARAMS,conlabs);
	}
	else if (startsame(in,"gamma")) {
		getdouble(ga,NLEVS,levlabs);
	}
	else if (startsame(in,"grace")) {
		getint(&grace);
	}
	else if (startsame(in,"rest")) {
		tval = rest[W];
		getdouble(rest,NLEVS,levlabs);
		if (tval != rest[W]) {
			initialize();
		}
	}
	else if (startsame(in,"fweight")) {
		getdouble(fweight,NCONTINS,contname);
	}
	else if (startsame(in,"pthresh")) {
		getdouble(pthresh,NLEVS,levlabs);
	}
	else if (startsame(in,"ngraph")) {
		newgraph(pmin,ng_max,pstep);
	}
	else if (startsame(in,"ngmax")) {
		getint(&ng_max);
	}
	else if (startsame(in,"ngwscale")) {
		getval(&ng_wscale);
	}
	else if (startsame(in,"ngsscale")) {
		getval(&ng_sscale);
	}
	else if (startsame(in,"ngpscale")) {
		getval(&ng_pscale);
	}
	else if (startsame(in,"nreps")) {
		getint(&nreps);
	}
	else if (startsame(in,"pfreq")) {
		getint(&printfreq);
	}
	else if (startsame(in,"rarate")) {
		getval(&rarate);
	}
	else if (startsame(in,"sumpr")) {
		scr_sum(pmin,pmax,pstep);
	}
	else if (startsame(in,"sinspec")) {
		sinspec();
	}
	else if (startsame(in,"sfeatures")) {
		getstring("Filename: ");
		sfeatures(in);
	}
	else if (startsame(in,"dinspec")) {
		dinspec();
	}
	else if (startsame(in,"sumopt")) {
	    getint(&sumflag);
	}
	else if (startsame(in,"pmin")) {
		getint(&pmin);
	}
	else if (startsame(in,"pmax")) {
		getint(&pmax);
	}
	else if (startsame(in,"pstep")) {
		getint(&pstep);
	}
	else if (startsame(in,"min")) {
		getval(&min);
	}
	else if (startsame(in,"max")) {
		getval(&max);
	}
	else if (startsame(in,"windowcent")) {
		getval(&windowcent);
	}
	else if (startsame(in,"wbase")) {
		getval(&wbase);
	}
	else if (startsame(in,"wgraph")) {
		wgraph(pmin,ng_max,pstep);
	}
	else if (startsame(in,"wchange")) {
		getval(&wchange);
	}
	else if (startsame(in,"wgain")) {
		getval(&wgain);
	}
	else if (startsame(in,"wramp")) {
		getval(&wramp);
	}
	else if (startsame(in,"imax")) {
		getval(&imax);
	}
	else if (startsame(in,"sscale")) {
		getval(&sscale);
	}
	else if (startsame(in,"nsscale")) {
		getval(&nsscale);
	}
	else if (startsame(in,"freqscale")) {
		tval = fscale;
		getval(&fscale);
		if (tval != fscale) {
		    initialize();
		}
	}
	else if (startsame(in,"abort")) {
		abort();	/* to get a core dump for sdb */
	}
	else {
		errprint("Unrecognized request: For help type ?.");
		if (infp != stdin) fileinput(STD);
	}
	wait(0);
}
}
Beispiel #27
0
void backpatchlabel(char *labelname)
{
  struct BackPatch *bp, *nbp, *pbp, *zbp;
  int off, vv, vvv, reg, in;
  unsigned int ui;
  struct Value *vp = getvaluepos(&llabels, labelname);

  vvv = getvalueint(vp);
  bp = bplist;
  while(bp) {
    if(!strcmp(bp->label, labelname)) {
      switch(bp->type) {
        case BP_ADR:
          in  = getint(&odata, bp->where);
          reg = getint(&odata, bp->where + 4);
          vv = vvv + bp->value;;
          ui = (vv - bp->where)-8;
          if((vv - bp->where)-8 < 0) {
            in |= 2<<21;	/* sub */
            ui = (unsigned int) (- (int) ui);
          } else
            in |= 4<<21;	/* add */
          placeint(&odata, in | constval(&ui) | (15<<16), bp->where);
          placeint(&odata, in | constval(&ui) | (reg<<16), bp->where + 4);
          placeint(&odata, in | constval(&ui) | (reg<<16), bp->where + 8);
          break;
        case BP_BRANCH:
          off = bp->value & 0x00ffffff;
          bp->value &= 0xff000000;
          vv = vvv + off;
          if((vv - bp->where)&3)
            error("Offset must be aligned");
          placeint(&odata, bp->value | ((((vv - bp->where)-8)>>2) & 0x00ffffff), bp->where);
          break;
        case BP_DTRANS:
          off = bp->value & 0xfff;
          in = bp->value & 0xfffff000;
          vv = vvv + off;
          vv = (vv - bp->where)-8;
          if((vv < -4095) || (vv > 4095))
            error("Offset out of range");
          if(vv < 0)
            vv = -vv;
          else
            in |= 1<<23;
          placeint(&odata, in | (vv&0xfff), bp->where);
          break;
        case BP_FPDTRANS:
          off = bp->value & 0xff;
          in = bp->value & 0xffffff00;
          vv = vvv + off;
          vv = (vv - bp->where)-8;
          if((vv < -0x3fc) || (vv > 0x3fc))
            error("Offset out of range");
          if(vv & 3)
            error("Offset not aligned");
          if(vv < 0)
            vv = -vv;
          else
            in |= 1<<23;
          placeint(&odata, in | ((vv >> 2) & 0xff), bp->where);
          break;
        case BP_DFNL:
          addinttoarea(&olinkis, bp->where - curfuncstart);
          addinttoarea(&olinkis, addonestrtoarea(curfuncname));
          addinttoarea(&olinkis, bp->value + vvv - curfuncstart);
          numlinkis++;
          break;
        default:
          fatal("Internal error: Unknown backpatch type");
      }

      freemem(bp->label);
      zbp = bp;
      nbp = bp->next;
      pbp = bp->prev;
      freemem(bp);
      if(zbp == bplist)
        bplist = nbp;
      if(pbp)
        pbp->next = nbp;
      if(nbp)
        nbp->prev = pbp;
      bp = nbp;
    } else
      bp = bp->next;
  }
Beispiel #28
0
afs_int32
UDP_GetTicket(int ksoc, struct packet *pkt, afs_int32 kvno,
	      char *authDomain, char *ticket, int ticketLen, char *auth,
	      int authLen)
{
    afs_int32 code;
    struct ktc_encryptionKey tgskey;
    char name[MAXKTCNAMELEN];
    char inst[MAXKTCNAMELEN];
    char cell[MAXKTCREALMLEN];
    struct ktc_encryptionKey authSessionKey;
    afs_int32 host;
    Date start;
    Date authEnd;
    Date now = time(0);
    int celllen;
    int import;

    char *packet;
    int slen;
    int byteOrder = pkt->byteOrder;
    char sname[MAXKTCNAMELEN];
    char sinst[MAXKTCNAMELEN];
    afs_int32 time_ws;
    unsigned char life;

    struct ubik_trans *tt;
    afs_int32 to;
    struct kaentry caller;
    struct kaentry server;
    Date reqEnd;
    struct ktc_encryptionKey sessionKey;
    int newTicketLen;
    char newTicket[MAXKTCTICKETLEN];

    char cipher[2 * MAXKTCTICKETLEN];	/* put encrypted part of answer here */
    int cipherLen;
    struct packet ans;

    COUNT_REQ(UGetTicket);

    if ((code = InitAuthServ(&tt, LOCKREAD, this_op)))
	goto fail;
    code =
	ka_LookupKvno(tt, KA_TGS_NAME,
		      ((strlen(authDomain) > 0) ? authDomain : lrealm), kvno,
		      &tgskey);
    if (code)
	goto abort;

    code =
	tkt_DecodeTicket(ticket, ticketLen, &tgskey, name, inst, cell,
			 &authSessionKey, &host, &start, &authEnd);
    pkt->name = name;
    pkt->inst = inst;
    pkt->realm = cell;
    if (code) {
	code = KERB_ERR_AUTH_EXP;	/* was KANOAUTH */
	goto abort;
    }
    save_principal(udptgsPrincipal, name, inst, cell);
    code = tkt_CheckTimes(start, authEnd, now);
    if (code <= 0) {
	if (code == -1) {
	    code = KERB_ERR_SERVICE_EXP;	/* was RXKADEXPIRED */
	    goto abort;
	}
	code = KERB_ERR_AUTH_EXP;	/* was KANOAUTH */
	goto abort;
    }
    celllen = strlen(cell);
    import = 0;
    if ((strlen(authDomain) > 0) && (strcmp(authDomain, lrealm) != 0))
	import = 1;
    if (import && (celllen == 0)) {
	code = KERB_ERR_PKT_VER;	/* was KABADTICKET */
	goto abort;
    }
    if (celllen == 0) {
	strncpy(cell, lrealm, MAXKTCREALMLEN - 1);
	cell[MAXKTCREALMLEN - 1] = 0;
    };

    if (!krb4_cross && strcmp(lrealm, cell) != 0) {
	code = KERB_ERR_PRINCIPAL_UNKNOWN;
	goto abort;
    }

    if (krb_udp_debug) {
	printf("UGetTicket: got ticket from '%s'.'%s'@'%s'\n", name, inst,
	       cell);
    }

    code = check_auth(pkt, auth, authLen, &authSessionKey, name, inst, cell);
    if (code)
	goto abort;

    /* authenticator and all is OK so read actual request */
    packet = pkt->rest;
    getint(time_ws);
    life = *(unsigned char *)packet++;
    getstr(sname);
    getstr(sinst);
    start = now;
    reqEnd = life_to_time(start, life);
    if (krb_udp_debug) {
	printf("UGetTicket: request for server '%s'.'%s'\n", sname, sinst);
    }
    save_principal(udptgsServerPrincipal, sname, sinst, 0);

    if (import) {
	strcpy(caller.userID.name, name);
	strcpy(caller.userID.instance, inst);
	caller.max_ticket_lifetime = htonl(MAXKTCTICKETLIFETIME);
    } else {
	code = FindBlock(tt, name, inst, &to, &caller);
	if (code)
	    goto abort;
	if (to == 0) {
	    ka_PrintUserID("GetTicket: User ", name, inst, " unknown.\n");
	    code = KERB_ERR_PRINCIPAL_UNKNOWN;	/* KANOENT */
	    goto abort;
	}
	if (ntohl(caller.flags) & KAFNOTGS) {
	    code = KERB_ERR_AUTH_EXP;	/* was KABADUSER */
	    goto abort;
	}
    }

    code = FindBlock(tt, sname, sinst, &to, &server);	/* get server's entry */
    if (code)
	goto abort;
    if (to == 0) {		/* entry not found */
	ka_PrintUserID("GetTicket: Server ", sname, sinst, " unknown.\n");
	code = KERB_ERR_PRINCIPAL_UNKNOWN;	/* KANOENT */
	goto abort;
    }
    code = ubik_EndTrans(tt);
    if (code)
	goto fail;

    if (ntohl(server.flags) & KAFNOSEAL)
	return KABADSERVER;

    code = DES_new_random_key(ktc_to_cblock(&sessionKey));
    if (code) {
	code = KERB_ERR_NULL_KEY;	/* was KANOKEYS */
	goto fail;
    }

    reqEnd =
	umin(umin(reqEnd, authEnd),
	     umin(start + ntohl(caller.max_ticket_lifetime),
		  start + ntohl(server.max_ticket_lifetime)));

    code =
	tkt_MakeTicket(newTicket, &newTicketLen, &server.key,
		       caller.userID.name, caller.userID.instance, cell,
		       start, reqEnd, &sessionKey,
		       htonl(pkt->from.sin_addr.s_addr), server.userID.name,
		       server.userID.instance);
    if (code)
	goto fail;

    cipherLen = sizeof(cipher);
    code =
	create_cipher(cipher, &cipherLen, &sessionKey, sname, sinst, start,
		      reqEnd, ntohl(server.key_version), newTicket,
		      newTicketLen, &authSessionKey);
    if (code)
	goto fail;

    code =
	create_reply(&ans, name, inst, start, reqEnd, 0, cipher, cipherLen);
    if (code)
	goto fail;

    code =
	sendto(ksoc, ans.data, ans.len, 0, (struct sockaddr *)&pkt->from,
	       sizeof(pkt->from));
    if (code != ans.len) {
	perror("calling sendto");
	code = -1;
	goto fail;
    }

    if (cipherLen != 0) {
	KALOG(name, inst, sname, sinst, NULL, host, LOG_GETTICKET);
    }
    osi_audit(UDPGetTicketEvent, 0, AUD_STR, name, AUD_STR, inst, AUD_STR,
	      cell, AUD_STR, sname, AUD_STR, sinst, AUD_END);
    return 0;

  abort:
    ubik_AbortTrans(tt);
  fail:
    osi_audit(UDPGetTicketEvent, code, AUD_STR, name, AUD_STR, inst, AUD_STR,
	      NULL, AUD_STR, NULL, AUD_STR, NULL, AUD_END);
    return code;
}
char* strptime(const char* s,const char* format, struct tm* tm) {
  int i,j;
  register time_t  day;
  while (*format) {
    switch (*format) {
    case ' ': case '\t':
      /* match zero or more white space in input string */
      while (isblank(*s)) ++s;
      ++format;
      break;
    case '%':
      ++format;
      switch (*format) {
      case '%': if (*s=='%') ++s; else return 0; break;
      case 'a': case 'A': /* weekday; we just skip */
	for (i=0; i<3; ++i)
	  if (isalpha(*s)) ++s;
	break;
      case 'b': case 'B': case 'h':
	for (i=0; i<12; ++i) {
	  if (strncasecmp(s,months[i],j=strlen(months[i])))
	    if (strncasecmp(s,months[i],j=3))
	      j=0;
	  if (j) break;
	}
	if (!j) return 0;
	s+=j;
	tm->tm_mon=i;
	break;
      case 'c':
	s=strptime(s,"%b %a %d %k:%M:%S %Z %Y",tm);
	break;
      case 'C':
	i=getint(&s,2);
	if (i==-1) return 0;
	tm->tm_year=(tm->tm_year%100)+(i*100);
	break;
      case 'd': case 'e':
	i=getint(&s,2);
	if (i==-1 || i>31) return 0;
	tm->tm_mday=i;
	break;
      case 'D':
	s=strptime(s,"%m/%d/%y",tm);
	break;
      case 'H': case 'k':
	i=getint(&s,2);
	if (i==-1 || i>23) return 0;
	tm->tm_hour=i;
	break;
      case 'I': case 'l':
	i=getint(&s,2);
	if (i==-1 || i>12) return 0;
	tm->tm_hour=(tm->tm_hour/12)*12+i;
	break;
      case 'j':
	getint(&s,3);	/* not used */
	break;
      case 'm':
	i=getint(&s,2);
	if (i<=0 || i>12) return 0;
	tm->tm_mon=i-1;
	break;
      case 'M':
	i=getint(&s,2);
	if (i==-1 || i>59) return 0;
	tm->tm_min=i;
	break;
      case 'n': case 't':
	while (isblank(*s)) ++s;
	break;
      case 'p': case 'P':
	if (*s=='p' || *s=='P') tm->tm_hour=(tm->tm_hour%12)+12;
	s+=2;
	break;
      case 'r':
	s=strptime(s,"%I:%M:%S %p",tm);
	break;
      case 'R':
	s=strptime(s,"%H:%M",tm);
	break;
      case 'S':
	i=getint(&s,2);
	if (i==-1 || i>60) return 0;
	tm->tm_sec=i;
	break;
      case 'T':
	s=strptime(s,"%H:%M:%S",tm);
	break;
      case 'U': case 'W':
	if (getint(&s,2)==-1) return 0;
	break;
      case 'w':
	if (*s<'0' || *s>'6') return 0;
	++s;
	break;
      case 'x':
	s=strptime(s,"%b %a %d",tm);
	break;
      case 'X':
	s=strptime(s,"%k:%M:%S",tm);
	break;
      case 'y':
	i=getint(&s,2);
	if (i<0) return 0;
	tm->tm_year=(i<69)?i+100:i;
	break;
      case 'Y':
	i=getint(&s,4);
	if (i==-1) return 0;
	tm->tm_year=i-1900;
	break;
      case 'Z':
	/* time zone.  Not sure what I'm expected to do here. We'll just
	 * skip to the next whitespace */
	while (*s!=' ' && *s!='\t') ++s;
	break;
      }
      ++format;
      break;
    default:
      if (*s != *format) return 0;
      ++format; ++s;
      break;
    }
  }
 
  day  = (tm->tm_year - 70) * 365 + (tm->tm_year - 69) / 4;
  day += tm->tm_yday = __spm [tm->tm_mon] + tm->tm_mday-1 + (__isleap (tm->tm_year+1900) & (tm->tm_mon > 1));
  tm->tm_wday = (day + 4) % 7;

  return (char*)s;
}
Beispiel #30
0
float raster_contagion ()
{
	int	*adj,*carea;
	int	edgeval;
	int	size;
	float	sum,contagion,prop1,prop2;
	short	i,j,n;
	short	value,neighbor;
	short	xptr,yptr;
	

/*
 *  Get a clean copy of the image.
 */
	read_image(0);

/*
 *  Allocate space for needed variables.
 */
	size = max_class - min_class + 1;

	adj = (int *) calloc ((unsigned)size,sizeof(int));
	if (adj == NULL) {
	   printf ("\nERROR! rascont: Can not allocate space for adj!");
	   exit(-1);
	}
	carea = (int *) calloc ((unsigned)size,sizeof(int));
	if (carea == NULL) {
	   printf ("\nERROR! rascont: Can not allocate space for carea!");
	   exit(-1);
	}

/*
 *  Initialize
 */
	for (i=0; i < size; i++) {
	   carea[i] = 0;
	   adj[i] = 0;
	   for(j=0; j < size; j++) 
	      setint(edge,num_wt,i,j,0);
	}


/*
 *  Step through all cells in the image 
 */

	for (i=0; i < num_rows; i++) {
	   for (j=0; j < num_cols; j++) {
	      value = getshort(image,num_cols,i,j);
	      if (value < 0) continue;

/*
 *  Get the area of each class.
 */
	      carea[value-min_class] ++;

/*
 *  Look at this values 4 neighbors ....
 */
	      for (n=0; n < 4; n++) {
                 xptr = j + xpos[n];
                 if (xptr < 0 || xptr >= num_cols) continue;
                 yptr = i + ypos[n];
                 if (yptr < 0 || yptr >= num_rows) continue;
 
		 neighbor = getshort(image,num_cols,yptr,xptr);

/*
 *  If the neighbor is within the landscape (value >=0), 
 *  increment the count of its patchtype, and increment the
 *  count of the number of this edge type combo.
 */
		 if (neighbor >= 0) {
		    adj[value-min_class] ++;
		    edgeval = getint(edge,num_wt,value-min_class,
			neighbor-min_class);
		    edgeval ++;
		    setint(edge,num_wt,value-min_class,neighbor-min_class,
			edgeval);
		 }
	      }
	   }
	}

/*
 *  Loop over all classes
 */
	sum = 0.0;
	for (i=0; i < size; i++) {
	   if (carea[i] == 0.0) continue;

/* 
 *  Get the proportion of the landscape in this class.
 */
	   prop1 = (float)carea[i] / (float)total_size;

/*
 *  Look for adjacencies with other classes.
 */
	   for (j=0; j < size; j++) {
	      edgeval = getint(edge,num_wt,i,j);
	      if (edgeval > 0) {
	         prop2 = (float)edgeval / (float)adj[i];
		 sum += (prop1 * prop2) * log(prop1 * prop2);
	      }
	   }
	}

/*
 *  Calculate contagion.
 */
	contagion = (sum / (2.0 * log((double)total_num_classes))) + 1.0;

	free (adj);
	free (carea);

	return (contagion);
}