Ejemplo n.º 1
0
Archivo: spec.c Proyecto: Hooman3/minix
/*
 * collect income tax
 */
void
inc_tax(void)
{
	int worth, com_num;

	com_num = getinp("Do you wish to lose 10% of your total worth or "
	    "$200? ", perc);
	worth = cur_p->money + prop_worth(cur_p);
	printf("You were worth $%d", worth);
	worth /= 10;
	if (com_num > 2) {
		if (worth < 200)
			printf(".  Good try, but not quite.\n");
		else if (worth > 200)
			lucky(".\nGood guess.  ");
		cur_p->money -= 200;
	}
	else {
		printf(", so you pay $%d", worth);
		if (worth > 200)
			printf("  OUCH!!!!.\n");
		else if (worth < 200)
			lucky("\nGood guess.  ");
		cur_p->money -= worth;
	}
	if (worth == 200)
		lucky("\nIt makes no difference!  ");
}
Ejemplo n.º 2
0
Archivo: prob4.c Proyecto: egall/cs122
int main(int argc, char *argv[])
{
    char buf[16];
    getinp (buf, sizeof (buf));
    display(buf);
    printf("buffer3 done\n");
}
Ejemplo n.º 3
0
void
trade()
{
	int	tradee, i;

	trading = TRUE;
	for (i = 0; i < 2; i++) {
		trades[i].cash = 0;
		trades[i].gojf = FALSE;
		trades[i].prop_list = NULL;
	}
over:
	if (num_play == 1) {
		printf("There ain't no-one around to trade WITH!!\n");
		return;
	}
	if (num_play > 2) {
		tradee = getinp("Which player do you wish to trade with? ",
		    name_list);
		if (tradee == num_play)
			return;
		if (tradee == player) {
			printf("You can't trade with yourself!\n");
			goto over;
		}
	}
	else
		tradee = 1 - player;
	get_list(0, player);
	get_list(1, tradee);
	if (getyn("Do you wish a summary? ") == 0)
		summate();
	if (getyn("Is the trade ok? ") == 0)
		do_trade();
}
Ejemplo n.º 4
0
/*
 *	This routine is the command level response the mortgage command.
 * it gets the list of mortgageable property and asks which are to
 * be mortgaged.
 */
mortgage() {

	reg int	prop;

	for (;;) {
		if (set_mlist() == 0) {
			if (got_houses)
				printf("You can't mortgage property with houses on it.\n");
			else
				printf("You don't have any un-mortgaged property.\n");
			return;
		}
		if (num_good == 1) {
			printf("Your only mortageable property is %s\n",names[0]);
			if (getyn("Do you want to mortgage it? ") == 0)
				m(square[0]);
			return;
		}
		prop = getinp("Which property do you want to mortgage? ",names);
		if (prop == num_good)
			return;
		m(square[prop]);
		notify(cur_p);
	}
}
int main()
{
	int N;
	int A[10];

	getinp(&N,A);
	Bubblesort(N,A);
	showout(N,A);

	return 0;
}
Ejemplo n.º 6
0
/*
 *	These routines deal with buying and selling houses
 */
void
buy_houses()
{
	int	num_mon;
	MON	*mp;
	OWN	*op;
	bool	good, got_morg;
	int	i,p;

over:
	num_mon = 0;
	good = TRUE;
	got_morg = FALSE;
	for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
		continue;
	while (op)
		if (op->sqr->desc->monop) {
			mp = op->sqr->desc->mon_desc;
			names[num_mon] = (monops[num_mon]=mp)->name;
			num_mon++;
			got_morg = good = FALSE;
			for (i = 0; i < mp->num_in; i++) {
				if (op->sqr->desc->morg)
					got_morg = TRUE;
				if (op->sqr->desc->houses != 5)
					good = TRUE;
				op = op->next;
			}
			if (!good || got_morg)
				--num_mon;
		}
		else
			op = op->next;
	if (num_mon == 0) {
		if (got_morg)
			printf("You can't build on mortgaged monopolies.\n");
		else if (!good)
			printf("You can't build any more.\n");
		else
			printf("But you don't have any monopolies!!\n");
		return;
	}
	if (num_mon == 1)
		buy_h(monops[0]);
	else {
		names[num_mon++] = "done";
		names[num_mon--] = 0;
		if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
			return;
		buy_h(monops[p]);
		goto over;
	}
}
Ejemplo n.º 7
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
int rtloginl ()
{
	LINK    *link;
	CIRCUIT *circuit;
	SADDR   sp;
	char    *buf, call[ln_axaddr+1];

	if (MemLow) return cmd_exit;
	getpeername(CurProc->input, &sp);
	if (sp.type isnt TYPE_NETROM) return cmd_exit;
	ax2str(call, sp.a.nr.node);
	if (node_find(call)) return cmd_exit; // Already linked.

	for (link = link_hd; link; link = link->next)
		if (matchi(call, link->call)) break;

	if (!link) return cmd_exit;           // We don't link with this system.
	if (link->flags & (p_linked | p_linkini)) return cmd_exit;  // Already linked.

// Accept the link request.

	puser(link->alias);
	buf = mallocw(LINE128);
	strcpy(buf, call);
	strlop(buf, '-');
	puser(buf);
	free(buf);

// Create a circuit for this link.

	circuit = circuit_new(p_linked, CurProc->output);
	if (!circuit) return cmd_exit;

	tputs("OK\n");
	circuit->u.link = link;
	link->flags     = p_linked;
	state_tell(circuit);
	makelinks();

// Run in circles, scream and shout.

	for (;;) if (getinp(circuit))
		chkctl(circuit);
	else
	{
		link_drop(circuit);
		link->flags = p_nil;
		return cmd_exit;
	}
}
Ejemplo n.º 8
0
/*
 *	This routine gets the list of things to be trader for the
 * player, and puts in the structure given.
 */
static void
get_list(int struct_no, int play_no)
{
	int sn, pn;
	PLAY *pp;
	int numin, propnum, num_prp;
	OWN *op;
	TRADE *tp;

	for (numin = 0; numin < MAX_PRP; numin++)
		used[numin] = FALSE;
	sn = struct_no, pn = play_no;
	pp = &play[pn];
	tp = &trades[sn];
	tp->trader = pn;
	printf("player %s (%d):\n", pp->name, pn+1);
	if (pp->own_list) {
		numin = set_list(pp->own_list);
		for (num_prp = numin; num_prp; ) {
			propnum=getinp("Which property do you wish to trade? ",
			    plist);
			if (propnum == numin)
				break;
			else if (used[propnum])
				printf("You've already allocated that.\n");
			else {
				num_prp--;
				used[propnum] = TRUE;
				for (op = pp->own_list; propnum--; op = op->next)
					continue;
				add_list(pn, &(tp->prop_list), sqnum(op->sqr));
			}
		}
	}
	if (pp->money > 0) {
		printf("You have $%d.  ", pp->money);
		tp->cash = get_int("How much are you trading? ");
	}
	if (pp->num_gojf > 0) {
once_more:
		printf("You have %d get-out-of-jail-free cards. ",pp->num_gojf);
		tp->gojf = get_int("How many are you trading? ");
		if (tp->gojf > pp->num_gojf) {
			printf("You don't have that many.  Try again.\n");
			goto once_more;
		}
	}
}
int main ()
{
  char s[INPUT], t[OUTPUT];
  int i,j,prv,nxt;

  for(i = 0; i < INPUT; i++) /* To flush input string */
    s[i] = 0;
  
  for(i = 0; i < OUTPUT; i++) /* To flush output string */
    t[i] = 0;
  
  j = prv = nxt = 0;

  if (getinp(s)) 
  {
    for(i=0; s[i] == DASH;i++)                                        /* Fill input with leading '-', if there is any */
      t[i] = s[i];
    j = i;
  
    while (s[i] != '\0') 
    {
      
      if (s[i] != DASH)
        t[j++] = s[i++];
      else if (s[i] == DASH)  {
        prv = s[i-1], nxt = s[i+1];
        
        if ((islower(prv) && islower(nxt)) || (isupper(prv) && isupper(nxt)) || (isdigit(prv) && isdigit(nxt))) 
        {
          explow(prv,nxt);
          prv = nxt = 0;
          t[j] = '\0';
          strcat(t,store);
          j = strlen(t);
          i++;
        }
        else
          t[j++] = s[i++];
      }
    }
    printf("%s\n",t);
  }
  else
    printf("INPUT MISSING !!!!\n");
  return 0;
}
Ejemplo n.º 10
0
int main(int argc,char *argv[])

{

printf("SRCSWAP - Source code mark/replace utility Version 1.0000 %s",__DATE__);
markchar='~';
ovrwrit = 0;
disp=0;
nomark=0;
noquote=0;
xargc=argc;

for (i=0;i<argc;i++) 
	{
	xargv[i] = argv[i];
	}

if (argc < 4) format();

i = 4;
while (i < argc) 
         {
         getopt(i);
         i++;
         }

getinp();
getout();

top=NULL;
cur=NULL;
 
get_xl();
srt_xl();
done=0;

printf("\nProcessing...");
while (!(done))
         {
         getline();
         process();
         }
fclose(outf);
return(0);
}
Ejemplo n.º 11
0
/*
 *	This routine lets a player resign
 */
void
resign(void)
{
	int i, new_own;
	OWN *op;
	SQUARE *sqp;

	if (cur_p->money <= 0) {
		switch (board[cur_p->loc].type) {
		  case UTIL:
		  case RR:
		  case PRPTY:
			new_own = board[cur_p->loc].owner;
			/* If you ran out of money by buying current location */
			if (new_own == player)
				new_own = num_play;
			break;
		  default:		/* Chance, taxes, etc */
			new_own = num_play;
			break;
		}
		if (new_own == num_play)
			printf("You would resign to the bank\n");
		else
			printf("You would resign to %s\n", name_list[new_own]);
	}
	else if (num_play == 1) {
		new_own = num_play;
		printf("You would resign to the bank\n");
	}
	else {
		name_list[num_play] = "bank";
		do {
			new_own = getinp("Who do you wish to resign to? ",
			    name_list);
			if (new_own == player)
				printf("You can't resign to yourself!!\n");
		} while (new_own == player);
		name_list[num_play] = "done";
	}
	if (getyn("Do you really want to resign? ") != 0)
		return;
	if (num_play == 1) {
		printf("Then NOBODY wins (not even YOU!)\n");
		exit(0);
	}
	if (new_own < num_play) {	/* resign to player		*/
		printf("resigning to player\n");
		trades[0].trader = new_own;
		trades[0].cash = trades[0].gojf = 0;
		trades[0].prop_list = NULL;
		trades[1].trader = player;
		trades[1].cash = cur_p->money > 0 ? cur_p->money : 0;
		trades[1].gojf = cur_p->num_gojf;
		trades[1].prop_list = cur_p->own_list;
		do_trade();
	}
	else {				/* resign to bank		*/
		printf("resigning to bank\n");
		for (op = cur_p->own_list; op; op = op->next) {
			sqp = op->sqr;
			sqp->owner = -1;
			sqp->desc->morg = FALSE;
			if (sqp->type == PRPTY) {
				is_not_monop(sqp->desc->mon_desc);
				sqp->desc->houses = 0;
			}
		}
		if (cur_p->num_gojf)
			ret_card(cur_p);
	}
	free(play[player].name);
	for (i = player; i < num_play; i++) {
		name_list[i] = name_list[i+1];
		if (i + 1 < num_play)
			play[i] = play[i+1];
	}
	name_list[num_play--] = NULL;
	for (i = 0; i < N_SQRS; i++)
		if (board[i].owner > player)
			--board[i].owner;
	player = player == 0 ? num_play - 1 : player - 1;
	next_play();
	if (num_play < 2) {
		printf("\nThen %s WINS!!!!!\n", play[0].name);
		printhold(0);
		printf("That's a grand worth of $%d.\n",
			play[0].money+prop_worth(&play[0]));
		exit(0);
	}
}
Ejemplo n.º 12
0
int main (void)
/************************************************************************
 * TESTDA								*
 * 									*
 * This program tests the GEMLIB DA functions.				*
 * 									*
 ** 									*
 * Log:									*
 * S. Jacobs/NCEP	 5/13	Initial coding				*
 ***********************************************************************/
{
    int		cont, ier, iret, numsub, is, ie, ii;
    char	select[5];

    char	pyfile[MXFLSZ], pymeth[MXFLSZ];

/*---------------------------------------------------------------------*/
    in_bdta(&ier);

    cont = G_TRUE;

    while ( cont ) {
	printf ( "\n\n" );
	printf ( "  1 = DA_RUNPY for CHAR output\n" );
	printf ( "  2 = DA_RUNPY for INT output\n" );
	printf ( "  3 = DA_RUNPY for FLOAT output\n" );
	printf ( "\n" );
	printf ( "Select a subroutine number or type EXIT: " );
	ier = getinp ( 1, select, NULL, NULL, 4 );
	switch ( select[0] ) {
	    case 'e':
	    case 'E':
		cont = G_FALSE;
	    default:
		numsub = atoi ( select );
		break;
	}

/*---------------------------------------------------------------------*/
	if ( numsub == 1 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DACHAR;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );
	    if  ( iret >= 0 )  {
		printf ( "The length of result is: %ld\n", strlen(daoutc) );
		printf ( "The result is: %s\n\n", daoutc );

		free ( daoutc );
	    }
	    free ( daargs );
	}
/*---------------------------------------------------------------------*/
	if ( numsub == 2 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DAINT;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );
	    if  ( iret >= 0 )  {
		printf ( "The array size of result is: %d\n", danumi );
		printf ( "The result array is:\n" );
		is = 0;
		ie = G_MIN ( 8, danumi );
		while ( is < danumi ) {
		    for ( ii = is; ii < ie; ii++ ) {
			printf ( "%9d ", daouti[ii] );
		    }
		    printf ( "\n" );
		    is = ie;
		    ie = G_MIN ( is+8, danumi );
		}
		printf ( "\n" );

		free ( daouti );
	    }
	    free ( daargs );
	}
/*---------------------------------------------------------------------*/
	if ( numsub == 3 ) {

	    printf ( "Enter the Python file name (without .py):\n" );
	    ier = getinp ( 1, pyfile, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the Python method name:\n" );
	    ier = getinp ( 1, pymeth, NULL, NULL, MXFLSZ );
	    if ( ier < 0 ) {
	       	break;
	    }

	    printf ( "Enter the number of input strings:\n" );
	    ier = getinp ( 2, NULL, &danarg, NULL, STRSIZE );
	    if ( ier < 0 ) {
	       	break;
	    }

	    daargs = (char **) malloc ( danarg * sizeof(char *) );
	    for ( ii = 0; ii < danarg; ii++ ) {
		daargs[ii] = (char *) malloc ( STRSIZE * sizeof(char) );
		printf ( "Enter input string %d:\n", ii );
		ier = getinp ( 1, daargs[ii], NULL, NULL, STRSIZE );
		if ( ier < 0 ) {
		    break;
		}
	    }

	    datype = DAFLOAT;
	    da_runpy ( pyfile, pymeth, &iret );

	    printf ( "\nDA_RUNPY: iret = %d\n\n", iret );

	    if  ( iret >= 0 )  {
		printf ( "The array size of result is: %d\n", danumf );
		printf ( "The result array is:\n" );
		is = 0;
		ie = G_MIN ( 8, danumf );
		while ( is < danumf ) {
		    for ( ii = is; ii < ie; ii++ ) {
			printf ( "%9.2f ", daoutf[ii] );
		    }
		    printf ( "\n" );
		    is = ie;
		    ie = G_MIN ( is+8, danumf );
		}
		printf ( "\n" );

		free ( daoutf );
	    }
	    free ( daargs );
	}

/*---------------------------------------------------------------------*/
    }

    return 0;
}
Ejemplo n.º 13
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
static void link_out ()
{
	LINK    *link;
	NR_NODE *np;
	CIRCUIT *circuit;
	SADDR    addr;
	word     s;

	link = (LINK *)p;
	if (MemLow) { link->flags = p_nil; return; }
	puser(link->alias);

// See if the requested destination is a known alias or call,
// use it if it is. Otherwise give up.

	np = nr_findca(link->call);
	if (!np) { link->flags = p_nil; return; }

	s = socket(TYPE_NETROM);
	mysock(s);
	flushoff(s);  // The RT control process will do the flush.

// Set up the local and remote addresses.

	addr.type = TYPE_NETROM;
	memcpy(addr.a.nr.user, Node->call, ln_call+1);
	memcpy(addr.a.nr.node, Node->call, ln_call+1);
	bind(s, &addr);
	memcpy(addr.a.nr.user, np->call, ln_call+1);
	memcpy(addr.a.nr.node, np->call, ln_call+1);

	if (!connect(s, &addr)) { link->flags = p_nil; return; }

// Create a circuit for this link.

	circuit = circuit_new(p_linkini, s);
	if (!circuit) { link->flags = p_nil; return; }

	circuit->u.link = link;
	tputs("*RTL\n");  // Log in to the remote RT system.

// Run in circles, scream and shout.

	for (;;) if (getinp(circuit))
	{
		if (circuit->flags & p_linked)
			chkctl(circuit);
		else
		{
			if (!matchi(circuit->buf, "OK"))
			{
				link_drop(circuit);
				link->flags = p_nil;
				return;
			}

			link->flags    = p_linked;
 	  	circuit->flags = p_linked;
			state_tell(circuit);
		}
	}
	else
	{
		link_drop(circuit);
		link->flags = p_nil;
		return;
	}
}
Ejemplo n.º 14
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
int rtloginu ()
{
	CIRCUIT *c, *circuit;
	USER    *user;

// Is this user already logged in to RT somewhere else?

	if (user_find(CurProc->user))
	{
		tputs("*** Already connected at another node.\n");
		return cmd_exit;
	}

	if (log_rt) tlogp("RT Login");

// Create a circuit for this user.

	circuit = circuit_new(p_user, CurProc->output);
	if (!circuit) return cmd_exit;

// Create the user entry.

	user = user_join(circuit, CurProc->user, Node->calls, Node->aliass);
	circuit->u.user = user;
	tputs("RoundTable Server.\nType /h for command summary.\nBringing up links to other nodes.\n");
	tputs("This may take a minute or two.\nThe /p command shows what nodes are linked.\n");
	text_tellu(user, rtjoin, NULL, o_all);
	user_tell(user, id_join);
	show_users();
	makelinks();

// Run in circles, scream and shout.

	for (;;) if (getinp(circuit))
	{
		if (circuit->buf[0] is '/')
		{
			if (!rt_cmd(circuit))
			{
				tputs("Returned to node.\n");
				logout(circuit);
				return cmd_ok;
			}
		}
		else
		{
			text_tellu(user, circuit->buf, NULL, o_topic); // To local users.

// To remote users.

			for (c = circuit_hd; c; c = c->next)
			if ((c->flags & p_linked) && c->refcnt && ct_find(c, user->topic))
				nprintf(c->s, "%c%c%s %s %s\n",
				FORMAT, id_data, Node->calls, user->call, circuit->buf);
		}
	}
	else
	{
		logout(circuit);
		return cmd_exit;
	}
}