示例#1
0
文件: check_line.c 项目: Fusiow/msh
int		check_line(char *str)
{
	t_error		err;
	int			i;

	err_init(&err);
	i = 0;
	while (str[i])
	{
		if (str[i] == '"' && str[i - 1] != '\\')
			err.dquote = dquote_check(str, &i);
		else if (str[i] == '\'' && str[i] != '\\')
			err.squote = squote_check(str, &i);
		else if (str[i] == '`' && str[i - 1] != '\\')
			err.bquote = bquote_check(str, &i);
		else if (str[i] == '|' && str[i - 1] != '\\')
			err.pipe = p_check(str, &i);
		else if (str[i] == '(' || str[i] == ')')
			err.par = check_par(str, &i);
		++i;
	}
	if (err.par == 2 || err.redir == 2)
		return (2);
	if (err.dquote == 1 || err.squote == 1 || err.pipe == 1
			|| err.bquote == 1 || err.par == 1)
		return (1);
	return (0);
}
示例#2
0
vec vec::turn_new(const vec& dir, vfloat angle) {
  pvecerror("vec turn(vec& dir, vfloat& angle)");
  if (length(*this) == 0) return vec(0, 0, 0);
  if (check_par(*this, dir, 0.0) !=0) {
    // parallel vectors are not changed
    return *this;
  }
  vfloat dirlen = length(dir);
  check_econd11a(dirlen, ==0, "cannot turn around zero vector", mcerr); 
  vec u = dir / dirlen;    // unit vector
  vec constcomp = u*(*this) * u;
  //vec  perpcomp = (*this) - constcomp;
  //vfloat len=length(perpcomp);
  vec ort1 = unit_vec( u || (*this) );
  vec ort2 = ort1 || u;
  vec  perpcomp = ort2 * (*this) * ort2;
  vfloat len = length(perpcomp);
  //mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2;
  ort1 = sin(angle) * len * ort1;
  ort2 = cos(angle) * len * ort2;
  //mcout<<" constcomp="<<constcomp<<" ort1="<<ort1<<" ort2="<<ort2
  //    <<" len="<<len<<" sin(angle)="<<sin(angle)<<" cos(angle)="<<cos(angle)
  //    <<" angle="<<angle<<'\n';
  return constcomp + ort1 + ort2;

}
示例#3
0
int apeq(const plane &pl1, const plane &pl2, vfloat prec)
{
  pvecerror("int apeq(const plane &pl1, const plane &pl2, vfloat prec)");
  if( check_par( pl1.dir, pl2.dir, prec) == 0 ) return 0;
  if( apeq( pl1.piv , pl2.piv, prec) == 1) return 1;
  if( pl1.check_point_in(pl2.piv, prec) == 1 ) return 1;
  else return 0;
}
int main(int argc, char *argv[]) {
    int i;

    init();                                 /* Init some variables (like malloc timestamp string, encrypt text string, etc.) */

    check_par(argc, argv);                  /* Check command arguments number */
    open_config(argv);                      /* Open config file and check if it failed */
    open_log(argv);                         /* Open log file and check if it failed */

    get_ipaddr();                           /* Get server IP address */

    create_socket();                        /* Create a socket */
    bind_socket();                          /* Bind the socket */
    listen_socket();                        /* Listen at the socket */

    print_server_info();                    /* Print server information */

    while (TRUE) {                          /* Read until the end of file */
        if (read_flag) {
            if (fscanf(fcfg, "%s", enc_txt) == EOF) {
                finish_flag = 1;
                break;
            } else {
                fscanf(fcfg, "%s", dec_txt);
            }
        }
        read_flag = 0;

        init_select();                      /* Select function */
        if (select_func() == -1) break;

        for (i = 0; i < max_fds + 1; i++) {
            if (FD_ISSET(i, &rfds)) {
                if (i == sockfd) {                              /* If have a new client connect */
                    if (accept_new_cli() == -1) break;          /* Try to accept new client */
                    if (check_connect() == -1) break;           /* Check connect message from client */
                    if (print_client_info() == -1) break;       /* Print the information of client side */
                    store_client_ip();                          /* Store the client ip address */
                    break;
                } else {                                        /* If have new message from client side */
                    client_ip = get_host_by_sockfd(i);          /* Get the client ip address by socket */
                    recv_socket_msg(i, recv_mark);              /* Get the message from socket */
                    handle_client_msg(i);                       /* Handle client message (SUCCESS_MSG, FAILURE_MSG, DISPATCH_MSG, etc.) */
                    break;
                }
            }
            if (main_flag == EXIT_FAILURE) break;
        }
        if (main_flag == EXIT_FAILURE) break;
    }

    remained_cli = ask_clients_quit();                          /* Ask clients quit and count the remain clients number */
    wait_clients_quit();                                        /* Wait for all clients quit */
    quit_server();                                              /* Clean up and quit server, also print the message to log */

    return main_flag;
}
示例#5
0
vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal) {
  pvecerror(
  "vfloat ang2projvec(const vec& r1, const vec& r2, const vec& normal)");
  vec rt1 = project_to_plane(r1, normal);
  vec rt2 = project_to_plane(r2, normal);
  if (rt1 == dv0 || rt2 == dv0) {
    vecerror = 1; return 0;
  }
  vfloat tang = ang2vec(rt1, rt2);
  if (tang == 0) return tang;  // projections are parallel 
  vec at = rt1 || rt2;
  int i = check_par(at, normal, 0.0001);
  //mcout<<"r1="<<r1<<"r2="<<r2<<"normal="<<normal
  //     <<"rt1="<<rt1<<"rt2="<<rt2<<"\ntang="<<tang
  //     <<"\nat="<<at<<" i="<<i<<'\n';
  if (i == -1) return 2.0 * M_PI - tang;
  return tang; // it works if angle <= PI
} 
示例#6
0
int plane::cross(const polyline &pll, point *crpt, int& qcrpt, 
		 polyline *crpll, int& qcrpll, vfloat prec) const 
{
  pvecerror("int plane::cross(polyline &pll, ...");

  int n;
  qcrpt=0;
  qcrpll=0;
  for(n=0; n<pll.qsl; n++)
  {
    point cpt=cross(pll.sl[n]);
    if(vecerror == 3) // the line is in the plane
      crpll[qcrpll++]=polyline(&(pll.pt[n]), 2);
    else if(vecerror != 0)
      vecerror=0;
    else
    {
      vec v1=cpt-pll.pt[n];
      if(length(v1) < prec)
      {
	if(n == 0) // otherwise it is probably included on the previous step
	{
	  crpt[qcrpt++]=cpt;
	}
      }
      else
      {
	vec v2=cpt-pll.pt[n+1];
	if(length(v2) < prec)
	  crpt[qcrpt++]=cpt;
	else if(check_par( v1 , v2, prec ) == -1 ) 
	        // anti-parallel vectors, point inside borders
	  crpt[qcrpt++]=cpt;
      }
    }
  }
  if(qcrpt>0 || qcrpll>0)
    return 1;
  else
    return 0;
}
示例#7
0
straight plane::cross(const plane &pl) const 
{
  pvecerror("point plane::cross(plane &pl)");
  point plpiv=pl.Gpiv();
  vec pldir=pl.Gdir();
  vec a=dir || pldir; //direction of the overall straight lines
  if(length(a)==0)
  {
    if(plpiv == piv || check_par(pldir, dir, 0.0)!=0)
    {       // planes coinsides
      vecerror=3; return straight();
    }
    else
    {
//		cerr<<"plane::cross : straight is parallel to plane\n";
      vecerror=2; return straight();
    }
  }
  a=unit_vec(a);
  vec c=a || dir;  //perpend. for ov. str.
  straight st(piv,c);
  point pt=pl.cross(st);   //one point on ov. str.
  return straight(pt,a);     //overall straight
}
示例#8
0
int splane::range(const trajestep& fts, vfloat* crange, point* cpt,
                  int* s_ext) const {
  mfunname("int splane::range(...)");
  if (fts.s_range_cf == 0) {
    // straight line
    point pt = pn.cross(straight(fts.currpos, fts.dir));
    if (vecerror != 0) {
      vecerror = 0;
      return 0;
    }
    vfloat rng = length(pt - fts.currpos);
    if (pt == fts.currpos || check_par(pt - fts.currpos, fts.dir, 0.01) == 1) {
        //                                   looks like not matter ^
      // otherwise the point is behind plane
      if (fts.mrange >= rng) {
        // otherwise it can not reach the plane
        cpt[0] = pt;
        crange[0] = rng;
        vfloat t = cos2vec(fts.dir, dir_ins);
        if (t < 0)
          s_ext[0] = 1;
        else if (t > 0)
          s_ext[0] = 0;
        else
          s_ext[0] = 2;
        return 1;
      }
      return 0;
    } else
      return 0;
  } else {
    point pt[2];
    circumf cf(fts.currpos + fts.relcen,
               fts.dir || fts.relcen,  // if to us, moving against clock
               length(fts.relcen));
    int q = cf.cross(pn, pt, 0.0);
    if (q == -1)  // total circle lyes in the plane
        {
      cpt[0] = fts.currpos;
      crange[0] = 0.0;
      s_ext[0] = 2;
      return 1;
    }
    if (q == 0) return 0;
    if (q == 1) {
      vec r1 = -fts.relcen;
      vec r2 = pt[0] - cf.Gpiv();
      vfloat angle = ang2projvec(r1, r2, cf.Gdir());
      vfloat rng = cf.Grad() * angle;
      if (fts.mrange >= rng) {
        cpt[0] = pt[0];
        crange[0] = rng;
        vfloat c = cos2vec(dir_ins, fts.relcen);
        if (angle == 0.0) {
          // cross in the current point
          if (c > 0)
            s_ext[0] = 0;
          else if (c < 0)
            s_ext[0] = 1;
          else
            s_ext[0] = 2;
        } else {
          if (c > 0)
            s_ext[0] = 1;
          else if (c < 0)
            s_ext[0] = 0;
          else
            s_ext[0] = 2;
        }
        return 1;
      } else
        return 0;
    }
    if (q == 2) {
      int qq = 0;
      vec r = -fts.relcen;
      vec vcr[2];
      vcr[0] = pt[0] - cf.Gpiv();
      vcr[1] = pt[1] - cf.Gpiv();
      vfloat angle[2];
      angle[0] = ang2projvec(r, vcr[0], cf.Gdir());
      angle[1] = ang2projvec(r, vcr[1], cf.Gdir());
      if (angle[0] > angle[1]) {  // ordering
        vfloat a = angle[0];
        angle[0] = angle[1];
        angle[1] = a;
        point p = pt[0];
        pt[0] = pt[1];
        pt[1] = p;
      }
      vfloat rng;
      rng = cf.Grad() * angle[0];
      if (fts.mrange >= rng) {
        // find out what the first point means
        int ins = 0;  // 1 if the point inside and exits
        vec td = fts.dir;
        td.turn(cf.Gdir(), angle[0]);  // local dir in the crossing point
        vfloat t = cos2vec(td, dir_ins);
        if (t < 0)
          ins = 1;  // means the point was inside and now exiting
        else
          ins = 0;
        cpt[0] = pt[0];
        crange[0] = rng;
        s_ext[0] = ins;
        qq++;
        rng = cf.Grad() * angle[1];
        if (fts.mrange >= rng) {
          cpt[1] = pt[1];
          crange[1] = rng;
          s_ext[1] = (ins == 0 ? 1 : 0);
          qq++;
        }
      }
      return qq;
    }
  }
  return 0;
}