static int hunk_matches (unsigned long orig_offset, unsigned long orig_count, unsigned long hunknum) { int h = 0, l = 0; struct range *r; /* The hunk can't match if the containing file doesn't. */ if (!file_matches ()) return 0; // For the purposes of matching, zero lines at offset n counts // as line n. if (!orig_count) orig_count = 1; // See if the hunk range list includes this hunk. -1UL is a // wildcard. for (r = hunks; r; r = r->next) if ((r->start == -1UL || r->start <= hunknum) && (r->end == -1UL || hunknum <= r->end)) { h = 1; break; } // See if the lines range list includes this hunk. -1UL is a // wildcard. for (r = lines; r; r = r->next) if ((r->start == -1UL || r->start < (orig_offset + orig_count)) && (r->end == -1UL || r->end >= orig_offset)) { l = 1; break; } if (hunks && !h && !hunks_exclude) return 0; if (hunks && h && hunks_exclude) return 0; if (lines && !l && !lines_exclude) return 0; if (lines && l && lines_exclude) return 0; return 1; }
int main (int argc, char *argv[]) { DIRST dir; char *directory, *filename, *slash; if (argc == 1 || streq (argv [1], "/?")) { puts ("dos2unix - part of the iMatix RealiBase Gaggle"); puts ("Strip CR characters from text file.\n"); puts ("syntax: dos2unix [/?] [filename]"); puts (" /? - show help on command"); puts (" filename - file to expand"); exit (0); } filename = argv [1]; if (strchr (filename, '*') || strchr (filename, '?')) { directory = mem_strdup (filename); slash = strrchr (directory, '\\'); if (!slash) slash = strrchr (directory, '/'); if (!slash) directory = "."; else { *slash = '\0'; filename = slash + 1; } if (open_dir (&dir, directory)) do { if ((dir.file_attrs & ATTR_HIDDEN) == 0 && (dir.file_attrs & ATTR_SUBDIR) == 0) if (file_matches (dir.file_name, filename)) convert (directory, dir.file_name); } while (read_dir (&dir)); close_dir (&dir); } else convert (".", filename); exit (0); }
static void display_filename (unsigned long linenum, char status, const char *filename, const char *patchname) { if (mode == mode_list && !file_matches ()) /* This is lsdiff --files=... and this file is not to be * listed. */ return; if (print_patchnames) printf ("%s:", patchname); if (numbering) printf ("%lu\t", linenum); if (number_files) printf ("File #%-3lu\t", filecount); if (show_status) printf ("%c ", status); if (prefix_to_add) fputs (prefix_to_add, stdout); puts (stripped (filename, strip_components)); }
TA_RetCode TA_DirectoryAlloc( const char *path, TA_Directory **directory ) { #if defined( USE_WIN32_API ) HANDLE handle; WIN32_FIND_DATA data; DWORD win32Error; #endif #if defined( USE_OSLAYER ) DIRST dirHandle; const char *filePattern; char *basePath; #endif unsigned pathLength; int findNextRetCode; TA_Directory *dir; TA_String *string; TA_RetCode retCode; TA_SystemGlobal *global; const char *entryName; unsigned int entryIsDirectory; *directory = NULL; if( (path == NULL) || (directory == NULL) ) return TA_BAD_PARAM; retCode = TA_GetGlobal( &TA_SystemGlobalControl, (void **)&global ); if( retCode != TA_SUCCESS ) return retCode; dir = (TA_Directory *)TA_Malloc( sizeof( TA_Directory ) ); if( dir == NULL ) return TA_ALLOC_ERR; dir->nbFile = 0; dir->nbDirectory = 0; dir->listOfFile = TA_ListAlloc(); dir->listOfDirectory = TA_ListAlloc(); if( (dir->listOfFile == NULL) || (dir->listOfDirectory == NULL) ) { TA_DirectoryFree( dir ); return TA_ALLOC_ERR; } /* Verify that the path is valid. */ pathLength = strlen( path ); if( (pathLength == 0) || (pathLength >= MAX_PATH) ) { TA_DirectoryFree( dir ); return TA_BAD_PARAM; } /* Now get the directory from the operating system. */ #if defined( USE_WIN32_API ) handle = FindFirstFile( path, &data ); if( handle == INVALID_HANDLE_VALUE ) { win32Error = GetLastError(); global->lastError = win32Error; if( (win32Error != ERROR_FILE_NOT_FOUND) && (win32Error != ERROR_PATH_NOT_FOUND) ) { TA_DirectoryFree( dir ); return TA_ACCESS_FAILED; } /* No files or directory... but still have to pass the result * to the caller. */ *directory = dir; return TA_SUCCESS; } entryName = data.cFileName; entryIsDirectory = data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; #endif #if defined( USE_OSLAYER ) /* Split the path into the basePath and the filePattern. */ basePath = TA_Malloc( pathLength+1 ); memcpy( basePath, path, pathLength+1 ); filePattern = split_path_and_file( basePath ); if( !filePattern ) { /* With no filePattern, no file can be found... * so return an empty directory to the caller. */ *directory = dir; TA_Free( basePath ); return TA_SUCCESS; } /* Look for last separetor. */ if( !open_dir(&dirHandle, basePath ) ) { /* Errors, or no files or no directory... but * still have to pass the result to the caller. */ TA_Free( basePath ); *directory = dir; return TA_SUCCESS; } entryName = dirHandle.file_name; entryIsDirectory = dirHandle.file_attrs & ATTR_SUBDIR; #endif do { #if defined( USE_OSLAYER ) if( file_matches( entryName, filePattern ) ) { #endif if( entryIsDirectory ) { if( entryName[0] != '.' ) { string = TA_StringAlloc( global->dirnameCache, entryName ); if( string == NULL ) { #if defined( USE_OSLAYER ) close_dir(&dirHandle); TA_Free( basePath ); #endif TA_DirectoryFree( dir ); return TA_ALLOC_ERR; } retCode = TA_ListAddTail( dir->listOfDirectory, (void *)string ); if( retCode != TA_SUCCESS ) { #if defined( USE_OSLAYER ) close_dir(&dirHandle); TA_Free( basePath ); #endif TA_DirectoryFree( dir ); return retCode; } dir->nbDirectory++; } } else { string = TA_StringAlloc( global->filenameCache, entryName ); if( string == NULL ) { #if defined( USE_OSLAYER ) close_dir(&dirHandle); TA_Free( basePath ); #endif TA_DirectoryFree( dir ); return TA_ALLOC_ERR; } retCode = TA_ListAddTail( dir->listOfFile, (void *)string ); if( retCode != TA_SUCCESS ) { #if defined( USE_OSLAYER ) close_dir(&dirHandle); TA_Free( basePath ); #endif TA_DirectoryFree( dir ); return retCode; } dir->nbFile++; } #if defined( USE_OSLAYER ) } #endif #if defined( USE_WIN32_API ) findNextRetCode = FindNextFile( handle, &data ); entryName = data.cFileName; entryIsDirectory = data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; #endif #if defined( USE_OSLAYER ) findNextRetCode = read_dir( &dirHandle ); entryName = dirHandle.file_name; entryIsDirectory = dirHandle.file_attrs & ATTR_SUBDIR; #endif } while( findNextRetCode == TRUE ); #if defined( USE_OSLAYER ) TA_Free( basePath ); if( !close_dir(&dirHandle) ) { TA_DirectoryFree( dir ); return TA_INTERNAL_ERROR(11); } #endif #if defined( USE_WIN32_API ) if( FindClose( handle ) != TRUE ) { global->lastError = GetLastError(); TA_DirectoryFree( dir ); return TA_INTERNAL_ERROR(12); } #endif /* Pass the result to the caller. */ *directory = dir; return TA_SUCCESS; }
int dwarf_getscopevar (Dwarf_Die *scopes, int nscopes, const char *name, int skip_shadows, const char *match_file, int match_lineno, int match_linecol, Dwarf_Die *result) { /* Match against the given file name. */ size_t match_file_len = match_file == NULL ? 0 : strlen (match_file); bool lastfile_matches = false; const char *lastfile = NULL; inline bool file_matches (Dwarf_Files *files, size_t idx) { if (idx >= files->nfiles) return false; const char *file = files->info[idx].name; if (file != lastfile) { size_t len = strlen (file); lastfile_matches = (len >= match_file_len && !memcmp (match_file, file, match_file_len) && (len == match_file_len || file[len - match_file_len - 1] == '/')); } return lastfile_matches; } /* Start with the innermost scope and move out. */ for (int out = 0; out < nscopes; ++out) if (INTUSE(dwarf_haschildren) (&scopes[out])) { if (INTUSE(dwarf_child) (&scopes[out], result) != 0) return -1; do { switch (INTUSE(dwarf_tag) (result)) { case DW_TAG_variable: case DW_TAG_formal_parameter: break; default: continue; } /* Only get here for a variable or parameter. Check the name. */ const char *diename = INTUSE(dwarf_diename) (result); if (diename != NULL && !strcmp (name, diename)) { /* We have a matching name. */ if (skip_shadows > 0) { /* Punt this scope for the one it shadows. */ --skip_shadows; break; } if (match_file != NULL) { /* Check its decl_file. */ Dwarf_Word i; Dwarf_Files *files; if (getattr (result, DW_AT_decl_file, &i) != 0 || getfiles (&scopes[out], &files) != 0) break; if (!file_matches (files, i)) break; if (match_lineno > 0 && (getattr (result, DW_AT_decl_line, &i) != 0 || (int) i != match_lineno)) break; if (match_linecol > 0 && (getattr (result, DW_AT_decl_column, &i) != 0 || (int) i != match_linecol)) break; } /* We have a winner! */ return out; } } while (INTUSE(dwarf_siblingof) (result, result) == 0); } return -2; }