int main() { char* cwd=gnu_getcwd(); strcat(cwd,"/"); //listfiles("./"); listfiles(cwd); }
int main(int argc, char **argv) { suite_fn suites[] = { #define SUITE(name) &suite_ ## name, #include "test/suites.h" #undef SUITE NULL }; static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; int verbose = 0; int c; char *testdir, *dir_before; int result; #ifdef _WIN32 putenv("CCACHE_DETECT_SHEBANG=1"); #endif while ((c = getopt_long(argc, argv, "hv", options, NULL)) != -1) { switch (c) { case 'h': fprintf(stdout, USAGE_TEXT); return 0; case 'v': verbose = 1; break; default: fprintf(stderr, USAGE_TEXT); return 1; } } if (getenv("RUN_FROM_BUILD_FARM")) { verbose = 1; } testdir = format("testdir.%d", (int)getpid()); cct_create_fresh_dir(testdir); dir_before = gnu_getcwd(); cct_chdir(testdir); result = cct_run(suites, verbose); if (result == 0) { cct_chdir(dir_before); cct_wipe(testdir); } free(testdir); free(dir_before); return result; }
void cct_suite_begin(const char *name) { ++total_suites; if (verbose) { printf("=== SUITE: %s ===\n", name); } dir_before_suite = gnu_getcwd(); create_dir(name); cct_chdir(name); current_suite = name; }
void cct_test_begin(const char *name) { ++total_tests; if (verbose) { printf("--- TEST: %s ---\n", name); } dir_before_test = gnu_getcwd(); create_dir(name); cct_chdir(name); current_test = name; putenv("CCACHE_CONFIG_PATH=/dev/null"); cc_reset(); }
int main(int argc, char **argv) { char **dirname = NULL; int i,j=0,k,n,optf,p,q,dtotal,ftotal,colored = FALSE; struct stat st; char sizebuf[64], *stmp; off_t size = 0; mode_t mt; bool needfulltree; q = p = dtotal = ftotal = 0; aflag = dflag = fflag = lflag = pflag = sflag = Fflag = uflag = gflag = FALSE; Dflag = qflag = Nflag = Qflag = Rflag = hflag = Hflag = siflag = cflag = FALSE; noindent = force_color = nocolor = xdev = noreport = nolinks = reverse = FALSE; ignorecase = matchdirs = dirsfirst = inodeflag = devflag = Xflag = Jflag = FALSE; duflag = pruneflag = FALSE; flimit = 0; dirs = xmalloc(sizeof(int) * (maxdirs=4096)); memset(dirs, 0, sizeof(int) * maxdirs); dirs[0] = 0; Level = -1; setlocale(LC_CTYPE, ""); setlocale(LC_COLLATE, ""); charset = getcharset(); if (charset == NULL) { charset = "UTF-8"; } /* Until I get rid of this hack, make it linux/cygwin/HP nonstop only: */ #if defined (LINUX) || defined (CYGWIN) || defined (__TANDEM) mb_cur_max = (int)MB_CUR_MAX; #else mb_cur_max = 1; #endif memset(utable,0,sizeof(utable)); memset(gtable,0,sizeof(gtable)); memset(itable,0,sizeof(itable)); optf = TRUE; for(n=i=1;i<argc;i=n) { n++; if (optf && argv[i][0] == '-' && argv[i][1]) { for(j=1;argv[i][j];j++) { switch(argv[i][j]) { case 'N': Nflag = TRUE; break; case 'q': qflag = TRUE; break; case 'Q': Qflag = TRUE; break; case 'd': dflag = TRUE; break; case 'l': lflag = TRUE; break; case 's': sflag = TRUE; break; case 'h': hflag = TRUE; sflag = TRUE; /* Assume they also want -s */ break; case 'u': uflag = TRUE; break; case 'g': gflag = TRUE; break; case 'f': fflag = TRUE; break; case 'F': Fflag = TRUE; break; case 'a': aflag = TRUE; break; case 'p': pflag = TRUE; break; case 'i': noindent = TRUE; _nl = ""; break; case 'C': force_color = TRUE; break; case 'n': nocolor = TRUE; break; case 'x': xdev = TRUE; break; case 'P': if (argv[n] == NULL) { fprintf(stderr,"tree: missing argument to -P option.\n"); exit(1); } pattern = argv[n++]; break; case 'I': if (argv[n] == NULL) { fprintf(stderr,"tree: missing argument to -I option.\n"); exit(1); } ipattern = argv[n++]; break; case 'A': ansilines = TRUE; break; case 'S': charset = "IBM437"; break; case 'D': Dflag = TRUE; break; case 't': cmpfunc = mtimesort; break; case 'c': cmpfunc = ctimesort; cflag = TRUE; break; case 'r': reverse = TRUE; break; case 'v': cmpfunc = versort; break; case 'U': cmpfunc = NULL; break; case 'X': Hflag = FALSE; Xflag = TRUE; break; case 'J': Jflag = TRUE; break; case 'H': Hflag = TRUE; Xflag = FALSE; if (argv[n] == NULL) { fprintf(stderr,"tree: missing argument to -H option.\n"); exit(1); } host = argv[n++]; sp = " "; break; case 'T': if (argv[n] == NULL) { fprintf(stderr,"tree: missing argument to -T option.\n"); exit(1); } title = argv[n++]; break; case 'R': Rflag = TRUE; break; case 'L': if ((sLevel = argv[n++]) == NULL) { fprintf(stderr,"tree: Missing argument to -L option.\n"); exit(1); } Level = strtoul(sLevel,NULL,0)-1; if (Level < 0) { fprintf(stderr,"tree: Invalid level, must be greater than 0.\n"); exit(1); } break; case 'o': if (argv[n] == NULL) { fprintf(stderr,"tree: missing argument to -o option.\n"); exit(1); } outfilename = argv[n++]; break; case '-': if (j == 1) { if (!strcmp("--", argv[i])) { optf = FALSE; break; } if (!strcmp("--help",argv[i])) { usage(2); exit(0); } if (!strcmp("--version",argv[i])) { char *v = version+12; printf("%.*s\n",(int)strlen(v)-1,v); exit(0); } if (!strcmp("--inodes",argv[i])) { j = strlen(argv[i])-1; inodeflag=TRUE; break; } if (!strcmp("--device",argv[i])) { j = strlen(argv[i])-1; devflag=TRUE; break; } if (!strcmp("--noreport",argv[i])) { j = strlen(argv[i])-1; noreport = TRUE; break; } if (!strcmp("--nolinks",argv[i])) { j = strlen(argv[i])-1; nolinks = TRUE; break; } if (!strcmp("--dirsfirst",argv[i])) { j = strlen(argv[i])-1; dirsfirst = TRUE; break; } if (!strncmp("--filelimit",argv[i],11)) { j = 11; if (*(argv[i]+11) == '=') { if (*(argv[i]+12)) { flimit=atoi(argv[i]+12); j = strlen(argv[i])-1; break; } } if (argv[n] != NULL) { flimit = atoi(argv[n++]); j = strlen(argv[i])-1; } else { fprintf(stderr,"tree: missing argument to --filelimit\n"); exit(1); } break; } if (!strncmp("--charset",argv[i],9)){ j = 9; if (*(argv[i]+j) == '=') { if (*(charset = (argv[i]+10))) { j = strlen(argv[i])-1; break; } } if (argv[n] != NULL) { charset = argv[n++]; j = strlen(argv[i])-1; } else { initlinedraw(1); exit(1); } break; } if (!strncmp("--si", argv[i], 4)) { j = strlen(argv[i])-1; sflag = TRUE; hflag = TRUE; siflag = TRUE; break; } if (!strncmp("--du",argv[i],4)) { j = strlen(argv[i])-1; sflag = TRUE; duflag = TRUE; break; } if (!strncmp("--prune",argv[i],7)) { j = strlen(argv[i])-1; pruneflag = TRUE; break; } if (!strncmp("--timefmt",argv[i],9)) { j = 9; if (*(argv[i]+j) == '=') { if (*(argv[i]+ (++j))) { timefmt=scopy(argv[i]+j); j = strlen(argv[i])-1; break; } } else if (argv[n] != NULL) { timefmt = scopy(argv[n]); n++; j = strlen(argv[i])-1; } else { fprintf(stderr,"tree: missing argument to --timefmt\n"); exit(1); } Dflag = TRUE; break; } if (!strncmp("--ignore-case",argv[i],13)) { j = strlen(argv[i])-1; ignorecase = TRUE; break; } if (!strncmp("--matchdirs",argv[i],11)) { j = strlen(argv[i])-1; matchdirs = TRUE; break; } if (!strncmp("--sort",argv[i],6)) { j = 6; if (*(argv[i]+j) == '=') { if (*(argv[i]+(++j))) { stmp = argv[i]+j; j = strlen(argv[i])-1; } else { fprintf(stderr,"tree: missing argument to --sort=\n"); exit(1); } } else if (argv[n] != NULL) { stmp = argv[n++]; } else { fprintf(stderr,"tree: missing argument to --sort\n"); exit(1); } cmpfunc = (void *)1; for(k=0;sorts[k].name;k++) { if (strcasecmp(sorts[k].name,stmp) == 0) { cmpfunc = sorts[k].cmpfunc; break; } } if (cmpfunc == (void *)1) { fprintf(stderr,"tree: sort type '%s' not valid, should be one of: ", stmp); for(k=0; sorts[k].name; k++) printf("%s%c", sorts[k].name, sorts[k+1].name? ',': '\n'); exit(1); } break; } } default: fprintf(stderr,"tree: Invalid argument -`%c'.\n",argv[i][j]); usage(1); exit(1); break; } } } else { if (!dirname) dirname = (char **)xmalloc(sizeof(char *) * (q=MINIT)); else if (p == (q-2)) dirname = (char **)xrealloc(dirname,sizeof(char *) * (q+=MINC)); dirname[p++] = scopy(argv[i]); } } if (p) dirname[p] = NULL; if (outfilename == NULL) { #ifdef __EMX__ _fsetmode(outfile=stdout,Hflag?"b":"t"); #else outfile = stdout; #endif } else { #ifdef __EMX__ outfile = fopen(outfilename,Hflag?"wb":"wt"); #else outfile = fopen(outfilename,"w"); #endif if (outfile == NULL) { fprintf(stderr,"tree: invalid filename '%s'\n",outfilename); exit(1); } } parse_dir_colors(); initlinedraw(0); needfulltree = duflag || pruneflag || matchdirs; /* Set our listdir function and sanity check options. */ if (Hflag) { listdir = needfulltree ? html_rlistdir : html_listdir; Xflag = FALSE; } else if (Xflag) { listdir = needfulltree ? xml_rlistdir : xml_listdir; colorize = FALSE; colored = FALSE; /* Do people want colored XML output? */ } else if (Jflag) { listdir = needfulltree ? json_rlistdir : json_listdir; colorize = FALSE; colored = FALSE; /* Do people want colored JSON output? */ } else { listdir = needfulltree ? unix_rlistdir : unix_listdir; } if (dflag) pruneflag = FALSE; /* You'll just get nothing otherwise. */ if (Rflag && (Level == -1)) Rflag = FALSE; if (Hflag) { emit_html_header(charset, title, version); fflag = FALSE; if (nolinks) { if (force_color) fprintf(outfile, "<b class=\"NORM\">%s</b>",host); else fprintf(outfile,"%s",host); } else { if (force_color) fprintf(outfile,"<a class=\"NORM\" href=\"%s\">%s</a>",host,host); else fprintf(outfile,"<a href=\"%s\">%s</a>",host,host); } curdir = gnu_getcwd(); } else if (Xflag) { fprintf(outfile,"<?xml version=\"1.0\""); if (charset) fprintf(outfile," encoding=\"%s\"",charset); fprintf(outfile,"?>%s<tree>%s",_nl,_nl); } else if (Jflag) fputc('[',outfile); if (dirname) { for(colored=i=0;dirname[i];i++,colored=0) { if (fflag) { do { j=strlen(dirname[i]); if (j > 1 && dirname[i][j-1] == '/') dirname[i][--j] = 0; } while (j > 1 && dirname[i][j-1] == '/'); } if ((n = lstat(dirname[i],&st)) >= 0) { saveino(st.st_ino, st.st_dev); if (colorize) colored = color(st.st_mode,dirname[i],n<0,FALSE); size += st.st_size; } if (Xflag || Jflag) { mt = st.st_mode & S_IFMT; for(j=0;ifmt[j];j++) if (ifmt[j] == mt) break; if (Xflag) fprintf(outfile,"%s<%s name=\"%s\">", noindent?"":" ", ftype[j], dirname[i]); else if (Jflag) { if (i) fprintf(outfile, ","); fprintf(outfile,"%s{\"type\":\"%s\",\"name\":\"%s\",\"contents\":[", noindent?"":"\n ", ftype[j], dirname[i]); } } else if (!Hflag) printit(dirname[i]); if (colored) fprintf(outfile,"%s",endcode); if (!Hflag) size += listdir(dirname[i],&dtotal,&ftotal,0,0); else { if (chdir(dirname[i])) { fprintf(outfile,"%s [error opening dir]\n",dirname[i]); exit(1); } else { size += listdir(".",&dtotal,&ftotal,0,0); chdir(curdir); } } if (Xflag) fprintf(outfile,"%s</%s>\n",noindent?"":" ", ftype[j]); if (Jflag) fprintf(outfile,"%s]}",noindent?"":" "); } } else { if ((n = lstat(".",&st)) >= 0) { saveino(st.st_ino, st.st_dev); if (colorize) colored = color(st.st_mode,".",n<0,FALSE); size = st.st_size; } if (Xflag) fprintf(outfile,"%s<directory name=\".\">",noindent?"":" "); else if (Jflag) fprintf(outfile, "{\"type\":\"directory\",\"name\": \".\",\"contents\":["); else if (!Hflag) fprintf(outfile,"."); if (colored) fprintf(outfile,"%s",endcode); size += listdir(".",&dtotal,&ftotal,0,0); if (Xflag) fprintf(outfile,"%s</directory>%s",noindent?"":" ", _nl); if (Jflag) fprintf(outfile,"%s]}",noindent?"":" "); } if (Hflag) fprintf(outfile,"\t<br><br>\n\t</p>\n\t<p>\n"); if (!noreport) { if (Xflag) { fprintf(outfile,"%s<report>%s",noindent?"":" ", _nl); if (duflag) fprintf(outfile,"%s<size>%lld</size>%s", noindent?"":" ", (long long int)size, _nl); fprintf(outfile,"%s<directories>%d</directories>%s", noindent?"":" ", dtotal, _nl); if (!dflag) fprintf(outfile,"%s<files>%d</files>%s", noindent?"":" ", ftotal, _nl); fprintf(outfile,"%s</report>%s",noindent?"":" ", _nl); } else if (Jflag) { fprintf(outfile, ",%s{\"type\":\"report\"",noindent?"":"\n "); if (duflag) fprintf(outfile,",\"size\":%lld", (long long int)size); fprintf(outfile,",\"directories\":%d", dtotal); if (!dflag) fprintf(outfile,",\"files\":%d", ftotal); fprintf(outfile, "}"); } else { if (duflag) { psize(sizebuf, size); fprintf(outfile,"\n%s%s used in ", sizebuf, hflag || siflag? "" : " bytes"); } else fputc('\n', outfile); if (dflag) fprintf(outfile,"%d director%s\n",dtotal,(dtotal==1? "y":"ies")); else fprintf(outfile,"%d director%s, %d file%s\n",dtotal,(dtotal==1? "y":"ies"),ftotal,(ftotal==1? "":"s")); } } if (Hflag) { fprintf(outfile,"\t<br><br>\n\t</p>\n"); fprintf(outfile,"\t<hr>\n"); fprintf(outfile,"\t<p class=\"VERSION\">\n"); fprintf(outfile,hversion,linedraw->copy, linedraw->copy, linedraw->copy, linedraw->copy); fprintf(outfile,"\t</p>\n"); fprintf(outfile,"</body>\n"); fprintf(outfile,"</html>\n"); } else if (Xflag) { fprintf(outfile,"</tree>\n"); } else if (Jflag) { fprintf(outfile, "%s]\n",_nl); } if (outfilename != NULL) fclose(outfile); return 0; }
/* find the hash for a command. The hash includes all argument lists, plus the output from running the compiler with -E */ static void find_hash(ARGS *args) { int i; char *path_stdout, *path_stderr; char *hash_dir; char *s; struct stat st; int status; int nlevels = 2; char *input_base; char *tmp; if ((s = getenv("CCACHE_NLEVELS"))) { nlevels = atoi(s); if (nlevels < 1) nlevels = 1; if (nlevels > 8) nlevels = 8; } hash_start(); /* when we are doing the unifying tricks we need to include the input file name in the hash to get the warnings right */ if (enable_unify) { hash_string(input_file); } /* we have to hash the extension, as a .i file isn't treated the same by the compiler as a .ii file */ hash_string(i_extension); /* first the arguments */ for (i=1;i<args->argc;i++) { /* some arguments don't contribute to the hash. The theory is that these arguments will change the output of -E if they are going to have any effect at all, or they only affect linking */ if (i < args->argc-1) { if (strcmp(args->argv[i], "-I") == 0 || strcmp(args->argv[i], "-include") == 0 || strcmp(args->argv[i], "-L") == 0 || strcmp(args->argv[i], "-D") == 0 || strcmp(args->argv[i], "-idirafter") == 0 || strcmp(args->argv[i], "-isystem") == 0) { i++; continue; } } if (strncmp(args->argv[i], "-I", 2) == 0 || strncmp(args->argv[i], "-L", 2) == 0 || strncmp(args->argv[i], "-D", 2) == 0 || strncmp(args->argv[i], "-idirafter", 10) == 0 || strncmp(args->argv[i], "-isystem", 8) == 0) { continue; } if (strncmp(args->argv[i], "--specs=", 8) == 0 && stat(args->argv[i]+8, &st) == 0) { /* if given a explicit specs file, then hash that file, but don't include the path to it in the hash */ hash_file(args->argv[i]+8); continue; } /* all other arguments are included in the hash */ hash_string(args->argv[i]); } /* the compiler driver size and date. This is a simple minded way to try and detect compiler upgrades. It is not 100% reliable */ if (stat(args->argv[0], &st) != 0) { cc_log("Couldn't stat the compiler!? (argv[0]='%s')\n", args->argv[0]); stats_update(STATS_COMPILER); failed(); } /* also include the hash of the compiler name - as some compilers use hard links and behave differently depending on the real name */ if (st.st_nlink > 1) { hash_string(str_basename(args->argv[0])); } hash_int(st.st_size); hash_int(st.st_mtime); /* possibly hash the current working directory */ if (getenv("CCACHE_HASHDIR")) { char *cwd = gnu_getcwd(); if (cwd) { hash_string(cwd); free(cwd); } } /* ~/hello.c -> tmp.hello.123.i limit the basename to 10 characters in order to cope with filesystem with small maximum filename length limits */ input_base = str_basename(input_file); tmp = strchr(input_base, '.'); if (tmp != NULL) { *tmp = 0; } if (strlen(input_base) > 10) { input_base[10] = 0; } /* now the run */ x_asprintf(&path_stdout, "%s/%s.tmp.%s.%s", temp_dir, input_base, tmp_string(), i_extension); x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string()); if (!direct_i_file) { /* run cpp on the input file to obtain the .i */ args_add(args, "-E"); args_add(args, input_file); status = execute(args->argv, path_stdout, path_stderr); args_pop(args, 2); } else { /* we are compiling a .i or .ii file - that means we can skip the cpp stage and directly form the correct i_tmpfile */ path_stdout = input_file; if (create_empty_file(path_stderr) != 0) { stats_update(STATS_ERROR); cc_log("failed to create empty stderr file\n"); failed(); } status = 0; } if (status != 0) { if (!direct_i_file) { unlink(path_stdout); } unlink(path_stderr); cc_log("the preprocessor gave %d\n", status); stats_update(STATS_PREPROCESSOR); failed(); } /* if the compilation is with -g then we have to include the whole of the preprocessor output, which means we are sensitive to line number information. Otherwise we can discard line number info, which makes us less sensitive to reformatting changes Note! I have now disabled the unification code by default as it gives the wrong line numbers for warnings. Pity. */ if (!enable_unify) { hash_file(path_stdout); } else { if (unify_hash(path_stdout) != 0) { stats_update(STATS_ERROR); failed(); } } hash_file(path_stderr); i_tmpfile = path_stdout; if (!getenv("CCACHE_CPP2")) { /* if we are using the CPP trick then we need to remember this stderr data and output it just before the main stderr from the compiler pass */ cpp_stderr = path_stderr; } else { unlink(path_stderr); free(path_stderr); } /* we use a N level subdir for the cache path to reduce the impact on filesystems which are slow for large directories */ s = hash_result(); x_asprintf(&hash_dir, "%s/%c", cache_dir, s[0]); x_asprintf(&stats_file, "%s/stats", hash_dir); for (i=1; i<nlevels; i++) { char *p; if (create_dir(hash_dir) != 0) { cc_log("failed to create %s\n", hash_dir); failed(); } x_asprintf(&p, "%s/%c", hash_dir, s[i]); free(hash_dir); hash_dir = p; } if (create_dir(hash_dir) != 0) { cc_log("failed to create %s\n", hash_dir); failed(); } x_asprintf(&hashname, "%s/%s", hash_dir, s+nlevels); free(hash_dir); }
static int exec_cli(int argc, char **argv) { int fni; char **s_params; (void)s_params; const char *fname; if (!get_file_name(argc, argv, &fname, &fni)) { USAGE(); return 0; } e8_environment env = e8_env_new(); e8_translator tr = e8_env_get_translator(env); e8_env_set_debug_flag(env, true); #ifdef __WINNT e8_env_set_output_encoding(env, "cp866"); #endif // __WINNT #ifdef __linux e8_env_set_output_encoding(env, "utf-8"); #endif // __linux char *source_cwd = gnu_getcwd(); load_global_settings(env, tr); /* Настройки из папки скрипта */ settings_from_file("./e8script.cfg", env, tr); e8_env_apply_PATH(env, "PATH"); bool no_run = false; /* settings_from_cli: */ { int i = 1; while (i < fni) { if (strcmp(argv[i], "--no-run") == 0) { no_run = true; ++i; continue; } e8_runtime_error *__err; __err = e8_option_apply_cli_option(argv[i], env, tr); if (__err) { print_error(__err, e8_env_get_output_encoding(env)); e8_free_exception(__err); __err = 0; } ++i; } s_params = &argv[fni + 1]; } setlocale(LC_NUMERIC, "C"); setlocale(LC_MONETARY, "C"); e8_register_stdlib(env); e8_register_stdio(env); int first_argument_index = fni + 1; { /* Создаём массив Аргументы командной строки */ e8_array *a_args = __e8_new_array(false, 0); E8_VAR(va_args); e8_var_object(&va_args, a_args); for (int i = first_argument_index; i < argc; i++) { e8_string *s_arg = e8_string_ascii(argv[i]); E8_VAR(vs_arg); e8_var_string(&vs_arg, s_arg->s); e8_string_destroy(s_arg); e8_array_add_nvalues(&va_args, 1, &vs_arg); e8_var_destroy(&vs_arg); } e8_env_add_global_value_utf(env, "АргументыКоманднойСтроки", &va_args); e8_env_add_global_value_utf(env, "CommandLineArguments", &va_args); e8_var_destroy(&va_args); } e8_runtime_error *__err; e8_unit u; int res = 0; char *used_filename = (char*)malloc(strlen(source_cwd) + strlen(fname) + 3); sprintf(used_filename, "%s/%s", source_cwd, fname); __err = e8_env_unit_from_file(env, used_filename, E8_FILE_AUTO, &u); free(used_filename); { /* Устанавливаем текущий каталог по первому файлу */ char *fdir = extract_dir(fname); chdir(fdir); free(fdir); } if (!__err) { e8_gc_use_object(u); if (!no_run) __err = e8_env_execute(u, false); e8_env_unit_free(u); } const char *enc = e8_env_get_output_encoding(env); if (__err) { res = __err->error_no; print_error(__err, enc); e8_free_exception(__err); } e8_env_close(env); e8_gc_done(); chdir(source_cwd); free(source_cwd); return res; } // exec_cli