示例#1
0
struct pkglist *lsports()
{
	FILE *file;
	struct pkglist *p = NULL;

	file = fopen(CACHE, "r");
	if (file == NULL)
		return (NULL);

	size_t n = 0;
	char *line = NULL;
	int nread = getline(&line, &n, file);

	if (nread < 0) {
		if (build_cache(ilenia_repos) != EXIT_SUCCESS)
			return (NULL);
		nread = getline(&line, &n, file);
	}

	while (nread > 0) {
		//int i, num = count(line, ' ');
		struct list *splitted_line;
		char *name, *version, *repo;
		struct deplist *d = NULL;

		splitted_line = split(line, " ");
		name = splitted_line->data;
		splitted_line = splitted_line->next;
		version = splitted_line->data;
		splitted_line = splitted_line->next;
		repo = splitted_line->data;
		splitted_line = splitted_line->next;

		while (splitted_line != NULL) {
			trim(splitted_line->data);
			d = deplist_add(splitted_line->data, d);
			splitted_line = splitted_line->next;
		}

		trim(name);
		trim(version);
		trim(repo);

		p = pkglist_add_ordered(name, version, repo, d, p);
		free(name);
		free(version);
		free(repo);
		nread = getline(&line, &n, file);
	}

	fclose(file);
	return (p);
}
示例#2
0
void simulate(FILE* fp, int setIndex, int lines, int blockBits) {
    //simulate cache memory
    struct cache_line** cache = build_cache(setIndex, lines);
    char blank;
    char Op;
    int addressVal;
    int offset;

    char buf[1000];
    int hit = 0, miss = 0, eviction = 0;
    int setNumber;
    int tag;
    int tempHit, tempMiss, tempEvict;
    while (fgets(buf, sizeof(buf), fp) != NULL) {
        tempHit = tempMiss = tempEvict = 0;
        sscanf(buf, "%c %c %x,%d",&blank, &Op, &addressVal, &offset);
        if (blank == 'I')
            continue;

        setNumber = getSetIndex(addressVal, setIndex, blockBits);
        tag = addressVal >> (setIndex + blockBits);

        if (findCache(cache, setNumber, lines, tag)) {
            hit ++;
            tempHit ++;
            updateCache(setNumber, tag);
        } else {
            miss ++;
            tempMiss ++;
            tempEvict += replaceCache(cache, setNumber, lines, tag);
        }
        if (Op == 'M') {
            //if the operation is M, need to find cache again
            if (findCache(cache, setNumber, lines, tag)) {
                hit ++;
                tempHit ++;
                updateCache(setNumber, tag);
            } else {
                miss ++;
                tempMiss ++;
                tempEvict += replaceCache(cache, setNumber, lines, tag);
            }
        }
        eviction += tempEvict;
        if (verbose)
            printVerboseInfo(buf, tempHit, tempMiss, tempEvict);
    }
    //printf("%d %d %d\n", hit, miss, eviction);
    freeCache(cache);
    freeQueue();
    printSummary(hit, miss, eviction);
}
示例#3
0
static void
test_go_data_cache_build_cache(void)
{
	
	GODataCache *cache;
	const char *test_name = "test_go_data_cache_build_cache";
	
	mark_test_start (test_name);
	
	cache = build_cache();
	go_data_cache_dump(cache, NULL, NULL);

	mark_test_end (test_name);
	
	//~ if (sstest_slicer_file) {
		//~ GOFileOpener *fo = NULL;
		//~ char *infile = sstest_slicer_file; //go_shell_arg_to_uri (sstest_slicer_file);
		//~ int res = 0, row = 0, col = 0, numRows = 10, numCols = 2;
		
		//~ GOIOContext *io_context = go_io_context_new (cc);
		//~ WorkbookView *wbv;
		
		//~ const char *test_name = "test_go_data_cache_build_cache";
	
		//~ mark_test_start (test_name);
		
		//~ wbv = wb_view_new_from_uri (infile, fo,
					    //~ io_context,
					    //~ NULL);

		//~ if (wbv == NULL || go_io_error_occurred (io_context)) {
			//~ go_io_error_display (io_context);
			//~ res = 1;
		//~ } else {
			//Workbook *wb = wb_view_get_workbook (wbv);
			//~ Sheet *sheet = wb_view_cur_sheet (wbv);
			
			//~ for (row = 0; row < numRows; row++) {
				//~ for (col = 0; col < numCols; col++) {
					//~ GnmCell * tempCell = sheet_cell_get(sheet, col, row);
					//~ GnmValue * tempVal = tempCell->value;
					//~ value_dump(tempVal);
				//~ }
			//~ }

			//~ res = handle_export_options (fs, GO_DOC (wb));
			//~ if (res) {
				//~ g_object_unref (wb);
				//~ goto out;
			//~ }
			
			//~ GSList *ptr;
			//~ GString *s;
			//~ char *tmpfile;
			//~ int idx = 0;
			//~ res = 0;
			
			//~ for (ptr = workbook_sheets(wb); ptr && !res; ptr = ptr->next, idx++) {
				//~ wb_view_sheet_focus(wbv, (Sheet *)ptr->data);
				//~ s = g_string_new (outfile);
				//~ g_string_append_printf(s, ".%d", idx);
				//~ tmpfile = g_string_free (s, FALSE);
				//~ res = !wb_view_save_as (wbv, fs, tmpfile, cc);
				//~ g_free(tmpfile);
			//~ }
			//~ g_object_unref (wb);
		//~ }
		//~ g_object_unref (io_context);
		
		//~ g_object_unref (wb);
	
		//~ mark_test_end (test_name);
	//~ }
	
}