Example #1
0
void TogBlk(char ch1, char ch2, const char * cmd)
{
	int	block;
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}
	
	switch (fcntl(sock, F_GETFL, 0))	{
	case 0:
		block	=	1;
		break;
	default:
		block = 	0;
		break;
	case -1:
		printf("# fcntl(F_GETFL) returned error %s\n", Explain());
		Where();
		
		return;
	}
	
	if (ioctl(sock, FIONBIO, &block))
		printf(
			"# ioctl(FIONBIO, %s) returned error %s\n", 
			block ? "true" : "false", 
			Explain());
	else
		printf("# Socket is now %s\n", block ? "nonblocking" : "blocking");
	
	Where();
}
Example #2
0
void Read(char ch1, char ch2, const char * cmd)
{
	int		len;
	char 		buf[500];
	char *	line;
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}

	len	=	read(sock, buf, 500);
	
	if (len < 0)	{
		printf("# read() returned error %s\n", Explain());
	} else {
		buf[len] = 0;
		printf("# read() returned:\n");
		
		for (line = strtok(buf, "\n\r"); line; line = strtok(nil, "\n\r"))
			printf("# %s\n", line);
	}
	
	Where();
}
Example #3
0
void Socket(char ch1, char ch2, const char * line)
{
	sock	=	socket(AF_APPLETALK, SOCK_STREAM, 0);
	
	if (sock == -1)	{
		printf("# socket() returned error %s\n", Explain());
		Where();
	}
}
Example #4
0
void Close(char ch1, char ch2, const char * cmd)
{
	if (close(sock))	{
		printf("# close() returned error %s\n", Explain());
		Where();
	}
	
	sock		=	accsock;
	accsock	=	-1;
}
Example #5
0
void GetError(char ch1, char ch2, const char * cmd)
{
	int err;
	socklen_t len = sizeof(int);
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}
	
	if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len))
		printf("# getsockopt(SOL_SOCKET, SO_ERROR) returned error %s\n", Explain());
	else {
		errno = err;
		printf("# Asynchronous error was %d (%s)\n", err, Explain());
	}
	
	Where();
}
Example #6
0
void Listen(char ch1, char ch2, const char * cmd)
{
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
		
		return;
	}

	if (listen(sock, 5))	{
		printf("# listen() returned error %s\n", Explain());
		Where();
	}
}
Example #7
0
void NRead(char ch1, char ch2, const char * cmd)
{
	int	nread;
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}
	
	if (ioctl(sock, FIONREAD, &nread))
		printf("# ioctl(FIONREAD) returned error %s\n", Explain());
	else
		printf("# %d bytes waiting to be read\n", nread);
	
	Where();
}
Example #8
0
void Shutdown(char ch1, char ch2, const char * cmd)
{
	int		what;
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}

	if (sscanf(cmd, "%d", &what) != 1) {
		Usage(ch1, ch2);
		return;
	}
	
	if (shutdown(sock, what))
		printf("# shutdown(%d) returned error %s\n", what, Explain());
}
Example #9
0
void Select(char ch1, char ch2, const char * cmd)
{
	int				res;
	fd_set			rdfds;
	fd_set			wrfds;
	fd_set			exfds;
	struct timeval	delay;
	
	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}
	
	FD_ZERO(&rdfds);
	FD_ZERO(&wrfds);
	FD_ZERO(&exfds);
	
	FD_SET(sock, &rdfds);
	FD_SET(sock, &wrfds);
	FD_SET(sock, &exfds);
	
	delay.tv_sec	=	10;
	delay.tv_usec	=	0;
	
	res = select(sock+1, &rdfds, &wrfds, &exfds, &delay);
	
	if (res < 0)	{
		printf("# select() returned error %s\n", Explain());
	} else if (!res) {
		printf("# select() timed out\n");
	} else {
		printf(
			"# select() returned %s%s%s\n", 
			FD_ISSET(sock, &rdfds) ? "canRead " : "",
			FD_ISSET(sock, &wrfds) ? "canWrite " : "",
			FD_ISSET(sock, &exfds) ? "exception " : "");
	}
	
	Where();
}
Example #10
0
void Write(char ch1, char ch2, const char * line)
{
	int len	=	strlen(line);
	int part;

	if (sock == -1)	{
		printf("# socket is not open\n");
		Where();
			
		return;
	}
	
	for (; len; len -= part, line += part) {
		part = write(sock, line, len);
		if (part < 0)	{
			printf("# write(\"%s\") returned error %s\n", line, Explain());
			Where();
			
			break;
		}		
	}
}
Example #11
0
static void
expand_g(Graph *g)
{	Node *now, *n1, *n2, *nx;
	int can_release;

	if (!g->New)
	{	Debug2("\nDone with %s", g->name->name);
		if (tl_verbose) dump_graph(g);
		if (not_new(g))
		{	if (tl_verbose) printf("\tIs Not New\n");
			return;
		}
		if (g->Next)
		{	Debug("	Has Next [");
			for (n1 = g->Next; n1; n1 = n1->nxt)
			{ Dump(n1); Debug(", "); }
			Debug("]\n");

			ng(ZS, getsym(g->name), g->Next, ZN, ZN);
		}
		return;
	}

	if (tl_verbose)
	{	Symbol *z;
		printf("\nExpand %s, from ", g->name->name);
		for (z = g->incoming; z; z = z->next)
			printf("%s, ", z->name);
		printf("\n\thandle:\t"); Explain(g->New->ntyp);
		dump_graph(g);
	}

	if (g->New->ntyp == AND)
	{	if (g->New->nxt)
		{	n2 = g->New->rgt;
			while (n2->nxt)
				n2 = n2->nxt;
			n2->nxt = g->New->nxt;
		}
		n1 = n2 = g->New->lft;
		while (n2->nxt)
			n2 = n2->nxt;
		n2->nxt = g->New->rgt;

		releasenode(0, g->New);

		g->New = n1;
		push_stack(g);
		return;
	}

	can_release = 0;	/* unless it need not go into Old */
	now = g->New;
	g->New = g->New->nxt;
	now->nxt = ZN;

	if (now->ntyp != TRUE)
	{	if (g->Old)
		{	for (n1 = g->Old; n1->nxt; n1 = n1->nxt)
				if (isequal(now, n1))
				{	can_release = 1;
					goto out;
				}
			n1->nxt = now;
		} else
			g->Old = now;
	}
out:
	switch (now->ntyp) {
	case FALSE:
		push_stack(g);
		break;
	case TRUE:
		releasenode(1, now);
		push_stack(g);
		break;
	case PREDICATE:
	case NOT:
		if (can_release) releasenode(1, now);
		push_stack(g);
		break;
	case V_OPER:
		Assert(now->rgt != ZN, now->ntyp);
		Assert(now->lft != ZN, now->ntyp);
		Assert(now->rgt->nxt == ZN, now->ntyp);
		Assert(now->lft->nxt == ZN, now->ntyp);
		n1 = now->rgt;
		n1->nxt = g->New;

		if (can_release)
			nx = now;
		else
			nx = getnode(now); /* now also appears in Old */
		nx->nxt = g->Next;

		n2 = now->lft;
		n2->nxt = getnode(now->rgt);
		n2->nxt->nxt = g->New;
		g->New = flatten(n2);
		push_stack(g);
		ng(ZS, g->incoming, n1, g->Old, nx);
		break;

	case U_OPER:
		Assert(now->rgt->nxt == ZN, now->ntyp);
		Assert(now->lft->nxt == ZN, now->ntyp);
		n1 = now->lft;

		if (can_release)
			nx = now;
		else
			nx = getnode(now); /* now also appears in Old */
		nx->nxt = g->Next;

		n2 = now->rgt;
		n2->nxt = g->New;

		goto common;

#ifdef NXT
	case NEXT:
		Assert(now->lft != ZN, now->ntyp);
		nx = dupnode(now->lft);
		nx->nxt = g->Next;
		g->Next = nx;
		if (can_release) releasenode(0, now);
		push_stack(g);
		break;
#endif

	case OR:
		Assert(now->rgt->nxt == ZN, now->ntyp);
		Assert(now->lft->nxt == ZN, now->ntyp);
		n1 = now->lft;
		nx = g->Next;

		n2 = now->rgt;
		n2->nxt = g->New;
common:
		n1->nxt = g->New;

		ng(ZS, g->incoming, n1, g->Old, nx);
		g->New = flatten(n2);

		if (can_release) releasenode(1, now);

		push_stack(g);
		break;
	}
}
Example #12
0
/*
 * Manual page at function.def
 */
INT16 CGEN_PUBLIC CFunction::OnExplain()
{
  FNC_DELEGATE OnExplain();                                                     // Delegate to running function
  return Explain(GetNextToken(TRUE));
}
/** load all parameters from the configuration file and the command line switches */
bool Parameter::LoadParam(int argc, char* argv[])
{
  // config file (-f) arg mandatory
  string configPath;
  if ( (configPath = FindParam("-f", argc, argv)) == ""
       && (configPath = FindParam("-config", argc, argv)) == "") {
    PrintCredit();
    Explain();

    UserMessage::Add("No configuration file was specified.  Use -config or -f");
    return false;
  } else {
    if (!ReadConfigFile(configPath)) {
      UserMessage::Add("Could not read "+configPath);
      return false;
    }
  }

  // overwrite parameters with values from switches
  for(PARAM_STRING::const_iterator iterParam = m_description.begin(); iterParam != m_description.end(); iterParam++) {
    const string paramName = iterParam->first;
    OverwriteParam("-" + paramName, paramName, argc, argv);
  }

  // ... also shortcuts
  for(PARAM_STRING::const_iterator iterParam = m_abbreviation.begin(); iterParam != m_abbreviation.end(); iterParam++) {
    const string paramName = iterParam->first;
    const string paramShortName = iterParam->second;
    OverwriteParam("-" + paramShortName, paramName, argc, argv);
  }

  // logging of parameters that were set in either config or switch
  int verbose = 1;
  if (m_setting.find("verbose") != m_setting.end() &&
      m_setting["verbose"].size() > 0)
    verbose = Scan<int>(m_setting["verbose"][0]);
  if (verbose >= 1) { // only if verbose
    TRACE_ERR( "Defined parameters (per moses.ini or switch):" << endl);
    for(PARAM_MAP::const_iterator iterParam = m_setting.begin() ; iterParam != m_setting.end(); iterParam++) {
      TRACE_ERR( "\t" << iterParam->first << ": ");
      for ( size_t i = 0; i < iterParam->second.size(); i++ )
        TRACE_ERR( iterParam->second[i] << " ");
      TRACE_ERR( endl);
    }
  }

  // check for illegal parameters
  bool noErrorFlag = true;
  for (int i = 0 ; i < argc ; i++) {
    if (isOption(argv[i])) {
      string paramSwitch = (string) argv[i];
      string paramName = paramSwitch.substr(1);
      if (m_valid.find(paramName) == m_valid.end()) {
        UserMessage::Add("illegal switch: " + paramSwitch);
        noErrorFlag = false;
      }
    }
  }

  // check if parameters make sense
  return Validate() && noErrorFlag;
}
Example #14
0
void main(int nar, char* ar[])
{
  int i,j,k,l,m, n=0, num, nnn[4];
  float*u; // ,*f;
  double*f;
  parlist par;
  FILE *in,*out,*col,*grs;
  char name[100];
  char buffer[48];
  float cpu[2]; 
  clock_t t;

  /* set default values */
  par.sigma=2; par.seed=200294;
  par.dim=intvector(1,3); par.dim[1]=64; par.dim[2]=32; par.dim[3]=16; 
  empty(&par.inname); empty(&par.outname);
  empty(&par.colname); empty(&par.grsname);
  par.length=1; par.nongauss=0; par.lo=-4; par.hi=4; par.bins=100; 
  par.med=0; par.pixel=1; par.normal=1; par.time=0;
  
  /* work through arguments */
  while(++n<nar){
    if(ar[n][0]=='-'&&ar[n][1]){
      switch(ar[n][1]) {
	case'0' : par.grsname =READSTR; break;
	case'1' : par.colname =READSTR; break;
	case'L' : par.length  =READINT; break;
	case'N' : par.normal  =0;       break;
	case'b' : par.bins    =READINT; break;
	case'g' : par.nongauss=READINT; break;
	case'h' : par.hi      =READFLT; break;
	case'i' : par.inname  =READSTR; break;
	case'l' : par.lo      =READFLT; break;
	case'm' : par.med     =READINT; break;
	case'o' : par.outname =READSTR; break;
	case'p' : par.pixel   =READINT; break;
	case'r' : par.seed    =READINT; break;
	case's' : par.sigma   =READFLT; break;
	case't' : par.time    =1;       break;
	case'x' : par.dim[1]  =READINT; break;
	case'y' : par.dim[2]  =READINT; break;
	case'z' : par.dim[3]  =READINT; break;
      default : Explain(stderr,ar[0],&par);
      }
    }
    else {
      Explain(stderr,ar[0],&par);
    }
  }
  par.a=1./(float)par.dim[1];	/* grid constant is used everywhere */

  /* allocate some memory */
  n=par.dim[1]*par.dim[2]*par.dim[3];
  u=vector(0,2*n);

  /* open input file and read data */
  fileopenr(&in,par.inname);
 /*   printf("%s"," here 1a \n");

    printf("size = %d\n",sizeof(in));   */
  if(in) {
    //f=vector(0,n);
    f=doublevector(0,n);

    fread((void*)buffer,sizeof(char),24,in);

    if(n!=fread((void*)f,sizeof(double),n,in)) {
      fprintf(stderr,"error when reading input!\n"); 
      exit(99);
    }  
/*      printf("f[0] %d\n",&f[0]);
      printf("f[0]wert %g\n", f[0]);
      printf("f[1]wert %g\n", f[1]);
      printf("f[1]wert %g\n", f[2]);
      printf("f[1]wert %g\n", f[3]);  */
      printf("---\n");    
 
      //for(i=0;i<n;i++) u[2*i]=f[i],u[2*i+1]=0; 
      for(i=0;i<n;i++) u[2*i]=(float)f[i],u[2*i+1]=0; 
 /*     printf("u[0] %d\n",&u[0]);
      printf("u[0]wert %g\n", u[0]);
      printf("f[0] %d\n",&f[0]);
      printf("f[0]wert %g\n", f[0]);
      printf("u[1] %d\n",&u[1]);
      printf("u[1]wert %g\n", u[1]);
      printf("f[1] %d\n",&f[1]);
      printf("f[1]wert %g\n", f[1]);
      printf("%s"," here 1c \n");    */

      //free_vector(f,0,n);
    free_doublevector(f,0,n);
 /*     printf("%s"," here 1d \n"); 
      printf("par.sigma = %g\n",par.sigma);   */

  if(par.sigma>0) fourn(u-1,par.dim,3,1); 
  }
   /*    printf("%s"," here 1e \n"); */
  fileclose(in);
  /*   printf("%s"," here 1 \n");   */
  /* open output files */
  fileopenw(&out,par.outname);
 /*   printf("%s"," here 2 \n");   */
  cpu[0]=cpu[1]=0;
  for(num=0; num<par.length; num++) {
      
    /* random field in Fourier space */
    if(par.time) t=clock();
    if(!in) randomfield(u,&par);
    if(par.time) cpu[0]+=(clock()-t)/(float)CLOCKS_PER_SEC;
    /* convolution and normalization */
    if(par.time) t=clock();
    if(par.sigma>0) convolution(u,&par);
    if(par.sigma>0) fourn(u-1,par.dim,3,-1);
    normalize(u,&par);
    if(par.time) cpu[0]+=(clock()-t)/(float)CLOCKS_PER_SEC;
  /*   printf("%s"," here 2c \n");*/
    /* perform statistics */
    if(par.time) t=clock();
    minkowski(out,u,&par);
    if(par.time) cpu[1]+=(clock()-t)/(float)CLOCKS_PER_SEC;
  }
/*      printf("%s"," here 3 \n"); */
  if(par.time) 
    fprintf(stderr,"CPU: %13s%13s\n"
	    "      %8.2f sec %8.2f sec\n",
	    "fields","minkowski",cpu[0],cpu[1]);

  /* output xpm bitmap data */
  fileopenw(&col,par.colname); if(col) picture(1,col,u,&par); fileclose(col);
  fileopenw(&grs,par.grsname); if(grs) picture(0,grs,u,&par); fileclose(grs);

  /* finish */
  fileclose(out);
  free_vector(u,0,2*n);
  exit(0);
}