コード例 #1
0
ファイル: icuinfo.cpp プロジェクト: venkatarajasekhar/Qt
extern int
main(int argc, char* argv[]) {
    UErrorCode errorCode = U_ZERO_ERROR;
    UBool didSomething = FALSE;
    
    /* preset then read command line options */
    argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);

    /* error handling, printing usage message */
    if(argc<0) {
        fprintf(stderr,
            "error in command line argument \"%s\"\n",
            argv[-argc]);
    }
    if( options[0].doesOccur || options[1].doesOccur) {
      fprintf(stderr, "%s: Output information about the current ICU\n", argv[0]);
      fprintf(stderr, "Options:\n"
              " -h     or  --help                 - Print this help message.\n"
              " -m     or  --millisecond-time     - Print the current UTC time in milliseconds.\n"
              " -d <dir>   or  --icudatadir <dir> - Set the ICU Data Directory\n"
              " -v                                - Print version and configuration information about ICU\n"
              " -L         or  --list-plugins     - List and diagnose issues with ICU Plugins\n"
              " -K         or  --cleanup          - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
              "\n"
              "If no arguments are given, the tool will print ICU version and configuration information.\n"
              );
      fprintf(stderr, "International Components for Unicode %s\n%s\n", U_ICU_VERSION, U_COPYRIGHT_STRING );
      return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
    }
    
    if(options[2].doesOccur) {
      u_setDataDirectory(options[2].value);
    }

    if(options[5].doesOccur) {
      cmd_millis();
      didSomething=TRUE;
    } 
    if(options[4].doesOccur) {
      cmd_listplugins();
      didSomething = TRUE;
    }
    
    if(options[3].doesOccur) {
      cmd_version(FALSE);
      didSomething = TRUE;
    }
        
    if(options[6].doesOccur) {  /* 2nd part of version: cleanup */
      cmd_cleanup();
      didSomething = TRUE;
    }
        
    if(!didSomething) {
      cmd_version(FALSE);  /* at least print the version # */
    }

    return U_FAILURE(errorCode);
}
コード例 #2
0
ファイル: smfsh.c プロジェクト: DanielAeolusLaude/ardour
int
main(int argc, char *argv[])
{
	int ch;

	while ((ch = getopt(argc, argv, "V")) != -1) {
		switch (ch) {
		case 'V':
			cmd_version(NULL);
			exit(EX_OK);

		case '?':
		default:
			usage();
		}
	}

	if (argc > 2)
		usage();

	g_log_set_default_handler(log_handler, NULL);

	smf = smf_new();
	if (smf == NULL) {
		g_critical("Cannot initialize smf_t.");
		return (-1);
	}

	if (argc == 2)
		cmd_load(argv[1]);
	else
		cmd_trackadd(NULL);

#ifdef HAVE_LIBREADLINE
	rl_readline_name = "smfsh";
	rl_attempted_completion_function = smfsh_completion;
#endif

	for (;;)
		read_and_execute_command();

	return (0);
}
コード例 #3
0
ファイル: erlxslt_adapter.c プロジェクト: chinnurtb/erlxslt-2
int main(int argc, char **argv, char **env) {
    debug("int main(int argc, char **argv, char **env)");
    unsigned char buffer[PACKET_SIZE];
    #ifndef USE_GLOBAL
        Trie* trie = NULL
    #endif
    trie = trie_try_new(trie);
    for(;;) {
        /**
            Читаем сообщение из буфера,
            до тех пор пока можем их читать,
            и пока не получили неизвестную нам команду
        **/
        if (1 != read_cmd(buffer)){
            trie_free(trie);
            exit(1);
        }
        switch (*buffer) {
            case CMD_VERSION:
                /**
                    Запрос версии
                **/
                cmd_version();
                break;
            case CMD_APPLY_XSL:
                /**
                    Запрос на преобразование 
                **/
                cmd_apply_xsl(trie);
                break;
            default:
                /**
                    Неведомая фигня
                **/
                trie_free(trie);
                fprintf(stderr, "unknown command %c in adapter\n",
                        *buffer);
                exit(1);
        }
    }
}
コード例 #4
0
ファイル: xdotool.c プロジェクト: cardil/xdotool
int args_main(int argc, char **argv) {
  int ret = 0;
  int opt;
  int option_index;

  const char *usage = "Usage: %s <cmd> <args>\n";
  static struct option long_options[] = {
    { "help", no_argument, NULL, 'h' },
    { "version", no_argument, NULL, 'v' },
    { 0, 0, 0, 0 }
  };

  if (argc < 2) {
    fprintf(stderr, usage, argv[0]);
    cmd_help(NULL);
    exit(1);
  }
  
  //for(i = 0; i<argc; i++) {
    //fprintf(stderr, "argv[%d] = \"%s\"\n", i, argv[i]);
  //}

  while ((opt = getopt_long_only(argc, argv, "++hv", long_options, &option_index)) != -1) {
    switch (opt) {
      case 'h':
        cmd_help(NULL);
        exit(EXIT_SUCCESS);
      case 'v':
        cmd_version(NULL);
        exit(EXIT_SUCCESS);
      default:
        fprintf(stderr, usage, argv[0]);
        exit(EXIT_FAILURE);
    }
  }
  
  context_t context;
  context.xdo = xdo_new(NULL);
  context.prog = *argv;
  argv++; argc--;
  context.argc = argc;
  context.argv = argv;
  context.windows = NULL;
  context.nwindows = 0;
  context.have_last_mouse = False;
  context.debug = (getenv("DEBUG") != NULL);
  context.xdo->debug = context.debug;

  if (context.xdo == NULL) {
    fprintf(stderr, "Failed creating new xdo instance\n");
    return 1;
  }

  ret = context_execute(&context);

  xdo_free(context.xdo);
  if (context.windows != NULL) {
    free(context.windows);
  }

  return ret;
} /* int args_main(int, char **) */
コード例 #5
0
ファイル: flux-kvs.c プロジェクト: surajpkn/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    char *cmd;

    log_init ("flux-kvs");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
        case 'h': /* --help */
            usage ();
            break;
        default:
            usage ();
            break;
        }
    }
    if (optind == argc)
        usage ();
    cmd = argv[optind++];

    if (!(h = flux_open (NULL, 0)))
        err_exit ("flux_open");

    if (!strcmp (cmd, "get"))
        cmd_get (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "type"))
        cmd_type (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "put"))
        cmd_put (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "unlink"))
        cmd_unlink (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "link"))
        cmd_link (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "readlink"))
        cmd_readlink (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "mkdir"))
        cmd_mkdir (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "exists"))
        cmd_exists (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "version"))
        cmd_version (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "wait"))
        cmd_wait (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "watch"))
        cmd_watch (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "watch-dir"))
        cmd_watch_dir (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dropcache"))
        cmd_dropcache (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dropcache-all"))
        cmd_dropcache_all (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "copy-tokvs"))
        cmd_copy_tokvs (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "copy-fromkvs"))
        cmd_copy_fromkvs (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dir"))
        cmd_dir (h, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dirsize"))
        cmd_dirsize (h, argc - optind, argv + optind);
    else
        usage ();

    flux_close (h);
    log_fini ();
    return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: GrayTShirt/bolo
int main(int argc, char **argv)
{
	int run_help = 0;
	int run_version = 0;

	char proc[256];
	char path[256];
	pid_t pid = getpid();
	sprintf(proc, "/proc/%d/exe", pid);
	if (readlink(proc, path, 256) == -1) {
		fprintf(stderr, "failed to read execution path from /proc\n");
		return 1;
	}

	if (strcmp(path, "/usr/sbin/bolo") == 0)
		return cmd_aggregator(argc, argc, argv);

	int i;
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-h") == 0
		 || strcmp(argv[i], "-?") == 0
		 || strcmp(argv[i], "--help") == 0) {
			run_help = 1;
			continue;
		}
		if (strcmp(argv[i], "-V") == 0
		 || strcmp(argv[i], "--version") == 0) {
			run_version = 1;
			continue;
		}
		if (argv[i][0] == '-') {
			fprintf(stderr, "Invalid option `%s'\n", argv[i]);
			return 1;
		}
		break;
	}

	if (run_help)    return cmd_help(i, argc, argv);
	if (run_version) return cmd_version(i, argc, argv);
	if (i == argc)   return cmd_help(i, argc, argv);

	if (strcmp(argv[i], "help") == 0)
		return cmd_help(i, argc, argv);

	if (strcmp(argv[i], "version") == 0)
		return cmd_version(i, argc, argv);

	if (strcmp(argv[i], "aggr") == 0
	 || strcmp(argv[i], "aggregator") == 0)
		return cmd_aggregator(i, argc, argv);

	if (strcmp(argv[i], "cache") == 0)
		return cmd_cache(i, argc, argv);

	if (strcmp(argv[i], "forget") == 0)
		return cmd_forget(i, argc, argv);

	if (strcmp(argv[i], "name") == 0)
		return cmd_name(i, argc, argv);

	if (strcmp(argv[i], "query") == 0)
		return cmd_query(i, argc, argv);

	if (strcmp(argv[i], "send") == 0)
		return cmd_send(i, argc, argv);

	if (strcmp(argv[i], "spy") == 0)
		return cmd_spy(i, argc, argv);

	if (strcmp(argv[i], "tail") == 0)
		return cmd_tail(i, argc, argv);

	fprintf(stderr, "Unrecognized command `%s'.  See bolo --help.\n", argv[i]);
	return 1;
}
コード例 #7
0
ファイル: p2p_upgrade.c プロジェクト: alkap007/ali3606
INT32 sys_upgrade_process(void (*callback)(INT32 type, INT32 process, UINT16 *str), UINT32 (*GetExitKey)(void), int nType)
{
	UINT32 result = SUCCESS;
	INT32 i;
	INT32 retry_count=0;
	BOOL bReboot = TRUE;
	BOOL bBurn = TRUE;
	char strTmp[30];
	char strTmp1[30];
	char strTmp2[30];
	char strTmp3[30];
	char strTmp4[30];
	char strTmp5[30];
	char strTmp6[30];
	char strTmp7[30];
	char strTmp8[30];
	char strTmp9[30];
	char strTmp10[30];
	char strTmp11[30];
	char strTmp12[30];
	char strTmp13[30];
	char strTmp14[30];

	if(nType == 2 || nType == 3)
		bReboot = FALSE;
	
	if(nType == 3)
		bBurn = FALSE;
	
	get_exit_key = GetExitKey;
	callback_fun = callback;
	
	LV_pPanDev = (struct pan_device *) dev_get_by_type(NULL, HLD_DEV_TYPE_PAN);
	if(NULL == LV_pPanDev)
	{
		PRINTF("dev_get_by_name failed\n");
		return !SUCCESS;
	}
	if(pan_open(LV_pPanDev)!=SUCCESS)
	{
		PRINTF("pan_open failed\n");
		return !SUCCESS;
	}

	//pan_display(LV_pPanDev,  "up9 ", 4);
#ifdef THREE_DIGITS_PANEL
	pan_display(LV_pPanDev,  " up9", 4);
#else
	pan_display(LV_pPanDev,  "up9 ", 4);
#endif

#ifdef ENABLE_EROM
    init_buffer();
//    uart_reset();
    osal_task_sleep(100);
    uart_high_speed_config(UART_SPEED_NORMAL);
    do
    {
        if(!sync_slave((UPGRADE_MULTI==upgrade_mode)?M2S_MODE:P2P_MODE, 1000))
            return !SUCCESS; ;
        //uart_high_speed_config(UART_HIGH_SPEED_2M);
        if(!init_slave()) // after init slave, uart 6M high bitrate is applied
            return !SUCCESS;;
    }while(0);
#endif

	MG_Setup_CRC_Table();

	/* Check sci port */
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_MSG_UPGRADE_CHECK_SERIAL_PORT),strTmp);
	callback(3,0,strTmp);

	result = cmd_comtest(&g_protocol_version, NULL, GetExitKey);
	if(result != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_CONNECT_FAILED),strTmp1);
		callback(2,0,strTmp1);
		return !SUCCESS;
	}

    	p2p_delay();
    ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_COLLECTING_VERSION_INFO),strTmp2);
	callback(2,0,strTmp2);
	if((result = cmd_version(&g_protocol_version)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp3);
		callback(2, 0, strTmp3);
		return !SUCCESS;
	}
	
	
	p2p_delay();
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_COMPARE_SLAVE_REORG),strTmp4);
	callback(2,0,strTmp4);
	if((result =SlaveReorg(callback)) != SUCCESS)
	{
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp5);
		callback(2,0,strTmp5);
		return !SUCCESS;
	}

	p2p_delay();

	UINT32 addr = 0x0;
	if(pslave_reorg_list[0].type == 2)  //transfer bootloader
	{
		addr = 0x0;
	}
	else
	{
#if (SYS_PROJECT_FE	== PROJECT_FE_DVBT && SYS_SDRAM_SIZE == 2)
		addr = 0x7800;
#else
#if (SYS_CHIP_MODULE == ALI_M3327C && SYS_SDRAM_SIZE == 2)
		//addr = 0xc000;
		//add logo data, so the address is changed
        addr = 0x8000;
#else
		addr = pslave_list[0].offset;
#endif
#endif
	}
	if((result = cmd_address(addr)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp6);
		callback(2, 0, strTmp6);
		return !SUCCESS;
	}

	trans_size = 0;
	prog = 0;
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_TRANSFERING_DATA),strTmp7);
	callback(3,0,strTmp7);
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "u0  ", 4);
#endif
	for(i=0; i<slave_reorg_number;i++)
	{
		p2p_delay();

		if(pslave_reorg_list[i].type==1) //move
		{
			if(i==0)  continue;
			result = command_move(pslave_reorg_list[i].index, pslave_reorg_list[i].offset, callback);
			if(result != SUCCESS)
			{
				pan_display_error(result);
				ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_MOVE_FAILED_TRY_AGAIN),strTmp8);
				callback(2,0,strTmp8);
				return !SUCCESS;
			}
			
		}
		else //transfer
		{
			result = command_transfer(pslave_reorg_list[i].index,callback);
			if(result != SUCCESS)
			{
				pan_display_error(result);
				ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_TRANSFER_FAILED_TRY_AGAIN),strTmp9);
				callback(2,0,strTmp9);
				return !SUCCESS;
			}
		}
	}
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "100 ", 4);
#endif

    	p2p_delay();
	/* Send command to burn flash */
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_MSG_UPGRADE_BURN_FLASH),strTmp10);
	callback(3,0,strTmp10);
	pan_display(LV_pPanDev,  "burn ", 4);
		
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "b0  ", 4);
#endif

	if((result = command_burn_new(callback, bBurn)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp11);
		callback(2,0,strTmp11);
		return !SUCCESS;
	}
		
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "100 ", 4);
#endif
	pan_display(LV_pPanDev,  "end ", 4);
	/*reboot slaver*/
	if(bReboot)
	{
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_REBOOTING_SLAVER),strTmp12);
		callback(2,0,strTmp12);
	    if(command_reboot(callback) != SUCCESS)
	    {
	    	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp13);
	        callback(2,0,strTmp13);
	        return !SUCCESS;
	    }
	}
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_SUCCESSFUL),strTmp14);
	callback(2, 0, strTmp14);

	return SUCCESS;
}
コード例 #8
0
ファイル: p2p_upgrade.c プロジェクト: alkap007/ali3606
/* Updata whole flash with LED support only */
INT32 sys_upgrade4(char* ledstr,void (*callback)(INT32 type, INT32 process, UINT8 *str), UINT32 (*GetExitKey)(void))
{
	UINT32 result = SUCCESS;
	INT32 i;
	INT32 retry_count=0;
	char strTmp[30];
	char strTmp1[30];
	char strTmp2[30];
	char strTmp3[30];
	char strTmp4[30];
	char strTmp5[30];
	char strTmp6[30];
	char strTmp7[30];
	char strTmp8[30];
	char strTmp9[30];
	
	get_exit_key = GetExitKey;
	callback_fun = callback;

	
	LV_pPanDev = (struct pan_device *) dev_get_by_type(NULL, HLD_DEV_TYPE_PAN);
	if(NULL == LV_pPanDev)
	{
		PRINTF("dev_get_by_name failed\n");
		return !SUCCESS;
	}
	if(pan_open(LV_pPanDev)!=SUCCESS)
	{
		PRINTF("pan_open failed\n");
		return !SUCCESS;
	}

	//pan_display(LV_pPanDev,  "up9 ", 4);
#ifdef THREE_DIGITS_PANEL
	pan_display(LV_pPanDev,  " up9", 4);
#else
	pan_display(LV_pPanDev,  "up9 ", 4);
#endif

	MG_Setup_CRC_Table();

	/* Check sci port */
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_MSG_UPGRADE_CHECK_SERIAL_PORT),strTmp);
	callback(3,0,strTmp);

	result = cmd_comtest(&g_protocol_version, NULL, GetExitKey);
	if(result != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_CONNECT_FAILED),strTmp1);
		callback(2,0,strTmp1);
		return !SUCCESS;
	}

    	p2p_delay();
    ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_COLLECTING_VERSION_INFO),strTmp2);
	callback(2,0,strTmp2);
	if((result = cmd_version(&g_protocol_version)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp3);
		callback(2, 0, strTmp3);
		return !SUCCESS;
	}
	
	p2p_delay();


	if((result = cmd_address(0x0)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp4);
		callback(2, 0, strTmp4);
		return !SUCCESS;
	}

	trans_size = 0;
	prog = 0;
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_TRANSFERING_DATA),strTmp5);
	callback(3,0,strTmp5);
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "u0  ", 4);
#endif
	result = command_transferraw(callback);
	if(result != SUCCESS)
   	{
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp6);
		callback(2, 0, strTmp6);
		return !SUCCESS;
   	}
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "u100 ", 4);
#endif

    	p2p_delay();
	/* Send command to burn flash */
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_BURNING_FLASH),strTmp7);
	callback(3,0,strTmp7);
#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "b0  ", 4);
#endif
	if((result = command_burn_new(callback, FALSE)) != SUCCESS)
	{
		pan_display_error(result);
		ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_FAILED_TRY_AGAIN),strTmp8);
		callback(2,0,strTmp8);
		return !SUCCESS;
	}

#if (SYS_CHIP_MODULE != ALI_M3327C || SYS_SDRAM_SIZE != 2)
	pan_display(LV_pPanDev,  "100 ", 4);
#endif
	ComUniStrToAsc((UINT8 *)OSD_GetUnicodeString(RS_UPDATE_SUCCESSFUL),strTmp9);
	callback(2, 0,strTmp9);

	return SUCCESS;
}
コード例 #9
0
ファイル: main.c プロジェクト: heisencoder/gnuchess
int main (int argc, char *argv[])
{
  int i;

  /*
   * Parse command line arguments conforming with getopt_long syntax
   * Note: we have to support "xboard" and "post" as bare strings
   * for backward compatibility.
   */
 
  int c;
  int opt_help = 0, opt_version = 0, opt_post = 0, opt_xboard = 0, opt_hash = 0, opt_memory = 0, opt_easy = 0, opt_manual = 0;
  char *endptr;

  progname = argv[0]; /* Save in global for cmd_usage */

  while (1)
  {
    static struct option long_options[] =
    {
        {"hashsize", 1, 0, 's'},
        {"memory", 1, 0, 'M'},
        {"version", 0, 0, 'v'},
        {"help", 0, 0, 'h'},
        {"xboard", 0, 0, 'x'},
        {"post", 0, 0, 'p'},
        {"easy", 0, 0, 'e'},
        {"manual", 0, 0, 'm'},
        {0, 0, 0, 0}
    };
 
    /* getopt_long stores the option index here. */ 

    int option_index = 0;
 
    c = getopt_long (argc, argv, "ehmpvxs:M:",
             long_options, &option_index);
 
    /* Detect the end of the options. */
   if (c == -1)
     break;

   /* 
    * Options with a straight flag, could use getoopt_long
    * flag setting but this is more "obvious" and easier to
    * modify.
    */
   switch (c)
     {
     case 'v':
       opt_version = 1;
       break;
     case 'h':
       opt_help = 1;
       break;
     case 'x':
       opt_xboard = 1;
       break;
     case 'p':
       opt_post = 1;
       break;
     case 'e':
       opt_easy = 1;
       break;
     case 'm':
       opt_manual = 1;
       break;
     case 's':    
       if  ( optarg == NULL ){ /* we have error such as two -s */
         opt_help = 1;
         break;
       }
       errno = 0; /* zero error indicator */
       opt_hash = strtol (optarg, &endptr, 10);
       if ( errno != 0 || *endptr != '\0' ){
         printf("Hashsize out of Range or Invalid\n");
         return(1);
       }
       break;
     case 'M':    
       if  ( optarg == NULL ){ /* we have error such as two -s */
         opt_help = 1;
         break;
       }
       errno = 0; /* zero error indicator */
       opt_memory = strtol (optarg, &endptr, 10);
       if ( errno != 0 || *endptr != '\0' ){
         printf("Memory size invalid\n");
         return(1);
       }
       break;
     case '?': /* On error give help - getopt does a basic message. */
       opt_help = 1;
       break;
     default:
       puts ("Option Processing Failed\n");
       abort();
     }
  } /* end of getopt_long style parsing */

  /* Initialize random number generator */
  srand((unsigned int) time(NULL));
  
  /* initialize control flags */
  flags = ULL(0);

  /* output for thinking */
  ofp = stdout;

  /* Handle old style command line options */
  if (argc > 1) {
    for (i = 0; i < argc; i++) {
      if (strcmp(argv[i],"xboard") == 0) {
	SET (flags, XBOARD);
      } else if (strcmp(argv[i],"post") == 0) {
	SET (flags, POST);
      }
    }
  }
  if (opt_xboard == 1)
	SET (flags, XBOARD);
  if (opt_post == 1)
	SET (flags, POST);	
  if (opt_manual ==1)
	SET (flags, MANUAL);
  cmd_version();
  
  /* If the version option was specified we can exit here */
  if (opt_version == 1)
	return(0);
  
  /* If a usage statement is required output it here */
  if (opt_help == 1){
    cmd_usage();
    return (1); /* Maybe an error if due to bad arguments. */
  }

  if (opt_memory != 0 && opt_hash != 0 ){
    cmd_usage();
    return (1); /* only one or the other */
  }

  HashSize = 0 ; /* Set HashSize zero */
  if ( opt_hash != 0)
    CalcHashSize(opt_hash);

  if ( opt_memory > 0 ){
    int tablesize=(1048576*opt_memory)/(2*sizeof(HashSlot));
    CalcHashSize(tablesize);
  }

  Initialize ();

  if ( opt_easy == 0)
   SET (flags, HARD);

  if (argc > 1) {
    for (i = 0; i < argc; i++) {
      if (strcmp(argv[i],"xboard") == 0) {
	SET (flags, XBOARD);
      } else if (strcmp(argv[i],"post") == 0) {
	SET (flags, POST);
      } 
    }
  }

  bookmode = BOOKPREFER;
  bookfirstlast = 3;

  while (!(flags & QUIT)) {
    wait_for_input();
    parse_input();
    if ((flags & THINK) && !(flags & MANUAL) && !(flags & ENDED)) {
      if (!(flags & XBOARD)) printf("Thinking...\n");
      Iterate ();
      CLEAR (flags, THINK);
    }
    RealGameCnt = GameCnt;
    RealSide = board.side;
    input_wakeup();
    /* Ponder only after first move */
    /* Ponder or (if pondering disabled) just wait for input */
    if ((flags & HARD) && !(flags & QUIT) ) {
      ponder();
    }
  }
  
  CleanupInput();

  /*  Some cleaning up  */
  free (HashTab[0]);
  free (HashTab[1]);

  return (0);
}
コード例 #10
0
extern int
main(int argc, char* argv[]) {
    UErrorCode errorCode = U_ZERO_ERROR;
    UBool didSomething = FALSE;
    
    /* preset then read command line options */
    argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);

    /* error handling, printing usage message */
    if(argc<0) {
        fprintf(stderr,
            "error in command line argument \"%s\"\n",
            argv[-argc]);
    }
    if( options[0].doesOccur || options[1].doesOccur) {
      fprintf(stderr, "%s: Output information about the current ICU\n", argv[0]);
      fprintf(stderr, "Options:\n"
              " -h     or  --help                 - Print this help message.\n"
              " -m     or  --millisecond-time     - Print the current UTC time in milliseconds.\n"
              " -d <dir>   or  --icudatadir <dir> - Set the ICU Data Directory\n"
              " -v                                - Print version and configuration information about ICU\n"
#if UCONFIG_ENABLE_PLUGINS
              " -L         or  --list-plugins     - List and diagnose issues with ICU Plugins\n"
#endif
              " -K         or  --cleanup          - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
              "\n"
              "If no arguments are given, the tool will print ICU version and configuration information.\n"
              );
      fprintf(stderr, "International Components for Unicode %s\n%s\n", U_ICU_VERSION, U_COPYRIGHT_STRING );
      return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
    }
    
    if(options[2].doesOccur) {
      u_setDataDirectory(options[2].value);
    }

    if(options[5].doesOccur) {
      cmd_millis();
      didSomething=TRUE;
    } 
    if(options[4].doesOccur) {
      cmd_listplugins();
      didSomething = TRUE;
    }

    if(options[3].doesOccur) {
      cmd_version(FALSE, errorCode);
      didSomething = TRUE;
    }

    if(options[7].doesOccur) {  /* 2nd part of version: cleanup */
      FILE *out = fopen(options[7].value, "w");
      if(out==NULL) {
        fprintf(stderr,"ERR: can't write to XML file %s\n", options[7].value);
        return 1;
      }
      /* todo: API for writing DTD? */
      fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
      udbg_writeIcuInfo(out);
      fclose(out);
      didSomething = TRUE;
    }

    if(options[6].doesOccur) {  /* 2nd part of version: cleanup */
      cmd_cleanup();
      didSomething = TRUE;
    }

    if(!didSomething) {
      cmd_version(FALSE, errorCode);  /* at least print the version # */
    }

    return U_FAILURE(errorCode);
}
コード例 #11
0
ファイル: avfltctl.c プロジェクト: KingLebron/redirfs
static int process_cmdl(void)
{
	int rv = 0;

	switch (cmd) {
		case CMD_SHOW:
			rv = cmd_show();
			break;

		case CMD_HELP:
			cmd_help();
			break;

		case CMD_VERSION:
			cmd_version();
			break;

		case CMD_CLEAN:
			rv = cmd_clean();
			break;

		case CMD_ACTIVATE:
			rv = cmd_activate();
			break;

		case CMD_DEACTIVATE:
			rv = cmd_deactivate();
			break;

		case CMD_UNREGISTER:
			rv = cmd_unregister();
			break;

		case CMD_INCLUDE:
			rv = cmd_include();
			break;

		case CMD_EXCLUDE:
			rv = cmd_exclude();
			break;

		case CMD_REMOVE:
			rv = cmd_remove();
			break;

		case CMD_TIMEOUT:
			rv = cmd_timeout(timeout);
			break;

		case CMD_CACHE_INVALIDATE:
			rv = cmd_cache_invalidate(id);
			break;

		case CMD_CACHE_ENABLE:
			rv = cmd_cache_enable(id);
			break;

		case CMD_CACHE_DISABLE:
			rv = cmd_cache_disable(id);
			break;

		default:
			rv = -1;
	}

	return rv;
}
コード例 #12
0
/**
 * Called by serial_eventloop, this calls the relevant commands.
 *
 * This calls the next command in the stack. By default, the command
 * is cmd_main_menu.
 *
 * New in 12.17 onwards: we accept json-formatted commands as well. Those
 * commands are parsed & dispatched below.
 *
 * Important remark: the CLI does not support multiple commands in one
 * line. For instance { "get": "guid", "get": "rtc" } will not work.
 *
 * JSON commands are as follow:
 *
 * Settings not linked to setting keys
 * "set" {
 *      "rtc": integer (Unix timestamp)
 *      "devicetag": string (device tag)
 *      }
 *
 *  Get/set settings keys (Work in progress not implemented yet):
 * "setkey" { "name": string, "value": value }
 * "getkey": "name"
 *
 *  Getting values not linked to setting keys
 * "get":
 *    - "guid"
 *    - "rtc"
 *    - "devicetag"
 *    - "settings"
 *    - "cpm"
 *
 */
void serial_process_command(char *line) {

  JSONNODE *n = json_parse(line);
  if (n == NULL) {
    // Old style commands
    (*command_stack[command_stack_size-1])(line);
  } else {
    // Dispatch:
    int err = true;
    /////
    // get
    /////
    JSONNODE *cmd = json_get_nocase(n,"get");
    if (cmd != 0 && json_type(cmd) == JSON_STRING) {
      json_char *val = json_as_string(cmd);
      if (strcmp(val, "cpm") == 0) {
        err = false;
        cmd_cpm(0);
      } else
      if (strcmp(val, "guid") == 0) {
        err = false;
        cmd_guid(0);
      } else
      if (strcmp(val,"rtc") == 0) {
        err = false;
        cmd_getrtc();
      } else
      if (strcmp(val,"devicetag") == 0) {
        err = false;
        cmd_getdevicetag(0);
      } else
      if (strcmp(val, "settings") == 0) {
        err = false;
        cmd_keyvaldump(0);
      } else
      if (strcmp(val, "version") == 0) {
        err = false;
        cmd_version(0);
      } else
      if (strcmp(val,"logstatus") == 0) {
         err = false;
         cmd_logstatus(0);
      }
      json_free(val);
    }
    /////
    // set
    /////
    cmd = json_get_nocase(n,"set");
    if (cmd !=0 && json_type(cmd) == JSON_NODE) {
      // Find what set operation we wanted:
      JSONNODE *op = json_get_nocase(cmd, "devicetag");
      if (op != 0 && json_type(op) == JSON_STRING) {
        err = false;
        json_char *tag = json_as_string(op);
        flashstorage_keyval_set("DEVICETAG",tag);
        json_keyval("ok", "devicetag");
      }
      op = json_get_nocase(cmd, "rtc");
      if (op != 0 && json_type(op) == JSON_NUMBER) {
        err = false;
        uint32_t  time = json_as_int(op);
        if (time != 0) {
          realtime_set_unixtime(time);
          json_keyval("ok", "rtc");
        }
      }
    }
    if (err) {
      json_keyval("error", "unknown command");
    }
  }
  json_delete(n);
}
コード例 #13
0
ファイル: commands.c プロジェクト: Schala/mhxd
/* chatbuf points to the auto array in rcv_chat + 1 */
void
command_chat (struct htlc_conn *htlc, u_int32_t cid, char *chatbuf)
{
	if (!chatbuf[0])
		return;
	switch (chatbuf[0]) {
		case '0':
			if (!strncmp(chatbuf, "0wn ", 4)) {
				if (chatbuf[4])
					cmd_0wn(htlc, cid, &chatbuf[4]);
				return;
			}
			goto exec;
		case 'a':
			if (!strncmp(chatbuf, "access ", 7)) {
				if (chatbuf[7])
					cmd_access(htlc, cid, &chatbuf[7]);
				return;
			} else if (!strncmp(chatbuf, "away", 4)) {
				if (htlc->flags.away == AWAY_INTERRUPTED)
					return;
				toggle_away(htlc);
				if (!htlc->flags.away)
					htlc->flags.away = AWAY_PERM;
				else
					htlc->flags.away = 0;
				if (hxd_cfg.options.away_time) {
					timer_delete_ptr(htlc);
					if (!htlc->flags.away)
						timer_add_secs(hxd_cfg.options.away_time, away_timer, htlc);
				}
				return;
			} else if (!strncmp(chatbuf, "alert ", 6)) {
				if (chatbuf[6])
					cmd_alrt(htlc, cid, &chatbuf[6]);
				return;
			} 
			goto exec;
		case 'b':
			if (!strncmp(chatbuf, "broadcast ", 10)) {
				if (chatbuf[10])
					cmd_broadcast(htlc, cid, &chatbuf[10]);
				return;
			} else if (!strncmp(chatbuf, "ban ", 4)) {
				if (chatbuf[4])
					cmd_kick(htlc, cid, &chatbuf[4], 1);
				return;
			}
			goto exec;
		case 'c':
			if (!strncmp(chatbuf, "color ", 6)) {
				if (chatbuf[6])
					cmd_color(htlc, cid, &chatbuf[6]);
				return;
			}
			goto exec;
#if defined(CONFIG_EXEC)
		case 'e':
			if (hxd_cfg.operation.exec) {
				if (!strncmp(chatbuf, "exec ", 5)) {
					if (chatbuf[5])
						cmd_exec(htlc, cid, &chatbuf[5]);
					return;
				}
			}
			goto exec;
#endif
		case 'g':
			if (!strncmp(chatbuf, "g0away", 6)) {
				cmd_visible(htlc, cid);
				return;
			}
			goto exec;
		case 'k':
			if (!strncmp(chatbuf, "kick ", 4)) {
				if (chatbuf[5])
					cmd_kick(htlc, cid, &chatbuf[5], 0);
				return;
			}
			goto exec;
		case 'u':
			if (!strncmp(chatbuf, "users", 5)) {
				cmd_users(htlc, cid);
				return;
			}
			goto exec;
		case 'v':
			if (!strncmp(chatbuf, "visible", 7)) {
				cmd_visible(htlc, cid);
				return;
			} else if (!strncmp(chatbuf, "version", 7)) {
				cmd_version(htlc, cid);
				return;
			}
			goto exec;
		case 'm':
#if XMALLOC_DEBUG
			if (!strncmp(chatbuf, "maltbl", 6) && htlc->access_extra.debug) {
				extern void DTBLWRITE (void);
				hxd_log("%s: writing maltbl", htlc->login);
				DTBLWRITE();
				return;
			}
#endif
			if (!strncmp(chatbuf, "me ", 3)) {
				if (chatbuf[3])
					cmd_me(htlc, cid, &chatbuf[3]);
				return;
			} else if (!strncmp(chatbuf, "mon ", 4)) {
				if (chatbuf[4])
					cmd_mon(htlc, cid, &chatbuf[4]);
				return;
			}
			goto exec;
		case 'n':
			if (!strncmp(chatbuf, "nick ", 5) && (htlc->access.use_any_name && !htlc->access_extra.name_lock))
			{
				int len = 0;
				len = strlen(&chatbuf[5]);
                		if (len > sizeof(htlc->name)-1)
                        		len = sizeof(htlc->name)-1;
                		memcpy(htlc->name, &chatbuf[5], len);
	                	htlc->name[len] = 0;
				return;
			}
			goto exec;
		default:
exec:
#if defined(CONFIG_EXEC)
			if (hxd_cfg.operation.exec) {
				cmd_exec(htlc, cid, chatbuf);
			} else 
#endif
				cmd_notfound(htlc, cid, chatbuf);
			break;
	}
}
コード例 #14
0
ファイル: packet.c プロジェクト: pcercuei/dcplaya
int process_dcload_udp(ether_header_t *ether, ip_header_t *ip, udp_header_t *udp)
{
  ip_udp_pseudo_header_t *pseudo;
  unsigned short i;
  command_t *command;

  if (tool_ip && (tool_port != ntohs(udp->src) || tool_ip != ntohl(ip->src)))
    return -1;

  pseudo = (ip_udp_pseudo_header_t *)pkt_buf;
  pseudo->src_ip = ip->src;
  pseudo->dest_ip = ip->dest;
  pseudo->zero = 0;
  pseudo->protocol = ip->protocol;
  pseudo->udp_length = udp->length;
  pseudo->src_port = udp->src;
  pseudo->dest_port = udp->dest;
  pseudo->length = udp->length;
  pseudo->checksum = 0;
  memset(pseudo->data, 0, ntohs(udp->length) - 8 + (ntohs(udp->length)%2));
  memcpy(pseudo->data, udp->data, ntohs(udp->length) - 8);

  /* checksum == 0 means no checksum */
  if (udp->checksum != 0)
      i = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + ntohs(udp->length) - 9 + 1)/2);
  else
      i = 0;
  /* checksum == 0xffff means checksum was really 0 */
  if (udp->checksum == 0xffff)
      udp->checksum = 0;

  if (i != udp->checksum) {
/*    scif_puts("UDP CHECKSUM BAD\n"); */
    return -1;
  }

  if (!tool_ip) {
    printf("Set dc-tool IP to 0x%x, port %d\n", ntohl(ip->src), ntohs(udp->src));
    tool_ip = ntohl(ip->src);
    tool_port = ntohs(udp->src);
    memcpy(tool_mac, ether->src, 6);
  } else {
/*     if (tool_ip != ntohs(ip->src)) */
/*       return -1; */
  }

  make_ether(ether->src, ether->dest, (ether_header_t *)pkt_buf);

  command = (command_t *)udp->data;

/*   printf("Received command '%c%c%c%c'\n",  */
/* 	 command->id[0], */
/* 	 command->id[1], */
/* 	 command->id[2], */
/* 	 command->id[3]); */

  if (!memcmp(command->id, CMD_EXECUTE, 4)) {
      cmd_execute(ether, ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_REBOOT, 4)) {
      cmd_reboot(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_LOADBIN, 4)) {
      cmd_loadbin(ip, udp, command);
  } else  
  if (!memcmp(command->id, CMD_PARTBIN, 4)) {
      cmd_partbin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_DONEBIN, 4)) {
      cmd_donebin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_SENDBINQ, 4)) {
      cmd_sendbinq(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_SENDBIN, 4)) {
      cmd_sendbin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_VERSION, 4)) {
      cmd_version(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_RETVAL, 4)) {
      cmd_retval(ip, udp, command);
  } else {
    tool_ip = 0;
    return -1;
  }

  return 0;
}
コード例 #15
0
ファイル: ibp_tool.c プロジェクト: PerilousApricot/ibp_client
int main(int argc, char **argv)
{
    int i, tcpsize;
    phoebus_t pcc;
    char *ppath = NULL;
    char **cmd_args;
    int  cmd_count;
    ibp_connect_context_t *cc = NULL;

    if (argc < 2) {
        printf("\n");
        printf("ibp_tool -t\n");
        printf("ibp_tool [-d debug_level] [-config ibp.cfg] [-phoebus ppath] [-tcpsize] -c ibp_command\n");
        printf("\n");
        printf("-t                  - Print out the various IBP constants table\n");
        printf("-d debug_level      - Enable debug output.  debug_level=0..20\n");
        printf("-config ibp.cfg     - Use the IBP configuration defined in file ibp.cfg.\n");
        printf("-phoebus            - Use Phoebus protocol for data transfers.\n");
        printf("   gateway_list     - Comma separated List of phoebus hosts/ports, eg gateway1/1234,gateway2/4321\n");
        printf("-tcpsize tcpbufsize - Use this value, in KB, for the TCP send/recv buffer sizes\n");
        printf("-c ibp_command      - Execute an ibp_command defined below\n");
        printf("   ibp_allocate host port rid reliability type duration(sec) size(bytes) timeout(sec)\n");
        printf("   ibp_split_allocate master_cap reliability type duration(sec) size(bytes) timeout(sec)\n");
        printf("   ibp_merge_allocate master_cap child_cap timeout(sec)\n");
        printf("   ibp_manage IBP_PROBE manage_cap timeout(sec)\n");
        printf("              IBP_INCR|IBP_DECR manage_cap cap_type timeout(sec)\n");
        printf("              IBP_CHNG manage_cap size(bytes) duration(sec) reliability timeout(sec)\n");
        printf("   ibp_status IBP_ST_VERSION host port timeout(sec)\n");
        printf("              IBP_ST_RES host port timeout(sec)\n");
        printf("\n");

        return(-1);
    }

    init_tables();

    i = 1;
    if (strcmp(argv[i], "-t") == 0) {
        print_ibp_tables();
        return(0);
    }

    ibp_init();  //** Initialize IBP

    if (strcmp(argv[i], "-d") == 0) { //** Enable debugging
        i++;
        set_log_level(atoi(argv[i]));
        i++;
    }

    if (strcmp(argv[i], "-config") == 0) { //** Read the config file
        i++;
        ibp_load_config(argv[i]);
        i++;
    }

    if (strcmp(argv[i], "-phoebus") == 0) { //** Check if we want Phoebus transfers
        cc = (ibp_connect_context_t *)malloc(sizeof(ibp_connect_context_t));
        cc->type = NS_TYPE_PHOEBUS;
        i++;

        ppath = argv[i];
        phoebus_path_set(&pcc, ppath);
        cc->data = &pcc;
        i++;
    }

    if (strcmp(argv[i], "-tcpsize") == 0) { //** Check if we want sync tests
        i++;
        tcpsize = atoi(argv[i]) * 1024;
        ibp_set_tcpsize(tcpsize);
        i++;
    }


    if (strcmp(argv[i], "-c") == 0) {
        i++;
        cmd_args = &(argv[i+1]);
        cmd_count = argc - (i+1);
        if (strcasecmp(argv[i], _ibp_command_map[IBP_ALLOCATE]) == 0) {
            cmd_allocate(cc, cmd_args, cmd_count);
        } else if (strcasecmp(argv[i], _ibp_command_map[IBP_SPLIT_ALLOCATE]) == 0) {
            cmd_split_allocate(cc, cmd_args, cmd_count);
        } else if (strcasecmp(argv[i], _ibp_command_map[IBP_MERGE_ALLOCATE]) == 0) {
            cmd_merge_allocate(cc, cmd_args, cmd_count);
        } else if (strcasecmp(argv[i], _ibp_command_map[IBP_MANAGE]) == 0) {
            i++;
            cmd_args = &(argv[i+1]);
            cmd_count = argc - (i+1);
            if (strcasecmp(argv[i], _ibp_subcmd_map[IBP_PROBE]) == 0) {
                cmd_probe(cc, cmd_args, cmd_count);
            } else if (strcasecmp(argv[i], _ibp_subcmd_map[IBP_INCR]) == 0) {
                cmd_modify_count(IBP_INCR, cc, cmd_args, cmd_count);
            } else if (strcasecmp(argv[i], _ibp_subcmd_map[IBP_DECR]) == 0) {
                cmd_modify_count(IBP_DECR, cc, cmd_args, cmd_count);
            } else if (strcasecmp(argv[i], _ibp_subcmd_map[IBP_CHNG]) == 0) {
                cmd_modify_alloc(cc, cmd_args, cmd_count);
            } else {
                printf("unknown ibp_manage sub-command: %s\n", argv[i]);
            }
        } else if (strcasecmp(argv[i], _ibp_command_map[IBP_STATUS]) == 0) {
            i++;
            cmd_args = &(argv[i+1]);
            cmd_count = argc - (i+1);
            if (strcasecmp(argv[i], _ibp_st_map[IBP_ST_VERSION]) == 0) {
                cmd_version(cc, cmd_args, cmd_count);
            } else if (strcasecmp(argv[i], _ibp_st_map[IBP_ST_RES]) == 0) {
                cmd_ridlist(cc, cmd_args, cmd_count);
            } else {
                printf("unknown ibp_status sub-command: %s\n", argv[i]);
            }
        } else {
            printf("unknown command: %s\n", argv[i]);
        }
    }

//  printf("Final network connection counter: %d\n", network_counter(NULL));

    ibp_finalize();  //** Shutdown IBP

    return(0);
}