Exemplo n.º 1
0
int main(void)
{
	unsigned long i,j,ji;
	float x,*xx;

	xx=vector(1,N);
	/* create array to be searched */
	for (i=1;i<=N;i++)
		xx[i]=exp(i/20.0)-74.0;
	printf("\n  result of:   j=0 indicates x too small\n");
	printf("%14s j=100 indicates x too large"," ");
	printf("\n%12s %8s %4s %11s %13s \n",
		"locate:","guess","j","xx(j)","xx(j+1)");
	/* do test */
	for (i=1;i<=19;i++) {
		x = -100.0+10.0*i;
		/* trial parameter */
		j=(ji=5*i);
		/* begin search */
		hunt(xx,N,x,&j);
		if ((j < N) && (j > 0))
			printf("%12.5f %6lu %6lu %12.6f %12.6f \n",
				x,ji,j,xx[j],xx[j+1]);
		else if (j == N)
			printf("%12.5f %6lu %6lu %12.6f %s \n",
				x,ji,j,xx[j],"   upper lim");
		else
			printf("%12.5f %6lu %6lu %s %12.6f \n",
				x,ji,j,"   lower lim",xx[j+1]);
	}
	free_vector(xx,1,N);
	return 0;
}
Exemplo n.º 2
0
/* Start function. It may be called from the start script as well as from
   the OSE shell directly (using late start hooks). It spawns epmd as an
   OSE process which calls the epmd main function. */
int start_ose_epmd(int argc, char **argv) {
  union SIGNAL *sig;
  PROCESS epmd_;
  OSENTRYPOINT ose_epmd;
  int i;

  if(hunt("epmd", 0, &epmd_, NULL)) {
    fprintf(stderr, "Warning! EPMD already exists (%u).\n", epmd_);
    return 0;
  }
  else {
    /* copy start args to signal */
    sig = alloc(sizeof(struct args_sig), 0);
    sig->args.argc = argc;
    for(i=0; i<argc; i++) {
      strcpy((sig->args.argv)[i], argv[i]);
    }    
    /* start epmd and send signal */
    epmd_ = create_process(OS_BG_PROC, /* processtype */
			   "epmd",      /* name        */
			   ose_epmd,    /* entrypoint  */
			   16383,	/* stacksize   */
			   20,	        /* priority    */
			   0,	        /* timeslice   */
			   0,	        /* block       */
			   NULL,0,0);   /* not used    */
    efs_clone(epmd_);
    start(epmd_);
    send(&sig, epmd_);	
#ifdef DEBUG
    printf("EPMD ID: %li\n", epmd_);
#endif
  }
  return 0;
}
Exemplo n.º 3
0
void Y_digitize(int nArgs)
{
  long number, origin, nbins, i, ip;
  double *x, *bins;
  Dimension *dimsx, *dimsb;
  long *ibin;
  if (nArgs!=2) YError("digitize takes exactly two arguments");

  bins= YGet_D(sp, 0, &dimsb);
  x= YGet_D(sp-1, 0, &dimsx);

  if (!dimsb || dimsb->number<2 || dimsb->next)
    YError("2nd argument to digitize must be 1D with >=2 elements");
  nbins= dimsb->number;
  origin= dimsb->origin;
  number= TotalNumber(dimsx);

  if (dimsx) {
    Array *array= PushDataBlock(NewArray(&longStruct, dimsx));
    ibin= array->value.l;
  } else {
    PushLongValue(0L);
    ibin= &sp->value.l;
  }
  ip= 0;
  for (i=0 ; i<number ; i++)
    ibin[i]= ip= origin+hunt(bins, nbins, x[i], ip);
}
Exemplo n.º 4
0
void TankAI::brainTick(float seconds) {

	//listen closely and watch out for enemies.
	sense();

	//take a decision
	if (_currentTarget == NULL && _strategy != EXPLORE) {
		switchStrategy(EXPLORE, NULL);
	} else if (_currentTarget != NULL && _strategy != HUNT) {
		switchStrategy(HUNT, _currentTarget);
		delete _path;
		_path = NULL;
	}

	//do what you decided to do
	switch (_strategy) {
	case HUNT: {
		hunt();
		break;
	}
	case EXPLORE: {
		explore();
		break;
	}
	case ESCAPE: {
		escape();
		break;
	}
	}

}
Exemplo n.º 5
0
void Enemy::step() {
	player_visible = !player->dead && world()->level->visible(shared_from_this(), std::static_pointer_cast<Entity>(player));
	player_distance = Game::distance(shared_from_this(), std::static_pointer_cast<Entity>(player));

	if(!attack) {
		scope();
		if(alert)
			hunt();
		else wander();
	}

	walking();
	worldCollision();

	dy += gravity;

	if(alert && frame==0) frame = 5;
	if(attack)
		shoot();

	processEntities();

	light->setPosition(sf::Vector2f(x,y));

	sprite.setPosition(round(x),round(y));
	sprite.setScale(facing_right?1.0:-1.0,1.0);
	sprite.setTextureRect(sf::IntRect(frame*24,0,24,24));
}
Exemplo n.º 6
0
/****************************************************************
 * Generate Maze
 ****************************************************************/
void PhotoMaze :: huntAndKill(){
    Vec2D<int> startPos((int)(ofRandom(1)*rw), (int)(ofRandom(1)*rh));
    while (startPos.x != -1) {
        rWalk(startPos);
        startPos = hunt();
    }
    fillImage();
}
Exemplo n.º 7
0
int hhsetput(HHSet *S, ulong x) {
  if (x == 0) return 0;
  ulong h = S->hash(x);
  if (hunt(S, h, x, 0)) return 1;
  if (hhashput(S->T, h, x)) return 1;
  if (!resize(S)) return 0;
  return hhashput(S->T, h, x);
}
Exemplo n.º 8
0
void interp_henke (henke_file *h,float energy, float *f1, float *f2) {
  static int index=0;
  float t;
  energy*=1000.0;
  hunt((h->energy)-1,h->n_entries,energy,&index);
  index=(index==0)?0:index-1;
  t=(energy - h->energy[index])/(h->energy[index+1] - h->energy[index]);
  *f1 = t * h->f1[index+1] + (1.0-t) * h->f1[index];
  *f2 = t * h->f2[index+1] + (1.0-t) * h->f2[index];
}
Exemplo n.º 9
0
 double hunt ( // finds root f_(x_) = y_ in (p_, q_)
 double y_, // f_ (x_) = y_
 double (*f_) (double x_), // function 
 double p_, // end-point
 double q_, // end-point
 double tol_, // absolute tolerance
 double rtol_, // relative tolerance
 Int4 *itmax_) // maximum # of permitted iterations
 {
    s_f = f_;
    return hunt (y_, f, ZERO, p_, q_, tol_, rtol_, itmax_);
 }
Exemplo n.º 10
0
void linint(int n, double *x, double *y, double x_, double *y_, int *j)
{
    double h, b, a;

    hunt(n, x, x_, j);
    
    h = x[*j+1] - x[*j];
    a = (x[*j+1] - x_) / h;
    b = (x_ - x[*j]) / h;
    *y_ = a * y[*j] + b * y[*j+1];

}
Exemplo n.º 11
0
int start_erl(int argc, char **argv) {
  union SIGNAL *sig;
  PROCESS erts_;
  OSENTRYPOINT erts;

  if(hunt("erts", 0, NULL, NULL)) {
    erl_dbg_fprintf(stderr, "ERROR: erts already running\n");
    return 0;
  }

  erl_block = get_bid(erl_tmp_);
  erl_dbg_fprintf(stdout, "Erlang block id: %li\n", (unsigned long)erl_block);
  fflush(stderr);

  /* initialise DNS service, needed for distributed Erlang */
  config_dns();

  erl_argc = argc;
  erl_argv = argv;		/* so that erts may copy the struct */

  /* used by erts to detect shutdown of ose shell (interactive mode only) */
  erlang_starter_ = current_process(); 

  /* create and start the erlang emulator as ose process "erts" */
  erts_ = create_process(OS_BG_PROC, /* processtype */
			 "erts", /* name        */
			 erts,	 /* entrypoint  */
			 524288, /* stacksize   */
			 20,	 /* priority (if OS_PRI_PROC) */
			 0,	 /* timeslice */
			 erl_block, /* block */
			 NULL,0,0); /* not used    */

  set_fsem((OSFSEMVAL) 0, current_process());

  efs_clone(erts_);
  start(erts_);

  /* sync with erts, this function must not return until erts has copied argv */
  wait_fsem((OSFSEMVAL) 1);

  /* in interactive mode the ose shell will "hang", waiting for erts to terminate */
  if(!start_detached) {	
    static const SIGSELECT recv_attach_sig[2] = {1, OS_ATTACH_SIG};
    erl_dbg_fprintf(stdout, "erts started in interactive mode\n");
    attach(NULL, erts_);
    sig = receive((SIGSELECT*)recv_attach_sig);
    erl_dbg_fprintf(stderr, "\n*** Erlang finished ***\n");
    free_buf(&sig);
  }
  return 0;

}
Exemplo n.º 12
0
void splint(int n, double *x, double *y, double *y2,
	    double x_, double *y_, int *j)
{

    double h, b, a;

    hunt(n, x, x_, j);
    
    h = x[*j+1] - x[*j];
    a = (x[*j+1] - x_) / h;
    b = (x_ - x[*j]) / h;
    *y_ = a * y[*j] + b * y[*j+1]
	+ ((a*a*a-a) * y2[*j] + (b*b*b-b) * y2[*j+1]) * (h*h) / 6.0;

}
Exemplo n.º 13
0
int		handle_followers(t_player *player, char **map, t_target *target)
{
  if (listen_chief(target, player->team + 2))
    {
      manage_ressources(UNLOCK);
      return 1;
    }
  if (wannabe_lead(player))
    {
      manage_ressources(UNLOCK);
      return 2;
    }
  hunt(player, target, map);
  return 0;
}
Exemplo n.º 14
0
int		handle_leader(t_player *player, char **map, t_target *target)
{
  int		ret;

  ret = 0;
  if (count_followers(map, player->team) >= 1 &&
      !(ret = determ_target(target, player, map, 1)))
    {
      stop_process(player, map);
      manage_ressources(UNLOCK);
      return 1;
    }
  if (ret > 0)
    {
      lead_team(target, count_followers(map, player->team));
      hunt(player, target, map);
    }
  return 0;
}
Exemplo n.º 15
0
void
main_loop (std::vector<Mosquito>& _swarm, Dragonfly& _dragonfly)
{
	is_active = true;
	SDL_Event event;

	while (!done)
	{
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_ACTIVEEVENT:
					if (event.active.state == SDL_APPACTIVE )
						is_active = (event.active.gain != 0);
				break;

				case SDL_QUIT:
					done = true; 
				break;

				default:
				break;
			}
		}

			
		if (is_active)
		{
			_swarm = step(_swarm, _dragonfly);
			_dragonfly.velocity += hunt(_dragonfly, _swarm);
			if (_dragonfly.velocity.length() > 0.2)
				_dragonfly.velocity /= 10.0f;
			_dragonfly.position += _dragonfly.velocity;

			draw_scene(_swarm, _dragonfly);
			SDL_GL_SwapBuffers();
		}
	}
}
Exemplo n.º 16
0
void HuntAndKillMaze::generate()
{
	m_visited = QVector< QVector<bool> >(columns(), QVector<bool>(rows()));
	m_unvisited = columns() * rows();

	QPoint current(0, randomInt(rows()));
	m_visited[current.x()][current.y()] = true;
	m_unvisited--;

	QPoint neighbor;
	while (m_unvisited) {
		neighbor = randomNeighbor(m_visited, current);
		if (neighbor.x() != -1) {
			mergeCells(current, neighbor);
			current = neighbor;
			m_unvisited--;
		} else {
			current = hunt();
		}
	}

	m_visited.clear();
}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
	char *system = NOSTR;
	int i;
	char *p;
	char sbuf[15];

	gid = getgid();
	egid = getegid();
	uid = getuid();
	euid = geteuid();
	if (equal(sname(argv[0]), "cu")) {
		cumode = 1;
		cumain(argc, argv);
		goto cucommon;
	}

	if (argc > 4) {
		(void) fprintf(stderr,
		    "usage: tip [-v] [-speed] [system-name]\n");
		return (1);
	}
	if (!isatty(0)) {
		(void) fprintf(stderr, "tip: must be interactive\n");
		return (1);
	}

	for (; argc > 1; argv++, argc--) {
		if (argv[1][0] != '-')
			system = argv[1];
		else switch (argv[1][1]) {

		case 'v':
			vflag++;
			break;

		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			BR = atoi(&argv[1][1]);
			break;

		default:
			(void) fprintf(stderr, "tip: %s, unknown option\n",
			    argv[1]);
			break;
		}
	}

	(void) setlocale(LC_CTYPE, "");

	if (system == NOSTR)
		goto notnumber;
	for (p = system; *p; p++)
		if (isalpha(*p))
			goto notnumber;
	/*
	 * System name is really a phone number...
	 * Copy the number then stomp on the original (in case the number
	 *	is private, we don't want 'ps' or 'w' to find it).
	 */
	if (strlen(system) > sizeof (PNbuf) - 1) {
		(void) fprintf(stderr,
		    "tip: phone number too long (max = %d bytes)\n",
		    sizeof (PNbuf) - 1);
		return (1);
	}
	(void) strncpy(PNbuf, system, sizeof (PNbuf) - 1);
	for (p = system; *p; p++)
		*p = '\0';
	PN = PNbuf;
	(void) snprintf(sbuf, sizeof (sbuf), "tip%d", BR);
	system = sbuf;

notnumber:
	(void) signal(SIGINT, (sig_handler_t)cleanup);
	(void) signal(SIGQUIT, (sig_handler_t)cleanup);
	(void) signal(SIGHUP, (sig_handler_t)cleanup);
	(void) signal(SIGTERM, (sig_handler_t)cleanup);

	if ((i = hunt(system)) == 0) {
		(void) printf("all ports busy\n");
		return (3);
	}
	if (i == -1) {
		(void) printf("link down\n");
		delock(uucplock);
		return (3);
	}
	setbuf(stdout, NULL);
	loginit();

	/*
	 * Now that we have the logfile and the ACU open
	 *  return to the real uid and gid.  These things will
	 *  be closed on exit.  The saved-setuid uid and gid
	 *  allows us to get the original setuid permissions back
	 *  for removing the uucp lock.
	 */
	userperm();

	/*
	 * Kludge, there's no easy way to get the initialization
	 *   in the right order, so force it here.
	 * Do the open here, before we change back to real uid.
	 * We will check whether the open succeeded later, when
	 * (and if) we actually go to use the file.
	 */
	if ((PH = getenv("PHONES")) == NOSTR) {
		myperm();
		PH = "/etc/phones";
	}
	phfd = fopen(PH, "r");

	userperm();

	vinit();				/* init variables */
	setparity("none");			/* set the parity table */
	if ((i = speed(number(value(BAUDRATE)))) == NULL) {
		(void) printf("tip: bad baud rate %d\n",
		    number(value(BAUDRATE)));
		myperm();
		delock(uucplock);
		return (3);
	}


	/*
	 * Hardwired connections require the
	 *  line speed set before they make any transmissions
	 *  (this is particularly true of things like a DF03-AC)
	 */
	if (HW)
		ttysetup(i);
	if (p = connect()) {
		(void) printf("\07%s\n[EOT]\n", p);
		myperm();
		delock(uucplock);
		return (1);
	}

	/*
	 * Always setup the tty again here in case hardware flow
	 *  control was selected, which can only be set after the
	 *  connection is made, or in case this is not a hardwired
	 *  modem (rare these days) that likewise can only be setup
	 *  after the connection is made.
	 */
	ttysetup(i);
cucommon:
	/*
	 * From here down the code is shared with
	 * the "cu" version of tip.
	 */

	(void) ioctl(0, TCGETS, (char *)&defarg);
	arg = defarg;
	/* turn off input processing */
	arg.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
	arg.c_cc[VMIN] = 1;
	arg.c_cc[VTIME] = 0;
	arg.c_iflag &= ~(INPCK|IXON|IXOFF|ICRNL);
	arg.c_oflag = 0;		/* turn off all output processing */
	/* handle tandem mode in case was set in remote file */
	if (boolean(value(TAND)))
		tandem("on");
	else
		tandem("off");
	raw();

	(void) pipe(fildes); (void) pipe(repdes);
	(void) signal(SIGALRM, (sig_handler_t)timeout);

	/*
	 * Everything's set up now:
	 *	connection established (hardwired or dialup)
	 *	line conditioned (baud rate, mode, etc.)
	 *	internal data structures (variables)
	 * so, fork one process for local side and one for remote.
	 */
	if (CM != NOSTR) {
		(void) sleep(2);	/* let line settle */
		parwrite(FD, (unsigned char *)CM, strlen(CM));
	}
	(void) printf(cumode ? "Connected\r\n" : "\07connected\r\n");
	(void) signal(SIGCHLD, (sig_handler_t)deadkid);
	if (pid = fork())
		tipin();
	else
		tipout();
	/*NOTREACHED*/
}
Exemplo n.º 18
0
/* deal with a new player command in countryside mode */
void p_country_process(void)
{
    int no_op;

    drawvision(Player.x,Player.y);
    do {
        no_op = FALSE;
        Cmd = mgetc();
        clear_if_necessary();
        switch (Cmd) {
        case ' ':
        case 13:
            no_op = TRUE;
            break;
        case 7:
            wizard();
            break; /* ^g */
        case 12:
            xredraw();
            no_op = TRUE;
            break; /* ^l */
#if !defined(WIN32)
        case 16:
            bufferprint();
            no_op = TRUE;
            break; /* ^p */
#else
        case 15:
            bufferprint();
            no_op = TRUE;
            break; /* ^o */
#endif
        case 18:
            redraw();
            no_op = TRUE;
            break; /* ^r */
        case 23:
            if (gamestatusp(CHEATED)) drawscreen();
            break; /* ^w */
        case 24:
            if (gamestatusp(CHEATED) ||
                    Player.rank[ADEPT]) wish(1);
            break; /* ^x */
        case 'd':
            drop();
            break;
        case 'e':
            eat();
            break;
        case 'i':
            do_inventory_control();
            break;
        case 's':
            countrysearch();
            break;
        case 'x':
            examine();
            break;
        case 'E':
            dismount_steed();
            break;
        case 'H':
            hunt(Country[Player.x][Player.y].current_terrain_type);
            break;
        case 'I':
            if (! optionp(TOPINV)) top_inventory_control();
            else {
                menuclear();
                display_possessions();
                inventory_control();
            }
            break;
        case 'O':
            setoptions();
            break;
        case 'P':
            show_license();
            break; /* actually show_license is in file.c */
        case 'Q':
            quit();
            break;
        case 'R':
            rename_player();
            break;
        case 'S':
            save(FALSE);
            break;
        case 'V':
            version();
            break;
        case '>':
            enter_site(Country[Player.x][Player.y].base_terrain_type);
            break;
        case '#':
            if (gamestatusp(CHEATED)) editstats();
            break; /* RAC - char editor */
        case '/':
            charid();
            no_op = TRUE;
            break;
        case '?':
            help();
            no_op = TRUE;
            break;
        case '4':
        case 'h':
            movepincountry(-1,0);
            break;
        case '2':
        case 'j':
            movepincountry(0,1);
            break;
        case '8':
        case 'k':
            movepincountry(0,-1);
            break;
        case '6':
        case 'l':
            movepincountry(1,0);
            break;
        case '1':
        case 'b':
            movepincountry(-1,1);
            break;
        case '3':
        case 'n':
            movepincountry(1,1);
            break;
        case '7':
        case 'y':
            movepincountry(-1,-1);
            break;
        case '9':
        case 'u':
            movepincountry(1,-1);
            break;
        default:
            commanderror();
            no_op = TRUE;
            break;
        }
    } while (no_op);
    screencheck(Player.x,Player.y);
}
Exemplo n.º 19
0
int
main(int argc, char *argv[])
{
	int		i;
	int		vflag;
	int		Vflag;
	char *		cutarg;
	char *		cuttimes;
	time_t		cutlotime;
	time_t		cuthitime;
	char **		fakeenv;
	time_t		now;
	time_t		t;
	time_t		newt;
	struct tm	tm;
	struct tm	newtm;
	struct tm *	tmp;
	struct tm *	newtmp;

	cutlotime = absolute_min_time;
	cuthitime = absolute_max_time;
#if HAVE_GETTEXT
	(void) setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
	(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
	(void) textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
	progname = argv[0];
	for (i = 1; i < argc; ++i)
		if (strcmp(argv[i], "--version") == 0) {
			(void) printf("zdump %s%s\n", PKGVERSION, TZVERSION);
			exit(EXIT_SUCCESS);
		} else if (strcmp(argv[i], "--help") == 0) {
			usage(stdout, EXIT_SUCCESS);
		}
	vflag = Vflag = 0;
	cutarg = cuttimes = NULL;
	for (;;)
	  switch (getopt(argc, argv, "c:t:vV")) {
	  case 'c': cutarg = optarg; break;
	  case 't': cuttimes = optarg; break;
	  case 'v': vflag = 1; break;
	  case 'V': Vflag = 1; break;
	  case -1:
	    if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
	      goto arg_processing_done;
	    /* Fall through.  */
	  default:
	    usage(stderr, EXIT_FAILURE);
	  }
 arg_processing_done:;

	if (vflag | Vflag) {
		intmax_t	lo;
		intmax_t	hi;
		char		dummy;
		intmax_t cutloyear = ZDUMP_LO_YEAR;
		intmax_t cuthiyear = ZDUMP_HI_YEAR;
		if (cutarg != NULL) {
			if (sscanf(cutarg, "%"SCNdMAX"%c", &hi, &dummy) == 1) {
				cuthiyear = hi;
			} else if (sscanf(cutarg, "%"SCNdMAX",%"SCNdMAX"%c",
				&lo, &hi, &dummy) == 2) {
					cutloyear = lo;
					cuthiyear = hi;
			} else {
(void) fprintf(stderr, _("%s: wild -c argument %s\n"),
					progname, cutarg);
				exit(EXIT_FAILURE);
			}
		}
		if (cutarg != NULL || cuttimes == NULL) {
			cutlotime = yeartot(cutloyear);
			cuthitime = yeartot(cuthiyear);
		}
		if (cuttimes != NULL) {
			if (sscanf(cuttimes, "%"SCNdMAX"%c", &hi, &dummy) == 1) {
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else if (sscanf(cuttimes, "%"SCNdMAX",%"SCNdMAX"%c",
					  &lo, &hi, &dummy) == 2) {
				if (cutlotime < lo) {
					if (absolute_max_time < lo)
						lo = absolute_max_time;
					cutlotime = lo;
				}
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else {
				(void) fprintf(stderr,
					_("%s: wild -t argument %s\n"),
					progname, cuttimes);
				exit(EXIT_FAILURE);
			}
		}
	}
	(void) time(&now);
	longest = 0;
	for (i = optind; i < argc; ++i)
		if (strlen(argv[i]) > longest)
			longest = strlen(argv[i]);
	{
		int	from;
		int	to;

		for (i = 0; environ[i] != NULL; ++i)
			continue;
		fakeenv = malloc((i + 2) * sizeof *fakeenv);
		if (fakeenv == NULL ||
			(fakeenv[0] = malloc(longest + 4)) == NULL) {
			err(EXIT_FAILURE, "Can't allocated %zu bytes",
			    longest + 4);
		}
		to = 0;
		(void)strcpy(fakeenv[to++], "TZ=");	/* XXX strcpy is safe */
		for (from = 0; environ[from] != NULL; ++from)
			if (strncmp(environ[from], "TZ=", 3) != 0)
				fakeenv[to++] = environ[from];
		fakeenv[to] = NULL;
		environ = fakeenv;
	}
	for (i = optind; i < argc; ++i) {
		static char	buf[MAX_STRING_LENGTH];

		(void) strcpy(&fakeenv[0][3], argv[i]);	/* XXX strcpy is safe */
		if (! (vflag | Vflag)) {
			show(argv[i], now, FALSE);
			continue;
		}
		warned = FALSE;
		t = absolute_min_time;
		if (!Vflag) {
			show(argv[i], t, TRUE);
			t += SECSPERDAY;
			show(argv[i], t, TRUE);
		}
		if (t < cutlotime)
			t = cutlotime;
		tmp = my_localtime(&t);
		if (tmp != NULL) {
			tm = *tmp;
			(void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
		}
		for ( ; ; ) {
			newt = (t < absolute_max_time - SECSPERDAY / 2
				? t + SECSPERDAY / 2
				: absolute_max_time);
			if (cuthitime <= newt)
				break;
			newtmp = localtime(&newt);
			if (newtmp != NULL)
				newtm = *newtmp;
			if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
				(delta(&newtm, &tm) != (newt - t) ||
				newtm.tm_isdst != tm.tm_isdst ||
				strcmp(abbr(&newtm), buf) != 0)) {
					newt = hunt(argv[i], t, newt);
					newtmp = localtime(&newt);
					if (newtmp != NULL) {
						newtm = *newtmp;
						(void) strncpy(buf,
							abbr(&newtm),
							(sizeof buf) - 1);
					}
			}
			t = newt;
			tm = newtm;
			tmp = newtmp;
		}
		if (!Vflag) {
			t = absolute_max_time;
			t -= SECSPERDAY;
			show(argv[i], t, TRUE);
			t += SECSPERDAY;
			show(argv[i], t, TRUE);
		}
	}
	if (fflush(stdout) || ferror(stdout)) {
		err(EXIT_FAILURE, _("Error writing standard output"));
	}
	exit(EXIT_SUCCESS);
	/* If exit fails to exit... */
	return EXIT_FAILURE;
}
Exemplo n.º 20
0
Arquivo: tip.c Projeto: ryo/netbsd-src
int
main(int argc, char *argv[])
{
	char *System = NULL;
	int c, i;
	char *p;
	const char *q;
	char sbuf[12];
	int cmdlineBR;
	int fcarg;

	setprogname(argv[0]);
	gid = getgid();
	egid = getegid();
	uid = getuid();
	euid = geteuid();
	if (strcmp(getprogname(), "cu") == 0) {
		cumode = 1;
		cumain(argc, argv);
		goto cucommon;
	}

	if (argc > 4)
		tipusage();

	if (!isatty(0))
		errx(EXIT_FAILURE, "must be interactive");

	cmdlineBR = 0;
	while((c = getopt(argc, argv, "v0123456789")) != -1) {
		switch(c) {

		case 'v':
			vflag++;
			break;

		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			cmdlineBR = cmdlineBR * 10 + (c - '0');
			BR = cmdlineBR;
			break;

		default:
			warnx("%s, unknown option", argv[1]);
			break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1)
		tipusage();
	else
		System = argv[0];


	if (System == NULL)
		goto notnumber;
	if (isalpha((unsigned char)*System))
		goto notnumber;
	/*
	 * System name is really a phone number...
	 * Copy the number then stomp on the original (in case the number
	 *	is private, we don't want 'ps' or 'w' to find it).
	 */
	if (strlen(System) > sizeof PNbuf - 1) {
		errx(1, "phone number too long (max = %d bytes)",
			(int)sizeof(PNbuf) - 1);
	}
	(void)strlcpy(PNbuf, System, sizeof(PNbuf));
	for (p = System; *p; p++)
		*p = '\0';
	PN = PNbuf;
	(void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR);
	System = sbuf;

notnumber:
	(void)signal(SIGINT, cleanup);
	(void)signal(SIGQUIT, cleanup);
	(void)signal(SIGHUP, cleanup);
	(void)signal(SIGTERM, cleanup);

	if ((i = hunt(System)) == 0) {
		errx(3, "all ports busy");
	}
	if (i == -1) {
		errx(3, "link down");
	}
	setbuf(stdout, NULL);

	/*
	 * Kludge, their's no easy way to get the initialization
	 *   in the right order, so force it here
	 */
	if ((PH = getenv("PHONES")) == NULL)
		PH = path_phones;
	vinit();				/* init variables */
	setparity("none");			/* set the parity table */

	/*
	 * Hardwired connections require the
	 *  line speed set before they make any transmissions
	 *  (this is particularly true of things like a DF03-AC)
	 */
	if (HW) {
		if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) {
			errx(3, "bad baud rate %d",
			    (int)number(value(BAUDRATE)));
		}
	}
	if ((q = tip_connect()) != NULL) {
		errx(1, "\07%s\n[EOT]", q);
	}
	if (!HW) {
		if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) {
			errx(3, "bad baud rate %d",
			    (int)number(value(BAUDRATE)));
		}
	}


cucommon:
	/*
	 * From here down the code is shared with
	 * the "cu" version of tip.
	 */

	/*
	 * Direct connections with no carrier require using O_NONBLOCK on
	 * open, but we don't want to keep O_NONBLOCK after open because it
	 * will cause busy waits.
	 */
	if (DC &&
	    ((fcarg = fcntl(FD, F_GETFL, 0)) < 0 ||
	     fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) {
		err(1, "can't clear O_NONBLOCK");
	}

	(void)tcgetattr(0, &defterm);
	term = defterm;
	term.c_lflag &= ~(ICANON|IEXTEN|ECHO);
	term.c_iflag &= ~(INPCK|ICRNL);
	term.c_oflag &= ~OPOST;
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	defchars = term;
	term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] =
		term.c_cc[VDSUSP] = term.c_cc[VDISCARD] =
	 	term.c_cc[VLNEXT] = _POSIX_VDISABLE;
	raw();

	(void)pipe(attndes);
	(void)pipe(fildes);
	(void)pipe(repdes);
	(void)signal(SIGALRM, alrmtimeout);

	/*
	 * Everything's set up now:
	 *	connection established (hardwired or dialup)
	 *	line conditioned (baud rate, mode, etc.)
	 *	internal data structures (variables)
	 * so, fork one process for local side and one for remote.
	 */
	(void)printf("%s", cumode ? "Connected\r\n" : "\07connected\r\n");
	switch (pid = fork()) {
	default:
		tipin();
		break;
	case 0:
		tipout();
		break;
	case -1:
		err(1, "can't fork");
	}
	/*NOTREACHED*/
	exit(0);	/* XXX: pacify gcc */
}
Exemplo n.º 21
0
ulong hhsetget(HHSet *S, ulong k) { return hunt(S, S->hash(k), k, 0); }
Exemplo n.º 22
0
int
main(int argc, char *argv[])
{
	register int		i;
	register int		c;
	register int		vflag;
	register char *		cutarg;
	register long		cutloyear = ZDUMP_LO_YEAR;
	register long		cuthiyear = ZDUMP_HI_YEAR;
	register time_t		cutlotime;
	register time_t		cuthitime;
	register char **	fakeenv;
	time_t			now;
	time_t			t;
	time_t			newt;
	struct tm		tm;
	struct tm		newtm;
	register struct tm *	tmp;
	register struct tm *	newtmp;

	INITIALIZE(cutlotime);
	INITIALIZE(cuthitime);
#if HAVE_GETTEXT
	(void) setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
	(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
	(void) textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
	progname = argv[0];
	for (i = 1; i < argc; ++i)
		if (strcmp(argv[i], "--version") == 0) {
			(void) printf("zdump %s%s\n", PKGVERSION, TZVERSION);
			exit(EXIT_SUCCESS);
		} else if (strcmp(argv[i], "--help") == 0) {
			usage(stdout, EXIT_SUCCESS);
		}
	vflag = 0;
	cutarg = NULL;
	while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v')
		if (c == 'v')
			vflag = 1;
		else	cutarg = optarg;
	if ((c != EOF && c != -1) ||
		(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
			usage(stderr, EXIT_FAILURE);
	}
	if (vflag) {
		if (cutarg != NULL) {
			long	lo;
			long	hi;
			char	dummy;

			if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) {
				cuthiyear = hi;
			} else if (sscanf(cutarg, "%ld,%ld%c",
				&lo, &hi, &dummy) == 2) {
					cutloyear = lo;
					cuthiyear = hi;
			} else {
(void) fprintf(stderr, _("%s: wild -c argument %s\n"),
					progname, cutarg);
				exit(EXIT_FAILURE);
			}
		}
		checkabsolutes();
		cutlotime = yeartot(cutloyear);
		cuthitime = yeartot(cuthiyear);
	}
	(void) time(&now);
	longest = 0;
	for (i = optind; i < argc; ++i)
		if (strlen(argv[i]) > longest)
			longest = strlen(argv[i]);
	{
		register int	from;
		register int	to;

		for (i = 0; environ[i] != NULL; ++i)
			continue;
		fakeenv = malloc((i + 2) * sizeof *fakeenv);
		if (fakeenv == NULL
		    || (fakeenv[0] = malloc(longest + 4)) == NULL) {
					(void) perror(progname);
					exit(EXIT_FAILURE);
		}
		to = 0;
		(void) strcpy(fakeenv[to++], "TZ=");
		for (from = 0; environ[from] != NULL; ++from)
			if (strncmp(environ[from], "TZ=", 3) != 0)
				fakeenv[to++] = environ[from];
		fakeenv[to] = NULL;
		environ = fakeenv;
	}
	for (i = optind; i < argc; ++i) {
		static char	buf[MAX_STRING_LENGTH];

		(void) strcpy(&fakeenv[0][3], argv[i]);
		if (!vflag) {
			show(argv[i], now, FALSE);
			continue;
		}
		warned = FALSE;
		t = absolute_min_time;
		show(argv[i], t, TRUE);
		t += SECSPERHOUR * HOURSPERDAY;
		show(argv[i], t, TRUE);
		if (t < cutlotime)
			t = cutlotime;
		tmp = my_localtime(&t);
		if (tmp != NULL) {
			tm = *tmp;
			(void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
		}
		for ( ; ; ) {
			if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12)
				break;
			newt = t + SECSPERHOUR * 12;
			newtmp = localtime(&newt);
			if (newtmp != NULL)
				newtm = *newtmp;
			if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
				(delta(&newtm, &tm) != (newt - t) ||
				newtm.tm_isdst != tm.tm_isdst ||
				strcmp(abbr(&newtm), buf) != 0)) {
					newt = hunt(argv[i], t, newt);
					newtmp = localtime(&newt);
					if (newtmp != NULL) {
						newtm = *newtmp;
						(void) strncpy(buf,
							abbr(&newtm),
							(sizeof buf) - 1);
					}
			}
			t = newt;
			tm = newtm;
			tmp = newtmp;
		}
		t = absolute_max_time;
		t -= SECSPERHOUR * HOURSPERDAY;
		show(argv[i], t, TRUE);
		t += SECSPERHOUR * HOURSPERDAY;
		show(argv[i], t, TRUE);
	}
	if (fflush(stdout) || ferror(stdout)) {
		(void) fprintf(stderr, "%s: ", progname);
		(void) perror(_("Error writing to standard output"));
		exit(EXIT_FAILURE);
	}
	exit(EXIT_SUCCESS);
	/* If exit fails to exit... */
	return EXIT_FAILURE;
}
Exemplo n.º 23
0
void run(){
	hunt();
}
Exemplo n.º 24
0
int
main(int argc, char *argv[])
{
	/* These are static so that they're initially zero.  */
	static char *		abbrev;
	static size_t		abbrevsize;

	int		i;
	bool		vflag;
	bool		Vflag;
	char *		cutarg;
	char *		cuttimes;
	time_t		cutlotime;
	time_t		cuthitime;
	time_t		now;
	bool iflag = false;

	cutlotime = absolute_min_time;
	cuthitime = absolute_max_time;
#if HAVE_GETTEXT
	(void) setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
	(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
	(void) textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
	progname = argv[0];
	for (i = 1; i < argc; ++i)
		if (strcmp(argv[i], "--version") == 0) {
			(void) printf("zdump %s%s\n", PKGVERSION, TZVERSION);
			return EXIT_SUCCESS;
		} else if (strcmp(argv[i], "--help") == 0) {
			usage(stdout, EXIT_SUCCESS);
		}
	vflag = Vflag = false;
	cutarg = cuttimes = NULL;
	for (;;)
	  switch (getopt(argc, argv, "c:it:vV")) {
	  case 'c': cutarg = optarg; break;
	  case 't': cuttimes = optarg; break;
	  case 'i': iflag = true; break;
	  case 'v': vflag = true; break;
	  case 'V': Vflag = true; break;
	  case -1:
	    if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
	      goto arg_processing_done;
	    /* Fall through.  */
	  default:
	    usage(stderr, EXIT_FAILURE);
	  }
 arg_processing_done:;

	if (iflag | vflag | Vflag) {
		intmax_t	lo;
		intmax_t	hi;
		char *loend, *hiend;
		intmax_t cutloyear = ZDUMP_LO_YEAR;
		intmax_t cuthiyear = ZDUMP_HI_YEAR;
		if (cutarg != NULL) {
			lo = strtoimax(cutarg, &loend, 10);
			if (cutarg != loend && !*loend) {
				hi = lo;
				cuthiyear = hi;
			} else if (cutarg != loend && *loend == ','
				   && (hi = strtoimax(loend + 1, &hiend, 10),
				       loend + 1 != hiend && !*hiend)) {
				cutloyear = lo;
				cuthiyear = hi;
			} else {
				fprintf(stderr, _("%s: wild -c argument %s\n"),
					progname, cutarg);
				return EXIT_FAILURE;
			}
		}
		if (cutarg != NULL || cuttimes == NULL) {
			cutlotime = yeartot(cutloyear);
			cuthitime = yeartot(cuthiyear);
		}
		if (cuttimes != NULL) {
			lo = strtoimax(cuttimes, &loend, 10);
			if (cuttimes != loend && !*loend) {
				hi = lo;
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else if (cuttimes != loend && *loend == ','
				   && (hi = strtoimax(loend + 1, &hiend, 10),
				       loend + 1 != hiend && !*hiend)) {
				if (cutlotime < lo) {
					if (absolute_max_time < lo)
						lo = absolute_max_time;
					cutlotime = lo;
				}
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else {
				(void) fprintf(stderr,
					_("%s: wild -t argument %s\n"),
					progname, cuttimes);
				return EXIT_FAILURE;
			}
		}
	}
	gmtzinit();
	INITIALIZE (now);
	if (! (iflag | vflag | Vflag))
	  now = time(NULL);
	longest = 0;
	for (i = optind; i < argc; i++) {
		size_t arglen = strlen(argv[i]);
		if (longest < arglen)
			longest = arglen < INT_MAX ? arglen : INT_MAX;
	}

	for (i = optind; i < argc; ++i) {
		timezone_t tz = tzalloc(argv[i]);
		char const *ab;
		time_t t;
		struct tm tm, newtm;
		bool tm_ok;

		if (!tz) {
			errx(EXIT_FAILURE, "%s", argv[i]);
		}
		if (! (iflag | vflag | Vflag)) {
			show(tz, argv[i], now, false);
			tzfree(tz);
			continue;
		}
		warned = false;
		t = absolute_min_time;
		if (! (iflag | Vflag)) {
			show(tz, argv[i], t, true);
			t += SECSPERDAY;
			show(tz, argv[i], t, true);
		}
		if (t < cutlotime)
			t = cutlotime;
		tm_ok = my_localtime_rz(tz, &t, &tm) != NULL;
		if (tm_ok) {
			ab = saveabbr(&abbrev, &abbrevsize, &tm);
			if (iflag) {
				showtrans("\nTZ=%f", &tm, t, ab, argv[i]);
				showtrans("-\t-\t%Q", &tm, t, ab, argv[i]);
			}
		} else
			ab = NULL;
		while (t < cuthitime) {
			time_t newt = ((t < absolute_max_time - SECSPERDAY / 2
			    && t + SECSPERDAY / 2 < cuthitime)
			    ? t + SECSPERDAY / 2 : cuthitime);
			struct tm *newtmp = localtime_rz(tz, &newt, &newtm);
			bool newtm_ok = newtmp != NULL;
			if (! (tm_ok & newtm_ok
			    ? (delta(&newtm, &tm) == newt - t
			    && newtm.tm_isdst == tm.tm_isdst
			    && strcmp(abbr(&newtm), ab) == 0)
			    : tm_ok == newtm_ok)) {
				newt = hunt(tz, argv[i], t, newt);
				newtmp = localtime_rz(tz, &newt, &newtm);
				newtm_ok = newtmp != NULL;
				if (iflag)
					showtrans("%Y-%m-%d\t%L\t%Q",
					    newtmp, newt, newtm_ok ?
					    abbr(&newtm) : NULL, argv[i]);
				else {
					show(tz, argv[i], newt - 1, true);
					show(tz, argv[i], newt, true);
				}
			}
			t = newt;
			tm_ok = newtm_ok;
			if (newtm_ok) {
				ab = saveabbr(&abbrev, &abbrevsize, &newtm);
				tm = newtm;
			}
		}
		if (! (iflag | Vflag)) {
			t = absolute_max_time;
			t -= SECSPERDAY;
			show(tz, argv[i], t, true);
			t += SECSPERDAY;
			show(tz, argv[i], t, true);
		}
		tzfree(tz);
	}
	close_file(stdout);
	if (errout && (ferror(stderr) || fclose(stderr) != 0))
		return EXIT_FAILURE;
	return EXIT_SUCCESS;
}
Exemplo n.º 25
0
 double interp(double x) {
   int jlo = cor ? hunt(x) : locate(x);
   return rawinterp(jlo,x);
 }
Exemplo n.º 26
0
ulong hhsetdel(HHSet *S, ulong k) { return hunt(S, S->hash(k), k, 1); }
Exemplo n.º 27
0
void run(){
	hunt(getParam());
}
Exemplo n.º 28
0
DSTTime
get_dst_time(const char *zone, int year)
{
	register time_t		cutlotime;
	register time_t		cuthitime;

	cutlotime = yeartot(year);
	cuthitime = yeartot(year+1);

	time_t			t;
	time_t			newt;
	struct tm		tm;
	struct tm		newtm;
	register struct tm *	tmp;
	register struct tm *	newtmp;
	static char	buf[MAX_STRING_LENGTH];
	DSTTime ret = {0, 0};

	char *tz = getenv("TZ");
	if (setenv("TZ", zone, 1) != 0 ) {
		fprintf(stderr, "Set TZ=%s failed\n", zone);
		return ret;
	}

	t = absolute_min_time;
	if (t < cutlotime)
		t = cutlotime;
	tmp = localtime(&t);
	if (tmp != NULL) {
		tm = *tmp;
		strncpy(buf, abbr(&tm), (sizeof buf) - 1);
	}

	int enter_flag = 0;
	for ( ; ; ) {
		newt = (t < absolute_max_time - SECSPERDAY / 2
		        ? t + SECSPERDAY / 2
		        : absolute_max_time);
		if (cuthitime <= newt)
			break;
		newtmp = localtime(&newt);
		if (newtmp != NULL)
			newtm = *newtmp;
		if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
		        (delta(&newtm, &tm) != (newt - t) ||
		         newtm.tm_isdst != tm.tm_isdst ||
		         strcmp(abbr(&newtm), buf) != 0)) {
			newt = hunt(t, newt);
			newtmp = localtime(&newt);
			if (newtmp != NULL) {
				if (newtmp->tm_isdst) {
					if (!enter_flag) {
						ret.enter = newt;
						enter_flag = 1;
					} else {
						ret.leave = newt;
					}
				} else {
					if (!enter_flag) {
						ret.enter = newt-1;
						enter_flag = 1;
					} else {
						ret.leave = newt-1;
					}
				}

				newtm = *newtmp;
				strncpy(buf, abbr(&newtm),(sizeof buf) - 1);
			}
		}
		t = newt;
		tm = newtm;
		tmp = newtmp;
	}
	setenv("TZ", tz, 1);

	return ret;
}
Exemplo n.º 29
0
/*
 * Botch the interface to look like cu's
 */
void
cumain(int argc, char *argv[])
{
	int i;
	static char sbuf[12];

	if (argc < 2) {
		printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
		exit(8);
	}
	CU = DV = NULL;
	BR = DEFBR;
	for (; argc > 1; argv++, argc--) {
		if (argv[1][0] != '-')
			PN = argv[1];
		else switch (argv[1][1]) {

		case 't':
			HW = 1, DU = -1;
			--argc;
			continue;

		case 'a':
			CU = argv[2]; ++argv; --argc;
			break;

		case 's':
			if (argc < 3 || speed(atoi(argv[2])) == 0) {
				fprintf(stderr, "cu: unsupported speed %s\n",
					argv[2]);
				exit(3);
			}
			BR = atoi(argv[2]); ++argv; --argc;
			break;

		case 'l':
			DV = argv[2]; ++argv; --argc;
			break;

		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			if (CU)
				CU[strlen(CU)-1] = argv[1][1];
			if (DV)
				DV[strlen(DV)-1] = argv[1][1];
			break;

		default:
			printf("Bad flag %s", argv[1]);
			break;
		}
	}
	signal(SIGINT, cleanup);
	signal(SIGQUIT, cleanup);
	signal(SIGHUP, cleanup);
	signal(SIGTERM, cleanup);

	/*
	 * The "cu" host name is used to define the
	 * attributes of the generic dialer.
	 */
	(void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
	if ((i = hunt(sbuf)) == 0) {
		printf("all ports busy\n");
		exit(3);
	}
	if (i == -1) {
		printf("link down\n");
		(void)uu_unlock(uucplock);
		exit(3);
	}
	setbuf(stdout, NULL);
	loginit();
	user_uid();
	vinit();
	setparity("none");
	boolean(value(VERBOSE)) = 0;
	if (HW)
		ttysetup(speed(BR));
	if (connect()) {
		printf("Connect failed\n");
		daemon_uid();
		(void)uu_unlock(uucplock);
		exit(1);
	}
	if (!HW)
		ttysetup(speed(BR));
	exit(0);
}
Exemplo n.º 30
0
Arquivo: tip.c Projeto: 2asoft/freebsd
int
main(int argc, char *argv[])
{
	char *sys = NOSTR, sbuf[12], *p;
	int i;

	/* XXX preserve previous braindamaged behavior */
	setboolean(value(DC), TRUE);

	gid = getgid();
	egid = getegid();
	uid = getuid();
	euid = geteuid();
	if (equal(__progname, "cu")) {
		cumode = 1;
		cumain(argc, argv);
		goto cucommon;
	}

	if (argc > 4) {
		fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n");
		exit(1);
	}
	if (!isatty(0)) {
		fprintf(stderr, "%s: must be interactive\n", __progname);
		exit(1);
	}

	for (; argc > 1; argv++, argc--) {
		if (argv[1][0] != '-')
			sys = argv[1];
		else switch (argv[1][1]) {

		case 'v':
			vflag++;
			break;

		case 'n':
			noesc++;
			break;

		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			BR = atoi(&argv[1][1]);
			break;

		default:
			fprintf(stderr, "%s: %s, unknown option\n", __progname,
			    argv[1]);
			break;
		}
	}

	if (sys == NOSTR)
		goto notnumber;
	if (isalpha(*sys))
		goto notnumber;
	/*
	 * System name is really a phone number...
	 * Copy the number then stomp on the original (in case the number
	 *	is private, we don't want 'ps' or 'w' to find it).
	 */
	if (strlen(sys) > sizeof PNbuf - 1) {
		fprintf(stderr, "%s: phone number too long (max = %d bytes)\n",
			__progname, (int)sizeof(PNbuf) - 1);
		exit(1);
	}
	strlcpy(PNbuf, sys, sizeof PNbuf - 1);
	for (p = sys; *p; p++)
		*p = '\0';
	PN = PNbuf;
	(void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR);
	sys = sbuf;

notnumber:
	(void)signal(SIGINT, cleanup);
	(void)signal(SIGQUIT, cleanup);
	(void)signal(SIGHUP, cleanup);
	(void)signal(SIGTERM, cleanup);
	(void)signal(SIGCHLD, SIG_DFL);

	if ((i = hunt(sys)) == 0) {
		printf("all ports busy\n");
		exit(3);
	}
	if (i == -1) {
		printf("link down\n");
		(void)uu_unlock(uucplock);
		exit(3);
	}
	setbuf(stdout, NULL);
	loginit();

	/*
	 * Now that we have the logfile and the ACU open
	 *  return to the real uid and gid.  These things will
	 *  be closed on exit.  Swap real and effective uid's
	 *  so we can get the original permissions back
	 *  for removing the uucp lock.
	 */
	user_uid();

	/*
	 * Kludge, their's no easy way to get the initialization
	 *   in the right order, so force it here
	 */
	if ((PH = getenv("PHONES")) == NOSTR)
		PH = _PATH_PHONES;
	vinit();				/* init variables */
	setparity("none");			/* set the parity table */

	/*
	 * Hardwired connections require the
	 *  line speed set before they make any transmissions
	 *  (this is particularly true of things like a DF03-AC)
	 */
	if (HW && ttysetup(number(value(BAUDRATE)))) {
		fprintf(stderr, "%s: bad baud rate %ld\n", __progname,
		    number(value(BAUDRATE)));
		daemon_uid();
		(void)uu_unlock(uucplock);
		exit(3);
	}
	if ((p = con())) {
		printf("\07%s\n[EOT]\n", p);
		daemon_uid();
		(void)uu_unlock(uucplock);
		exit(1);
	}
	if (!HW && ttysetup(number(value(BAUDRATE)))) {
		fprintf(stderr, "%s: bad baud rate %ld\n", __progname,
		    number(value(BAUDRATE)));
		daemon_uid();
		(void)uu_unlock(uucplock);
		exit(3);
	}
cucommon:
	/*
	 * From here down the code is shared with
	 * the "cu" version of tip.
	 */

	i = fcntl(FD, F_GETFL);
	if (i == -1) {
		perror("fcntl");
		cleanup(0);
	}
	i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK);
	if (i == -1) {
		perror("fcntl");
		cleanup(0);
	}

	tcgetattr(0, &defterm);
	gotdefterm = 1;
	term = defterm;
	term.c_lflag &= ~(ICANON|IEXTEN|ECHO);
	term.c_iflag &= ~(INPCK|ICRNL);
	term.c_oflag &= ~OPOST;
	term.c_cc[VMIN] = 1;
	term.c_cc[VTIME] = 0;
	defchars = term;
	term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] =
	    term.c_cc[VDSUSP] = term.c_cc[VDISCARD] =
	    term.c_cc[VLNEXT] = _POSIX_VDISABLE;
	raw();

	pipe(fildes); pipe(repdes);
	(void)signal(SIGALRM, timeout);

	if (value(LINEDISC) != TTYDISC) {
		int ld = (int)(intptr_t)value(LINEDISC);
		ioctl(FD, TIOCSETD, &ld);
	}		

	/*
	 * Everything's set up now:
	 *	connection established (hardwired or dialup)
	 *	line conditioned (baud rate, mode, etc.)
	 *	internal data structures (variables)
	 * so, fork one process for local side and one for remote.
	 */
	printf(cumode ? "Connected\r\n" : "\07connected\r\n");
	tipin_pid = getpid();
	if ((tipout_pid = fork()))
		tipin();
	else
		tipout();
	/*NOTREACHED*/
	exit(0);
}