Пример #1
0
/*
 * SOCKDGRAM is unreliable, so we must repeat messages if we have
 * not received an acknowledgement within a reasonable amount
 * of time
 */
void
ctl_transact(struct in_addr target, CTL_MSG lmsg, int type, CTL_RESPONSE *rp)
{
	fd_set read_mask, ctl_mask;
	int nready = 0, cc;
	struct timeval wait;

	lmsg.type = type;
	daemon_addr.sin_addr = target;
	daemon_addr.sin_port = daemon_port;
	FD_ZERO(&ctl_mask);
	FD_SET(ctl_sockt, &ctl_mask);

	/*
	 * Keep sending the message until a response of
	 * the proper type is obtained.
	 */
	do {
		wait.tv_sec = CTL_WAIT;
		wait.tv_usec = 0;
		/* resend message until a response is obtained */
		do {
			cc = sendto(ctl_sockt, (char *)&lmsg, sizeof (lmsg), 0,
			    (struct sockaddr *)&daemon_addr,
			    sizeof (daemon_addr));
			if (cc != sizeof (lmsg)) {
				if (errno == EINTR)
					continue;
				p_error("Error on write to talk daemon");
			}
			read_mask = ctl_mask;
			nready = select(32, &read_mask, 0, 0, &wait);
			if (nready < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error waiting for daemon response");
			}
		} while (nready == 0);
		/*
		 * Keep reading while there are queued messages
		 * (this is not necessary, it just saves extra
		 * request/acknowledgements being sent)
		 */
		do {
			cc = recv(ctl_sockt, (char *)rp, sizeof (*rp), 0);
			if (cc < 0) {
				if (errno == EINTR)
					continue;
				p_error("Error on read from talk daemon");
			}
			read_mask = ctl_mask;
			/* an immediate poll */
			timerclear(&wait);
			nready = select(32, &read_mask, 0, 0, &wait);
		} while (nready > 0 && (rp->vers != TALK_VERSION ||
		    rp->type != type));
	} while (rp->vers != TALK_VERSION || rp->type != type);
	rp->id_num = ntohl(rp->id_num);
	rp->addr.sa_family = ntohs(rp->addr.sa_family);
}
Пример #2
0
/*
 * Trade edit characters with the other talk. By agreement
 * the first three characters each talk transmits after
 * connection are the three edit characters.
 */
void
set_edit_chars(void)
{
    char buf[3];
    int cc;
    struct termios tio;

    tcgetattr(0, &tio);
    my_win.cerase = tio.c_cc[VERASE];
    my_win.kill = tio.c_cc[VKILL];
    my_win.werase = tio.c_cc[VWERASE];
    if (my_win.cerase == (char)_POSIX_VDISABLE)
        my_win.kill = CERASE;
    if (my_win.kill == (char)_POSIX_VDISABLE)
        my_win.kill = CKILL;
    if (my_win.werase == (char)_POSIX_VDISABLE)
        my_win.werase = CWERASE;
    buf[0] = my_win.cerase;
    buf[1] = my_win.kill;
    buf[2] = my_win.werase;
    cc = write(sockt, buf, sizeof(buf));
    if (cc != sizeof(buf) )
        p_error("Lost the connection");
    cc = read(sockt, buf, sizeof(buf));
    if (cc != sizeof(buf) )
        p_error("Lost the connection");
    his_win.cerase = buf[0];
    his_win.kill = buf[1];
    his_win.werase = buf[2];
}
Пример #3
0
/*
 * Trade edit characters with the other talk. By agreement
 * the first three characters each talk transmits after
 * connection are the three edit characters.
 */
void
set_edit_chars(void)
{
	char buf[3];
	int cc;
	struct termios tty;
	
	tcgetattr(0, &tty);
	my_win.cerase = tty.c_cc[VERASE];
	my_win.kill = tty.c_cc[VKILL];
	if (tty.c_cc[VWERASE] == (unsigned char) -1)
		my_win.werase = '\027';	 /* control W */
	else
		my_win.werase = tty.c_cc[VWERASE];
	buf[0] = my_win.cerase;
	buf[1] = my_win.kill;
	buf[2] = my_win.werase;
	cc = write(sockt, buf, sizeof(buf));
	if (cc != sizeof(buf) )
		p_error("Lost the connection");
	cc = read(sockt, buf, sizeof(buf));
	if (cc != sizeof(buf) )
		p_error("Lost the connection");
	his_win.cerase = buf[0];
	his_win.kill = buf[1];
	his_win.werase = buf[2];
}
Пример #4
0
/* Sinusoidal inverse equations--mapping x,y to lat,long 
  -----------------------------------------------------*/
int sininv(
double x,		/* (I) X projection coordinate */
double y,		/* (I) Y projection coordinate */
double *lon,		/* (O) Longitude */
double *lat)		/* (O) Latitude */
{
  double temp;		/* Re-used temporary variable */
  double mu, ml;
  double sin_phi, cos_phi;
/* Inverse equations
  -----------------*/
  x -= false_easting;
  y -= false_northing;
  
  if (ind != 0) /* Spherical */
    {
      *lat = y / R;
      if (fabs(*lat) > HALF_PI) 
	{
	  p_error("Input data error","sinusoidal-inverse");
	  return(164);
	}
      temp = fabs(*lat) - HALF_PI;
      if (fabs(temp) > EPSLN)
	{
	  temp = lon_center + x / (R * cos(*lat));
	  *lon = adjust_lon(temp);
	}
      else *lon = lon_center;
      return(OK);
    }
  else /* Ellipsoidal */
    {
      ml = y;
      mu = ml / (r_major * imu);
      *lat = mu + 
	(e2 * sin(2.0 * mu)) + 
	(e3 * sin(4.0 * mu)) + 
	(e4 * sin(6.0 * mu)) + 
	(e5 * sin(8.0 * mu));

      if (fabs(*lat) > HALF_PI) 
	{
	  p_error("Input data error","sinusoidal-inverse");
	  return(164);
	}
      temp = fabs(*lat) - HALF_PI;
      if (fabs(temp) > EPSLN)
	{
	  sin_phi = sin(*lat);
	  cos_phi = cos(*lat);
	  temp = lon_center + 
	    x * sqrt(1.0 - es * SQUARE(sin_phi)) / (r_major * cos_phi);
	  *lon = adjust_lon(temp);
	}
     else *lon = lon_center;
     return(OK);
   }
}
Пример #5
0
int
invite_remote (void)
{
  int new_sockt;
  struct itimerval itimer;
  CTL_RESPONSE response;

  itimer.it_value.tv_sec = RING_WAIT;
  itimer.it_value.tv_usec = 0;
  itimer.it_interval = itimer.it_value;
  if (listen (sockt, 5) != 0)
    p_error ("Error on attempt to listen for caller");

  msg.addr.sa_family = htons (my_addr.sin_family);
  memcpy (msg.addr.sa_data,
	  ((struct sockaddr *) &my_addr)->sa_data,
	  sizeof ((struct sockaddr *) & my_addr)->sa_data);

  msg.id_num = htonl (-1);	/* an impossible id_num */
  invitation_waiting = 1;
  announce_invite ();
  /*
   * Shut off the automatic messages for a while,
   * so we can use the interupt timer to resend the invitation
   */
  end_msgs ();
  setitimer (ITIMER_REAL, &itimer, (struct itimerval *) 0);
  message ("Waiting for your party to respond");
  signal (SIGALRM, re_invite);
  setjmp (invitebuf);
  while ((new_sockt = accept (sockt, 0, 0)) < 0)
    {
      if (errno == EINTR)
	continue;
      p_error ("Unable to connect with your party");
    }
  close (sockt);
  sockt = new_sockt;

  /*
   * Have the daemons delete the invitations now that we
   * have connected.
   */
  current_state = "Waiting for your party to respond";
  start_msgs ();

  msg.id_num = htonl (local_id);
  ctl_transact (my_machine_addr, msg, DELETE, &response);
  msg.id_num = htonl (remote_id);
  ctl_transact (his_machine_addr, msg, DELETE, &response);
  invitation_waiting = 0;

  return 0;
}
Пример #6
0
int p_close(p_team_t team)
{
    struct team *pteam = p_to_team(team);

    if (p_error(pteam))
            p_error(pteam);

    if (pteam->dev->dev_ops->close)
	    return pteam->dev->dev_ops->close(pteam->dev, pteam);

    return 0;
}
Пример #7
0
/*
 * Get simple payload from file
 */
int getpayload(char *path) {
    FILE *file;

    // open file
    if((file=fopen(path, "r"))==NULL)
        p_error("\nError opening payload file.\n");

    if(!fread(progopt.payload, 1, MAX_ARG*4-1, file))
        p_error("\nError reading  payload from file.\n");

    fclose(file);

    return 1;
}
Пример #8
0
/*
 * See if the local daemon has an invitation for us.
 */
int
check_local(void)
{
	CTL_RESPONSE response;
	CTL_RESPONSE *rp = &response;
	struct sockaddr addr;

	/* the rest of msg was set up in get_names */
#ifdef MSG_EOR
	/* copy new style sockaddr to old, swap family (short in old) */
	msg.ctl_addr = *(struct osockaddr *)&ctl_addr;
	msg.ctl_addr.sa_family = htons(ctl_addr.sin_family);
#else
	msg.ctl_addr = *(struct sockaddr *)&ctl_addr;
#endif
	/* must be initiating a talk */
	if (!look_for_invite(rp))
		return (0);
	/*
	 * There was an invitation waiting for us,
	 * so connect with the other (hopefully waiting) party
	 */
	current_state = "Waiting to connect with caller";
	do {
		if (rp->addr.sa_family != AF_INET)
			p_error("Response uses invalid network address");
		(void)memcpy(&addr, &rp->addr.sa_family, sizeof(addr));
		addr.sa_family = rp->addr.sa_family;
		addr.sa_len = sizeof(addr);
		errno = 0;
		if (connect(sockt, &addr, sizeof(addr)) != -1)
			return (1);
	} while (errno == EINTR);
	if (errno == ECONNREFUSED) {
		/*
		 * The caller gave up, but his invitation somehow
		 * was not cleared. Clear it and initiate an
		 * invitation. (We know there are no newer invitations,
		 * the talkd works LIFO.)
		 */
		ctl_transact(his_machine_addr, msg, DELETE, rp);
		close(sockt);
		open_sockt();
		return (0);
	}
	p_error("Unable to connect with initiator");
	/*NOTREACHED*/
	return (0);
}
Пример #9
0
/* open the ctl socket */
open_ctl() 
{
    int length;

    ctl_addr.sin_port = 0;
    ctl_addr.sin_addr = my_machine_addr;
    ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
    if (ctl_sockt <= 0)
	p_error("Bad socket");
    if (bind(ctl_sockt, (struct sockaddr *)&ctl_addr, sizeof(ctl_addr)) != 0)
	p_error("Couldn't bind to control socket");
    length = sizeof(ctl_addr);
    if (getsockname(ctl_sockt, (struct sockaddr *)&ctl_addr, &length) == -1)
	p_error("Bad address for ctl socket");
}
Пример #10
0
open_sockt()
{
    int length;

    my_addr.sin_addr = my_machine_addr;
    my_addr.sin_port = 0;
    sockt = socket(AF_INET, SOCK_STREAM, 0);
    if (sockt <= 0)
	p_error("Bad socket");
    if (bind(sockt, (struct sockaddr *)&my_addr, sizeof(my_addr)) != 0)
	p_error("Binding local socket");
    length = sizeof(my_addr);
    if (getsockname(sockt, (struct sockaddr *)&my_addr, &length) == -1)
	p_error("Bad address for socket");
}
Пример #11
0
/** Trade edit characters with the other talk. By agreement
 * the first three characters each talk transmits after
 * connection are the three edit characters.
 * A normal talk client uses tcgetattr() to get the chars,
 * but the daemon isn't connected to a terminal, so we can't call it.
 * We just send dummy chars, to disable control chars. */
void TalkConnection::set_edit_chars()
{
	char buf[3];
        int cc;
        buf[0] = buf[1] = buf[2] = (char)0xff;
        /* Write our config to the caller */
	cc = write(sockt, buf, sizeof(buf));
	if (cc != sizeof(buf) )
		p_error("Lost the connection");
        /* Read the caller configuration */
	cc = read(sockt, buf, sizeof(buf));
	if (cc != sizeof(buf) )
		p_error("Lost the connection");
	char_erase = buf[0]; // store it in TalkConnection
}
Пример #12
0
/* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  -----------------------------------------------------------------------*/
long lamazfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)
{
double delta_lon;	/* Delta longitude (Given longitude - center 	*/
double sin_delta_lon;	/* Sine of the delta longitude 			*/
double cos_delta_lon;	/* Cosine of the delta longitude 		*/
double sin_lat;		/* Sine of the given latitude 			*/
double cos_lat;		/* Cosine of the given latitude 		*/
double g;		/* temporary varialbe				*/
double ksp;		/* heigth above elipsiod			*/
char mess[60];

/* Forward equations
  -----------------*/
delta_lon = adjust_lon(lon - lon_center);
gctp_sincos(lat, &sin_lat, &cos_lat);
gctp_sincos(delta_lon, &sin_delta_lon, &cos_delta_lon);
g = sin_lat_o * sin_lat + cos_lat_o * cos_lat * cos_delta_lon;
if (g == -1.0) 
   {
   sprintf(mess, "Point projects to a circle of radius = %f\n", 2.0 * R);
   p_error(mess, "lamaz-forward");
   return(113);
   }
ksp = R * sqrt(2.0 / (1.0 + g));
*x = ksp * cos_lat * sin_delta_lon + false_easting;
*y = ksp * (cos_lat_o * sin_lat - sin_lat_o * cos_lat * cos_delta_lon) + 
	false_northing;
return(GCTP_OK);
}
Пример #13
0
/* Function to compute the latitude angle, phi2, for the inverse of the
   Lambert Conformal Conic and Polar Stereographic projections.
----------------------------------------------------------------*/
double phi2z
(
    double eccent,		/* Spheroid eccentricity		*/
    double ts,		/* Constant value t			*/
    long *flag		/* Error flag number			*/
)
{
    double eccnth;
    double phi;
    double con;
    double dphi;
    double sinpi;
    long i;

    *flag = 0;
    eccnth = .5 * eccent;
    phi = HALF_PI - 2 * atan(ts);
    for (i = 0; i <= 15; i++)
    {
        sinpi = sin(phi);
        con = eccent * sinpi;
        dphi = HALF_PI - 2 * atan(ts *(pow(((1.0 - con)/(1.0 + con)),eccnth))) 
             - phi;
        phi += dphi; 
        if (fabs(dphi) <= .0000000001)
            return(phi);
    }
    p_error ("Convergence error","phi2z-conv");
    *flag = 002;
    return(002);
}
Пример #14
0
/** Look for an invitation on remote machine */
int TalkConnection::look_for_invite(int mandatory)
{
    /* Check for invitation on caller's machine */
    ctl_transact(LOOK_UP, 0);

    uint8_t answer;
    uint32_t id_num;
    getResponseItems(&answer, &id_num, &lookup_addr);

    if (!mandatory) return 0;

    /* the switch is for later options, such as multiple invitations */
    switch (answer) {

	case SUCCESS:
            new_msg.id_num = htonl(id_num);
            old_msg.id_num = htonl(id_num);
            ktalk_debug("TalkConnection::look_for_invite : got SUCCESS");
            if (lookup_addr.ta_family != AF_INET)
                p_error("Response uses invalid network address");
            return (1);

	default:
            /* there wasn't an invitation waiting for us */
            ktalk_debug("TalkConnection::look_for_invite : didn't get SUCCESS");
            return (0);
    }
}
Пример #15
0
/* **************************************************************** */
long utmConversionInit(PointLla point)
{
	long zone = 0;
	double r_maj = 6378137;			// Magic Number: These are the values
	double r_min = 6356752.3142;	// needed for the UTM ellipsoid
	double scale_fact = .9996;
//	long val;
	
	if(point->longitudeRadians > PI || point->longitudeRadians < -PI)
	{
		p_error("Invalid Seed Point for UTM Init. Check Radians??","");
		return(-1);
	}

	zone = calc_utm_zone(point->longitudeRadians*R2D);

	// Check if the zone is different than what was done before
	if(zone != utmLibZone)
	{		
		if(utmforint(r_maj, r_min, scale_fact, zone) != OK) return -1;
		if(utminvint(r_maj, r_min, scale_fact, zone) != OK) return -1;
		
		utmLibInitFlag = 1;
		utmLibZone = zone;
		return OK;
	}
	else
	{
		// Zone is the same, no need to re-init
		return OK;
	}
}
Пример #16
0
// Sinusoidal inverse equations--mapping x,y to lat,long 
long Projectoid::sininv(
double x,               // (I) X projection coordinate
double y,               // (I) Y projection coordinate
double *lon,            // (O) Longitude
double *lat)            // (O) Latitude
{
double temp;            // Re-used temporary variable

// Inverse equations
x -= false_easting;
y -= false_northing;
*lat = y / R;
if (fabs(*lat) > HALF_PI) 
	{
	p_error("Input data error", "sinusoidal-inverse");
	return(164);
	}
temp = fabs(*lat) - HALF_PI;
if (fabs(temp) > EPSLN)
	{
	temp = lon_center + x / (R * cos(*lat));
	*lon = adjust_lon(temp);
	}
else
	*lon = lon_center;

return(OK);

}
Пример #17
0
/*
 * See if the local daemon has a invitation for us
 */
check_local()
{
	CTL_RESPONSE response;

	/* the rest of msg was set up in get_names */
	msg.ctl_addr = ctl_addr;
	/* must be initiating a talk */
	if (!look_for_invite(&response))
		return (0);
	/*
	 * There was an invitation waiting for us, 
	 * so connect with the other (hopefully waiting) party 
	 */
	current_state = "Waiting to connect with caller";
again:
	swapresponse(&response);
	if (connect(sockt, &response.addr, sizeof(response.addr)) != -1)
		return (1);
	if (errno == EINTR)
		goto again;
	if (errno == ECONNREFUSED) {
		/*
		 * The caller gave up, but his invitation somehow
		 * was not cleared. Clear it and initiate an 
		 * invitation. (We know there are no newer invitations,
		 * the talkd works LIFO.)
		 */
		ctl_transact(his_machine_addr, msg, DELETE, &response);
		close(sockt);
		open_sockt();
		return (0);
	}
	p_error("Unable to connect with initiator");
	/*NOTREACHED*/
}
Пример #18
0
int is_dir(char *url)
{
	struct stat st;
	if(stat(url,&st)<0)
		p_error("error in is_dir logic error",5);
	return S_ISDIR(st.st_mode)?1:0;
}
Пример #19
0
/* Function to compute latitude, phi3, for the inverse of the Equidistant
   Conic projection.
-----------------------------------------------------------------*/
double phi3z
(
    double ml,		/* Constant 			*/
    double e0,		/* Constant			*/
    double e1,		/* Constant			*/
    double e2,		/* Constant			*/
    double e3,		/* Constant			*/
    long *flag		/* Error flag number		*/
)
{
    double phi;
    double dphi;
    long i;

    phi = ml;
    for (i = 0; i < 15; i++)
    {
        dphi = (ml + e1 * sin(2.0 * phi) - e2 * sin(4.0 * phi) + e3 * 
                sin(6.0 * phi)) / e0 - phi;
        phi += dphi;
        if (fabs(dphi) <= .0000000001)
        {
            *flag = 0;
            return(phi);
        }
    }
    p_error("Latitude failed to converge after 15 iterations","PHI3Z-CONV");
    *flag = 3;
    return(3);
}
Пример #20
0
/* General Vertical Near-Side Perspective forward equations--mapping 
   lat,long to x,y
  ----------------------------------------------------------------*/
long gvnspfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)

{
double dlon;
double sinphi,cosphi;
double coslon;
double g;
double ksp;

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
gctp_sincos(lat,&sinphi,&cosphi);
coslon = cos(dlon);
g = sin_p15 * sinphi + cos_p15 * cosphi * coslon;
if (g < (1.0/ p))
   {
   p_error("Point cannot be projected","gvnsp-for");
   return(153);
   }
ksp = (p - 1.0)/(p - g);
*x = false_easting + R * ksp * cosphi * sin(dlon);
*y = false_northing + R * ksp * (cos_p15 * sinphi - sin_p15 * cosphi * coslon);

return(GCTP_OK);
}
Пример #21
0
/* Wagner IV forward equations--mapping lat,long to x,y
  ----------------------------------------------------*/
long wivfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)
{
double delta_lon;	/* Delta longitude (Given longitude - center */
double theta;
double delta_theta;
double con;
long i;

/* Forward equations
  -----------------*/
delta_lon = adjust_lon(lon - lon_center);
theta = lat;
con = 2.9604205062 * sin(lat);

/* Iterate using the Newton-Raphson method to find theta
  -----------------------------------------------------*/
for (i=0;;i++)
   {
   delta_theta = -(theta + sin(theta) - con) / (1.0 + cos(theta));
   theta += delta_theta;
   if (fabs(delta_theta) < EPSLN) break;
   if (i >= 30) p_error("Iteration failed to converge","wagneriv-forward");
   }
theta /= 2.0;
*x = 0.86310 * R * delta_lon * cos(theta) + false_easting;
*y = 1.56548 * R * sin(theta) + false_northing;
return(GCTP_OK);
}
Пример #22
0
/* Universal Transverse Mercator forward equations--mapping lat,long to x,y
   Note:  The algorithm for UTM is exactly the same as TM and therefore
	  if a change is implemented, also make the change to TMFOR.c
  -----------------------------------------------------------------------*/
long utmfor
(
    double lon,			/* (I) Longitude 		*/
    double lat,			/* (I) Latitude 		*/
    double *x,			/* (O) X projection coordinate 	*/
    double *y			/* (O) Y projection coordinate 	*/
)
{
    double delta_lon;	/* Delta longitude (Given longitude - center 	*/
    double sin_phi, cos_phi;/* sin and cos value				*/
    double al, als;		/* temporary values				*/
    double b;		/* temporary values				*/
    double c, t, tq;	/* temporary values				*/
    double con, n, ml;	/* cone constant, small m			*/

    /* Forward equations
      -----------------*/
    delta_lon = adjust_lon(lon - lon_center);
    gctp_sincos(lat, &sin_phi, &cos_phi);

    /* This part was in the fortran code and is for the spherical form
    ----------------------------------------------------------------*/
    if (ind != 0)
    {
        b = cos_phi * sin(delta_lon);
        if ((fabs(fabs(b) - 1.0)) < .0000000001)
        {
            p_error("Point projects into infinity","utm-for");
            return(93);
        }
        else
        {
            *x = .5 * r_major * scale_factor * log((1.0 + b)/(1.0 - b));
            con = acos(cos_phi * cos(delta_lon)/sqrt(1.0 - b*b));
            if (lat < 0)
                con = - con;
            *y = r_major * scale_factor * (con - lat_origin);
            return(GCTP_OK);
        }
    }

    al  = cos_phi * delta_lon;
    als = SQUARE(al);
    c   = esp * SQUARE(cos_phi);
    tq  = tan(lat);
    t   = SQUARE(tq);
    con = 1.0 - es * SQUARE(sin_phi);
    n   = r_major / sqrt(con);
    ml  = r_major * mlfn(e0, e1, e2, e3, lat);

    *x  = scale_factor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 *
                                   (5.0 - 18.0 * t + SQUARE(t) + 72.0 * c - 58.0 * esp))) + false_easting;

    *y  = scale_factor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 *
                          (5.0 - t + 9.0 * c + 4.0 * SQUARE(c) + als / 30.0 * (61.0 - 58.0 * t
                                  + SQUARE(t) + 600.0 * c - 330.0 * esp))))) + false_northing;

    return(GCTP_OK);
}
Пример #23
0
Value* Scope::newVar(const char* n) {
  if ( numvar >= MAX_SCOPE_VARS-1 ) {
    printf("Scope layer has too much variables: %d [max: %d]\n", numvar, MAX_SCOPE_VARS );
    printf("DUMPING SCOPE:\n");
    dump();
    p_error("DONE");
  }

  if ( getVar(n) != NULL )
    p_error("Variable %s has already been declared in this scope.", n );

  Value* res = new Value((long int)0);
  val[numvar] = res;
  name[numvar] = n;
  numvar++;
  return res;
}
Пример #24
0
static void sndcmd(const char *line )
{
	char *buf;

	if ( (buf=strstr( line, " " )) ) {
		gp_tell( port, "%s\n", buf+1 );
	} else
		p_error( "no command given" );
}
Пример #25
0
/*
 * See if the local daemon has an invitation for us.
 */
int
check_local()
{
	CTL_RESPONSE response;
	register CTL_RESPONSE *rp = &response;

	/* the rest of msg was set up in get_names */
	msg.ctl_addr.sa_family = htons (ctl_addr.sin_family);
	memcpy (msg.ctl_addr.sa_data,
		((struct sockaddr *)&ctl_addr)->sa_data,
		sizeof ((struct sockaddr *)&ctl_addr)->sa_data);

	/* must be initiating a talk */
	if (!look_for_invite(rp))
		return (0);
	/*
	 * There was an invitation waiting for us,
	 * so connect with the other (hopefully waiting) party
	 */
	current_state = "Waiting to connect with caller";
	do {
		if (rp->addr.sa_family != AF_INET)
			p_error("Response uses invalid network address");
		errno = 0;
		if (connect(sockt,
		    (struct sockaddr *)&rp->addr, sizeof (rp->addr)) != -1)
			return (1);
	} while (errno == EINTR);
	if (errno == ECONNREFUSED) {
		/*
		 * The caller gave up, but his invitation somehow
		 * was not cleared. Clear it and initiate an
		 * invitation. (We know there are no newer invitations,
		 * the talkd works LIFO.)
		 */
		ctl_transact(his_machine_addr, msg, DELETE, rp);
		close(sockt);
		open_sockt();
		return (0);
	}
	p_error("Unable to connect with initiator");
	/*NOTREACHED*/
}
Пример #26
0
int TalkConnection::open_socket (struct sockaddr_in *addr, int type)
{
    addr->sin_family = AF_INET;
    addr->sin_addr = my_machine_addr;
    addr->sin_port = 0;
    int newSocket = socket (PF_INET, type, 0);
    if (newSocket <= 0)
        p_error ("Unable to open a new socket!");

    ksize_t length = sizeof (*addr);
    if (bind (newSocket, (struct sockaddr *) addr, length) != 0) {
        ::close (newSocket);
        p_error ("Error binding socket!");
    }
    if (getsockname (newSocket, (struct sockaddr *) addr, &length) == -1) {
        ::close (newSocket);
        p_error ("New socket has a bad address!");
    }
    return newSocket;
}
Пример #27
0
void Context::popscope() {    
#ifdef __DEBUG__
  printf("Context::popscope\n");
#endif

  if ( numscope <= 0 )
    p_error("Scope depth underloaded" );

  numscope--;
  scopes[numscope].clean();
}
Пример #28
0
/*
 * The routine to do the actual talking
 */
void
talk()
{
	register int read_template, sockt_mask;
	int read_set, nb;
	char buf[BUFSIZ];
	struct timeval wait;

	message("Connection established\007\007\007");
	current_line = 0;
	sockt_mask = (1<<sockt);

	/*
	 * Wait on both the other process (sockt_mask) and 
	 * standard input ( STDIN_MASK )
	 */
	read_template = sockt_mask | STDIN_MASK;
	forever {
		read_set = read_template;
		wait.tv_sec = A_LONG_TIME;
		wait.tv_usec = 0;
		nb = select(32, (fd_set *)&read_set, 0, 0, &wait);
		if (nb <= 0) {
			if (errno == EINTR) {
				read_set = read_template;
				continue;
			}
			/* panic, we don't know what happened */
			p_error("Unexpected error from select");
			quit();
		}
		if (read_set & sockt_mask) { 
			/* There is data on sockt */
			nb = read(sockt, buf, sizeof buf);
			if (nb <= 0) {
				message("Connection closed. Exiting");
				quit();
			}
			display(&his_win, buf, nb);
		}
		if (read_set & STDIN_MASK) {
			/*
			 * We can't make the tty non_blocking, because
			 * curses's output routines would screw up
			 */
			ioctl(0, FIONREAD, (struct sgttyb *) &nb);
			nb = read(0, buf, nb);
			display(&my_win, buf, nb);
			/* might lose data here because sockt is non-blocking */
			write(sockt, buf, nb);
		}
	}
}
Пример #29
0
/** Accept a connection from another talk client */
int TalkConnection::accept()
{
    int accept_sockt;
    while ((accept_sockt = ::accept(sockt, 0, 0)) < 0) {
        if (errno == EINTR)
            continue;
        p_error("Unable to connect with your party");
    }
    ::close(sockt);
    sockt = accept_sockt;
    return sockt;
}
Пример #30
0
static void padjfi(const char *line )
{
	int g;

	if ( sscanf( line, "%*s %d", &g )!=EOF ) {
		if ( 0 < g && g <= status.curgen ) {
			printf( "adjf[i] = %e\n", adjfitnessi( run[g-1].besti ) );
		} else
			fprintf( stderr, "individual must lie in [1,%d]\n", status.curgen );
	} else
		p_error( "no individual" );
}