예제 #1
0
파일: main.c 프로젝트: drwebb/ncdu
/* main program */
int main(int argc, char **argv) {
  char *dir;

  setlocale(LC_ALL, "");

  if((dir = argv_parse(argc, argv)) == NULL)
    dir = ".";

  calc_init(dir, NULL);

  initscr();
  cbreak();
  noecho();
  curs_set(0);
  keypad(stdscr, TRUE);
  if(ncresize(min_rows, min_cols))
    min_rows = min_cols = 0;

  while(1) {
    if(pstate == ST_CALC && calc_process())
      break;
    else if(pstate == ST_DEL)
      delete_process();
    else if(input_handle(0))
      break;
  }

  erase();
  refresh();
  endwin();
  exclude_clear();

  return 0;
}
예제 #2
0
파일: test.c 프로젝트: Shimejing/demo_class
int main(int argc, char *argv[])
{
	if (argc < 2) {
		fprintf(stderr, "miss args\n");
		usage(argv[0]);
		exit(1);
	}
	
	struct calc_info  *q =  (struct calc_info *)malloc(sizeof(*q));

	if (q == NULL) {
		perror("malloc");
		goto err_malloc;
	}

	calc_init(q);
	num_t ret = 0;

	int i;
	for (i = 1; i < argc; ++i) {
		ret = q->calc(q, argv[i]);
		printf("\n---%s = %d----\n", argv[i], ret);
	}

	calc_destroy(q);
	free(q);

	return 0;
err_malloc:
	return -1;
}
예제 #3
0
파일: main.c 프로젝트: sktwj/var
int main(int argc, char *argv[])
{
	struct calc *this = NULL;
	//const char *default_expr = \
		"(--1 ++2 + +-3 * (1 + 1)) * 2";
	const char *default_expr = "1 -+- 2";

	if (argc == 1) {
		this = calc_init(this, default_expr);	
		printf("%s = %d\n", default_expr, this->analyze(this, default_expr));	
	} else if (argc == 2) {
		this = calc_init(this, argv[1]);
		printf("%s = %d\n", argv[1], this->analyze(this, argv[1]));	
	} else {
		printf("sorry, 最多只能传递一个参数!\n使用方法:可执行文件 要进行运算的表达式\n");
		return 1;
	}

	calc_destroy(this);

	return 0;
}
예제 #4
0
void get_RPN ( char *input )
{
  int length = strlen( input );
  int i=0;
  int sp=0;

  calc_init();

  for( i = 0; i < length; i++  ) {
    if( check_operator_and_convert_number( input[i] ) == TRUE ) {

      if( input[i] == ')' ){
	/* 最初の括弧まで計算。 */
	pop_stack( &sp, input[i] );
      }
      else if( input[i] == '(' ){
	stack_buf[sp++] = input[i];
      }
      else{
	if( sp == 0 ){
	  stack_buf[sp++] = input[i];
	}
	else{
	  priority_type cur_sign   =  check_priority( input[i] );
	  priority_type stack_sign =  check_priority( stack_buf[sp-1] );

	  /* 演算子の優先度を確認 */
	  /* "*", "/" の場合は、スタックに追加 */
	  if( cur_sign > stack_sign ){
	    stack_buf[sp++] = input[i];
	  }
	  else{
	    pop_stack( &sp, input[i] );
	    stack_buf[sp++] = input[i];
	  }
	}
      }
    }
  }


  /* 最終の文字が ')' でなければ、数値の変換が必要。 */
  if( input[ length-1 ] != ')' ){
    result_buf[result_index++] = atof( &temp_val[0] );
  }

  pop_stack( &sp, 0 );

  return;
}
예제 #5
0
int main(int argc, char *argv[])
{
	assert(argc >= 2);
	
	struct calc_info *pcalc = (struct calc_info *)
		malloc(sizeof(*pcalc));
	assert(pcalc != NULL);

	calc_init(pcalc);

	printf("%s = %d\n", argv[1], 
		pcalc->parser(pcalc, argv[1]));

	calc_destroy(pcalc);
	free(pcalc);
	
	return 0;
}
예제 #6
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();

	/** GPIO Register set */
	volatile unsigned int *gpio = led_init();

	/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
    //gpio = (unsigned int*)GPIO_BASE;

    /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO
       peripheral register to enable GPIO16 as an output */
    //gpio[LED_GPFSEL] |= (1 << LED_GPFBIT);

	(void) r0;
	(void) r1;
	(void) atags;
 
	uart_init();
	uart_puts("> Hello, World!\r\n");

	int str_len = 80;
	char stringin[str_len];
	int i=0;
	uart_puts("> ");

	int x = 0;
	int *calc = &x;

	while (true){
		//art_puts("hello");
		//led_blink(gpio, .25);
		char x = uart_getc();
		//Checks if current str is being written outside size allotment
		if (i > str_len-1){
			uart_puts(stringin);
			reset_string(stringin, i);
		
			uart_puts("Max string len reached\r\n");
			i = 0;
		}
		// if enter is pressed
		else if (x == '\r')
		{
			uart_puts("\r\n");

			if (memcmp(stringin, "calc", sizeof("calc")) == 0) {
				uart_puts("CALC RECOGNIZED!\r\n");
				calc_init();
				*calc = 1;
			}
			if (memcmp(stringin, "blink", sizeof("blink")) == 0) {
				uart_puts("LEDDDDDD!\r\n");
				led_blink(gpio, 1);
			}
			if (memcmp(stringin, "stop", sizeof("stop")) == 0) {
				uart_puts("LEDDDDDD STOP!\r\n");
				led_blink(gpio, 0);
			}
			else{
				uart_puts(stringin);
				uart_puts("\n");
				// char str[16];
				// int c = -146;
				// uart_puts(itos(c, str));
			}
			
			reset_string(stringin, i);
			uart_puts("> ");
			i = 0;
		}
		else if (x == 127 || x == 8) // backspace character
		{
			if (i>0)
			{
				uart_putc('\b'); // move cursor back
				uart_putc(' '); // insert space in terminal
				uart_putc('\b'); // move cursor back before space
				stringin[i-1] = 0x00; // replace last char with empty
				i--; // decrement length
			}
		}
		else{
			stringin[i] = x;
			uart_putc(stringin[i]);
			i++;
		}

	}

}