Пример #1
0
bool
atf_check::run_status_check(const atf::check::check_result &r)
    const
{
    int status = r.status();
    bool retval = true;

    if (m_status_check == sc_equal) {
        if (m_status_arg != status) {
            std::cerr << "Fail: incorrect exit status: "
                      << status << ", expected: "
                      << m_status_arg << std::endl;
            retval = false;
        }
    } else if (m_status_check == sc_not_equal) {
        if (m_status_arg == status) {
            std::cerr << "Fail: incorrect exit status: "
                      << status << ", expected: "
                      << "anything other" << std::endl;
            retval = false;
        }
    }

    if (retval == false) {
        std::cerr << "stdout:" << std::endl;
        print_file(r.stdout_path());
        std::cerr << std::endl;

        std::cerr << "stderr:" << std::endl;
        print_file(r.stderr_path());
        std::cerr << std::endl;
    }

    return retval;
}
Пример #2
0
void
unit_test_jit_fragment_tree()
{
    uint i;
    bb_node_t *node_list[FRAGMENT_TREE_TEST_NODE_COUNT]; /* N.B.: may contain NULLs */

    print_file(STDERR, "test DGC fragment tree: ");

    dynamo_options.opt_jit = true;

    fragment_tree = fragment_tree_create();
    set_random_seed((uint) query_time_millis());

    for (i = 0; i < 3; i++) {
        print_file(STDERR, "pass %d... ", i+1);

        unit_test_insert_random_nodes(node_list, FRAGMENT_TREE_TEST_NODE_COUNT);
        unit_test_remove_random_spans(node_list, FRAGMENT_TREE_TEST_NODE_COUNT);
        fragment_tree_clear(fragment_tree);
        unit_test_churn_narrow_span(node_list, FRAGMENT_TREE_TEST_NODE_COUNT);
        fragment_tree_clear(fragment_tree);
    }

    fragment_tree_destroy(fragment_tree);

    print_file(STDERR, "\n");
}
Пример #3
0
void
unit_test_string(void)
{
    static const char test_path[] = "/path/to/file";
    const char *ret;
    char buf[MAXIMUM_PATH];
    unsigned long num;

    print_file(STDERR, "testing string\n");

    /* strchr */
    ret = strchr(identity(test_path), '/');
    EXPECT(ret == test_path, true);
    ret = strchr(identity(test_path), '\0');
    EXPECT(ret != NULL, true);
    EXPECT(*ret, '\0');

    /* strrchr */
    ret = strrchr(identity(test_path), '/');
    EXPECT(strcmp(ret, "/file"), 0);
    ret = strrchr(identity(test_path), '\0');
    EXPECT(ret != NULL, true);
    EXPECT(*ret, '\0');

    /* strncpy, strncat */
    strncpy(buf, test_path, sizeof(buf));
    EXPECT(is_region_memset_to_char((byte *) buf + strlen(test_path),
                                    sizeof(buf) - strlen(test_path), '\0'),
           true);
    strncat(buf, "/foo_wont_copy", 4);
    EXPECT(strcmp(buf, "/path/to/file/foo"), 0);

    /* strtoul */
    num = strtoul(identity("-10"), NULL, 0);
    EXPECT((long)num, -10);  /* negative */
    num = strtoul(identity("0777"), NULL, 0);
    EXPECT(num, 0777);  /* octal */
    num = strtoul(identity("0xdeadBEEF"), NULL, 0);
    EXPECT(num, 0xdeadbeef);  /* hex */
    num = strtoul(identity("deadBEEF next"), (char **) &ret, 16);
    EXPECT(num, 0xdeadbeef);  /* non-0x prefixed hex */
    EXPECT(strcmp(ret, " next"), 0);  /* end */
    num = strtoul(identity("1001a"), NULL, 2);
    EXPECT(num, 9);  /* binary */
    num = strtoul(identity("1aZ"), NULL, 36);
    EXPECT(num, 1 * 36 * 36 + 10 * 36 + 35);  /* weird base */
    num = strtoul(identity("1aZ"), (char **) &ret, 37);
    EXPECT(num, ULONG_MAX);  /* invalid base */
    EXPECT(ret == NULL, true);

    /* memmove */
    strncpy(buf, test_path, sizeof(buf));
    memmove(buf + 4, buf, strlen(buf) + 1);
    strncpy(buf, "/foo", 4);
    EXPECT(strcmp(buf, "/foo/path/to/file"), 0);

    print_file(STDERR, "done testing string\n");
}
Пример #4
0
int
cgiMain()
{ 
	cgiHeaderContentType("text/html");
	
	int serverside = 0;
	cgiFormInteger("serverside", &serverside, 0);
	
	char function_call[50];
	int callback = 0;
	if (cgiFormString("function_call", &function_call[0], 50) == cgiFormSuccess)
		callback = 1;
	
	if(serverside) {
		/* Initialise the SEE library */
		SEE_init();
		
		/* Initialise an interpreter */
		SEE_interpreter_init(&g_interp_storage);
		g_interp = &g_interp_storage;
	
		/* Bring our native functions into the interpreter */
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "println", g_println, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "include", g_include, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "version", g_version, 1, 0);
		
		/* evaluate bootstrapping code, and then script, then transform events */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/serverside.js");
		evaluate_file(g_interp, &g_result, cgiPathTranslated);
		
		/* this is dangerous lol.  should check to make sure the callback is a function */
		if(callback)
			evaluate_string(g_interp, &g_result, function_call);
		
		/* this converts elements with onclick event attributes into links */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/transform.js");
		evaluate_string(g_interp, &g_result, "document.render();");
		
	} else {
		
		fprintf(cgiOut, "<html>\n<head>\n");
		fprintf(cgiOut, "<script type = \"text/javascript\">\n");
		fprintf(cgiOut, "function boot() {\n");
		print_file("/Users/alan/working/golf/boot/clientside.js");
		print_file(cgiPathTranslated);
		fprintf(cgiOut, "\n}\n");
		fprintf(cgiOut, "</script>\n</head>\n");
		fprintf(cgiOut, "<body onload = \"boot();\">\n");
		fprintf(cgiOut, "</body>\n</html>");
		
	}
	
	return EXIT_SUCCESS;
}
Пример #5
0
void
dump_thread_kstats(dcontext_t *dcontext)
{
    if (dcontext->thread_kstats == NULL)
        return;

    /* add thread id's in case outfile is rerouted to process_kstats_outfile */
    print_file(dcontext->thread_kstats->outfile_kstats, "Thread %d KSTATS {\n",
               dcontext->thread_kstats->thread_id);
    kstat_report(dcontext->thread_kstats->outfile_kstats,
                 &dcontext->thread_kstats->vars_kstats);
    print_file(dcontext->thread_kstats->outfile_kstats, "} KSTATS\n");
}
Пример #6
0
/** 도움말을 출력합니다
 *
 * 인자로 받은 도움말 종류중 하나를 출력합니다
 *
 * @param int help 출력할 도움말 `HELP_ALL` , `HELP_START`, `HELP_DONE` ,
 *                 `HELP_LIST` , `HELP_REPORT` 중 하나
 */
void print_help(int help) {
  switch(help) {
    case HELP_ALL:
      print_file("./docs/help.md");
      break;
    case HELP_START:
      print_file("./docs/help_start.md");
      break;
    case HELP_DONE:
      print_file("./docs/help_done.md");
      break;
    default:
      printf("unrecognize option for HELP");
  }
}
Пример #7
0
static int list(const char *filename, int arglen, char *args[]) {
	xar_t x;
	xar_iter_t i;
	xar_file_t f;

	x = xar_open(filename, READ);
	if( !x ) {
		fprintf(stderr, "Error opening xar archive: %s\n", filename);
		exit(1);
	}

	i = xar_iter_new();
	if( !i ) {
		fprintf(stderr, "Error creating xar iterator\n");
		exit(1);
	}

	for(f = xar_file_first(x, i); f; f = xar_file_next(i)) {
		print_file(f);
	}

	xar_iter_free(i);
	xar_close(x);

	return Err;
}
Пример #8
0
/**
 * Prints a graphical view of the directory structure.
 */
int main(int argc, char *argv[]) {

  // directory to list
  char *dir_name;
  // directory listing
  struct dirent **dir_list;
  // file count and loop variable
  int count, i;


  // check if we provided an arguement
  if( argc < 2 ) {
    // use the current dir
    dir_name = ".";
  } else {
    // use the provided dir
    dir_name = argv[1];
  }

  // read directory listing into array
  count = scandir(dir_name, &dir_list, file_select, alphasort);

  // loop through each file
  for (i=1; i<count+1; ++i)
    print_file(dir_list[i-1]);

  // exit cleanly
  return 0;

}
Пример #9
0
int
main(int argc, char **argv, char **envp)
{
    dcontext_t *dc = standalone_init();

    /* Each test will abort if it fails, so we just call each in turn and return
     * 0 for success.  If we want to be able to call each test independently, it
     * might be worth looking into gtest, which already does this.
     */
    unit_test_io();
#ifdef UNIX
    unit_test_string();
    unit_test_os();
#endif
    unit_test_utils();
    unit_test_options();
    unit_test_vmareas();
#ifdef WINDOWS
    unit_test_drwinapi();
#endif
    unit_test_asm(dc);
    unit_test_atomic_ops();
    unit_test_jit_fragment_tree();
    print_file(STDERR, "all done\n");
    return 0;
}
Пример #10
0
int main(int ac, char **av) {
  /* Function opens, sends to print, and closes file to be printed */
  int fd;

  if (ac != 2) /* Confirm there are two arguments */
    return 1;

  fd = open(av[1], O_RDONLY); /* Opens the file */
  if (fd == -1) {
    perror("open");
    return 1;
  }

  if (print_file(fd) == 1){ /* Prints the file */
    perror("read");
    return 1;
  }

  if (close(fd) == -1) { /* Close the file */
    perror("close");
    return 1;
  }

  return 0;
}
Пример #11
0
/* funcao responsavel pela montagem do arquivo. Une  todos processos. */
void mount(char* fileFrom, char* fileTo) {
    set_table s_table;
    label_table l_table = build_labels(fileFrom, &s_table);

    print_file(fileFrom, fileTo, l_table, s_table);
    free_tables(s_table, l_table);
}
Пример #12
0
int main()
{

	printf("Hello world! \n");
	int i=0;
	char *liste;
	int16_t taille_liste=0;
	int16_t nb_block= 500;
	sfs = createSfs("sfstest", nb_block);
	printf("dans createSfs la signature est %s \n", sfs.sb.signature);
	printf("taille de sfs en block %d \n", sfs.sb.nbBlockTotal);
	sfsadd(&sfs, "fichier.txt");
	sfsadd(&sfs, "fichier2.txt");


	liste=sfslist(&sfs,&taille_liste);
	printf("Dans main liste est \n");
	for(i=0; i<taille_liste; i++)
		printf("%c", liste[i]);
	printf("\n");;

	printf("sfs.name[0] %s \n", sfs.fe[0].name);
	printf("sfs.name[1] %s \n", sfs.fe[1].name);
	printf("sfs.name[2] %s \n", sfs.fe[2].name);
	print_file(sfs.fc.data[2]);
	createImage();
	return 0;
}
Пример #13
0
void		print_dir(t_files *head, char *dir_name, t_ls_args *args)
{
	int		links_column;
	int		size_column;

	links_column = get_length_column(head, 1);
	size_column = get_length_column(head, 2);
	ft_putstr(dir_name);
	ft_putendl(":");
	if (ft_strchr(args->options, 'l') && head)
	{
		ft_putstr("total ");
		ft_putnbr(get_total_size(head));
		ft_putchar('\n');
	}
	while (head)
	{
		if (ft_strchr(args->options, 's'))
		{
			ft_putnbr(head->blocks);
			ft_putchar(' ');
		}
		print_file(head, args, links_column, size_column);
		head = head->next;
	}
}
Пример #14
0
int main(int argc, char *argv[]) {
    num_tokens = 0;
    num_vars = 0;

    // set yyin to file if passed by user
    if(argc > 1) {
        yyin = fopen(argv[1], "r");
        if(yyin == NULL) {
            printf("error: invalid file\n");
            exit(1);
        }
    }
    else {
        printf("> "); // prompt
    }

    yyparse();
    fclose(yyin);
    generate_pla(root);

    and_or_not(root);
    freopen ("/dev/tty", "a", stdout); // make sure stdout is restored

    free_ast(root);
    empty_tokens();
    reformat_output();

    // print output
    char *fname = (char *)"out.pla";
    print_file(&fname);

    return 0;
}
Пример #15
0
/* PR 312534: reduce stack usage (gcc does not combine locals) */
static void
kstat_print_individual(file_t outf, kstat_variable_t *kv,
                       const char *name, const char *desc)
{
    print_file(outf, "%20s:"FIXED_TIMESTAMP_FORMAT" totc,"
               "%8u num,"
               FIXED_TIMESTAMP_FORMAT" minc,"
               FIXED_TIMESTAMP_FORMAT" avg,"
               FIXED_TIMESTAMP_FORMAT" maxc,"
               FIXED_TIMESTAMP_FORMAT" self,"
               FIXED_TIMESTAMP_FORMAT" sub,"
               "\n"
               "                   "
               FIXED_TIMESTAMP_FORMAT" ms,"
               FIXED_TIMESTAMP_FORMAT" ms out,"
               "%s\n",
               name,
               kv->total_self + kv->total_sub,
               kv->num_self,
               (kv->min_cum == (timestamp_t)-1) ? 0 : kv->min_cum,
               (kv->total_self + kv->total_sub) / kv->num_self,
               kv->max_cum,
               kv->total_self,
               kv->total_sub,
               (kv->total_self + kv->total_sub) / kstat_frequency_per_msec,
               kv->total_outliers/ kstat_frequency_per_msec,
               desc);
}
Пример #16
0
double print_file2()
{
  char filename[100];
  FILE *fr;
  
  printf("Zadejte jmeno souboru: ");
  scanf("%s", filename);

  if ((fr = fopen(filename, "r")) == NULL) {
    printf("Soubor %s nebyl nalezen!\n", filename);
    return filename_is_k(filename) ? 2.2 : 1.1;
  }

  print_file(fr);
  
  if (fclose(fr) == EOF) {
    printf("Nepodarilo se zavrit soubor %s!\n", filename);
    return 0.5;
  }

  if (filename_is_k(filename)) {
    return 2.2;
  }

  return 0.5;

}
Пример #17
0
int do_normal_ls(const char *remote_path, int option_show_detail) {
//{{{
    int ret             = 0;
    PCSFile *file       = NULL;
    PCSFileList *list   = NULL;
    PCSFile *tmp        = NULL;
    const char *error   = NULL;

    file = BaiduPCS_NewRemoteFile(api, remote_path);
    error = BaiduPCS_GetError(api);
    if (error != NULL || file == NULL) {
        color_log(COLOR_LOG_ERROR, "%s 获取文件信息失败:%s\n", remote_path, error);
        ret = 1;
        goto free;
    }

    if (!file->is_dir) {
        print_file(file, option_show_detail);
    } else {
        list = BaiduPCS_ListRemoteDir(api, file->path);
        error = BaiduPCS_GetError(api);
        if (error != NULL || list == NULL) {
            color_log(COLOR_LOG_ERROR, "%s 获取文件信息失败:%s\n", file->path, error);
            ret = 1;
            goto free;
        }
        tmp = list->first;
        while (tmp) {
            print_file(tmp, option_show_detail);
            tmp = tmp->next;
        }
        PCSFileList_Free(list);
        list = NULL;
    }

free:
    if (file != NULL) {
        PCSFile_Free(file); 
    }

    if (list != NULL) {
        PCSFileList_Free(list);
    }

    return ret;
}
Пример #18
0
Файл: ls.c Проект: akat1/impala
void
print_path(const char *file)
{
    struct stat st;
    lstat(file, &st);
    if (S_ISDIR(st.st_mode))
        print_dir(file);
        else print_file(file);
}
Пример #19
0
static int do_ls(int argc, char **argv)
{
	u8 buf[256], *cur = buf;
	int r, count;

	r = sc_list_files(card, buf, sizeof(buf));
	if (r < 0) {
		check_ret(r, SC_AC_OP_LIST_FILES, "unable to receive file listing", current_file);
		return -1;
	}
	count = r;
	printf("FileID\tType  Size\n");
	while (count >= 2) {
		sc_path_t path;
		sc_file_t *file = NULL;
		char filename[10];
		int i = 0;
		int matches = 0;

		/* construct file name */
		sprintf(filename, "%02X%02X", cur[0], cur[1]);

		 /* compare file name against patterns */
		for (i = 0; i < argc; i++) {
			if (pattern_match(argv[i], filename)) {
				matches = 1;
				break;
			}
		}

		/* if any filename pattern were given, filter only matching file names */
		if (argc == 0 || matches) {
			if (current_path.type != SC_PATH_TYPE_DF_NAME) {
				path = current_path;
				sc_append_path_id(&path, cur, 2);
			} else {
				if (sc_path_set(&path, SC_PATH_TYPE_FILE_ID, cur, 2, 0, 0) != SC_SUCCESS) {
					printf("unable to set path.\n");
					die(1);
				}
			}

			r = sc_select_file(card, &path, &file);
			if (r) {
				printf(" %02X%02X unable to select file, %s\n", cur[0], cur[1], sc_strerror(r));
			} else {
				file->id = (cur[0] << 8) | cur[1];
					print_file(file);
				sc_file_free(file);
			}
		}
		cur += 2;
		count -= 2;
		select_current_path_or_die();
	}
	return 0;
}
Пример #20
0
int main(int argc, const char **argv) {
    char *id = NULL, *line = NULL;
    int show_utmp = 1, show_wtmp = 0;
    int c;
    poptContext optCon;
    struct poptOption optionsTable[] = {
        { "utmp", 'u', POPT_ARG_NONE|POPT_ARGFLAG_XOR, 
	   &show_utmp, 0,
          "toggle showing contents of utmp file", NULL },
        { "wtmp", 'w', POPT_ARG_NONE|POPT_ARGFLAG_XOR, 
	   &show_wtmp, 0,
          "toggle showing contents of wtmp file", NULL },
        { "id", 'i', POPT_ARG_STRING, &id, 0,
          "show process entries for specified inittab id", 
	  "<inittab id>" },
        { "line", 'l', POPT_ARG_STRING, &line, 0,
          "show process entries for specified device line", 
	  "<line>" },
        POPT_AUTOHELP
        POPT_TABLEEND
    };

    optCon = poptGetContext("utmp", argc, argv, optionsTable, 0);
    if ((c = poptGetNextOpt(optCon)) < -1) {
        fprintf(stderr, "%s: %s\n",
            poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
            poptStrerror(c));
        return 1;
    }
    poptFreeContext(optCon);

    if (id && line)
        fprintf(stderr, "Cannot choose both by id and line, "
			"choosing by line\n");

    if (show_utmp)
        print_file(_PATH_UTMP, id, line);
    if (show_utmp && show_wtmp)
        printf("\n\n\n");
    if (show_wtmp)
        print_file(_PATH_WTMP, id, line);

    return 0;
}
Пример #21
0
int main(int argc, char **argv)
{
    static char *callback = NULL, *user;
    int i;
    extern int headers_initialized;

    if (argc < 2) {  /* normal operation as a CGI application */
	cgi_init();
	atexit(cgi_end);
       	cgi_process_form();
	printf("Content-type: application/javascript; charset=utf-8\r\n\r\n");
    }
    else
        interactive = 1;  /* interactive mode for debugging */
    wfdbquiet();	  /* suppress WFDB library error messages */
    atexit(cleanup);	/* release allocated memory before exiting */

    /* Define data sources to be accessed via this server. */
    setrepos();		/* function defined in "setrepos.c" */

    if (!(action = get_param("action"))) {
	print_file(LWDIR "/doc/about.txt");
	exit(0);
    }

    if (!interactive && (callback = get_param("callback"))) {
	printf("%s(", callback);	/* JSONP:  "wrap" output in callback */
	atexit(jsonp_end);	/* close the output with ")" before exiting */
    }

    if (strcmp(action, "dblist") == 0)
	dblist();

    else if ((db = get_param("db")) == NULL)
	lwfail("Your request did not specify a database");
  
    else if (strcmp(action, "rlist") == 0)
	rlist();

    else if (strcmp(action, "alist") == 0)
	alist();

    else if ((record = get_param("record")) == NULL)
	lwfail("Your request did not specify a record");

    else if (strcmp(action, "info") == 0)
	info();

    else if (strcmp(action, "fetch") == 0)
	fetch();

    else
	lwfail("Your request did not specify a valid action");

    exit(0);
}
Пример #22
0
int open_file(char *file) {
    if ((strstr(file,".ovd")!=NULL) || (strstr(file,".odt")!=NULL) )  /* check whether it's a ovd or odt*/
    {
        if (strstr(file,".ovd")!=NULL)			/* ovd*/
        {
            ovd_file = fopen(file,"r");

            if (ovd_file != NULL)
            {
                buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
                main_win = subwin(stdscr,LINES-2,COLS,1,0);
                get_file_content(ovd_file, file, buffer);
                fclose(ovd_file);
                cur_char = buffer->content;
                print_site(buffer->cur_line, buffer->lines);
                print_file(buffer,cur_char);
                file_printed = true;
                file_type = 2;
            }
            else
            {
                print_status_bar("File does not exist!");
            }
        }
        else								/* else if odt */
        {
            buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
            main_win= subwin(stdscr,LINES-2,COLS,1,0);
            open_odt(file, buffer);
            /*												get_file_meta("/tmp/ooview/meta.xml",buffer);*/
            cur_char = buffer->content;
            print_site(buffer->cur_line, buffer->lines);
            print_file(buffer,cur_char);
            file_printed = true;
            file_type = 1;
        }

    }
    else
    {
        print_status_bar("Must be a OOView-file (ovd) or OpenDocument-file (odt)!");
    }
}
Пример #23
0
int main(void)
{
	while(1)
	{
		print_file();
		sleep(5);
		system("clear");
	}
	return 0;
}
Пример #24
0
void			ft_print_arg(t_file *file, t_ls *ls)
{
	if (ft_strchr(ls->options, 'l') != NULL)
		print_file_l(file, ls);
	else
	{
		print_file(file, ls);
		if (ft_strchr(ls->options, '1') != NULL)
			ft_putchar('\n');
	}
}
/* Cat clone */
int main(int argc, char **argv) {
  int i;
  if (argc < 2) {
    read_stdin();
    return 0;
  }
  for (i=1 ; i<argc ; i++) {
    print_file(argv[i]);
  }
  return 0;
}
Пример #26
0
static void
our_memcpy_vs_libc(void)
{
    /* Compare our memcpy with libc memcpy.
     * XXX: Should compare on more sizes, especially small ones.
     */
    size_t alloc_size = 20 * 1024;
    int loop_count = 100 * 1000;
    void *src = global_heap_alloc(alloc_size HEAPACCT(ACCT_OTHER));
    void *dst = global_heap_alloc(alloc_size HEAPACCT(ACCT_OTHER));
    int i;
    memcpy_t glibc_memcpy = (memcpy_t) dlsym(RTLD_NEXT, "memcpy");
    uint64 our_memcpy_start, our_memcpy_end, our_memcpy_time;
    uint64 libc_memcpy_start, libc_memcpy_end, libc_memcpy_time;
    memset(src, -1, alloc_size);
    memset(dst, 0, alloc_size);

    our_memcpy_start = query_time_millis();
    for (i = 0; i < loop_count; i++) {
        memcpy(src, dst, alloc_size);
    }
    our_memcpy_end = query_time_millis();

    libc_memcpy_start = query_time_millis();
    for (i = 0; i < loop_count; i++) {
        glibc_memcpy(src, dst, alloc_size);
    }
    libc_memcpy_end = query_time_millis();

    global_heap_free(src, alloc_size HEAPACCT(ACCT_OTHER));
    global_heap_free(dst, alloc_size HEAPACCT(ACCT_OTHER));
    our_memcpy_time = our_memcpy_end - our_memcpy_start;
    libc_memcpy_time = libc_memcpy_end - libc_memcpy_start;
    print_file(STDERR, "our_memcpy_time: "UINT64_FORMAT_STRING"\n",
               our_memcpy_time);
    print_file(STDERR, "libc_memcpy_time: "UINT64_FORMAT_STRING"\n",
               libc_memcpy_time);
    /* We could assert that we're not too much slower, but that's a recipe for
     * flaky failures when the suite is run on shared VMs or in parallel.
     */
}
Пример #27
0
void file_view(const datat &data)
{
  std::ofstream out("file_view.html");

  out << "<html>\n<head>\n";
  out << "<title>" << html_escape(data.description) << "</title>\n";
  
  out << "<style type=\"text/css\">\n";
  out << "/* Source-code listing */\n";
  out << "div.file { float: left; padding-right: 20px; }\n";
  out << "div.listing { font-size: 3px; width: 150px; height: 400px; overflow-y: scroll; overflow-x: scroll; white-space: pre; }\n";
  out << "div.filename { text-align: center; font-size: 14px; width: 150px; }\n";

  out << "strong.alarm { font-style: normal; background-color: #ff6633; font-weight: normal; }\n";
  
  out << "/* Description of sw under test */\n";
  out << "div.description { float: center; font: 14px \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;  width=100%; text-align: center; }\n";
  
  out << "</style>\n";
  out << "</head>\n";
  
  out << "<body>\n";
  
  out << "<center><img src=\"http://www.deltacheck.org/deltacheck_logo_small.png\"></center>\n";
  
  out << "<div class=\"description\">\n";
  out << html_escape(data.description) << "\n";
  out << "</div>\n";
  
  std::set<irep_idt> files;
  
  for(datat::propertiest::const_iterator
      e_it=data.properties.begin();
      e_it!=data.properties.end();
      e_it++)
    files.insert(e_it->file);

  for(std::set<irep_idt>::const_iterator
      f_it=files.begin();
      f_it!=files.end();
      f_it++)
  {
    if(has_prefix(id2string(*f_it), "/usr/include/"))
      continue;
  
    if(has_prefix(id2string(*f_it), "<builtin-library>"))
      continue;
  
    print_file(data, *f_it, out);
  }
  
  out << "</body>\n</html>\n";
}
Пример #28
0
void * handle_request(void * args){
    int * fd = (int *)args;
    int run = 1;
    int ptr = 0;
    ssize_t got_bytes = 0;
    char * buf = malloc(BUFFER_SIZE);
    while( run ) {
        got_bytes = read( *fd, buf + ptr, BUFFER_SIZE - ptr);
        if(got_bytes <= 0){
            buf[ptr] = 0; // Terminate string
            break;
        }
        ptr += got_bytes;
        if( get_line(buf, ptr) ){
            break;
        }
    }
    
    struct request_t * req = malloc(sizeof(struct request_t));
    req->fd = *fd;
    req->selector = buf;
    req->selector_len = strlen(req->selector);
    req->path = resolve_selector(NULL, req->selector);
    req->path_len = strlen(req->path);
    
    plog("Request: %s", buf);
    
    if( is_menu( req ) ) {
        char * gopherfile;
        asprintf(&gopherfile, "%s%s", req->path, GOPHERMAP_FILENAME);
        plog("Sending menu @ %s", gopherfile);
        menu_item * items[1024];
        int item_count = parse_gophermap( gopherfile, &items[0], DEFAULT_HOST, DEFAULT_PORT );
        plog("Gophermap parsed, items: %u", item_count);
        for( int i = 0; i < item_count; i++ ){
            print_menu_item( req->fd, items[i] );
        }
        free( gopherfile) ;
    } else if ( is_file( req->path ) ) {
        plog("Sending file");
        print_file(req);
    } else if ( is_dir( req->path ) ) {
        plog("Sending dir");
        print_directory(req);
    }
    
    close_socket(req->fd, 1);
    free(req->selector);
    free(req->path);
    free(args);
    pthread_exit(NULL);
}
Пример #29
0
/**
 * Outputs a file into the console
 */
void console_read(char *dir, char *command) {
    memset(senddir, 0, 64);
    strcpy(senddir, dir);
    strcat(senddir, "/");
    strcat(senddir, get_argument(command, 1));
    file *f = vfs_file_open(senddir, "r");
    if(f->type != FS_FILE) {
        printk("read: file %s not found\n", senddir);
    } else {
        print_file(f);
    }
    vfs_file_close(f);
}
Пример #30
0
void recv_file_info(int sockfd, std::map<std::string, std::set<std::string> > &file_sets, login::Login user){
    int count;
    char bufferFST[4];
    count = recv(sockfd, bufferFST, 4, MSG_PEEK);
    if(count == -1)
        perror("Recv with error");

    google::protobuf::uint32 pkg_size = readHdr(bufferFST);
    int byteCount;
    file::Files files;
    char buffer[pkg_size + HDR_SIZE];
    if( ( byteCount = recv(sockfd, (void *)buffer, pkg_size + HDR_SIZE, MSG_WAITALL) ) == -1 ){
        perror("Error recviving data");
    }
    google::protobuf::io::ArrayInputStream ais(buffer, pkg_size + HDR_SIZE);
    google::protobuf::io::CodedInputStream coded_input(&ais);
    coded_input.ReadVarint32(&pkg_size);
    google::protobuf::io::CodedInputStream::Limit msgLimit = coded_input.PushLimit(pkg_size);
    files.ParseFromCodedStream(&coded_input);

    printf("%sFile update: \n", ANSI_COLOR_GREEN);
    for(int i=0; i<files.files_size(); ++i){
        file::File file = files.files(i);
        if( file_sets.find( file.file_name() ) == file_sets.end() ){
            file_sets[file.file_name()].insert(user.id());
            std::cout << file.file_name() << ":";
            print_file(file_sets[file.file_name()]);
        }
        else{
            file_sets[file.file_name()].insert(user.id());
            std::cout << file.file_name() << ":";
            print_file(file_sets[file.file_name()]);
        }
    }
    printf("%s\n", ANSI_COLOR_RESET);
    update();
}