Пример #1
0
int main(int argc, char *argv[])
{
    int c;

    if(argc != 2)
    {
        printf("Usage: profile #command, -h for help info\n");

        return 1;
    }

    while((c = getopt(argc, argv, "bseh")) != -1)
    {
        switch(c) {
        case 'b':
            cm_start_watch();
            break;
        case 'e':
            cm_stop_watch();
            break;
        case 's':
            cm_stop_all_watch();
            break;
        case 'h':
            help_info();
            break;
        default :
            printf("error option : %c\n", c);
            help_info();
        }
    }

    return 1;
}
Пример #2
0
int main()
{
 help_info();
 snake_init();
 show_food();
 drow_wall();
 game_info();
 while(judge()){
  snake_move();
 }
 return 0;
}
Пример #3
0
int main(void)
{
	int i, j;
	node_init(&address_list);
	char *menu[7] = {"1.新增联系人","2.更新联系人","3.查找联系人","4.查看","5.导出联系人","9.帮助","0.退出"};


	printf("----------------欢迎使用本通讯录-------------\n");
	for(;;){
		for( j = 0 ; j < 7 ; ++j){
			printf("%s\n", menu[j]);
		}
		printf("[0-5,9]:");
		scanf("%d",&i);
		printf("\n");
		switch(i){
			case 1 :
				add_link_man();
				break;
			case 2 :
				display_link_man(&address_list,print_linkman);
				update_link_man(&address_list);
				break;
			case 3 :
				find_link_man(&address_list);
				break;
			case 4 :
				display_link_man(&address_list,print_linkman);
				break;
			case 5 :
				if(save(&address_list) < 0){
					printf("save failed!\n");
				}else
					printf("save succeed!\n");
				break;
			case 0 :
				list_destory(&address_list);
				exit(-1);
				break;
			case 9 :
				help_info();
				break;
			default :
				break;
		}

	}
	return 0;
}
int main(int argc, const char *argv[])
{
	int fd, timeout, sleep_sec, test;
	if (argc < 2) {
		help_info();
		return 1;
	}
	timeout = atoi(argv[1]);
	sleep_sec = atoi(argv[2]);
	if (sleep_sec <= 0) {
		sleep_sec = 1;
		printf("correct 0 or negative sleep time to %d seconds\n",
		       sleep_sec);
	}
	test = atoi(argv[3]);
	printf("Starting wdt_driver (timeout: %d, sleep: %d, test: %s)\n",
	       timeout, sleep_sec, (test == 0) ? "ioctl" : "write");
	fd = open("/dev/watchdog", O_WRONLY);
	if (fd == -1) {
		perror("watchdog");
		exit(1);
	}
	printf("Trying to set timeout value=%d seconds\n", timeout);
	ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
	printf("The actual timeout was set to %d seconds\n", timeout);
	ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
	printf("Now reading back -- The timeout is %d seconds\n", timeout);
	while (1) {
		if (test == 0) {
			ioctl(fd, WDIOC_KEEPALIVE, 0);
		} else {
			write(fd, "\0", 1);
		}
		sleep(sleep_sec);
	}
	return 0;
}
Пример #5
0
int main(int argc, char **argv)
{
	int spi_id;
	int bytes, len;
	int res;
	int i;

	if (argc <= 1) {
		help_info(argv[0]);
		return 1;
	}

	mode = 0;
	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i], "-D")) {
			i++;
			spi_id = atoi(argv[i]);
			if (spi_id < 0 || spi_id > 2) {
				printf("invalid parameter for device option\n");
				help_info(argv[0]);
				return -1;
			}
		} else if(!strcmp(argv[i], "-s")) {
			i++;
			speed = atoi(argv[i]);
		} else if(!strcmp(argv[i], "-b")) {
			i++;
			bits_per_word = atoi(argv[i]);
		} else if(!strcmp(argv[i], "-H"))
			mode |= SPI_CPHA;
		else if(!strcmp(argv[i], "-O"))
			mode |= SPI_CPOL;
		else if(!strcmp(argv[i], "-C"))
			mode |= SPI_CS_HIGH;
		else if((i != (argc - 1))) {
			printf("invalid parameter\n");
			help_info(argv[0]);
			return -1;
		}
	}

	bytes = strlen((char *)argv[argc - 1]);
	if (bytes < 1) {
		printf("invalid parameter for buffer size\n");
		help_info(argv[0]);
		return -1;
	}

	/* The spidev driver copies len of bytes to tx buffer, and sends len of
	   units to SPI device. So it will send much more data to the SPI
	   device when bits per word is larger than 8, we only care the
	   first len of bytes for this test */
	len = bytes;
	if (bits_per_word <= 8 && bytes > BUF_MAX_SIZE)
		len = BUF_MAX_SIZE;
	else if (bits_per_word <= 16 && bytes > BUF_MAX_SIZE/2)
		len = BUF_MAX_SIZE/2;
	else if (bytes > BUF_MAX_SIZE/4)
		len = BUF_MAX_SIZE/4;

	buffer = malloc(BUF_MAX_SIZE);
	memset(buffer, 0, BUF_MAX_SIZE);
	strcpy(buffer, (char *)argv[argc-1]);

	printf("Execute data transfer test: %d %d %s\n", spi_id, len, buffer);
	res = execute_buffer_test(spi_id, len, buffer);
	free(buffer);
	return res;
}
Пример #6
0
int main(int argc, char **argv)
{
  int c;
  SshCryptoStatus cs;
  SshCipher cipher;
  Boolean all_ciphers = FALSE, speed_test = FALSE, quiet = FALSE;
  unsigned char *iv = NULL, *key = NULL;
  size_t iv_len = 0, key_len = 0;
  char *cipher_name = NULL, *cipher_names, *hlp, *passphrase = NULL;
  Boolean encrypt_mode = TRUE;
  char *input_file = NULL, *output_file = NULL;
  FILE *fin, *fout;
  Boolean r = TRUE;

  if (strchr(argv[0], '/'))
    av0 = strrchr(argv[0], '/') + 1;
  else
    av0 = argv[0];

  if (strcasecmp(av0, "ssh-encrypt") == 0)
    encrypt_mode = TRUE;
  else if (strcasecmp(av0, "ssh-decrypt") == 0)
    encrypt_mode = FALSE;

  if (ssh_crypto_library_initialize() != SSH_CRYPTO_OK)
    {
      fprintf(stderr, "Can't initialize the cryptographic provider.\n");
      exit(1);
    }
  while ((c = ssh_getopt(argc, argv, "thd:ac:i:k:EDp:", NULL)) != -1)
    {
      switch (c)
        {
        case 'd':
          ssh_debug_set_level_string(ssh_optarg);
          break;
        case 't':
          speed_test = TRUE;
          break;
        case 'a':
          all_ciphers = TRUE;
          break;
        case 'c':
          cipher_name = ssh_xstrdup(ssh_optarg);
          break;
        case 'q':
          quiet = TRUE;
          break;
        case 'i':
          if (iv)
            {
              fprintf(stderr,
                      "%s: No multiple initialization vectors allowed.\n",
                      av0);
              usage();
              exit(-1);
            }
          if (! hex_string_to_data(ssh_optarg, &iv, &iv_len))
            {
              fprintf(stderr, "%s: Bad IV string.\n", av0); 
              exit(-1);
            }
          break;
        case 'k':
          if (key)
            {
              fprintf(stderr, "%s: No multiple keys allowed.\n", av0);
              usage();
              exit(-1);
            }
          if (! hex_string_to_data(ssh_optarg, &key, &key_len))
            {
              fprintf(stderr, "%s: Bad KEY string.\n", av0); 
              exit(-1);
            }
          break;
        case 'p':
          if (passphrase)
            {
              fprintf(stderr, "%s: No multiple passphrases allowed.\n", av0);
              usage();
              exit(-1);
            }
          passphrase = ssh_optarg;
          break;
        case 'E':
          encrypt_mode = TRUE;
          break;
        case 'D':
          encrypt_mode = FALSE;
          break;
        case 'h':
          help_info();
          usage();
          exit(0);
          /*NOTREACHED*/
        default:
          usage();
          exit(-1);
          /*NOTREACHED*/
        }
    }
  argc -= ssh_optind;
  argv += ssh_optind;
  if (speed_test && (argc > 0))
    {
      fprintf(stderr, "%s: Extra parameters.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if (argc > 2)
    {
      fprintf(stderr, "%s: Extra parameters.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if (argc > 1)
    output_file = ssh_xstrdup(argv[1]);
  if (argc > 0)
    input_file = ssh_xstrdup(argv[0]);
  if ((cipher_name != NULL) && all_ciphers)
    {
      fprintf(stderr, "%s: -c and -a can't be used together.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if (all_ciphers && !speed_test)
    {
      fprintf(stderr, "%s: -a can only be used with -t.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if ((cipher_name != NULL) && strchr(cipher_name, ',') && !speed_test)
    {
      fprintf(stderr, "%s: Multiple ciphers only be used with -t.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if (cipher_name == NULL)
    {
      if (speed_test)
        {
          all_ciphers = TRUE; /* Assume `all' if test mode with no ciphers. */
        }
      else
        {
          fprintf(stderr, "Missing -c flag.\n");
          usage();
          exit(-1);
          /*NOTREACHED*/
        }
    }
  if (passphrase && key)
    {
      fprintf(stderr, "%s: Can't use both passphrase and hex key.\n", av0);
      usage();
      exit(-1);
      /*NOTREACHED*/
    }
  if (!key && !passphrase && !speed_test)
    {
      ssh_warning("%s: No key!  Empty passphrase assumed.", av0);
      passphrase = "";
      /*NOTREACHED*/
    }
  if (speed_test)
    {
      fprintf(stderr, "Performing speed tests\n");
      if (all_ciphers)
        {
          cipher_names = ssh_cipher_get_supported();
        }
      else
        {
          /* Steal allocated cipher_name */
          cipher_names = cipher_name;
          cipher_name = NULL;
        }
      hlp = cipher_names;
      while ((cipher_name = ssh_name_list_get_name(hlp)) != NULL)
        {
          hlp += strlen(cipher_name);
          if (*hlp == ',')
            hlp++;
          cipher_speed_test(cipher_name,
                            passphrase,
                            key, key_len,
                            iv, iv_len,
                            encrypt_mode);
          ssh_xfree(cipher_name);

          if (strlen(hlp) == 0)
            break;
        }
      ssh_xfree(cipher_names);
    }
  else
    {
      if (passphrase)
        cs = ssh_cipher_allocate_with_passphrase(cipher_name,
                                                 passphrase,
                                                 encrypt_mode,
                                                 &cipher);
      else
        cs = ssh_cipher_allocate(cipher_name,
                                 key,
                                 key_len,
                                 encrypt_mode,
                                 &cipher);
      if (cs != SSH_CRYPTO_OK)
        {
          switch (cs)
            {
            case SSH_CRYPTO_UNSUPPORTED:
              fprintf(stderr, "%s: Unsupported cipher \"%s\".\n", av0, 
                      cipher_name);
              usage();
              exit(-1);
            case SSH_CRYPTO_KEY_TOO_SHORT:
              fprintf(stderr, "%s: Key too short for \"%s\".\n", av0, 
                      cipher_name);
              usage();
              exit(-1);
            default:
              fprintf(stderr, "%s: Cipher allocate failed.\n", av0);
              exit(-1);
            }
          /*NOTREACHED*/
        }
      if (iv != NULL)
        {
          if (ssh_cipher_get_iv_length(ssh_cipher_name(cipher)) == iv_len)
            ssh_cipher_set_iv(cipher, iv);
          else
            {
              fprintf(stderr, "%s: Weird IV length.\n", av0);
              exit(-1);
            }
        }
      if (input_file != NULL)
        {
          fin = fopen(input_file, "r");
          if (fin == NULL)
            {
              fprintf(stderr, "%s: Cannot open input file \"%s\".\n", 
                      av0, input_file);
              exit(-1);
            }
        }
      else
        {
          fin = stdin;
        }
      if (output_file != NULL)
        {
          struct stat st;
          if (stat(output_file, &st) >= 0)
            {
              fprintf(stderr, "%s: Output file \"%s\" exists.\n", av0, 
                      output_file);
              exit(-1);
            }
          fout = fopen(output_file, "w");
          if (fout == NULL)
            {    
              fprintf(stderr, "%s: Cannot open output file \"%s\".\n", 
                      av0, output_file);
              exit(-1);
            }
        }
      else
        {
          fout = stdout;
        }
      if (encrypt_mode)
        r = cipher_encrypt(cipher, fin, fout);
      else
        r = cipher_decrypt(cipher, fin, fout);
      if (input_file)
        fclose(fin);
      if (output_file)
        {
          fclose(fout);
          if (! r)
            (void)unlink(output_file);
        }
      ssh_cipher_free(cipher);
      ssh_xfree(cipher_name);
    }

  ssh_xfree(input_file);
  ssh_xfree(output_file);
  ssh_xfree(key);
  ssh_xfree(iv);

  ssh_crypto_library_uninitialize();
  ssh_util_uninit();
  return((r == TRUE) ? 0 : -1);
}
Пример #7
0
int main(int argc, char* argv[])
{
	if(argc > 1 && strcmp(argv[1], "-v") == 0)
	{
		cout<<"SinaShow DCS Version Infomation:"<<endl;
		cout<<"CrsTrans Version: "<<gstrDCSWorkerVersion.c_str()<<endl;
		cout<<"Copyright (C) Beijing Sina Information Technology Co.,Ltd 2003-2009"<<endl;
		return 0;
	}

	if(argc > 1 && strcmp(argv[1], "-h") == 0)
	{
		help_info();
		return 0;
	}

	if(argc > 1 && strcmp(argv[1], "-f") != 0)
	{
		help_info();
		return 0;
	}

	string lstrConfigName = "";
	if(argc > 1 && strcmp(argv[1], "-f") == 0)
	{
		lstrConfigName = argv[2];
		if(lstrConfigName.empty())
		{
			help_info();
			return 0;
		}
	}

	char lszLogFileName[255];
	memset(lszLogFileName, 0, 255);
	CFileStream::GetAppPath(lszLogFileName,255);

	string lstrAppPath = lszLogFileName;
	string lstrApp = lstrAppPath.substr(0, lstrAppPath.find_last_of('/'));
	if (chdir(lstrApp.c_str()))
	{
		cout<<"crs_trans error: chdir error."<<lszLogFileName<<endl;
		return 0;
	}

	goDebugTrace = new CDebugTrace;

	unsigned int process_id = CCommon::GetProcessId();

	//设置日志文件信息
	SET_TRACE_LEVEL(5);
	unsigned liOptions = (CDebugTrace::Timestamp | CDebugTrace::LogLevel
		& ~CDebugTrace::FileAndLine | CDebugTrace::AppendToFile);
	SET_TRACE_OPTIONS(GET_TRACE_OPTIONS() | liOptions);

	strcpy(strrchr(lszLogFileName,'/'),"//DCS_log");
	CFileStream::CreatePath(lszLogFileName);
	char lszFileDate[50];
	memset(lszFileDate, 0, 50);
	sprintf(lszFileDate, "//DCS-%u", process_id);
	strcat(lszLogFileName,lszFileDate);
	SET_LOG_FILENAME(lszLogFileName);
	TRACE(1,"\n\n*******************DCS调试日志VERSION:" <<
		gstrDCSWorkerVersion.c_str() << "*******************");

	TRACE(1, "配置文件信息: "<<lstrConfigName.c_str());

	//加载配置文件
	CDCSConfig loDCSConfig;
	loDCSConfig.set_conf_file_name(lstrConfigName.c_str());
	bool bRet = loDCSConfig.load();
	if(!bRet)
	{
		TRACE(1, "ERROR: 加载配置文件失败。");
		return 0;
	}

	CDCSWorker worker;
	worker.SetConfig(&loDCSConfig);
	worker.Run();

	return 0;
}
int main(int argc, char* argv[])
{
struct stat fileStat ;
struct stat *c=&fileStat;    

    
int file_type=0;
int size_info=0;
int owner_details=0;
int write_file=0;
char opt;
char* file = malloc(100);
strcpy(file,argv[argc-1]);
 

if(argc<2)  	
help_info();
else
	{
		while((opt=getopt(argc,argv,":toe"))!=-1)
		{
			
			switch(opt)
			{
				case 't': 
				  file_type=1;
				  size_info=1;					
				break;
			
				case 'o': 
				  owner_details=1;
				  size_info=1;	
				break;
				
				case 'e': 
				  write_file=1;			
				break;
				
				default:
				  printf("Invalid option:Please enter valid option, Exiting the program\n");
				  free(file);
				return -1;
			}

		}


	char *file = argv[optind];
	if( access( file, F_OK ) == -1 )
	{
	    printf("File doesn't exist, please enter a valid file name. Exiting the program\n");
	    return -1;
	    free(file);
	}
 

                 
		
	if (write_file==1)
	{
		if((file_type==1) && (owner_details ==1))
		{
			func_filetype(file,c);
			func_ownerdetails(file,c);
			func_writefile(file,c);			
			func_sizeinfo(file,c);
		}	
		else if ((file_type==1) && (owner_details==0))
		{
			func_filetype(file,c);
			func_writefile(file,c);
			func_sizeinfo(file,c);				
		}
		else if ((file_type==0) && (owner_details==1))
		{
			func_ownerdetails(file,c);
			func_writefile(file,c);
			func_sizeinfo(file,c);
		}
		else
		{
			func_writefile(file,c);
			func_sizeinfo(file,c);			
				
		}
	}
	
	else
	{
		if((file_type==1) && (owner_details ==1))
		{
			func_filetype(file,c);
			func_ownerdetails(file,c);
			func_sizeinfo(file,c);
		}	
		else if ((file_type==1) && (owner_details==0))
		{
			func_filetype(file,c);
			func_sizeinfo(file,c);				
		}
		else if ((file_type==0) && (owner_details==1))
		{
			func_ownerdetails(file,c);
			func_sizeinfo(file,c);
		}
		else
		{
			func_sizeinfo(file,c);
				
		}
	}
		
	
	}
return 0;
  

    printf("File doesn't exist, please enter a valid file name. Exiting the program\n");
    return -1;
    free(file);

}