Beispiel #1
0
/* endgame - attempts to pass a constitutional amendment to help win the game */
void amendment_termlimits(char canseethings)
{
   if(termlimits)return; // Durr~! Don't pass this amendment if it's already passed!
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,1);

      move(12,6);
      addstr("A National Convention has proposed an ELITE LIBERAL AMENDMENT!");

      getkey();
   }

   //STATE THE AMENDMENT
   if(canseethings)
   {
      amendmentheading();

      move(2,5);
      addstr("In light of the Conservative nature of entrenched politicians,");
      move(3,0);
      addstr("and the corrupting influence of incumbency on the democratic process,");
      move(4,0);
      addstr("all members of the House of Representatives and Senate shall henceforth");
      move(5,0);
      addstr("be limited to one term in office.  This shall be immediately enforced");
      move(6,0);
      addstr("by holding elections to replace all members of Congress upon the");
      move(7,0);
      addstr("ratification of this amendment.");

      move(24,0);
      addstr("Press 'C' to watch the ratification process unfold.");

      while(getkey()!='c');
   }

   if(ratify(2,-1,-1,0,canseethings))
   {
      termlimits = true;
      if(canseethings)
      {
         move(24,0);
         addstr("Press any key to hold new elections!                           ");

         getkey();
      }
      elections_senate(0,canseethings);
      elections_senate(1,canseethings);
      elections_senate(2,canseethings);
      elections_house(canseethings);

      amendnum++;
   }
   else if(canseethings)
   {
      move(24,0);
      addstr("Press any key to reflect on what has happened.");

      getkey();
   }
}
Beispiel #2
0
/**
 * \param threads - number of threads to run in
 * \param chunk - size of chunk to generate
 * \param stop_after - seconds of generating the chunk. \
 *          Zero to generate only once, negative to infinite (until ESC is pressed)
 * \param stream - stream to write data
 * \param type - which function should be used? GET_UINT8_ARRAY, ...
 * \return throughput in MB/s
 */
double test_throughput( int threads, const size_t chunk, int stop_after, FILE *stream, const int type)
{
	size_t written, total,buf_size;
	uint64_t buf[threads*chunk];
    //char* buf_ptr;
    //uint64_t* buf;
    //size_t size;
	omp_set_num_threads(threads);
	struct timespec t[2];
	double run_time, throughput;
	int key,i;
	unsigned int retry;

	//buf_ptr = malloc(threads*chunk*sizeof(uint64_t)+10);
    //buf = (uint64_t*)&(buf_ptr[3]);
	run_time = 0;
	total = 0;
	clock_gettime(CLOCK_REALTIME, &t[0]);
	if(verbose_flag)
		fprintf(stderr, "Press [Esc] to stop the loop");

	key = 0;
	// SIZE threads*chunk;
	buf_size = SIZEOF(buf);
	do
	{
		written = 0;
#if 0
#pragma omp parallel for reduction(+:written)
		for ( i=0; i<threads; ++i)
		{
			/****************************************************************
			*                      TESTED METHODS INSERT HERE              *
			****************************************************************/
			switch(type)
			{
			case GET_BYTES:
				written += rdrand_get_bytes_retry((uint8_t*)&buf[i*chunk], chunk*8,1)/8;
				break;
			case GET_UINT8_ARRAY:
				written += rdrand_get_uint8_array_retry((uint8_t*)&buf[i*chunk], chunk*8, 1)/8;
				break;
			case GET_UINT16_ARRAY:
				written += rdrand_get_uint16_array_retry((uint16_t*)&buf[i*chunk], chunk*4, 1)/4;
				break;
			case GET_UINT32_ARRAY:
				written += rdrand_get_uint32_array_retry((uint32_t*)&buf[i*chunk], chunk*2, 1)/2;
				break;
			case GET_UINT64_ARRAY:
				written += rdrand_get_uint64_array_retry(&buf[i*chunk], chunk, 1);
				break;


			case GET_RDRAND16_STEP:
				written += fill_uint16_step((uint16_t *)&buf[i*chunk], chunk*4, 1)/4;
				break;
			case GET_RDRAND32_STEP:
				written += fill_uint32_step((uint32_t *)&buf[i*chunk], chunk*2, 1)/2;
				break;
			case GET_RDRAND64_STEP:
				written += fill_uint64_step(&buf[i*chunk], chunk, 1);
				break;

			case GET_RDRAND16_RETRY:
				written += fill_uint16_retry((uint16_t *)&buf[i*chunk], chunk*4, 1)/4;
				break;
			case GET_RDRAND32_RETRY:
				written += fill_uint32_retry((uint32_t *)&buf[i*chunk], chunk*2, 1)/2;
				break;
			case GET_RDRAND64_RETRY:
				written += fill_uint64_retry(&buf[i*chunk], chunk, 1);
				break;

			case GET_RESEED64_DELAY:
				written += rdrand_get_uint64_array_reseed_delay(&buf[i*chunk], chunk, 1);
				break;
			case GET_RESEED64_SKIP:
				written += rdrand_get_uint64_array_reseed_skip(&buf[i*chunk], chunk, 1);
				break;
			}
		}
		/* test generated amount */
		if ( written != SIZEOF(buf) )
		{
			fprintf(stderr, "ERROR: bytes generated %zu, bytes expected %zu\n", written, SIZEOF(buf));
			break;
		}

		if(!no_print_flag)
		{
			/* Test written amount */
			if(print_numbers_flag == 1)
			{
				written = print_numbers(stream, (char *)buf,sizeof(buf))/8;
				// written = fwrite(, sizeof(buf[0]), SIZEOF(buf), stream);
			}
			else
			{
				written = fwrite(buf, sizeof(buf[0]), SIZEOF(buf), stream);
			}
			total += written;
			if ( written !=  SIZEOF(buf) )
			{
				perror("fwrite");
				fprintf(stderr, "ERROR: fwrite - bytes written %zu, bytes to write %zu\n", sizeof(buf[0]) * written, sizeof(buf));
				break;
			}
		}
		else
		{
			total += written;
		}
#else
		#pragma omp parallel for reduction(+:written)
		for ( i=0; i<threads; ++i)
		{
			written += generate_with_metod(type,&buf[i*chunk], chunk, RETRY_LIMIT);


		}

		if ( written != buf_size )
		{
			/* if we can't lower threads count anymore */
			if ( threads == 1 )
			{
				fprintf(stderr, "Warning: %zu bytes generated, but %zu bytes expected. Trying to get randomness with slower speed.\n", written, buf_size);
				retry = 0;
				while(written != buf_size && retry++ < SLOW_RETRY_LIMIT_CYCLES)
				{
					usleep(retry*SLOW_RETRY_DELAY);
					// try to generate the rest
					written +=generate_with_metod(type,buf+written, chunk-written, SLOW_RETRY_LIMIT);
				}
				if( written != buf_size )
				{
					fprintf(stderr, "Error:  %zu bytes generated, but %zu bytes expected. Probably there is a hardware problem with your CPU.\n", written, buf_size);
					break;
				}
			}
			else
			{
				/* try to lower threads count to avoid underflow */
				threads--;
				fprintf(stderr, "Warning: %zu bytes generated, but %zu bytes expected. Probably slow internal generator - decreaseing threads count by one to %d to avoid problems.\n", written, buf_size, threads);
				buf_size -= chunk;

				continue;
			}
		}
		if(!no_print_flag)
		{

			/* Test written amount */
			if(print_numbers_flag == 1)
			{
				written = print_numbers(stream, (char *)buf,sizeof(buf))/8;
				// written = fwrite(, sizeof(buf[0]), SIZEOF(buf), stream);
			}
			else
			{
				written = fwrite(buf, sizeof(buf[0]), SIZEOF(buf), stream);
			}
			total += written;
			if ( written !=  SIZEOF(buf) )
			{
				perror("fwrite");
				fprintf(stderr, "ERROR: fwrite - bytes written %zu, bytes to write %zu\n", sizeof(buf[0]) * written, sizeof(buf));
				break;
			}
		}
		else
		{
			total += written;
		}




#endif // 0

		/* Stopping */
		key = getkey();

		if (stop_after >= 0)
		{
			clock_gettime(CLOCK_REALTIME, &t[1]);
			run_time = (double)(t[1].tv_sec) - (double)(t[0].tv_sec) +
				   ( (double)(t[1].tv_nsec) - (double)(t[0].tv_nsec) ) / 1.0E9;
			if(run_time > stop_after)
				key = 0x1B;
		}
	}
	while (key != 0x1B);

	if(stop_after < 0) // compute only if it wasn't already computed
	{
		clock_gettime(CLOCK_REALTIME, &t[1]);
		run_time = (double)(t[1].tv_sec) - (double)(t[0].tv_sec) +
			   ( (double)(t[1].tv_nsec) - (double)(t[0].tv_nsec) ) / 1.0E9;
	}
	throughput = (double) (total) * sizeof(buf[0]) / run_time/1024.0/1024.0;
	if(verbose_flag)
	{

		if(print_numbers_flag == 1)
			fprintf(stderr,"\n");
		fprintf(stderr, "\r  Runtime %.2f sec, throughput %.3f MiB/s\n", run_time, throughput);
	}

	return throughput;
}
Beispiel #3
0
int pop_up(char **manu,int x,int y,int num)
 { int i,step=1,y1;
   y1=y;
   setcolor(7);
 for(i=1;i<=num;i++)
 {  setcolor(7);
    rectangle(x,y1,x+120,y1+20);
    rectangle(x+1,y1+1,x+119,y1+19);
    setcolor(2);
     //gotoxy(x+20,y1+5);
    // cout<<*manu;
     outtextxy(x+20,y1+5,*manu);
     y1=y1+20;
    **manu++;
    }

  setcolor(1);
  rectangle(x+3,y+3,x+120-3,y+20-3);
  rectangle(x+4,y+4,x+120-4,y+20-4);
  while(1)
  {
    getkey();
   if(ascii==0)
    {switch(scan)
     {case 80:
       if(step==num)
	 {//step=0;
	  // y=y-20*(num-1);
	  break;
	   }
	else
	{ setcolor(0);
	 rectangle(x+3,y+3,x+120-3,y+20-3);
	 rectangle(x+4,y+4,x+120-4,y+20-4);
	 setcolor(1);
	 y=y+20;
	 rectangle(x+3,y+3,x+120-3,y+20-3);
	 rectangle(x+4,y+4,x+120-4,y+20-4);
	 step++;
	 break;
	 }
      case 72:
	if(step==1)
	 {//step=num+1;
	 // y=y+20*(num-1);
	   break;
	   }
	else
	{ setcolor(0);
	 rectangle(x+3,y+3,x+120-3,y+20-3);
	 rectangle(x+4,y+4,x+120-4,y+20-4);
	 y=y-20;
	 setcolor(1);
	 rectangle(x+3,y+3,x+120-3,y+20-3);
	 rectangle(x+4,y+4,x+120-4,y+20-4);
	 step--;
	 break;
	 }
	};
      }
     else
       {if(ascii==13)
	 { return(step);
	   }
	}
      }
}
Beispiel #4
0
Datei: search.c Projekt: sctb/em
/*
 * Incremental Search.
 *	dir is used as the initial direction to search.
 *	^S	switch direction to forward
 *	^R	switch direction to reverse
 *	^Q	quote next character (allows searching for ^N etc.)
 *	<ESC>	exit from Isearch
 *	<DEL>	undoes last character typed. (tricky job to do this correctly).
 *	other ^ exit search, don't set mark
 *	else	accumulate into search string
 */
static int
isearch(int dir)
{
	struct line	*clp;		/* Saved line pointer */
	int		 c;
	int		 cbo;		/* Saved offset */
	int		 success;
	int		 pptr;
	int		 firstc;
	int		 xcase;
	int		 i;
	char		 opat[NPAT];
	int		 cdotline;	/* Saved line number */

	if (macrodef) {
		dobeep();
		ewprintf("Can't isearch in macro");
		return (FALSE);
	}
	for (cip = 0; cip < NSRCH; cip++)
		cmds[cip].s_code = SRCH_NOPR;

	(void)strlcpy(opat, pat, sizeof(opat));
	cip = 0;
	pptr = -1;
	clp = curwp->w_dotp;
	cbo = curwp->w_doto;
	cdotline = curwp->w_dotline;
	is_lpush();
	is_cpush(SRCH_BEGIN);
	success = TRUE;
	is_prompt(dir, TRUE, success);

	for (;;) {
		update(CMODE);

		switch (c = getkey(FALSE)) {
		case CCHR('['):
			/*
			 * If new characters come in the next 300 msec,
			 * we can assume that they belong to a longer
			 * escaped sequence so we should ungetkey the
			 * ESC to avoid writing out garbage.
			 */
			if (ttwait(300) == FALSE)
				ungetkey(c);
			srch_lastdir = dir;
			curwp->w_markp = clp;
			curwp->w_marko = cbo;
			curwp->w_markline = cdotline;
			ewprintf("Mark set");
			return (TRUE);
		case CCHR('G'):
			if (success != TRUE) {
				while (is_peek() == SRCH_ACCM)
					is_undo(&pptr, &dir);
				success = TRUE;
				is_prompt(dir, pptr < 0, success);
				break;
			}
			curwp->w_dotp = clp;
			curwp->w_doto = cbo;
			curwp->w_dotline = cdotline;
			curwp->w_rflag |= WFMOVE;
			srch_lastdir = dir;
			(void)ctrlg(FFRAND, 0);
			(void)strlcpy(pat, opat, sizeof(pat));
			return (ABORT);
		case CCHR('S'):
			if (dir == SRCH_BACK) {
				dir = SRCH_FORW;
				is_lpush();
				is_cpush(SRCH_FORW);
				success = TRUE;
			}
			if (success == FALSE && dir == SRCH_FORW) {
				/* wrap the search to beginning */
				curwp->w_dotp = bfirstlp(curbp);
				curwp->w_doto = 0;
				curwp->w_dotline = 1;
				if (is_find(dir) != FALSE) {
					is_cpush(SRCH_MARK);
					success = TRUE;
				}
				ewprintf("Overwrapped I-search: %s", pat);
				break;
			}
			is_lpush();
			pptr = strlen(pat);
			if (forwchar(FFRAND, 1) == FALSE) {
                                dobeep();
                                success = FALSE;
                                ewprintf("Failed I-search: %s", pat);
			} else {
				if (is_find(SRCH_FORW) != FALSE)
					is_cpush(SRCH_MARK);
				else {
					(void)backchar(FFRAND, 1);
					dobeep();
					success = FALSE;
					ewprintf("Failed I-search: %s", pat);
				}
			}
			is_prompt(dir, pptr < 0, success);
			break;
		case CCHR('R'):
			if (dir == SRCH_FORW) {
				dir = SRCH_BACK;
				is_lpush();
				is_cpush(SRCH_BACK);
				success = TRUE;
			}
			if (success == FALSE && dir == SRCH_BACK) {
				/* wrap the search to end */
				curwp->w_dotp = blastlp(curbp);
				curwp->w_doto = llength(curwp->w_dotp);
				curwp->w_dotline = curwp->w_bufp->b_lines;
				if (is_find(dir) != FALSE) {
					is_cpush(SRCH_MARK);
					success = TRUE;
				}
				ewprintf("Overwrapped I-search: %s", pat);
				break;
			}
			is_lpush();
			pptr = strlen(pat);
                        if (backchar(FFRAND, 1) == FALSE) {
                                dobeep();
                                success = FALSE;
                        } else {
				if (is_find(SRCH_BACK) != FALSE)
					is_cpush(SRCH_MARK);
				else {
					(void)forwchar(FFRAND, 1);
					dobeep();
					success = FALSE;
				}
			}
			is_prompt(dir, pptr < 0, success);
			break;
		case CCHR('W'):
			/* add the rest of the current word to the pattern */
			clp = curwp->w_dotp;
			cbo = curwp->w_doto;
			firstc = 1;
			if (pptr == -1)
				pptr = 0;
			if (dir == SRCH_BACK) {
				/* when isearching backwards, cbo is the start of the pattern */
				cbo += pptr;
			}

			/* if the search is case insensitive, add to pattern using lowercase */
			xcase = 0;
			for (i = 0; pat[i]; i++)
				if (ISUPPER(CHARMASK(pat[i])))
					xcase = 1;

			while (cbo < llength(clp)) {
				c = lgetc(clp, cbo++);
				if ((!firstc && !isalnum(c)))
					break;

				if (pptr == NPAT - 1) {
					dobeep();
					break;
				}
				firstc = 0;
				if (!xcase && ISUPPER(c))
					c = TOLOWER(c);

				pat[pptr++] = c;
				pat[pptr] = '\0';
				/* cursor only moves when isearching forwards */
				if (dir == SRCH_FORW) {
					curwp->w_doto = cbo;
					curwp->w_rflag |= WFMOVE;
					update(CMODE);
				}
			}
			is_prompt(dir, pptr < 0, success);
			break;
		case CCHR('H'):
		case CCHR('?'):
			is_undo(&pptr, &dir);
			if (is_peek() != SRCH_ACCM)
				success = TRUE;
			is_prompt(dir, pptr < 0, success);
			break;
		case CCHR('\\'):
		case CCHR('Q'):
			c = (char)getkey(FALSE);
			goto addchar;
		case CCHR('M'):
			c = CCHR('J');
			goto addchar;
		default:
			if (ISCTRL(c)) {
				ungetkey(c);
				curwp->w_markp = clp;
				curwp->w_marko = cbo;
				curwp->w_markline = cdotline;
				ewprintf("Mark set");
				curwp->w_rflag |= WFMOVE;
				return (TRUE);
			}
			/* FALLTHRU */
		case CCHR('I'):
		case CCHR('J'):
	addchar:
			if (pptr == -1)
				pptr = 0;
			if (pptr == 0)
				success = TRUE;
			if (pptr == NPAT - 1)
				dobeep();
			else {
				pat[pptr++] = c;
				pat[pptr] = '\0';
			}
			is_lpush();
			if (success != FALSE) {
				if (is_find(dir) != FALSE)
					is_cpush(c);
				else {
					success = FALSE;
					dobeep();
					is_cpush(SRCH_ACCM);
				}
			} else
				is_cpush(SRCH_ACCM);
			is_prompt(dir, FALSE, success);
		}
	}
	/* NOTREACHED */
}
Beispiel #5
0
int main(int argc, char **argv)
{
	char str[81],compiler[32],*p;
	int i,file;
	FILE *stream;

	node_dir[0]=0;
	for(i=1;i<argc;i++)
		if(!stricmp(argv[i],"/L"))
			logit=1;
		else if(!stricmp(argv[i],"/T"))
			tutor=2;
		else if(!stricmp(argv[i],"/S"))
			tutor=1;
		else strcpy(node_dir,argv[i]);

	p=getenv("SBBSNODE");
	if(!node_dir[0] && p)
		strcpy(node_dir,p);

	if(!node_dir[0]) {	  /* node directory not specified */
		printf("usage: sbj <node directory> [/options]\r\n");
		printf("\r\noptions: L = log wins/losses for each day\r\n");
		getch();
		return(1); }

	if(node_dir[strlen(node_dir)-1]!='\\'
		&& node_dir[strlen(node_dir)-1]!='/')  /* make sure node_dir ends in '\' */
		strcat(node_dir,"/");

	initdata(); 								/* read XTRN.DAT and more */
	credits=user_cdt;
	total_nodes=sys_nodes;

	remove("debug.log");

	if((file=nopen("sbj.cfg",O_RDONLY))==-1) {  /* open config file */
		bputs("Error opening sbj.cfg\r\n");
		pause();
		return(1); }
	if((stream=fdopen(file,"rb"))==NULL) {      /* convert to stream */
		bputs("Error converting sbj.cfg handle to stream\r\n");
		pause();
		return(1); }
	fgets(str,81,stream);						/* number of decks in shoe */
	total_decks=sys_decks=atoi(str);
	fgets(str,81,stream);						/* min bet (in k) */
	min_bet=atoi(str);
	fgets(str,81,stream);						/* max bet (in k) */
	max_bet=atoi(str);
	fgets(str,81,stream);						/* default bet (in k) */
	ibet=atoi(str);
	fclose(stream);
	if(!total_decks || total_decks>MAX_DECKS) {
		bputs("Invalid number of decks in sbj.cfg\r\n");
		pause();
		return(1); }
	if(!max_bet) {
		bputs("Invalid max bet in sbj.cfg\r\n");
		pause();
		return(1); }
	if(min_bet>max_bet) {
		bputs("Invalid min bet in sbj.cfg\r\n");
		pause();
		return(1); }
	if(ibet>max_bet || ibet<min_bet) {
		bputs("Invalid default bet in sbj.cfg\r\n");
		pause();
		return(1); }

	if(!fexist("card.dab")) {
		cur_card=0;
		dc=0;
		memset(dealer,0,sizeof(dealer));
		memset(card,0,sizeof(card));
		putcarddat(); }
	else {
		getcarddat();
		if(total_decks!=sys_decks) {
			remove("card.dab");
			total_decks=sys_decks;
			putcarddat(); } }

	if(!fexist("game.dab"))         /* File's not there */
		create_gamedab();

	open_gamedab();

	getgamedat(0);
	if(total_nodes!=sys_nodes) {  /* total nodes changed */
		close(gamedab);
		total_nodes=sys_nodes;
		create_gamedab();
		open_gamedab(); }

	srand((unsigned)time(NULL));

#ifdef __16BIT__
	while(_bios_keybrd(1))	 /* clear input buffer */
		_bios_keybrd(0);
#endif

	putchar(5); /* ctrl-e */
	mswait(500);
	if(keyhit()) {
#ifdef __16BIT__
		while(_bios_keybrd(1))
			_bios_keybrd(0);
#else
		getkey(0);
#endif
		bputs("\r\n\1r\1h\1i*** ATTENTION ***\1n\1h\r\n");
		bputs("\r\nSynchronet Blackjack uses Ctrl-E (ENQ) for the 'club' card "
			"symbol.");
		bputs("\r\nYour terminal responded to this control character with an "
			"answerback string.");
		bputs("\r\nYou will need to disable all Ctrl-E (ENQ) answerback "
			"strings (Including \r\nCompuserve Quick B transfers) if you wish to "
			"toggle card symbols on.\r\n\r\n");
		symbols=0;
		pause(); }

	getgamedat(1);
	node[node_num-1]=0;
	putgamedat();

	/* Override default mnemonic colors */
	mnehigh=RED|HIGH;
	mnelow=CYAN|HIGH;

	/* Override default inactivity timeout values */
	sec_warn=120;	
	sec_timeout=180;

	COMPILER_DESC(compiler);

#define SBJ_INDENT "                                "
	while(1) {
		cls();
		sprintf(str,"\1n\1h\1cSynchronet \1rBlackjack! \1cv3.20 for %s\r\n"
			,PLATFORM_DESC);
		center(str);
		sprintf(str,"\1w(XSDK v%s %s %s)\r\n\r\n"
            ,xsdk_ver,compiler,__DATE__);
		center(str);

		aborted=0;
		mnemonics(SBJ_INDENT"~Instructions\r\n");
		mnemonics(SBJ_INDENT"~Join/Begin Game\r\n");
		mnemonics(SBJ_INDENT"~List Players\r\n");
		mnemonics(SBJ_INDENT"~Rules of the Game\r\n");
		mnemonics(SBJ_INDENT"~Toggle Card Symbols\r\n");
		sprintf(str,SBJ_INDENT"~Quit to %s\r\n",sys_name);
		mnemonics(str);
		nodesync();
		bprintf("\1_\r\n"SBJ_INDENT"\1y\1hWhich: \1n");
		switch(getkeys("IJBLRTQ|!",0)) {
			#if DEBUG
			case '!':
				if(!com_port)
					autoplay=1;
				break;
			case '|':
				debug();
				break;
			#endif
			case 'I':
				cls();
				printfile("sbj.msg");
				break;
			case 'L':
				listplayers();
				bprintf(ShoeStatus,cur_card,total_decks*52);
				break;
			case 'R':
				bprintf("\1n\1c\r\nMinimum bet: \1h%uk",min_bet);
				bprintf("\1n\1c\r\nMaximum bet: \1h%uk\r\n",max_bet);
				bprintf("\1w\1h\r\nCard decks in shoe: \1h%u\r\n",sys_decks);
				break;
			case 'T':
				symbols=!symbols;
				bprintf("\1_\1w\r\nCard symbols now: %s\r\n",symbols ? "ON":"OFF");
				break;
			case 'Q':
				exit(0);
			case 'J':
			case 'B':
				sec_warn=60;	/* Override default inactivity timeout values */
				sec_timeout=90;
				play();
				sec_warn=120;
				sec_timeout=180;
				break; 
		} 
	}
}
/* base - liberal agenda */
bool liberalagenda(signed char won)
{
   int page=0, y;

   while(true)
   {
      erase();
      if(won==1)
      {
         set_color(COLOR_GREEN,COLOR_BLACK,1);
         move(0,0);
         addstr("The Triumph of the Liberal Agenda");
         music.play(MUSIC_VICTORY);
      }
      else if(won==-1||won==-2)
      {
         set_color(COLOR_RED,COLOR_BLACK,1);
         move(0,0);
         addstr("The Abject Failure of the Liberal Agenda");
         if(won==-1) music.play(MUSIC_REAGANIFIED);
         if(won==-2) music.play(MUSIC_STALINIZED);
      }
      else
      {
         set_color(COLOR_WHITE,COLOR_BLACK,1);
         move(0,0);
         addstr("The Status of the Liberal Agenda");
         music.play(MUSIC_LIBERALAGENDA);
      }

      if(page<0) page=PAGENUM-1;
      if(page>=PAGENUM) page=0;

      switch(page)
      {
      case PAGE_LEADERS:
      {

         move(1,0);
         addstr("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»ÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿");
         move(2,0);
         addstr("º GENERAL SUMMARY º ISSUES A ³ ISSUES B ³");
         move(3,0);
         addstr("¼                 ÈÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");

         signed char align=exec[EXEC_PRESIDENT];
         set_alignment_color(align,true);
         move(5,0);
         if(won==-1) addstr("King: ");
         else if(won==-2) addstr("General Secretary: ");
         else
         {
            addstr("President ");
            if(execterm==1)addstr("(1st Term):");
            else addstr("(2nd Term):");
         }
         if(won==-2) move(5,30);
         else move(5,25);
         addstr(execname[EXEC_PRESIDENT]);

         align=exec[EXEC_VP];
         set_alignment_color(align,true);
         move(6,0);
         if(won==-1) addstr("Minister of Love: ");
         else if(won==-2) addstr("Premier: ");
         else addstr("Vice President: ");
         if(won==-2) move(6,30);
         else move(6,25);
         addstr(execname[EXEC_VP]);

         align=exec[EXEC_STATE];
         set_alignment_color(align,true);
         move(7,0);
         if(won==-1) addstr("Minister of Peace: ");
         else if(won==-2) addstr("Foreign Affairs Commissar: ");
         else addstr("Secretary of State: ");
         if(won==-2) move(7,30);
         else move(7,25);
         addstr(execname[EXEC_STATE]);

         align=exec[EXEC_ATTORNEY];
         set_alignment_color(align,true);
         move(8,0);
         if(won==-1) addstr("Minister of Truth: ");
         else if(won==-2) addstr("Internal Affairs Commissar: ");
         else addstr("Attorney General: ");
         if(won==-2) move(8,30);
         else move(8,25);
         addstr(execname[EXEC_ATTORNEY]);

         if(won==-1)
         {
            set_color(COLOR_RED,COLOR_BLACK,1);
            move(10,0);
            addstr("The Congress consists of CEOs and televangelists.");
         }
         else if(won==-2)
         {
            set_color(COLOR_RED,COLOR_BLACK,1);
            move(10,0);
            addstr("The Congress consists of Stalinist Party loyalists.");
         }
         else
         {
            int housemake[6]={0,0,0,0,0,0};
            for(int h=0;h<HOUSENUM;h++) housemake[house[h]+2]++;
            if(housemake[5]+MIN(housemake[0],housemake[4])>=HOUSEMAJORITY) align=ALIGN_STALINIST; // Stalinists have a majority (perhaps with help from extremists on both sides)
            else if(housemake[0]>=HOUSEMAJORITY) align=ALIGN_ARCHCONSERVATIVE; // Arch-Conservatives have a majority
            else if(housemake[4]>=HOUSEMAJORITY) align=ALIGN_ELITELIBERAL; // Elite Liberals have a majority
            else if(housemake[0]+housemake[1]>=HOUSEMAJORITY) align=ALIGN_CONSERVATIVE; // Conservatives plus Arch-Conservatives have a majority
            else if(housemake[3]+housemake[4]>=HOUSEMAJORITY) align=ALIGN_LIBERAL; // Liberals plus Elite Liberals have a majority
            else align=ALIGN_MODERATE; // nobody has a majority
            set_alignment_color(align,true);
            mvaddstr(10,0,"House: ");
            if(stalinmode) addstr(tostring(housemake[5])+"Sta, ");
            addstr(tostring(housemake[4])+"Lib+, ");
            addstr(tostring(housemake[3])+"Lib, ");
            addstr(tostring(housemake[2])+"Mod, ");
            addstr(tostring(housemake[1])+"Cons, ");
            addstr(tostring(housemake[0])+"Cons+");

            int senatemake[6]={0,0,0,0,0,0};
            for(int s=0;s<SENATENUM;s++) senatemake[senate[s]+2]++;
            senatemake[exec[EXEC_VP]+2]++; // Vice President is tie-breaking vote in the Senate
            if(senatemake[5]+MIN(senatemake[0],senatemake[4])>=SENATEMAJORITY) align=ALIGN_STALINIST; // Stalinists have a majority (perhaps with help from extremists on both sides)
            else if(senatemake[0]>=SENATEMAJORITY) align=ALIGN_ARCHCONSERVATIVE; // Arch-Conservatives have a majority
            else if(senatemake[4]>=SENATEMAJORITY) align=ALIGN_ELITELIBERAL; // Elite Liberals have a majority
            else if(senatemake[0]+senatemake[1]>=SENATEMAJORITY) align=ALIGN_CONSERVATIVE; // Conservatives plus Arch-Conservatives have a majority
            else if(senatemake[3]+senatemake[4]>=SENATEMAJORITY) align=ALIGN_LIBERAL; // Liberals plus Elite Liberals have a majority
            else align=ALIGN_MODERATE; // nobody has a majority
            set_alignment_color(align,true);
            senatemake[exec[EXEC_VP]+2]--; // Vice President isn't actually a Senator though
            mvaddstr(11,0,"Senate: ");
            if(stalinmode) addstr(tostring(senatemake[5])+"Sta, ");
            addstr(tostring(senatemake[4])+"Lib+, ");
            addstr(tostring(senatemake[3])+"Lib, ");
            addstr(tostring(senatemake[2])+"Mod, ");
            addstr(tostring(senatemake[1])+"Cons, ");
            addstr(tostring(senatemake[0])+"Cons+");
         }

         if(won==-1||won==-2) set_color(COLOR_RED,COLOR_BLACK,1);
         else if(won==1) set_color(COLOR_GREEN,COLOR_BLACK,1);
         else
         {
            int courtmake[6]={0,0,0,0,0,0};
            for(int s=0;s<COURTNUM;s++) courtmake[court[s]+2]++;
            if(courtmake[5]+MIN(courtmake[0],courtmake[4])>=COURTMAJORITY) align=ALIGN_STALINIST; // Stalinists have a majority (perhaps with help from extremists on both sides)
            else if(courtmake[0]>=COURTMAJORITY) align=ALIGN_ARCHCONSERVATIVE; // Arch-Conservatives have a majority
            else if(courtmake[4]>=COURTMAJORITY) align=ALIGN_ELITELIBERAL; // Elite Liberals have a majority
            else if(courtmake[0]+courtmake[1]>=COURTMAJORITY) align=ALIGN_CONSERVATIVE; // Conservatives plus Arch-Conservatives have a majority
            else if(courtmake[3]+courtmake[4]>=COURTMAJORITY) align=ALIGN_LIBERAL; // Liberals plus Elite Liberals have a majority
            else align=ALIGN_MODERATE; // nobody has a majority
            set_alignment_color(align,true);
         }

         mvaddchar(5,56,'S');
         mvaddchar(6,56,'U');
         mvaddchar(7,56,'P');
         mvaddchar(8,56,'R');
         mvaddchar(9,56,'E');
         mvaddchar(10,56,'M');
         mvaddchar(11,56,'E');

         mvaddchar(6,58,'C');
         mvaddchar(7,58,'O');
         mvaddchar(8,58,'U');
         mvaddchar(9,58,'R');
         mvaddchar(10,58,'T');

         if(won==-1)
         {
            mvaddstr(7,65,   "Replaced");
            mvaddstr(8,63, "By Corporate");
            mvaddstr(9,62,"Ethics Officers");
         }
         else if(won==-2)
         {
            mvaddstr(7,63, "Replaced By");
            mvaddstr(8,62,"Stalinist Show");
            mvaddstr(9,63, "Trial Judges");
         }
         else
         {
            y=4;
            for(int c=0;c<COURTNUM;c++,y++)
            {
               set_alignment_color(court[c],true);
               mvaddstr(y,60,courtname[c]);
            }
         }
         for(int l=0;l<LAWNUM;l++)
         {
            if(won==-1||won==-2)
               set_alignment_color(ALIGN_ARCHCONSERVATIVE,true);
            else if(won==1&&wincondition==WINCONDITION_ELITE)
               set_alignment_color(ALIGN_ELITELIBERAL,true);
            else set_color(COLOR_BLACK,COLOR_BLACK,1);
            mvaddstr(14+l/3,l%3*26,"\x11ÄÄÄÄÄ\x10");
            if(won==-1||won==-2)
               set_alignment_color(ALIGN_ARCHCONSERVATIVE,true);
            else set_alignment_color(law[l],true);
            addstr(getlaw(l));
            mvaddchar(14+l/3,l%3*26 + 3 - law[l],'O');
         }
         break;
      }

      case PAGE_ISSUES_A:
      case PAGE_ISSUES_B:
      {
         if(page==PAGE_ISSUES_A)
         {
            move(1,0);
            addstr("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÉÍÍÍÍÍÍÍÍÍÍ»ÄÄÄÄÄÄÄÄÄÄ¿");
            move(2,0);
            addstr("³ GENERAL SUMMARY º ISSUES A º ISSUES B ³");
            move(3,0);
            addstr("ÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ          ÈÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
         }
         else
         {
            move(1,0);
            addstr("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÉÍÍÍÍÍÍÍÍÍÍ»");
            move(2,0);
            addstr("³ GENERAL SUMMARY ³ ISSUES A º ISSUES B º");
            move(3,0);
            addstr("ÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍͼ          ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
         }

         int y=4,startinglaw=0;
         if(page==PAGE_ISSUES_B) startinglaw=18;
         for(int l=startinglaw;l<startinglaw+18&&l<LAWNUM;l++,y++)
         {
            if(won==-1||won==-2)
               set_alignment_color(ALIGN_ARCHCONSERVATIVE,true);
            else set_alignment_color(law[l],true);

            move(y,0);

            switch(l)
            {
               case LAW_WOMEN:
                  if(won==-2)addstr("Women are usually drafted into the armed forces to fight in place of men.");
                  else if(won==-1)addstr("Women are considered property, and rape has been legalized.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Women are second-class citizens.");
                  else if(law[l]==-1)addstr("Non-discrimination laws do not apply to gender.");
                  else if(law[l]==0)addstr("Women are nominally equal under law, but this is not enforced.");
                  else if(law[l]==1)addstr("Women have substantial recourse against discrimination.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Gender equality is universally respected.");
                  else addstr("Binary gender identities no longer exist, and gender segregation has ended.");
                  break;
               case LAW_CIVILRIGHTS:
                  if(won==-2)addstr("Entire ethnic groups are branded \"enemies of the state\".");
                  else if(won==-1)addstr("Slavery has been reintroduced, along with an apartheid system.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Civil rights laws have been repealed, ostensibly to promote \"states' rights\".");
                  else if(law[l]==-1)addstr("Racial discrimination is prohibited in name only.");
                  else if(law[l]==0)addstr("Pervasive racial inequality exists, although overt discrimination is illegal.");
                  else if(law[l]==1)addstr("Affirmative action is in place to counteract racial discrimination.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Racial equality is guaranteed and vigorously enforced.");
                  else addstr("The very idea of \"race\" has been universally discarded as pseudoscience.");
                  break;
               case LAW_DRUGS:
                  if(won==-2)addstr("Vodka is the only legal recreational drug in the People's Republic of America.");
                  else if(won==-1)addstr("Talking about recreational drugs is punishable by death.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Violent criminals are released to make room for drug offenders.");
                  else if(law[l]==-1)addstr("Prisons are filled with the targets of a war on drugs.");
                  else if(law[l]==0)addstr("Recreational drugs are prohibited unless medically prescribed.");
                  else if(law[l]==1)addstr("Marijuana is regulated and taxed, but harder drugs are illegal.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Recreational drugs all are regulated and taxed like alcohol and tobacco.");
                  else addstr("The government distributes free recreational drugs to anyone who wants them.");
                  break;
               case LAW_IMMIGRATION:
                  if(won==-2)addstr("All Americans must carry around an internal passport, or be shot on sight.");
                  else if(won==-1)addstr("Private border militiamen shoot suspected foreigners on sight.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Immigration is illegal, and noncitizens are shipped to Mexico at gunpoint.");
                  else if(law[l]==-1)addstr("The National Guard has been deployed to the borders to slow immigration.");
                  else if(law[l]==0)addstr("Great expense is taken to slow immigration, without success.");
                  else if(law[l]==1)addstr("The government works to accommodate potential immigrants but deports criminals.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Immigration is unregulated, and new immigrants are welcomed warmly.");
                  else addstr("There are open borders, and no distinctions between citizens and non-citizens.");
                  break;
               case LAW_ELECTIONS:
                  if(won==-2)addstr("Only Stalinist Party members may run in elections, and they all run unopposed.");
                  else if(won==-1)addstr("Instead of elections, political offices are auctioned off to the highest bidder.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                  addstr("Virtually no ethics restrictions exist on political officeholders.");
                  else if(law[l]==-1)addstr("Elections are mostly unregulated, but basic ethics restrictions are in place.");
                  else if(law[l]==0)addstr("Moderate campaign finance reform is implemented.");
                  else if(law[l]==1)addstr("Election financing is transparent and well-regulated.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Election expenses are publicly funded, and voting is by ranked list.");
                  else addstr("There is proportional representation, and over a dozen major political parties.");
                  break;
               case LAW_MILITARY:
                  if(won==-2)addstr("The military promotes Stalinism throughout the world by using force.");
                  else if(won==-1)addstr("The massive military kills dissenters at home and conquers poor nations abroad.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                  addstr("Out-of-control military spending funds several ongoing wars around the world.");
                  else if(law[l]==-1)addstr("Massive investment is put into the military, which always seems to be at war.");
                  else if(law[l]==0)addstr("Military spending is growing each year to fund overseas military adventures.");
                  else if(law[l]==1)addstr("The military is not a major priority, and mostly does peacekeeping missions.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The military has been weakened significantly, as there is little need for it.");
                  else addstr("The military has been abolished, and the entire world is at peace.");
                  break;
               case LAW_TORTURE:
                  if(won==-2)addstr("The Internal Affairs Commissariat constantly invents new methods of torture.");
                  else if(won==-1)addstr("The new Inquisition tortures heretics, blasphemers, and non-Christians to death.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Military and intelligence interrogators regularly engage in torture.");
                  else if(law[l]==-1)addstr("The line between standard interrogation and torture is severely blurred.");
                  else if(law[l]==0)addstr("Torture allegations still occasionally crop up, despite an official ban.");
                  else if(law[l]==1)addstr("The government strongly enforces a ban on torture.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The nation is a respected international leader on Moral Interrogation Practices.");
                  else addstr("Terrorism ended after the government formally apologized to terrorist leaders.");
                  break;
               case LAW_PRISONS:
                  if(won==-2)addstr("The former nation of Canada has been annexed and filled with Stalinist gulags.");
                  else if(won==-1)addstr("Prisoners must fight to the death in corporate-sponsored gladiatorial bouts.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Prisoners are often subject to torture and slave labor.");
                  else if(law[l]==-1)addstr("Prisoners suffer from horrible conditions and lack of basic rights.");
                  else if(law[l]==0)addstr("Prisoners receive basic rights and services, but reports of abuse are common.");
                  else if(law[l]==1)addstr("The prisons are regulated to protect prisoners' rights and safety.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The prisons are targeted at rehabilitation, rather than punishment.");
                  else addstr("Instead of prison, criminals voluntarily attend free support groups.");
                  break;
	           case LAW_TAX:
                  if(won==-2)addstr("Having any money whatsoever is punishable by 20 years in a gulag.");
                  else if(won==-1)addstr("There are no taxes, yet most people have no money.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("The tax code is a nightmare designed to maintain class structure.");
                  else if(law[l]==-1)addstr("A flat tax is in effect, and there is no capital gains or inheritance tax.");
                  else if(law[l]==0)addstr("Taxes are moderate, but the code is full of loopholes.");
                  else if(law[l]==1)addstr("The wealthy are heavily taxed under a progressive taxation system.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Rich people are virtually unheard of, due to taxation.");
                  else addstr("Money no longer exists, everything is free, and everyone enjoys lives of luxury.");
                  break;
               case LAW_ABORTION:
                  if(won==-2)addstr("Mandatory abortions are carried out for population control.");
                  else if(won==-1)addstr("Abortion, contraception, and consensual sex are all capital offenses.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Abortion is a felony equal to murder, not allowed under any circumstance.");
                  else if(law[l]==-1)addstr("Abortion is prohibited except in cases of rape, incest, or health of the mother.");
                  else if(law[l]==0)addstr("Abortion is limited to the first trimester, and is very expensive.");
                  else if(law[l]==1)addstr("Abortion is legal, but taxpayer funding of abortion is prohibited.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The right to an abortion is strongly protected, and subsidized for poor women.");
                  else addstr("Free abortions are easily available at any time during pregnancy.");
                  break;
               case LAW_ANIMALRESEARCH:
                  if(won==-2)addstr("All forms of human experimentation on \"class enemies\" are encouraged.");
                  else if(won==-1)addstr("All forms of human experimentation on the poor are encouraged.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Animals are property that can be experimented upon freely.");
                  else if(law[l]==-1)addstr("Animal testing is self-regulated by the scientific community.");
                  else if(law[l]==0)addstr("Animal research is regulated with a system of licenses and certificates.");
                  else if(law[l]==1)addstr("Animal research is strictly regulated by purpose and suffering caused.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Animals are people, too, and have full citizenship rights.");
                  else addstr("All species of life have equal rights as people, even bacteria.");
                  break;
               case LAW_POLICEBEHAVIOR:
                  if(won==-2)addstr("Everyone lives in constant fear of the Stalinist Party's Secret Police.");
                  else if(won==-1)addstr("Privatized police get bonuses on their paychecks for every person they kill.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Law enforcement is given free reign.");
                  else if(law[l]==-1)addstr("Even the worst police misconduct only earns slap-on-the-wrist punishments.");
                  else if(law[l]==0)addstr("Law enforcement is regulated to prevent extreme misconduct.");
                  else if(law[l]==1)addstr("Law enforcement has heavy oversight and freedom-of-information requirements.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("All law enforcement positions are subject to election and recall.");
                  else addstr("With no police, criminals follow the honor system and turn themselves in.");
                  break;
               case LAW_PRIVACY:
                  if(won==-2)addstr("Citizens have to spy on each other and report to the Stalinist Party.");
                  else if(won==-1)addstr("Very detailed reports on each citizen are easily accessible to corporations.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Any corporation requesting private information is granted unrestricted access.");
                  else if(law[l]==-1)addstr("Privacy laws are full of loopholes and security backdoors are in everything.");
                  else if(law[l]==0)addstr("Basic safeguards for medical and financial privacy are in place but ineffective.");
                  else if(law[l]==1)addstr("All areas of privacy are protected with strong, effective safeguards.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Individual privacy is sacred, and state-of-the-art safeguards are mandatory.");
                  else addstr("All large organizations are prohibited from keeping any data about anyone.");
                  break;
               case LAW_DEATHPENALTY:
                  if(won==-2)addstr("Class enemies receive mandatory death sentences.");
                  else if(won==-1)addstr("Poor and minority criminals receive mandatory death sentences.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("People can be put to death for minor offenses.");
                  else if(law[l]==-1)addstr("The death penalty is actively enforced in many states.");
                  else if(law[l]==0)addstr("The death penalty is in effect but under scrutiny.");
                  else if(law[l]==1)addstr("The death penalty is only permitted in extreme cases.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The death penalty is considered barbaric and never practiced.");
                  else addstr("The death penalty, like all other harsh punishments, has been abolished.");
                  break;
               case LAW_NUCLEARPOWER:
                  if(won==-2)addstr("Nuclear power plants routinely have meltdowns but keep getting built.");
                  else if(won==-1)addstr("Nuclear power plants are ubiquitous and cancer rates are astronomical.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Nuclear power is wildly proliferating with no controls or regulation at all.");
                  else if(law[l]==-1)addstr("Nuclear power is a preferred energy source and the industry self-regulates.");
                  else if(law[l]==0)addstr("Nuclear power is often an energy source and only moderately regulated.");
                  else if(law[l]==1)addstr("Nuclear power is intensely regulated and rarely used anymore.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Nuclear power is illegal and the leftover nuclear waste is being cleaned up.");
                  else addstr("A global ban on nuclear power and nuclear weapons is enforced by UN inspectors.");
                  break;
               case LAW_POLLUTION:
                  if(won==-2)addstr("State-run industries pollute so much, the workers all have cancer.");
                  else if(won==-1)addstr("Deformed children are the norm in the vast industrial wastelands.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Industry may pollute as much as they like.");
                  else if(law[l]==-1)addstr("Industry voluntarily regulates pollution.");
                  else if(law[l]==0)addstr("Industry is subject to moderate pollution regulations.");
                  else if(law[l]==1)addstr("Industry is subject to strict pollution regulations.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Industry is subject to zero-tolerance pollution regulations.");
                  else addstr("Pollution is unheard of, and nature has reclaimed much of the land.");
                  break;
               case LAW_LABOR:
                  if(won==-2)addstr("The state has nationalized all industries and assigns everyone jobs.");
                  else if(won==-1)addstr("People are bred in pens to be farmed out to corporations like beasts.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("There is no weekend, children are forced to work, and workers can't afford food.");
                  else if(law[l]==-1)addstr("Working conditions are deplorable and there is no minimum wage.");
                  else if(law[l]==0)addstr("Workers are underpaid, have lousy benefits, and get fired if they complain.");
                  else if(law[l]==1)addstr("Workers are fairly compensated, have good benefits, and are difficult to fire.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("There are universal workers' rights and a high guaranteed minimum income.");
                  else addstr("Wage slavery has been abolished, and robots have been built to do all the work.");
                  break;
               case LAW_GAY:
                  if(won==-2)addstr("Homosexuals are executed regularly for their \"bourgeoisie decadence\".");
                  else if(won==-1)addstr("Homosexuals are executed regularly for \"promoting the Gay Agenda\".");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Homosexuals are routinely persecuted with no recourse.");
                  else if(law[l]==-1)addstr("Homosexuals are not tolerated.");
                  else if(law[l]==0)addstr("Homosexuals are grudgingly tolerated but have few equal rights.");
                  else if(law[l]==1)addstr("Homosexuals have many rights shared by heterosexuals.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Homosexuals have equal rights that are vigorously protected.");
                  else addstr("All sexual orientations are accepted, and most people are polyamorous.");
                  break;
               case LAW_CORPORATE:
                  if(won==-2)addstr("All forms of private enterprise are punishable by death.");
                  else if(won==-1)addstr("Corporations under the King run the country in a feudal system.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Corporations essentially run the country in a feudal system.");
                  else if(law[l]==-1)addstr("Corporate culture is corrupt and there is a great disparity in wages.");
                  else if(law[l]==0)addstr("Corporations are moderately regulated, although wages are still unfair.");
                  else if(law[l]==1)addstr("Corporations are stiffly regulated, and executive compensation is reasonable.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Corporations are subject to intense regulation, and there is a maximum wage law.");
                  else addstr("Corporations have been abolished, along with the rest of capitalism.");
                  break;
               case LAW_FREESPEECH:
                  if(won==-2)addstr("Counterrevolutionary speech is a capital crime.");
                  else if(won==-1)addstr("Even *THINKING* about saying something unacceptable is a capital crime.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Armored squads are tasked with suppressing unacceptable speech.");
                  else if(law[l]==-1)addstr("People who express unpopular opinions are often harassed and mistreated.");
                  else if(law[l]==0)addstr("Free speech is legal, with minor exceptions, and is usually tolerated.");
                  else if(law[l]==1)addstr("Free speech is legally protected and publicly encouraged.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("Free speech is strongly protected and universally supported.");
                  else addstr("Free speech is sacrosanct and diverse points of view are celebrated.");
                  break;
               case LAW_FLAGBURNING:
                  if(won==-2)addstr("Flags of the old American regime are burnt primarily as fuel.");
                  else if(won==-1)addstr("Images or words describing flag burning are punished by death.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Burning the flag is a serious crime on par with murder.");
                  else if(law[l]==-1)addstr("Burning the flag is a felony and vigorously prosecuted.");
                  else if(law[l]==0)addstr("Flag-burning is a misdemeanor, but not a serious crime.");
                  else if(law[l]==1)addstr("Flag-burning is technically legal but stigmatized as unpatriotic.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("The right of flag-burning is upheld even by its critics.");
                  else addstr("Flag-burning is traditionally done on July 4th to celebrate freedom.");
                  break;
               case LAW_GUNCONTROL:
                  if(won==-2)addstr("Anyone owning a gun is executed by firing squad.");
                  else if(won==-1)addstr("Gangs of young children carrying AK-47s roam the streets.");
                  else if(law[l]==ALIGN_ARCHCONSERVATIVE)
                     addstr("Machine guns, tanks, and missiles can be bought and sold freely.");
                  else if(law[l]==-1)addstr("Military weapons are banned, but similar-looking guns are available.");
                  else if(law[l]==0)addstr("A comprehensive ban on military-style weapons is in effect.");
                  else if(law[l]==1)addstr("Most guns cannot be sold to anyone outside of law enforcement.");
                  else if(won!=1||wincondition!=WINCONDITION_ELITE)addstr("It is illegal to buy or sell a gun, or carry one in public.");//XXX: Should guns be legal in private, too? -- LK
                  else addstr("All gun manufacturers have been shut down and all existing guns destroyed."); //They are illegal in private under Elite Liberal victory conditions - yetisyny
                  break;
            }
         }
         break;
      }
      }

      if(won==1)
      {
         set_color(COLOR_GREEN,COLOR_BLACK,1);
         if(wincondition==WINCONDITION_EASY)
            mvaddstr(23,0,"The country has achieved Liberal status!");
         else mvaddstr(23,0,"The country has achieved Elite Liberal status!");
         mvaddstr(24,0,"Press 'L' to view the high score list.");

         int c=getkey();

         if(c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT) page++;
         else if(c==interface_pgup||c==KEY_UP||c==KEY_LEFT) page--;
         else if(c=='l') break;
      }
      else if(won==-1)
      {
         set_color(COLOR_RED,COLOR_BLACK,1);
         mvaddstr(23,0,"The country has been Reaganified.");
         mvaddstr(24,0,"Press 'L' to view the high score list.");

         int c=getkey();

         if(c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT) page++;
         else if(c==interface_pgup||c==KEY_UP||c==KEY_LEFT) page--;
         else if(c=='l') break;
      }
      else if(won==-2)
      {
         set_color(COLOR_RED,COLOR_BLACK,1);
         mvaddstr(23,0,"The country has been Stalinized.");
         mvaddstr(24,0,"Press 'L' to view the high score list.");

         int c=getkey();

         if(c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT) page++;
         else if(c==interface_pgup||c==KEY_UP||c==KEY_LEFT) page--;
         else if(c=='l') break;
      }
      else
      {
         move(23,0);
         if(stalinmode)
         {
            set_color(COLOR_RED,COLOR_BLACK,1);
            addstr("Stalinist  ");
         }
         set_color(COLOR_GREEN,COLOR_BLACK,1);
         addstr("Elite Liberal  ");
         if(!stalinmode)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            addstr("-  ");
         }
         set_color(COLOR_CYAN,COLOR_BLACK,1);
         addstr("Liberal  ");
         if(!stalinmode)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            addstr("-  ");
         }
         set_color(COLOR_YELLOW,COLOR_BLACK,1);
         addstr("moderate  ");
         if(!stalinmode)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            addstr("-  ");
         }
         set_color(COLOR_MAGENTA,COLOR_BLACK,1);
         addstr("Conservative  ");
         if(!stalinmode)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            addstr("-  ");
         }
         set_color(COLOR_RED,COLOR_BLACK,1);
         addstr("Arch-Conservative");
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         //mvaddstr(23,0,"Once these are Green, the country will have achieved Elite Liberal status.");
         mvaddstr(24,0,"Press D to disband and wait. Use cursors for other pages. Any other key to exit.");

         int c=getkey();

         if(c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT) page++;
         else if(c==interface_pgup||c==KEY_UP||c==KEY_LEFT) page--;
         else if(c=='d') return confirmdisband();
         else break;
      }
   }
   return false;
}
Beispiel #7
0
/*
 * Get a line into genbuf after gcursor.
 * Cnt limits the number of input characters
 * accepted and is used for handling the replace
 * single character command.  Aescaped is the location
 * where we stick a termination indicator (whether we
 * ended with an ESCAPE or a newline/return.
 *
 * We do erase-kill type processing here and also
 * are careful about the way we do this so that it is
 * repeatable.  (I.e. so that your kill doesn't happen,
 * when you repeat an insert if it was escaped with \ the
 * first time you did it.  commch is the command character
 * involved, including the prompt for readline.
 */
char *
vgetline(int cnt, char *gcursor, bool *aescaped, int commch)
{
	register int c, ch;
	register char *cp;
	int x, y, iwhite, backsl=0;
	cell *iglobp;
	char cstr[2];
	int (*OO)(int) = Outchar;

	/*
	 * Clear the output state and counters
	 * for autoindent backwards motion (counts of ^D, etc.)
	 * Remember how much white space at beginning of line so
	 * as not to allow backspace over autoindent.
	 */
	*aescaped = 0;
	ogcursor = gcursor;
	flusho();
	CDCNT = 0;
	HADUP = 0;
	HADZERO = 0;
	gobbled = 0;
	iwhite = whitecnt(genbuf);
	iglobp = vglobp;

	/*
	 * Carefully avoid using vinschar in the echo area.
	 */
	if (splitw)
		Outchar = vputchar;
	else {
		Outchar = vinschar;
		vprepins();
	}
	for (;;) {
		backsl = 0;
		if (gobblebl)
			gobblebl--;
		if (cnt != 0) {
			cnt--;
			if (cnt == 0)
				goto vadone;
		}
		c = getkey();
		if (c != ATTN)
			c &= (QUOTE|TRIM);
		ch = c;
		maphopcnt = 0;
		if (vglobp == 0 && Peekkey == 0 && commch != 'r')
			while ((ch = map(c, immacs)) != c) {
				c = ch;
				if (!value(REMAP))
					break;
				if (++maphopcnt > 256)
					error(catgets(catd, 1, 234,
						"Infinite macro loop"));
			}
		if (!iglobp) {

			/*
			 * Erase-kill type processing.
			 * Only happens if we were not reading
			 * from untyped input when we started.
			 * Map users erase to ^H, kill to -1 for switch.
			 */
			if (c == tty.c_cc[VERASE])
				c = CTRL('h');
			else if (c == tty.c_cc[VKILL])
				c = -1;
			if (c == ATTN)
				goto case_ATTN;
			switch (c) {

			/*
			 * ^?		Interrupt drops you back to visual
			 *		command mode with an unread interrupt
			 *		still in the input buffer.
			 *
			 * ^\		Quit does the same as interrupt.
			 *		If you are a ex command rather than
			 *		a vi command this will drop you
			 *		back to command mode for sure.
			 */
			case QUIT:
case_ATTN:
				ungetkey(c);
				goto vadone;

			/*
			 * ^H		Backs up a character in the input.
			 *
			 * BUG:		Can't back around line boundaries.
			 *		This is hard because stuff has
			 *		already been saved for repeat.
			 */
			case CTRL('h'):
bakchar:
				cp = gcursor + skipleft(ogcursor, gcursor);
				if (cp < ogcursor) {
					if (splitw) {
						/*
						 * Backspacing over readecho
						 * prompt. Pretend delete but
						 * don't beep.
						 */
						ungetkey(c);
						goto vadone;
					}
					beep();
					continue;
				}
				goto vbackup;

			/*
			 * ^W		Back up a white/non-white word.
			 */
			case CTRL('w'):
				wdkind = 1;
				for (cp = gcursor; cp > ogcursor
						&& isspace(cp[-1]&0377); cp--)
					continue;
				for (c = wordch(cp - 1);
				    cp > ogcursor && wordof(c, cp - 1); cp--)
					continue;
				goto vbackup;

			/*
			 * users kill	Kill input on this line, back to
			 *		the autoindent.
			 */
			case -1:
				cp = ogcursor;
vbackup:
				if (cp == gcursor) {
					beep();
					continue;
				}
				endim();
				*cp = 0;
				c = cindent();
				vgotoCL(qcolumn(cursor +
					skipleft(linebuf, cursor), genbuf));
				if (doomed >= 0)
					doomed += c - cindent();
				gcursor = cp;
				continue;

			/*
			 * \		Followed by erase or kill
			 *		maps to just the erase or kill.
			 */
			case '\\':
				x = destcol, y = destline;
				putchar('\\');
				vcsync();
				c = getkey();
				if (c == tty.c_cc[VERASE]
				    || c == tty.c_cc[VKILL])
				{
					vgoto(y, x);
					if (doomed >= 0)
						doomed++;
					goto def;
				}
				ungetkey(c), c = '\\';
				backsl = 1;
				break;

			/*
			 * ^Q		Super quote following character
			 *		Only ^@ is verboten (trapped at
			 *		a lower level) and \n forces a line
			 *		split so doesn't really go in.
			 *
			 * ^V		Synonym for ^Q
			 */
			case CTRL('q'):
			case CTRL('v'):
				x = destcol, y = destline;
				putchar('^');
				vgoto(y, x);
				c = getkey();
				if (c != NL) {
					if (doomed >= 0)
						doomed++;
					goto def;
				}
				break;
			}
		}

		/*
		 * If we get a blank not in the echo area
		 * consider splitting the window in the wrapmargin.
		 */
		if (c != NL && !splitw) {
			if (c == ' ' && gobblebl) {
				gobbled = 1;
				continue;
			}
			if (value(WRAPMARGIN) &&
				(outcol >= OCOLUMNS - value(WRAPMARGIN) ||
				 (backsl && outcol == 0)) &&
				commch != 'r') {
				/*
				 * At end of word and hit wrapmargin.
				 * Move the word to next line and keep going.
				 */
				wdkind = 1;
				gappend(c);
				if (backsl)
					gappend(getkey());
				*gcursor = 0;
				/*
				 * Find end of previous word if we are past it.
				 */
				for (cp=gcursor; cp>ogcursor
						&& isspace(cp[-1]&0377); cp--)
					;
				if (outcol+(backsl?OCOLUMNS:0) - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) {
					/*
					 * Find beginning of previous word.
					 */
					for (; cp>ogcursor && !isspace(cp[-1]&0377); cp--)
						;
					if (cp <= ogcursor) {
						/*
						 * There is a single word that
						 * is too long to fit.  Just
						 * let it pass, but beep for
						 * each new letter to warn
						 * the luser.
						 */
						c = *--gcursor;
						*gcursor = 0;
						beep();
						goto dontbreak;
					}
					/*
					 * Save it for next line.
					 */
					macpush(cp, 0);
					cp--;
				}
				macpush("\n", 0);
				/*
				 * Erase white space before the word.
				 */
				while (cp > ogcursor && isspace(cp[-1]&0377))
					cp--;	/* skip blank */
				gobblebl = 3;
				goto vbackup;
			}
		dontbreak:;
		}

		/*
		 * Word abbreviation mode.
		 */
		cstr[0] = c;
		if (anyabbrs && gcursor > ogcursor && !wordch(cstr) && wordch(gcursor-1)) {
				int wdtype, abno;

				cstr[1] = 0;
				wdkind = 1;
				cp = gcursor + skipleft(ogcursor, gcursor);
				for (wdtype = wordch(cp - 1);
				    cp > ogcursor && wordof(wdtype, cp - 1); cp--)
					;
				*gcursor = 0;
				for (abno=0; abbrevs[abno].mapto; abno++) {
					if (!abbrevs[abno].hadthis &&
						eq(cp, abbrevs[abno].cap)) {
						abbrevs[abno].hadthis++;
						macpush(cstr, 0);
						macpush(abbrevs[abno].mapto, 0);
						goto vbackup;
					}
				}
		}

#ifdef	BIT8
		if (c == OVERBUF)
			goto btrp;
#endif
		switch (c) {

		/*
		 * ^M		Except in repeat maps to \n.
		 */
		case CR:
			if (vglobp)
				goto def;
			c = '\n';
			/* presto chango ... */

		/*
		 * \n		Start new line.
		 */
		case NL:
			*aescaped = c;
			goto vadone;

		/*
		 * escape	End insert unless repeat and more to repeat.
		 */
		case ESCAPE:
			if (lastvgk)
				goto def;
			goto vadone;

		/*
		 * ^D		Backtab.
		 * ^T		Software forward tab.
		 *
		 *		Unless in repeat where this means these
		 *		were superquoted in.
		 */
		case CTRL('d'):
		case CTRL('t'):
			if (vglobp)
				goto def;
			/* fall into ... */

		/*
		 * ^D|QUOTE	Is a backtab (in a repeated command).
		 */
#ifndef	BIT8
		case CTRL('d') | QUOTE:
#else
btrp:
#endif
			*gcursor = 0;
			cp = vpastwh(genbuf);
			c = whitecnt(genbuf);
			if (ch == CTRL('t')) {
				/*
				 * ^t just generates new indent replacing
				 * current white space rounded up to soft
				 * tab stop increment.
				 */
				if (cp != gcursor)
					/*
					 * BUG:		Don't hack ^T except
					 *		right after initial
					 *		white space.
					 */
					continue;
				cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1));
				ogcursor = cp;
				goto vbackup;
			}
			/*
			 * ^D works only if we are at the (end of) the
			 * generated autoindent.  We count the ^D for repeat
			 * purposes.
			 */
			if (c == iwhite && c != 0) {
				if (cp == gcursor) {
					iwhite = backtab(c);
					CDCNT++;
					ogcursor = cp = genindent(iwhite);
					goto vbackup;
				} else if (&cp[1] == gcursor &&
				    (*cp == '^' || *cp == '0')) {
					/*
					 * ^^D moves to margin, then back
					 * to current indent on next line.
					 *
					 * 0^D moves to margin and then
					 * stays there.
					 */
					HADZERO = *cp == '0';
					ogcursor = cp = genbuf;
					HADUP = 1 - HADZERO;
					CDCNT = 1;
					endim();
					back1();
					vputchar(' ');
					goto vbackup;
				}
			}
			if (vglobp && vglobp - iglobp >= 2 &&
			    (vglobp[-2] == '^' || vglobp[-2] == '0')
			    && gcursor == ogcursor + 1)
				goto bakchar;
			continue;

		default:
			/*
			 * Possibly discard control inputs.
			 */
			if (!vglobp && junk(c)) {
				beep();
				continue;
			}
def:
			if (!backsl) {
				/* int cnt; */
				putchar(c);
				flush();
			}
			if (gcursor > &genbuf[LBSIZE - 2])
				error(catgets(catd, 1, 235, "Line too long"));
			gappend(c & TRIM);
			vcsync();
			if (value(SHOWMATCH) && !iglobp)
				if (c == ')' || c == '}')
					lsmatch(gcursor);
			continue;
		}
	}
vadone:
	*gcursor = 0;
	if (Outchar != termchar)
		Outchar = OO;
	endim();
	return (gcursor);
}
Beispiel #8
0
/* The standard ASCII keyboard is also checked so that very short keypresses
   are not overlooked. The functions kbhit() (returns bool denoting whether or
   not there is a key in the buffer) and getkey() (wait until a key is in the
   buffer, then return it) are used. These functions are emulated on platforms
   which only provide an inkey() function (return the key in the buffer, unless
   there is none, in which case return -1. It is done this way around for
   historical reasons, there is no fundamental reason why it shouldn't be the
   other way around. */
void checkkeyb(void)
{
    int i, j, k = 0;
    bool *aflagp[10] = {&arightpressed, &auppressed, &aleftpressed, &adownpressed,
                        &af1pressed, &aright2pressed, &aup2pressed, &aleft2pressed,
                        &adown2pressed, &af12pressed
                       };
    if (leftpressed)
        aleftpressed = true;
    if (rightpressed)
        arightpressed = true;
    if (uppressed)
        auppressed = true;
    if (downpressed)
        adownpressed = true;
    if (f1pressed)
        af1pressed = true;
    if (left2pressed)
        aleft2pressed = true;
    if (right2pressed)
        aright2pressed = true;
    if (up2pressed)
        aup2pressed = true;
    if (down2pressed)
        adown2pressed = true;
    if (f12pressed)
        af12pressed = true;

    while (kbhit())
    {
        akeypressed = getkey();
        for (i = 0; i < 10; i++)
            for (j = 2; j < 5; j++)
                if (akeypressed == keycodes[i][j])
                    *aflagp[i] = true;
        for (i = 10; i < 17; i++)
            for (j = 0; j < 5; j++)
                if (akeypressed == keycodes[i][j])
                    k = i;
        switch (k)
        {
        case 10: /* Cheat! */
            if (!gauntlet)
            {
                playing = false;
                drfvalid = false;
            }
            break;
        case 11: /* Increase speed */
            if (ftime > 10000l)
                ftime -= 10000l;
            break;
        case 12: /* Decrease speed */
            ftime += 10000l;
            break;
        case 13: /* Toggle music */
            musicflag = !musicflag;
            break;
        case 14: /* Toggle sound */
            soundflag = !soundflag;
            break;
        case 15: /* Exit */
            escape = true;
            break;
        case 16: /* Pause */
            pausef = true;
        }
        if (akeypressed == ASCIIF8) /* Save DRF */
            savedrf = true;
        if (akeypressed != 27 && akeypressed != 'n' && akeypressed != 'N')
            start = true;                              /* Change number of players */
    }
}
Beispiel #9
0
int fileselector(char *name, char *path, char *filter, char *title, int filemode)
{
  int c, d, scrrep;
  int color;
  int files;
  int filepos = 0;
  int fileview = 0;
  int lastclick = 0;
  int lastfile = 0;
  int lowest;
  int exitfilesel;

  DIR *dir;
  struct dirent *de;
  struct stat st;
  #ifdef __WIN32__
  char drivestr[] = "A:\\";
  char driveexists[26];
  #endif
  char cmpbuf[MAX_PATHNAME];
  char tempname[MAX_PATHNAME];

  // Set initial path (if any)
  if (strlen(path)) chdir(path);

  // Scan for all existing drives
  #ifdef __WIN32__
  for (c = 0; c < 26; c++)
  {
    drivestr[0] = 'A'+c;
    if (GetDriveType(drivestr) > 1) driveexists[c] = 1;
    else driveexists[c] = 0;
  }
  #endif

  // Read new directory
  NEWPATH:
  getcwd(path, MAX_PATHNAME);
  files = 0;
  // Deallocate old names
  for (c = 0; c < MAX_DIRFILES; c++)
  {
    if (direntry[c].name)
    {
      free(direntry[c].name);
      direntry[c].name = NULL;
    }
  }
  #ifdef __WIN32__
  // Create drive letters
  for (c = 0; c < 26; c++)
  {
    if (driveexists[c])
    {
      drivestr[0] = 'A'+c;
      direntry[files].name = strdup(drivestr);
      direntry[files].attribute = 2;
      files++;
    }
  }
  #endif

  // Process directory
  #ifdef __amigaos__
  dir = opendir("");
  #else
  dir = opendir(".");
  #endif
  if (dir)
  {
    char *filtptr = strstr(filter, "*");
    if (!filtptr) filtptr = filter;
    else filtptr++;
    for (c = 0; c < strlen(filter); c++)
      filter[c] = tolower(filter[c]);

    while ((de = readdir(dir)))
    {
      if ((files < MAX_DIRFILES) && (strlen(de->d_name) < MAX_FILENAME))
      {
        direntry[files].name = strdup(de->d_name);
        direntry[files].attribute = 0;
        stat(de->d_name, &st);
        if (st.st_mode & S_IFDIR)
        {
          direntry[files].attribute = 1;
          files++;
        }
        else
        {
          int c;
          // If a file, must match filter
          strcpy(cmpbuf, de->d_name);
          if ((!strcmp(filtptr, "*")) || (!strcmp(filtptr, ".*")))
            files++;
          else
          {
            for (c = 0; c < strlen(cmpbuf); c++)
              cmpbuf[c] = tolower(cmpbuf[c]);
            if (strstr(cmpbuf, filtptr))
              files++;
            else
            {
              free(direntry[files].name);
              direntry[files].name = NULL;
            }
          }
        }
      }
    }
    closedir(dir);
  }
  // Sort the filelist in a most horrible fashion
  for (c = 0; c < files; c++)
  {
    lowest = c;
    for (d = c+1; d < files; d++)
    {
      if (direntry[d].attribute < direntry[lowest].attribute)
      {
        lowest = d;
      }
      else
      {
        if (direntry[d].attribute == direntry[lowest].attribute)
        {
          if (cmpname(direntry[d].name, direntry[lowest].name) < 0)
          {
            lowest = d;
          }
        }
      }
    }
    if (lowest != c)
    {
      DIRENTRY swaptemp = direntry[c];
      direntry[c] = direntry[lowest];
      direntry[lowest] = swaptemp;
    }
  }

  // Search for the current filename
  fileview = 0;
  filepos = 0;
  for (c = 0; c < files; c++)
  {
    if ((!direntry[c].attribute) && (!cmpname(name, direntry[c].name)))
    {
      filepos = c;
    }
  }

  exitfilesel = -1;
  while (exitfilesel < 0)
  {
    int cc = cursorcolortable[cursorflash];
    if (cursorflashdelay >= 6)
    {
      cursorflashdelay %= 6;
      cursorflash++;
      cursorflash &= 3;
    }
    fliptoscreen();
    getkey();
    if (lastclick) lastclick--;

    if (win_quitted)
    {
      exitprogram = 1;
      for (c = 0; c < MAX_DIRFILES; c++)
      {
        if (direntry[c].name)
        {
          free(direntry[c].name);
          direntry[c].name = NULL;
        }
      }
      return 0;
    }

    if (mouseb)
    {
      // Cancel (click outside)
      if ((mousey < 3) || (mousey > 3+VISIBLEFILES+6) || (mousex <= 4+10) || (mousex >= 75+10))
      {
        if ((!prevmouseb) && (lastclick)) exitfilesel = 0;
      }

      // Select dir,name,filter
      if ((mousey >= 3+VISIBLEFILES+3) && (mousey <= 3+VISIBLEFILES+5) && (mousex >= 14+10) && (mousex <= 73+10))
      {
        filemode = mousey - (3+VISIBLEFILES+3) + 1;
        if ((filemode == 3) && (!prevmouseb) && (lastclick)) goto ENTERFILE;
      }

      // Select file from list
      if ((mousey >= 3) && (mousey <= 3+VISIBLEFILES+2) && (mousex >= 6+10) && (mousex <= 73+10))
      {
        filemode = 0;
        filepos = mousey - 4 - 1 + fileview;
        if (filepos < 0) filepos = 0;
        if (filepos > files-1) filepos = files - 1;

        if (!direntry[filepos].attribute)
          strcpy(name, direntry[filepos].name);

        if ((!prevmouseb) && (lastclick) && (lastfile == filepos)) goto ENTERFILE;
      }
    }

    if (!filemode)
    {
      if (((key >= '0') && (key <= '0')) || ((key >= 'a') && (key <= 'z')) || ((key >= 'A') && (key <= 'Z')))
      {
        char k = tolower(key);
        int oldfilepos = filepos;

        for (filepos = oldfilepos + 1; filepos < files; filepos++)
          if (tolower(direntry[filepos].name[0]) == k) break;
        if (filepos >= files)
        {
          for (filepos = 0; filepos < oldfilepos; filepos++)
             if (tolower(direntry[filepos].name[0]) == k) break;
        }

        if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
      }
    }

    switch(rawkey)
    {
      case KEY_ESC:
      exitfilesel = 0;
      break;

      case KEY_BACKSPACE:
      if (!filemode)
      {
      #ifdef __amigaos__
        chdir("/");
      #else
        chdir("..");
      #endif
        goto NEWPATH;
      }
      break;

      case KEY_HOME:
      if (!filemode)
      {
        filepos = 0;
        if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
      }
      break;

      case KEY_END:
      if (!filemode)
      {
        filepos = files-1;
        if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
      }
      break;

      case KEY_PGUP:
      for (scrrep = PGUPDNREPEAT; scrrep; scrrep--)
      {
        if ((!filemode) && (filepos > 0))
        {
          filepos--;
          if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
        }
      }
      break;

      case KEY_UP:
      if ((!filemode) && (filepos > 0))
      {
        filepos--;
        if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
      }
      break;

      case KEY_PGDN:
      for (scrrep = PGUPDNREPEAT; scrrep; scrrep--)
      {
        if ((!filemode) && (filepos < files-1))
        {
          filepos++;
          if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
        }
      }
      break;

      case KEY_DOWN:
      if ((!filemode) && (filepos < files-1))
      {
        filepos++;
        if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name);
      }
      break;

      case KEY_TAB:
      if (!shiftpressed)
      {
        filemode++;
        if (filemode > 3) filemode = 0;
      }
      else
      {
        filemode--;
        if (filemode < 0) filemode = 3;
      }
      break;

      case KEY_ENTER:
      ENTERFILE:
      switch(filemode)
      {
        case 0:
        switch (direntry[filepos].attribute)
        {
          case 0:
          strcpy(name, direntry[filepos].name);
          exitfilesel = 1;
          break;

          case 1:
          chdir(direntry[filepos].name);
          goto NEWPATH;

          case 2:
          strcpy(tempname, direntry[filepos].name);
          if (strlen(tempname))
          {
            if (tempname[strlen(tempname)-1] != '\\')
              strcat(tempname, "\\");
          }
          chdir(tempname);
          goto NEWPATH;
        }
        break;

        case 1:
        chdir(path);
        case 2:
        filemode = 0;
        goto NEWPATH;

        case 3:
        exitfilesel = 1;
        break;
      }
      break;
    }

    switch(filemode)
    {
      case 1:
      editstring(path, MAX_PATHNAME);
      break;

      case 2:
      editstring(filter, MAX_FILENAME);
      break;

      case 3:
      editstring(name, MAX_FILENAME);
      break;
    }

    // Validate filelist view
    if (filepos < fileview) fileview = filepos;
    if (filepos - fileview >= VISIBLEFILES) fileview = filepos - VISIBLEFILES + 1;

    // Refresh fileselector display
    if (isplaying()) printstatus();
    for (c = 0; c < VISIBLEFILES+7; c++)
    {
      printblank(50-(MAX_FILENAME+10)/2, 3+c, MAX_FILENAME+10);
    }
    drawbox(50-(MAX_FILENAME+10)/2, 3, 15, MAX_FILENAME+10, VISIBLEFILES+7);
    printblankc(50-(MAX_FILENAME+10)/2+1, 4, 15+16,MAX_FILENAME+8);
    printtext(50-(MAX_FILENAME+10)/2+1, 4, 15+16, title);

    for (c = 0; c < VISIBLEFILES; c++)
    {
      if ((fileview+c >= 0) && (fileview+c < files))
      {
        switch (direntry[fileview+c].attribute)
        {
          case 0:
          sprintf(textbuffer, "%-60s        ", direntry[fileview+c].name);
          break;

          case 1:
          sprintf(textbuffer, "%-60s   <DIR>", direntry[fileview+c].name);
          break;

          case 2:
          sprintf(textbuffer, "%-60s   <DRV>", direntry[fileview+c].name);
          break;
        }
      }
      else
      {
        sprintf(textbuffer, "                                                                    ");
      }
      color = CNORMAL;
      if ((fileview+c) == filepos) color = CEDIT;
      textbuffer[68] = 0;
      printtext(50-(MAX_FILENAME+10)/2+1, 5+c, color, textbuffer);
      if ((!filemode) && ((fileview+c) == filepos)) printbg(50-(MAX_FILENAME+10)/2+1, 5+c, cc, 68);
    }

    printtext(50-(MAX_FILENAME+10)/2+1, 6+VISIBLEFILES, 15, "PATH:   ");
    sprintf(textbuffer, "%-60s", path);
    textbuffer[MAX_FILENAME] = 0;
    color = CNORMAL;
    if (filemode == 1) color = CEDIT;
    printtext(50-(MAX_FILENAME+10)/2+9, 6+VISIBLEFILES, color, textbuffer);
    if ((filemode == 1) && (strlen(path) < MAX_FILENAME)) printbg(50-(MAX_FILENAME+10)/2+9+strlen(path), 6+VISIBLEFILES, cc, 1);

    printtext(50-(MAX_FILENAME+10)/2+1, 7+VISIBLEFILES, 15, "FILTER: ");
    sprintf(textbuffer, "%-60s", filter);
    textbuffer[MAX_FILENAME] = 0;
    color = CNORMAL;
    if (filemode == 2) color = CEDIT;
    printtext(50-(MAX_FILENAME+10)/2+9, 7+VISIBLEFILES, color, textbuffer);
    if (filemode == 2) printbg(50-(MAX_FILENAME+10)/2+9+strlen(filter), 7+VISIBLEFILES, cc, 1);

    printtext(50-(MAX_FILENAME+10)/2+1, 8+VISIBLEFILES, 15, "NAME:   ");
    sprintf(textbuffer, "%-60s", name);
    textbuffer[MAX_FILENAME] = 0;
    color = CNORMAL;
    if (filemode == 3) color = CEDIT;
    printtext(50-(MAX_FILENAME+10)/2+9, 8+VISIBLEFILES, color, textbuffer);
    if (filemode == 3) printbg(50-(MAX_FILENAME+10)/2+9+strlen(name), 8+VISIBLEFILES, cc, 1);

    if (win_quitted) exitfilesel = 0;

    if ((mouseb) && (!prevmouseb))
    {
      lastclick = DOUBLECLICKDELAY;
      lastfile = filepos;
    }
  }

  // Deallocate all used names
  for (c = 0; c < MAX_DIRFILES; c++)
  {
    if (direntry[c].name)
    {
      free(direntry[c].name);
      direntry[c].name = NULL;
    }
  }

  // Restore screen & exit
  printmainscreen();
  return exitfilesel;
}
Beispiel #10
0
/* endgame - checks if a constitutional amendment is ratified */
char ratify(int level,int lawview,int view,char congress,char canseethings)
{
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,1);

      move(0,0);
      addstr("The Ratification Process:");
   }

   //THE STATE VOTE WILL BE BASED ON VIEW OF LAW
   int mood=publicmood(lawview);
   //OR OF A PARTICULAR ISSUE
   if(view>=0) mood=attitude[view];

   //CONGRESS
   bool ratified=false;

   int y=0;

   if(congress)
   {
      ratified=true;

      if(canseethings)
      {
         move(0,62);
         addstr("House");

         move(0,70);
         addstr("Senate");

         move(24,0);
         addstr("Press any key to watch the Congressional votes unfold.     ");

         getkey();
      }

      bool yeswin_h=false,yeswin_s=false;
      int yesvotes_h=0,yesvotes_s=0,vote,s=0;

      for(int l=0;l<HOUSENUM;l++)
      {
         vote=house[l];
         if(vote>=-1&&vote<=1) vote+=LCSrandom(3)-1;

         if(level==vote) yesvotes_h++;

         if(l==HOUSENUM-1) if(yesvotes_h>=HOUSESUPERMAJORITY) yeswin_h=true;

         if(canseethings)
         {
            if(l==HOUSENUM-1&&yeswin_h) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(2,62);
            addstr(yesvotes_h);
            addstr(" Yea");

            if(l==HOUSENUM-1&&!yeswin_h) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(3,62);
            addstr(l+1-yesvotes_h);
            addstr(" Nay");
         }

         if(l%4==0&&s<SENATENUM)
         {
            vote=senate[s++];
            if(vote>=-1&&vote<=1) vote+=LCSrandom(3)-1;

            if(level==vote) yesvotes_s++;
         }

         if(l==HOUSENUM-1&&yesvotes_s>=SENATESUPERMAJORITY) yeswin_s=true;

         if(canseethings)
         {
            if(l==HOUSENUM-1&&yeswin_s) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(2,70);
            addstr(yesvotes_s);
            addstr(" Yea");

            if(l==HOUSENUM-1&&!yeswin_s) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(3,70);
            addstr(s-yesvotes_s);
            addstr(" Nay");

            if(l%5==0) pause_ms(10);
         }
      }

      if(!yeswin_h||!yeswin_s) ratified=false;

      y+=4;
   }
   else ratified=true;

   if(level==3) level=-2; // special case for Stalinists: do this after Congress but before the states

   //STATES
   if(ratified)
   {
      ratified=false;

      int yesstate=0;

      if(canseethings)
      {
         set_color(COLOR_WHITE,COLOR_BLACK,1);

         for(int s=0;s<50;s++)
         {
            if(s<17) move(5+s,0);
            else if(s<34) move(5+s-17,27);
            else move(5+s-34,54);
            addstr(statename(s));
         }

         move(24,0);
         addstr("Press any key to watch the State votes unfold.              ");

         getkey();
      }

      int vote,smood;
      for(int s=0;s<STATENUM;s++)
      {
         smood=mood;

         // State biases.
         int multiplier = 5+LCSrandom(3);
         switch(s)
         {
            case 0:smood-=3*multiplier;break;  // Alabama
            case 1:smood-=4*multiplier;break;  // Alaska
            case 2:smood-=1*multiplier;break;  // Arkansas
            case 3:smood-=2*multiplier;break;  // Arizona
            case 4:smood+=4*multiplier;break;  // California
            case 5:break;                      // Colorado
            case 6:smood+=3*multiplier;break;  // Connecticut
            case 7:smood+=3*multiplier;break;  // Delaware
            case 8:break;                      // Florida
            case 9:smood-=2*multiplier;break;  // Georgia
            case 10:smood+=4*multiplier;break; // Hawaii
            case 11:smood-=5*multiplier;break; // Idaho
            case 12:smood+=4*multiplier;break; // Illinois
            case 13:smood-=1*multiplier;break; // Indiana
            case 14:smood+=1*multiplier;break; // Iowa
            case 15:smood-=3*multiplier;break; // Kansas
            case 16:smood-=3*multiplier;break; // Kentucky
            case 17:smood-=1*multiplier;break; // Louisiana
            case 18:smood+=2*multiplier;break; // Maine
            case 19:smood+=3*multiplier;break; // Maryland
            case 20:smood+=6*multiplier;break; // Massachusetts
            case 21:smood+=2*multiplier;break; // Michigan
            case 22:smood+=2*multiplier;break; // Minnesota
            case 23:smood-=4*multiplier;break; // Mississippi
            case 24:smood-=1*multiplier;break; // Missouri
            case 25:smood-=2*multiplier;break; // Montana
            case 26:smood-=3*multiplier;break; // Nebraska
            case 27:break;                     // Nevada
            case 28:smood+=1*multiplier;break; // New Hampshire
            case 29:smood+=3*multiplier;break; // New Jersey
            case 30:smood+=1*multiplier;break; // New Mexico
            case 31:smood+=5*multiplier;break; // New York
            case 32:smood-=1*multiplier;break; // North Carolina
            case 33:smood-=3*multiplier;break; // North Dakota
            case 34:break;                     // Ohio
            case 35:smood-=4*multiplier;break; // Oklahoma
            case 36:smood+=3*multiplier;break; // Oregon
            case 37:smood+=2*multiplier;break; // Pennsylvania
            case 38:smood+=4*multiplier;break; // Rhode Island
            case 39:smood-=5*multiplier;break; // South Carolina
            case 40:smood-=3*multiplier;break; // South Dakota
            case 41:smood-=2*multiplier;break; // Tennessee
            case 42:smood-=4*multiplier;break; // Texas
            case 43:smood-=6*multiplier;break; // Utah
            case 44:smood+=5*multiplier;break; // Vermont
            case 45:break;                     // Virginia
            case 46:smood+=3*multiplier;break; // Washington
            case 47:smood-=2*multiplier;break; // West Virginia
            case 48:smood+=2*multiplier;break; // Wisconsin
            case 49:smood-=5*multiplier;break; // Wyoming
         }

         vote=-2;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(vote==1&&!LCSrandom(2)) vote=2;
         if(vote==-1&&!LCSrandom(2)) vote=-2;

         if(canseethings)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,1);
            if(s<17) move(5+s,22);
            else if(s<34) move(5+s-17,49);
            else move(5+s-34,76);
         }
         if(vote==level)
         {
            yesstate++;
            if(canseethings) addstr("Yea");
         }
         else if(canseethings) addstr("Nay");

         if(canseethings)
         {
            if(s==STATENUM-1&&yesstate>=STATESUPERMAJORITY) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(s==STATENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(23,50);
            addstr(yesstate);
            addstr(" Yea");

            if(s==STATENUM-1&&yesstate<STATESUPERMAJORITY) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(s==STATENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(23,60);
            addstr(s+1-yesstate);
            addstr(" Nay");

            pause_ms(50);
         }
      }

      if(yesstate>=STATESUPERMAJORITY) ratified=true;
   }

   if(canseethings)
   {
      set_color(COLOR_WHITE,COLOR_BLACK,1);
      move(23,0);
      if(ratified) addstr("AMENDMENT ADOPTED.");
      else addstr("AMENDMENT REJECTED.");
   }

   return ratified;
}
Beispiel #11
0
void findkey(int kn)
{
    keycodes[kn][0] = getkey();
}
Beispiel #12
0
/* endgame - attempts to pass a constitutional amendment to lose the game */
void stalinize(char canseethings)
{
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      set_color(COLOR_WHITE,COLOR_BLACK,1);

      erase();
      move(12,11);
      addstr("The Stalinist Congress is proposing a STALINIST AMENDMENT!");

      getkey();

      //STATE THE AMENDMENT
      amendmentheading();

      move(2,5);
      addstr("In recognition of the fact that the proletariat is being exploited");
      move(3,0);
      addstr("by bourgeoisie faux-leftist liberal elites, WE THE PEOPLE HEREBY");
      move(4,0);
      addstr("REPEAL THE CONSTITUTION.  The former United States are to be");
      move(5,0);
      addstr("reorganized into the PEOPLE'S REPUBLIC OF AMERICA, with new");
      move(6,0);
      addstr("boundaries to be determined by leading Stalinist philosophers.");
      move(8,5);
      addstr("Josef Stalin is General Secretary and Premier, forever, even after death.");
      move(10,5);
      addstr("The following Politburo Commissars are also chosen in perpetuity:");
      move(11,0);
      addstr("People's Commissar for Foreign Affairs Vyacheslav Molotov");
      move(12,0);
      addstr("and People's Commissar for Internal Affairs Lavrentiy Beria.");
      move(14,5);
      addstr("In the event of the deaths of any of the aforementioned");
      move(15,0);
      addstr("persons, though they shall still nominally hold these posts,");
      move(16,0);
      addstr("actual decisions shall be made by Stalinist Party leaders,");
      move(17,0);
      addstr("chosen by Stalinist Party loyalists.");
      move(19,5);
      addstr("Anyone attempting to petition for redress of grievances will be sent");
      move(20,0);
      addstr("to a gulag in newly annexed Canada or, if you're lucky, executed.");
      move(22,5);
      addstr("Have a nice day.");

      move(24,0);
      addstr("Press 'C' to watch the ratification process unfold.");

      while(getkey()!='c');
   }

   if(ratify(3,-2,-2,1,canseethings))
   {
      music.play(MUSIC_STALINIZED);
      if(canseethings)
      {
         move(24,0);
         addstr("Press any key to reflect on what has happened ONE LAST TIME.");

         getkey();
      }

      amendnum = 1; // Constitution repealed...

      //STALINIZE
      if(canseethings)
      {
         strcpy(execname[EXEC_PRESIDENT],"Josef Stalin");
         strcpy(execname[EXEC_VP],"Josef Stalin");
         strcpy(execname[EXEC_STATE],"Vyacheslav Molotov");
         strcpy(execname[EXEC_ATTORNEY],"Lavrentiy Beria");
         for(int e=0;e<EXECNUM;e++) exec[e]=ALIGN_STALINIST;
         for(int l=0;l<LAWNUM;l++) law[l]=stalinview(l,true)?ALIGN_ELITELIBERAL:ALIGN_ARCHCONSERVATIVE;
         liberalagenda(-2);
         savehighscore(END_STALIN);
      }
      else
      {
         switch(cantseereason)
         {
            case 1:
               //DATING AND STALINIZED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You went on vacation when the country was on the verge of collapse.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Stalinists have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round up the last of you eventually.  All is lost.");

               getkey();

               savehighscore(END_DATING);
               break;
            case 2:
               //HIDING AND STALINIZED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You went into hiding when the country was on the verge of collapse.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Stalinists have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round the last of you up eventually.  All is lost.");

               getkey();

               savehighscore(END_HIDING);
               break;
            case 3:
               //IF YOU ARE ALL IN PRISON, YOU END UP IN A GULAG, COMRADE
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("While you were on the inside, the country degenerated...");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("You've been shipped off to a gulag in newly annexed Canada...");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("Ain't no sunshine in this frozen tundra...");

               getkey();

               savehighscore(END_PRISON);
               break;
            case 4:
               //DISBANDED AND STALINIZED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You disappeared safely, but you hadn't done enough.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Stalinists have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round the last of you up eventually.  All is lost.");

               getkey();

               savehighscore(END_DISBANDLOSS);
               break;
         }
      }
      reset();
      viewhighscores(MUSIC_STALINIZED);
      end_game();
   }
   else
   {
      if(canseethings)
      {
         move(24,0);
         addstr("Press any key to breathe a sigh of relief.                   ");

         getkey();
      }
   }
}
Beispiel #13
0
/* endgame - attempts to pass a constitutional amendment to help win the game */
void tossjustices(char canseethings)
{
   int j;
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,1);

      move(12,6);
      addstr("The Elite Liberal Congress is proposing an ELITE LIBERAL AMENDMENT!");

      getkey();
   }

   //STATE THE AMENDMENT
   if(canseethings)
   {
      int tossnum=0;
      for(j=0;j<COURTNUM;j++) if(court[j]!=ALIGN_ELITELIBERAL) tossnum++;

      amendmentheading();

      move(2,5);
      addstr("The following former citizen");
      if(tossnum!=1)addstr("s are");
      else addstr(" is");
      addstr(" branded Arch-Conservative:");

      int y=4;

      for(j=0;j<COURTNUM;j++) if(court[j]!=ALIGN_ELITELIBERAL)
      {
         move(y++,0);
         addstr(courtname[j]);
      }

      move(y+1,5);
      addstr("In particular, the aforementioned former citizen");
      if(tossnum!=1)addstr("s");
      addstr(" may");
      move(y+2,0);
      addstr("not serve on the Supreme Court.  Said former citizen");
      if(tossnum!=1)addstr("s");
      addstr(" will");
      move(y+3,0);
      addstr("be deported to ");
      if(tossnum!=1)addstr("Conservative countries");
      else addstr("a Conservative country");
      addstr(" of the President's");
      move(y+4,0);
      addstr("choosing to be replaced by ");
      if(tossnum!=1)addstr("Proper Justices");
      else addstr("a Proper Justice");
      addstr(", also of");
      move(y+5,0);
      addstr("the President's choosing with the advice and consent of");
      move(y+6,0);
      addstr("the Senate.");


      move(24,0);
      addstr("Press 'C' to watch the ratification process unfold.");

      while(getkey()!='c');
   }

   if(ratify(2,-1,-1,1,canseethings))
   {
      //BLAST JUSTICES
      for(int j=0;j<COURTNUM;j++) if(court[j]!=ALIGN_ELITELIBERAL)
      {
         do generate_name(courtname[j]); while(len(courtname[j])>20);
         court[j]=ALIGN_ELITELIBERAL;
      }

      amendnum++;
   }

   if(canseethings)
   {
      move(24,0);
      addstr("Press any key to reflect on what has happened.");

      getkey();
   }
}
Beispiel #14
0
/* endgame - attempts to pass a constitutional amendment to lose the game */
void reaganify(char canseethings)
{
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      set_color(COLOR_WHITE,COLOR_BLACK,1);

      erase();
      move(12,3);
      addstr("The Arch-Conservative Congress is proposing an ARCH-CONSERVATIVE AMENDMENT!");

      getkey();

      //STATE THE AMENDMENT
      amendmentheading();

      move(2,5);
      addstr("In recognition of the fact that society is degenerating under");
      move(3,0);
      addstr("the pressure of the elite liberal threat, WE THE PEOPLE HEREBY");
      move(4,0);
      addstr("REPEAL THE CONSTITUTION.  The former United States are to be");
      move(5,0);
      addstr("reorganized into the CONFEDERATED STATES OF AMERICA, with new");
      move(6,0);
      addstr("boundaries to be determined by leading theologians.");
      move(8,5);
      addstr("Ronald Reagan is to be King, forever, even after death.");
      move(10,5);
      addstr("The following Executive Officers are also chosen in perpetuity:");
      move(11,0);
      addstr("Minister of Love Strom Thurmond, Minister of Peace Jesse Helms,");
      move(12,0);
      addstr("and Minister of Truth Jerry Falwell.");
      move(14,5);
      addstr("In the event of the deaths of any of the aforementioned");
      move(15,0);
      addstr("persons, though they shall still nominally hold these posts,");
      move(16,0);
      addstr("actual decisions shall be made by business representatives,");
      move(17,0);
      addstr("chosen by respected business leaders.");
      move(19,5);
      addstr("People may petition Jesus for a redress of grievances, as");
      move(20,0);
      addstr("He will be the only one listening.");
      move(22,5);
      addstr("Have a nice day.");

      move(24,0);
      addstr("Press 'C' to watch the ratification process unfold.");

      while(getkey()!='c');
   }

   if(ratify(-2,-1,-1,1,canseethings))
   {
      music.play(MUSIC_REAGANIFIED);
      if(canseethings)
      {
         move(24,0);
         addstr("Press any key to reflect on what has happened ONE LAST TIME.");

         getkey();
      }

      amendnum = 1; // Constitution repealed...

      //REAGANIFY
      if(canseethings)
      {
         strcpy(execname[EXEC_PRESIDENT],"Ronald Reagan");
         strcpy(execname[EXEC_VP],"Strom Thurmond");
         strcpy(execname[EXEC_STATE],"Jesse Helms");
         strcpy(execname[EXEC_ATTORNEY],"Jerry Falwell");
         for(int e=0;e<EXECNUM;e++) exec[e]=ALIGN_ARCHCONSERVATIVE;
         for(int l=0;l<LAWNUM;l++) law[l]=ALIGN_ARCHCONSERVATIVE;
         liberalagenda(-1);
         savehighscore(END_REAGAN);
      }
      else
      {
         switch(cantseereason)
         {
            case 1:
               //DATING AND REAGANIFIED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You went on vacation when the country was on the verge of collapse.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Conservatives have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round up the last of you eventually.  All is lost.");

               getkey();

               savehighscore(END_DATING);
               break;
            case 2:
               //HIDING AND REAGANIFIED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You went into hiding when the country was on the verge of collapse.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Conservatives have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round the last of you up eventually.  All is lost.");

               getkey();

               savehighscore(END_HIDING);
               break;
            case 3:
               //IF YOU ARE ALL IN PRISON, JUST PASS AWAY QUIETLY
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("While you were on the inside, the country degenerated...");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("Your kind are never released these days.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("Ain't no sunshine...");

               getkey();

               savehighscore(END_PRISON);
               break;
            case 4:
               //DISBANDED AND REAGANIFIED
               set_color(COLOR_WHITE,COLOR_BLACK,1);

               erase();
               move(12,10);
               addstr("You disappeared safely, but you hadn't done enough.");

               getkey();

               set_color(COLOR_WHITE,COLOR_BLACK,0);
               erase();
               move(12,12);
               addstr("The Conservatives have made the world in their image.");

               getkey();

               set_color(COLOR_BLACK,COLOR_BLACK,1);
               erase();
               move(12,14);
               addstr("They'll round the last of you up eventually.  All is lost.");

               getkey();

               savehighscore(END_DISBANDLOSS);
               break;
         }
      }
      reset();
      viewhighscores(MUSIC_REAGANIFIED);
      end_game();
   }
   else
   {
      if(canseethings)
      {
         move(24,0);
         addstr("Press any key to breathe a sigh of relief.                   ");

         getkey();
      }
   }
}
/**
 * @brief Función para capturar los datos de entrada del usuario
 * 
 */
void ingresoDeDatos()
{
	// Mientras sea 1, se mantiene en el bucle
	int salir = 0;		

	// Se almacenan las entradas del teclado
	int entrada = 1;	
					
	setColor(WHITE);
	system("cls");
	printf("\n\t\t\tPrograma estadistico");
	printf("\n\nIngrese el nombre de la variable: ");
	gets(NombreVariable);
	printf("Variable \"%s\" registrada!\n\n", NombreVariable);
	Sleep(500);

	gotoxy(60, 1);
	setColor(CYAN);
	printf("Iniciando...", o);
	gotoxy(3, 10);
	setColor(YELLOW);
	printf("Cargando programa");
	puntitos(200, 5);
	printf("\n\n  Programa listo, presiona enter para continuar!");

	gotoxy(1, 20);
	setColor(RED);
	hidecursor();
	printf("si deseas cancelar, presiona: CONTROL+C");
	entrada = _getche();

	if (entrada == 3) { main(); }


	int indiceDato = 0;

	do
	{
		setColor(WHITE);
		char Dato_cadena[MAX_LENGHT] = { '\0' };
		system("cls");
		setColor(CYAN);
		printf("Variable: %s", NombreVariable);
		gotoxy(60, 1);
		setColor(GREEN);
		printf("En ejecuci%cn.", o);
		gotoxy(0, 0);
		setColor(WHITE);
		printf("\n\t\t\tPrograma estadistico\n\n");
		showcursor();
		printf("Ingresa el dato cuantitativo a registrar:");
		gets(Dato_cadena);

		if (validarDatos(Dato_cadena))
		{
			/* Convierte el Dato_cadena a entero*/
			Datos[indiceDato] = atoi(Dato_cadena);
			indiceDato++;

			/* Muestra los datos ingresados en pantalla */
			for (int i = 0; i < (int)sizeof(Datos) / (int)sizeof(Datos[0]); i++)
			{
				if (Datos[i] != 0)
				{
					printf(" %d, ", Datos[i]);
				}
			}
			gotoxy(4, 15);
			printf("ESCAPE para terminar");
			printf("\t\t\tENTER para continuar");

			/* Escucha las pulsaciones del teclado */
			for (;;)
			{
				hidecursor();
				entrada = getkey();
				/*printf("%d\n", entrada);*/
				if (entrada == 0)				/* ESCAPE  0*/
				{
					salir = 0; break;
				}
				if (entrada == 1)				/* ENTER 1*/
				{
					salir = 1; break;
				}
			}
		}
		else
		{
			salir = 1;
		}
		showcursor();

	} while (salir == 1);
}
Beispiel #16
0
void time_out_screen(void){
	char *s,i,l,p;
	char c = 0;

	if (demo)
		return;
	
	for (p=0;p<players+1;++p){
		for (i=0;i<10;++i){
			if (score[p] > highscore[i].score)
				break;
		}
		if (i != 10){
			for (l=9;l>i;--l){
				strcpy(highscore[l].name,highscore[l-1].name);
				highscore[l].score = highscore[l-1].score;
				highscore[l].level = highscore[l-1].level;
			}
			txt_mode();
			init_msx(5);
			if (team)
				sprintf(str_dummy,"well done, team!");
			else
				sprintf(str_dummy,"well done player %d",p+1);
			print2x2_centered(str_dummy,7,8,8);
			sprintf(str_dummy,"#%d score: %06lu",i+1,score[p]);
			print2x2_centered(str_dummy,10,2,10);
			print2x2_centered("enter your name:",4,3,14);
			l = 0;
			s = highscore[i].name;
			*s = '\0';

			while(1){
				if (*(char*)0xdc00 == 111 && l == 0){
					strcpy(highscore[i].name,"mr. button");
					print2x2_centered(highscore[i].name,15,12,17);
					delay(50);
					break;
				}
				if ((c = getkey())== 13)
					break;

				else if (c == 20){
					if (l){
						*(--s) = '\0';
						--l;
					memset((char*)(0x0400 + 17*40),0xff,80);
					}
				}
				else if (!isprint(c))
					continue;
				else if (++l == 11){
					l = 10;
					continue;
				}
				else{
					*s++ = c;
					*s = '\0';
				}
				print2x2_centered(highscore[i].name,15,12,17);
			}
			highscore[i].score = score[p];
			highscore[i].level = level;
			show_highscores();
		}
	}
}
Beispiel #17
0
int t_chat2()
{
	int currchar;
	char inbuf[120];
	BOOL page_pending = FALSE;
	int ch;
	char seedstr[STRLEN];
	long seed;
	char rcvbuf[512];
	int chatport;
	char *mycrypt();


	if (check_page_perm() < 0)
		return C_FOOT;

	chatport = CHATPORT;
#if 1
	if (chatport == 0)
		chatport = 6177;
#endif

#if 0
#if	defined(NSYSUBBS1)
	getdata(1, 0, _msg_chat_1, genbuf, 2, ECHONOSP);
	if (genbuf[0] == '2')
		chatport = CHATPORT + 1;
#endif
#endif

	/* initialize */
	inbuf[0] = '\0';
	currchar = 0;
	chat_line = 0;

	if (!getdata(1, 0, "Enter Chat id: ", mychatid, CHATIDLEN, ECHONOSP))
		xstrncpy(mychatid, curuser.userid, CHATIDLEN);

	fixchatid(mychatid);

	if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
	{
		move(2, 0);
		outs(_msg_chat_3);
		refresh();
		sprintf(genbuf, "bbschatd %d", chatport);
		outdoor(genbuf);
		sleep(2);
		if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
		{
			perror("connect failed");
			pressreturn();
			return C_FULL;
		}
	}

	/* receive ChatServer Hello Welcome VersionInfo */
	net_gets(ac, genbuf, sizeof(genbuf));
	/* receive Random Number for Checksum */
	net_gets(ac, seedstr, sizeof(seedstr));
	seed = atol(mycrypt(seedstr));
	net_printf(ac, "USRID\t%s\t%ld\r\n", curuser.userid, seed);
	net_gets(ac, genbuf, sizeof(genbuf));
	if (strncmp(genbuf, "+OK", 3))	/* lthuang */
	{
		outs(_msg_chat_4);
		pressreturn();
		return C_FULL;
	}

	uinfo.mode = CHATROOM;
	xstrncpy(uinfo.chatid, mychatid, sizeof(uinfo.chatid));
	update_ulist(cutmp, &uinfo);

	/* set prompt */
	strcpy(prompt, mychatid);
	strcat(prompt, ":           ");
	prompt[SAYWORD_POINT] = '\0';

	draw_chat_screen();

	add_io(ac, 0);

	net_gets(ac, genbuf, sizeof(genbuf));	/* welcome !! */
	genbuf[strlen(genbuf) - 1] = '\0';
	printchatline(genbuf);
#if 0
	net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	net_gets(ac, genbuf, sizeof(genbuf));
#endif
	if (strcmp(mychatid, curuser.userid))
	{
		net_printf(ac, "NICKNAME\t%s\r\n", mychatid);
		net_gets(ac, genbuf, sizeof(genbuf));
	}

	/* Chat Main */
	while (1)
	{
		ch = getkey();
		if (PLINE != CUR_PLINE) {
			draw_chat_screen();
			continue;
		}
		if (talkrequest)
			page_pending = TRUE;
		if (page_pending)
			page_pending = servicepage(0);
		if (msqrequest)
		{
			add_io(0, 0);
			msqrequest = FALSE;
			msq_reply();
			add_io(ac, 0);
			continue;
		}

		if (ch == I_OTHERDATA)
		{
			if (!net_gets(ac, rcvbuf, sizeof(rcvbuf)))
				break;
			rcvbuf[strlen(rcvbuf) - 1] = '\0';	/* lthuang */
			if (rcvbuf[0] == '/')
			{
				char *p, *nick;

				if ((p = strchr(rcvbuf, '\t')) != NULL)
				{
					*p = '\0';
					if (cmp_wlist(iglist, rcvbuf + 1, strcmp))
						continue;

					nick = p + 1;
					if ((p = strchr(nick, '\t')) != NULL)
					{
						*p = '\0';

						if (cmp_wlist(iglist, nick, strcmp))
							continue;

						strcpy(genbuf, nick);
						strcat(genbuf, ":           ");
						genbuf[SAYWORD_POINT] = '\0';
						strcat(genbuf, ++p);
						printchatline(genbuf);
					}
				}
			}
#if 0
			else if (rcvbuf[0] == '*')
			{
				sprintf(genbuf, "%s", rcvbuf);
				printchatline(genbuf);
			}
#endif
			else
				printchatline(rcvbuf);
		}
		else if (isprint2(ch))
		{
			if (SAYWORD_POINT + currchar - 1 >= t_columns - 3)
			{
				bell();
				continue;
			}
			inbuf[currchar++] = ch;
			inbuf[currchar] = '\0';
			move(PLINE, SAYWORD_POINT + currchar - 1);
			outc(ch);
		}
		else if (ch == '\n' || ch == '\r')
		{
			char *p = inbuf;

			currchar = 0;

			while (*p != '\0' && isspace((int)(*p)))
				p++;
			if (*p == '\0')
				continue;
			if (inbuf[0] == '/')
				dochatcommand(inbuf + 1);
			else
			{
				net_printf(ac, "SPEAK\t%s\r\n", inbuf);
				sprintf(genbuf, "%s%s", prompt, inbuf);
				printchatline(genbuf);
			}

			inbuf[0] = '\0';

			/* show prompt */
			move(PLINE, 0);
			clrtoeol();
			outs(prompt);
		}
		else if (ch == CTRL('H') || ch == '\177')
		{
			if (currchar == 0)
			{
				bell();
				continue;
			}
			move(PLINE, SAYWORD_POINT + --currchar);
			outs(" ");
			inbuf[currchar] = '\0';
		}
		else if (ch == CTRL('C') || ch == CTRL('D'))
		{
			net_printf(ac, "QUIT\r\n");	/* lthuang */
			break;
		}
		else if (ch == CTRL('R'))
		{
			msq_reply();
			continue;
		}
		else if (ch == CTRL('Q'))
		{
			add_io(0, 0);
			t_query();
			add_io(ac, 0);
			continue;
		}
		move(PLINE, currchar + SAYWORD_POINT);
	}
	add_io(0, 0);
	close(ac);
	uinfo.chatid[0] = '\0';
	update_ulist(cutmp, &uinfo);
	free_wlist(&iglist, free);

	return C_FULL;
}
Beispiel #18
0
/*
 * Name:    differ
 * Purpose: diff text pointers
 * Date:    October 31, 1992
 * Passed:  initial_rcol1:  beginning column to begin diff in window1
 *          initial_rcol2:  beginning column to begin diff in window2
 *          bottom:         line to display diagnostics
 * Notes:   a straight diff on text pointers is simple; however, diffing
 *            with leading spaces and tabs is kinda messy.  let's do the
 *            messy diff.
 */
int  differ( int initial_rcol1, int initial_rcol2, int bottom )
{
int  rcol1;             /* virtual real column on diff window 1 */
int  rcol2;             /* virtual real column on diff window 2 */
int  r1;                /* real real column rcol1 - needed for tabs */
int  r2;                /* real real column rcol2 - needed for tabs */
char c1;                /* character under r1 */
char c2;                /* character under r2 */
int  leading1;          /* adjustment for leading space in window 1 */
int  leading2;          /* adjustment for leading space in window 2 */
int  len1;              /* length of diff1 line */
int  len2;              /* length of diff2 line */
line_list_ptr node1;    /* scratch node in window 1 */
line_list_ptr node2;    /* scratch node in window 2 */
text_ptr diff1;         /* scratch text ptr in window 1 */
text_ptr diff2;         /* scratch text ptr in window 2 */
long rline1;            /* real line number of diff pointer 1 */
long rline2;            /* real line number of diff pointer 2 */
long bin_offset1;       /* binary offset of diff pointer 1 */
long bin_offset2;       /* binary offset of diff pointer 2 */
int  len;               /* line length variable */
register int tabs;      /* local variable for mode.inflate_tabs, T or F */
char line_buff[(MAX_COLS+1)*2];  /* buffer for char and attribute  */

   /*
    * initialize the text pointers and the initial column.  skip any
    *  initial blank lines.
    */
   rline1 = diff.rline1;
   rline2 = diff.rline2;
   node1 = diff.d1;
   node2 = diff.d2;
   bin_offset1 = diff.bin_offset1;
   bin_offset2 = diff.bin_offset2;
   tabs  = mode.inflate_tabs;
   if (diff.blank_lines) {
      while (node1->len != EOF  && is_line_blank( node1->line, node1->len )) {
         bin_offset1 += node1->len;
         node1 = node1->next;
         ++rline1;
         initial_rcol1 = 0;
      }
      while (node2->len != EOF  && is_line_blank( node2->line , node2->len)) {
         bin_offset2 += node2->len;
         node2 = node2->next;
         ++rline2;
         initial_rcol2 = 0;
      }
   }

   /*
    * if everything is everything, initialize the diff variables and diff.
    */
   if (node1->len != EOF  &&  node2->len != EOF) {
      diff1 = node1->line;
      diff2 = node2->line;
      rcol1 = initial_rcol1;
      rcol2 = initial_rcol2;
      len1  = node1->len;
      len2  = node2->len;

      assert( rcol1 >= 0 );
      assert( rcol1 < MAX_LINE_LENGTH );
      assert( rcol2 >= 0 );
      assert( rcol2 < MAX_LINE_LENGTH );
      assert( len1 >= 0 );
      assert( len1 < MAX_LINE_LENGTH );
      assert( len2 >= 0 );
      assert( len2 < MAX_LINE_LENGTH );

      /*
       * if cursors are past EOL, move them back to EOL.
       */
      len = find_end( diff1, len1 );
      if (rcol1 > len)
         rcol1 = len;
      len = find_end( diff2, len2 );
      if (rcol2 > len)
         rcol2 = len;

      /*
       * if skip leading space, make sure our cursors start on first non-space.
       */
      if (diff.leading) {
         leading1 = skip_leading_space( diff1, len1 );
         leading2 = skip_leading_space( diff2, len2 );
         if (tabs) {
            leading1 = detab_adjust_rcol( diff1, leading1 );
            leading2 = detab_adjust_rcol( diff2, leading2 );
         }
         if (rcol1 < leading1)
            rcol1 = leading1;
         if (rcol2 < leading2)
            rcol2 = leading2;
      }

      /*
       * we now have a valid rcol for the diff start, we may need to adjust
       *   for tabs, though.
       */
      assert( rcol1 >= 0 );
      assert( rcol1 < MAX_LINE_LENGTH );
      assert( rcol2 >= 0 );
      assert( rcol2 < MAX_LINE_LENGTH );

      r1 =  tabs ? entab_adjust_rcol( diff1, len1, rcol1 ) : rcol1;
      r2 =  tabs ? entab_adjust_rcol( diff2, len2, rcol2 ) : rcol2;

      assert( r1 >= 0 );
      assert( r1 <= len1 );
      assert( r2 >= 0 );
      assert( r2 <= len2 );
      assert( r1 <= rcol1 );
      assert( r2 <= rcol2 );

      s_output( diff_message, g_display.mode_line, 67, g_display.diag_color );
      while (node1->len != EOF  &&  node2->len != EOF  &&
                         !g_status.control_break) {

         /*
          * look at each character in each diff window
          */
         c1 = (char)(r1 < len1 ? *(diff1 + r1)  : 0);
         c2 = (char)(r2 < len2 ? *(diff2 + r2)  : 0);

         /*
          *  tabs == space
          */
         if (tabs) {
            if (c1 == '\t')
               c1 = ' ';
            if (c2 == '\t')
               c2 = ' ';
         }

         /*
          * skip spaces, if needed
          */
         if (diff.all_space) {
            while (c1 == ' '  &&  r1 < len1) {
               ++rcol1;
               r1 = tabs ? entab_adjust_rcol( diff1, len1, rcol1 ) : rcol1;
               c1 =  (char)(r1 < len1  ?  *(diff1 + r1) :  0);
               if (c1 == '\t'  &&  tabs)
                  c1 = ' ';
            }
            while (c2 == ' '  &&  r2 < len2) {
               ++rcol2;
               r2 = tabs ? entab_adjust_rcol( diff2, len2, rcol2 ) : rcol2;
               c2 =  (char)(r2 < len2  ? *(diff2 + r2) : 0);
               if (c2 == '\t'  &&  tabs)
                  c2 = ' ';
            }
         }

         /*
          * if one of the node pointers has come to EOL, move to next
          *   diff line.
          */
         if (diff.ignore_eol) {
            if (r1 >= len1) {
               node1 = skip_eol( node1, &r1, &rcol1, &rline1, &bin_offset1 );
               len1  = node1->len;
               if (len1 != EOF) {
                  diff1 = node1->line;
                  c1 =  (char)(r1 < len1  ?  *(diff1 + r1) : 0);
                  if (c1 == '\t'  &&  tabs)
                     c1 = ' ';
               }
            }
            if (r2 >= len2) {
               node2 = skip_eol( node2, &r2, &rcol2, &rline2, &bin_offset2 );
               len2  = node2->len;
               if (len2 != EOF) {
                  diff2 = node2->line;
                  c2 =  (char)(r2 < len2  ? *(diff2 + r2)  :  0);
                  if (c2 == '\t'  &&  tabs)
                     c2 = ' ';
               }
            }
         }

         /*
          * convert the characters to lower case, if needed.
          */
         if (mode.search_case == IGNORE) {
            c1 = (char)tolower( c1 );
            c2 = (char)tolower( c2 );
         }

         /*
          * diff each character in the diff lines until we reach EOL
          */
         while (r1 < len1  && r2 < len2) {
            if (c1 == c2) {
               if (diff.all_space) {
                  do {
                     ++rcol1;
                     r1 = tabs ? entab_adjust_rcol( diff1,len1,rcol1 ) : rcol1;
                     c1 =  (char)(r1 < len1  ?  *(diff1 + r1)  :  0);
                     if (c1 == '\t'  &&  tabs)
                        c1 = ' ';
                  } while (c1 == ' '  &&  r1 < len1);
                  do {
                     ++rcol2;
                     r2 = tabs ? entab_adjust_rcol( diff2,len2,rcol2 ) : rcol2;
                     c2 =  (char)(r2 < len2  ?  *(diff2 + r2)  :  0);
                     if (c2 == '\t'  &&  tabs)
                        c2 = ' ';
                  } while (c2 == ' '  &&  r2 < len2);
               } else {
                  ++rcol1;
                  ++rcol2;
                  r1 = tabs ? entab_adjust_rcol( diff1, len1, rcol1 ) : rcol1;
                  r2 = tabs ? entab_adjust_rcol( diff2, len2, rcol2 ) : rcol2;
                  c1 =  (char)(r1 < len1  ?  *(diff1 + r1)  :  0);
                  c2 =  (char)(r2 < len2  ?  *(diff2 + r2)  :  0);
                  if (tabs) {
                     if (c1 == '\t')
                        c1 = ' ';
                     if (c2 == '\t')
                        c2 = ' ';
                  }
               }
               if (diff.ignore_eol) {
                  if (r1 >= len1) {
                     node1 = skip_eol(node1, &r1, &rcol1, &rline1,&bin_offset1);
                     len1  = node1->len;
                     if (len1 != EOF) {
                        diff1 = node1->line;
                        c1 =  (char)(r1 < len1  ?  *(diff1 + r1)  : 0);
                        if (c1 == '\t'  &&  tabs)
                           c1 = ' ';
                     }
                  }
                  if (r2 >= len2) {
                     node2 = skip_eol(node2, &r2, &rcol2, &rline2,&bin_offset2);
                     len2  = node2->len;
                     if (len2 != EOF) {
                        diff2 = node2->line;
                        c2 = (char)(r2 < len2  ? *(diff2 + r2)  :  0);
                        if (c2 == '\t'  &&  tabs)
                           c2 = ' ';
                     }
                  }
               }
               if (mode.search_case == IGNORE) {
                  c1 = (char)tolower( c1 );
                  c2 = (char)tolower( c2 );
               }
            } else {

               /*
                * when we show the diff, use rcol1 and rcol2, as
                *   find_adjust does not adjust rcol for tabs.
                */
               update_line( diff.w1 );
               diff.w1->bin_offset = bin_offset1;
               find_adjust( diff.w1, node1, rline1, rcol1 );
               check_virtual_col( diff.w1, rcol1, rcol1 );
               show_diff_window( diff.w1 );
               update_line( diff.w2 );
               diff.w2->bin_offset = bin_offset2;
               bin_offset_adjust( diff.w2, rline2 );
               find_adjust( diff.w2, node2, rline2, rcol2 );
               check_virtual_col( diff.w2, rcol2, rcol2 );
               show_diff_window( diff.w2 );
               s_output( diff_blank, g_display.mode_line, 67,
                         g_display.mode_color );
               return( OK );
            }
         }

         /*
          * if we haven't come to the end of a file buffer, check the last
          *   characters.  see if pointers are at EOL.
          */
         if (node1->len != EOF && node2->len != EOF) {
            if (rcol1 != len1  &&  rcol2 != len2) {
               update_line( diff.w1 );
               diff.w1->bin_offset = bin_offset1;
               find_adjust( diff.w1, node1, rline1, rcol1 );
               show_diff_window( diff.w1 );
               update_line( diff.w2 );
               diff.w2->bin_offset = bin_offset2;
               find_adjust( diff.w2, node2, rline2, rcol2 );
               show_diff_window( diff.w2 );
               s_output( diff_blank, g_display.mode_line, 67,
                         g_display.mode_color );
               return( OK );
            } else {
               node1 = skip_eol( node1, &r1, &rcol1, &rline1, &bin_offset1 );
               len1  = node1->len;
               diff1 = node1->line;
               node2 = skip_eol( node2, &r2, &rcol2, &rline2, &bin_offset2 );
               len2  = node2->len;
               diff2 = node2->line;
            }
         }

         assert( rcol1 >= 0 );
         assert( rcol1 < MAX_LINE_LENGTH );
         assert( rcol2 >= 0 );
         assert( rcol2 < MAX_LINE_LENGTH );
         assert( r1 >= 0 );
         assert( r1 < MAX_LINE_LENGTH );
         assert( r2 >= 0 );
         assert( r2 < MAX_LINE_LENGTH );
         assert( r1 <= rcol1 );
         assert( r2 <= rcol2 );
         if (node1->len == EOF)
            assert( len1 == EOF );
         else {
            assert( len1 >= 0 );
            assert( len1 < MAX_LINE_LENGTH );
         }
         if (node2->len == EOF)
            assert( len2 == EOF );
         else {
            assert( len2 >= 0 );
            assert( len2 < MAX_LINE_LENGTH );
         }
      }
      save_screen_line( 0, bottom, line_buff );
      set_prompt( diff_prompt4, bottom );
      getkey( );
      restore_screen_line( 0, bottom, line_buff );
      s_output( diff_blank, g_display.mode_line, 67, g_display.mode_color );
   }
   return( ERROR );
}
bool confirmdisband()                      // concerned should be (slightly) more likely
{                                          // to be the phrase. (Issue, not the CCS, etc.)
   static const char *issue_phrases[] =    //    -- LK
   {  /////////////////////////////////////////////////////////////////////////////////////////
      // Liberal Phrase           // Conservative Equivalent  // Stalinist Equivalent        //
      /////////////////////////////////////////////////////////////////////////////////////////
      "Corporate Accountability", // Deregulation             // Nationalized Industry       //
      "Free Speech",              // Child Safety             // Ideological Purity          //
      "Gay Marriage",             // Sanctity of Marriage     // Bourgeoisie Decadence       //
      "Abortion Rights",          // Right to Life            // Population Control          //
      "Separation Clause",        // Under God                // Opiate of the Masses        //
      "Racial Equality",          // Emmett Till              // Kulaks                      //
      "Gun Control",              // Second Amendment         // Firing Squad                //
      "Campaign Finance Reform",  // Freedom to Campaign      // People's Republic           //
      "Animal Rights",            // Animal Abuse             // Capitalist Pig-Dogs         //
      "Worker's Rights",          // Right to Work            // Canadian Gulags             //
      "Police Responsibility",    // Rodney King              // Secret Police               // /* XXX: "Civilian" Police (Note to self) -- LK */
      "Global Warming",           // Self-Regulation          // Five-Year Plan              //
      "Immigration Reform",       // Border Control           // Iron Curtain                // /* XXX: "Nicer" Term (Note to self) -- LK */
      "Human Rights",             // National Security        // Reeducation                 // /* XXX: 2+2 = 5? (Note to self) -- LK */
      "Woman's Suffrage",         // Traditional Gender Roles // Honey Trap                  //
      "Right To Privacy",         // Wiretapping              // Stasi                       //
      "Medical Marijuana",        // War on Drugs             // Vodka                       //
      "Flag Burning",             // Patriotism               // Hammer and Sickle           // /* XXX: Towards the beginning of 1984, at Winston's job. (Note to self) -- LK */
      "Life Imprisonment",        // Zero Tolerance           // Mass Grave                  //
      "Conflict Resolution",      // Preemptive Strike        // Mutual Assured Destruction  //
      "Radiation Poisoning",      // Nuclear Power            // Chernobyl                   //
      "Tax Bracket"               // Flat Tax                 // Proletariat                 //
   }; /////////////////////////////////////////////////////////////////////////////////////////

   string word=pickrandom(issue_phrases);

   for(int pos=0;pos<len(word);)
   {
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,1);
      mvaddstr(0,0,"Are you sure you want to disband?");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      mvaddstr(2,0,"Disbanding scatters the Liberal Crime Squad, sending all of its members");
      mvaddstr(3,0,"into hiding, free to pursue their own lives.  You will be able to observe");
      mvaddstr(4,0,"the political situation in brief, and wait until a resolution is reached.");

      mvaddstr(6,0,"If at any time you determine that the Liberal Crime Squad will be needed");
      mvaddstr(7,0,"again, you may return to the homeless shelter to restart the campaign.");

      mvaddstr(9,0,"Do not make this decision lightly.  If you do need to return to action,");
      mvaddstr(10,0,"only the most devoted of your former members will return.");

      set_color(COLOR_WHITE,COLOR_BLACK,1);
      mvaddstr(13,0,"Type this Liberal phrase to confirm (press a wrong letter to rethink it):");

      for(int x=0;x<len(word);x++)
      {
         if(x==pos) set_color(COLOR_GREEN,COLOR_BLACK,0);
         else if(x<pos) set_color(COLOR_GREEN,COLOR_BLACK,1);
         else set_color(COLOR_WHITE,COLOR_BLACK,0);
         mvaddchar(15,x,word[x]);
      }

      if(getkey()==::tolower(word[pos]))
      {
         pos++;
         if(word[pos]==' '||word[pos]=='\''||word[pos]=='-') pos++;
      }
      else return false;
   }
   //SET UP THE DISBAND
   for(int p=len(pool)-1;p>=0;p--)
   {
      if(!pool[p]->alive || pool[p]->flag&CREATUREFLAG_KIDNAPPED || pool[p]->flag&CREATUREFLAG_MISSING) delete_and_remove(pool,p);
      else if(!(pool[p]->flag&CREATUREFLAG_SLEEPER))
      {
         removesquadinfo(*pool[p]);
         pool[p]->hiding=-1;
      }
   }
   cleangonesquads();
   disbandtime=year;
   return true;
}
Beispiel #20
0
int main(void)
{
   int idx, wordm = 0, loop = 0;
   char class, *tokp, string[SIZE], word[12];
   double tot, divs;

   char units[3][TYPES][11] = {
      { /* The labels */
	"millimetr", "centimetr", "decimetr", "metr", "kilometr",
	"millilitr", "centilitr", "decilitr", "litr", "decalitr", "ettolitr",
        "milligramm", "gramm", "decagramm", "kilogramm", "tonnellat", "quintal",
        "gallon", "pollic", "pied", "libbr", "yard",

        /* Word meters */
        "quart", "dozzin" },

      { /* The values */
	"1", "10", "100", "1000", "1000000",
	"1", "10", "100", "1000", "10000", "100000",
	"1", "1000", "10000", "1000000", "10000000", "100000000",

	/* 3.7853  "2.54" "30.48"  "0.4536"  "0.9144" */
	"3785", "25.4", "304.8", "4.536", "914.4",

        /* Word meters */
	"4", "12" },

      { /* The classes */
	"A", "A", "A", "A", "A",
	"B", "B", "B", "B", "B", "B",
	"C", "C", "C", "C", "C", "C",
	"B", "A", "A", "C", "A",

        /* Word meters: 0 divide, 1 multiply */
	"0", "1" }
   };

   printf("Please, write your answer: ");
   gets(string);

   tokp = getkey(string, units, &idx);
   while(tokp != NULL) {

      /* Check for the "word meters": un quarto, una dozzina, etc. */
      if( !memcmp(tokp, "un", 2) )
	 strcpy(word, "1");
      else
	 strcpy(word, tokp);

      if( *units[2][idx] == '0' || *units[2][idx] == '1' ) {
	 wordm = 1; /* Mark the "operation" as "Word meter" */
	 strcat(word, " ");

	 if( (tokp = getkey(NULL, units, &idx)) != NULL )
	    strcat(word, tokp);
	 else
	    break;
      }

      switch(++loop) {
	 case 1:
	    divs = atof(units[1][idx]);
	    class = *units[2][idx];
	    break;
	 case 2:
	    tot = atof(word);
	    break;
	 case 3:

            /* If there is a word meter.. */
	    if(wordm) { /* Marked operation */
	       if( !memcmp(word, "quart", 5) )
		  tot *= atof(units[1][idx]) / 4;
	       else
		  tot *= atof(units[1][idx]) * 12;
	    }
	    else
	       tot *= atof(units[1][idx]);

	    if(class != *units[2][idx]) {
	       printf("error: conflict in conversion types\n");
	       return -1;
	    }
	    
	    break;
	 default:
	    printf("unknown error: please fix this\n");
	    break;
      }

      /* DeBuG
      printf("case[%d]===[ word: %s\n", loop, word);
      */

      tokp = getkey(NULL, units, &idx);
   }

   if(loop != 3)
      printf("Are you forgetting something? :-)\n");
   else
      printf("Results: %.2f\n", tot / divs);

   return 0;
} /* E0F main */
Beispiel #21
0
/* Convert Arrow keystrokes to Control characters: */
static char
msdos_getch()
{
	char c;

#ifdef DJGPP
    int ch = getkey();
    c = (ch & 0xff00) ? 0 : ch & 0xff;
#elif defined (OS2)
    c = getc(stdin);
#else /* not OS2, not DJGPP*/
# if defined (_Windows) && defined (USE_MOUSE)
    if (term && term->waitforinput && interactive)
	c = term->waitforinput();
    else
# endif /* not _Windows && not USE_MOUSE */
    c = getch();
#endif /* not DJGPP, not OS2 */

    if (c == 0) {
#ifdef DJGPP
	c = ch & 0xff;
#else /* not DJGPP */
# ifdef OS2
	c = getc(stdin);
# else				/* not OS2 */
	c = getch();		/* Get the extended code. */
# endif				/* OS2 */
#endif /* not DJGPP */

	switch (c) {
	case 75:		/* Left Arrow. */
	    c = 002;
	    break;
	case 77:		/* Right Arrow. */
	    c = 006;
	    break;
	case 72:		/* Up Arrow. */
	    c = 020;
	    break;
	case 80:		/* Down Arrow. */
	    c = 016;
	    break;
	case 115:		/* Ctl Left Arrow. */
	case 71:		/* Home */
	    c = 001;
	    break;
	case 116:		/* Ctl Right Arrow. */
	case 79:		/* End */
	    c = 005;
	    break;
	case 83:		/* Delete */
	    c = 0177;
	    break;
	default:
	    c = 0;
	    break;
	}
    } else if (c == 033) {	/* ESC */
	c = 025;
    }
    return c;
}
Beispiel #22
0
#define NUM_REGISTERS	256

static estr regs[NUM_REGISTERS];

DEFUN_ARGS ("copy-to-register", copy_to_register,
            INT_ARG (reg))
/*+
Copy region into register @i{register}.
+*/
{
  INT_INIT (reg)
  else
    {
      minibuf_write ("Copy to register: ");
      reg = getkey (GETKEY_DEFAULT);
    }

  if (reg == KBD_CANCEL)
    ok = FUNCALL (keyboard_quit);
  else
    {
      minibuf_clear ();
      if (reg < 0)
        reg = 0;
      reg %= NUM_REGISTERS; /* Nice numbering relies on NUM_REGISTERS
                               being a power of 2. */

      if (warn_if_no_mark ())
        ok = leNIL;
      else
Beispiel #23
0
Datei: search.c Projekt: sctb/em
/* ARGSUSED */
int
queryrepl(int f, int n)
{
	int	s;
	int	rcnt = 0;		/* replacements made so far	*/
	int	plen;			/* length of found string	*/
	char	news[NPAT], *rep;	/* replacement string		*/

	if (macrodef) {
		dobeep();
		ewprintf("Can't query replace in macro");
		return (FALSE);
	}

	if ((s = readpattern("Query replace")) != TRUE)
		return (s);
	if ((rep = eread("Query replace %s with: ", news, NPAT,
	    EFNUL | EFNEW | EFCR, pat)) == NULL)
		return (ABORT);
	else if (rep[0] == '\0')
		news[0] = '\0';
	ewprintf("Query replacing %s with %s:", pat, news);
	plen = strlen(pat);

	/*
	 * Search forward repeatedly, checking each time whether to insert
	 * or not.  The "!" case makes the check always true, so it gets put
	 * into a tighter loop for efficiency.
	 */
	while (forwsrch() == TRUE) {
retry:
		update(CMODE);
		switch (getkey(FALSE)) {
		case 'y':
		case ' ':
			if (lreplace((RSIZE)plen, news) == FALSE)
				return (FALSE);
			rcnt++;
			break;
		case '.':
			if (lreplace((RSIZE)plen, news) == FALSE)
				return (FALSE);
			rcnt++;
			goto stopsearch;
		/* ^G, CR or ESC */
		case CCHR('G'):
			(void)ctrlg(FFRAND, 0);
			goto stopsearch;
		case CCHR('['):
		case CCHR('M'):
			goto stopsearch;
		case '!':
			do {
				if (lreplace((RSIZE)plen, news) == FALSE)
					return (FALSE);
				rcnt++;
			} while (forwsrch() == TRUE);
			goto stopsearch;
		case 'n':
		case CCHR('H'):
		/* To not replace */
		case CCHR('?'):
			break;
		default:
			ewprintf("y/n or <SP>/<DEL>: replace/don't, [.] repl-end, [!] repl-rest, <CR>/<ESC> quit");
			goto retry;
		}
	}
stopsearch:
	curwp->w_rflag |= WFFULL;
	update(CMODE);
	if (rcnt == 1)
		ewprintf("Replaced 1 occurrence");
	else
		ewprintf("Replaced %d occurrences", rcnt);
	return (TRUE);
}
Beispiel #24
0
int waitforkey(void)
{
    do idle(); while (!keypressed());
    return getkey();
}
Beispiel #25
0
AuthInfo*
p9any(int fd)
{
	char buf[1024], buf2[1024], cchal[CHALLEN], *bbuf, *p, *dom, *u;
	char *pass;
	char tbuf[TICKETLEN+TICKETLEN+AUTHENTLEN], trbuf[TICKREQLEN];
	char authkey[DESKEYLEN];
	Authenticator auth;
	int afd, i, n, v2;
	Ticketreq tr;
	Ticket t;
	AuthInfo *ai;

	if((afd = open("/mnt/factotum/ctl", ORDWR)) >= 0)
		return p9anyfactotum(fd, afd);

	if(readstr(fd, buf, sizeof buf) < 0)
		fatal(1, "cannot read p9any negotiation");
	bbuf = buf;
	v2 = 0;
	if(strncmp(buf, "v.2 ", 4) == 0){
		v2 = 1;
		bbuf += 4;
	}
	if((p = strchr(bbuf, ' ')))
		*p = 0;
	p = bbuf;
	if((dom = strchr(p, '@')) == nil)
		fatal(1, "bad p9any domain");
	*dom++ = 0;
	if(strcmp(p, "p9sk1") != 0)
		fatal(1, "server did not offer p9sk1");

	sprint(buf2, "%s %s", p, dom);
	if(write(fd, buf2, strlen(buf2)+1) != strlen(buf2)+1)
		fatal(1, "cannot write user/domain choice in p9any");
	if(v2){
		if(readstr(fd, buf, sizeof buf) != 3)
			fatal(1, "cannot read OK in p9any");
		if(memcmp(buf, "OK\0", 3) != 0)
			fatal(1, "did not get OK in p9any");
	}
	for(i=0; i<CHALLEN; i++)
		cchal[i] = fastrand();
	if(write(fd, cchal, 8) != 8)
		fatal(1, "cannot write p9sk1 challenge");

	if(readn(fd, trbuf, TICKREQLEN) != TICKREQLEN)
		fatal(1, "cannot read ticket request in p9sk1");


	convM2TR(trbuf, &tr);
	u = user;
	pass = findkey(&u, tr.authdom);
	if(pass == nil)
	again:
		pass = getkey(u, tr.authdom);
	if(pass == nil)
		fatal(1, "no password");

	passtokey(authkey, pass);
	memset(pass, 0, strlen(pass));

	tr.type = AuthTreq;
	strecpy(tr.hostid, tr.hostid+sizeof tr.hostid, u);
	strecpy(tr.uid, tr.uid+sizeof tr.uid, u);
	convTR2M(&tr, trbuf);

	if(gettickets(&tr, authkey, trbuf, tbuf) < 0)
		fatal(1, "cannot get auth tickets in p9sk1");

	convM2T(tbuf, &t, authkey);
	if(t.num != AuthTc){
		print("?password mismatch with auth server\n");
		goto again;
	}
	memmove(tbuf, tbuf+TICKETLEN, TICKETLEN);

	auth.num = AuthAc;
	memmove(auth.chal, tr.chal, CHALLEN);
	auth.id = 0;
	convA2M(&auth, tbuf+TICKETLEN, t.key);

	if(write(fd, tbuf, TICKETLEN+AUTHENTLEN) != TICKETLEN+AUTHENTLEN)
		fatal(1, "cannot send ticket and authenticator back in p9sk1");

	if((n=readn(fd, tbuf, AUTHENTLEN)) != AUTHENTLEN ||
			memcmp(tbuf, "cpu:", 4) == 0){
		if(n <= 4)
			fatal(1, "cannot read authenticator in p9sk1");

		/*
		 * didn't send back authenticator:
		 * sent back fatal error message.
		 */
		memmove(buf, tbuf, n);
		i = readn(fd, buf+n, sizeof buf-n-1);
		if(i > 0)
			n += i;
		buf[n] = 0;
		werrstr("");
		fatal(0, "server says: %s", buf);
	}
	
	convM2A(tbuf, &auth, t.key);
	if(auth.num != AuthAs
	|| memcmp(auth.chal, cchal, CHALLEN) != 0
	|| auth.id != 0){
		print("?you and auth server agree about password.\n");
		print("?server is confused.\n");
		fatal(0, "server lies got %llux.%d want %llux.%d",
		      *(int64_t*)auth.chal, auth.id, *(int64_t*)cchal, 0);
	}
	//print("i am %s there.\n", t.suid);
	ai = mallocz(sizeof(AuthInfo), 1);
	ai->secret = mallocz(8, 1);
	des56to64((uint8_t*)t.key, ai->secret);
	ai->nsecret = 8;
	ai->suid = strdup(t.suid);
	ai->cuid = strdup(t.cuid);
	memset(authkey, 0, sizeof authkey);
	return ai;
}
Beispiel #26
0
int fgetc(FILE *f) {
  return (getkey());
}
Beispiel #27
0
int fgetc(FILE *f) {
    return (sendchar(getkey()));
}
Beispiel #28
0
static void PerformEditCommand(
  void *theEnv)
{
        register int    c;
        register int    f;
        register int    n;
        register int    mflag;
        register int    rtn_flag;
        char            bname[NBUFN];
        int num_a;
        char *fileName = NULL;
        DATA_OBJECT arg_ptr;

   /*====================*/
   /* Get the file name. */
   /*====================*/

   if ((num_a = EnvArgCountCheck(theEnv,"edit",NO_MORE_THAN,1)) == -1) return;

   if (num_a == 1)
     {
      if (EnvArgTypeCheck(theEnv,"edit",1,SYMBOL_OR_STRING,&arg_ptr) == FALSE) return;
      fileName = DOToString(arg_ptr);
     }

   if(bheadp == NULL) {

	/**********************************************/
	/* Initial entry, set up buffers and pointers */
	/**********************************************/

        genstrcpy(bname, "main");                  /* Work out the name of */
        if (num_a > 0)                     /* the default buffer.  */
                makename(bname,fileName);
        edinit(theEnv,bname);                          /* Buffers, windows.    */
        vtinit(theEnv);                               /* Displays.            */
        if (num_a > 0) {
                update();                       /* You have to update   */
                readin(theEnv,fileName);             /* in case "[New file]" */
                }

	init_cmp_router(theEnv);			/* Prepare the compile  */
        EnvDeactivateRouter(theEnv,"cmp_router");		/* router.              */
        }
   else {

	/**********************************************************/
	/* Return from temporary exit, reset necessary stuff only */
	/**********************************************************/

	(*term.t_open)();

        if (num_a > 0) {
           filevisit_guts(theEnv,fileName);
           }
        }

   sgarbf = TRUE;                          /* Force screen update  */
   lastbufn[0] = '\0';                     /* Make sure last name  */
                                           /* is cleared out       */

   lastflag = 0;                           /* Fake last flags.     */
loop:
        update();                               /* Fix up the screen    */
        c = getkey();
        if (mpresf != FALSE) {
                mlerase();
                update();
                if (c == ' ')                   /* ITS EMACS does this  */
                        goto loop;
        }
        f = FALSE;
        n = 1;
        if (c == (COTL|'U')) {                  /* ^U, start argument   */
                f = TRUE;
                n = 4;                          /* with argument of 4 */
                mflag = 0;                      /* that can be discarded. */
                mlwrite("Arg: 4");
                while ((((c=getkey()) >='0') && (c<='9'))
                       || (c==(COTL|'U')) || (c=='-')){
                        if (c == (COTL|'U'))
                                n = n*4;
                        /*
                         * If dash, and start of argument string, set arg.
                         * to -1.  Otherwise, insert it.
                         */
                        else if (c == '-') {
                                if (mflag)
                                        break;
                                n = 0;
                                mflag = -1;
                        }
                        /*
                         * If first digit entered, replace previous argument
                         * with digit and set sign.  Otherwise, append to arg.
                         */
                        else {
                                if (!mflag) {
                                        n = 0;
                                        mflag = 1;
                                }
                                n = 10*n + c - '0';
                        }
                        mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1));
                }
                /*
                 * Make arguments preceded by a minus sign negative and change
                 * the special argument "^U -" to an effective "^U -1".
                 */
                if (mflag == -1) {
                        if (n == 0)
                                n++;
                        n = -n;
                }
        }
        if (c == (COTL|'X'))                    /* ^X is a prefix       */
                c = CTLX | getctl();
        if (kbdmip != NULL) {                   /* Save macro strokes.  */
                if (c!=(CTLX|')') && kbdmip>&kbdm[NKBDM-6]) {
                        ctrlg(theEnv,FALSE, 0);
                        goto loop;
                }
                if (f != FALSE) {
                        *kbdmip++ = (COTL|'U');
                        *kbdmip++ = n;
                }
                *kbdmip++ = c;
        }
        rtn_flag = execute(theEnv,c, f, n);                /* Do it.               */
        if(rtn_flag == EXIT)
           return;
	else
           goto loop;
}
Beispiel #29
0
//interface functions as below
int	getString(const char *pkey, char *value)
{
	if ((0 == strlen(pkey)) || (NULL == fpl))	return FAILURE;
	uint p, key, c = 0;
	key = getkey(pkey);
	Find(&s_parse, key, &p, &c);
	uint offset = s_parse.ele[p].ioffset;
	
	//FILE	*fp = NULL;
	char	*pk = NULL;
	char	stream[MAX_STREAM] = {0};
	char	str_value[MAX_VALUE] = {0};
	int	totalLength, enterOffSet = 0;
	
	/*fp=fopen("string1.conf","r");
	if(fp==NULL)
	{
		printf("\r\nCan't open string1.conf\n");
		return NULL;
	}*/
	
	fseek(fpl, offset, SEEK_SET);
	while(fgets(stream, MAX_STREAM, fpl) != NULL){
	
		enterOffSet = 0;
		if(strrchr(stream,'\r') != NULL)
		{
			enterOffSet++;
		}
		if(strrchr(stream,'\n') != NULL)
		{
			enterOffSet++;
		}

		pk = strstr(stream, pkey);
		
		if ((pk != NULL) && (pk == stream))
		{
			totalLength=strlen(stream)-strlen(pkey)-1-enterOffSet;//1 means '=' length
			if(MAX_VALUE<totalLength+1) 		/*total length + '\0' should not less than buffer*/
			{
				//tcdbg_printf("\r\nToo small buffer to catch the %s frome get_string_value\n", keyname);
				//fclose(fp);
				return FAILURE;
			}
			else if(totalLength<0)		/*can't get a negative length string*/ 
			{
				//printf("\r\nNo profile string can get\n");
				//fclose(fp);
				return FAILURE;
			}
			else
			{
				strncpy(str_value, pk+strlen(pkey)+1, totalLength);
				str_value[totalLength] = '\0';
				strcpy(value, str_value);
				//if (0 != flag){
				//	tcdbg_printf("\r\n%s:Can't get string value from hash table\n", pkey);
				//}
				//fclose(fp);
				return strlen(value);
			}
			
		}
		else{
			break;
		}
	}
	//fclose(fp);
	tcdbg_printf("\r\n%s:Can't get string value from file\n", pkey);
	return FAILURE;
	
}
                // Trial using bitmap copying
                // Caller must create and destroy the bitmap
int bitmap_recording_trial(HBITMAP gbm, UINT32 time_limit)
{
  UINT32 trial_start;	// trial start time (for timeout) 
  UINT32 drawing_time;  // retrace-to-draw delay
  int button;		// the button pressed (0 if timeout) 
  int error;            // trial result code

    // NOTE: TRIALID AND TITLE MUST HAVE BEEN SET BEFORE DRIFT CORRECTION!
    // FAILURE TO INCLUDE THESE MAY CAUSE INCOMPATIBILITIES WITH ANALYSIS SOFTWARE!

	   // DO PRE-TRIAL DRIFT CORRECTION 
	   // We repeat if ESC key pressed to do setup. 
  while(1)
    {              // Check link often so we can exit if tracker stopped
      if(!eyelink_is_connected()) return ABORT_EXPT;
	   // We let do_drift_correct() draw target in this example
	   // 3rd argument would be 0 if we already drew the fixation target
      error = do_drift_correct((INT16)(SCRWIDTH/2), (INT16)(SCRHEIGHT/2), 1, 1);
           // repeat if ESC was pressed to access Setup menu 
      if(error!=27) break;
    }

  clear_full_screen_window(target_background_color);  // make sure display is blank
  
	// Start data recording to EDF file, BEFORE DISPLAYING STIMULUS 
	// You should always start recording 50-100 msec before required
	// otherwise you may lose a few msec of data 
  error = start_recording(1,1,0,0);   // record samples and events to EDF file only
  if(error != 0) return error;        // ERROR: couldn't start recording

                              // record for 100 msec before displaying stimulus 
  begin_realtime_mode(100);   // Windows 2000/XP: no interruptions till display start marked

    // DISPLAY OUR IMAGE TO SUBJECT  by copying bitmap to display
    // Because of faster drawing speeds and good refresh locking,
    // we now place the stimulus onset message just after display refresh 
    // and before drawing the stimulus.  This is accurate and will allow 
    // drawing a new stimulus each display refresh.
    // However, we do NOT send the message after the retrace--this may take too long
    // instead, we add a number to the message that represents the delay 
    // from the event to the message in msec
  wait_for_video_refresh();	// synchronize before drawing so all seen at once
  drawing_time = current_msec();                  // time of retrace
  trial_start = drawing_time;  // record the display onset time 
  
  display_bitmap(full_screen_window, gbm, 0, 0);  // COPY BITMAP to display
  wait_for_drawing(full_screen_window);    // wait till bitmap copy finished

  drawing_time = current_msec()-drawing_time;    // delay from retrace (time to draw)
  eyemsg_printf("%d DISPLAY ON", drawing_time);	 // message for RT recording in analysis 
  eyemsg_printf("SYNCTIME %d", drawing_time);	 // message marks zero-plot time for EDFVIEW 

                        // we would stay in realtime mode if timing is critical   
                        // for example, if a dynamic (changing) stimulus was used
                        // or if display duration accuracy of 1 video refresh. was needed
  end_realtime_mode();  // we don't care as much about time now, allow keyboard to work
     
                                 // Now get ready for trial loop
  eyelink_flush_keybuttons(0);   // reset keys and buttons from tracker 

                       // we don't use getkey() especially in a time-critical trial
                       // as Windows may interrupt us and cause an unpredicatable delay
                       // so we would use buttons or tracker keys only  

     // Trial loop: till timeout or response 
  while(1)   
    {                            // First, check if recording aborted 
      if((error=check_recording())!=0) return error;  
                                 // Check if trial time limit expired
      if(current_time() > trial_start+time_limit)
        {
          eyemsg_printf("TIMEOUT");    // message to log the timeout 
	  end_trial();                 // local function to stop recording
	  button = 0;                  // trial result message is 0 if timeout 
	  break;                       // exit trial loop
	}
      if(break_pressed())     // check for program termination or ALT-F4 or CTRL-C keys
	{
	   end_trial();         // local function to stop recording
	   return ABORT_EXPT;   // return this code to terminate experiment
	 }

      if(escape_pressed())    // check for local ESC key to abort trial (useful in debugging)   
         {
	   end_trial();         // local function to stop recording
	   return SKIP_TRIAL;   // return this code if trial terminated
         }

		/* BUTTON RESPONSE TEST */
		// Check for eye-tracker buttons pressed
		// This is the preferred way to get response data or end trials	
      button = eyelink_last_button_press(NULL);
      if(button!=0)       // button number, or 0 if none pressed
	{
	   eyemsg_printf("ENDBUTTON %d", button);  // message to log the button press
	   end_trial();                            // local function to stop recording
	   break;                                  // exit trial loop
	 }
    }                       // END OF RECORDING LOOP
  end_realtime_mode();      // safety cleanup code
  while(getkey());          // dump any accumulated key presses

			   // report response result: 0=timeout, else button number
  eyemsg_printf("TRIAL_RESULT %d", button);
			   // Call this at the end of the trial, to handle special conditions
  return check_record_exit();
}