示例#1
0
文件: test.cpp 项目: MaDOS/pi1
bool test_execute_turn(int input[SIZE_Y][SIZE_X], const int output[SIZE_Y][SIZE_X],
					   const int player, const int pos_x, const int pos_y)
{
		std::cout << "Running test for 'valid turn execution'..." << std::endl;
		std::cout << "----------------------------" << std::endl;
		show_field(input);
		std::cout << "Checking turn" << std::endl;
		execute_turn(input, player, pos_x, pos_y);

		bool result = true;
		for(int i = 0; i < SIZE_X; i++)
		{
			for(int j = 0; j < SIZE_Y; j++)
			{
				if(input[j][i] != output[j][i])
				{
					result = false;
					break;
				}
			}
		}
		if (result)
		{
			std::cout << "Test passed!" << std::endl;
			if (VERBOSE == 1)
			{
				std::cout << "Calculated result: " << result << std::endl;
				show_field(input);

				std::cout << "Right result: " << result << std::endl;
				show_field(output);
			}
			return true;
		}
		else
		{
			std::cout << "Test failed!" << std::endl;
			if (VERBOSE == 1)
			{
				std::cout << "Calculated result: " << result << std::endl;
				show_field(input);

				std::cout << "Right result: " << result << std::endl;
				show_field(output);
			}
			return false;
		}
		return 0;
}
示例#2
0
/*!
 * @brief 様々な初期化設定を行う
 *
 * シグナルハンドラを設定し、画面を初期化する。<br>
 * また、ブロックを生成する。
 */
static void initialize(int sock) {
  uint i;

  sig_sock = sock;                   /* シグナルハンドラが参照できるように、グローバル変数にソケットを記憶 */
  signal(SIGINT, sig_handler);       /* シグナルハンドラの設定 */
  srand(gettimeofday_sec());         /* 乱数の種の設定 */
  initscr();                         /* 画面を初期化する */
  clear();
  cbreak();                          /* 入力をバッファに溜め込まないようにする */
  noecho();                          /* エコーバックを行わないようにする */
  fcntl(sock, F_SETFL, O_NONBLOCK);  /* sockからのread()をノンブロッキングに(リアルタイム処理を可能にする) */
  nodelay(stdscr, TRUE);             /* getch()をノンブロッキングに */
  print_labels();                    /* ラベルを描画する */

  /* 画面と壁を初期設定 */
  for (i = 0; i < STAGE_HEIGHT; i++) {
    uint j;
    for (j = 0; j < STAGE_WIDTH; j++) {
      if ((j == 0) || (j == STAGE_WIDTH - 1) || (i == STAGE_HEIGHT - 1)) {
        field[i][j] = stage[i][j] = WALL;
      } else {
        field[i][j] = stage[i][j] = SPACE;
      }
    }
  }
  create_block();                 /* 最初のブロック発生させる */
  show_field(field, MY_FIELD_X);  /* ゲーム直後の画面を描画 */
}
示例#3
0
文件: test.cpp 项目: MaDOS/pi1
///Tests if the winner is calculated correctly
///
///Checks a given field for a winner and tests if the winner is calculated correctly
///Params: field The field to test, winner_code the player who should have won on the given field(0-draw;1-p1;2-p2)
bool test_winner(const int field[SIZE_Y][SIZE_X], const int winner_code)
{
	std::cout << "Running test for 'winner'..." << std::endl;
	std::cout << "----------------------------" << std::endl;
	show_field(field);
	std::cout << "Checking who wins" << std::endl;
	int result = winner(field);
	if (result == winner_code)
	{
		std::cout << "Test passed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << winner_code
					  << std::endl;
		}
		return true;
	}
	else
	{
		std::cout << "Test failed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << winner_code
					  << std::endl;
		}
		return false;
	}
}
示例#4
0
文件: test.cpp 项目: MaDOS/pi1
bool test_turn_valid(const int field[SIZE_Y][SIZE_X], const int player, const int pos_x,
					 const int pos_y, const bool valid)
{
	std::cout << "Running test for 'valid turn'..." << std::endl;
	std::cout << "----------------------------" << std::endl;
	show_field(field);
	std::cout << "Checking turn" << std::endl;
	bool result = turn_valid(field, player, pos_x, pos_y);
	if (result == valid)
	{
		std::cout << "Test passed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << valid
					  << std::endl << "Player: " << player << std::endl << "X: " << pos_x << std::endl << "Y: " << pos_y << std::endl;
		}
		return true;
	}
	else
	{
		std::cout << "Test failed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << valid
					  << std::endl << "Player: " << player << std::endl << "X: " << pos_x << std::endl << "Y: " << pos_y << std::endl;
		}
		return false;
	}
	return 0;
}
示例#5
0
文件: test.cpp 项目: MaDOS/pi1
bool test_possible_turns(const int field[SIZE_Y][SIZE_X], const int player,
						 const int count_possible_turns)
{
	std::cout << "Running test for 'possible turns'..." << std::endl;
	std::cout << "----------------------------" << std::endl;
	show_field(field);
	std::cout << "Checking how many turns are possible" << std::endl;
	int result = possible_turns(field, player);
	if (result == count_possible_turns)
	{
		std::cout << "Test passed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << count_possible_turns
					  << std::endl;
		}
		return true;
	}
	else
	{
		std::cout << "Test failed!" << std::endl;
		if (VERBOSE == 1)
		{
			std::cout << "Calculated result: " << result << std::endl << "Right result: " << count_possible_turns
					  << std::endl;
		}
		return false;
	}
	return 0;
}
static void
do_once(struct varnish_stats *VSL_stats, const char* fields)
{
	struct timeval tv;
	double up;

	gettimeofday(&tv, NULL);
	up = tv.tv_sec - VSL_stats->start_time;

	do {
		if (fields != NULL && ! show_field("uptime", fields ))
			break;
		printf("%-16s %12ju %12s %s\n", "uptime",
		    (uintmax_t)(tv.tv_sec - VSL_stats->start_time),
		    ".  ", "Child uptime");
	} while (0);

#define MAC_STAT(n, t, l, f, d) \
	do { \
		if (fields != NULL && ! show_field( #n, fields )) break; \
		intmax_t ju = VSL_stats->n; \
		if (f == 'a') \
			printf("%-16s %12ju %12.2f %s\n", #n, ju, ju / up, d); \
		else \
			printf("%-16s %12ju %12s %s\n", #n, ju, ".  ", d); \
	} while (0);
#include "stat_field.h"
#undef MAC_STAT
}
示例#7
0
/*!
 * @brief ブロックを落下させる
 *
 * ブロックの重なりも検出する。
 * @see check_overlap()
 */
static void drop_block(void) {
  if (!check_overlap(x, y + 1)) {  /* 重なりがなければ移動 */
    move_block(x, y + 1);
  } else {                         /* 重なりがあれば壁にする */
    lock_block();
    create_block();
    show_field(field, MY_FIELD_X);
  }
}
示例#8
0
/*!
 * @brief ゲームのメインループ
 * @param [in] sock  送信先ソケットのディスクリプタ
 */
int play_tetris(int sock) {
  static const uchar FLAG = GAMEOVER;  /* ゲームオーバ時に送信する値 */
  uint   cnt = 1;                 /* カウンタ */
  time_t base_time = time(NULL);  /* ゲーム開始時刻を記憶 */

  initialize(sock); /* 初期化 */
  while (!gameover) {  /* ゲームオーバーになるまでゲーム続行 */
    static uchar enemy_field[STAGE_HEIGHT][STAGE_WIDTH];  /* 相手のフィールドデータを格納する2次元配列 */
    time_t game_time;        /* ゲームを開始してから、何秒経過したかを保持する */

    /* キー入力があればそれに応じて操作 */
    control_block();
    /* 32回ループをしたら、ブロックを1マス落とす */
    if ((cnt = (cnt + 1) % 32) == 0) {
      drop_block();
    }

    write(sock,  field, sizeof(field));             /* 自分のフィールドデータを送信 */
    write(sock, &score, sizeof(score));             /* 自分のスコアを送信 */
    read(sock,  enemy_field, sizeof(enemy_field));  /* 相手のフィールドデータを受信 */
    read(sock, &enemy_score, sizeof(enemy_score));  /* 相手のスコアを受信 */
    show_field(enemy_field, ENEMY_FIELD_X);  /* 相手のフィールドを描画する */

    if (read_protocol(enemy_field[0][0])) {  /* 特別な値を受信していないかチェックする */
      sleep(1);
      return EXIT_SUCCESS;  /* ゲーム終了 */
    }

    print_score(ENEMY_SCORE_X, ENEMY_SCORE_Y, enemy_score);  /* 相手のスコアを描画 */

    if ((game_time = GAME_TIME - (time(NULL) - base_time)) == 0) {
      timeup(sock);
      sleep(1);
      return EXIT_SUCCESS;  /* ゲーム終了 */
    }
    print_time(game_time);  /* ゲーム時間を表示する */

    usleep(20000);                   /* 20000マイクロ秒停止する(この間、CPUに負荷をかけない) */
  }
  write(sock, &FLAG, sizeof(FLAG));  /* 自分がゲームオーバになったことを相手に知らせる */

  clear();
  mvprintw(RESULT_STR_Y, RESULT_STR_X, "You lose!");
  refresh();
  sleep(2);
  endwin();  /* curses終了 */

  puts("\nYou lose!");
  sleep(1);
  return EXIT_SUCCESS;
}
示例#9
0
/*!
 * @brief ブロックを回転させる
 * @return 回転できなかったとき1を、回転できたとき0を返す。
 */
static uchar turn_block(turn_drct_e direction) {
  static uchar temp[BLOCK_HEIGHT][BLOCK_WIDTH];  /*ブロックを一時保存するための配列 */
  uint i;
  for (i = 0; i < BLOCK_HEIGHT; i++) {
    uint j;
    for (j = 0; j < BLOCK_WIDTH; j++) {
      temp[i][j] = block[i][j];
    }
  }
  /* ブロックを回転 */
  if (direction == RIGHT) {  /* 右回りに回転 */
    for (i = 0; i < BLOCK_HEIGHT; i++) {
      uint j;
      for (j = 0; j < BLOCK_WIDTH; j++) {
        block[i][j] = temp[(BLOCK_WIDTH - 1) - j][i];
      }
    }
  } else {                   /* 左回りに回転 */
    for (i = 0; i < BLOCK_HEIGHT; i++) {
      uint j;
      for (j = 0; j < BLOCK_WIDTH; j++) {
        block[i][j] = temp[j][(BLOCK_WIDTH - 1) - i];
      }
    }
  }

  /* 重なってるブロックが出てしまったらブロックを回転前に戻して中止 */
  if (check_overlap(x, y)) {
    for (i = 0; i < BLOCK_HEIGHT; i++) {
      uint j;
      for (j = 0; j < BLOCK_WIDTH; j++) {
        block[i][j] = temp[i][j];
      }
    }
    return FALSE;
  }
  /* 一旦フィールドからブロック消して回転後のブロックを再表示 */
  for (i = 0; i < BLOCK_HEIGHT; i++) {
    uint j;
    for (j = 0; j < BLOCK_WIDTH; j++) {
      field[y + i][x + j] -= temp[i][j];
      field[y + i][x + j] += block[i][j];
    }
  }
  show_field(field, MY_FIELD_X);
  return TRUE;
}
示例#10
0
/*!
 * @brief ブロックを移動する
 * @param [in] new_x 基準位置のx座標
 * @param [in] new_y 基準位置のy座標
 */
static void move_block(uint new_x, uint new_y) {
  uint i;
  /* 今までのブロックを消す */
  for (i = 0; i < BLOCK_HEIGHT; i++) {
    uint j;
    for (j = 0; j < BLOCK_WIDTH; j++) {
      field[y + i][x + j] -= block[i][j];
    }
  }

  /* ブロックの座標を更新 */
  x = new_x;
  y = new_y;

  /* 新しい座標にブロックを入れ直す */
  for (i = 0; i < BLOCK_HEIGHT; i++) {
    uint j;
    for (j = 0; j < BLOCK_WIDTH; j++) {
      field[y + i][x + j] += block[i][j];
    }
  }
  show_field(field, MY_FIELD_X);
}
示例#11
0
文件: 114.c 项目: Shmuma/acm.uva.es
void next_step (int *x, int *y, int *dir, unsigned long long *got, int *ttl)
{
    int xx = *x, yy = *y;
    
#ifdef DEBUG
    printf ("Step %d: (%d,%d), dir = %d, ttl = %d, score = %d\n", step++, 1 + *x, 1 + *y, *dir, *ttl, *got);
#endif

    (*ttl)--;
    if (*ttl <= 0)
        return;
    xx += inc_x[*dir];
    yy += inc_y[*dir];

#ifdef DEBUG
    show_field (*x, *y, xx, yy, *dir, *got, *ttl);
#endif

    /* We'll hit bump or wall */
    if (bumps[xx][yy]) {
        *ttl -= costs[xx][yy];
        if (*ttl > 0)
            *got += values[xx][yy];
        *dir = rotate [*dir];
#ifdef DEBUG
        printf ("Hit bump at %d,%d. New ttl = %d, dir = %d, score = %d\n", xx+1, yy+1, *ttl, *dir, *got);
#endif
        return;
    }

#ifdef DEBUG
    printf ("Don't hit anything, new coord (%d,%d)\n", xx+1, yy+1);
#endif
    *x = xx;
    *y = yy;
}
示例#12
0
/* Show the object whose raw beginning (i.e. including tag(s)) is at s */
static mem_t
show_obj(mem_t start, ptr_t* objRef, int show, ShowType_t replicaType,
	Heap_t** legalHeaps, Bitmap_t** legalStarts)
{
	int i, type;
	mem_t temp, end = NULL;
	tag_t tag;
	ptr_t obj, replica;

	/* Skip past all extra tags (belonging to the obj) at the beginning */
	temp = start;
	while(*temp == SEGSTALL_TAG || *temp == SEGPROCEED_TAG)
		temp++;

	tag = *temp;
	obj = temp + 1;
	replica = obj;                       /* replica ultimately is 0 if equal to obj */

	if(show && !IS_SKIP_TAG(tag)){
		printf("%lx:  ", (long)start);
		if(start < obj - 1){
			printf("[");
			for (temp=start; temp < start - 1; temp++)
				printf("%d%s", *temp, (temp < start - 2) ? ", " : "");
			printf("]");
		}
	}
	while(TAG_IS_FORWARD(tag)){
		assert(replica != (ptr_t) tag);
		replica = (ptr_t) tag;
		tag = replica[-1];
		if(show)
			printf( " -> %lx", (long)replica);
		if(0 && inHeaps(replica, legalHeaps, NULL))
			trace_error("forwarding pointer is in same heap(s):  %lx -> %lx",
				obj, replica);
	}
	if(obj==replica || replicaType==NoReplica)
		replica = 0;
	if(show)
		printf (": ");
	type = GET_TYPE(tag);

	switch(type){
	case RECORD_TYPE:{
		int len = GET_RECLEN(tag);
		int mask = GET_RECMASK(tag);
		if(mask >> len){
			trace_error("bad record tag %d at %lx\n", tag, (long)start);
			DIE("bad record tag in show_obj");
		}
		if(show)
			printf("REC(%d)   %lx: ", len, (long)obj);
		for(i=0; i<len; i++){
			int isPointer = 1 & (mask >> i);
			show_field(show,
				isPointer ? PointerField : IntField,
				obj, replica, i, i, legalHeaps, legalStarts);
		}
		if(show)
			printf("\n");
		end = obj + len;
		break;
	}

	case MIRROR_PTR_ARRAY_TYPE:{
		unsigned int bytelen = GET_ANY_ARRAY_LEN(tag);
		unsigned int wordlen = (bytelen + 3) / 4;
		unsigned int loglen = wordlen / 2;
		int i;
		if(show)
			printf("MPA(%ld/%ld)  %lx: ",
				(long)wordlen,(long)loglen,(long)obj);
		for(i=0; i<loglen; i++){
			if(show && i != 0 && i % 4 == 0)
				printf("        ");
			if(!mirrorArray){
				assert(primaryArrayOffset == 0);
				show_field(show, PointerField, obj, replica,
					2*i, 2*i, legalHeaps, legalStarts);
			}
			else{
				int doReplica = replicaType != NoReplica;
				if(replicaType == SelfReplica && replica == NULL)
					/* self is replica if in tenured space */
					replica = obj;
				if(primaryArrayOffset == 0){
					show_field(show,
						doReplica ? OldPointerField : PointerField,
						obj, replica, 2*i,  2*i+1,
						legalHeaps, legalStarts);
					show_field(show,
						doReplica ? PointerField : IntField,
						obj, NULL, 2*i+1, 2*i,
						legalHeaps, legalStarts);
				}
				else{
					show_field(show,
						doReplica ? PointerField : IntField,
						obj, NULL, 2*i, 2*i+1,
						legalHeaps, legalStarts);
					show_field(show,
						doReplica ? OldPointerField : PointerField,
						obj, replica, 2*i+1, 2*i,
						legalHeaps, legalStarts);
				}
				if(show)
					printf("   ");
			}
		}
		if(show)
			printf("\n");
		end = obj + wordlen;
		break;
	}

	case WORD_ARRAY_TYPE:
	case QUAD_ARRAY_TYPE:
	case PTR_ARRAY_TYPE:{
		unsigned int bytelen = GET_ANY_ARRAY_LEN(tag);
		unsigned int wordlen = (bytelen + 3) / 4;
		unsigned int loglen, fieldlen;
		char *typeDesc = NULL;

		switch(type){
		case WORD_ARRAY_TYPE:
			loglen = bytelen;
			fieldlen = wordlen;
			typeDesc = "IAR";
			break;
		case QUAD_ARRAY_TYPE:
			loglen = bytelen / 8;
			fieldlen = loglen;
			typeDesc = "RAR";
			break;
		case PTR_ARRAY_TYPE:
			loglen = bytelen / 4;
			fieldlen = loglen;
			typeDesc = "PAR";
			break;
		default: 
			DIE("impossible");
		}
		if(show)
			printf("%s(%ld/%ld)  %lx: ",
				typeDesc,(long)wordlen,(long)loglen,(long)obj);

		for(i=0; i<fieldlen; i++){
			if(show && i != 0 && i%8 == 0)
				printf("        ");
			switch(type){
			case WORD_ARRAY_TYPE: 
				show_field(show,IntField,obj,replica,i,i,
					legalHeaps,legalStarts);  
				break;
			case PTR_ARRAY_TYPE: 
				show_field(show,PointerField,obj,replica,i,i,
					legalHeaps,legalStarts); 
				break;
			case QUAD_ARRAY_TYPE: 
				show_field(show,DoubleField,obj,replica,i,i,
					legalHeaps,legalStarts); 
				break;
			default :
				DIE("impossible");
			}
			if(show && (i+1)%8 == 0)
				printf("\n");
		}
		if(show)
			printf("\n");
		end = obj + wordlen;
		break;
	}

	case OTHER_TYPE:
		if(IS_SKIP_TAG(tag)){
			int wordsSkipped = GET_SKIPWORD(tag);
			end = start + wordsSkipped;
			if(show)
				printf("%lx - %lx: SKIP %d words\n",
					(long)start, (long)end, wordsSkipped);
			assert(wordsSkipped > 0);
		}
		else if(tag==MIRROR_GLOBAL_PTR_TAG){
			if(show)
				printf("MIRROR_GLOBAL   %lx: ", (long)obj);
			if(!mirrorGlobal){
				assert(primaryGlobalOffset == 0);
				show_field(show, PointerField, obj, replica, 0, 0,
					legalHeaps, legalStarts);
			}
			else{
				int doReplica = replicaType != NoReplica;
				if(replicaType == SelfReplica && replica == NULL)
					/* self is replica if in tenured space */
					replica = obj;
				if(primaryGlobalOffset == 0){
					show_field(show,
						doReplica ? OldPointerField : PointerField,
						obj, replica, 0, 1, legalHeaps, legalStarts);
					show_field(show,
						doReplica ? PointerField : IntField,
						obj, NULL, 1, 0, legalHeaps, legalStarts);
				}
				else{
					show_field(show,
						doReplica ? PointerField : IntField,
						obj, NULL, 0, 1,  legalHeaps, legalStarts);
					show_field(show,
						doReplica ? OldPointerField : PointerField,
						obj, replica, 1, 0, legalHeaps, legalStarts);
				}
			}
			if(show)
				printf("\n");
			end = obj + 2;
		}
		else{
			trace_error("bad tag %d(%d) at address = %lx",
				tag,GET_TYPE(tag),(long)obj);
			DIE("bad tag in show_obj");
		}
		break;
	}
	*objRef = obj;
	return end;
}
示例#13
0
void Game::turn()
{
	
	Player x;
	Opponent o;
	char mark;//bekommt den Wert X oder O je nach Spieler
	int who_inserts=1;//Wechsel zwischen Spielern durch %2
	int messenger_of_X_or_O=0;//überbringt das gewählte Feld vom aktuellen Spieler
	int i=-1; //sagt durch bestimmen von Gewinner/Draw ob das Spiel weiter geht

	do
	{

		show_field();

		/*********************************************
		Choses the Player and gives him his properties
		*********************************************/
		
		who_inserts=who_inserts%2;
		if (who_inserts==1)
		{
			x.ask_for_playerset();
			messenger_of_X_or_O=x.get_playerset();
			mark='X';
		}
		else
		{
			o.ask_for_opponentset();
			messenger_of_X_or_O=o.get_opponentset();
			mark='O';
		}

		/*******************************
		Sets the mark at a free position
		*******************************/

		if ( messenger_of_X_or_O == 1 && field[0] == '1')
			field[0] = mark;

		else if (messenger_of_X_or_O == 2 && field[1] == '2')
			field[1] = mark;

		else if (messenger_of_X_or_O == 3 && field[2] == '3')
			field[2] = mark;

		else if (messenger_of_X_or_O == 4 && field[3] == '4')
			field[3] = mark;

		else if (messenger_of_X_or_O == 5 && field[4] == '5')
			field[4] = mark;

		else if (messenger_of_X_or_O == 6 && field[5] == '6')
			field[5] = mark;

		else if (messenger_of_X_or_O == 7 && field[6] == '7')
			field[6] = mark;

		else if (messenger_of_X_or_O == 8 && field[7] == '8')
			field[7] = mark;

		else if (messenger_of_X_or_O == 9 && field[8] == '9')
			field[8] = mark;

		else
		{
				cout<<"Invalid move!" << endl;
				continue;
		}
		
		who_inserts++;
		i=check_if_won();
		
	}while (i==-1);

	show_field();

	if (i==1)
	{
		if(who_inserts==2)
			cout << "Yay the Player won!" << endl << endl;
		else
			cout << "Oh no, the Opponent won!" << endl << endl;
	}
	else 
		cout << "Draw!" << endl;

}
示例#14
0
static int
show_field_list( char *driver_name,
		mx_bool_type show_all_fields,
		mx_bool_type show_handles,
		mx_bool_type debug )
{
	static const char fname[] = "show_field_list()";

	MX_DRIVER *driver;
	MX_RECORD_FIELD_DEFAULTS *field_defaults_array, *field_defaults;
	unsigned long i;
	int status;

	if ( debug ) {
		fprintf(stderr, "%s invoked for driver '%s'\n",
			fname, driver_name);
	}

	/* Get the requested driver. */

	driver = mx_get_driver_by_name( driver_name );

	if ( driver == (MX_DRIVER *) NULL ) {
		fprintf( stderr, "The MX driver '%s' was not found.\n",
			driver_name );

		exit(1);
	}

	/* The pointers to the number of record fields and the record
	 * field defaults array must both be non-NULL for us to proceed.
	 */

	if ( ( driver->num_record_fields == NULL ) 
	  || ( driver->record_field_defaults_ptr == NULL ) )
	{
		/* This driver has no fields available and is not currently
		 * useable, so we do not try to do anything further with it.
		 */

		return SUCCESS;
	}

	/* Show the field list. */

	field_defaults_array = *(driver->record_field_defaults_ptr);

	for ( i = 0; i < *(driver->num_record_fields); i++ ) {

		field_defaults = &field_defaults_array[i];

		if ( ( show_all_fields == TRUE )
		  || ( field_defaults->flags & MXFF_IN_DESCRIPTION ) )
		{
			status = show_field( driver, field_defaults,
						(int) i, show_handles, debug );

		}
	}

	MXW_UNUSED( status );

	return SUCCESS;
}
示例#15
0
main()
{
  register long k;
  unsigned char t;
  struct fld_parms fld;

  putenv("_=record_format_srn");
  chdir(getenv("HOME"));

  sd_open(leave);
  sd_echo_flag = 0x20;
  ss_open();
  co_open();
  
  fix(record_format_srn);
  sd_screen_off();
  sd_clear_screen();
  sd_text(record_format_srn);
  sd_screen_on();
  
  memcpy(&x, rf, sizeof(struct rf_item));
  
  for (k = 0; k < NUM_PROMPTS; k++) show_field(k);
  
/*
 *  Only Super Operator May Input Data
 */
  getparms(0);
  
  if (!SUPER_OP)
  {
    eh_post(ERR_SUPER, 0);
    sd_cursor(0, 23, 3);
    sd_text("* * *  Hit Any Key   * * *");
    t = sd_keystroke(NOECHO);
    leave();
  }
  k = 0;
  
  while (1)
  {
    fld.irow   = field[k].row;
    fld.icol   = field[k].col;
    fld.pcol   = 0;
    fld.arrow  = 0;
    fld.length = &field[k].len;
    fld.prompt = 0;
    fld.type   = field[k].type;
    
    get_field(k); 

    t = sd_input(&fld, 0, 0, buf, 0);
  
    put_field(k);
    
    if (t == EXIT) leave();
    
    if (field[k].type == 'a')
    {
      if (field[k].valid)
      {
        if (!memchr(field[k].valid, *buf, strlen(field[k].valid)))
        {
          eh_post(ERR_CODE, buf);
          continue;
        }
      }
    }
    else
    {
      if (value < field[k].min || value > field[k].max)
      {
        eh_post(ERR_CODE, buf);
        continue;
      }
    }
    switch(k)
    {
      case 0:  if (x.rf_rp == 0x20 || !x.rf_rp)
               {
                 eh_post(ERR_PREFACE, 0);
                 x.rf_rp = rf->rf_rp;
                 continue;
               }
               break;
               
      case 1:  if (x.rf_rt == 0x20) x.rf_rt = 0; break;
      
      case 2:  if (x.rf_ft == 0x20) x.rf_ft = 0; break;
      
      case 3:  if (x.rf_eof == 0x20) x.rf_eof = 0; break;
      
      case 13: if (x.rf_box_pos > x.rf_rmks)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;
               
      case 14: if (x.rf_box_len && !x.rf_rmks)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;
      
      case 15: if (x.rf_box_count && !x.rf_box_len)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;

    }
    show_field(k);
    
    if (t == UP_CURSOR) {if (k > 0) k--;}
    else if (t == RETURN) break;
    else 
    {
      k++;
      if (k >= NUM_PROMPTS) k = 0;
    }
  }
  sd_prompt(&fld1, 0);
  memset(buf, 0, 2);
  t = sd_input(&fld1, 0, 0, buf, 0);
  if (t == EXIT) leave();
  *buf = tolower(*buf);
  if (*buf == 'y')
  {
    memcpy(rf, &x, sizeof(struct rf_item));
    system("ss_dump -sp= -rf=sys/rf_text 1>/dev/null 2>/dev/null");
  }
  leave();
}