示例#1
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	if (argc > 1)
		font = GP_FontFaceLoad(argv[1], 0, 20);

	print_instructions();

	win = GP_BackendInit(backend_opts, "Font Align Test");

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	black_pixel    = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context);
	red_pixel      = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context);
	blue_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context);
	green_pixel    = GP_RGBToContextPixel(0x00, 0xff, 0x00, win->context);
	yellow_pixel   = GP_RGBToContextPixel(0xff, 0xff, 0x00, win->context);
	white_pixel   = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context);
	darkgray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context);

	redraw_screen();
	GP_BackendFlip(win);
	event_loop();

	return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	print_instructions();

	if (argc > 1) {
		font_path = argv[1];
		fprintf(stderr, "\nLoading font '%s'\n", argv[1]);
		font = gp_font_face_load(argv[1], 0, font_h);
	}

	win = gp_backend_init(backend_opts, "Font Test");

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	white_pixel     = gp_rgb_to_pixmap_pixel(0xff, 0xff, 0xff, win->pixmap);
	gray_pixel      = gp_rgb_to_pixmap_pixel(0xbe, 0xbe, 0xbe, win->pixmap);
	dark_gray_pixel = gp_rgb_to_pixmap_pixel(0x7f, 0x7f, 0x7f, win->pixmap);
	black_pixel     = gp_rgb_to_pixmap_pixel(0x00, 0x00, 0x00, win->pixmap);
	red_pixel       = gp_rgb_to_pixmap_pixel(0xff, 0x00, 0x00, win->pixmap);
	blue_pixel      = gp_rgb_to_pixmap_pixel(0x00, 0x00, 0xff, win->pixmap);

	redraw_screen();
	gp_backend_flip(win);

	event_loop();

	return 0;
}
示例#3
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	print_instructions();

	if (argc > 1) {
		font_path = argv[1];
		fprintf(stderr, "\nLoading font '%s'\n", argv[1]);
		font = GP_FontFaceLoad(argv[1], 0, font_h);
	}

	win = GP_BackendInit(backend_opts, "Font Test");

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	white_pixel     = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context);
	gray_pixel      = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win->context);
	dark_gray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context);
	black_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context);
	red_pixel       = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context);
	blue_pixel      = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context);

	redraw_screen();
	GP_BackendFlip(win);

	event_loop();

	return 0;
}
示例#4
0
int
main(void)
{
	bool win = FALSE;
	int move, max_moves;
	int player;

	print_instructions();
	max_moves = DIM * DIM;	/* Maximum number of moves in a game */

	while (TRUE) {
		initialize_board();
		for (move = 1; move <= max_moves; move++) {
			player = move % 2 == 0 ? 2 : 1;
			win = do_move(player);
			print_board();
			if (win) {
				printf("Player %d, you WON!\n\n", player);
				break;		/* out of for loop */
			}
		}
		/*
		 * If we got here by falling through the loop, then it is a
		 * tie game.
		 */
		if (!win)
			printf("Tie Game!\n\n");
		if (!ask_yesno("Do you wish to play again?"))
			break;			/* out of while loop */
	}
	return 0;
}
示例#5
0
void
print_function(FunctionSpec* function) 
{
    print_metadata(function);
    print_components(&function->components);
    print_input_mapping(&function->input_mapping);
    print_instructions(&function->instructions);
    print_output_instructions(&function->output_instructions);
}
示例#6
0
int print_nhlfe(const struct nlmsghdr *n, void *arg, struct rtattr **tb)
{
	FILE *fp = (FILE*)arg;
	struct mpls_out_label_req *mol;
	struct mpls_instr_req *instr;
	struct gnet_stats_basic *stats;
        struct genlmsghdr *ghdr = NLMSG_DATA(n);

	if ((ghdr->cmd != MPLS_CMD_NEWNHLFE &&
	    ghdr->cmd != MPLS_CMD_DELNHLFE) ||
	    (!tb[MPLS_ATTR_NHLFE])) {
		fprintf(stderr, "Not a NHLFE\n");
		sprintf(mpls_table,"%s","Not a NHLFE \r\n"); //ad by here
		return -1;
	}

	mol = RTA_DATA(tb[MPLS_ATTR_NHLFE]);
	instr = RTA_DATA(tb[MPLS_ATTR_INSTR]);
	stats = RTA_DATA(tb[MPLS_ATTR_STATS]);

	if (ghdr->cmd == MPLS_CMD_DELNHLFE){
		fprintf(fp, "deleted NHLFE entry ");
		sprintf(mpls_table,"%s%s",mpls_table,"deleted NHLFE entry "); //ad by here
	}
	if (ghdr->cmd == MPLS_CMD_NEWNHLFE){
		fprintf(fp, "NHLFE entry ");
		sprintf(mpls_table,"%s%s",mpls_table,"NHLFE entry "); //ad by here
	}
	fprintf(fp, "key 0x%08x ", mol->mol_label.u.ml_key);
	fprintf(fp, "mtu %d ",mol->mol_mtu);
	
	add_olabel_key=mol->mol_label.u.ml_key; //add by here
	sprintf(mpls_table,"%s key 0x%08x mtu %d ",mpls_table,
	 mol->mol_label.u.ml_key,mol->mol_mtu); //ad by here

	
	if (mol->mol_propagate_ttl) {
		fprintf(fp, "propagate_ttl ");
		sprintf(mpls_table,"%s%s",mpls_table,"propagate_ttl "); //ad by here
	}
	fprintf(fp, "\n\t");
	sprintf(mpls_table,"%s\r\n\t",mpls_table); //ad by here
	if (instr && instr->mir_instr_length) {
		print_instructions(fp, instr);
		sprintf(mpls_table,"%s%s",mpls_table,print_instructions_buf); //ad by here
		flush_print_instructions_buf();
	}

	if (stats){
		print_mpls_stats(fp, stats);
		sprintf(mpls_table,"%s%s",mpls_table,print_mpls_stats_buf); //ad by here
	}
	fprintf(fp, "\n");
  sprintf(mpls_table,"%s\r\n",mpls_table); //ad by here
	fflush(fp);
	return 0;
}
示例#7
0
文件: codegen.c 项目: Neodyblue/a2c
void print_case(struct caseblock *c, int indent)
{
  for(size_t i = 0; i<c->exprlist.size;i++)
  {
    print_indent(indent);
    printf("case ");
    print_expression(c->exprlist.data[i]);
    printf(":\n");
  }
  print_instructions(c->instructions, indent + INDENT_WIDTH);
  print_indent(indent + INDENT_WIDTH);
  printf("break;\n");
}
示例#8
0
文件: codegen.c 项目: Neodyblue/a2c
void print_algo(struct algo *algo)
{
  if (algo->return_type)
    printf("%s ", algo_to_c_type(algo->return_type));
  else
    printf("void ");
  printf("%s(", algo->ident);
  print_param_decl(algo->declarations->param_decl);
  printf(")\n{\n");
  print_const_decl(algo->declarations->const_decls, INDENT_WIDTH);
  print_var_decl(algo->declarations->var_decl, INDENT_WIDTH);
  print_instructions(algo->instructions, INDENT_WIDTH);
  printf("}\n");
}
示例#9
0
文件: codegen.c 项目: Neodyblue/a2c
void print_prog(struct prog *prog)
{
  printf("#include <standard_lib.h>\n#include <stdio.h>\n#include <stdlib.h>\n");
  print_const_decl(prog->entry_point->const_decls, 0);
  for (unsigned i = 0; i < prog->algos.size; ++i)
    print_type_decls(prog->algos.data[i]->declarations->type_decls);
  print_type_decls(prog->entry_point->type_decls);
  print_var_decl(prog->entry_point->var_decl, 0);
  for (unsigned i = 0; i < prog->algos.size; ++i)
    print_algo(prog->algos.data[i]);
  printf("int main(void)\n{\n");
  print_instructions(prog->entry_point->instructions, INDENT_WIDTH);
  printf("}\n");
}
示例#10
0
void print_jsa_solution(messaget::mstreamt &os, const jsa_programt &program,
    const jsa_solutiont &solution, const pred_op_idst &op_ids,
    const pred_op_idst &const_op_ids)
{
  if (solution.query.empty() || program.st.symbols.empty())
  {
    os << "<jsa_solution />" << messaget::endl << messaget::eom;
    return;
  }
  os << "<jsa_solution>" << messaget::endl;
  print_consts(os, program);
  os << "  <variables>" << messaget::endl;
  os << "    <mutable>" << messaget::endl;
  print(os, op_ids);
  os << "    </mutable>" << messaget::endl;
  os << "    <const>" << messaget::endl;
  print(os, const_op_ids);
  os << "    </const>" << messaget::endl;
  os << "  </variables>" << messaget::endl;
  os << "  <predicates>" << messaget::endl;
  const jsa_solutiont::predicatest &predicates=solution.predicates;
  for (const goto_programt::instructionst &predicate : predicates)
  {
    os << "    <predicate>" << messaget::endl;
    print_instructions(os, program, predicate);
    os << "    </predicate>" << messaget::endl;
  }
  os << "  </predicates>" << messaget::endl;
  os << "  <query>" << messaget::endl;
  print_instructions(os, program, solution.query);
  os << "  </query>" << messaget::endl;
  os << "  <invariant>" << messaget::endl;
  print_instructions(os, program, solution.invariant);
  os << "  </invariant>" << messaget::endl;
  os << "</jsa_solution>" << messaget::endl << messaget::eom;
}
示例#11
0
void main(int argc, char *argv[])
{
	switch (argc) {
	case 2:
		encrypt_init();
		scramble_file(argv[1]);
		break;
	case 3:
		encrypt_init();
		if ( !stricmp("-u", argv[1]) ) {
			unscramble_file(argv[2]);
		} else if ( !stricmp("-st", argv[1]) ) {
			scramble_file(argv[2], argv[2], PREPROCESS_SHIPS_TBL);
		} else if ( !stricmp("-wt", argv[1]) ) {
			scramble_file(argv[2], argv[2], PREPROCESS_WEAPONS_TBL);
		} else {
			scramble_file(argv[1], argv[2]);
		}
		break;
	case 4:
		encrypt_init();
		if ( !stricmp("-u", argv[1]) ) {
			unscramble_file(argv[2], argv[3]);
		} else if ( !stricmp("-st", argv[1]) ) {
			scramble_file(argv[2], argv[3], PREPROCESS_SHIPS_TBL);
		} else if ( !stricmp("-wt", argv[1]) ) {
			scramble_file(argv[2], argv[3], PREPROCESS_WEAPONS_TBL);
		} else {
			print_instructions();
		}
		break;
	default:
		print_instructions();
		return;
	}
}
示例#12
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	print_instructions();

	GP_SetDebugLevel(10);

	if (argc > 1) {
		font_path = argv[1];
		fprintf(stderr, "\nLoading font '%s'\n", argv[1]);
		font = GP_FontFaceLoad(argv[1], 0, font_h);
	}

	win = GP_BackendInit(backend_opts, "Font Test", stderr);

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	white_pixel     = GP_ColorToContextPixel(GP_COL_WHITE, win->context);
	gray_pixel      = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win->context);
	dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context);
	black_pixel     = GP_ColorToContextPixel(GP_COL_BLACK, win->context);
	red_pixel       = GP_ColorToContextPixel(GP_COL_RED, win->context);
	blue_pixel      = GP_ColorToContextPixel(GP_COL_BLUE, win->context);

	redraw_screen();
	GP_BackendFlip(win);

	event_loop();

	return 0;
}
示例#13
0
文件: ui.c 项目: Sobih/BW4SA
void ui()
{
	int choice, len = 0;
	char* input = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH);
	char* res = malloc(sizeof(char));
	int* array = calloc(20, sizeof(int)); 
	
	print_choices();
	
	printf("Write the number of the operation you want to do:\n");
	scanf("%d", &choice);
	
	printf("Give the input string: (max size %d) ", MAX_INPUT_STRING_LENGTH);
	print_instructions(choice);
	scanf("%s", input);
	wavelet_tree* root = create_wavelet_tree(input);
	wavelet_tree* res_root;

	if (choice == 1) {
		char** strings = malloc(sizeof(char*));
		strings[0] = input;
		iterator_state* state = initialize_iterator(strings, 1);
		single_iterate(state, &print_node, 0);
		free_iterator_state(state);
		free(strings);
	} else if (choice == 2) {
		res_root = s_to_bwt(input);
		print_wavelet_tree(res_root);
	} else if (choice == 3) {
		res = bwt_to_s(root);
		printf("%s\n", res);
	} else if (choice == 4) {
		res_root = reverse_bwt(input);
		print_wavelet_tree(res_root);
	} else if (choice == 5) {
		array = create_c_array(root,0,0,0,0);
		int len = strlen(determine_alphabet(input));
		print_int_array(array, len);
	} else if (choice == 6) {
		bit_vector* runs = create_runs_vector(root,0);
		print_runs_vector(runs, strlen(input)+1);
		free_bit_vector(runs);
	} else if (choice == 7) {
		printf("Give the second input string: ");
		char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH);
		scanf("%s", input2);

		char** strings = malloc(2 * sizeof(char*));
		strings[0] = input;
		strings[1] = input2;
		parameter_struct* params = initialize_for_mums(strings, 0);
		iterator_state* state = iterate(params);
		mum_results* results = (mum_results*) params->ret_data;
		triplet* nodes = results->data;

		print_mums(input, results, state);
		mum_print_bit_vectors(input,input2, results, state);

		free(strings);
		free(results->data);
		free_iterator_state(state);

	} else if (choice == 8) {
		printf("Not supported yet\n");
	} else if (choice == 9) {
		printf("%d\n", distinct_substrings(input));
	} else if (choice == 10) {
		parameter_struct* params = initialize_for_max_repeats(input, 0);
		iterator_state* state = iterate(params);
		max_repeat_results* results = (max_repeat_results*) params->ret_data;
		//maximals_print_nodes(input);

		print_maximal_repeat_substrings(input, results, state);
		//compare_quick_sort()
	} else if (choice == 11) {
		printf("Give the second input string: ");
		char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH);
		scanf("%s", input2);

		char** strings = malloc(2 * sizeof(char*));
		strings[0] = input;
		strings[1] = input2;
		parameter_struct* params = initialize_for_mems(strings, 0);
		iterator_state* state = iterate(params);
		mem_results* results = (mem_results*) params->ret_data;
		triplet* nodes = results->data;

		print_mems(input, results, state);

		free(strings);
		free(results->data);
		free_iterator_state(state);
	}else {
		printf("Invalid choice\n");
	}


}
示例#14
0
static void parse_arguments(const int argc, char *const argv[])
{
	if (argc == 0) print_instructions();
	bool infile_found = false;
	bool outfile_found = false;

	for(int i = 0; i<argc; i++)
	{
		// Enable verbose if -v flag encountered in arguments list
		if(argv[i][0] == '-')
		{
			if(!strcmp(argv[i], "-v"))
			{
				verbose_flag = true;

				// Verbose to file if a file name is given
				if(i < argc-1 && argv[i+1][0] != '-')
				{
					verbose_output_to_file = true;
					out_txt = fopen(argv[i]+2, "w");
					if(!out_txt)
					{
						fprintf(stderr, "Invalid output text verbose file : %s\n", argv[i]+2);
						exit(-1);
					}
				}
			}else if(argv[i][1] == 'f')
			{
				force_output_unused = true;
			}

			// Change sampling rate if -s is encountered
			else if(argv[i][1] == 's')
			{
				change_sample_rate = true;
				sample_rate = atoi(argv[i]+2);
				if(!sample_rate)
				{
					fprintf(stderr, "Error, sampling rate %s is not a valid number.\n", argv[i]+2);
					exit(-1);
				}
			}
			
			// Change main volume if -mv is encountered
			else if(argv[i][1] == 'm' && argv[i][2] == 'v')
			{
				unsigned int volume = strtoul(argv[i]+3, 0, 10);
				if(volume==0 || volume>15)
				{
					fprintf(stderr, "Error, main volume %u is not valid (should be 0-15).\n", volume);
					exit(-1);
				}
				main_volume = volume;
			}
			else if(!strcmp(argv[i], "-gm"))
				gm_preset_names = true;
			
			else if(!strcmp(argv[i], "-help"))
				print_instructions();
		}

		// Try to parse an address and add it to list if succes
		else if(!infile_found)
		{
			// Input File
			infile_found = true;
			inGBA = fopen(argv[i], "rb");
			if(!inGBA)
			{
				fprintf(stderr, "Can't read input GBA file : %s\n", argv[0]);
				exit(-1);
			}
		}
		else if(!outfile_found)
		{
			outfile_found = true;
			size_t l = strlen(argv[i]);
			char *buffer = argv[i];
			if(l <= 4 || strcmp(argv[i] + (l-4), ".sf2"))
			{	// Append ".sf2" after the given file name if there isn't it already
				buffer = new char[l+4];
				strcpy(buffer, argv[i]);
				strcpy(buffer + l, ".sf2");
			}
			outSF2 = fopen(buffer, "wb");
			if(!outSF2)
			{
				fprintf(stderr, "Can't write on file : %s\n", argv[i]);
				exit(-1);
			}
			if(buffer != argv[i])
				delete[] buffer;
		}
		else
		{
			uint32_t address = strtoul(argv[i], 0, 0);
			if(!address) print_instructions();
			addresses.insert(address);				
		}
	}
	// Diagnostize errors/missing information
	if(!infile_found)
	{
		fputs("An input .gba file should be given. Use -help for more information.\n", stderr);
		exit(-1);
	}
	if(!outfile_found)
	{
		fputs("An output .sf2 file should be given. Use -help for more information.\n", stderr);
		exit(-1);
	}
	if(addresses.empty())
	{
		fputs("At least one adress should be given for decoding. Use -help for more information.\n", stderr);
		exit(-1);
	}
}
示例#15
0
int Amazons::play_game() {
    int row, col;

    // Reset the board in case mutliple games are played
    for (int i = 0; i < mImpl->board_size * mImpl->board_size; i++) {
        mImpl->board[i] = 0;
    }
    // Randomize player positions initially
    for (int p = 0; p < mImpl->p_count; p++) {
        row = rand() % mImpl->board_size;
        col = rand() % mImpl->board_size;
        if ( mImpl->board[mImpl->board_size * row + col] == 0){
            mImpl->board[mImpl->board_size * row + col] = (p+1);
        }
        else {
            p--;
        }
    }
    lock_game();
    int player = 0;
    int winner = 0;
    int p_with_move = mImpl->p_count;
    bool *has_move = (bool*) malloc(mImpl->p_count * sizeof(bool));
    for (int i = 0; i < mImpl->p_count; i++)
        has_move[i] = true;
    int move = 0;
    int r_to, c_to, r_arrow, c_arrow;
    while (p_with_move > 1) {
        player = move % mImpl->p_count;
        print_game(mImpl->p[player]->get_out_stream());
        if (!mImpl->can_move(player)) {
            if ((mImpl->p[player]->get_out_stream()) != NULL) {
                fprintf(mImpl->p[player]->get_out_stream(), "Player %i has no valid "
                            "move. Their turn will be skipped.\n", player+1);
            }
            p_with_move--;
            has_move[player] = false;
            move++;
        }
        else {
            if (!has_move[player]) {
                has_move[player] = true;
                p_with_move++;
            }
            char* s = mImpl->p[player]->get_move();
            char* tok = strtok(s, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &r_to)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &c_to)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &r_arrow)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            tok = strtok(NULL, " (),");
            if(tok == NULL || !sscanf(tok, "%i", &c_arrow)) {
                fprintf(stderr, "Invalid input format.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            free(s);
            if (!mImpl->make_move(player, r_to, c_to, r_arrow, c_arrow)) {
                fprintf(stderr, "Try again, must be a valid move.\n");
                print_instructions(mImpl->p[player]->get_out_stream());
            }
            else {
                move++;
            }
        }
    }
    winner = 0;
    free(has_move);
    while(!mImpl->can_move(winner))  {
        winner++;
    }
    if (mImpl->p_count == 2) {
        winner = move % 2;
    }
    winner++; // Adjust from index to count
    unlock_game();
    return winner;
}
示例#16
0
int main(const int argc, char *const argv[])
{
	unsigned int looppos = 0, loopcount = 1, samplerate = 32000;
	int size;
	double min_length = 0.0;
	bool gaussian_lowpass = false;

	int c;
	while ((c = getopt(argc, argv, "l:n:s:m:g")) != -1)
	{
		switch(c)
		{
			case 'l':
				looppos = atoi(optarg);
				break;

			case 'n':
				loopcount = atoi(optarg);
				break;

			case 's':
				samplerate = atoi(optarg);
				break;

			case 'm':
				min_length = atof(optarg);
				break;

			case 'g':
				gaussian_lowpass = true;
				break;

			default:
				printf("Invalid command line syntax !\n");
				print_instructions();
		}
	}

	if(argc - optind != 2) print_instructions();

	char *inbrr_path = argv[optind];
	char *outwav_path = argv[optind+1];
	// Try to open input BRR file
	FILE *inbrr = fopen(inbrr_path, "rb");
	if(!inbrr)
	{
		fprintf(stderr, "No such file : %s\n", inbrr_path);
		exit(1);
	}

	// Get the size of the input BRR file
	fseek(inbrr, 0L, SEEK_END);
	size = ftell(inbrr);
	fseek(inbrr, 0L, SEEK_SET);
	// Size should be an integer multiple of 9
	if(size%9 != 0)
	{
		fprintf(stderr, "Error : Size of BRR file %s isn't a multiple of 9 bytes.\n", inbrr_path);
		exit(1);
	}

	int blockamount = size/9;
	printf("Number of BRR blocks to decode : %d.\n", blockamount);

	if(looppos >= blockamount)  	//Make sure the loop position is in range
	{
		fprintf(stderr, "Error : Loop position is out of range\n");
		exit(1);
	}

	//Implement the "minimum length" function
	int min_len_samples = (int)ceil(min_length*samplerate/16.0);
	loopcount = MAX((signed)loopcount, (min_len_samples-(signed)looppos)/(blockamount-(signed)looppos));

	pcm_t olds0[loopcount];
	pcm_t olds1[loopcount];			//Tables to remember value of p1, p2 when looping

	//Create sample buffer
	unsigned int out_blocks = loopcount*(blockamount-looppos)+looppos;
	pcm_t *samples = safe_malloc(out_blocks * 32);

	fseek(inbrr, 0, SEEK_SET);				//Start to read at the beginning of the file
	pcm_t *buf_ptr = samples;

	for(int i=0; i<looppos; ++i) 		//Read the start of the sample before loop point
	{
		fread(BRR, 1, 9, inbrr);
		decodeBRR(buf_ptr);					//Append 16 BRR samples to existing array
		buf_ptr += 16;
	}
	for(int j=0; j<loopcount; ++j)
	{
		fseek(inbrr, looppos*9, SEEK_SET);
		for(int i=looppos; i<blockamount; ++i)
		{
			fread(BRR, 1, 9, inbrr);
			decodeBRR(buf_ptr);			//Append 16 BRR samples to existing array
			if(i == looppos)
			{							//Save the p1 and p2 values on each loop point encounter
				olds0[j] = buf_ptr[0];
				olds1[j] = buf_ptr[1];
			}
			buf_ptr += 16;
		}
	}

	if(loopcount > 1) print_note_info(blockamount - looppos, samplerate);
	print_loop_info(loopcount, olds0, olds1);
	fclose(inbrr);

	// Try to open output WAV file
	FILE *outwav = fopen(outwav_path, "wb");
	if(!outwav)
	{
		fprintf(stderr, "Can't open file %s for writing.\n", outwav_path);
		exit(1);
	}

	// Lowpass filter data to simulate real SNES hardware
	if(gaussian_lowpass) apply_gauss_filter(samples, out_blocks * 16);

	generate_wave_file(outwav, samplerate, samples, out_blocks);

	fclose(outwav);
	free(samples);
	printf("Done !\n");
	return 0;		// Exit without error
}
示例#17
0
int main(int argc, char **argv) {
    int c;

  puts ("\n\n\n\n\n\n\n\n\tCymon's Games\n\n\thttp://WWW.CYMONSGAMES.COM\n\n\n"
  "   WUMPUS and its code is a 2008 Cymon's Games game.\n"
  "   If you enjoy this game or you think you could do better please visit\n"
  "   http://WWW.CYMONSGAMES.COM for C/C++ programming resources and programs\n"
  "   for everyone, beginners and advanced users alike.\n\n"
  "   If programming is not for you stop by anyways for a free game every week.");
  printf ("\n\tPress ENTER to continue...\n\n\n\n\n\n");
  getchar();

    if (argc >= 2 && strcmp(argv[1], "-s") == 0)
        srand(atoi(argv[2]));
    else
        srand((int)time((long *) 0));
    c = getlet("Instructions (Y-N)");
    if (c == 'Y')
        print_instructions();
badlocs:
    for (j = 0; j < LOCS; j++)
        loc[j] = save[j] = FNA();
    for (j = 0; j < LOCS; j++)
        for (k = 0; k < LOCS; k++)
            if (j == k)
                continue;
            else if (loc[j] == loc[k])
                goto badlocs;
newgame:
    arrows = 5;
    scratchloc = loc[YOU];
    (void) puts("HUNT THE WUMPUS");
#ifdef DEBUG
    (void) printf("Wumpus is at %d, pits at %d & %d, bats at %d & %d\n",
                  loc[WUMPUS]+1,
                  loc[PIT1]+1, loc[PIT2]+1,
                  loc[BATS1]+1, loc[BATS2]+1);
#endif
nextmove:
    check_hazards();
    if (move_or_shoot()) {
        shoot();
        if (finished == NOT)
            goto nextmove;
    } else {
        move();
        if (finished == NOT)
            goto nextmove;
    }
    if (finished == LOSE) {
        (void) puts("HA HA HA - You lose!");
    } else {
        (void) puts("Hee hee hee - The wumpus'll get you next time!!");
    }
    for (j = YOU; j < LOCS; j++)
        loc[j] = save[j];
    c = getlet("Same setup (Y-N)");
    if (c != 'Y')
        goto badlocs;
    else
        goto newgame;
}
示例#18
0
board start_editor() {
  int h = get_dim("enter height: ");
  clear();
  int w = get_dim("enter width: ");
  curs_set(1);
  noecho();
  cbreak();
  move(20,20);
  int x = 0;
  int x_1 = 0;
  int y = 0;
  board b = init_board(h, w);
  int key;
  print_board(0, 0, b);
  print_instructions();
  move(y,x);
  while((key = getch()) != 113) { // wait until user hits q
    print_board(0, 0, b);
    print_instructions();
    move(y,x);
    if(key == 10) { // enter key
      toggle_alive(b,y,x_1);
      print_board(0,0,b);
      print_instructions();
      y++;
      move(y,x);
      refresh();
    }
    if(key == 32) { // space bar
      toggle_alive(b,y,x_1);
      print_board(0,0,b);
      print_instructions();
      x+=2;
      x_1++;
      move(y,x);
      refresh();
    }
    if(key == 260 && x_1 > 0) { // left arrow key
      x-=2;
      x_1--;
      move(y,x);
    }
    if(key == 261 && x_1 < w-1) { // right arrow key
      x+=2;
      x_1++;
      move(y,x);
    }
    if(key == 259 && y > 0) { // up arrow key
      y-=1;
      move(y,x);
    }
    if(key == 258 && y < h-1) { // down arrow key
      y+=1;
      move(y,x);
    }
    if(key == 544) { // control left
      board newboard = change_board_size(b, -1, 0);
      free_board(b);
      b = newboard;
      w--;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 559) {
      board newboard = change_board_size(b, 1, 0);
      free_board(b);
      b = newboard;
      w++;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 565) { // control up
      board newboard = change_board_size(b, 0, -1);
      free_board(b);
      b = newboard;
      h--;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    if(key == 524) { // control down
      board newboard = change_board_size(b, 0, 1);
      free_board(b);
      b = newboard;
      h++;
      print_board(0,0,b);
      print_instructions();
      move(y,x);
      refresh();
    }
    refresh();
  }
  curs_set(0);
  clear();
  return b;
}
示例#19
0
int main(int argc, char *argv[] )
{
	char archive[1024];
	char *p;

	if ( argc < 3 )	{
#ifndef PLAT_UNIX
		printf( "Usage: %s archive_name src_dir\n", argv[0] );
		printf( "Example: %s freespace c:\\freespace\\data\n", argv[0] );
		printf( "Creates an archive named freespace out of the\nfreespace data tree\n" );
		printf( "Press any key to exit...\n" );
		getch();
		return 1;
#else
		print_instructions();
#endif
	}

	strcpy( archive, argv[1] );
	p = strchr( archive, '.' );
	if (p) *p = 0;		// remove extension	

	strcpy( archive_dat, archive );
	strcat( archive_dat, ".vp" );

	strcpy( archive_hdr, archive );
	strcat( archive_hdr, ".hdr" );

	fp_out = fopen( archive_dat, "wb" );
	if ( !fp_out )	{
		printf( "Couldn't open '%s'!\n", archive_dat );
#ifndef PLAT_UNIX
		printf( "Press any key to exit...\n" );
		getch();
		return 1;
#else
		exit(1);
#endif
	}

	fp_out_hdr = fopen( archive_hdr, "wb" );
	if ( !fp_out_hdr )	{
		printf( "Couldn't open '%s'!\n", archive_hdr );
#ifndef PLAT_UNIX
		printf( "Press any key to exit...\n" );
		getch();
		return 1;
#else
		exit(2);
#endif
	}

	if ( verify_directory( argv[2] ) != 0 ) {
		printf("Warning! Last directory must be named \"data\" (not case sensitive)\n");
		exit(3);
	}

	write_header();

	pack_directory( argv[2] );

	// in case the directory doesn't exist
	if ( no_dir )
		exit(4);

	write_header();

	fclose(fp_out);
	fclose(fp_out_hdr);

	printf( "Data files written, appending index...\n" );

	if (!write_index(archive_hdr, archive_dat)) {
		printf("Error appending index!\n");
#ifndef PLAT_UNIX
		printf("Press any key to exit...\n");
		getch();
#endif
		return 1;
	}
	
	printf( "%d total KB.\n", Total_size/1024 );
	return 0;
}
示例#20
0
文件: codegen.c 项目: Neodyblue/a2c
void print_instruction(struct instruction *i, int indent)
{
  switch (i->kind)
  {
    case assignment:
      print_indent(indent);
      print_assignment(i->instr.assignment);
      printf(";\n");
      break;
    case whiledo:
      print_indent(indent);
      printf("while (");
      print_expression(i->instr.whiledo->cond);
      printf(")\n");
      print_indent(indent);
      printf("{\n");
      print_instructions(i->instr.whiledo->instructions, indent + INDENT_WIDTH);
      print_indent(indent);
      printf("}\n");
      break;
    case dowhile:
      print_indent(indent);
      printf("do\n");
      print_indent(indent);
      printf("{\n");
      print_instructions(i->instr.dowhile->instructions, indent + INDENT_WIDTH);
      print_indent(indent);
      printf("} while (");
      print_expression(i->instr.dowhile->cond);
      printf(");\n");
      break;
    case forloop:
      print_indent(indent);
      printf("for (");
      print_assignment(i->instr.forloop->assignment);
      printf("; ");
      print_expression(i->instr.forloop->assignment->e1);
      if (i->instr.forloop->decreasing)
        printf(" >= ");
      else
        printf(" <= ");
      print_expression(i->instr.forloop->upto);
      if (i->instr.forloop->decreasing)
        printf("; --(");
      else
        printf("; ++(");
      print_expression(i->instr.forloop->assignment->e1);
      printf("))\n");
      print_indent(indent);
      printf("{\n");
      print_instructions(i->instr.forloop->instructions, indent + INDENT_WIDTH);
      print_indent(indent);
      printf("}\n");
      break;
    case funcall:
      print_funcall(i->instr.funcall, indent);
      break;
    case ifthenelse:
      print_indent(indent);
      printf("if (");
      print_expression(i->instr.ifthenelse->cond);
      printf(")\n");
      print_indent(indent);
      printf("{\n");
      print_instructions(i->instr.ifthenelse->instructions, indent + INDENT_WIDTH);
      print_indent(indent);
      printf("}\n");
      if (i->instr.ifthenelse->elseblock.size > 0)
      {
        print_indent(indent);
        printf("else\n");
        print_indent(indent);
        printf("{\n");
        print_instructions(i->instr.ifthenelse->elseblock, indent + INDENT_WIDTH);
        print_indent(indent);
        printf("}\n");
      }
      break;
    case returnstmt:
      print_indent(indent);
      printf("return ");
      if (i->instr.returnstmt->expr)
        print_expression(i->instr.returnstmt->expr);
      printf(";\n");
      break;
    default:
      printf("instruction not handled yet\n");
    case switchcase:
      print_indent(indent);
      printf("switch (");
      print_expression(i->instr.switchcase->cond);
      printf(")\n");
      print_indent(indent);
      printf("{\n");
      print_caselist(i->instr.switchcase->caseblocklist, indent+ INDENT_WIDTH);
      if(i->instr.switchcase->otherwiseblock.size > 0)
      {
        print_indent(indent + INDENT_WIDTH);
        printf("default:\n");
        print_instructions(i->instr.switchcase->otherwiseblock, indent + 2 * INDENT_WIDTH);
        print_indent(indent + 2 * INDENT_WIDTH);
        printf("break;\n");
      }
      print_indent(indent);
      printf("}\n");
      break;
  }
}
示例#21
0
文件: crc_rev.c 项目: lgeek/crc_rev
int main(int argc, char **argv) {
  long int bitwidth, no_of_files;
  uint8_t **input;
  off_t *input_size;
  uint32_t *crcs;
  int fd;
  char *fname;
  struct stat fs;

  if (argc < 6 || (argc % 2) == 1) {
    print_instructions();
  }
  
  bitwidth = strtol(argv[1], NULL, 0);
  switch(bitwidth) {
    case 16:
      break;
    default:
      fprintf(stderr, "Unsupported width\n");
      print_instructions();
  }
  
  no_of_files = (argc - 2) / 2;
  input = malloc(sizeof(uint8_t*) * no_of_files);
  if (input == NULL) {
    fprintf(stderr, "Failed to allocate memory\n");
  }
  crcs = malloc(sizeof(uint32_t) * no_of_files);
  if (crcs == NULL) {
    fprintf(stderr, "Failed to allocate memory\n");
  }
  input_size = malloc(sizeof(off_t) * no_of_files);
  if (input_size == NULL) {
    fprintf(stderr, "Failed to allocate memory\n");
  }
  
  for (int i = 0; i < no_of_files; i++) {
    fname = argv[2 + i *2];

    crcs[i] = strtol(argv[3 + i *2], NULL, 0);
    printf("CRC for file %s: 0x%x\n", fname, crcs[i]);
  
    fd = open(fname, O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "Failed to open file: %s\n", fname);
      exit(EXIT_FAILURE);
    }
    fstat(fd, &fs);
    
    input[i] = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (input[i] == MAP_FAILED) {
      fprintf(stderr, "Failed to map file: %s\n", fname);
      exit(EXIT_FAILURE);
    }
    input_size[i] = fs.st_size;
  }
  
  init_reverse_lookup_table();

  find_poly_16(no_of_files, input, input_size, crcs);

  return EXIT_SUCCESS;
}
示例#22
0
int main(int argc, char *argv[])
{
	switch (argc) {
	case 2:
		encrypt_init();
		if ( !stricmp("-u", argv[1]) || !stricmp("-i", argv[1]) || !stricmp("-st", argv[1]) ||
				!stricmp("-wt", argv[1]) || !stricmp("-fs1", argv[1]) || !stricmp("-8bit", argv[1]) ) {
			print_instructions();
		} else {
			scramble_file(argv[1]);
		}
		break;

	case 3:
		encrypt_init();
		if ( !stricmp("-u", argv[1]) ) {
			unscramble_file(argv[2]);
		} else if ( !stricmp("-i", argv[1]) ) {
			scramble_identify(argv[2]);
		} else if ( !stricmp("-st", argv[1]) ) {
			Use_8bit = 0;
			fs2 = false;
			scramble_file(argv[2], argv[2], PREPROCESS_SHIPS_TBL);
		} else if ( !stricmp("-wt", argv[1]) ) {
			Use_8bit = 0;
			fs2 =false;
			scramble_file(argv[2], argv[2], PREPROCESS_WEAPONS_TBL);
		} else if ( !stricmp("-fs1", argv[1]) ) {
			Use_8bit = 0;
			fs2 = false;
			scramble_file(argv[2], argv[2]);
		} else if ( !stricmp("-8bit", argv[1]) ) {
			Use_8bit = 1;
			fs2 = false;
			scramble_file(argv[2], argv[2]);
		} else {
			scramble_file(argv[1], argv[2]);
		}
		break;

	case 4:
		encrypt_init();
		if ( !stricmp("-u", argv[1]) ) {
			unscramble_file(argv[2], argv[3]);
		} else if ( !stricmp("-st", argv[1]) ) {
			Use_8bit = 0;
			fs2 = false;
			scramble_file(argv[2], argv[3], PREPROCESS_SHIPS_TBL);
		} else if ( !stricmp("-wt", argv[1]) ) {
			Use_8bit = 0;
			fs2 = false;
			scramble_file(argv[2], argv[3], PREPROCESS_WEAPONS_TBL);
		} else if ( !stricmp("-fs1", argv[1]) ) {
			Use_8bit = 0;
			fs2 = false;
			scramble_file(argv[2], argv[3]);
		} else if ( !stricmp("-8bit", argv[1]) ) {
			Use_8bit = 1;
			fs2 = false;
			scramble_file(argv[2], argv[3]);
		} else {
			print_instructions();
		}
		break;

	default:
		print_instructions();
		return 1;
	}
}
示例#23
0
int print_ilm(const struct nlmsghdr *n, void *arg, struct rtattr **tb)
{
	FILE *fp = (FILE*)arg;
	struct mpls_in_label_req *mil;
	struct mpls_instr_req *instr;
	struct gnet_stats_basic *stats;
        struct genlmsghdr *ghdr = NLMSG_DATA(n);

	if ((ghdr->cmd != MPLS_CMD_NEWILM &&
	    ghdr->cmd != MPLS_CMD_DELILM) ||
	    (!tb[MPLS_ATTR_ILM])) {
		fprintf(stderr, "Not an ILM\n");
		sprintf(mpls_table,"%s","Not an ILM\r\n");//add by here
		return -1;
	}

	if (ghdr->cmd == MPLS_CMD_DELILM){
		fprintf(fp, "deleted ILM entry ");
		sprintf(mpls_table,"%s%s",mpls_table,"deleted ILM entry ");//add by here
	}
	
	if (ghdr->cmd == MPLS_CMD_NEWILM){
		fprintf(fp, "ILM entry ");
		sprintf(mpls_table,"%s%s",mpls_table,"ILM entry ");//add by here
	}
	
	mil = RTA_DATA(tb[MPLS_ATTR_ILM]);
	instr = RTA_DATA(tb[MPLS_ATTR_INSTR]);
	stats = RTA_DATA(tb[MPLS_ATTR_STATS]);

	fprintf(fp, "label ");
	print_label(fp, &mil->mil_label);

	fprintf(fp, "labelspace %d ", mil->mil_label.ml_index);
	/* add by here to get ilm table to vty_out*/
	sprintf(mpls_table,"%s%s%s labelspace %d ",mpls_table,
	"label ",print_label_buf,mil->mil_label.ml_index);//add by here
	/*end by here */

	switch(mil->mil_proto) {
		case AF_INET:
			fprintf(fp, "proto ipv4 ");
			sprintf(mpls_table,"%s%s",mpls_table,"proto ipv4 ");
			break;
		case AF_INET6:
			fprintf(fp, "proto ipv6 ");
			sprintf(mpls_table,"%s%s",mpls_table,"proto ipv6 ");
			break;
		case AF_PACKET:
			fprintf(fp, "proto packet ");
			sprintf(mpls_table,"%s%s",mpls_table,"proto packet ");
			break;
		default:
			fprintf(fp, "<unknown proto %d> ", mil->mil_proto);
			sprintf(mpls_table,"%s <unknown proto %d> ",mpls_table, mil->mil_proto);
	}

	fprintf(fp, "\n\t");
	sprintf(mpls_table,"%s\r\n\t",mpls_table);
	if (instr && instr->mir_instr_length) {
		print_instructions(fp, instr);
		sprintf(mpls_table,"%s%s",mpls_table,print_instructions_buf);
		flush_print_instructions_buf();
	}

	if (stats)
		print_mpls_stats(fp, stats);

	fprintf(fp, "\n");
	fflush(fp);
	sprintf(mpls_table,"%s%s \r\n",mpls_table,print_mpls_stats_buf);
	
	return 0;
}
示例#24
0
文件: main.c 项目: geraldstanje/luci
/**
 * Main entry point to the Luci compiler/interpreter
 *
 * @param argc number of command-line arguments
 * @param argv C-string array of command-line arguments
 * @returns 1 on error, 0 on success
 */
int luci_main(int argc, char *argv[])
{
#ifdef DEBUG
    yydebug = 1;
#endif

    if (argc < 2) {
        /* interactive mode */
	yyin = stdin;
        return luci_interactive();
    }

    unsigned int mode = MODE_EXE;

    char *arg;
    char *infilename = NULL;
    unsigned int i;
    for (i = 1; i < argc; i++) {
        arg = argv[i];
        if (strcmp(arg, "-h") == 0) {
            help();
            return EXIT_SUCCESS;
        } else if (strcmp(arg, "-V") == 0) {
            fprintf(stdout, "%s\n", version_string);
            return EXIT_SUCCESS;
        } else if (strcmp(arg, "-g") == 0) {
            mode = MODE_GRAPH;
        } else if (strcmp(arg, "-p") == 0) {
            mode = MODE_PRINT;
        } else if (strcmp(arg, "-c") == 0) {
            mode = MODE_SERIAL;
            printf("%s\n", "This option is not yet supported");
            return EXIT_SUCCESS;
        } else if (strcmp(arg, "-n") == 0) {
            mode = MODE_SYNTAX;
        } else if (i == (argc - 1)) {
            infilename = arg;
        } else {
            LUCI_DIE("Invalid option: %s\n", arg);
        }
    }

    if (infilename == NULL) {
        /* interactive mode */
        yyin = stdin;
        return luci_interactive();
    } else if (!(yyin = fopen(infilename, "r"))) {
        LUCI_DIE("Can't read from file %s\n", infilename);
    }
    LUCI_DEBUG("Reading from %s\n", infilename? infilename : "stdin");

    /* initialize the scanner in non-interactive mode */
    yy_luci_init(false);

    /* parse yyin and build and AST */
    yyparse();
    extern AstNode* g_root_node;    /* parser.y */
    if (!g_root_node) {
        /* empty program */
        return EXIT_SUCCESS;
    } else if (mode == MODE_SYNTAX) {
        printf("%s\n", "Syntax valid");
        return EXIT_SUCCESS;
    } else if (mode == MODE_GRAPH) {
        print_ast_graph(g_root_node);
        return EXIT_SUCCESS;
    }

    /* initialize systems */
    gc_init();
    compiler_init();

    /* Compile the AST */
    CompileState *cs = compile_ast(g_root_node);

    ast_destroy(g_root_node);

    LuciObject *gf = LuciFunction_new();
    convert_to_function(cs, gf, 0);

    compile_state_delete(cs);

    if (setjmp(LUCI_EXCEPTION_BUF) == 0) {
        switch (mode) {
            case MODE_EXE:
                /* Execute the bytecode */
                eval(gf);
                break;
            case MODE_PRINT:
                /* Print the bytecode */
                print_instructions(gf);
                break;
            case MODE_SERIAL:
                /* Serialize program */
                serialize_program(gf);
                break;
            default:
                LUCI_DIE("%s\n", "Invalid mode?!");
        }
    }

    /* cleanup systems */
    compiler_finalize();
    gc_finalize();

    return EXIT_SUCCESS;
}