示例#1
0
static int init_server(tcp_listener_relay_server_type* server,
		       const char* ifname,
		       const char *local_address, 
		       int port, 
		       int verbose,
		       ioa_engine_handle e,
		       uint32_t *stats) {

  if(!server) return -1;

  server->stats=stats;

  if(ifname) STRCPY(server->ifname,ifname);

  if(make_ioa_addr((const u08bits*)local_address, port, &server->addr)<0) {
    return -1;
  }

  server->verbose=verbose;
  
  server->e = e;
  
  return create_server_listener(server);
}
示例#2
0
文件: log.c 项目: jinfeng-geeya/3202C
RET_CODE amslog_reg(INT32 mod_index, amslog_t *plog)
{    
	if (mod_index >= 0 && mod_index < (LOG_NUM+1))
	{
		if (STRLEN(plog->mod_name) < MAX_LOG_NAME_LENGTH)
			STRCPY(amslog[mod_index].mod_name, plog->mod_name);
		else
		{
			//error
			//#@$#@%, wait string.c to add STRNCPY function!!!!!
			//STRNCPY(amslog[mod_index].mod_name, plog->mod_name, MAX_LOG_NAME_LENGTH-1);
			//amslog[mod_index].mod_name[MAX_LOG_NAME_LENGTH-1] = '\0';
		}

        amslog[mod_index].log_level = plog->log_level;
        
		return SUCCESS;
	}
	else
	{
		//error!
		return ERR_PARA;
	}
}
示例#3
0
文件: str_var.c 项目: surki/hipl
/** Set or add data string, depending whether string is already defined. */
StringData *str_var_set(const char *name, const char *string, ...)
{
	/* Variables. */
	StringData *err = NULL, *st;
	va_list args;
	
	st = str_var_find(name);
	
	if (!st)
	{
		st = (StringData *)malloc(sizeof(StringData));
		HIP_IFEL(!st, NULL, "malloc()");
		memset(st, 0, sizeof(StringData));
		STRCPY(st->name, name);
		
		if (str_data_last)
		{
			str_data_last->next = (void *)st;
			str_data_last = st;
		}
		else
		{
			str_data = st;
			str_data_last = st;
		}

		str_count++;
	}
	
	va_start(args, string);
	VSPRINTHUGESTR(st->data, string, args);
	va_end(args);

out_err:
	return err;
}
示例#4
0
realm_params_t* get_realm(char* name)
{
	if(name && name[0]) {
		lock_realms();
		ur_string_map_value_type value = 0;
		ur_string_map_key_type key = (ur_string_map_key_type)name;
		if (ur_string_map_get(realms, key, &value)) {
			unlock_realms();
			return (realm_params_t*)value;
		} else {
			realm_params_t *ret = (realm_params_t*)turn_malloc(sizeof(realm_params_t));
			ns_bcopy(default_realm_params_ptr,ret,sizeof(realm_params_t));
			STRCPY(ret->options.name,name);
			value = (ur_string_map_value_type)ret;
			ur_string_map_put(realms, key, value);
			ret->status.alloc_counters =  ur_string_map_create(NULL);
			add_to_secrets_list(&realms_list, name);
			unlock_realms();
			return ret;
		}
	}

	return default_realm_params_ptr;
}
示例#5
0
int main(int argc, char **argv)
{
	int port = 0;
	int messagenumber = 5;
	char local_addr[256];
	int c;
	int mclient = 1;
	char peer_address[129] = "\0";
	int peer_port = PEER_DEFAULT_PORT;

	char rest_api_separator = ':';
	int use_null_cipher=0;

	set_logfile("stdout");

	set_execdir();

	set_system_parameters(0);

	ns_bzero(local_addr, sizeof(local_addr));

	while ((c = getopt(argc, argv, "d:p:l:n:L:m:e:r:u:w:i:k:z:W:C:E:F:vsyhcxXgtTSAPDNOUHMRIGB")) != -1) {
		switch (c){
		case 'B':
			random_disconnect = 1;
			break;
		case 'G':
			extra_requests = 1;
			break;
		case 'F':
			STRCPY(cipher_suite,optarg);
			break;
		case 'I':
			no_permissions = 1;
			break;
		case 'M':
			mobility = 1;
			break;
		case 'H':
			shatype = SHATYPE_SHA256;
			break;
		case 'E':
		{
			char* fn = find_config_file(optarg,1);
			if(!fn) {
				fprintf(stderr,"ERROR: file %s not found\n",optarg);
				exit(-1);
			}
			STRCPY(ca_cert_file,fn);
		}
			break;
		case 'O':
			dos = 1;
			break;
		case 'C':
			rest_api_separator=*optarg;
			break;
		case 'D':
			mandatory_channel_padding = 1;
			break;
		case 'N':
			negative_test = 1;
			break;
		case 'R':
			negative_protocol_test = 1;
			break;
		case 'z':
			RTP_PACKET_INTERVAL = atoi(optarg);
			break;
		case 'A':
			use_short_term = 1;
			break;
		case 'u':
			STRCPY(g_uname, optarg);
			break;
		case 'w':
			STRCPY(g_upwd, optarg);
			break;
		case 'g':
			dont_fragment = 1;
			break;
		case 'd':
			STRCPY(client_ifname, optarg);
			break;
		case 'x':
			default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
			break;
		case 'X':
			default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4;
			break;
		case 'l':
			clmessage_length = atoi(optarg);
			break;
		case 's':
			do_not_use_channel = 1;
			break;
		case 'n':
			messagenumber = atoi(optarg);
			break;
		case 'p':
			port = atoi(optarg);
			break;
		case 'L':
			STRCPY(local_addr, optarg);
			break;
		case 'e':
			STRCPY(peer_address, optarg);
			break;
		case 'r':
			peer_port = atoi(optarg);
			break;
		case 'v':
			clnet_verbose = TURN_VERBOSE_NORMAL;
			break;
		case 'h':
			hang_on = 1;
			break;
		case 'c':
			no_rtcp = 1;
			break;
		case 'm':
			mclient = atoi(optarg);
			break;
		case 'y':
			c2c = 1;
			break;
		case 't':
			use_tcp = 1;
			break;
		case 'P':
			passive_tcp = 1;
			/* implies 'T': */
			/* no break */
		case 'T':
			relay_transport = STUN_ATTRIBUTE_TRANSPORT_TCP_VALUE;
			break;
		case 'U':
		  use_null_cipher = 1;
		  /* implies 'S' */
		  /* no break */
		case 'S':
			use_secure = 1;
			break;
		case 'W':
			g_use_auth_secret_with_timestamp = 1;
			STRCPY(g_auth_secret,optarg);
			break;
		case 'i':
		{
			char* fn = find_config_file(optarg,1);
			if(!fn) {
				fprintf(stderr,"ERROR: file %s not found\n",optarg);
				exit(-1);
			}
			STRCPY(cert_file,fn);
			free(fn);
		}
			break;
		case 'k':
		{
			char* fn = find_config_file(optarg,1);
			if(!fn) {
				fprintf(stderr,"ERROR: file %s not found\n",optarg);
				exit(-1);
			}
			STRCPY(pkey_file,fn);
			free(fn);
		}
			break;
		default:
			fprintf(stderr, "%s\n", Usage);
			exit(1);
		}
	}

	if(g_use_auth_secret_with_timestamp) {

		if(use_short_term) {
			fprintf(stderr,"ERROR: You cannot use authentication secret (REST API) with short-term credentials mechanism.\n");
			exit(-1);
		}
		{
			char new_uname[1025];
			const unsigned long exp_time = 3600 * 24; /* one day */
			if(g_uname[0]) {
			  snprintf(new_uname,sizeof(new_uname),"%lu%c%s",(unsigned long)time(NULL) + exp_time,rest_api_separator, (char*)g_uname);
			} else {
			  snprintf(new_uname,sizeof(new_uname),"%lu", (unsigned long)time(NULL) + exp_time);
			}
			STRCPY(g_uname,new_uname);
		}
		{
			u08bits hmac[MAXSHASIZE];
			unsigned int hmac_len;

			switch(shatype) {
			case SHATYPE_SHA256:
				hmac_len = SHA256SIZEBYTES;
				break;
			default:
				hmac_len = SHA1SIZEBYTES;
			};

			hmac[0]=0;

			if(stun_calculate_hmac(g_uname, strlen((char*)g_uname), (u08bits*)g_auth_secret, strlen(g_auth_secret), hmac, &hmac_len, shatype)>=0) {
				size_t pwd_length = 0;
				char *pwd = base64_encode(hmac,hmac_len,&pwd_length);

				if(pwd) {
					if(pwd_length>0) {
						ns_bcopy(pwd,g_upwd,pwd_length);
						g_upwd[pwd_length]=0;
					}
				}
				free(pwd);
			}
		}
	}

	if(is_TCP_relay()) {
		dont_fragment = 0;
		no_rtcp = 1;
		c2c = 1;
		use_tcp = 1;
		do_not_use_channel = 1;
	}

	if(port == 0) {
		if(use_secure)
			port = DEFAULT_STUN_TLS_PORT;
		else
			port = DEFAULT_STUN_PORT;
	}

	if (clmessage_length < (int) sizeof(message_info))
		clmessage_length = (int) sizeof(message_info);

	const int max_header = 100;
	if(clmessage_length > (int)(STUN_BUFFER_SIZE-max_header)) {
		fprintf(stderr,"Message length was corrected to %d\n",(STUN_BUFFER_SIZE-max_header));
		clmessage_length = (int)(STUN_BUFFER_SIZE-max_header);
	}

	if (optind >= argc) {
		fprintf(stderr, "%s\n", Usage);
		exit(-1);
	}

	if (!c2c) {
		if (make_ioa_addr((const u08bits*) peer_address, peer_port, &peer_addr) < 0)
			return -1;
		if(peer_addr.ss.sa_family == AF_INET6)
			default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;

	}

	/* SSL Init ==>> */

	if(use_secure) {

		SSL_load_error_strings();
		OpenSSL_add_ssl_algorithms();

		const char *csuite = "ALL"; //"AES256-SHA" "DH"
		if(use_null_cipher)
			csuite = "eNULL";
		else if(cipher_suite[0])
			csuite=cipher_suite;

		if(use_tcp) {
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(SSLv23_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(SSLv3_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
#if defined(SSL_TXT_TLSV1_1)
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_1_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
#if defined(SSL_TXT_TLSV1_2)
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_2_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
#endif
#endif
		} else {
#if defined(TURN_NO_DTLS)
		  fprintf(stderr,"ERROR: DTLS is not supported.\n");
		  exit(-1);
#else
		  if(OPENSSL_VERSION_NUMBER < 0x10000000L) {
		  	TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "WARNING: OpenSSL version is rather old, DTLS may not be working correctly.\n");
		  }
		  root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(DTLSv1_client_method());
		  SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite);
		  root_tls_ctx_num++;
#endif
		}

		int sslind = 0;
		for(sslind = 0; sslind<root_tls_ctx_num; sslind++) {

			if(cert_file[0]) {
				if (!SSL_CTX_use_certificate_chain_file(root_tls_ctx[sslind], cert_file)) {
					TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: no certificate found!\n");
					exit(-1);
				}
			}

			if (!SSL_CTX_use_PrivateKey_file(root_tls_ctx[sslind], pkey_file,
						SSL_FILETYPE_PEM)) {
				TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: no private key found!\n");
				exit(-1);
			}

			if(cert_file[0]) {
				if (!SSL_CTX_check_private_key(root_tls_ctx[sslind])) {
					TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: invalid private key!\n");
					exit(-1);
				}
			}

			if (ca_cert_file[0]) {
				if (!SSL_CTX_load_verify_locations(root_tls_ctx[sslind], ca_cert_file, NULL )) {
					TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
							"ERROR: cannot load CA from file: %s\n",
							ca_cert_file);
				}

				/* Set to require peer (client) certificate verification */
				SSL_CTX_set_verify(root_tls_ctx[sslind], SSL_VERIFY_PEER, NULL );

				/* Set the verification depth to 9 */
				SSL_CTX_set_verify_depth(root_tls_ctx[sslind], 9);
			} else {
				SSL_CTX_set_verify(root_tls_ctx[sslind], SSL_VERIFY_NONE, NULL );
			}

			if(!use_tcp)
				SSL_CTX_set_read_ahead(root_tls_ctx[sslind], 1);
		}
	}

	start_mclient(argv[optind], port, client_ifname, local_addr, messagenumber, mclient);

	return 0;
}
示例#6
0
//////////////////////////////////////////////////////////////////////////////
//! Find the path for a file assuming that
//! files are found in the searchPath.
//!
//! @return the path if succeeded, otherwise 0
//! @param filename         name of the file
//! @param executable_path  optional absolute path of the executable
//////////////////////////////////////////////////////////////////////////////
inline char *sdkFindFilePath(const char *filename, const char *executable_path)
{
    // <executable_name> defines a variable that is replaced with the name of the executable

    // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files)
    // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc
    const char *searchPath[] =
            {
                    "./",                                       // same dir
                    "./common/",                                // "/common/" subdir
                    "./common/data/",                           // "/common/data/" subdir
                    "./data/",                                  // "/data/" subdir
                    "./src/",                                   // "/src/" subdir
                    "./src/<executable_name>/data/",            // "/src/<executable_name>/data/" subdir
                    "./inc/",                                   // "/inc/" subdir
                    "./0_Simple/",                              // "/0_Simple/" subdir
                    "./1_Utilities/",                           // "/1_Utilities/" subdir
                    "./2_Graphics/",                            // "/2_Graphics/" subdir
                    "./3_Imaging/",                             // "/3_Imaging/" subdir
                    "./4_Finance/",                             // "/4_Finance/" subdir
                    "./5_Simulations/",                         // "/5_Simulations/" subdir
                    "./6_Advanced/",                            // "/6_Advanced/" subdir
                    "./7_CUDALibraries/",                       // "/7_CUDALibraries/" subdir
                    "./8_Android/",                             // "/8_Android/" subdir
                    "./samples/",                               // "/samples/" subdir

                    "../",                                      // up 1 in tree
                    "../common/",                               // up 1 in tree, "/common/" subdir
                    "../common/data/",                          // up 1 in tree, "/common/data/" subdir
                    "../data/",                                 // up 1 in tree, "/data/" subdir
                    "../src/",                                  // up 1 in tree, "/src/" subdir
                    "../inc/",                                  // up 1 in tree, "/inc/" subdir

                    "../0_Simple/<executable_name>/data/",       // up 1 in tree, "/0_Simple/<executable_name>/" subdir
                    "../1_Utilities/<executable_name>/data/",    // up 1 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../2_Graphics/<executable_name>/data/",     // up 1 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../3_Imaging/<executable_name>/data/",      // up 1 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../4_Finance/<executable_name>/data/",      // up 1 in tree, "/4_Finance/<executable_name>/" subdir
                    "../5_Simulations/<executable_name>/data/",  // up 1 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../6_Advanced/<executable_name>/data/",     // up 1 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../7_CUDALibraries/<executable_name>/data/",// up 1 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../8_Android/<executable_name>/data/",      // up 1 in tree, "/8_Android/<executable_name>/" subdir
                    "../samples/<executable_name>/data/",        // up 1 in tree, "/samples/<executable_name>/" subdir
                    "../../",                                        // up 2 in tree
                    "../../common/",                                 // up 2 in tree, "/common/" subdir
                    "../../common/data/",                            // up 2 in tree, "/common/data/" subdir
                    "../../data/",                                   // up 2 in tree, "/data/" subdir
                    "../../src/",                                    // up 2 in tree, "/src/" subdir
                    "../../inc/",                                    // up 2 in tree, "/inc/" subdir
                    "../../sandbox/<executable_name>/data/",         // up 2 in tree, "/sandbox/<executable_name>/" subdir
                    "../../0_Simple/<executable_name>/data/",        // up 2 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../1_Utilities/<executable_name>/data/",     // up 2 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../2_Graphics/<executable_name>/data/",      // up 2 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../3_Imaging/<executable_name>/data/",       // up 2 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../4_Finance/<executable_name>/data/",       // up 2 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../5_Simulations/<executable_name>/data/",   // up 2 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../6_Advanced/<executable_name>/data/",      // up 2 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../7_CUDALibraries/<executable_name>/data/", // up 2 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../8_Android/<executable_name>/data/",       // up 2 in tree, "/8_Android/<executable_name>/" subdir
                    "../../samples/<executable_name>/data/",         // up 2 in tree, "/samples/<executable_name>/" subdir
                    "../../../",                                        // up 3 in tree
                    "../../../src/<executable_name>/",                  // up 3 in tree, "/src/<executable_name>/" subdir
                    "../../../src/<executable_name>/data/",             // up 3 in tree, "/src/<executable_name>/data/" subdir
                    "../../../src/<executable_name>/src/",              // up 3 in tree, "/src/<executable_name>/src/" subdir
                    "../../../src/<executable_name>/inc/",              // up 3 in tree, "/src/<executable_name>/inc/" subdir
                    "../../../sandbox/<executable_name>/",              // up 3 in tree, "/sandbox/<executable_name>/" subdir
                    "../../../sandbox/<executable_name>/data/",         // up 3 in tree, "/sandbox/<executable_name>/data/" subdir
                    "../../../sandbox/<executable_name>/src/",          // up 3 in tree, "/sandbox/<executable_name>/src/" subdir
                    "../../../sandbox/<executable_name>/inc/",          // up 3 in tree, "/sandbox/<executable_name>/inc/" subdir
                    "../../../0_Simple/<executable_name>/data/",        // up 3 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../../1_Utilities/<executable_name>/data/",     // up 3 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../../2_Graphics/<executable_name>/data/",      // up 3 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../../3_Imaging/<executable_name>/data/",       // up 3 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../../4_Finance/<executable_name>/data/",       // up 3 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../../5_Simulations/<executable_name>/data/",   // up 3 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../../6_Advanced/<executable_name>/data/",      // up 3 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../../7_CUDALibraries/<executable_name>/data/", // up 3 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../../8_Android/<executable_name>/data/",       // up 3 in tree, "/8_Android/<executable_name>/" subdir
                    "../../../0_Simple/<executable_name>/",        // up 3 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../../1_Utilities/<executable_name>/",     // up 3 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../../2_Graphics/<executable_name>/",      // up 3 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../../3_Imaging/<executable_name>/",       // up 3 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../../4_Finance/<executable_name>/",       // up 3 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../../5_Simulations/<executable_name>/",   // up 3 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../../6_Advanced/<executable_name>/",      // up 3 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../../7_CUDALibraries/<executable_name>/", // up 3 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../../8_Android/<executable_name>/",       // up 3 in tree, "/8_Android/<executable_name>/" subdir
                    "../../../samples/<executable_name>/data/",         // up 3 in tree, "/samples/<executable_name>/" subdir
                    "../../../common/",                                 // up 3 in tree, "../../../common/" subdir
                    "../../../common/data/",                            // up 3 in tree, "../../../common/data/" subdir
                    "../../../data/",                                   // up 3 in tree, "../../../data/" subdir
                    "../../../../",                                // up 4 in tree
                    "../../../../src/<executable_name>/",          // up 4 in tree, "/src/<executable_name>/" subdir
                    "../../../../src/<executable_name>/data/",     // up 4 in tree, "/src/<executable_name>/data/" subdir
                    "../../../../src/<executable_name>/src/",      // up 4 in tree, "/src/<executable_name>/src/" subdir
                    "../../../../src/<executable_name>/inc/",      // up 4 in tree, "/src/<executable_name>/inc/" subdir
                    "../../../../sandbox/<executable_name>/",      // up 4 in tree, "/sandbox/<executable_name>/" subdir
                    "../../../../sandbox/<executable_name>/data/", // up 4 in tree, "/sandbox/<executable_name>/data/" subdir
                    "../../../../sandbox/<executable_name>/src/",  // up 4 in tree, "/sandbox/<executable_name>/src/" subdir
                    "../../../../sandbox/<executable_name>/inc/",   // up 4 in tree, "/sandbox/<executable_name>/inc/" subdir
                    "../../../../0_Simple/<executable_name>/data/",     // up 4 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../../../1_Utilities/<executable_name>/data/",  // up 4 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../../../2_Graphics/<executable_name>/data/",   // up 4 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../../../3_Imaging/<executable_name>/data/",    // up 4 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../../../4_Finance/<executable_name>/data/",    // up 4 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../../../5_Simulations/<executable_name>/data/",// up 4 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../../../6_Advanced/<executable_name>/data/",   // up 4 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../../../7_CUDALibraries/<executable_name>/data/", // up 4 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../../../8_Android/<executable_name>/data/",    // up 4 in tree, "/8_Android/<executable_name>/" subdir
                    "../../../../0_Simple/<executable_name>/",     // up 4 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../../../1_Utilities/<executable_name>/",  // up 4 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../../../2_Graphics/<executable_name>/",   // up 4 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../../../3_Imaging/<executable_name>/",    // up 4 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../../../4_Finance/<executable_name>/",    // up 4 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../../../5_Simulations/<executable_name>/",// up 4 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../../../6_Advanced/<executable_name>/",   // up 4 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../../../7_CUDALibraries/<executable_name>/", // up 4 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../../../8_Android/<executable_name>/",    // up 4 in tree, "/8_Android/<executable_name>/" subdir
                    "../../../../samples/<executable_name>/data/",      // up 4 in tree, "/samples/<executable_name>/" subdir
                    "../../../../common/",                              // up 4 in tree, "../../../common/" subdir
                    "../../../../common/data/",                         // up 4 in tree, "../../../common/data/" subdir
                    "../../../../data/",                                // up 4 in tree, "../../../data/" subdir
                    "../../../../../",                                // up 5 in tree
                    "../../../../../src/<executable_name>/",          // up 5 in tree, "/src/<executable_name>/" subdir
                    "../../../../../src/<executable_name>/data/",     // up 5 in tree, "/src/<executable_name>/data/" subdir
                    "../../../../../src/<executable_name>/src/",      // up 5 in tree, "/src/<executable_name>/src/" subdir
                    "../../../../../src/<executable_name>/inc/",      // up 5 in tree, "/src/<executable_name>/inc/" subdir
                    "../../../../../sandbox/<executable_name>/",      // up 5 in tree, "/sandbox/<executable_name>/" subdir
                    "../../../../../sandbox/<executable_name>/data/", // up 5 in tree, "/sandbox/<executable_name>/data/" subdir
                    "../../../../../sandbox/<executable_name>/src/",  // up 5 in tree, "/sandbox/<executable_name>/src/" subdir
                    "../../../../../sandbox/<executable_name>/inc/",   // up 5 in tree, "/sandbox/<executable_name>/inc/" subdir
                    "../../../../../0_Simple/<executable_name>/data/",     // up 5 in tree, "/0_Simple/<executable_name>/" subdir
                    "../../../../../1_Utilities/<executable_name>/data/",  // up 5 in tree, "/1_Utilities/<executable_name>/" subdir
                    "../../../../../2_Graphics/<executable_name>/data/",   // up 5 in tree, "/2_Graphics/<executable_name>/" subdir
                    "../../../../../3_Imaging/<executable_name>/data/",    // up 5 in tree, "/3_Imaging/<executable_name>/" subdir
                    "../../../../../4_Finance/<executable_name>/data/",    // up 5 in tree, "/4_Finance/<executable_name>/" subdir
                    "../../../../../5_Simulations/<executable_name>/data/",// up 5 in tree, "/5_Simulations/<executable_name>/" subdir
                    "../../../../../6_Advanced/<executable_name>/data/",   // up 5 in tree, "/6_Advanced/<executable_name>/" subdir
                    "../../../../../7_CUDALibraries/<executable_name>/data/", // up 5 in tree, "/7_CUDALibraries/<executable_name>/" subdir
                    "../../../../../8_Android/<executable_name>/data/",    // up 5 in tree, "/8_Android/<executable_name>/" subdir
                    "../../../../../samples/<executable_name>/data/",      // up 5 in tree, "/samples/<executable_name>/" subdir
                    "../../../../../common/",                         // up 5 in tree, "../../../common/" subdir
                    "../../../../../common/data/",                    // up 5 in tree, "../../../common/data/" subdir
            };

    // Extract the executable name
    std::string executable_name;

    if (executable_path != 0)
    {
        executable_name = std::string(executable_path);

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
        // Windows path delimiter
        size_t delimiter_pos = executable_name.find_last_of('\\');
        executable_name.erase(0, delimiter_pos + 1);

        if (executable_name.rfind(".exe") != std::string::npos)
        {
            // we strip .exe, only if the .exe is found
            executable_name.resize(executable_name.size() - 4);
        }

#else
        // Linux & OSX path delimiter
        size_t delimiter_pos = executable_name.find_last_of('/');
        executable_name.erase(0,delimiter_pos+1);
#endif
    }

    // Loop over all search paths and return the first hit
    for (unsigned int i = 0; i < sizeof(searchPath)/sizeof(char *); ++i)
    {
        std::string path(searchPath[i]);
        size_t executable_name_pos = path.find("<executable_name>");

        // If there is executable_name variable in the searchPath
        // replace it with the value
        if (executable_name_pos != std::string::npos)
        {
            if (executable_path != 0)
            {
                path.replace(executable_name_pos, strlen("<executable_name>"), executable_name);
            }
            else
            {
                // Skip this path entry if no executable argument is given
                continue;
            }
        }

#ifdef _DEBUG
        printf("sdkFindFilePath <%s> in %s\n", filename, path.c_str());
#endif

        // Test if the file exists
        path.append(filename);
        FILE *fp;
        FOPEN(fp, path.c_str(), "rb");

        if (fp != NULL)
        {
            fclose(fp);
            // File found
            // returning an allocated array here for backwards compatibility reasons
            char *file_path = (char *) malloc(path.length() + 1);
            STRCPY(file_path, path.length() + 1, path.c_str());
            return file_path;
        }

        if (fp)
        {
            fclose(fp);
        }
    }

    // File not found
    return 0;
}
示例#7
0
void AAIConfig::LoadConfig(AAI *ai)
{
	// this size equals the one used in "AIAICallback::GetValue(AIVAL_LOCATE_FILE_..."
	char filename[2048];
	char buffer[500];

	MAX_UNITS = ai->Getcb()->GetMaxUnits();

	FILE* file = NULL;

	STRCPY_T(buffer, sizeof(buffer), MAIN_PATH);
	STRCAT_T(buffer, sizeof(buffer), MOD_CFG_PATH);
	const std::string modHumanName = MakeFileSystemCompatible(ai->Getcb()->GetModHumanName());
	STRCAT_T(buffer, sizeof(buffer), modHumanName.c_str());
	STRCAT_T(buffer, sizeof(buffer), ".cfg");
	STRCPY_T(filename, sizeof(filename), buffer);
	ai->Getcb()->GetValue(AIVAL_LOCATE_FILE_R, filename);
	file = fopen(filename, "r");
	if (file == NULL) {
		ai->Log("Mod config file %s not found\n", filename);
		ai->Log("Now trying with legacy mod config file name ...\n");
		STRCPY_T(buffer, sizeof(buffer), MAIN_PATH);
		STRCAT_T(buffer, sizeof(buffer), MOD_CFG_PATH);
		const std::string modName = MakeFileSystemCompatible(ai->Getcb()->GetModName());
		STRCAT_T(buffer, sizeof(buffer), modName.c_str());
		ReplaceExtension(buffer, filename, sizeof(filename), ".cfg");
		ai->Getcb()->GetValue(AIVAL_LOCATE_FILE_R, filename);
		file = fopen(filename, "r");
	}
	if (file == NULL) {
		ai->Log("Mod config file %s not found\n", filename);
		ai->Log("Now trying with version independent mod config file name ...\n");
		STRCPY_T(buffer, sizeof(buffer), MAIN_PATH);
		STRCAT_T(buffer, sizeof(buffer), MOD_CFG_PATH);
		const std::string modShortName = MakeFileSystemCompatible(ai->Getcb()->GetModShortName());
		STRCAT_T(buffer, sizeof(buffer), modShortName.c_str());
		STRCAT_T(buffer, sizeof(buffer), ".cfg");
		STRCPY_T(filename, sizeof(filename), buffer);
		ai->Getcb()->GetValue(AIVAL_LOCATE_FILE_R, filename);
		file = fopen(filename, "r");
	}
	if (file == NULL) {
		ai->Log("Mod config file %s not found\n", filename);
		ai->Log("Give up trying to find mod config file (required).\n");
		initialized = false;
		return;
	}

	char keyword[50];
	int ival;
	float fval;
	const UnitDef *def;

	bool error = false;
//	bool loaded = false;

	if(file)
	{
		ai->Log("Using mod config file %s\n", filename);

		while(EOF != fscanf(file, "%s", keyword))
		{
			if(!strcmp(keyword,"SIDES"))
			{
				fscanf(file, "%i", &ival);
				SIDES = ival;
			}
			else if(!strcmp(keyword, "START_UNITS"))
			{
				START_UNITS = new char*[SIDES];

				for(int i = 0; i < SIDES; i++)
				{
					START_UNITS[i] = new char[20];
					fscanf(file, "%s", filename);
					STRCPY(START_UNITS[i], filename);

					if(!ai->Getcb()->GetUnitDef(START_UNITS[i]))
					{
						ai->Log("ERROR: loading starting units - could not find unit %s\n", START_UNITS[i]);
						error = true;
						break;
					}
				}
			}
			else if(!strcmp(keyword, "SIDE_NAMES"))
			{
				SIDE_NAMES = new char*[SIDES];

				for(int i = 0; i < SIDES; i++)
				{
					SIDE_NAMES[i] = new char[80];
					fscanf(file, "%s", filename);
					STRCPY(SIDE_NAMES[i], filename);
				}
			}
			else if(!strcmp(keyword, "SCOUTS"))
			{
				// get number of scouts
				fscanf(file, "%i", &ival);

				for(int i = 0; i < ival; ++i)
				{
					fscanf(file, "%s", filename);
					if(ai->Getcb()->GetUnitDef(filename))
						SCOUTS.push_back(ai->Getcb()->GetUnitDef(filename)->id);
					else
					{
						ai->Log("ERROR: loading scouts - could not find unit %s\n", filename);
						error = true;
						break;
					}
				}
			}
			else if(!strcmp(keyword, "ATTACKERS"))
			{
				// get number of attackers
				fscanf(file, "%i", &ival);

				for(int i = 0; i < ival; ++i)
				{
					fscanf(file, "%s", filename);
					if(ai->Getcb()->GetUnitDef(filename))
						ATTACKERS.push_back(ai->Getcb()->GetUnitDef(filename)->id);
					else
					{
						ai->Log("ERROR: loading attackers - could not find unit %s\n", filename);
						error = true;
						break;
					}
				}
			}
			else if(!strcmp(keyword, "TRANSPORTERS"))
			{
				// get number of transporters
				fscanf(file, "%i", &ival);

				for(int i = 0; i < ival; ++i)
				{
					fscanf(file, "%s", filename);
					if(ai->Getcb()->GetUnitDef(filename))
						TRANSPORTERS.push_back(ai->Getcb()->GetUnitDef(filename)->id);
					else
					{
						ai->Log("ERROR: loading transporters - could not find unit %s\n", filename);
						error = true;
						break;
					}
				}
			}
			else if(!strcmp(keyword, "DONT_BUILD"))
			{
				// get number of units that should not be built
				fscanf(file, "%i", &ival);

				for(int i = 0; i < ival; ++i)
				{
					fscanf(file, "%s", filename);
					if(ai->Getcb()->GetUnitDef(filename))
						DONT_BUILD.push_back(ai->Getcb()->GetUnitDef(filename)->id);
					else
					{
						ai->Log("ERROR: loading dont_build units - could not find unit %s\n", filename);
						error = true;
						break;
					}
				}
			}
			else if(!strcmp(keyword, "COST_MULTIPLIER"))
			{
				// get the unit def
				fscanf(file, "%s", filename);
				def = ai->Getcb()->GetUnitDef(filename);

				if(def)
				{
					fscanf(file, "%f", &fval);

					CostMultiplier temp;
					temp.id = def->id;
					temp.multiplier = fval;

					cost_multipliers.push_back(temp);
				}
				else
				{
					ai->Log("ERROR: could not set cost multiplier - could not find unit %s\n", filename);
					error = true;
					break;
				}
			}
			else if(!strcmp(keyword,"SECTOR_SIZE"))
			{
				fscanf(file, "%f", &fval);
				SECTOR_SIZE = fval;
				ai->Log("SECTOR_SIZE set to %f", SECTOR_SIZE);
			}
			else if(!strcmp(keyword,"MIN_ENERGY"))
			{
				fscanf(file, "%i", &ival);
				MIN_ENERGY = ival;
			}
			else if(!strcmp(keyword, "MAX_UNITS"))
			{
				fscanf(file, "%i", &ival);
				MAX_UNITS = ival;
			}
			else if(!strcmp(keyword, "MAX_SCOUTS"))
			{
				fscanf(file, "%i", &ival);
				MAX_SCOUTS = ival;
			}
			else if(!strcmp(keyword, "MAX_SECTOR_IMPORTANCE"))
			{
				fscanf(file, "%i", &ival);
				MAX_SECTOR_IMPORTANCE = ival;
			}
			else if(!strcmp(keyword, "MAX_XROW"))
			{
				fscanf(file, "%i", &ival);
				MAX_XROW = ival;
			}
			else if(!strcmp(keyword, "MAX_YROW"))
			{
				fscanf(file, "%i", &ival);
				MAX_YROW = ival;
			}
			else if(!strcmp(keyword, "X_SPACE"))
			{
				fscanf(file, "%i", &ival);
				X_SPACE = ival;
			}
			else if(!strcmp(keyword, "Y_SPACE"))
			{
				fscanf(file, "%i", &ival);
				Y_SPACE = ival;
			}
			else if(!strcmp(keyword, "MAX_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_AIR_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_AIR_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_NAVAL_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_NAVAL_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_SUBMARINE_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_SUBMARINE_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_ANTI_AIR_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_ANTI_AIR_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_ARTY_GROUP_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_ARTY_GROUP_SIZE = ival;
			}
			else if(!strcmp(keyword, "UNIT_SPEED_SUBGROUPS"))
			{
				fscanf(file, "%i", &ival);
				UNIT_SPEED_SUBGROUPS = ival;
			}
			else if(!strcmp(keyword, "FALLBACK_DIST_RATIO"))
			{
				fscanf(file, "%f", &fval);
				FALLBACK_DIST_RATIO = fval;
			}
			else if(!strcmp(keyword, "MIN_FALLBACK_RANGE"))
			{
				fscanf(file, "%f", &fval);
				MIN_FALLBACK_RANGE = fval;
			}
			else if(!strcmp(keyword, "MAX_FALLBACK_RANGE"))
			{
				fscanf(file, "%f", &fval);
				MAX_FALLBACK_RANGE = fval;
			}
			else if(!strcmp(keyword, "MIN_FALLBACK_TURNRATE"))
			{
				fscanf(file, "%f", &fval);
				MIN_FALLBACK_TURNRATE = fval;
			}
			else if(!strcmp(keyword, "MIN_EFFICIENCY"))
			{
				fscanf(file, "%f", &fval);
				MIN_EFFICIENCY = fval;
			}
			else if(!strcmp(keyword, "MIN_AIR_SUPPORT_EFFICIENCY"))
			{
				fscanf(file, "%f", &fval);
				MIN_AIR_SUPPORT_EFFICIENCY = fval;
			}
			else if(!strcmp(keyword, "MAX_BUILDERS"))
			{
				fscanf(file, "%i", &ival);
				MAX_BUILDERS = ival;
			}
			else if(!strcmp(keyword, "MAX_BUILDQUE_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_BUILDQUE_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_ASSISTANTS"))
			{
				fscanf(file, "%i", &ival);
				MAX_ASSISTANTS = ival;
			}
			else if(!strcmp(keyword, "MIN_ASSISTANCE_BUILDSPEED"))
			{
				fscanf(file, "%i", &ival);
				MIN_ASSISTANCE_BUILDSPEED = ival;
			}
			else if(!strcmp(keyword, "MAX_BASE_SIZE"))
			{
				fscanf(file, "%i", &ival);
				MAX_BASE_SIZE = ival;
			}
			else if(!strcmp(keyword, "MAX_AIR_TARGETS"))
			{
				fscanf(file, "%i", &ival);
				MAX_AIR_TARGETS = ival;
			}
			else if(!strcmp(keyword, "MIN_AIR_ATTACK_COST"))
			{
				fscanf(file, "%i", &ival);
				MIN_AIR_ATTACK_COST = ival;
			}
			else if(!strcmp(keyword, "SCOUT_SPEED"))
			{
				fscanf(file, "%f", &fval);
				SCOUT_SPEED = fval;
			}
			else if(!strcmp(keyword, "GROUND_ARTY_RANGE"))
			{
				fscanf(file, "%f", &fval);
				GROUND_ARTY_RANGE = fval;
			}
			else if(!strcmp(keyword, "SEA_ARTY_RANGE"))
			{
				fscanf(file, "%f", &fval);
				SEA_ARTY_RANGE = fval;
			}
			else if(!strcmp(keyword, "HOVER_ARTY_RANGE"))
			{
				fscanf(file, "%f", &fval);
				HOVER_ARTY_RANGE = fval;
			}
			else if(!strcmp(keyword, "STATIONARY_ARTY_RANGE"))
			{
				fscanf(file, "%f", &fval);
				STATIONARY_ARTY_RANGE = fval;
			}
			else if(!strcmp(keyword, "MAX_BUILDERS_PER_TYPE"))
			{
				fscanf(file, "%i", &ival);
				MAX_BUILDERS_PER_TYPE = ival;
			}
			else if(!strcmp(keyword, "MAX_FACTORIES_PER_TYPE"))
			{
				fscanf(file, "%i", &ival);
				MAX_FACTORIES_PER_TYPE = ival;
			}
			else if(!strcmp(keyword, "MIN_ASSISTANCE_BUILDTIME"))
			{
				fscanf(file, "%i", &ival);
				MIN_ASSISTANCE_BUILDTIME = ival;
			}
			else if(!strcmp(keyword, "AIR_DEFENCE"))
			{
				fscanf(file, "%i", &ival);
				AIR_DEFENCE = ival;
			}
			else if(!strcmp(keyword, "AIRCRAFT_RATE"))
			{
				fscanf(file, "%i", &ival);
				AIRCRAFT_RATE = ival;
			}
			else if(!strcmp(keyword, "HIGH_RANGE_UNITS_RATE"))
			{
				fscanf(file, "%i", &ival);
				HIGH_RANGE_UNITS_RATE = ival;
			}
			else if(!strcmp(keyword, "FAST_UNITS_RATE"))
			{
				fscanf(file, "%i", &ival);
				FAST_UNITS_RATE = ival;
			}
			else if(!strcmp(keyword, "MAX_METAL_COST"))
			{
				fscanf(file, "%i", &ival);
				MAX_METAL_COST = ival;
			}
			else if(!strcmp(keyword, "MAX_DEFENCES"))
			{
				fscanf(file, "%i", &ival);
				MAX_DEFENCES = ival;
			}
			else if(!strcmp(keyword, "MIN_SECTOR_THREAT"))
			{
				fscanf(file, "%f", &fval);
				MIN_SECTOR_THREAT = fval;
			}
			else if(!strcmp(keyword, "MAX_STAT_ARTY"))
			{
				fscanf(file, "%i", &ival);
				MAX_STAT_ARTY = ival;
			}
			else if(!strcmp(keyword, "MAX_AIR_BASE"))
			{
				fscanf(file, "%i", &ival);
				MAX_AIR_BASE = ival;
			}
			else if(!strcmp(keyword, "AIR_ONLY_MOD"))
			{
				fscanf(file, "%i", &ival);
				AIR_ONLY_MOD = (bool)ival;
			}
			else if(!strcmp(keyword, "METAL_ENERGY_RATIO"))
			{
				fscanf(file, "%f", &fval);
				METAL_ENERGY_RATIO = fval;
			}
			else if(!strcmp(keyword, "NON_AMPHIB_MAX_WATERDEPTH"))
			{
				fscanf(file, "%f", &fval);
				NON_AMPHIB_MAX_WATERDEPTH = fval;
			}
			else if(!strcmp(keyword, "MAX_METAL_MAKERS"))
			{
				fscanf(file, "%i", &ival);
				MAX_METAL_MAKERS = ival;
			}
			else if(!strcmp(keyword, "MAX_STORAGE"))
			{
				fscanf(file, "%i", &ival);
				MAX_STORAGE = ival;
			}
			else if(!strcmp(keyword, "MIN_METAL_MAKER_ENERGY"))
			{
				fscanf(file, "%f", &fval);
				MIN_METAL_MAKER_ENERGY = fval;
			}
			else if(!strcmp(keyword, "MAX_MEX_DISTANCE"))
			{
				fscanf(file, "%i", &ival);
				MAX_MEX_DISTANCE = ival;
			}
			else if(!strcmp(keyword, "MAX_MEX_DEFENCE_DISTANCE"))
			{
				fscanf(file, "%i", &ival);
				MAX_MEX_DEFENCE_DISTANCE = ival;
			}
			else if(!strcmp(keyword, "MIN_FACTORIES_FOR_DEFENCES"))
			{
				fscanf(file, "%i", &ival);
				MIN_FACTORIES_FOR_DEFENCES = ival;
			}
			else if(!strcmp(keyword, "MIN_FACTORIES_FOR_STORAGE"))
			{
				fscanf(file, "%i", &ival);
				MIN_FACTORIES_FOR_STORAGE = ival;
			}
			else if(!strcmp(keyword, "MIN_FACTORIES_FOR_RADAR_JAMMER"))
			{
				fscanf(file, "%i", &ival);
				MIN_FACTORIES_FOR_RADAR_JAMMER = ival;
			}
			else if(!strcmp(keyword, "MIN_SUBMARINE_WATERLINE"))
			{
				fscanf(file, "%i", &ival);
				MIN_SUBMARINE_WATERLINE = ival;
			}
			else if(!strcmp(keyword, "MAX_ATTACKS"))
			{
				fscanf(file, "%i", &ival);
				MAX_ATTACKS = ival;
			}
			else
			{
				error = true;
				break;
			}
		}

		if(error)
		{
			ai->Log("Mod config file %s contains erroneous keyword %s\n", filename, keyword);
			initialized = false;
			return;
		}
		else
		{
//			loaded = true;
			fclose(file);
			ai->Log("Mod config file loaded\n");
		}
	}


	// load general settings
	STRCPY_T(buffer, sizeof(buffer), MAIN_PATH);
	STRCAT_T(buffer, sizeof(buffer), GENERAL_CFG_FILE);
	ReplaceExtension(buffer, filename, sizeof(filename), ".cfg");
	ai->Getcb()->GetValue(AIVAL_LOCATE_FILE_R, filename);
	file = fopen(filename, "r");

	if(file)
	{
		while(EOF != fscanf(file, "%s", keyword))
		{
			if(!strcmp(keyword, "LEARN_RATE"))
			{
				fscanf(file, "%i", &ival);
				LEARN_RATE = ival;
			}
			else if(!strcmp(keyword, "LEARN_SPEED"))
			{
				fscanf(file, "%f", &fval);
				LEARN_SPEED = fval;
			}
			else if(!strcmp(keyword, "WATER_MAP_RATIO"))
			{
				fscanf(file, "%f", &fval);
				WATER_MAP_RATIO = fval;
			}
			else if(!strcmp(keyword, "LAND_WATER_MAP_RATIO"))
			{
				fscanf(file, "%f", &fval);
				LAND_WATER_MAP_RATIO = fval;
			}
			else if(!strcmp(keyword, "SCOUT_UPDATE_FREQUENCY"))
			{
				fscanf(file, "%i", &ival);
				SCOUT_UPDATE_FREQUENCY = ival;
			}
			else if(!strcmp(keyword, "SCOUTING_MEMORY_FACTOR"))
			{
				fscanf(file, "%f", &fval);
				SCOUTING_MEMORY_FACTOR = fval;
			}
			else
			{
				error = true;
				break;
			}
		}

		fclose(file);

		if(error)
		{
			ai->Log("General config file %s contains erroneous keyword %s\n", filename, keyword);
			initialized = false;
			return;
		}

		else
		{
			ai->Log("General config file loaded\n");
			initialized = true;
			return;
		}
	}
	else
	{
		ai->Log("General config file %s not found\n", filename);
		initialized = false;
		return;
	}
}
示例#8
0
/*ARGSUSED*/
    void
workshop_toolbar_button(
	char	*label,
	char	*verb,
	char	*senseVerb,
	char	*filepos,
	char	*help,
	char	*sense,
	char	*file,
	char	*left)
{
    char	cbuf[BUFSIZ + MAXPATHLEN];
    char	namebuf[BUFSIZ];
    static int	tbid = 1;
    char_u	*p;

#ifdef WSDEBUG_TRACE
    if (WSDLEVEL(WS_TRACE_VERBOSE))
	wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
		"\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
		label   && *label   ? label   : "<None>",
		verb    && *verb    ? verb    : "<None>",
		senseVerb && *senseVerb    ? senseVerb    : "<None>",
		filepos && *filepos ? filepos : "<None>",
		help    && *help    ? help    : "<None>",
		sense   && *sense   ? sense   : "<None>",
		file    && *file    ? file    : "<None>",
		left    && *left    ? left    : "<None>");
    else if (WSDLEVEL(WS_TRACE))
	wstrace("workshop_toolbar_button(\"%s\", %s)\n",
		label   && *label   ? label   : "<None>",
		verb    && *verb    ? verb    : "<None>");
#endif
#ifdef WSDEBUG_SENSE
    if (ws_debug)
	wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb,
		*sense == '1' ? "Sensitive" : "Insensitive");
#endif

    if (left && *left && atoi(left) > 0)
    {
	/* Add a separator (but pass the width passed after the ':') */
	sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
		tbpri - 5, tbid++, left);

	coloncmd(cbuf, True);
    }

    p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. ");
    sprintf(namebuf, "ToolBar.%s", p);
    vim_free(p);
    STRCPY(cbuf, "amenu <silent> ");
    if (file != NULL && *file != NUL)
    {
	p = vim_strsave_escaped((char_u *)file, (char_u *)" ");
	sprintf(cbuf + STRLEN(cbuf), "icon=%s ", p);
	vim_free(p);
    }
    sprintf(cbuf + STRLEN(cbuf), "1.%d %s :wsverb %s<CR>",
							tbpri, namebuf, verb);

    /* Define the menu item */
    coloncmd(cbuf, True);

    if (*sense == '0')
    {
	/* If menu isn't sensitive at startup... */
	sprintf(cbuf, "amenu disable %s", namebuf);
	coloncmd(cbuf, True);
    }

    if (help && *help)
    {
	/* Do the tooltip */
	sprintf(cbuf, "tmenu %s %s", namebuf, help);
	coloncmd(cbuf, True);
    }

    addMenu(namebuf, NULL, verb);
    tbpri += 10;
}
示例#9
0
char* util_allocStrCpy(const char* toCopy) {

	char* copy = (char*) calloc(strlen(toCopy)+1, sizeof(char));
	STRCPY(copy, toCopy);
	return copy;
}
示例#10
0
/*
 * Read the errorfile into memory, line by line, building the error list.
 * Return FAIL for error, OK for success.
 */
	int
qf_init()
{
	char_u 			namebuf[CMDBUFFSIZE + 1];
	char_u			errmsg[CMDBUFFSIZE + 1];
	int				col;
	int				type;
	int				valid;
	long			lnum;
	int				enr;
	FILE			*fd;
	struct qf_line	*qfp = NULL;
	struct qf_line	*qfprev = NULL;		/* init to make SASC shut up */
	char_u			*pfmt, *fmtstr;
#ifdef UTS2
	char_u			*(adr[7]);
#else
	void			*(adr[7]);
#endif
	int				adr_cnt = 0;
	int				maxlen;
	int				i;

	if (p_ef == NULL || *p_ef == NUL)
	{
		emsg(e_errorf);
		return FAIL;
	}
	if ((fd = fopen((char *)p_ef, "r")) == NULL)
	{
		emsg2(e_openerrf, p_ef);
		return FAIL;
	}
	qf_free();
	qf_index = 0;
	for (i = 0; i < 7; ++i)
		adr[i] = NULL;

/*
 * The format string is copied and modified from p_efm to fmtstr.
 * Only a few % characters are allowed.
 */
		/* get some space to modify the format string into */
		/* must be able to do the largest expansion 7 times (7 x 3) */
	maxlen = STRLEN(p_efm) + 25;
	fmtstr = alloc(maxlen);
	if (fmtstr == NULL)
		goto error2;
	for (pfmt = p_efm, i = 0; *pfmt; ++pfmt, ++i)
	{
		if (pfmt[0] != '%')				/* copy normal character */
			fmtstr[i] = pfmt[0];
		else
		{
			fmtstr[i++] = '%';
			switch (pfmt[1])
			{
			case 'f':		/* filename */
					adr[adr_cnt++] = namebuf;

			case 'm':		/* message */
					if (pfmt[1] == 'm')
						adr[adr_cnt++] = errmsg;
					fmtstr[i++] = '[';
					fmtstr[i++] = '^';
					if (pfmt[2])
						fmtstr[i++] = pfmt[2];
					else
#ifdef MSDOS
						fmtstr[i++] = '\r';
#else
						fmtstr[i++] = '\n';
#endif
					fmtstr[i] = ']';
					break;
			case 'c':		/* column */
					adr[adr_cnt++] = &col;
					fmtstr[i] = 'd';
					break;
			case 'l':		/* line */
					adr[adr_cnt++] = &lnum;
					fmtstr[i++] = 'l';
					fmtstr[i] = 'd';
					break;
			case 'n':		/* error number */
					adr[adr_cnt++] = &enr;
					fmtstr[i] = 'd';
					break;
			case 't':		/* error type */
					adr[adr_cnt++] = &type;
					fmtstr[i] = 'c';
					break;
			case '%':		/* %% */
			case '*':		/* %*: no assignment */
					fmtstr[i] = pfmt[1];
					break;
			default:
					EMSG("invalid % in format string");
					goto error2;
			}
			if (adr_cnt == 7)
			{
				EMSG("too many % in format string");
				goto error2;
			}
			++pfmt;
		}
		if (i >= maxlen - 6)
		{
			EMSG("invalid format string");
			goto error2;
		}
	}
	fmtstr[i] = NUL;

	while (fgets((char *)IObuff, CMDBUFFSIZE, fd) != NULL && !got_int)
	{
		if ((qfp = (struct qf_line *)alloc((unsigned)sizeof(struct qf_line))) == NULL)
			goto error2;

		IObuff[CMDBUFFSIZE] = NUL;	/* for very long lines */
		namebuf[0] = NUL;
		errmsg[0] = NUL;
		lnum = 0;
		col = 0;
		enr = -1;
		type = 0;
		valid = TRUE;

		if (sscanf((char *)IObuff, (char *)fmtstr, adr[0], adr[1], adr[2], adr[3],
												adr[4], adr[5]) != adr_cnt)
		{
			namebuf[0] = NUL;			/* something failed, remove file name */
			valid = FALSE;
			STRCPY(errmsg, IObuff);		/* copy whole line to error message */
			if ((pfmt = STRRCHR(errmsg, '\n')) != NULL)
				*pfmt = NUL;
#ifdef MSDOS
			if ((pfmt = STRRCHR(errmsg, '\r')) != NULL)
				*pfmt = NUL;
#endif
		}

		if (namebuf[0] == NUL)			/* no file name */
			qfp->qf_fnum = 0;
		else
			qfp->qf_fnum = buflist_add(namebuf);
		if ((qfp->qf_text = strsave(errmsg)) == NULL)
			goto error1;
		qfp->qf_lnum = lnum;
		qfp->qf_col = col;
		qfp->qf_nr = enr;
		qfp->qf_type = type;
		qfp->qf_valid = valid;

		if (qf_count == 0)		/* first element in the list */
		{
			qf_start = qfp;
			qfp->qf_prev = qfp;	/* first element points to itself */
		}
		else
		{
			qfp->qf_prev = qfprev;
			qfprev->qf_next = qfp;
		}
		qfp->qf_next = qfp;		/* last element points to itself */
		qfp->qf_cleared = FALSE;
		qfprev = qfp;
		++qf_count;
		if (qf_index == 0 && qfp->qf_valid)		/* first valid entry */
		{
			qf_index = qf_count;
			qf_ptr = qfp;
		}
		breakcheck();
	}
	free(fmtstr);
	if (!ferror(fd))
	{
		if (qf_index == 0)		/* no valid entry found */
		{
			qf_ptr = qf_start;
			qf_index = 1;
			qf_nonevalid = TRUE;
		}
		else
			qf_nonevalid = FALSE;
		fclose(fd);
		qf_jump(0, 0);			/* display first error */
		return OK;
	}
	emsg(e_readerrf);
error1:
	free(qfp);
error2:
	fclose(fd);
	qf_free();
	return FAIL;
}
示例#11
0
static PRESULT lan_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact,input;
	UINT8	id = OSD_GetObjID(pObj);
	POBJECT_HEAD submenu;
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 lang_code[8];

	switch(event)
	{		
	case EVN_FOCUS_PRE_GET:
		break;
		
	case EVN_FOCUS_PRE_LOSE:
		break;

	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
#ifdef SHOW_WELCOME_SCREEN
		if(id != ITEM_NEXT_ID)
		{
#endif
			if(unact == VACT_ENTER)
		{
			win_language_enter_key(pObj,id);
		}
		else if(unact == VACT_DECREASE)
		{
			win_language_left_key(pObj,id);
		}
		else if(unact == VACT_INCREASE)
		{
			win_language_right_key(pObj,id);
		}
#ifdef SHOW_WELCOME_SCREEN
		}
		else if(unact == VACT_ENTER)
		{
    #ifdef EPG_MULTI_LANG
			/*set epg language*/
			p_sys_data = sys_data_get();
			STRCPY(lang_code,stream_iso_639lang_abbr[p_sys_data->lang.OSD_lang]);
			epg_set_lang_code(lang_code);
    #endif

    #ifndef NEW_DEMO_FRAME
			UIChChgApplyAudLanguage();
    #endif
			sys_data_save(1);
       	 	TTXEng_set_g0_set();
			//show_win_as_welcome = FALSE;

			submenu = (POBJECT_HEAD) & win_country_net_con;
			if (OSD_ObjOpen(submenu, 0xFFFFFFFF) != PROC_LEAVE)
			{
				menu_stack_pop();
				menu_stack_push(submenu);
			}
		}
#endif
		ret = PROC_LOOP;
		break;
	}
	return ret;

}
示例#12
0
void win_language_right_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 lang_code[8]={0};
	switch(id)
	{
		case MENU_LANGUAGE_MENU_LAN:
			if(p_sys_data->lang.OSD_lang==(MENU_LANGUAGE_OSD_NUMBER-1))
			{
				p_sys_data->lang.OSD_lang=0;
			}
			else
			{
				p_sys_data->lang.OSD_lang++;
			}
			win_lan_set_menu_lan_string(p_sys_data->lang.OSD_lang);
			sys_data_select_language(p_sys_data->lang.OSD_lang);
			wincom_open_subtitle((POBJECT_HEAD)&win_lan_con,RS_SYSTEM_LANGUAGE, 0);
			OSD_TrackObject((POBJECT_HEAD)&win_lan_con,C_DRAW_SIGN_EVN_FLG| C_UPDATE_ALL);
			break;
		case MENU_LANGUAGE_1ST_AUDIO_LAN:
			if(p_sys_data->lang.Audio_lang_1==(MENU_LANGUAGE_STREAM_NUMBER-1))
			{
				p_sys_data->lang.Audio_lang_1=0;
			}
			else
			{
				p_sys_data->lang.Audio_lang_1++;
			}
			win_lan_set_1st_audio_lan_string(p_sys_data->lang.Audio_lang_1);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			ap_language_setting(p_sys_data->lang.Audio_lang_1, p_sys_data->lang.Audio_lang_2);
			break;
		case MENU_LANGUAGE_2ND_AUDIO_LAN:
			if(p_sys_data->lang.Audio_lang_2==(MENU_LANGUAGE_STREAM_NUMBER-1))
			{
				p_sys_data->lang.Audio_lang_2=0;
			}
			else
			{
				p_sys_data->lang.Audio_lang_2++;
			}
			win_lan_set_2nd_audio_lan_string(p_sys_data->lang.Audio_lang_2);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			ap_language_setting(p_sys_data->lang.Audio_lang_1, p_sys_data->lang.Audio_lang_2);
			break;
		case MENU_LANGUAGE_SUB_LAN:
			if(p_sys_data->lang.sub_lang==(MENU_LANGUAGE_STREAM_NUMBER-1))
			{
				p_sys_data->lang.sub_lang=0;
			}
			else
			{
				p_sys_data->lang.sub_lang++;
			}
			p_sys_data->osd_set.subtitle_display = 1;/*select sub on */
			p_sys_data->osd_set.subtitle_lang = 0xFF;
			win_lan_set_subtitle_lan_string(p_sys_data->lang.sub_lang);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_LANGUAGE_TXT_LAN:
			if(p_sys_data->lang.ttx_lang==(MENU_LANGUAGE_STREAM_NUMBER-1))
			{
				p_sys_data->lang.ttx_lang=0;
			}
			else
			{
				p_sys_data->lang.ttx_lang++;
			}
			win_lan_set_teletext_lan_string(p_sys_data->lang.ttx_lang);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	#ifdef ORDER_GZ1207009
		case MENU_LANGUAGE_EPG_LAN:
			if(p_sys_data->lang.epg_lang==(MENU_LANGUAGE_STREAM_NUMBER-1))
			{
				p_sys_data->lang.epg_lang=0;
			}
			else
			{
				p_sys_data->lang.epg_lang++;
			}
			win_lan_set_epg_lan_string(p_sys_data->lang.epg_lang);

			STRCPY(lang_code,stream_iso_639lang_abbr[p_sys_data->lang.epg_lang]);
			epg_set_lang_code(lang_code);
			
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	#endif
	}
}
示例#13
0
void win_language_enter_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	UINT8 lang_code[8]={0};
	
	rect.uLeft=CON_L+TXTS_L_OF;
	rect.uWidth=TXTS_W;
	rect.uHeight=350;//340;
	param.selecttype = POP_LIST_SINGLESELECT;
	switch(id)
	{
		case MENU_LANGUAGE_MENU_LAN:
			rect.uTop=CON_T;
			param.cur=p_sys_data->lang.OSD_lang;
			p_sys_data->lang.OSD_lang = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_OSD,&rect,&param);
			win_lan_set_menu_lan_string(p_sys_data->lang.OSD_lang);
			sys_data_select_language(p_sys_data->lang.OSD_lang);
			wincom_open_subtitle((POBJECT_HEAD)&win_lan_con,RS_SYSTEM_LANGUAGE, 0);
			OSD_TrackObject((POBJECT_HEAD)&win_lan_con,C_DRAW_SIGN_EVN_FLG| C_UPDATE_ALL);
			break;
		case MENU_LANGUAGE_1ST_AUDIO_LAN:
			rect.uTop=CON_T + (CON_H + CON_GAP)*1;
			param.cur=p_sys_data->lang.Audio_lang_1;
			p_sys_data->lang.Audio_lang_1 = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_STREAM,&rect,&param);
			win_lan_set_1st_audio_lan_string(p_sys_data->lang.Audio_lang_1);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			ap_language_setting(p_sys_data->lang.Audio_lang_1, p_sys_data->lang.Audio_lang_2);
			break;
		case MENU_LANGUAGE_2ND_AUDIO_LAN:
			rect.uTop=CON_T + (CON_H + CON_GAP)*2;
			param.cur=p_sys_data->lang.Audio_lang_2;
			p_sys_data->lang.Audio_lang_2 = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_STREAM,&rect,&param);
			win_lan_set_2nd_audio_lan_string(p_sys_data->lang.Audio_lang_2);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			ap_language_setting(p_sys_data->lang.Audio_lang_1, p_sys_data->lang.Audio_lang_2);
			break;
		case MENU_LANGUAGE_SUB_LAN:
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			param.cur=p_sys_data->lang.sub_lang;
			p_sys_data->lang.sub_lang = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_STREAM,&rect,&param);
			p_sys_data->osd_set.subtitle_display = 1;/*select sub on */
			p_sys_data->osd_set.subtitle_lang = 0xFF;
			win_lan_set_subtitle_lan_string(p_sys_data->lang.sub_lang);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_LANGUAGE_TXT_LAN:
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			rect.uHeight=300;
			param.cur=p_sys_data->lang.ttx_lang;
			p_sys_data->lang.ttx_lang = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_STREAM,&rect,&param);
			win_lan_set_teletext_lan_string(p_sys_data->lang.ttx_lang);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	#ifdef ORDER_GZ1207009
		case MENU_LANGUAGE_EPG_LAN:
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			rect.uHeight=300;
			param.cur=p_sys_data->lang.epg_lang;
			p_sys_data->lang.epg_lang = win_com_open_sub_list(POP_LIST_MENU_LANGUAGE_STREAM,&rect,&param);
			win_lan_set_epg_lan_string(p_sys_data->lang.epg_lang);

			STRCPY(lang_code,stream_iso_639lang_abbr[p_sys_data->lang.epg_lang]);
			epg_set_lang_code(lang_code);
			
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	#endif
	}
}
示例#14
0
/*
 * Return a string which contains the name of the given key when the given
 * modifiers are down.
 */
char_u *get_special_key_name(int c, int modifiers)
{
  static char_u string[MAX_KEY_NAME_LEN + 1];

  int i, idx;
  int table_idx;
  char_u  *s;

  string[0] = '<';
  idx = 1;

  /* Key that stands for a normal character. */
  if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY)
    c = KEY2TERMCAP1(c);

  /*
   * Translate shifted special keys into unshifted keys and set modifier.
   * Same for CTRL and ALT modifiers.
   */
  if (IS_SPECIAL(c)) {
    for (i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE)
      if (       KEY2TERMCAP0(c) == (int)modifier_keys_table[i + 1]
                 && (int)KEY2TERMCAP1(c) == (int)modifier_keys_table[i + 2]) {
        modifiers |= modifier_keys_table[i];
        c = TERMCAP2KEY(modifier_keys_table[i + 3],
            modifier_keys_table[i + 4]);
        break;
      }
  }

  /* try to find the key in the special key table */
  table_idx = find_special_key_in_table(c);

  /*
   * When not a known special key, and not a printable character, try to
   * extract modifiers.
   */
  if (c > 0
      && (*mb_char2len)(c) == 1
      ) {
    if (table_idx < 0
        && (!vim_isprintc(c) || (c & 0x7f) == ' ')
        && (c & 0x80)) {
      c &= 0x7f;
      modifiers |= MOD_MASK_ALT;
      /* try again, to find the un-alted key in the special key table */
      table_idx = find_special_key_in_table(c);
    }
    if (table_idx < 0 && !vim_isprintc(c) && c < ' ') {
      c += '@';
      modifiers |= MOD_MASK_CTRL;
    }
  }

  /* translate the modifier into a string */
  for (i = 0; mod_mask_table[i].name != 'A'; i++)
    if ((modifiers & mod_mask_table[i].mod_mask)
        == mod_mask_table[i].mod_flag) {
      string[idx++] = mod_mask_table[i].name;
      string[idx++] = (char_u)'-';
    }

  if (table_idx < 0) {          /* unknown special key, may output t_xx */
    if (IS_SPECIAL(c)) {
      string[idx++] = 't';
      string[idx++] = '_';
      string[idx++] = (char_u)KEY2TERMCAP0(c);
      string[idx++] = KEY2TERMCAP1(c);
    }
    /* Not a special key, only modifiers, output directly */
    else {
      if (has_mbyte && (*mb_char2len)(c) > 1)
        idx += (*mb_char2bytes)(c, string + idx);
      else if (vim_isprintc(c))
        string[idx++] = (char_u)c;
      else {
        s = transchar(c);
        while (*s)
          string[idx++] = *s++;
      }
    }
  } else {            /* use name of special key */
    STRCPY(string + idx, key_names_table[table_idx].name);
    idx = (int)STRLEN(string);
  }
  string[idx++] = '>';
  string[idx] = NUL;
  return string;
}
示例#15
0
void win_get_fullname(char *fullname,char *path, char *name)
{
	STRCPY(fullname, path);
	strcat(fullname, "/");
	strcat(fullname, name);
}
示例#16
0
static void win_mpegYT_player_draw_infor(void)
{
	BITMAP* bmp;
	TEXT_FIELD* txt;
	PROGRESS_BAR* bar;
	mpegYTplayer_bmp_t* bmp_desc;
	mpegYTplayer_txt_t* txt_desc;
	UINT32 i, hd_fulless;
	UINT16 icon;
	char string[30];
	UINT32 hh, mm, ss;
	UINT32 play_pos = 0;
	FileInfo file_node;
	char name_buffer[MAX_FILE_NAME_SIZE + 1];

	bmp = &mpegYT_player_bmp;
	txt = &mpegYT_player_text;
	bar = &mpegYT_player_bar;

	for (i = 0; i < MPEGYT_BMP_NUM; i++)
	{
		bmp_desc = &mpegYTplayer_bmps[i];
		icon = INVALID_ID;
		switch (bmp_desc->bmp_type)
		{
		case MPEGYT_BMP_STATIC:
			//icon = bmp_desc->icon;
			break;
		case MPEGYT_BMP_PLAY_RECORD:
			icon = bmp_desc->icon;
			break;
		case MPEGYT_BMP_PLAY_MODE:
			if (MPEGYTInfo.PlayState < sizeof(mpegplayer_yt_status_icons) / 2)
			{
				icon = mpegplayer_yt_status_icons[MPEGYTInfo.PlayState];
			}
			break;
		case MPEGYT_BMP_HDD_STATUS:
			/*			step_sectors =  (hdd_info.total_size - hdd_info.tms_size) / 5;
						if(step_sectors >0 )
						{
							hd_fulless = (hdd_info.rec_size + step_sectors/2) / step_sectors ;
							if(hd_fulless == 5)
								hd_fulless = 4;
							icon = MP_HDstatus_icons[4-hd_fulless];//hd_fulless -> 4-hd_fulles, show used space!
						}
			*/
			break;
		default:
			break;
		}


		OSD_SetBitmapContent(bmp, icon);
		OSD_SetRect(&bmp->head.frame, bmp_desc->left, bmp_desc->top, bmp_desc->width, bmp_desc->height);
		OSD_DrawObject( (OBJECT_HEAD*) bmp, C_UPDATE_ALL);
	}

	for (i = 0;i < MPEGYT_TXT_NUM;i++)
	{
		txt_desc = &mpegYTplayer_txts[i];

		OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)"");

		switch (txt_desc->txt_type)
		{
		case MPEGYT_TXT_PLAY_NAME:
			//get_file_from_file_list(win_file_list[VIDEO_FILE_LIST], mpegYTlist_idx, &file_node);
			//filter_unkownfont_name(file_node.name, name_buffer);
			win_shorten_filename(entry_youtube->title,name_buffer);
			sprintf(name_buffer, "%s", name_buffer);
			OSD_SetTextFieldContent(txt, STRING_UTF8, (UINT32)name_buffer);
			break;
		case MPEGYT_TXT_DATE:
			//sprintf(string,"%02d/%02d",dt.month,dt.day);
			//STRCPY(string, "");
			sprintf(string, "%02d/%02d/%02d",
					entry_youtube->pub_date.year,
					entry_youtube->pub_date.month,
					entry_youtube->pub_date.day);
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			break;
		case MPEGYT_TXT_TIME:
			//sprintf(string,"%02d:%02d",dt.hour,dt.min);
			STRCPY(string, "");
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			break;
		case MPEGYT_TXT_PLAY_MODE:
			STRCPY(string, "");
			if (MPEGYTInfo.PlayState == MPEG_STOP)
			{
				sprintf(string, "%s", "Stop");
			}
			else if (MPEGYTInfo.PlayState == MPEG_PLAY)
			{
				sprintf(string, "%s", "Play");
			}
			else if (MPEGYTInfo.PlayState == MPEG_PAUSE)
			{
				sprintf(string, "%s", "Pause");
			}
			else if (MPEGYTInfo.PlayState == MPEG_FF || MPEGYTInfo.PlayState == MPEG_FB)
			{
				sprintf(string, "X%d", mpegYTspeed_steps[MPEGYTInfo.PlaySpeed]);
			}
			else if (MPEGYTInfo.PlayState == MPEG_SF || MPEGYTInfo.PlayState == MPEG_SB)
			{
				sprintf(string, "X1/%d", mpegYTspeed_steps[MPEGYTInfo.PlaySpeed]);
			}
			else if(MPEGYTInfo.PlayState == MPEG_STEP)
			{
				sprintf(string,"%s","Step");
			}
#ifdef SUPPORT_DIVX_CERT
            else if(MPEGYTInfo.PlayState == MPEG_RESUME_STOP)
            {
                sprintf(string,"%s","Stop");
            }
#endif
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			break;
		case MPEGYT_TXT_PLAY_1ST_TIME:
			STRCPY(string, "");
			MPEGYTInfo.PlayTime = (UINT32)MPGFileDecoderGetPlayTime() + s_ytvideo_seektime;
            if (MPEGYTInfo.PlayState == MPEG_STOP)
                MPEGYTInfo.PlayTime = 0;
#if 1
			hh = MPEGYTInfo.PlayTime / 3600;
			mm = (MPEGYTInfo.PlayTime % 3600) / 60;
			ss = MPEGYTInfo.PlayTime % 60;
#else
			hh = entry_youtube->info->duration/3600;
			mm = (entry_youtube->info->duration % 3600) / 60;
			ss = entry_youtube->info->duration % 60;			
#endif
			sprintf(string, "%02d:%02d:%02d", hh, mm, ss);
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			break;

		case MPEGYT_TXT_PLAY_2ND_TIME:
			STRCPY(string, "");
#if 0
			hh = MPEGYTInfo.TotalTime / 3600;
			mm = (MPEGYTInfo.TotalTime % 3600) / 60;
			ss = MPEGYTInfo.TotalTime % 60;
#else
			hh = entry_youtube->info->duration/3600;
			mm = (entry_youtube->info->duration % 3600) / 60;
			ss = entry_youtube->info->duration % 60;	
#endif
			sprintf(string, "%02d:%02d:%02d", hh, mm, ss);
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			break;
		case MPEGYT_TXT_HDD_STATUS:
			/*step_sectors = (hdd_info.total_size - hdd_info.tms_size)/100;
			if(step_sectors >0 )
			{
				sprintf(string,"%d%%",(100 - (hdd_info.rec_size+ step_sectors/2 )/step_sectors));
			}
			else
			{
				STRCPY(string,"");
			}
			OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)string);
			*/
			break;
		}

		OSD_SetRect(&txt->head.frame, txt_desc->left, txt_desc->top, txt_desc->width, txt_desc->height);
		txt->head.style.bShowIdx = txt_desc->shidx;
		OSD_DrawObject( (OBJECT_HEAD *)txt, C_UPDATE_ALL);
	}

	/* Draw progress bar */
	OSD_SetProgressBarPos(bar, 100);
	OSD_SetRect(&bar->head.frame, BAR_L, BAR_T, BAR_W, 24);
	bar->rcBar.uLeft 	= 2;
	bar->rcBar.uTop 		= 5;
	bar->rcBar.uWidth	= BAR_W - 4;
	bar->rcBar.uHeight 	= 14;//16 - 6;
	bar->wTickFg 		= WSTL_BAR_06;
	OSD_DrawObject((POBJECT_HEAD)bar, C_UPDATE_ALL);

	/* Draw play pos */
//    BarState.nPos = MPEGYTInfo.PlayTime;
	if (BarState.nRange)
	{
		play_pos = BarState.nPos * 100 / BarState.nRange;
	}
	OSD_SetRect(&bmp->head.frame, bar->head.frame.uLeft+6 + (bar->head.frame.uWidth-12)*play_pos / 100*OSD_GetProgressBarPos(bar) / 100 - POS_ICON_WIDTH / 2,
				bar->head.frame.uTop, POS_ICON_WIDTH, bar->head.frame.uHeight);
	OSD_SetBitmapContent(bmp, IM_PVR_DOT);
	OSD_DrawObject((POBJECT_HEAD)bmp, C_UPDATE_ALL);

	/* Draw play cursor */
	if (CURSOR_MOVING == BarState.State)
	{
		if (BarState.nRange)
		{
			play_pos = BarState.nCursor * 100 / BarState.nRange;
		}
		OSD_SetRect(&bmp->head.frame, bar->head.frame.uLeft + 6 + (bar->head.frame.uWidth-4)*play_pos / 100/**OSD_GetProgressBarPos(bar) / 100*/ - POS_ICON_WIDTH / 2,
		//OSD_SetRect(&bmp->head.frame, bar->head.frame.uLeft + 6 + (bar->head.frame.uWidth-4)*play_pos / 100*OSD_GetProgressBarPos(bar) / 100 - POS_ICON_WIDTH / 2,
					bar->head.frame.uTop, POS_ICON_WIDTH, bar->head.frame.uHeight);
		OSD_SetBitmapContent(bmp, IM_PVR_DOT_ORANGE);
		OSD_DrawObject((POBJECT_HEAD)bmp, C_UPDATE_ALL);
	}
}
示例#17
0
/*
 * Initialization routine for vim_findfile().
 *
 * Returns the newly allocated search context or NULL if an error occurred.
 *
 * Don't forget to clean up by calling vim_findfile_cleanup() if you are done
 * with the search context.
 *
 * Find the file 'filename' in the directory 'path'.
 * The parameter 'path' may contain wildcards. If so only search 'level'
 * directories deep. The parameter 'level' is the absolute maximum and is
 * not related to restricts given to the '**' wildcard. If 'level' is 100
 * and you use '**200' vim_findfile() will stop after 100 levels.
 *
 * 'filename' cannot contain wildcards!  It is used as-is, no backslashes to
 * escape special characters.
 *
 * If 'stopdirs' is not NULL and nothing is found downward, the search is
 * restarted on the next higher directory level. This is repeated until the
 * start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the
 * format ";*<dirname>*\(;<dirname>\)*;\=$".
 *
 * If the 'path' is relative, the starting dir for the search is either VIM's
 * current dir or if the path starts with "./" the current files dir.
 * If the 'path' is absolute, the starting dir is that part of the path before
 * the first wildcard.
 *
 * Upward search is only done on the starting dir.
 *
 * If 'free_visited' is TRUE the list of already visited files/directories is
 * cleared. Set this to FALSE if you just want to search from another
 * directory, but want to be sure that no directory from a previous search is
 * searched again. This is useful if you search for a file at different places.
 * The list of visited files/dirs can also be cleared with the function
 * vim_findfile_free_visited().
 *
 * Set the parameter 'find_what' to FINDFILE_DIR if you want to search for
 * directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both.
 *
 * A search context returned by a previous call to vim_findfile_init() can be
 * passed in the parameter "search_ctx_arg".  This context is reused and
 * reinitialized with the new parameters.  The list of already visited
 * directories from this context is only deleted if the parameter
 * "free_visited" is true.  Be aware that the passed "search_ctx_arg" is freed
 * if the reinitialization fails.
 *
 * If you don't have a search context from a previous call "search_ctx_arg"
 * must be NULL.
 *
 * This function silently ignores a few errors, vim_findfile() will have
 * limited functionality then.
 */
void *
vim_findfile_init (
    char_u *path,
    char_u *filename,
    char_u *stopdirs,
    int level,
    int free_visited,
    int find_what,
    void *search_ctx_arg,
    int tagfile,                    /* expanding names of tags files */
    char_u *rel_fname         /* file name to use for "." */
)
{
  char_u              *wc_part;
  ff_stack_T          *sptr;
  ff_search_ctx_T     *search_ctx;

  /* If a search context is given by the caller, reuse it, else allocate a
   * new one.
   */
  if (search_ctx_arg != NULL)
    search_ctx = search_ctx_arg;
  else {
    search_ctx = xcalloc(1, sizeof(ff_search_ctx_T));
  }
  search_ctx->ffsc_find_what = find_what;
  search_ctx->ffsc_tagfile = tagfile;

  /* clear the search context, but NOT the visited lists */
  ff_clear(search_ctx);

  /* clear visited list if wanted */
  if (free_visited == TRUE)
    vim_findfile_free_visited(search_ctx);
  else {
    /* Reuse old visited lists. Get the visited list for the given
     * filename. If no list for the current filename exists, creates a new
     * one. */
    search_ctx->ffsc_visited_list = ff_get_visited_list(filename,
        &search_ctx->ffsc_visited_lists_list);
    if (search_ctx->ffsc_visited_list == NULL)
      goto error_return;
    search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename,
        &search_ctx->ffsc_dir_visited_lists_list);
    if (search_ctx->ffsc_dir_visited_list == NULL)
      goto error_return;
  }

  if (ff_expand_buffer == NULL) {
    ff_expand_buffer = xmalloc(MAXPATHL);
  }

  /* Store information on starting dir now if path is relative.
   * If path is absolute, we do that later.  */
  if (path[0] == '.'
      && (vim_ispathsep(path[1]) || path[1] == NUL)
      && (!tagfile || vim_strchr(p_cpo, CPO_DOTTAG) == NULL)
      && rel_fname != NULL) {
    int len = (int)(path_tail(rel_fname) - rel_fname);

    if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) {
      /* Make the start dir an absolute path name. */
      STRLCPY(ff_expand_buffer, rel_fname, len + 1);
      search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE);
    } else
      search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
    if (*++path != NUL)
      ++path;
  } else if (*path == NUL || !vim_isAbsName(path)) {
#ifdef BACKSLASH_IN_FILENAME
    /* "c:dir" needs "c:" to be expanded, otherwise use current dir */
    if (*path != NUL && path[1] == ':') {
      char_u drive[3];

      drive[0] = path[0];
      drive[1] = ':';
      drive[2] = NUL;
      if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, TRUE) == FAIL)
        goto error_return;
      path += 2;
    } else
#endif
    if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL)
      goto error_return;

    search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer);

#ifdef BACKSLASH_IN_FILENAME
    /* A path that starts with "/dir" is relative to the drive, not to the
     * directory (but not for "//machine/dir").  Only use the drive name. */
    if ((*path == '/' || *path == '\\')
        && path[1] != path[0]
        && search_ctx->ffsc_start_dir[1] == ':')
      search_ctx->ffsc_start_dir[2] = NUL;
#endif
  }

  /*
   * If stopdirs are given, split them into an array of pointers.
   * If this fails (mem allocation), there is no upward search at all or a
   * stop directory is not recognized -> continue silently.
   * If stopdirs just contains a ";" or is empty,
   * search_ctx->ffsc_stopdirs_v will only contain a  NULL pointer. This
   * is handled as unlimited upward search.  See function
   * ff_path_in_stoplist() for details.
   */
  if (stopdirs != NULL) {
    char_u  *walker = stopdirs;
    int dircount;

    while (*walker == ';')
      walker++;

    dircount = 1;
    search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *));

    do {
      char_u  *helper;
      void    *ptr;

      helper = walker;
      ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
          (dircount + 1) * sizeof(char_u *));
      search_ctx->ffsc_stopdirs_v = ptr;
      walker = vim_strchr(walker, ';');
      if (walker) {
        search_ctx->ffsc_stopdirs_v[dircount-1] =
          vim_strnsave(helper, (int)(walker - helper));
        walker++;
      } else
        /* this might be "", which means ascent till top
         * of directory tree.
         */
        search_ctx->ffsc_stopdirs_v[dircount-1] =
          vim_strsave(helper);

      dircount++;

    } while (walker != NULL);
    search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
  }

  search_ctx->ffsc_level = level;

  /* split into:
   *  -fix path
   *  -wildcard_stuff (might be NULL)
   */
  wc_part = vim_strchr(path, '*');
  if (wc_part != NULL) {
    int llevel;
    int len;
    char    *errpt;

    /* save the fix part of the path */
    search_ctx->ffsc_fix_path = vim_strnsave(path, (int)(wc_part - path));

    /*
     * copy wc_path and add restricts to the '**' wildcard.
     * The octet after a '**' is used as a (binary) counter.
     * So '**3' is transposed to '**^C' ('^C' is ASCII value 3)
     * or '**76' is transposed to '**N'( 'N' is ASCII value 76).
     * For EBCDIC you get different character values.
     * If no restrict is given after '**' the default is used.
     * Due to this technique the path looks awful if you print it as a
     * string.
     */
    len = 0;
    while (*wc_part != NUL) {
      if (len + 5 >= MAXPATHL) {
        EMSG(_(e_pathtoolong));
        break;
      }
      if (STRNCMP(wc_part, "**", 2) == 0) {
        ff_expand_buffer[len++] = *wc_part++;
        ff_expand_buffer[len++] = *wc_part++;

        llevel = strtol((char *)wc_part, &errpt, 10);
        if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255)
          ff_expand_buffer[len++] = llevel;
        else if ((char_u *)errpt != wc_part && llevel == 0)
          /* restrict is 0 -> remove already added '**' */
          len -= 2;
        else
          ff_expand_buffer[len++] = FF_MAX_STAR_STAR_EXPAND;
        wc_part = (char_u *)errpt;
        if (*wc_part != NUL && !vim_ispathsep(*wc_part)) {
          EMSG2(_(
                  "E343: Invalid path: '**[number]' must be at the end of the path or be followed by '%s'."),
              PATHSEPSTR);
          goto error_return;
        }
      } else
        ff_expand_buffer[len++] = *wc_part++;
    }
    ff_expand_buffer[len] = NUL;
    search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer);
  } else
    search_ctx->ffsc_fix_path = vim_strsave(path);

  if (search_ctx->ffsc_start_dir == NULL) {
    /* store the fix part as startdir.
     * This is needed if the parameter path is fully qualified.
     */
    search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path);
    search_ctx->ffsc_fix_path[0] = NUL;
  }

  /* create an absolute path */
  if (STRLEN(search_ctx->ffsc_start_dir)
      + STRLEN(search_ctx->ffsc_fix_path) + 3 >= MAXPATHL) {
    EMSG(_(e_pathtoolong));
    goto error_return;
  }
  STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
  add_pathsep(ff_expand_buffer);
  {
    size_t eb_len = STRLEN(ff_expand_buffer);
    char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1);

    STRCPY(buf, ff_expand_buffer);
    STRCPY(buf + eb_len, search_ctx->ffsc_fix_path);
    if (os_isdir(buf)) {
      STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
      add_pathsep(ff_expand_buffer);
    } else {
      char_u *p =  path_tail(search_ctx->ffsc_fix_path);
      char_u *wc_path = NULL;
      char_u *temp = NULL;
      int len = 0;

      if (p > search_ctx->ffsc_fix_path) {
        len = (int)(p - search_ctx->ffsc_fix_path) - 1;
        STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len);
        add_pathsep(ff_expand_buffer);
      } else
        len = (int)STRLEN(search_ctx->ffsc_fix_path);

      if (search_ctx->ffsc_wc_path != NULL) {
        wc_path = vim_strsave(search_ctx->ffsc_wc_path);
        temp = xmalloc(STRLEN(search_ctx->ffsc_wc_path)
                       + STRLEN(search_ctx->ffsc_fix_path + len)
                       + 1);
      }

      if (temp == NULL || wc_path == NULL) {
        free(buf);
        free(temp);
        free(wc_path);
        goto error_return;
      }

      STRCPY(temp, search_ctx->ffsc_fix_path + len);
      STRCAT(temp, search_ctx->ffsc_wc_path);
      free(search_ctx->ffsc_wc_path);
      free(wc_path);
      search_ctx->ffsc_wc_path = temp;
    }
    free(buf);
  }

  sptr = ff_create_stack_element(ff_expand_buffer,
      search_ctx->ffsc_wc_path,
      level, 0);

  ff_push(search_ctx, sptr);
  search_ctx->ffsc_file_to_search = vim_strsave(filename);
  return search_ctx;

error_return:
  /*
   * We clear the search context now!
   * Even when the caller gave us a (perhaps valid) context we free it here,
   * as we might have already destroyed it.
   */
  vim_findfile_cleanup(search_ctx);
  return NULL;
}
示例#18
0
static PRESULT lan_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT32 i;
	UINT8	unact;
	BOOL subt_popup;
	CONTAINER* cont = (CONTAINER*)pObj;
	UINT8	id = OSD_GetObjID(pObj);
	SYSTEM_DATA* p_sys_data;
	UINT8 lang_code[8];
    
	switch(event)
	{
	case EVN_PRE_OPEN:
#ifdef EXIT_KEY_EXIT_ALL_MENU
	         exit_key_flag =  FALSE;
#endif
		wincom_open_subtitle((POBJECT_HEAD)&win_lan_con,RS_SYSTEM_LANGUAGE, 0);
#ifdef SHOW_WELCOME_SCREEN
		if(show_win_as_welcome)
		//if(1)
		{
			OSD_SetAttr(&lan_item_con6, C_ATTR_ACTIVE);
			((POBJECT_HEAD)(&lan_item_con1))->bUpID = 6;
			((POBJECT_HEAD)(&lan_item_con5))->bDownID = 6;
            //win_lan_con.head.style.bShowIdx = WSTL_WIN_BODYLEFT_01_HD;
            //win_lan_con.head.style.bHLIdx = WSTL_WIN_BODYLEFT_01_HD;
           // win_lan_con.head.style.bSelIdx = WSTL_WIN_BODYLEFT_01_HD;
           // win_lan_con.head.style.bGrayIdx = WSTL_WIN_BODYLEFT_01_HD;
            OSD_SetRect(&(win_lan_con.head.frame), MAIN_W_L, W_T, MAIN_W_W, W_H);
		}
		else
		{
			OSD_SetAttr(&lan_item_con6, C_ATTR_HIDDEN);
			((POBJECT_HEAD)(&lan_item_con1))->bUpID = 5;
			((POBJECT_HEAD)(&lan_item_con5))->bDownID = 1;
            win_lan_con.head.style.bShowIdx = WIN_SH_IDX;
            win_lan_con.head.style.bHLIdx = WIN_HL_IDX;
            win_lan_con.head.style.bSelIdx = WIN_SL_IDX;
            win_lan_con.head.style.bGrayIdx = WIN_GRY_IDX;

            OSD_SetRect(&(win_lan_con.head.frame), W_L, W_T, W_W, W_H);
    		//remove_menu_item(&win_lan_con, (OBJECT_HEAD *)&lan_item_con6, CON_H + CON_GAP);
			
		}
         ((CONTAINER*)(&win_lan_con))->FocusObjectID = 1;
#endif

		p_sys_data=sys_data_get();
//libc_printf("\nmmmmm-lan_open--mmmmmmm==%d\n",p_sys_data->lang.OSD_lang);
		win_lan_set_menu_lan_string(p_sys_data->lang.OSD_lang);
		win_lan_set_1st_audio_lan_string(p_sys_data->lang.Audio_lang_1);
		win_lan_set_2nd_audio_lan_string(p_sys_data->lang.Audio_lang_2);
		win_lan_set_subtitle_lan_string(p_sys_data->lang.sub_lang);
		win_lan_set_teletext_lan_string(p_sys_data->lang.ttx_lang);
#ifdef ORDER_GZ1207009
		win_lan_set_epg_lan_string(p_sys_data->lang.epg_lang);
#endif

#ifdef SUPPORT_POP_SUBT
		subt_popup = TRUE;
#else
		subt_popup = FALSE;
#endif

#ifdef PREVIEW_SUBMENU  //-a by wangyang 
{
				
			POBJECT_HEAD focusObj=OSD_GetFocusObject(pObj);
			
			if(param2==MENU_OPEN_TYPE_OTHER)
			{
				lan_item_set[focusObj->bID-1]->style.bHLIdx=TXTS_SH_IDX;
				lan_item_name[focusObj->bID-1]->style.bHLIdx=TXTN_SH_IDX;
			}
			else
			{
				lan_item_set[focusObj->bID-1]->style.bHLIdx=TXTS_HL_IDX;
				lan_item_name[focusObj->bID-1]->style.bHLIdx=TXTN_HL_IDX;
			}

}
#endif

	/*	if(subt_popup) //-d by wangyang  for add subtitle language
		{
			remove_menu_item(&win_lan_con, (POBJECT_HEAD)lan_items[3], (CON_H + CON_GAP));			
		}*/
		break;
	
	case EVN_POST_OPEN:
		wincom_open_commen_help(pObj);//-a by wangyang 
		break;
		
	case EVN_PRE_CLOSE:
#ifdef EPG_MULTI_LANG
#ifndef ORDER_GZ1207009
		/*set epg language*/
		p_sys_data = sys_data_get();
		STRCPY(lang_code,stream_iso_639lang_abbr[p_sys_data->lang.OSD_lang]);
		epg_set_lang_code(lang_code);
#endif
#endif

#ifndef NEW_DEMO_FRAME
		UIChChgApplyAudLanguage();
#endif
//libc_printf("\nmmmmm---mmmmmmm==%d\n",p_sys_data->lang.OSD_lang);
		sys_data_save(1);
		/* Make OSD not flickering */
		*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
		
		break;

	case EVN_POST_CLOSE:
              TTXEng_set_g0_set();
  		wincom_close_subtitle();
			OSD_ClearScreen();
#ifdef EXIT_KEY_EXIT_ALL_MENU
	        if( exit_key_flag == TRUE)
	        	{
 			 exit_key_flag =FALSE;
			mm_leave_all_menu();
		}
#endif
		//OSD_TrackObject( (POBJECT_HEAD) &g_win_mainmenu, C_UPDATE_ALL);
		break;
	}
	return ret;
}
示例#19
0
/*
 * Find a file in a search context.
 * The search context was created with vim_findfile_init() above.
 * Return a pointer to an allocated file name or NULL if nothing found.
 * To get all matching files call this function until you get NULL.
 *
 * If the passed search_context is NULL, NULL is returned.
 *
 * The search algorithm is depth first. To change this replace the
 * stack with a list (don't forget to leave partly searched directories on the
 * top of the list).
 */
char_u *vim_findfile(void *search_ctx_arg)
{
  char_u      *file_path;
  char_u      *rest_of_wildcards;
  char_u      *path_end = NULL;
  ff_stack_T  *stackp;
  int len;
  int i;
  char_u      *p;
  char_u      *suf;
  ff_search_ctx_T *search_ctx;

  if (search_ctx_arg == NULL)
    return NULL;

  search_ctx = (ff_search_ctx_T *)search_ctx_arg;

  /*
   * filepath is used as buffer for various actions and as the storage to
   * return a found filename.
   */
  file_path = xmalloc(MAXPATHL);

  /* store the end of the start dir -- needed for upward search */
  if (search_ctx->ffsc_start_dir != NULL)
    path_end = &search_ctx->ffsc_start_dir[
      STRLEN(search_ctx->ffsc_start_dir)];

  /* upward search loop */
  for (;; ) {
    /* downward search loop */
    for (;; ) {
      /* check if user user wants to stop the search*/
      ui_breakcheck();
      if (got_int)
        break;

      /* get directory to work on from stack */
      stackp = ff_pop(search_ctx);
      if (stackp == NULL)
        break;

      /*
       * TODO: decide if we leave this test in
       *
       * GOOD: don't search a directory(-tree) twice.
       * BAD:  - check linked list for every new directory entered.
       *       - check for double files also done below
       *
       * Here we check if we already searched this directory.
       * We already searched a directory if:
       * 1) The directory is the same.
       * 2) We would use the same wildcard string.
       *
       * Good if you have links on same directory via several ways
       *  or you have selfreferences in directories (e.g. SuSE Linux 6.3:
       *  /etc/rc.d/init.d is linked to /etc/rc.d -> endless loop)
       *
       * This check is only needed for directories we work on for the
       * first time (hence stackp->ff_filearray == NULL)
       */
      if (stackp->ffs_filearray == NULL
          && ff_check_visited(&search_ctx->ffsc_dir_visited_list
              ->ffvl_visited_list,
              stackp->ffs_fix_path
              , stackp->ffs_wc_path
              ) == FAIL) {
#ifdef FF_VERBOSE
        if (p_verbose >= 5) {
          verbose_enter_scroll();
          smsg((char_u *)"Already Searched: %s (%s)",
              stackp->ffs_fix_path, stackp->ffs_wc_path);
          /* don't overwrite this either */
          msg_puts((char_u *)"\n");
          verbose_leave_scroll();
        }
#endif
        ff_free_stack_element(stackp);
        continue;
      }
#ifdef FF_VERBOSE
      else if (p_verbose >= 5) {
        verbose_enter_scroll();
        smsg((char_u *)"Searching: %s (%s)",
            stackp->ffs_fix_path, stackp->ffs_wc_path);
        /* don't overwrite this either */
        msg_puts((char_u *)"\n");
        verbose_leave_scroll();
      }
#endif

      /* check depth */
      if (stackp->ffs_level <= 0) {
        ff_free_stack_element(stackp);
        continue;
      }

      file_path[0] = NUL;

      /*
       * If no filearray till now expand wildcards
       * The function expand_wildcards() can handle an array of paths
       * and all possible expands are returned in one array. We use this
       * to handle the expansion of '**' into an empty string.
       */
      if (stackp->ffs_filearray == NULL) {
        char_u *dirptrs[2];

        /* we use filepath to build the path expand_wildcards() should
         * expand.
         */
        dirptrs[0] = file_path;
        dirptrs[1] = NULL;

        /* if we have a start dir copy it in */
        if (!vim_isAbsName(stackp->ffs_fix_path)
            && search_ctx->ffsc_start_dir) {
          STRCPY(file_path, search_ctx->ffsc_start_dir);
          add_pathsep(file_path);
        }

        /* append the fix part of the search path */
        STRCAT(file_path, stackp->ffs_fix_path);
        add_pathsep(file_path);

        rest_of_wildcards = stackp->ffs_wc_path;
        if (*rest_of_wildcards != NUL) {
          len = (int)STRLEN(file_path);
          if (STRNCMP(rest_of_wildcards, "**", 2) == 0) {
            /* pointer to the restrict byte
             * The restrict byte is not a character!
             */
            p = rest_of_wildcards + 2;

            if (*p > 0) {
              (*p)--;
              file_path[len++] = '*';
            }

            if (*p == 0) {
              /* remove '**<numb> from wildcards */
              STRMOVE(rest_of_wildcards, rest_of_wildcards + 3);
            } else
              rest_of_wildcards += 3;

            if (stackp->ffs_star_star_empty == 0) {
              /* if not done before, expand '**' to empty */
              stackp->ffs_star_star_empty = 1;
              dirptrs[1] = stackp->ffs_fix_path;
            }
          }

          /*
           * Here we copy until the next path separator or the end of
           * the path. If we stop at a path separator, there is
           * still something else left. This is handled below by
           * pushing every directory returned from expand_wildcards()
           * on the stack again for further search.
           */
          while (*rest_of_wildcards
                 && !vim_ispathsep(*rest_of_wildcards))
            file_path[len++] = *rest_of_wildcards++;

          file_path[len] = NUL;
          if (vim_ispathsep(*rest_of_wildcards))
            rest_of_wildcards++;
        }

        /*
         * Expand wildcards like "*" and "$VAR".
         * If the path is a URL don't try this.
         */
        if (path_with_url(dirptrs[0])) {
          stackp->ffs_filearray = (char_u **)xmalloc(sizeof(char *));
          stackp->ffs_filearray[0] = vim_strsave(dirptrs[0]);
          stackp->ffs_filearray_size = 1;
        } else
          /* Add EW_NOTWILD because the expanded path may contain
           * wildcard characters that are to be taken literally.
           * This is a bit of a hack. */
          expand_wildcards((dirptrs[1] == NULL) ? 1 : 2, dirptrs,
              &stackp->ffs_filearray_size,
              &stackp->ffs_filearray,
              EW_DIR|EW_ADDSLASH|EW_SILENT|EW_NOTWILD);

        stackp->ffs_filearray_cur = 0;
        stackp->ffs_stage = 0;
      } else
        rest_of_wildcards = &stackp->ffs_wc_path[
          STRLEN(stackp->ffs_wc_path)];

      if (stackp->ffs_stage == 0) {
        /* this is the first time we work on this directory */
        if (*rest_of_wildcards == NUL) {
          /*
           * We don't have further wildcards to expand, so we have to
           * check for the final file now.
           */
          for (i = stackp->ffs_filearray_cur;
               i < stackp->ffs_filearray_size; ++i) {
            if (!path_with_url(stackp->ffs_filearray[i])
                && !os_isdir(stackp->ffs_filearray[i]))
              continue;                 /* not a directory */

            /* prepare the filename to be checked for existence
             * below */
            STRCPY(file_path, stackp->ffs_filearray[i]);
            add_pathsep(file_path);
            STRCAT(file_path, search_ctx->ffsc_file_to_search);

            /*
             * Try without extra suffix and then with suffixes
             * from 'suffixesadd'.
             */
            len = (int)STRLEN(file_path);
            if (search_ctx->ffsc_tagfile)
              suf = (char_u *)"";
            else
              suf = curbuf->b_p_sua;
            for (;; ) {
              /* if file exists and we didn't already find it */
              if ((path_with_url(file_path)
                   || (os_file_exists(file_path)
                       && (search_ctx->ffsc_find_what
                           == FINDFILE_BOTH
                           || ((search_ctx->ffsc_find_what
                                == FINDFILE_DIR)
                               == os_isdir(file_path)))))
#ifndef FF_VERBOSE
                  && (ff_check_visited(
                          &search_ctx->ffsc_visited_list->ffvl_visited_list,
                          file_path
                          , (char_u *)""
                          ) == OK)
#endif
                  ) {
#ifdef FF_VERBOSE
                if (ff_check_visited(
                        &search_ctx->ffsc_visited_list->ffvl_visited_list,
                        file_path
                        , (char_u *)""
                        ) == FAIL) {
                  if (p_verbose >= 5) {
                    verbose_enter_scroll();
                    smsg((char_u *)"Already: %s",
                        file_path);
                    /* don't overwrite this either */
                    msg_puts((char_u *)"\n");
                    verbose_leave_scroll();
                  }
                  continue;
                }
#endif

                /* push dir to examine rest of subdirs later */
                stackp->ffs_filearray_cur = i + 1;
                ff_push(search_ctx, stackp);

                if (!path_with_url(file_path))
                  simplify_filename(file_path);
                if (os_dirname(ff_expand_buffer, MAXPATHL)
                    == OK) {
                  p = path_shorten_fname(file_path,
                      ff_expand_buffer);
                  if (p != NULL)
                    STRMOVE(file_path, p);
                }
#ifdef FF_VERBOSE
                if (p_verbose >= 5) {
                  verbose_enter_scroll();
                  smsg((char_u *)"HIT: %s", file_path);
                  /* don't overwrite this either */
                  msg_puts((char_u *)"\n");
                  verbose_leave_scroll();
                }
#endif
                return file_path;
              }

              /* Not found or found already, try next suffix. */
              if (*suf == NUL)
                break;
              copy_option_part(&suf, file_path + len,
                  MAXPATHL - len, ",");
            }
          }
        } else {
          /*
           * still wildcards left, push the directories for further
           * search
           */
          for (i = stackp->ffs_filearray_cur;
               i < stackp->ffs_filearray_size; ++i) {
            if (!os_isdir(stackp->ffs_filearray[i]))
              continue;                 /* not a directory */

            ff_push(search_ctx,
                ff_create_stack_element(
                    stackp->ffs_filearray[i],
                    rest_of_wildcards,
                    stackp->ffs_level - 1, 0));
          }
        }
        stackp->ffs_filearray_cur = 0;
        stackp->ffs_stage = 1;
      }

      /*
       * if wildcards contains '**' we have to descent till we reach the
       * leaves of the directory tree.
       */
      if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) {
        for (i = stackp->ffs_filearray_cur;
             i < stackp->ffs_filearray_size; ++i) {
          if (fnamecmp(stackp->ffs_filearray[i],
                  stackp->ffs_fix_path) == 0)
            continue;             /* don't repush same directory */
          if (!os_isdir(stackp->ffs_filearray[i]))
            continue;               /* not a directory */
          ff_push(search_ctx,
              ff_create_stack_element(stackp->ffs_filearray[i],
                  stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
        }
      }

      /* we are done with the current directory */
      ff_free_stack_element(stackp);

    }

    /* If we reached this, we didn't find anything downwards.
     * Let's check if we should do an upward search.
     */
    if (search_ctx->ffsc_start_dir
        && search_ctx->ffsc_stopdirs_v != NULL && !got_int) {
      ff_stack_T  *sptr;

      /* is the last starting directory in the stop list? */
      if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
              (int)(path_end - search_ctx->ffsc_start_dir),
              search_ctx->ffsc_stopdirs_v) == TRUE)
        break;

      /* cut of last dir */
      while (path_end > search_ctx->ffsc_start_dir
             && vim_ispathsep(*path_end))
        path_end--;
      while (path_end > search_ctx->ffsc_start_dir
             && !vim_ispathsep(path_end[-1]))
        path_end--;
      *path_end = 0;
      path_end--;

      if (*search_ctx->ffsc_start_dir == 0)
        break;

      STRCPY(file_path, search_ctx->ffsc_start_dir);
      add_pathsep(file_path);
      STRCAT(file_path, search_ctx->ffsc_fix_path);

      /* create a new stack entry */
      sptr = ff_create_stack_element(file_path,
          search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
      ff_push(search_ctx, sptr);
    } else
      break;
  }

  free(file_path);
  return NULL;
}
示例#20
0
static void win_search_program_append(UINT32 tp_idx, UINT16 prog_idx)
{
	UINT32 si,i,j,n,cnt,str_len;
	UINT16* pstr;
	OSD_RECT rect;
	UINT8	shidx;
	char    str[30];
	
	DBG_PRINTF("Enter %s....\n",__FUNCTION__);
	
	if(prog_idx != INVALID_ID)
	{
		P_NODE p_node;

		get_prog_at(prog_idx, &p_node);
		MEMCPY(&win_search_cur_prog[p_node.av_flag], &p_node, sizeof(p_node));
		
		srch_ch_cnt[p_node.av_flag] ++;		
		cnt = srch_ch_cnt[p_node.av_flag];

		if(cnt <= INFOR_CHAN_CNT)
		{
			si = 0;
			n = cnt;
		}
		else
		{
			si = cnt - INFOR_CHAN_CNT;
			n = INFOR_CHAN_CNT;
		}

		if(si != 0)
		{
			for(i=0;i<n - 1;i++)
				MEMCPY(display_strs[10 + p_node.av_flag*10 + i], display_strs[10 + p_node.av_flag*10 + i + 1], MAX_DISP_STR_LEN*2);
		}

		pstr = display_strs[10 + p_node.av_flag*10 + n - 1];		
		if(p_node.ca_mode)
			ComAscStr2Uni("$", pstr);
		else
			ComAscStr2Uni("", pstr);
		str_len = ComUniStrLen(pstr);
		ComUniStrCopyChar((UINT8*)&pstr[str_len] ,p_node.service_name);

		if(p_node.av_flag == PROG_TV_MODE)
		{
			rect.uLeft 	= TVB_L + 20;//INFO_TV_L;
			rect.uTop  	= TVB_T + INFO_TXT_H;//INFO_TV_T+4;
			rect.uWidth = INFO_TV_W;
			rect.uHeight= INFO_TXT_H;
			shidx = TV_TXT_SH_IDX;
		}
		else
		{
			rect.uLeft 	= RADIOB_L + 20;//INFO_RADIO_L;
			rect.uTop  	= RADIOB_T + INFO_TXT_H;//INFO_RADIO_T+4;
			rect.uWidth = INFO_TV_W;//INFO_RADIO_W;
			rect.uHeight= INFO_TXT_H;
			shidx = RADIO_TXT_SH_IDX;
		}
		
		for(i=0;i<n;i++)
		{
			pstr = display_strs[10 + p_node.av_flag*10 + i];
			//win_srch_draw_info(&rect, NULL,pstr, shidx);
			win_srch_draw_info_ex(&rect, NULL,pstr, INFOMATION_TXT_IDX);
			rect.uTop += rect.uHeight;
		}


		rect.uTop = TVB_T+3;
		rect.uLeft += (rect.uWidth-80);
		rect.uWidth = 80;
        rect.uHeight = TXT_H;
		sprintf(str,"%d",cnt);
		win_srch_draw_info(&rect, str,NULL, shidx);
		tp_chsrched = 1;
		
	}

	if(tp_idx != 0xFFFFFFFF)
	{
		T_NODE t_node;
		S_NODE s_node;

		get_tp_by_id(tp_idx, &t_node);
		//get_sat_at(cur_sat_pos, VIEW_ALL,&s_node);
		get_sat_by_id(cur_sat_id, &s_node);
		srch_tp_cnt ++;

		cnt = srch_tp_cnt;
		if(cnt <= INFOR_TP_CNT)
		{
			si = 0;
			n = cnt;
		}
		else
		{
			si = cnt - INFOR_TP_CNT;
			n = INFOR_TP_CNT;
		}
		
		if(si != 0)
		{
			for(i=0;i<n - 1;i++)
			{
				MEMCPY(display_strs[ 30 + i], display_strs[30 + i + 1], MAX_DISP_STR_LEN*2);
			}
		}
		if(n>1)
		{
			pstr = display_strs[ 30 + n - 2];
#if 0			
			str_len = ComUniStrLen(pstr);
#else
			str_len = tp_info_chw_tbl[0] + tp_info_chw_tbl[1] + tp_info_chw_tbl[2] + tp_info_chw_tbl[3] + tp_info_chw_tbl[4];
#endif
			if(tp_chsrched)
				ComAscStr2Uni("OK", &pstr[str_len]);
			else
				ComAscStr2Uni("Failed", &pstr[str_len]);
		}

		pstr = display_strs[30 + n - 1];
		
		sprintf(str,"%d",srch_tp_cnt);
		ComAscStr2Uni(str,&pstr[0]);

#if 0		
		str_len = ComUniStrLen(pstr);
		str_len = tp_info_chw_tbl[0];
		ComUniStrCopyChar(&pstr[str_len], s_node.sat_name);
		str_len = ComUniStrLen(pstr);
		sprintf(str," %d %c %d ... ",t_node.frq,(t_node.pol == 0)? 'H' : 'V',t_node.sym);
		ComAscStr2Uni(str,&pstr[str_len]);
#else
		str_len = tp_info_chw_tbl[0];
		ComUniStrCopyChar((UINT8*)&pstr[str_len], s_node.sat_name);
		
		str_len += tp_info_chw_tbl[1];
		sprintf(str,"%d",t_node.frq);
		ComAscStr2Uni(str,&pstr[str_len]);
		
		str_len += tp_info_chw_tbl[2];
		sprintf(str,"%c",(t_node.pol == 0)? 'H' : 'V');
		ComAscStr2Uni(str,&pstr[str_len]);

		str_len += tp_info_chw_tbl[3];
		sprintf(str,"%d",t_node.sym);
		ComAscStr2Uni(str,&pstr[str_len]);

		str_len += tp_info_chw_tbl[4];
		STRCPY(str,"");
		ComAscStr2Uni(str,&pstr[str_len]);

#endif

		
		tp_chsrched = 0;
		
		rect.uLeft 	= INFO_TP_L;
		rect.uTop  	= INFO_TP_T;
		rect.uWidth = INFO_TP_W;
		rect.uHeight= INFO_TXT_H;
		shidx = TP_TXT_SH_IDX;
		for(i=0;i<n;i++)
		{
			
			pstr = display_strs[30 + i];
#if 0			
			win_srch_draw_info(&rect, NULL,pstr, shidx);
#else
			rect.uLeft 	= INFO_TP_L;
			str_len = 0;
			pstr = display_strs[30 + i];
			for(j=0;j<7;j++)
			{
				rect.uWidth = tp_info_w_tbl[j] - 2;	
				if(j != 5)
					win_srch_draw_info(&rect, NULL,pstr, shidx);				
				else
					win_srch_draw_info(&rect, "...",NULL, shidx);
				rect.uLeft +=  tp_info_w_tbl[j] ;
				if(j < 5)
				{
					pstr += tp_info_chw_tbl[j];
					//pstr += str_len;
				}
			}
#endif

			rect.uTop += rect.uHeight;
		}		

		
	}

	DBG_PRINTF("Exit %s....\n",__FUNCTION__);	
}
示例#21
0
static unsigned int util_listFilesRec(const char* dir, const char* suffix,
		char** fileNames, bool recursive, const unsigned int maxFileNames,
		unsigned int numFileNames, const char* relPath) {

	if (numFileNames >= maxFileNames) {
		return numFileNames;
	}

	struct _finddata_t fileInfo;
	int handle;

	// look for files which end in: suffix
	char suffixFilesSpec[strlen(dir) + strlen("\\*") + strlen(suffix) + 1];
	STRCPY(suffixFilesSpec, dir);
	STRCAT(suffixFilesSpec, "\\*");
	STRCAT(suffixFilesSpec, suffix);
	handle = _findfirst(suffixFilesSpec, &fileInfo);
	if (handle != -1L) {
		if (util_isFile(&fileInfo)) {
			fileNames[numFileNames++] = util_allocStrCpy(fileInfo.name);
		}
		while (_findnext(handle, &fileInfo) == 0
				&& numFileNames < maxFileNames) {
			if (util_isFile(&fileInfo)) {
				char fileRelPath[strlen(relPath) + strlen(fileInfo.name) + 1];
					STRCPY(fileRelPath, relPath);
					STRCAT(fileRelPath, fileInfo.name);
				fileNames[numFileNames++] = util_allocStrCpy(fileRelPath);
			}
		}
		_findclose(handle);
	}

	// search in sub-directories
	if (recursive) {
		char subDirsSpec[strlen(dir) + strlen("\\*.*") + 1];
		STRCPY(subDirsSpec, dir);
		STRCAT(subDirsSpec, "\\*.*");
		handle = _findfirst(subDirsSpec, &fileInfo);
		if (handle != -1L) {
			// check if not current or parent directories
			if (util_isNormalDir(&fileInfo)) {
				char subDir[strlen(dir) + strlen("\\")
						+ strlen(fileInfo.name) + 1];
				STRCPY(subDir, dir);
				STRCAT(subDir, "\\");
				STRCAT(subDir, fileInfo.name);
				char subRelPath[strlen(relPath) + strlen(fileInfo.name)
						+ strlen("\\") + 1];
				STRCPY(subRelPath, relPath);
				STRCAT(subRelPath, fileInfo.name);
				STRCAT(subRelPath, "\\");
				numFileNames = util_listFilesRec(subDir, suffix, fileNames,
						recursive, maxFileNames, numFileNames, subRelPath);
			}
			while (_findnext(handle, &fileInfo) == 0
					&& numFileNames < maxFileNames) {
				if (util_isNormalDir(&fileInfo)) {
					char subDir[strlen(dir) + strlen("\\")
							+ strlen(fileInfo.name) + 1];
					STRCPY(subDir, dir);
					STRCAT(subDir, "\\");
					STRCAT(subDir, fileInfo.name);
					char subRelPath[strlen(relPath) + strlen(fileInfo.name)
							+ strlen("\\") + 1];
					STRCPY(subRelPath, relPath);
					STRCAT(subRelPath, fileInfo.name);
					STRCAT(subRelPath, "\\");
					numFileNames = util_listFilesRec(subDir, suffix, fileNames,
							recursive, maxFileNames, numFileNames, subRelPath);
				}
			}
			_findclose(handle);
		}
	}

	return numFileNames;
}
示例#22
0
static void do_intro_line(int row, char_u *mesg, int add_version, int attr)
{
  char_u vers[20];
  int col;
  char_u *p;
  int l;
  int clen;

#ifdef MODIFIED_BY
# define MODBY_LEN 150
  char_u modby[MODBY_LEN];

  if (*mesg == ' ') {
    vim_strncpy(modby, (char_u *)_("Modified by "), MODBY_LEN - 1);
    l = STRLEN(modby);
    vim_strncpy(modby + l, (char_u *)MODIFIED_BY, MODBY_LEN - l - 1);
    mesg = modby;
  }
#endif  // ifdef MODIFIED_BY

  // Center the message horizontally.
  col = vim_strsize(mesg);

  if (add_version) {
    STRCPY(vers, mediumVersion);

    if (highest_patch()) {
      // Check for 9.9x or 9.9xx, alpha/beta version
      if (isalpha((int)vers[3])) {
        int len = (isalpha((int)vers[4])) ? 5 : 4;
        sprintf((char *)vers + len, ".%d%s", highest_patch(),
                mediumVersion + len);
      } else {
        sprintf((char *)vers + 3,   ".%d",   highest_patch());
      }
    }
    col += (int)STRLEN(vers);
  }
  col = (Columns - col) / 2;

  if (col < 0) {
    col = 0;
  }

  // Split up in parts to highlight <> items differently.
  for (p = mesg; *p != NUL; p += l) {
    clen = 0;

    for (l = 0; p[l] != NUL
         && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) {
      if (has_mbyte) {
        clen += ptr2cells(p + l);
        l += (*mb_ptr2len)(p + l) - 1;
      } else {
        clen += byte2cells(p[l]);
      }
    }
    screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr);
    col += clen;
  }

  // Add the version number to the version line.
  if (add_version) {
    screen_puts(vers, row, col, 0);
  }
}
示例#23
0
文件: movestr.c 项目: mingpen/OpenNT
BOOL
NetpMoveStrings(
    IN OUT LPTSTR * Floor,
    IN LPTSTR pInputBuffer,
    OUT LPTSTR pOutputBuffer,
    IN LPMOVESTRING MoveStringArray,
    IN LPDWORD MoveStringLength
    )

/*++

Routine Description:

    This function is used to move a variable number of strings into a user's
    buffer, and to update pointers in a structure to point to the location
    where they are copied.  According to the semantics of the LM 2.0 API,
    each buffer is filled with fixed length structures from the top, while
    variable length strings are copied in from the bottom.

    There are two companion arrays, MoveStringArray and MoveStringLength.
    MoveStringArray contains the offset to the source string in the input
    buffer, and the offset of the pointers in the fixed structure from the
    beginning of the output buffer.

    MoveStringLength contains an entry for each entry in MoveStringArray,
    and this entry is the length of the source string in MoveStringArray.
    This was broken into two arrays so that MoveStringArray could be built
    at compile time and not be modified at run time.

Arguments:

    Floor  -  This is the bottom of the user's buffer, where the strings
              will be copied.  This must be updated to reflect the strings
              that are copied into the buffer

    pInputBuffer - The buffer which contains the source strings.
              MoveStringArray contains offsets into this buffer.

    pOutputBuffer - The buffer which contains the fixed portion of the info
              structure, which contains fields that need to be set to point
              to the string locations in the output buffer. MoveStringArray
              contains offsets into this buffer.

    MoveStringArray - This is an array of MOVESTRING entries, terminated
              by an entry with a source offset of MOVESTRING_END_MARKER.  Each
              entry describes a string, and the address of a variable which will
              hold the address where the string is copied.

    MoveStringLength - This is a companion array to MoveStringArray.
              Each entry contains the length of the matching source string
              from MoveStringArray.

Side Effects:

    There are pointers in the MoveStringArray that point to pointers in the
    fixed length portion of the structure.  These are updated with the
    location in the buffer where the string is copied.

Return Value:

    TRUE  if the strings were successfully copied,
    FALSE if the strings would not all fit in the buffer.

--*/

{

    //
    // Move them all in, and update Floor
    //

    while(MoveStringArray->Source != MOVESTRING_END_MARKER) {

        //
        // Since the following is a really gross piece of code, let me
        // explain:
        //    pInputBuffer is a pointer to the start of a lanman struct and
        //    MoveStringArray->Source is an offset from the start of that
        //    structure to a PSZ.
        //

        // If this is a 0 length string, just place NULL in the pointer and
        // press on.

        if (*MoveStringLength == 0) {
            *((LPTSTR *) (((LPBYTE) pOutputBuffer)
                                + MoveStringArray->Destination)) = NULL;
        }
        else {
            //
            // Back the pointer up since we're filling the buffer from the
            // bottom up, then do the copy
            //

            *Floor -= *MoveStringLength;

            (void) STRCPY(*Floor,
                *((LPTSTR*)((LPBYTE)pInputBuffer + MoveStringArray->Source)));

            //
            // Update the field in the structure which points to the string
            //
            //          pOutputBuffer is a pointer to the start of a lanman struct
            //          and MoveStringArray->Destination is an offset from the start
            //          of that structure to a PSZ that needs to have the address of
            //          the just copied string put into it.
            //

            *((LPTSTR*) ((LPBYTE)pOutputBuffer + MoveStringArray->Destination)) =
                *Floor;
        }

        //
        // Now let's do the next one
        //

        MoveStringArray++;
        MoveStringLength++;
    }

    return(TRUE);
}
示例#24
0
/*===========================================================================
 * Main body
 *===========================================================================*/ 
char* AHC_GetSoundEffectFileName(AHC_SOUNDEFFECT_TYPE soundtype)
{	
	static char path[256];

	#if(STORAGE_FOR_FACTORY_INFO == INFO_NAND_FLASH)
    STRCPY(path, "SM:1:");
    #elif (STORAGE_FOR_FACTORY_INFO == INFO_SERIAL_FLASH)
    STRCPY(path,"SF:0:\\");
    #endif

    switch(soundtype)
    {
    case AHC_SOUNDEFFECT_SHUTTER:
        #ifdef CFG_CUS_SOUNDEFFECT_SHUTTER
        STRCAT(path,CFG_CUS_SOUNDEFFECT_SHUTTER);
        #else
        STRCAT(path,"Shutter.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_START:
        #ifdef CFG_CUS_SOUNDEFFECT_START
        STRCAT(path,CUS_SOUNDEFFECT_START);
        #else
        STRCAT(path,"start.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_BUTTON:
        #ifdef CFG_CUS_SOUNDEFFECT_BUTTON
        STRCAT(path,CFG_CUS_SOUNDEFFECT_BUTTON);
        #else
        STRCAT(path,"sound_operation.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_VR_START:
        #ifdef CFG_CUS_SOUNDEFFECT_VR_START
        STRCAT(path,CFG_CUS_SOUNDEFFECT_VR_START);
        #else
        STRCAT(path,"Record_start.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_VR_STOP:
        STRCAT(path,"Record_stop.wav");
        break;
    case AHC_SOUNDEFFECT_VR_SAVE:
    case AHC_SOUNDEFFECT_VR_EMER:
        STRCAT(path,"save_record.wav");
        break;
    case AHC_SOUNDEFFECT_FOCUS:
        STRCAT(path,"sound_focus.wav");
        break;
    case AHC_SOUNDEFFECT_ERROR:
        STRCAT(path,"sound_error.wav");
        break;
    case AHC_SOUNDEFFECT_CONFIRM:
        #if CFG_SOUND_EFFECT_SPECIAL_ENABLE
        STRCAT(path,"Record_start.wav");
        #else
        STRCAT(path,"sound_operation.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SELFTIMER:
        STRCAT(path,"SelfTimer.wav");
        break;
    case AHC_SOUNDEFFECT_POWERON:
        #ifdef CFG_CUS_SOUNDEFFECT_POWERON
        STRCAT(path,CFG_CUS_SOUNDEFFECT_POWERON);
        #else
        STRCAT(path,"Power_On.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_POWEROFF:
        #ifdef CFG_CUS_SOUNDEFFECT_POWEROFF
        STRCAT(path,CFG_CUS_SOUNDEFFECT_POWEROFF);
        #else
        STRCAT(path,"Power_Off.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SPCAMWARN:
        STRCAT(path,"speedcam_warning.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_CHT:
        #if(C005_TWN_ALERT_VOICE_UPDATE)
        STRCAT(path,"Speedcam_voice_CHT2.wav");
        #else
        STRCAT(path,"Speedcam_voice_CHT.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_CHS:
        #if(C005_TWN_ALERT_VOICE_UPDATE)
        STRCAT(path,"Speedcam_voice_CHS.wav");
        #else
        STRCAT(path,"Speedcam_voice_CHS.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_ENG:
        #if(C005_TWN_ALERT_VOICE_UPDATE)
        STRCAT(path,"Speedcam_voice_ENG.wav");
        #else
        STRCAT(path,"Speedcam_voice_ENG.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_RUS:
        #if(C005_TWN_ALERT_VOICE_UPDATE)
        STRCAT(path,"Speedcam_voice_RUS.wav");
        #else
        STRCAT(path,"Speedcam_voice_RUS.wav");
        #endif
        break;
    case AHC_SOUNDEFFECT_SPCAMRELEASE:
        STRCAT(path,"speedcam_release.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMOVERSPEED:
        STRCAT(path,"Overspeed.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_15KM_CHT:
        STRCAT(path,"15.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_20KM_CHT:
        STRCAT(path,"20.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_25KM_CHT:
        STRCAT(path,"25.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_30KM_CHT:
        STRCAT(path,"30.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_35KM_CHT:
        STRCAT(path,"35.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_40KM_CHT:
        STRCAT(path,"40.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_50KM_CHT:
        STRCAT(path,"50.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_60KM_CHT:
        STRCAT(path,"60.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_70KM_CHT:
        STRCAT(path,"70.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_80KM_CHT:
        STRCAT(path,"80.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_90KM_CHT:
        STRCAT(path,"90.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_100KM_CHT:
        STRCAT(path,"100.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_110KM_CHT:
        STRCAT(path,"110.wav");
        break;
    case AHC_SOUNDEFFECT_SPCAMVOICE_120KM_CHT:
        STRCAT(path,"120.wav");
        break;
    case AHC_SOUNDEFFECT_NO_SD_CARD:
        STRCAT(path,"no_sd_card_1.wav");
        break;
    case AHC_SOUNDEFFECT_FINDME:
        // for Net findme
        STRCAT(path,"findme.wav");
        break;
    case AHC_SOUNDEFFECT_WIFIFAIL:
        STRCAT(path,"WIFI_Fail.wav");
        break;
    case AHC_SOUNDEFFECT_LDWS_WARNING:
        STRCAT(path,"LDWS_Warning.wav");
        break;
    case AHC_SOUNDEFFECT_FCWS_WARNING:
        STRCAT(path,"FCWS_Warning.wav");
        break;
    case AHC_SOUNDEFFECT_HEADLIGHT_WARNING:
    	STRCAT(path,"HeadLight_Alert_CHT.wav");
    	break;
    case AHC_SOUNDEFFECT_FATIGUE_ALERT:
    	STRCAT(path,"FatigueAlert_CHT.wav");
    	break;
    
    default:
        return NULL;
        break;
    }
    return path;
}
示例#25
0
文件: expand.c 项目: mingpen/OpenNT
/* WIN32 MOD, CopyFile is a win32 API!*/
INT lz_CopyFile(INT doshSource, INT doshDest, PLZINFO pLZI)
{
   DWORD ucbRead, ucbWritten;

   // !!! Assumes pLZI parm is valid.  No sanity check (should be done above in caller).

   // Rewind input file again.
   if (FSEEK(doshSource, 0L, SEEK_SET) != 0L) {
      return(LZERROR_BADINHANDLE);
   }

   // Rewind output file.
   if (doshDest != NO_DOSH &&
       FSEEK(doshDest, 0L, SEEK_SET) != 0L) {
      return( LZERROR_BADOUTHANDLE );
   }

   // Set up a fresh buffer state.
   ResetBuffers();

   while ((ucbRead = FREAD(doshSource, pLZI->rgbyteInBuf, pLZI->ucbInBufLen)) > 0U &&
#ifdef LZA_DLL
           ucbRead != (DWORD)(-1))
#else
           FERROR() == 0)
#endif
   {
      if ((ucbWritten = FWRITE(doshDest, pLZI->rgbyteInBuf, ucbRead)) != ucbRead)
#ifdef LZA_DLL
         if (ucbWritten != (DWORD)(-1)) {
#else
         if (FERROR() != 0) {
#endif
            return(LZERROR_BADOUTHANDLE);
         }
         else {
            return(LZERROR_WRITE);
         }

      pLZI->cblOutSize += ucbWritten;

      if (ucbRead != pLZI->ucbInBufLen)
         break;
   }

#ifdef LZA_DLL
   // here, ucbRead ==  0,    EOF (proper loop termination)
   //               == -1,    bad DOS handle
   if (ucbRead == (DWORD)(-1)) {
#else
   // here, FERROR() == 0U,   EOF (proper loop termination)
   //                != 0U,   bad DOS handle
   if (FERROR() != 0U) {
#endif
      return(LZERROR_BADINHANDLE);
   }

   // Copy successful - return number of bytes copied.
   return(TRUE);
}


/*
** int ExpandOrCopyFile(int doshDource, int doshDest);
**
** Expands one file to another.
**
** Arguments:  doshSource - source DOS file handle
**             doshDest   - destination DOS file handle
**
** Returns:    int - TRUE if expansion finished successfully.  One of the
**                   LZERROR_ codes if not.
**
** Globals:    none
*/
INT ExpandOrCopyFile(INT doshSource, INT doshDest, PLZINFO pLZI)
{
   INT f;
   FH FHInfo;                 // compressed header info struct
   BOOL bExpandingFile;

   // !!! Assumes pLZI parm is valid.  No sanity check (should be done above in caller).

   // Get compressed file header.
   if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE
       && pLZI->cblInSize >= (LONG)HEADER_LEN)
      // read error occurred
      return(LZERROR_BADINHANDLE);

   // Expand or copy input file to output file.
   bExpandingFile = (IsCompressed(& FHInfo) == TRUE);

   if (bExpandingFile)
   {
      switch (FHInfo.byteAlgorithm)
      {
         case ALG_FIRST:
            f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L,
               TRUE, TRUE, pLZI);
            break;

#if 0
         case ALG_LZ:
            f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L,
               TRUE, FALSE, pLZI);
            break;
#endif

         default:
            f = LZERROR_UNKNOWNALG;
            break;
      }
   }
   else
      f = lz_CopyFile(doshSource, doshDest, pLZI);

   if (f != TRUE)
      return(f);

   // Flush output buffer to file.
   if ((f = FlushOutputBuffer(doshDest, pLZI)) != TRUE)
      return(f);

   // Copy date and time stamp from source file to destination file.
   if ((f = CopyDateTimeStamp(doshSource, doshDest)) != TRUE)
      return(f);

   // Did we expand the exact number of bytes we expected to from the
   // compressed file header entry?
   if (bExpandingFile &&
       (DWORD)pLZI->cblOutSize != FHInfo.cbulUncompSize)
      return(LZERROR_READ);

   // Expansion / copying finished successfully.
   return(TRUE);
}


/*
** int Expand(char ARG_PTR *pszSource, char ARG_PTR *pszDest, BOOL bDoRename);
**
** Expands one file to another.
**
** Arguments:  pszSource - name of file to compress
**             pszDest   - name of compressed output file
**             bDoRename - flag for output file renaming
**
** Returns:    int - TRUE if expansion finished successfully.  One of the
**                   LZERROR_ codes if not.
**
** Globals:    none
*/
INT Expand(
   NOTIFYPROC pfnNotify,
   CHAR ARG_PTR *pszSource,
   CHAR ARG_PTR *pszDest,
   BOOL bDoRename,
   PLZINFO pLZI)
{
   INT doshSource,            // input file handle
       doshDest,              // output file handle
       f;
   FH FHInfo;                 // compressed header info struct
   CHAR szDestFileName[MAX_PATH];

   // Sanity check
   if (!pLZI) {
      return(LZERROR_GLOBLOCK);
   }

   // Set up input file handle. Set cblInSize to length of input file.
   if ((f = GetIOHandle(pszSource, READ_IT, & doshSource, &pLZI->cblInSize)) != TRUE)
      return(f);

   if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE &&
       pLZI->cblInSize >= (LONG)HEADER_LEN)
   {
      // Read error occurred.
      FCLOSE(doshSource);
      return(LZERROR_BADINHANDLE);
   }

   // Create destination file name.

   STRCPY(szDestFileName, pszDest);

#if 0
   if (bDoRename == TRUE && FHInfo.byteAlgorithm != ALG_FIRST)
#else
   if (bDoRename == TRUE)
#endif
   {
      // Rename output file using expanded file name extension character
      // stored in compressed file header.
      MakeExpandedName(szDestFileName, FHInfo.byteExtensionChar);
   }

   // Ask if we should compress this file.
   if (! (*pfnNotify)(pszSource, szDestFileName, (WORD)
                      (IsCompressed(&FHInfo) ?  NOTIFY_START_EXPAND : NOTIFY_START_COPY)))
   {
      // Don't expand / copy file.  This error condition should be handled in
      // pfnNotify, so indicate that it is not necessary for the caller to
      // display an error message.
      FCLOSE(doshSource);
      return(BLANK_ERROR);
   }

   // Set up output file handle.
   if ((f = GetIOHandle(szDestFileName, WRITE_IT, & doshDest, &pLZI->cblInSize)) != TRUE)
   {
      FCLOSE(doshSource);
      return(f);
   }

   // Expand or copy input file into output file.
   f = ExpandOrCopyFile(doshSource, doshDest, pLZI);

   // Close files.
   FCLOSE(doshSource);
   FCLOSE(doshDest);

   return(f);
}
示例#26
0
void AAI::InitAI(IGlobalAICallback* callback, int team)
{
	aicb = callback;
	cb = callback->GetAICallback();

	// open log file
	char filename[500];
	char buffer[500];
	char team_number[3];

	SNPRINTF(team_number, 3, "%d", team);

	STRCPY(buffer, MAIN_PATH);
	STRCAT(buffer, AILOG_PATH);
	STRCAT(buffer, "AAI_log_team_");
	STRCAT(buffer, team_number);
	STRCAT(buffer, ".txt");
	ReplaceExtension (buffer, filename, sizeof(filename), ".txt");

	cb->GetValue(AIVAL_LOCATE_FILE_W, filename);

	file = fopen(filename,"w");

	fprintf(file, "AAI %s running mod %s\n \n", AAI_VERSION(team), cb->GetModHumanName());

	// load config file first
	cfg->LoadConfig(this);

	if(!cfg->initialized)
	{
		std::string errorMsg =
				std::string("Error: Could not load mod and/or general config file."
					" For further information see the config file under: ") +
				filename;
		cb->SendTextMsg(errorMsg.c_str(), 0);
		throw 1;
	}

	// create buildtable
	bt = new AAIBuildTable(cb, this);
	bt->Init();

	// init unit table
	ut = new AAIUnitTable(this, bt);

	// init map
	map = new AAIMap(this);
	map->Init();

	// init brain
	brain = new AAIBrain(this);

	// init executer
	execute = new AAIExecute(this, brain);

	// create unit groups
	group_list.resize(MOBILE_CONSTRUCTOR+1);

	// init airforce manager
	af = new AAIAirForceManager(this, cb, bt);

	// init attack manager
	am = new AAIAttackManager(this, cb, bt, map->continents.size());

	cb->SendTextMsg("AAI loaded", 0);
}
	bool OnProcess(void)
	{
		CStageMap& map = avej_lite::singleton<CStageMap>::get();

		if (GetSysDesc().stage.has_cleared)
		{
			SetSysDesc().stage.has_cleared = false;
			SetSysDesc().stage.current_stage = GetSysDesc().stage.current_stage + 1;

			if (GetSysDesc().stage.current_stage > 5)
			{
				g_ChangeState(STATE_ENDING_HAPPY);
				return false;
			}

			map.SetCurrentMap(GetSysDesc().stage.current_stage);

			SetSysDesc().stage.message.remained_ticks = SCROLL_DELAY_CALC(100);

			tchar stage_message[256];
			util::ComposeString(stage_message, TCHAR("STAGE @"), GetSysDesc().stage.current_stage);
			// -> sprintf(stage_message, "STAGE %d", GetSysDesc().stage.current_stage);

			SetSysDesc().stage.message.Set(stage_message);
		}

		CInputDevice& input_device = avej_lite::singleton<CInputDevice>::get();
		input_device.UpdateInputState();

		{
			bool has_pressed_exit_key;
			
			has_pressed_exit_key = input_device.WasKeyPressed(avej_lite::INPUT_KEY_SYS1);

			if (has_pressed_exit_key)
			{
				if ((assigned_(objects[MIN_FRIEND]) && objects[MIN_FRIEND]->IsValid()) ||
					(assigned_(objects[MAX_FRIEND]) && objects[MAX_FRIEND]->IsValid()))
					g_ChangeState(STATE_EXIT);
				else
					g_ChangeState(STATE_ENDING_BAD);

				return false;
			}
		}

		// process objects
		map.Move(SCROLL_SPEED, 0);

		{
			IGfxDevice::TDeviceDesc screenDesc;

			g_p_gfx_device->GetDesc(screenDesc);

			g_p_gfx_device->BeginDraw();

			// clear the screen
			g_p_back_buffer->StretchBlt(0, 0, 800, 480, g_p_res_sprite, 0, 512, 640, 216*2);

			// display background
			for (int j = 0; j < 8; j++)
			for (int i = 0; i < 18; i++)
			{
				int x_offset = map.GetXOffset();
				int y_offset = map.GetYOffset();

				if (map.GetTile(i*TILE_X_SIZE-x_offset, j*TILE_Y_SIZE-y_offset) > 0)
				{
					gfx::DrawImage(i*TILE_X_SIZE-x_offset, j*TILE_Y_SIZE-y_offset+Y_DOWN+1,tile_data[TILENAME_TILE_GROUND]->m_p_sprite);
				}
			}

			for (int i = MAX_ENEMY; i >= MIN_OBJECTS; i--)
			{
				if (assigned_(objects[i]))
				{
					if (objects[i]->ProcessByAI())
					{
						if (objects[i]->IsValid())
						{
							objects[i]->ProcessByGravity();
							objects[i]->Display();
						}
						else
						{
							delete objects[i];
							objects[i] = NULL;
						}
					}
					else
					{
						delete objects[i];
						objects[i] = NULL;
					}
				}
			}

			{
				gui::CFloatMessage& message = avej_lite::singleton<gui::CFloatMessage>::get();
				message.Show();
			}

			g_p_back_buffer->StretchBlt
			(
				0, 0, 800, 31,
				g_p_res_sprite,
				g_sprite_rect[TILENAME_TILE_STATUS_BAR].x,
				g_sprite_rect[TILENAME_TILE_STATUS_BAR].y,
				g_sprite_rect[TILENAME_TILE_STATUS_BAR].w,
				g_sprite_rect[TILENAME_TILE_STATUS_BAR].h
			);

			{
				int   i = 0;
				int   j = 0;
				tchar s1[64] = {0, };
				tchar s2[64] = {0, };
				int   number1 = 0;
				int   number2 = 0;

				if (assigned_(objects[MIN_FRIEND]))
				{
					TFriend* p_friend = (TFriend*)objects[MIN_FRIEND];
					i = p_friend->m_hit_point;
					number1 = p_friend->m_special_weapon;
					util::ComposeString(s1, TCHAR("@"), p_friend->GetLevel());
					// -> sprintf(s1, "%d", p_friend->GetLevel());
				}
				if (assigned_(objects[MAX_FRIEND]))
				{
					TFriend* p_friend = (TFriend*)objects[MAX_FRIEND];
					j = p_friend->m_hit_point;
					number2 = p_friend->m_special_weapon;
					util::ComposeString(s2, TCHAR("@"), p_friend->GetLevel());
					// -> sprintf(s2, "%d", p_friend->GetLevel());
				}

				switch (GetSysDesc().GetPlayerMode())
				{
					case PLAYERMODE_PLAYER1_ONLY:
						i = 104 + i;
						j = 424;
						break;
					case PLAYERMODE_PLAYER2_ONLY:
						j = 424 + i;
						i = 104;
						STRCPY(s2, s1);
						STRCPY(s1, TCHAR(""));
						number2 = number1;
						number1 = 0;
						break;
					case PLAYERMODE_DOUBLE_MODE1:
						i = 104 + i;
						j = 424 + j;
						break;
					case PLAYERMODE_DOUBLE_MODE2:
						{
							int k;

							k = i;
							i = 104 + j;
							j = 424 + k;

							k = number1;
							number1 = number2;
							number2 = k;

							tchar s3[64];
							STRCPY(s3, s2);
							STRCPY(s2, s1);
							STRCPY(s1, s3);
						}
						break;
				}

				if (i < 208)
				{
					// i: 104~208
					// (x:129,y:12)-(w:132,h:5)
					int percentage = (i-104) * 100 / (208-104);

					int x1 = 129;
					int y1 = 12;
					int x2 = 129 + 132;
					int y2 = y1 + 5;

					x1 = x1 + 132 * percentage / 100;

					gfx::FillRect(0xFF000000, x1, y1, x2-x1, y2-y1);
				}

				if (j < 528)
				{
					// j: 424~528
					// (x:530,y:12)-(w:131,h:5)
					int percentage = (j-424) * 100 / (528-424);

					int x1 = 530;
					int y1 = 12;
					int x2 = 530 + 131;
					int y2 = y1 + 5;

					x1 = x1 + 131 * percentage / 100;

					gfx::FillRect(0xFF000000, x1, y1, x2-x1, y2-y1);
				}

				if (s1[0])
				{
					gfx_ix::DrawText(341,4,s1,TIndexColor(3));
					gfx_ix::DrawText(340,3,s1,TIndexColor(4));
				}
				if (s2[0])
				{
					gfx_ix::DrawText(741,4,s2,TIndexColor(3));
					gfx_ix::DrawText(740,3,s2,TIndexColor(4));
				}
				if (number1 > 0)
				{
					if (number1 > 10) number1 = 10;
					for (int i = 0; i < number1; i++)
					{
						gfx::DrawSprite(i*24+TILE_X_SIZE,30,tile_data[TILENAME_SMGAL_SP]->m_p_sprite,true);
					}
				}
				if (number2 > 0)
				{
					if (number2 > 10) number2 = 10;
					for (int i = 0; i < number2; i++)
					{
						gfx::DrawSprite(i*24+TILE_X_SIZE+330,36,tile_data[TILENAME_NETO_SP]->m_p_sprite,true);
					}
				}
			}

			if (GetSysDesc().stage.message.remained_ticks > 0)
			{
				SetSysDesc().stage.message.remained_ticks = GetSysDesc().stage.message.remained_ticks - 1;
				int i = (640/24 - STRLEN(GetSysDesc().stage.message.Get())) / 2;
				gfx_ix::DrawText_x2(i*12, 85, GetSysDesc().stage.message.Get(), TIndexColor(11));
			}

			gui::CButtonGroupFull::Show();

			// flip the screen
			g_p_gfx_device->EndDraw();
			g_p_gfx_device->Flip();
		}

		if (map.IsEndOfMap())
		{
			int k = 0;
			for (int i = MIN_ENEMY; i <= MAX_ENEMY; i++)
			{
				if (assigned_(objects[i]))
					k++;
			}
			if (k == 0)
			{
				SetSysDesc().stage.has_cleared = true;
//				ascii_code  = ascii_code + [_ESC_KEY];
			}
		}

		return true;
	}
示例#28
0
acpi_status
acpi_get_object_info (
	acpi_handle             handle,
	acpi_device_info        *info)
{
	acpi_device_id          hid;
	acpi_device_id          uid;
	acpi_status             status;
	u32                     device_status = 0;
	acpi_integer            address = 0;
	acpi_namespace_node     *node;


	/* Parameter validation */

	if (!handle || !info) {
		return (AE_BAD_PARAMETER);
	}

	acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);

	node = acpi_ns_map_handle_to_node (handle);
	if (!node) {
		acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
		return (AE_BAD_PARAMETER);
	}

	info->type      = node->type;
	info->name      = node->name;

	acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);

	/*
	 * If not a device, we are all done.
	 */
	if (info->type != ACPI_TYPE_DEVICE) {
		return (AE_OK);
	}


	/*
	 * Get extra info for ACPI devices only.  Run the
	 * _HID, _UID, _STA, and _ADR methods.  Note: none
	 * of these methods are required, so they may or may
	 * not be present.  The Info->Valid bits are used
	 * to indicate which methods ran successfully.
	 */
	info->valid = 0;

	/* Execute the _HID method and save the result */

	status = acpi_ut_execute_HID (node, &hid);
	if (ACPI_SUCCESS (status)) {
		STRNCPY (info->hardware_id, hid.buffer, sizeof(info->hardware_id));

		info->valid |= ACPI_VALID_HID;
	}

	/* Execute the _UID method and save the result */

	status = acpi_ut_execute_UID (node, &uid);
	if (ACPI_SUCCESS (status)) {
		STRCPY (info->unique_id, uid.buffer);

		info->valid |= ACPI_VALID_UID;
	}

	/*
	 * Execute the _STA method and save the result
	 * _STA is not always present
	 */
	status = acpi_ut_execute_STA (node, &device_status);
	if (ACPI_SUCCESS (status)) {
		info->current_status = device_status;
		info->valid |= ACPI_VALID_STA;
	}

	/*
	 * Execute the _ADR method and save result if successful
	 * _ADR is not always present
	 */
	status = acpi_ut_evaluate_numeric_object (METHOD_NAME__ADR,
			  node, &address);

	if (ACPI_SUCCESS (status)) {
		info->address = address;
		info->valid |= ACPI_VALID_ADR;
	}

	return (AE_OK);
}
示例#29
0
redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int port0, char *pwd, int db)
{

  struct redisLibeventEvents *e = NULL;
  redisAsyncContext *ac = NULL;

  char ip[256];
  if(ip0 && ip0[0])
	  STRCPY(ip,ip0);
  else
	  STRCPY(ip,"127.0.0.1");

  int port = DEFAULT_REDIS_PORT;
  if(port0>0)
	  port=port0;
  
  ac = redisAsyncConnect(ip, port);
  if (ac->err) {
  	fprintf(stderr,"Error: %s\n", ac->errstr);
  	return NULL;
  }

  /* Create container for context and r/w events */
  e = (struct redisLibeventEvents*)turn_malloc(sizeof(struct redisLibeventEvents));
  ns_bzero(e,sizeof(struct redisLibeventEvents));

  e->allocated = 1;
  e->context = ac;
  e->base = base;

  /* Register functions to start/stop listening for events */
  ac->ev.addRead = redisLibeventAddRead;
  ac->ev.delRead = redisLibeventDelRead;
  ac->ev.addWrite = redisLibeventAddWrite;
  ac->ev.delWrite = redisLibeventDelWrite;
  ac->ev.cleanup = redisLibeventCleanup;

  ac->ev.data = e;

  /* Initialize and install read/write events */
  e->rev = event_new(e->base,e->context->c.fd,
  		     EV_READ|EV_PERSIST,redisLibeventReadEvent,
  		     e);

  e->wev = event_new(e->base,e->context->c.fd,
		     EV_WRITE,redisLibeventWriteEvent,
  		     e);

  if (e->rev == NULL || e->wev == NULL) {
	  turn_free(e, sizeof(struct redisLibeventEvents));
	  return NULL;
  }
  
  event_add(e->wev, NULL);
  e->wev_set = 1;

  struct bufferevent *pair[2];

  bufferevent_pair_new(base, TURN_BUFFEREVENTS_OPTIONS, pair);
  e->in_buf = pair[0];
  e->out_buf = pair[1];
  bufferevent_setcb(e->in_buf, receive_message_for_redis, NULL, NULL, e);
  bufferevent_enable(e->in_buf, EV_READ);

  //Authentication
  if(pwd)
	  redisAsyncCommand(ac, NULL, e, "AUTH %s", pwd);

  if(db>0)
	  redisAsyncCommand(ac, NULL, e, "SELECT %d", db);

  return ac;
}
示例#30
0
void win_progname_draw_infor(void)
{
	UINT16 group_name[MAX_SERVICE_NAME_LENGTH + 1 + 10];
	UINT8   group_type,av_mode;

	UINT16 cur_channel;
	P_NODE p_node;
	S_NODE s_node;
//	T_NODE t_node;
	char string[100];
	char prog_name[MAX_SERVICE_NAME_LENGTH + 1];
	INT32 ret,len;
	UINT32 i,j;
	BITMAP* bmp;
	TEXT_FIELD* txt;
	UINT16 icon;
	date_time dt;
	prog_txt_t* p_prog_txt;
	prog_bmp_t* p_prog_bmp;
	eit_event_info_t *pe=NULL,*fe=NULL;
	UINT8 *s1=NULL,*s2=NULL;
	INT32 strlen;
	struct ACTIVE_SERVICE_INFO service;

	struct t_ttx_lang *ttx_lang_list;
	UINT8 ttx_lang_num;
	struct t_subt_lang* sub_lang_list;
	UINT8 sub_lang_num;

	bmp = &prog_bmp;
	txt = &prog_text;
	UINT32 fav_mask;

	fav_mask = 0;
	for(i=0;i<MAX_FAVGROUP_NUM;i++)
		fav_mask |= (0x01<<i);


	av_mode = sys_data_get_cur_chan_mode();
	cur_channel = sys_data_get_cur_group_cur_mode_channel();
	ret = get_prog_at(cur_channel,&p_node);
	get_sat_by_id(p_node.sat_id, &s_node);
	get_cur_group_name((char*)group_name,&group_type);
	get_local_time(&dt);
/*
#ifdef _EPG_MULTI_SERVICE
#ifdef EPG_FAST_PARSE			
	epg_fast_pasrse_set(FALSE,NULL,NULL);
#endif
	get_tp_by_id(p_node.tp_id, &t_node);
	api_epg_parse(p_node.tp_id, t_node.network_id, t_node.t_s_id, p_node.prog_number, epg_type_pf);

	struct active_service_t service;
	service.tp_id = p_node.tp_id;
	service.orig_network_id = t_node.network_id;
	service.ts_id = t_node.t_s_id;
	service.service_id = p_node.prog_number;
	api_epg_set_active_service(&service, 1);

	api_epg_parse(p_node.tp_id, t_node.network_id, t_node.t_s_id, p_node.prog_number, epg_type_pf);
#endif
*/
	service.tp_id = p_node.tp_id;
	service.service_id = p_node.prog_number;
	epg_set_active_service(&service, 1);

	/*current next epg info */
	pe=epg_get_cur_service_event((INT32)cur_channel, PRESENT_EVENT, NULL,NULL,NULL, /*event_update*/TRUE);
	fe=epg_get_cur_service_event((INT32)cur_channel, FOLLOWING_EVENT, NULL,NULL,NULL, event_update);
    if(event_update==FALSE)
    {
        if(pe==NULL || fe==NULL)
        {
            event_update = TRUE;    
        }
    }
    else
    {
        if(pe!=NULL && fe!=NULL)
        {
            event_update = FALSE;
        }
    }
	s1=epg_get_event_name(pe, &len);
//	s1=(UINT8*)epg_get_event_name(pe, present_name, 32);
	s2=epg_get_event_name(fe, &len);
//	s2=(UINT8*)epg_get_event_name(fe, following_name, 32);

	TTXEng_GetInitLang(&ttx_lang_list, &ttx_lang_num);
	subt_get_language(&sub_lang_list ,&sub_lang_num);
	if(sub_lang_num == 0)
		TTXEng_GetSubtLang(&ttx_lang_list,&sub_lang_num);

		
	for(i=0;i<PROG_BMP_NUM;i++)
	{
	    p_prog_bmp = &prog_bmps[i];
	    icon = INVALID_ID;
	    switch(p_prog_bmp->bmp_type)
	    {
	     case PROG_BMP_STATIC:
	        icon = prog_bmps[i].icon;
	       break;
#ifndef MODIFY_FOR_EGYPT_CUSTOMER	   
	    case PROG_BMP_AV_TYPE:
	        if(av_mode==TV_CHAN)
	            icon = IM_INFO_BAR_TV;
	        else
	            icon = IM_INFO_BAR_RADIO;            
	        break;
#endif
	    case PROG_BMP_EPG:
	        if( (s1||s2) )
	            icon = prog_bmps[i].icon;
	        break;
	    case PROG_BMP_TTX:
			if(ttx_lang_num>0)
	            icon = prog_bmps[i].icon;
	        break;
	    case PROG_BMP_SUBT:
			if(sub_lang_num>0)
	            icon = prog_bmps[i].icon;
	        break;			
	    case PROG_BMP_LOCK:
	        if(p_node.lock_flag)
	            icon = prog_bmps[i].icon;
	        break;
	    case PROG_BMP_FAV:
			if(p_node.fav_group[0] & fav_mask)
				icon = prog_bmps[i].icon;
	       break;
	    case PROG_BMP_CA:
			{
#if 0				
				BOOL			b,bFlag;

				INT8 level,quality,lock;
				signal_lock_status lock_flag;
				signal_scramble_status scramble_flag;
				signal_lnbshort_status lnbshort_flag;
				signal_parentlock_status parrentlock_flag;

				bFlag = GetSignalStatus(&lock_flag, &scramble_flag,&lnbshort_flag,&parrentlock_flag);  
				if(bFlag && lock_flag== SIGNAL_STATUS_LOCK
					&& lnbshort_flag==SIGNAL_STATUS_LNBNORMAL 
					&& parrentlock_flag==SIGNAL_STATUS_PARENT_UNLOCK
					&& scramble_flag == SIGNAL_STATUS_SCRAMBLED)
					icon = prog_bmps[i].icon;
#else
				if(p_node.ca_mode)
					icon = prog_bmps[i].icon;
#endif				
					
        	}
			break;
        default:
            break;
        }
	OSD_SetBitmapContent(bmp, icon);
	OSD_SetRect(&bmp->head.frame, p_prog_bmp->left, p_prog_bmp->top, p_prog_bmp->width,p_prog_bmp->height);
	OSD_DrawObject( (OBJECT_HEAD*) bmp, C_UPDATE_ALL);
    }
    
    for(i=0;i<PROG_TXT_NUM;i++)
    {
        p_prog_txt = &prog_txts[i];
        
        string[0] = '\0';
        switch(p_prog_txt->txt_type)
        {
        case PROG_TXT_PROG_NAME: 
#ifndef DB_USE_UNICODE_STRING  
            STRCPY(prog_name,p_node.service_name);
            for(j=0;j<STRLEN(prog_name);j++)
                if(prog_name[j] >= 0x80)
                {
                    prog_name[j] = '\0';
                    break;
                }
            if(p_node.ca_mode==0)
                sprintf(string,"%s(%s)",prog_name,s_node.sat_name);
            else
                sprintf(string,"$%s(%s)",prog_name,s_node.sat_name);

#else
            if(p_node.ca_mode==0)
                STRCPY(string,"");
            else
                STRCPY(string,"$");
			
            ComAscStr2Uni(string,len_display_str);
            strlen = ComUniStrLen( len_display_str);
            //strcpy_uni(&len_display_str[strlen],p_node.service_name);
            ComUniStrCopyChar((UINT8 * )&len_display_str[strlen],p_node.service_name);
            strlen = ComUniStrLen( len_display_str);
            ComAscStr2Uni("(",&len_display_str[strlen]);
            strlen = ComUniStrLen( len_display_str);
            ComUniStrCopyChar((UINT8 * )&len_display_str[strlen],s_node.sat_name);
            strlen = ComUniStrLen( len_display_str);
            ComAscStr2Uni(")",&len_display_str[strlen]);
#endif            
            
            break;
        case PROG_TXT_DATE:
            sprintf(string,"%02d/%02d",dt.month,dt.day);
            ComAscStr2Uni(string, (UINT16 *)len_display_str);
            break;
        case PROG_TXT_TIME:
            sprintf(string,"%02d:%02d",dt.hour,dt.min);
            ComAscStr2Uni(string, (UINT16 *)len_display_str);
            break;
        case PROG_TXT_PROG_NUM:
            sprintf(string,"%04d",cur_channel + 1);
            ComAscStr2Uni(string, (UINT16 *)len_display_str);
            break;
        case PROG_TXT_EPG_NOW:
            if (s1 )				
			{
				sprintf(string,"Now: ");
				ComAscStr2Uni(string, (UINT16 *)len_display_str);
				len =ComUniStrLen(len_display_str);
				ComUniStrCopyChar((UINT8*)&len_display_str[len],s1);
			}
            else
			{
                        OSD_SetTextFieldStrPoint(txt,NULL);
                        OSD_SetTextFieldContent(txt,STRING_ID,RS_EPG_NO_INFORMATION);
			}
            break;
        case PROG_TXT_EPG_NEXT:
            if (s2)				
			{
				sprintf(string,"Next: ");
				ComAscStr2Uni(string, (UINT16 *)len_display_str);
				len =ComUniStrLen(len_display_str);
				ComUniStrCopyChar((UINT8*)&len_display_str[len],s2);		
			}
            else
			{
	            sprintf(string," ");
	            ComAscStr2Uni(string, (UINT16 *)len_display_str);
			}
    	     break;
        case PROG_TXT_PROG_GROUP:
#ifndef DB_USE_UNICODE_STRING  
            sprintf(string,"%s",group_name);
#else
            ComUniStrCopy(len_display_str, group_name);
#endif
            break;
        default:
            ;
        }  

#ifndef DB_USE_UNICODE_STRING
        ComAscStr2Uni(string, (UINT16 *)len_display_str);
#else

/*
        if(p_prog_txt->txt_type != PROG_TXT_PROG_NAME 
            && p_prog_txt->txt_type != PROG_TXT_PROG_GROUP
                        &&p_prog_txt->txt_type != PROG_TXT_EPG_NOW
            &&p_prog_txt->txt_type != PROG_TXT_EPG_NEXT)
            ComAscStr2Uni(string, (UINT16 *)len_display_str);
*/
	if(p_prog_txt->txt_type == PROG_TXT_PROG_NUM) 
		txt->head.bFont = 2;
	else
		txt->head.bFont = 0;
 
#endif

	OSD_SetRect(&txt->head.frame, p_prog_txt->left, p_prog_txt->top, p_prog_txt->width,p_prog_txt->height);
	//txt->pText = (UINT8*)len_display_str;
	txt->head.style.bShowIdx = p_prog_txt->shidx;
	OSD_DrawObject( (OBJECT_HEAD *)txt, C_UPDATE_ALL);
	OSD_SetTextFieldContent(txt,STRING_ID,0);
	OSD_SetTextFieldStrPoint(txt,len_display_str);
    }
#ifdef MODIFY_FOR_EGYPT_CUSTOMER
	progname_signal_refresh(TRUE);
#endif

}