int main(int argc, char *argv[]) { astring *dirname = NULL, *tempfilename = NULL, *tempheader = NULL, *tempfooter = NULL; UINT32 bufsize; void *buffer; int listnum; int result; /* first argument is the directory */ if (argc < 4) { fprintf(stderr, "Usage:\nregrep <template> <outputdir> <summary1> [<summary2> [<summary3> ...]]\n"); return 1; } tempfilename = astring_dupc(argv[1]); dirname = astring_dupc(argv[2]); list_count = argc - 3; /* read the template file into an astring */ if (core_fload(astring_c(tempfilename), &buffer, &bufsize) == FILERR_NONE) { tempheader = astring_dupch((const char *)buffer, bufsize); free(buffer); } /* verify the template */ if (tempheader == NULL) { fprintf(stderr, "Unable to read template file\n"); return 1; } result = astring_findc(tempheader, 0, "<!--CONTENT-->"); if (result == -1) { fprintf(stderr, "Template is missing a <!--CONTENT--> marker\n"); return 1; } tempfooter = astring_substr(astring_dup(tempheader), result + 14, -1); tempheader = astring_substr(tempheader, 0, result); /* loop over arguments and read the files */ for (listnum = 0; listnum < list_count; listnum++) { result = read_summary_log(argv[listnum + 3], listnum); if (result != 0) return result; } /* output the summary */ output_report(dirname, tempheader, tempfooter, sort_file_list()); astring_free(dirname); astring_free(tempfilename); astring_free(tempheader); astring_free(tempfooter); return 0; }
int main(int argc, char *argv[]) { astring *srcdir = NULL, *dstdir = NULL; int unadorned = 0; int result; int argnum; /* loop over arguments */ for (argnum = 1; argnum < argc; argnum++) { char *arg = argv[argnum]; /* include path? */ if (arg[0] == '-' && arg[1] == 'I') { *incpathhead = malloc(sizeof(**incpathhead)); if (*incpathhead != NULL) { (*incpathhead)->next = NULL; (*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]); incpathhead = &(*incpathhead)->next; } } /* other parameter */ else if (arg[0] != '-' && unadorned == 0) { srcdir = astring_dupc(arg); unadorned++; } else if (arg[0] != '-' && unadorned == 1) { dstdir = astring_dupc(arg); unadorned++; } else goto usage; } /* make sure we got 2 parameters */ if (srcdir == NULL || dstdir == NULL) goto usage; /* recurse over subdirectories */ result = recurse_dir(astring_len(srcdir), astring_len(dstdir), srcdir, dstdir); /* free source and destination directories */ astring_free(srcdir); astring_free(dstdir); return result; usage: fprintf(stderr, "Usage:\n%s <srcroot> <destroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]); return 1; }
static chd_file *get_disc(const device_config *device) { mame_file *image_file = NULL; chd_file *image_chd = NULL; mame_path *path; /* open a path to the ROMs and find the first CHD file */ path = mame_openpath(mame_options(), OPTION_ROMPATH); if (path != NULL) { const osd_directory_entry *dir; /* iterate while we get new objects */ while ((dir = mame_readpath(path)) != NULL) { int length = strlen(dir->name); /* look for files ending in .chd */ if (length > 4 && dir->name[length - 4] == '.' && tolower(dir->name[length - 3]) == 'c' && tolower(dir->name[length - 2]) == 'h' && tolower(dir->name[length - 1]) == 'd') { file_error filerr; chd_error chderr; /* open the file itself via our search path */ filerr = mame_fopen(SEARCHPATH_IMAGE, dir->name, OPEN_FLAG_READ, &image_file); if (filerr == FILERR_NONE) { /* try to open the CHD */ chderr = chd_open_file(mame_core_file(image_file), CHD_OPEN_READ, NULL, &image_chd); if (chderr == CHDERR_NONE) { set_disk_handle(device->machine, "laserdisc", image_file, image_chd); filename = astring_dupc(dir->name); add_exit_callback(device->machine, free_string); break; } /* close the file on failure */ mame_fclose(image_file); image_file = NULL; } } } mame_closepath(path); } /* if we failed, pop a message and exit */ if (image_file == NULL) fatalerror("No valid image file found!\n"); return get_disk_handle(device->machine, "laserdisc"); }
x86log_context *x86log_create_context(const char *filename) { x86log_context *log; /* allocate the log */ log = alloc_clear_or_die(x86log_context); /* allocate the filename */ log->filename = astring_dupc(filename); /* reset things */ reset_log(log); return log; }
x86log_context *x86log_create_context(const char *filename) { x86log_context *log; /* allocate the log */ log = malloc_or_die(sizeof(*log)); memset(log, 0, sizeof(*log)); /* allocate the filename */ log->filename = astring_dupc(filename); /* reset things */ reset_log(log); return log; }
static void output_report(const astring *dirname, const astring *tempheader, const astring *tempfooter, summary_file *filelist) { summary_file *buckethead[BUCKET_COUNT], **buckettailptr[BUCKET_COUNT]; summary_file *curfile; astring *title = astring_dupc("MAME Regressions"); astring *tempname = astring_alloc(); int listnum, bucknum; core_file *indexfile; int count = 0, total; /* initialize the lists */ for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++) { buckethead[bucknum] = NULL; buckettailptr[bucknum] = &buckethead[bucknum]; } /* compute the total number of files */ total = 0; for (curfile = filelist; curfile != NULL; curfile = curfile->next) total++; /* first bucketize the games */ for (curfile = filelist; curfile != NULL; curfile = curfile->next) { int statcount[STATUS_COUNT] = { 0 }; int bucket = BUCKET_UNKNOWN; int unique_codes = 0; int first_valid; /* print status */ if (++count % 100 == 0) fprintf(stderr, "Processing file %d/%d\n", count, total); /* find the first valid entry */ for (first_valid = 0; curfile->status[first_valid] == STATUS_NOT_PRESENT; first_valid++) ; /* do we need to output anything? */ for (listnum = first_valid; listnum < list_count; listnum++) if (statcount[curfile->status[listnum]]++ == 0) unique_codes++; /* were we consistent? */ if (unique_codes == 1) { /* were we consistently ok? */ if (curfile->status[first_valid] == STATUS_SUCCESS) bucket = compare_screenshots(curfile); /* must have been consistently erroring */ else bucket = BUCKET_CONSISTENT_ERROR; } /* ok, we're not consistent; could be a number of things */ else { /* were we ok at the start and end but not in the middle? */ if (curfile->status[first_valid] == STATUS_SUCCESS && curfile->status[list_count - 1] == STATUS_SUCCESS) bucket = BUCKET_GOOD_BUT_CHANGED; /* did we go from good to bad? */ else if (curfile->status[first_valid] == STATUS_SUCCESS) bucket = BUCKET_REGRESSED; /* did we go from bad to good? */ else if (curfile->status[list_count - 1] == STATUS_SUCCESS) bucket = BUCKET_IMPROVED; /* must have had multiple errors */ else bucket = BUCKET_MULTI_ERROR; } /* add us to the appropriate list */ *buckettailptr[bucket] = curfile; buckettailptr[bucket] = &curfile->next; } /* terminate all the lists */ for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++) *buckettailptr[bucknum] = NULL; /* output header */ astring_printf(tempname, "%s" PATH_SEPARATOR "%s", astring_c(dirname), "index.html"); indexfile = create_file_and_output_header(tempname, tempheader, title); if (indexfile == NULL) { fprintf(stderr, "Error creating file '%s'\n", astring_c(tempname)); astring_free(tempname); astring_free(title); return; } /* iterate over buckets and output them */ for (bucknum = 0; bucknum < ARRAY_LENGTH(bucket_output_order); bucknum++) { int curbucket = bucket_output_order[bucknum]; if (buckethead[curbucket] != NULL) { fprintf(stderr, "Outputting bucket: %s\n", bucket_name[curbucket]); append_driver_list_table(bucket_name[curbucket], dirname, indexfile, buckethead[curbucket], tempheader, tempfooter); } } /* output footer */ output_footer_and_close_file(indexfile, tempfooter, title); astring_free(tempname); astring_free(title); }
static int recurse_dir(int srcrootlen, const astring *srcdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; int result = 0; int entindex; /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry **listarray = NULL; list_entry *list = NULL; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = (list_entry *)malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = (list_entry **)malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } free(listarray); /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile; /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ if (entry_type == ENTTYPE_FILE) { /* make sure we care, first */ if (core_filename_ends_with(astring_c(curlist->name), ".c")) { tagmap *depend_map = tagmap_alloc(); tagmap_entry *map_entry; file_entry *file; astring *target; int taghash; /* find dependencies */ file = compute_dependencies(srcrootlen, srcfile); recurse_dependencies(file, depend_map); /* convert the target from source to object (makes assumptions about rules) */ target = astring_dup(file->name); astring_replacec(target, 0, "src/", "$(OBJ)/"); astring_replacec(target, 0, ".c", ".o"); printf("\n%s : \\\n", astring_c(target)); /* iterate over the hashed dependencies and output them as well */ for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++) for (map_entry = depend_map->table[taghash]; map_entry != NULL; map_entry = map_entry->next) printf("\t%s \\\n", astring_c((astring *)map_entry->object)); astring_free(target); tagmap_free(depend_map); } } /* if we have a directory, recurse */ else result = recurse_dir(srcrootlen, srcfile); /* free memory for the names */ astring_free(srcfile); } /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: return result; }
int main(int argc, char *argv[]) { include_path **incpathhead = &incpaths; exclude_path **excpathhead = &excpaths; astring *srcdir = NULL; int unadorned = 0; int result; int argnum; /* loop over arguments */ for (argnum = 1; argnum < argc; argnum++) { char *arg = argv[argnum]; /* include path? */ if (arg[0] == '-' && arg[1] == 'I') { *incpathhead = (include_path *)malloc(sizeof(**incpathhead)); if (*incpathhead != NULL) { (*incpathhead)->next = NULL; (*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]); incpathhead = &(*incpathhead)->next; } } /* exclude path? */ else if (arg[0] == '-' && arg[1] == 'X') { *excpathhead = (exclude_path *)malloc(sizeof(**excpathhead)); if (*excpathhead != NULL) { astring *path; (*excpathhead)->next = NULL; path = astring_replacechr(astring_dupc(&arg[2]), PATH_SEPARATOR[0], '/'); (*excpathhead)->recursive = (astring_replacec(path, astring_len(path) - 4, "/...", "") != 0); (*excpathhead)->path = path; (*excpathhead)->pathlen = astring_len(path); excpathhead = &(*excpathhead)->next; } } /* ignore -include which is used by sdlmame to include sdlprefix.h before all other includes */ else if (strcmp(arg,"-include") == 0) { argnum++; } /* other parameter */ else if (arg[0] != '-' && unadorned == 0) { srcdir = astring_replacechr(astring_dupc(arg), '/', PATH_SEPARATOR[0]); unadorned++; } else goto usage; } /* make sure we got 1 parameter */ if (srcdir == NULL) goto usage; /* create a tagmap for tracking files we've visited */ file_map = tagmap_alloc(); /* recurse over subdirectories */ result = recurse_dir(astring_len(srcdir), srcdir); /* free source and destination directories */ tagmap_free(file_map); astring_free(srcdir); return result; usage: fprintf(stderr, "Usage:\n%s <srcroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]); return 1; }
static int recurse_dir(int srcrootlen, int dstrootlen, const astring *srcdir, const astring *dstdir) { static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE }; const astring *srcdir_subpath; core_file *indexfile = NULL; astring *indexname; int result = 0; int entindex; /* extract a normalized subpath */ srcdir_subpath = normalized_subpath(srcdir, srcrootlen + 1); if (srcdir_subpath == NULL) return 1; /* create an index file */ indexname = astring_alloc(); astring_printf(indexname, "%s%c%s", astring_c(dstdir), PATH_SEPARATOR[0], "index.html"); indexfile = create_file_and_output_header(indexname, "MAME Source Code", astring_c(srcdir_subpath)); astring_free(indexname); /* output the directory navigation */ core_fprintf(indexfile, "<h3>Viewing Directory: "); output_path_as_links(indexfile, srcdir_subpath, TRUE, FALSE); core_fprintf(indexfile, "</h3>"); astring_free((astring *)srcdir_subpath); /* iterate first over directories, then over files */ for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++) { osd_dir_entry_type entry_type = typelist[entindex]; const osd_directory_entry *entry; list_entry *list = NULL; list_entry **listarray; list_entry *curlist; osd_directory *dir; int found = 0; /* open the directory and iterate through it */ dir = osd_opendir(astring_c(srcdir)); if (dir == NULL) { result = 1; goto error; } /* build up the list of files */ while ((entry = osd_readdir(dir)) != NULL) if (entry->type == entry_type && entry->name[0] != '.') { list_entry *lentry = malloc(sizeof(*lentry)); lentry->name = astring_dupc(entry->name); lentry->next = list; list = lentry; found++; } /* close the directory */ osd_closedir(dir); /* skip if nothing found */ if (found == 0) continue; /* allocate memory for sorting */ listarray = malloc(sizeof(list_entry *) * found); found = 0; for (curlist = list; curlist != NULL; curlist = curlist->next) listarray[found++] = curlist; /* sort the list */ qsort(listarray, found, sizeof(listarray[0]), compare_list_entries); /* rebuild the list */ list = NULL; while (--found >= 0) { listarray[found]->next = list; list = listarray[found]; } /* iterate through each file */ for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next) { astring *srcfile, *dstfile; /* add a header */ if (curlist == list) core_fprintf(indexfile, "\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files"); /* build the source filename */ srcfile = astring_alloc(); astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name)); /* if we have a file, output it */ dstfile = astring_alloc(); if (entry_type == ENTTYPE_FILE) { file_type type = FILE_TYPE_INVALID; int extnum; /* make sure we care, first */ for (extnum = 0; extnum < ARRAY_LENGTH(extension_lookup); extnum++) if (core_filename_ends_with(astring_c(curlist->name), extension_lookup[extnum].extension)) { type = extension_lookup[extnum].type; break; } /* if we got a valid file, process it */ if (type != FILE_TYPE_INVALID) { astring_printf(dstfile, "%s%c%s.html", astring_c(dstdir), PATH_SEPARATOR[0], astring_c(curlist->name)); if (indexfile != NULL) core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", astring_c(curlist->name), astring_c(curlist->name)); result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, astring_cmp(srcdir, dstdir) == 0); } } /* if we have a directory, recurse */ else { astring_printf(dstfile, "%s%c%s", astring_c(dstdir), PATH_SEPARATOR[0], astring_c(curlist->name)); if (indexfile != NULL) core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", astring_c(curlist->name), astring_c(curlist->name)); result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile); } /* free memory for the names */ astring_free(srcfile); astring_free(dstfile); } /* close the list if we found some stuff */ if (list != NULL) core_fprintf(indexfile, "\t</ul>\n"); /* free all the allocated entries */ while (list != NULL) { list_entry *next = list->next; astring_free((astring *)list->name); free(list); list = next; } } error: if (indexfile != NULL) output_footer_and_close_file(indexfile); return result; }