Example #1
0
void main(void)
{
   int p;
   puts("\rStarting, should delay for 10 seconds\r");
   EF_Timer_Init(EF_Timer_RATE_8MS);
   EF_Timer_InitTimer(0, TIME_OUT_DELAY); /* TIME_OUT_DELAY  = 10s w/ 8.19mS interval */
   EF_Timer_InitTimer(1, TIME_OUT_DELAY);
   EF_Timer_InitTimer(2, TIME_OUT_DELAY);
   EF_Timer_InitTimer(3, TIME_OUT_DELAY);
   EF_Timer_InitTimer(4, TIME_OUT_DELAY);
   EF_Timer_InitTimer(5, TIME_OUT_DELAY);
   EF_Timer_InitTimer(6, TIME_OUT_DELAY);
   EF_Timer_InitTimer(7, TIME_OUT_DELAY);
   while(EF_Timer_IsTimerExpired(0) != EF_Timer_EXPIRED)
      ;
   puts("Timed Out\r");

   EF_Timer_InitTimer(7, TIME_OUT_DELAY);
   for (p=0;p<10000;p++ ); /* kill some time */
   EF_Timer_StopTimer(7);
   if (EF_Timer_IsTimerActive(7) != EF_Timer_NOT_ACTIVE)
      puts("Timer Stop Failed\r");
   else
      puts("Timer Stop Succeded, restarting timeout\r");
   EF_Timer_StartTimer(7);
   while(EF_Timer_IsTimerExpired(7) != EF_Timer_EXPIRED)
      ;

   puts("Timed Out Again\r");

   DisableInterrupts;
}
Example #2
0
static void *
tf_for (void *arg)
{
  long cnt;
  char number[160];
  sprintf(number, "tf_for(%ld): begin", (long)arg);
  puts (number);
  
  sas_spin_lock_with_yield(&t_lock);
  sas_spin_unlock(&t_lock);
  
  for (cnt=sas_atomic_inc_long(&atomic_cnt); cnt<20; cnt=sas_atomic_inc_long(&atomic_cnt))
  {
    sprintf(number, "tf_for(%ld): sas_atomic_inc_long(%p)=%ld",
    		(long)arg, &atomic_cnt, cnt);
    puts (number);
  
    sleep(1);
  }

  sprintf(number, "tf_for(%ld): end", (long)arg);
  puts (number);
  
  return NULL;
}
void test_board_san() {
    puts("test_board_san");
    board_t pos;
    char san[LEN_SAN];

    // Double pawn move.
    board_reset(&pos);
    board_san(&pos, move_make(SQ_H2, SQ_H4, kNone), san);
    assert(strcmp(san, "h4") == 0);

    // Promotion.
    assert(board_set_fen(&pos, "4k3/8/8/8/8/8/6p1/4K3 b - - 0 1"));
    board_san(&pos, move_make(SQ_G2, SQ_G1, kRook), san);
    assert(strcmp(san, "g1=R+") == 0);

    // Not ambiguous because of pin.
    assert(board_set_fen(&pos, "4k3/8/8/b7/8/2N3N1/8/4K3 w - - 0 1"));
    board_san(&pos, move_make(SQ_G3, SQ_E4, 0), san);
    puts(san);
    assert(strcmp(san, "Ne4") == 0);

    // Ambiguous.
    board_remove_piece_at(&pos, SQ_A5);
    board_san(&pos, move_make(SQ_G3, SQ_E4, 0), san);
    assert(strcmp(san, "Nge4") == 0);
}
int add(){
	struct flower *newflower = NULL ;
	char *buf = NULL ;
	unsigned size =0;
	unsigned index ;
	if(flowercount < 100){
		newflower = malloc(sizeof(struct flower));
		memset(newflower,0,sizeof(struct flower));
		printf("Length of the name :");
		if(scanf("%u",&size)== EOF) exit(-1);
		buf = (char*)malloc(size);
		if(!buf){
			puts("Alloca error !!");
			exit(-1);
		}
		printf("The name of flower :");
		read(0,buf,size);
		newflower->name = buf ;
		printf("The color of the flower :");
		scanf("%23s",newflower->color);
		newflower->vaild = 1 ;
		for(index = 0 ; index < 100 ; index++ ){
			if(!flowerlist[index]){
				flowerlist[index] = newflower ;
				break ;
			}
		}
		flowercount++ ;
		puts("Successful !");
	}else{
		puts("The garden is overflow");
	}
}
Example #5
0
int main(int argc, const char *argv[])
{
	char *path="start_build:xxxxx";
	char str2[] = "start_build:123;abcdefghidk";
	printf("size:%d\n",(int)sizeof("start_build:"));
	//if(strncmp("start_build:",path,sizeof("start_build:")-1) == 0){
	if(strcase("start_build:",path) == 0){
		puts("ok");
	}else{
		puts("no");
	}
	//int fd=0;
	//fd = atoi(str2+12);
	//printf("fd:%d\n",fd);

	char * tmpbuff = str2 + 12;

	while (*tmpbuff != ';' && *tmpbuff != '\0' ){
		putchar(*tmpbuff);
		tmpbuff++;
	}
	puts("\n----------");
	puts(++tmpbuff);
	


	return 0;
}
Example #6
0
static int adc_power_control(int on)
{
	struct udevice *dev;
	int ret;
	u8 reg;

	ret = pmic_get("max8998-pmic", &dev);
	if (ret) {
		puts("Failed to get MAX8998!\n");
		return ret;
	}

	reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
	if (on)
		reg |= MAX8998_LDO4;
	else
		reg &= ~MAX8998_LDO4;

	ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
	if (ret) {
		puts("MAX8998 LDO setting error\n");
		return -EINVAL;
	}

	return 0;
}
Example #7
0
File: qsnd.c Project: Og192/CPro
int main(int argc,char **argv)
{
	int qid;
	int len;
	key_t key;
	key = 113;
	struct msg pmsg;

	if( (qid = msgget(key,IPC_CREAT | 0666)) < 0){
		perror("msgget");
		exit(EXIT_FAILURE);
	}

	printf("Enter message to post <%d>:\n",qid);
	if( (fgets((&pmsg)->msg_text,BUFSZ,stdin)) == NULL){
		puts("no message to post");
		exit(EXIT_SUCCESS);
	}

	pmsg.msg_type = getpid();

	len = strlen(pmsg.msg_text);
	if( (msgsnd(qid,&pmsg,len,0)) < 0){
		perror("msgsnd");
		exit(EXIT_FAILURE);
	}

	puts("message poeted");
	exit(EXIT_SUCCESS);
}
Example #8
0
File: main.c Project: A-Paul/RIOT
/* Test 1: Add temperature and humidity */
static void test01(lora_serialization_t *serialization)
{
    puts("Test 1");
    puts("Temperature and humidity");
    puts("---------------------------------");
    lora_serialization_reset(serialization); // Always reset

    puts("- Writing temperature: 80.12");
    lora_serialization_write_temperature(serialization, 80.12);

    puts("- Writing humidity: 99.99");
    lora_serialization_write_humidity(serialization, 99.99);

    printf("- Encoded: ");
    print_buffer(serialization->buffer,
                 LORA_SERIALIZATION_TEMPERATURE_SIZE +
                 LORA_SERIALIZATION_HUMIDITY_SIZE);
    puts("");

    printf("- Expected:");
    print_buffer(test01Expected, sizeof(test01Expected));
    puts("");
    puts("---------------------------------");

    if (memcmp(serialization->buffer, test01Expected,
               sizeof(test01Expected)) != 0) {
        puts("FAILED");
    }
    else {
        puts("SUCCESS");
    }
}
Example #9
0
File: main.c Project: A-Paul/RIOT
/* Test 2: Add GPS coordinates and unix time */
static void test02(lora_serialization_t *serialization)
{
    puts("Test 2");
    puts("Coordinates and unix time");
    puts("---------------------------------");
    lora_serialization_reset(serialization); // Always reset

    puts("- Writing coordinates: -33.905052, 151.26641");
    lora_serialization_write_coordinates(serialization, -33.905052, 151.26641);

    puts("- Writing unix time: 1467632413");
    lora_serialization_write_unix_time(serialization, 1467632413);

    printf("- Encoded: ");
    print_buffer(serialization->buffer,
                 LORA_SERIALIZATION_GPS_SIZE +
                 LORA_SERIALIZATION_UNIX_TIME_SIZE);
    puts("");

    printf("- Expected:");
    print_buffer(test02Expected, sizeof(test02Expected));
    puts("");
    puts("---------------------------------");

    if (memcmp(serialization->buffer, test02Expected,
               sizeof(test02Expected)) != 0) {
        puts("FAILED");
    }
    else {
        puts("SUCCESS");
    }
}
Example #10
0
int create_client(string ip, int port)
{
    int socket_desc;
    struct sockaddr_in server;

    //Create socket
    socket_desc = socket(AF_INET , SOCK_STREAM , 0);
    if (socket_desc == -1)
    {
        printf("create_client::Could not create socket");
    }

    server.sin_addr.s_addr = inet_addr(ip.c_str());
    server.sin_family = AF_INET;
    server.sin_port = htons( port );

    //Connect to remote server
    if (connect(socket_desc , (struct sockaddr *)&server , sizeof(server)) < 0)
    {
        puts("create_client::connect error");
        return -1;
    }

    puts("Connected\n");
    return socket_desc;
}
int main (int argc, char *argv[])
{
    GfrEntry *currGE;
    int count;
    int countRemoved;

    if (argc != 2) {
        usage ("%s <string>",argv[0]);
    }
    count = 0;
    countRemoved = 0;
    gfr_init ("-");
    puts (gfr_writeHeader ());
    while (currGE = gfr_nextEntry ()) {
        if (currGE->descriptionTranscript1 == NULL ||
                currGE->descriptionTranscript2 == NULL) {
            die ("Transcript description is missing");
        }
        if (strCaseStr (currGE->descriptionTranscript1,argv[1]) ||
                strCaseStr (currGE->descriptionTranscript2,argv[1])) {
            countRemoved++;
            continue;
        }
        puts (gfr_writeGfrEntry (currGE));
        count++;
    }
    gfr_deInit ();
    warn ("%s_string: %s",argv[0],argv[1]);
    warn ("%s_numRemoved: %d",argv[0],countRemoved);
    warn ("%s_numGfrEntries: %d",argv[0],count);
    return 0;
}
Example #12
0
// READ
void readdigit(unsigned int* iChr, const char* comment)
{
  char cChr[3];
  do{
    // reset
    memset(cChr, '\0', 3);
    puts(comment);

    // read
    fgets(cChr, 3, stdin);

    // check stdin and clean in case input exceeded the
    if('\n' == cChr[1]){
      // ok - do nothing here

    }else if(('\n' == cChr[0]) || ('\n' == cChr[2])){
      // number too long or input empty - erease
      memset(cChr, '\0', 3);

    }else{
      // '\n' still in stdin - clean up
      puts("input too long - will reset");
      memset(cChr, '\0', 3);
      while('\n' != fgetc(stdin));
    }

    // CAUTION: due to '\n' checking the set of '\0' here!
    cChr[2] = '\0';

    // number?
  }while(!isdigit(cChr[0]));

  // transform
  *iChr = atoi(cChr);
}
Example #13
0
/**
 * [TcbState :print current tcb state]
 */
void TcbState()
{
	int id;
    printf("\n ----- Current Thread Process -------\n");
    for(id = 0; id < MAX_TCB_NUM; id++)
    {
        printf("Thread %d %9s State is ", id, tcbs[id].name);
        switch(tcbs[id].state)
        {
            case FINISHED: 
            	puts("FINISHED"); 
            	break;
            case RUNNING: 
            	puts("RUNNING"); 
            	break;
            case READY: 
            	puts("READY");
            	break;
            case BLOCKED:
            	puts("BLOCKED"); 
            	break;
        }
    }

}
Example #14
0
int main(void)
{
    int idx = 0, count = 0;
    char ch, str[SIZE];

    puts("Enter a string(less than 100 charactors and ended in '#'): ");

    while((ch = getchar()) != '#')
    {
        if(ch == '.')
        {
            ch = '!';
            count++;
        }
        
        str[idx] = ch;
        idx++;
    }

    str[idx] = '\0';

    puts(str);
    printf("Replace times: %d\n", count);

    return 0;
}
Example #15
0
int main( int argc, char **argv )
{
  uint8_t key[BLAKE2B_KEYBYTES];
  uint8_t buf[KAT_LENGTH];

  for( size_t i = 0; i < BLAKE2B_KEYBYTES; ++i )
    key[i] = ( uint8_t )i;

  for( size_t i = 0; i < KAT_LENGTH; ++i )
    buf[i] = ( uint8_t )i;

  for( size_t i = 0; i < KAT_LENGTH; ++i )
  {
    uint8_t hash[BLAKE2B_OUTBYTES];
    blake2b( hash, buf, key, BLAKE2B_OUTBYTES, i, BLAKE2B_KEYBYTES );

    if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
    {
      puts( "error" );
      return -1;
    }
  }

  puts( "ok" );
  return 0;
}
Example #16
0
static void usage_gui(void)
{
	puts("usage: stoken-gui [ <options> ]");
	puts("");
	usage_common();
	exit(1);
}
Example #17
0
void exynos_lcd_power_on(void)
{
	struct udevice *dev;
	int ret;
	u8 reg;

	ret = pmic_get("max8998-pmic", &dev);
	if (ret) {
		puts("Failed to get MAX8998!\n");
		return;
	}

	reg = pmic_reg_read(dev, MAX8998_REG_ONOFF3);
	reg |= MAX8998_LDO17;
	ret = pmic_reg_write(dev, MAX8998_REG_ONOFF3, reg);
	if (ret) {
		puts("MAX8998 LDO setting error\n");
		return;
	}

	reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
	reg |= MAX8998_LDO7;
	ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
	if (ret) {
		puts("MAX8998 LDO setting error\n");
		return;
	}
}
Example #18
0
int main(int argc, char* argv[]) {
	
	errno_t err;
    char str[50]; 
    FILE *file1;
    FILE *file2;
	char ch1[] = "C:\\c++\\epbgit\\ConsoleApplication\\Debug\\out\\a.txt";
	char ch2[] = "C:\\c++\\epbgit\\ConsoleApplication\\Debug\\out\\b.txt";
	                        
	
    if(err = fopen_s(&file1,ch1, "r")) { 
        puts("來源檔案開啟失敗"); 
        return 1; 
    }
    
    if(err = fopen_s(&file2,ch2, "w")) { 
        puts("目的檔案開啟失敗"); 
        return 1; 
    }    
                                    
    while((fgets(str,50,file1)) != NULL) { 
        fputs(str, file2);
    } 
          
    fclose(file1);
    fclose(file2);
        
	system("pause");
    return 0; 
}
Example #19
0
int do_eep_wren(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	int query = argc == 1;
	int state = 0;

	if (query) {
		/* Query write access state. */
		state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, -1);
		if (state < 0) {
			puts("Query of write access state failed.\n");
		} else {
			printf("Write access for device 0x%0x is %sabled.\n",
			       CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
			state = 0;
		}
	} else {
		if ('0' == argv[1][0]) {
			/* Disable write access. */
			state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 0);
		} else {
			/* Enable write access. */
			state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 1);
		}
		if (state < 0) {
			puts("Setup of write access state failed.\n");
		}
	}

	return state;
}
Example #20
0
void kmain(void){
	vga_init();
	heap_init();
	unreal_init();

	// DETECT MEMORY
	puts("Detecting memory... ");
	memdetect();
	uint16_t count = *((uint16_t *) 0x7E00);
	if(!count){
		puts("error - something is wrong with INT15/EAX=E820");
		while(1);
	}

	uint16_t i;
	uint32_t amount = 0;
	for(i = 0;i < count;i++){
		amount += *((uint32_t *) 0x7008 + i * 4);
	}
	
	uint32_t mb = amount / 1048576;
	amount %= 1048576;
	uint8_t point = amount / 131072;
	if(amount % 131072 > 65536) point++;

	putd(mb);
	putc('.');
	putd(point);
	puts(" MB\n");

	unreal_disk();
	read_unbuffered(0, 0x30000, 1);
	puts("Done!");
	while(1);
}
Example #21
0
int main(){
	init();
	int choice ;
	char buf[10];
	while(1){
		menu();
		read(0,buf,8);
		choice = atoi(buf);
		switch(choice){
			case 1:
				add();
				break ;
			case 2:
				visit();
				break ;
			case 3:
				del();
				break ;
			case 4:
				clean();
				break ;
			case 5:
				puts("See you next time.");
				exit(0);
			default :
				puts("Invalid choice");
				break ;
		}

	}

}
Example #22
0
main()
{
    srand(time(NULL));
   long long i,n;
    while(scanf("%lld",&n) && n)
   {
       if(n==1)
       {
           puts("1 = 1");
           continue;
       }
       printf("%lld = ",n);
       fn=0;
       if(n<0)
       {
           n=-n;
           s[fn++]=-1;
       }
       factor(n,fn,s);
       std::sort(s,s+fn);
       printf("%lld",s[0]);
       for(i=1;i<fn;i++)
           printf(" x %lld",s[i]);
       puts("");
   }
}
Example #23
0
int main(int argc, char **argv )
{
	int status;
	longword host;

	if (argc > 2)
	{
		puts("Quote of the Day (Cookie) - retrieves a witty message");
		puts("Usage: COOKIE [server]");
		exit( 3 );
	}

	sock_init();

	if ( argc == 1)
	{
		status = cookie ((longword) NULL);
	}
	else
	{
		if ( (host = resolve( argv[1])) != 0uL )
		{
			status = cookie( host );
		}
		else
		{
			printf("Could not resolve host '%s'\n", argv[1]);
			status = 3;
		}
	}

	exit( status );
        return (0);  /* not reached */
}
Example #24
0
static void udp_send(char *addr_str, char *port_str, char *data)
{
    struct sockaddr_in6 src, dst;
    size_t data_len = strlen(data);
    uint16_t port;
    int s;
    src.sin6_family = AF_INET6;
    dst.sin6_family = AF_INET6;
    memset(&src.sin6_addr, 0, sizeof(src.sin6_addr));
    /* parse destination address */
    if (inet_pton(AF_INET6, addr_str, &dst.sin6_addr) != 1) {
        puts("Error: unable to parse destination address");
    }
    /* parse port */
    port = (uint16_t)atoi(port_str);
    dst.sin6_port = htons(port);
    src.sin6_port = htons(port);
    s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
    if (s < 0) {
        puts("error initializing socket");
    }

    if (sendto(s, data, data_len, 0, (struct sockaddr *)&dst, sizeof(dst)) < 0) {
	puts("could not send");
    }
    else {
	printf("Success: send %u byte to %s:%u\n", (unsigned)data_len, addr_str, port);
    }
    usleep(1000000);

    close(s);
}
Example #25
0
static void *
tf (void *arg)
{
  int tmp = 0;
  char number[160];
  sprintf(number, "tf(%ld): begin", (long)arg);
  puts (number);
  
  tmp = sas_spin_trylock(&t_lock);
  if (tmp == 0)
  {
    sprintf(number, "tf(%ld): sas_spin_trylock", (long)arg);
    puts (number);
    
    sas_spin_unlock(&t_lock);

    sprintf(number, "tf(%ld): end", (long)arg);
    puts (number);
  } else {
    sas_spin_lock_with_yield(&t_lock);

    sprintf(number, "tf(%ld): sas_spin_lock_with_yield", (long)arg);
    puts (number);
  
    sas_spin_unlock(&t_lock);

    sprintf(number, "tf(%ld): end", (long)arg);
    puts (number);
  }
  return NULL;
}
Example #26
0
File: ga.c Project: haiy/XF_PRISM
population *elitist_sel(population *pop,population *S)
{
    qksort(pop);
    qksort(S);
#ifdef debug_elt
    puts("The pop is:\t");
    check_pop(*pop);
    puts("The S is :\t");
    check_pop(*S);
#endif
    int i=0;
    int p=0;
    int q=0;
    for(i=0;i<pop->n;i++)
    {
        if(EXACT(pop->m[p].sig)>EXACT(S->m[q].sig))
        {
            p++;
        }
        else
        {
            chg_chro_PS(pop,i,S,q);
            q++;
        }
    }
#ifdef debug_elt
    puts("After merging...\t");
    check_pop(*pop);
#endif
    return pop;
}
Example #27
0
int main()
{
	srand(time(NULL));
	int A[N], B[N];
	arrayRandomFill(A, N, 1, 64000);
	arrayRandomFill(B, N, 1, 128);

#if MY == 1
	puts("Zastosowano wlasna implementacje algorytmu sortowania przez zliczanie");
#else
	puts("Zastosowano implementacje algorytmu sortowania przez zliczanie zgodna z pseudokodem z wykladu");
#endif

	int Niter = 100000;
	double time = czasWykonaniaSortowania(A, N, 1, 64000, Niter);
	printf("Czas sortowania %d razy tablicy A: %lf\n", Niter, time);

	Niter = 20000000;
	time = czasWykonaniaSortowania(B, N, 1, 128, Niter);
	printf("Czas sortowania %d razy tablicy B: %lf\n", Niter, time);

	printf("Nacisnij enter aby kontynuowac");
	getchar();
	return 0;
}
Example #28
0
main()
{
    int i,j,k,n,m,T,C=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=m=0;i<n;i++)
            for(j=0;j<i;j++)
            {
                scanf("%d",&c[i][j]),m++;
                c[j][i]=c[i][j],u[i][j]=1;
            }
        printf("Case #%d:\n",C++);
        for(k=0;k<n;k++)
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                {
                    if(i==k || k==j)continue;
                    if(c[i][k]+c[k][j]<c[i][j])
                        goto better;
                    if(c[i][k]+c[k][j]==c[i][j])
                        if(u[i][j])m--,u[i][j]=0;
                }
        printf("%d\n",m);
        for(i=0;i<n;i++)
            for(j=0;j<i;j++)
                if(u[i][j])
                    printf("%d %d %d\n",j+1,i+1,c[i][j]);
        puts("");
        continue;
    better:
        puts("Need better measurements.\n");
    }
}
Example #29
0
static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ENTRY *match;
	unsigned char matched[env_htab.size / 8];
	int rcode = 1, arg = 1, idx;

	if (argc < 2)
		return cmd_usage(cmdtp);

	memset(matched, 0, env_htab.size / 8);

	while (arg <= argc) {
		idx = 0;
		while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
			if (!(matched[idx / 8] & (1 << (idx & 7)))) {
				puts(match->key);
				puts("=");
				puts(match->data);
				puts("\n");
			}
			matched[idx / 8] |= 1 << (idx & 7);
			rcode = 0;
		}
		arg++;
	}

	return rcode;
}
Example #30
0
void InputGamblingMoney(void)
{
	int gamblingMoney;

	while (1)
		{
			puts("& 판돈 설정합니다.! &");
			fputs("판돈 입력 : ", stdout);
			scanf("%d", &gamblingMoney);
		
			if (gamblingMoney > GetCurrentYouMoney())
			{
				puts("소유하고 있는 금액 내에서 거세요!");
				printf("당신의 현재 게임 머니 : %d \n", GetCurrentYouMoney());
			}
			else if (gamblingMoney > GetCurrentComMoney())
			{
				puts("컴퓨터 소유 금액 초고 입니다.!");
				printf("컴퓨터의 현재 게임 머니 : %d \n", GetCurrentComMoney());
			}
			else			
				break;
		}
		
		SetGamblingTableMoney(gamblingMoney);
		puts("");
	
}