Пример #1
0
CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true */)
{
	std::string szBinaryPath = szPath;
#ifdef __linux__
	if (bSrvCheck && !str_ends_with(szBinaryPath.data(), "_srv") && !str_ends_with(szBinaryPath.data(), ".so"))
		szBinaryPath += "_srv.so";
	else if (!str_ends_with(szBinaryPath.data(), ".so"))
		szBinaryPath += ".so";
#endif

	unsigned long ulAddr = (unsigned long) dlLoadLibrary(szBinaryPath.data());
#ifdef __linux__
	if (!ulAddr)
	{
		char szGameDir[MAX_PATH_LENGTH];
		engine->GetGameDir(szGameDir, MAX_PATH_LENGTH);

		// If the previous path failed, try the "bin" folder of the game.
		// This will allow passing e.g. "server" to this function.
		szBinaryPath = std::string(szGameDir) + "/bin/" + szBinaryPath;
		ulAddr = (unsigned long) dlLoadLibrary(szBinaryPath.data());
	}
#endif

	if (!ulAddr)
	{
		szBinaryPath = "Unable to find " + szBinaryPath;
		#ifdef _WIN32
			if (!str_ends_with(szBinaryPath.data(), ".dll"))
				szBinaryPath += ".dll";
		#endif
		BOOST_RAISE_EXCEPTION(PyExc_IOError, szBinaryPath.data())
	}
Пример #2
0
static int is_ngs_file(const char* filename)
	{
	return ( str_ends_with(filename,".bam") ||
	     	fileExtExists(filename,".tbi") ||
	     	str_ends_with(filename,".fastq.gz") ||
	     	str_ends_with(filename,".fq.gz") ||
	     	(str_ends_with(filename,".fasta") && fileExtExists(filename,".fai")) ||
	     	(str_ends_with(filename,".fa") && fileExtExists(filename,".fai"))?
	     	TRUE : FALSE );
	}
Пример #3
0
static void cb_switch_state(zhandle_t *zh, int type, int state, const char *path, void *ctx) 
{
	service_location_t *service = (service_location_t *) ctx;
	
	if (type == ZOO_SESSION_EVENT) {
		if (state == ZOO_CONNECTED_STATE) {
			LOG_INFO(service->log_fd, "Changed to connected state");
			service->connected_state = true;
			create_service_nodes(service);
		}
		else if (state == ZOO_EXPIRED_SESSION_STATE || 
				 state == ZOO_CONNECTING_STATE) {
			LOG_INFO(service->log_fd, "Changed to disconnected state, trying to reconnect");
			service->connected_state = false;
			disconnect_zookeeper(service);
			connect_zookeeper(service, true);
		}
	}
	else if (type == ZOO_DELETED_EVENT) {
		char token[HOSTNAME_MAX + 1];
		snprintf(token, HOSTNAME_MAX + 1, "/%s", service->hostname);

		if (str_ends_with(path, token) == true) {
			create_service_nodes(service);
		}
	}
}
Пример #4
0
static char *make_dir_path(const char *path, baton_error_t *error) {
    size_t slen = strnlen(path, MAX_STR_LEN);
    size_t dlen = slen + 1; // +1 for NUL
    // Only trim trailing '/' if the path is >1 character long
    if (slen > 1 && str_ends_with(path, "/", MAX_STR_LEN)) {
        dlen--;
    }

    if (dlen > MAX_STR_LEN) {
        set_baton_error(error, CAT_INVALID_ARGUMENT,
                        "The path '%s' exceeded the maximum "
                        "length of %d characters", path, MAX_STR_LEN);
        goto error;
    }

    char *dpath = NULL;
    dpath = calloc(dlen, sizeof (char));
    if (!dpath) {
        set_baton_error(error, errno, "Failed to allocate memory: error %d %s",
                        errno, strerror(errno));
        goto error;
    }

    snprintf(dpath, dlen, "%s", path);

    return dpath;

error:
    return NULL;
}
bool
string_buffer_ends_with (string_buffer_t *sb, const char *str)
{
    assert (sb != NULL);
    assert (str != NULL);

    return str_ends_with (sb->s, str);
}
Пример #6
0
/*
 * jenkins_color_atoi() - converts a string status to its traffic light counterpart.
 *
 * @color:	A string with a jenkins color status.
 *
 * Converts a string denoting a status of a jenkins job to its numeric 
 * led status counterpart. 
 */
int jenkins_color_to_led(const char* color) 
{
	int status = 0;
	if (str_starts_with(color, "blue")) status = LED_GREEN;
	if (str_starts_with(color, "yellow")) status = LED_ORANGE;
	if (str_starts_with(color, "red")) status = LED_RED;
	if (str_starts_with(color, "disabled")) status = LED_OFF;
	if (str_starts_with(color, "grey")) status = LED_GREEN | LED_ORANGE | LED_RED | LED_BLINKING;
	if (str_starts_with(color, "aborted")) status = LED_OFF;
	if (str_ends_with(color, "anime")) status |= LED_BLINKING;
	return status;
}
Пример #7
0
void DeployDevCommand::parseParameters()
{
    exe_change  = _tcscmp(m_vecArgv[3], L"1") == 0 ? true : false;
	app_name    = m_vecArgv[4];
	bundle_path = m_vecArgv[5];
	app_exe     = m_vecArgv[6];
	log_port    = m_vecArgv[7];
	lcdll_path  = m_vecArgv[8];

    if ((!use_shared_runtime) && app_exe)
        use_shared_runtime = str_ends_with(app_exe, L".lnk");
}
Пример #8
0
void training_image(const char *filename) {
    char fname[256];
#ifndef ANDROID
    if (str_ends_with(filename,".jpg")) {
#endif
        fig = filename[0];
        strcpy(fname,DIR_TR);
        strcat(fname, filename);
        getFeaturesFN( fname );
#ifndef ANDROID
    }
#endif
}
Пример #9
0
enum item_types resolve_item(struct dirent * entry){
    enum item_types type;
    switch( entry->d_type ){
        case DT_REG:
            if( str_ends_with(entry->d_name, ".zip") ) {
                type = ITEM_ARCHIVE;
            } else if ( str_ends_with(entry->d_name, ".jpg" )) {
                type = ITEM_IMAGE;
            } else if ( str_ends_with(entry->d_name, ".png" )) {
                type = ITEM_PNG;
            } else if ( str_ends_with(entry->d_name, ".pdf" )) {
                type = ITEM_PDF;
            } else if ( str_ends_with(entry->d_name, ".gif" )) {
                type = ITEM_GIF;
            } else {
                type = ITEM_FILE; // text file?
            }
            break;
        case DT_DIR: type = ITEM_DIR; break;
        default: type = NO_ITEM;
    }
    return type;
}
Пример #10
0
void test_finda() {
    char** exts = str_strings(".o",".d",".obj",NULL);
    str_t extensions[] = {".o",".d",".obj",NULL};
    str_t file = "bonzo.d";
    // use with llib arrays, with start index
    FINDA(idx,exts,0,str_ends_with(file,_));
    assert(idx == 1);
    // use with any NULL-terminated array
    FINDZ(i,extensions,str_ends_with(file,_));
    assert(i == 1);
    
    int nums[] = {-1,-2,2,-1,4,3};
    int *arr = array_new_init(int,nums);

    // unrolling a loop for searching through an array
    // we need different names because FINDA/Z declares a new index.
    FINDA(i1,arr,0, _ > 0);
    assert(i1 == 2);
    FINDA(i2,arr,i1+1, _ > 0);
    assert(i2 == 4);
    FINDA(i3,arr,i2+1, _ > 0);
    assert(i3 == 5);
}
Пример #11
0
void load_data(const char* datafile) {
	if(str_ends_with(datafile, "descriptors.txt")) load_all(datafile);
	else X.load(datafile);
	if(LIMIT_NDATA!=-1 && X.height > LIMIT_NDATA) X.height = LIMIT_NDATA;
	n = X.height;
	D = X.width;

	distribute_data();


	DBGV(LIMIT_NDATA);
	DBGV(N);
	DBGV(D);
	DBGV(n);
}
Пример #12
0
int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir, ipkg_conf_t *conf)
{
    dest->name = strdup(name);

    /* Guarantee that dest->root_dir ends with a '/' */
    if (str_ends_with(root_dir, "/")) {
	dest->root_dir = strdup(root_dir);
    } else {
	sprintf_alloc(&dest->root_dir, "%s/", root_dir);
    }
    file_mkdir_hier(dest->root_dir, 0755);

    if (!conf->ipkg_libdir) {
	    sprintf_alloc(&dest->ipkg_dir, "%s%s",
			  dest->root_dir, IPKG_STATE_DIR_PREFIX);
    }else{
	    sprintf_alloc(&dest->ipkg_dir, "%s%s",
			  dest->root_dir, conf->ipkg_libdir);
    }
    file_mkdir_hier(dest->ipkg_dir, 0755);

    if (str_starts_with (lists_dir, "/")) 
        sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
    else
        sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);

    file_mkdir_hier(dest->lists_dir, 0755);

    sprintf_alloc(&dest->info_dir, "%s/%s",
		  dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
    file_mkdir_hier(dest->info_dir, 0755);

    sprintf_alloc(&dest->status_file_name, "%s/%s",
		  dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);

    sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
		  dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);

    dest->status_file = NULL;

    return 0;
}
Пример #13
0
/*
  Runs through the y86 file, and assign an address to each label
  Also stores each source line in source_lines by calling
    add_source_line (this just happens to be the easiest place to do so)
*/
void parse_labels(FILE *str_in) {
	char line[4096];
	int len, cur_addr = 0;
	Label *cur_label = NULL;
	
	assert(str_in != NULL);
	
	while (read_y86_line(str_in, line, sizeof(line))) {
		if (cur_addr > 4096) {
			DBG_PRINT("cur_addr exceeds 4096\n");
			exit(0);
		}
		
		len = strlen(line);
   
		DBG_PRINT("Read in line: %s\n", line);
        
		if (len == 0)
			continue; /* blank line or line with only a comment, so skip */

		add_source_line(line, cur_addr);    
    
		if (str_ends_with(line, ':')) {
			// this is a label line
			line[len-1] = '\0';
			cur_label = malloc(sizeof(Label));
			strcpy(cur_label->name, line);
			cur_label->addr = cur_addr;

			DBG_PRINT("Got a label line %s at address %x\n", line, cur_addr);

			labels = realloc(labels, (num_labels + 1) * sizeof(Label));
			labels[num_labels++] = cur_label;
		} else {
			// this is not a label line, but we still need to keep counting the current address so we know where we are
			DBG_PRINT("cur instr size = %d, cur addr = %x\n", get_instr_size(line, cur_addr), cur_addr);
			cur_addr += get_instr_size(line, cur_addr); /* line now contains only the instruction */
		}
	}
}
Пример #14
0
static char *make_file_path(const char *path, const char *filename,
                            baton_error_t *error) {
    size_t dlen = strnlen(path, MAX_STR_LEN);
    size_t flen = strnlen(filename, MAX_STR_LEN);
    size_t len = dlen + flen + 1; // +1 for NUL

    int includes_slash = str_ends_with(path, "/", MAX_STR_LEN);
    if (!includes_slash) len++;

    if (len > MAX_STR_LEN) {
        set_baton_error(error, CAT_INVALID_ARGUMENT,
                        "The path components '%s' + '%s' "
                        "combined exceeded the maximum length of %d "
                        "characters", path, filename, MAX_STR_LEN);
        goto error;
    }

    char *fpath = NULL;
    fpath = calloc(len, sizeof (char));
    if (!fpath) {
        set_baton_error(error, errno,
                        "Failed to allocate memory: error %d %s",
                        errno, strerror(errno));
        goto error;
    }

    if (includes_slash) {
        snprintf(fpath, len, "%s%s", path, filename);
    }
    else {
        snprintf(fpath, len, "%s/%s", path, filename);
    }

    return fpath;

error:
    return NULL;
}
Пример #15
0
/*
 * Calculate open basedir directory from:
 * original_path: the path of the script requested
 * uri: the request URI
 * new_basedir: buffer to place the new basedir
 * uri_component: the URI component that must be part of the basedir
 */
static void calculate_basedir(const char *original_path, char *uri, const char *path_info, const char *uri_component, char *new_basedir)
{
    char realpath_buff[PATH_MAX];
    char *p, *c;
    /* duplicate since we're going to edit it */
	char *request_uri = estrdup(uri);

    strcpy(new_basedir, original_path);
    /* handle URLs like /index.php/foo/bar */
	if (path_info && path_info[0]) {
		p = str_ends_with(request_uri, path_info);
		/* request_info ends with path_info, cut it off since we don't need it for the path */
		if(p) {
			*p = '\0';
		}
	}
    
    /* normalize request_uri by removing // and /./ */
    for(p = c = request_uri; *p ;) {
        while(*p == '/' && p[1] == '/') {
            /* skip slash runs */
            p++;
        }
        if(p[0] == '/' && p[1] == '.' && p[2] == '/') {
            /* skip /./ */
            p += 2;
            continue;
        }
        if(p != c) {
            *c = *p;
        }
        p++; c++;
    }
    *c = '\0';
    
    /* Strip the URL from the DocumentRoot */
	char *localpath = str_ends_with(original_path, request_uri);
	if (localpath) {
		int new_basedir_len = localpath - original_path;
		int localpath_len = strlen(localpath);

		if (uri_component) {
    		int basedir_uri_component_len = strlen(uri_component);
			int i;
			/* 0 is the leading slash */
			for (i = 1; i < localpath_len; i++) {
				int j;
				for (j = 0; i+j < localpath_len; j++) {
					if (localpath[i+j] == '/') {
						break;
					}
				}
				if (j == basedir_uri_component_len && !strncmp(uri_component, &localpath[i], j)) {
					new_basedir_len += i+j;
					break;
				} else {
					i += j;
				}
			}
		}
		new_basedir[new_basedir_len] = '\0';
		realpath(new_basedir, realpath_buff);
        /* If realpath does not match, add it too. Smarty needs this */
		if (strcmp(new_basedir, realpath_buff)) {
			new_basedir[new_basedir_len] = ':';
			strcpy(&new_basedir[new_basedir_len+1],realpath_buff);
		}
	}
     
    efree(request_uri);
}
Пример #16
0
/**
 * tabix workhorse function
 */
static int tabix_handler(request_rec *r)
    {
    htsFile *fp=NULL;
    hts_itr_t *itr=NULL;
    kstring_t line = {0,0,0};
    int print_header=1;
    int print_body=1;
    struct tabix_callback_t handler;
    int http_status=OK;
	
	memset((void*)&handler,0,sizeof(struct tabix_callback_t));
    handler.r=r;
    handler.limit=DEFAULT_LIMIT_RECORDS;
	
    if (!r->handler || strcmp(r->handler, "tabix-handler")) return (DECLINED);
    if (strcmp(r->method, "GET")!=0) return DECLINED;
    if(r->canonical_filename==NULL)  return DECLINED;
     /* file must be b-gzipped */
    if( !(
    	str_ends_with(r->canonical_filename,".gz")
       	))  return DECLINED;
    /* file must be indexed with tabix */
    if( !(
    	fileExtExists(r->canonical_filename,".tbi")
       	))  return 404;
   
    
   
    handler.httParams = HttpParamParseGET(r); 
    if(handler.httParams==NULL) return DECLINED;
    handler.file_format=E_FORMAT_UNDEFINED;
    if(str_ends_with(r->canonical_filename,".vcf.gz"))
    	{
    	handler.file_format=E_FORMAT_VCF;
    	}
    else if(str_ends_with(r->canonical_filename,".bed.gz"))
    	{
    	handler.file_format=E_FORMAT_BED;
    	}
    
    /* only one loop, we use this to cleanup the code, instead of using a goto statement */
    do	{
    	const char* format=HttpParamGet(handler.httParams,"format");
    	const char* limit=HttpParamGet(handler.httParams,"limit");
    	const char* region=HttpParamGet(handler.httParams,"region");
    	int iterator_was_requested=FALSE;
    	
    	
    	if(limit!=NULL)
    		{
    		handler.limit=atol(limit);
    		}
    	
    	if(format==NULL)
    		{
    		http_status=DECLINED;
    		break;
    		}
    	else if(strcmp(format,"xml")==0)
    	 	{
    	 	SETUP_HANDLER(xml);
    	 	}

    	 else if(strcmp(format,"json")==0 || strcmp(format,"jsonp")==0)
    	 	{
    	 	handler.jsonp_callback=HttpParamGet(handler.httParams,"callback");
    	 	SETUP_HANDLER(json);
    	 	}
    	 else if(strcmp(format,"html")==0)
    	 	{
    	 	SETUP_HANDLER(html);
    	 	}
    	 else
    	 	{
    	 	SETUP_HANDLER(plain);
    	 	}
    	
    	fp=hts_open(r->canonical_filename,"r");
    	if(fp==NULL)
    		{
    		http_status=HTTP_NOT_FOUND;
    		break;
    		}
    	//read index
    	handler.tbx = tbx_index_load(r->canonical_filename);
    	if(handler.tbx==NULL)
			{
			http_status=HTTP_INTERNAL_SERVER_ERROR;
			break;
			}
    	if(region!=NULL && !str_is_empty(region))
    		{
    		iterator_was_requested=TRUE;
    		itr = tbx_itr_querys(handler.tbx,region);
    		}

	
    	handler.startdocument(&handler);
    	if(print_header)
    	    {
    	    handler.startheader(&handler);
    	    while ( hts_getline(fp, KS_SEP_LINE, &line) >= 0 )
    	            {
		    if ( !line.l || line.s[0]!=handler.tbx->conf.meta_char ) break;
		    handler.header(&handler,&line);
		    handler.count++;
    	            }
    	    handler.enddheader(&handler);
    	    }
    	handler.count=0;//Reset 
    	if(print_body)
    	    {
    	    handler.startbody(&handler);
		    if(iterator_was_requested)
				{
				if(itr!=NULL)
					{
					while ((handler.limit==-1 || handler.count< handler.limit) && tbx_itr_next(fp, handler.tbx, itr, &line) >= 0)
						{
						if(handler.show(&handler,&line)<0) break;
						handler.count++;
						}
					}
		
				}
		    else
				{
				while ((handler.limit==-1 || handler.count< handler.limit) && \
					hts_getline(fp, KS_SEP_LINE, &line) >= 0)
					{
					if(handler.show(&handler,&line)<0) break;
					handler.count++;
					}
				}
	   	 handler.endbody(&handler);
    	    }
	handler.enddocument(&handler);
    	} while(0);/* always abort */
    
    
    //cleanup
    if(itr!=NULL) tbx_itr_destroy(itr);
    HttpParamFree(handler.httParams);
    free(line.s);
    if(fp!=NULL) hts_close(fp);
    if(handler.tbx!=NULL) tbx_destroy(handler.tbx);
    return http_status;
    }
Пример #17
0
static int list_handler(request_rec *r)
    {
	struct listngs_callback_t handler;
    int http_status=OK;
    memset((void*)&handler,0,sizeof(struct listngs_callback_t));
    handler.r=r;
    
    
   // if (!r->handler || strcmp(r->handler, "listngs-handler")) return (DECLINED);
    
    
    if (strcmp(r->method, "GET")!=0) return DECLINED;
#ifdef ENABLE_LISTNGS
    if (strcmp(ENABLE_LISTNGS, "yes")!=0) return DECLINED;
#endif
    if(r->canonical_filename==NULL)  return DECLINED;
   

    
    	/* only one loop, we use this to cleanup the code, instead of using a goto statement */
	    do	{
	    	DIR *dir;
	    	char* slash=NULL;
   			
   			handler.httParams = HttpParamParseGET(r); 
    
		    
		    if(str_ends_with(r->canonical_filename,"/" INDEX_NGS_NAME ".json"))
		    	{
		    	handler.jsonp_callback=HttpParamGet(handler.httParams,"callback");
		    	SETUP_HANDLER(json);
		    	}
		    else if(str_ends_with(r->canonical_filename,"/" INDEX_NGS_NAME ".xml"))
		    	{
		    	SETUP_HANDLER(xml);	
		    	}
		    else
		    	{
		    	http_status=DECLINED;
		    	break;
		    	}
		   			
   			
   			
	    	/* get last file separator */
			slash=strrchr(r->canonical_filename,'/');
		    if(slash==NULL)
		    	{
		    	http_status=HTTP_INTERNAL_SERVER_ERROR;
		    	break;
		    	}
	    	handler.basedir=strndup(r->canonical_filename,slash-r->canonical_filename);
	    	if(handler.basedir==NULL)
		    	{
		    	http_status=HTTP_INTERNAL_SERVER_ERROR;
		    	break;
		    	}
	    	if ((dir = opendir(handler.basedir))==NULL)
       			{
       			http_status=HTTP_INTERNAL_SERVER_ERROR;
		    	break;
       			}
       		handler.directory(&handler,dir);
			closedir(dir);
    	} while(0);/* always abort */
    
    
    //cleanup
    HttpParamFree(handler.httParams);
    free(handler.basedir);
    return http_status;
    }
Пример #18
0
static int is_unseen_course(struct dir_item *item)
{
    return (str_starts_with(base_name(item->path), "holes-") &&
            str_ends_with(item->path, ".txt") &&
            !course_is_loaded(item->path));
}
Пример #19
0
static int is_archive(struct dir_item *item)
{
    return (str_ends_with(item->path, ".zip") ||
            str_ends_with(item->path, ".pk3"));
}
Пример #20
0
/*
  Takes as input a line, read by read_y86_line, and calls the necessary codegen function
   in assembler.c to build the program memory
   
  Returns 1 on success, 0 on error
*/
int parse_line(char *line) {
	char *space, *cmd, *rest, *args[8], *line_copy;
	int i, num_args = 0, succ = 1;
  
	assert(line != NULL);
  
	DBG_PRINT("Line: %s\n", line);
	
	line_copy = strdup(line);
	
	if (line_copy == NULL)
		return 0;
	
	if (!str_ends_with(line, ':')) {
		// this is not a label line
		space = strchr(line_copy, ' ');
		
		for (i = 0; i < 8; i++)
			args[i] = NULL;
		
		if (space != NULL) {
			*space = '\0'; // separate instruction from parameters  
			cmd = line_copy;
			rest = cmd + strlen(cmd) + 1;
			
			num_args = 1;
			args[0] = strtok(rest, ",");
			args[1] = strtok(NULL, ",");
			
			if (args[1] != NULL)
				num_args++;
		} else {
			cmd = line_copy;
		}

		DBG_PRINT("Instruction: %s, num_args=%d\n", cmd, num_args);
		
		if (strcmp(cmd, "irmovl") == 0) {
			succ = (num_args != 2) ? 0 : irmovl_codegen(cmd, args);
		}
		
		// rmmovl %eax, (%ebx) is equiv. to rmmovl %eax, 0(%ebx)
		else if (strcmp(cmd, "rmmovl") == 0 || strcmp(cmd, "mrmovl") == 0) {
			succ = (num_args != 2) ? 0 : reg_mem_codegen(cmd, args);
		}
		
		else if (strcmp(cmd, "rdint") == 0 || strcmp(cmd, "rdch") == 0 || strcmp(cmd, "wrch") == 0 || strcmp(cmd, "wrint") == 0 ||
				 strcmp(cmd, "pushl") == 0 || strcmp(cmd, "popl") == 0) {
			succ = (num_args != 1) ? 0 : reg_num_codegen(cmd, args);
		}
		
		else if (strcmp(cmd, "addl") == 0 || strcmp(cmd, "subl") == 0 || strcmp(cmd, "xorl") == 0 || strcmp(cmd, "andl") == 0 ||
				 strcmp(cmd, "multl") == 0 || strcmp(cmd, "divl") == 0 || strcmp(cmd, "modl") == 0 || strcmp(cmd, "rrmovl") == 0) {
			succ = (num_args != 2) ? 0 : reg_nums_mask_codegen(cmd, args);
		}
		
		else if (strcmp(cmd, "halt") == 0 || strcmp(cmd, "ret") == 0 || strcmp(cmd, "nop") == 0) {
			succ = (num_args != 0) ? 0 : no_operands_codegen(cmd, args); 
		}
		
		else if (strcmp(cmd, "je") == 0 || strcmp(cmd, "jle") == 0 || strcmp(cmd, "jmp") == 0 || strcmp(cmd, "jg") == 0 ||
				 strcmp(cmd, "jl") == 0 || strcmp(cmd, "jne") == 0 || strcmp(cmd, "jge") == 0 || strcmp(cmd, "call") == 0) {
		    succ = (num_args != 1) ? 0 : label_addr_codegen(cmd, args);
		}
		
		else if (strcmp(cmd, ".long") == 0) {
			succ = (num_args != 1) ? 0 : long_codegen(cmd, args);
		}
  
		else if (strcmp(cmd, ".pos") == 0) {
			succ = (num_args != 1) ? 0 : pos_codegen(cmd, args);
		}
		
		else if (strcmp(cmd, ".align") == 0) {
		    succ = (num_args != 1) ? 0 : align_codegen(cmd, args);
		}
	}
	
	if (!succ) {
		write_to_dbg("parser: Error processing %s", line);
		get_key_and_exit();
	}
	
	free(line_copy);
	return 1;
}
Пример #21
0
static int is_replay(struct dir_item *item)
{
    return str_ends_with(item->path, ".nbr");
}
Пример #22
0
static int is_unseen_set(struct dir_item *item)
{
    return (str_starts_with(base_name(item->path), "set-") &&
            str_ends_with(item->path, ".txt") &&
            !set_is_loaded(item->path));
}
Пример #23
0
LRESULT CDlgTimingScoring::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static int tmStartRace, tmEndRace;	//	Variables for setting up receive time / live car position
	HL_hWnd = GetDlgItem(hWnd,IDC_TIMINGSCORING);	//	Hot Laps listview
	TS_hWnd = GetDlgItem(hWnd,IDC_RACESCORING);	//	Race Timing listview
	switch(uMsg)
  {
    case WM_INITDIALOG:
    {
		//	Initialize the results array
		for (int i=0;i<50;i++)
		{
			swprintf(m_ScoringData[i].db_strRaceName, NUMCHARS(m_ScoringData[i].db_strRaceName),L"");
			swprintf(m_ScoringData[i].db_szTotTime, NUMCHARS(m_ScoringData[i].db_szTotTime),L"");
		}
//		tmStartRace = NULL;
//		tmEndRace = NULL;	//	Set the initial End Race time to NULL
		//	Set up the Hot Lap timing list box
		vector<wstring> lstCols;
		vector<int> lstWidths;
		lstCols.push_back(L"Pos");
		lstCols.push_back(L"Name");
		lstCols.push_back(L"Comment");
		lstCols.push_back(L"Laptime");
		lstWidths.push_back(40);
		lstWidths.push_back(210);
		lstWidths.push_back(85);
		lstWidths.push_back(85);
//		HL_hWnd = GetDlgItem(hWnd,IDC_TIMINGSCORING);	//	Hot Laps listview
		sfListBox.Init(HL_hWnd,lstCols,lstWidths);


		//	Now set up the Scoring list box
		vector<wstring> scoringLstCols;
		vector<int> scoringLstWidths;
		scoringLstCols.push_back(L"Pos");
		scoringLstCols.push_back(L"Name");
		scoringLstCols.push_back(L"Lap/Time Ahead");
		scoringLstWidths.push_back(30);
		scoringLstWidths.push_back(145);
		scoringLstWidths.push_back(95);
		sfListBox.Init(TS_hWnd,scoringLstCols,scoringLstWidths);
		HWND hWnd_Comment = GetDlgItem(hWnd, IDC_RACE_COMMENT);
		SetDlgItemText(hWnd, IDC_RACE_COMMENT, szTitle);

		TimingScoringProc((LPVOID)&m_szPath, hWnd);
		break;
    }
	case WM_NOTIFY:
	{
		// check for column click notification and sort the list view accordingly
		if ( ( ((LPNMHDR)lParam)->idFrom == IDC_RACESCORING) && ( ((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) )
		{
//			TS_hWnd = GetDlgItem(hWnd,IDC_RACESCORING);
			OnColumnClick((LPNMLISTVIEW)lParam, TS_hWnd );
		}
		else if ( ( ((LPNMHDR)lParam)->idFrom == IDC_TIMINGSCORING) && ( ((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) )
		{
//			HL_hWnd = GetDlgItem(hWnd,IDC_TIMINGSCORING);
			OnColumnClick((LPNMLISTVIEW)lParam, HL_hWnd );
		}
		return TRUE;
	}
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
        case IDRESCAN:
        {
			TimingScoringProc((LPVOID)&m_szPath, hWnd);
			if (tmStartRace)
			{
				CRaceScoring((LPVOID) &m_szPath, hWnd, tmStartRace, tmEndRace);
			}
            m_pResults->fCancelled = false;
			return TRUE;
        }
        case IDCANCEL:
		{
          m_pResults->fCancelled = true;
		  for (int i=0;i<50;i++)
		  {
				m_sfResult->m_RaceId[i] = -1;
		  }
          EndDialog(hWnd,0);
          return TRUE;
		}
        case IDSTARTRACE:
		{
			TCHAR szText[MAX_PATH] = {NULL};			
			TCHAR szTemp[MAX_PATH] = {NULL};			
			if (tmEndRace == NULL && tmStartRace != NULL)
			{
				MessageBox(hWnd, L"Race already in progress!\n\nYou must end that race before starting a new one", L"***ERROR***", MB_OK);
			}
			else
			{
				if (tmStartRace > 0)	//	There is already a time marker stored, verify user wants to change this
				{
					DWORD dRet = MessageBox(hWnd, L"You already have a race stored!\n\nAre you sure you want to start a new race?\n\nPrevious race results will be lost if you haven't saved them", L"WARNING", MB_YESNO);
					if(dRet == IDNO)
					{
						//	Do nothing
						m_pResults->fCancelled = true;
						return TRUE;
					}
				}
				tmEndRace = NULL;	//	Remove any end of race marker when new race begins. INT format
				tmStartRace = GetSecondsSince1970();		//	Set the start time for this race session. Unixtime in INT format
//				tmStartRace = 1376100527;	// Used for the TestRaces database only
//				swprintf(szText, NUMCHARS(szText), L"Race Started\n\nTime = %i", tmStartRace);
//				MessageBox(hWnd, szText, L"Started", MB_OK);
				MessageBox(hWnd, L"Race started", L"Started", MB_OK);

				HWND prog_hWnd = GetDlgItem(hWnd, IDC_RACE_PROGRESS);
				swprintf(szText, NUMCHARS(szText), L"<<<< Race In Progress >>>>");
				SendMessage(prog_hWnd, WM_SETTEXT, 0, (LPARAM)szText);
			}
			m_pResults->fCancelled = false;
			return TRUE;
		}
		case IDENDRACE:
		{
			if (tmStartRace != NULL)
			{
				TCHAR szText[MAX_PATH] = {NULL};			
				TCHAR szTemp[MAX_PATH] = {NULL};			
				if (tmEndRace > 0)	//	There is already a time marker stored, verify user wants to change this
				{
					DWORD dRet = MessageBox(hWnd, L"You already have a race stored!\n\nAre you sure you want to change the end time for this race?\n\nPrevious race results will be lost if you haven't saved them", L"WARNING", MB_YESNO);
					if(dRet == IDNO)
					{
						//	Do nothing
						m_pResults->fCancelled = true;
						return TRUE;
					}
				}

				tmEndRace = GetSecondsSince1970();		//	Set the end time for this race session. Unixtime in INT format
//				tmEndRace = 1376100699;	// Used for the TestRaces database only
//				swprintf(szText, NUMCHARS(szText), L"Race End = %i", tmEndRace);
//				MessageBox(hWnd, szText, L"Ended", MB_OK);

				HWND prog_hWnd = GetDlgItem(hWnd, IDC_RACE_PROGRESS);
				swprintf(szText, NUMCHARS(szText), L">>>> Race Ended <<<<");
				SendMessage(prog_hWnd, WM_SETTEXT, 0, (LPARAM)szText);

				::FormatTimeMinutesSecondsMs((tmEndRace - tmStartRace), szText, NUMCHARS(szText) );
				TimingScoringProc((LPVOID)&m_szPath, hWnd);	//	Refresh the results one last time
				if (tmStartRace)
				{
					CRaceScoring((LPVOID) &m_szPath, hWnd, tmStartRace, tmEndRace);
				}

				swprintf(szTemp, NUMCHARS(szTemp), szText);
				_snwprintf(szText, NUMCHARS(szText), L"Race has ended\n\nRace duration: %s", szTemp);
				MessageBox(hWnd, szText, L"Ended", MB_OK);
			}
			else
			{
				MessageBox(hWnd, L"Race scoring has not been started", L"***ERROR***", MB_OK);
			}
			m_pResults->fCancelled = false;
			return TRUE;
		}
		case IDC_RACE_RERUN:
        {
			//	Let's set up for displaying the T&S page
			int m_RaceId[50] = {NULL};
			// Show the race-selection dialog and let the User pick which ones to use on T&S page
			RACERERUN_RESULT sfResult;
			if (sfResult.iStart <= 0 || tmStartRace > 0) sfResult.iStart = tmStartRace;
			if (sfResult.iEnd <= 0 || tmEndRace > 0) sfResult.iEnd = tmEndRace;

			CRaceRerunDlg dlgRace(&sfResult);
			ArtShowDialog<IDD_RACE_RERUN>(&dlgRace);

			if(!sfResult.fCancelled)
			{
				// Get the Start and End race markers and store them for race scoring
				tmStartRace = sfResult.iStart;
				tmEndRace = sfResult.iEnd;
				TimingScoringProc((LPVOID)&m_szPath, hWnd);	//	Refresh the results one last time
				if (tmStartRace)
				{
					CRaceScoring((LPVOID) &m_szPath, hWnd, tmStartRace, tmEndRace);
				}
			}
			return TRUE;
		}
        case IDC_RACE_SAVE:
		{
			if (tmEndRace == NULL && tmStartRace != NULL)
			{
				MessageBox(hWnd, L"Race in progress!\n\nYou must end the race before saving your results", L"***ERROR***", MB_OK);
			}
			else if (tmEndRace == NULL && tmStartRace == NULL)
			{
				MessageBox(hWnd, L"No race data to save", L"***ERROR***", MB_OK);
			}
			else
			{
				TCHAR szText[MAX_PATH] = {NULL};			
				TCHAR szTemp[MAX_PATH] = {NULL};			
				//	Save the results into a text file
				if(tmEndRace > 0)
				{
//				  swprintf(szText, NUMCHARS(szText), L"Race Start = %i\n\nRace End = %i", tmStartRace, tmEndRace);
//				  MessageBox(hWnd, szText, L"Saving", MB_OK);
				  TCHAR szFilename[MAX_PATH] = {NULL};
				  wcscat(szFilename,L"TimingScoring.txt");
				  while (true)
				  {
					if(ArtGetSaveFileName(hWnd, L"Choose Output file", szFilename, NUMCHARS(szFilename),L"TXT Files (*.txt)\0*.TXT\0\0"))
					{
						// let's make sure there's a .txt suffix on that bugger.
						if(!str_ends_with(szFilename,L".txt") && !str_ends_with(szFilename,L".TXT") )
						{
							wcsncat(szFilename,L".txt", NUMCHARS(szFilename));
						}
						const bool fFileIsNew = !DoesFileExist(szFilename);
						if(fFileIsNew)
						{
							break;	//	Exit loop, as file name is valid and new
						}
						else
						{
							DWORD dwRet = MessageBox(NULL,L"A file already exists with that name.\n\nAre you sure you want to overwrite it?",L"WARNING", MB_APPLMODAL | MB_ICONWARNING | MB_YESNO | MB_TOPMOST | MB_DEFBUTTON2);
							if (dwRet == IDYES)
							{
								break;	//	User wants to overwrite file, so exit loop and proceed
							}
						}
					}
					else
					{
						return 0;	//	User cancelled the save operation, so leave subroutine
					}
				  }

					//	Open up the file and write the information to it
					wofstream out;
					out.open(szFilename);

					//	First the race title information
					HWND hWnd_Comment = GetDlgItem(hWnd, IDC_RACE_COMMENT);
					int len;
					len = GetWindowTextLength(hWnd_Comment);
					GetDlgItemText(hWnd, IDC_RACE_COMMENT, szTitle, len+1);
					out<<szTitle<<endl<<endl;

					out<<L"File Name: "<<m_szPath<<endl;
					//	Let's save the start/end markers so the race can be recreated if needed
					_snwprintf(szText, NUMCHARS(szText), L"Race start marker:\t%i", tmStartRace);
					out<<szText<<endl;
					_snwprintf(szText, NUMCHARS(szText), L"Race ending marker:\t%i", tmEndRace);
					out<<szText<<endl;
					//	Now the race duration
					::FormatTimeMinutesSecondsMs((tmEndRace - tmStartRace), szText, NUMCHARS(szText) );
	//				swprintf(szText, _tcslen(szText) - 2, L"%s", szText);	//	Remove the fractional time
					swprintf(szTemp, NUMCHARS(szTemp), szText);
					_snwprintf(szText, NUMCHARS(szText), L"Race duration:\t%s", szTemp);

					out<<szText<<endl<<endl;
					out<<L"ID\tName\t\t\t\t\tLap/Time Ahead"<<endl;
					out<<L"====================================================================="<<endl;

					for(int i = 0; i < 25; i++)
					{
						if (m_ScoringData[i].db_iRaceId <= 0 || m_ScoringData[i].db_iUnixFirstTime == 0) break;
						int Temp = m_ScoringData[i].db_iUnixFirstTime + m_ScoringData[i].db_iUnixLastTime;
						::FormatTimeMinutesSecondsMs(Temp, szTemp, NUMCHARS(szTemp) );
						out << m_ScoringData[i].db_iRaceId << L"\t";
						out << m_ScoringData[i].db_strRaceName << L"\t";
						out << m_ScoringData[i].db_szTotTime << endl;
					}
					out<<endl;

					//	Now let's push out all of the Top 40 Hot Laps to the file

					out<<endl<<endl;
					out<<L"\t\tTop 40 Hot Laps"<<endl;
					out<<L"Pos\tName\t\t\t\t\tComment\tLap Time"<<endl;
					out<<L"====================================================================="<<endl;
					for(int i = 0; i < 40; i++)
					{
						if (_wtoi(m_ScoringData[i].lstPos) <= 0) break;
						out << m_ScoringData[i].lstPos << L"\t";
						out << m_ScoringData[i].lstRaceName << L"\t";
						out << m_ScoringData[i].lstComment << L"\t\t";
						out << m_ScoringData[i].lstLapTimes << endl;
					}
					out<<endl;

					out.close();	//	Close the file
					MessageBox(hWnd, L"Race Results Saved", L"Saved", MB_OK);
	
					m_pResults->fCancelled = false;
					return TRUE;
				}
				else
				{
					swprintf(szText, NUMCHARS(szText), L"Race Start = %i\n\nRace End = %i", tmStartRace, tmEndRace);
					MessageBox(hWnd, szText, MB_OK, NULL);
				}
			}
		}
      }
      break;
    } // end WM_COMMAND
    case WM_CLOSE:
    {
      m_pResults->fCancelled = true;
      for (int i=0;i<50;i++)
	  {
			m_sfResult->m_RaceId[i] = -1;
	  }
	  EndDialog(hWnd,0);
      break;
    }
  }
  return FALSE;
}