From cc9b99b34cb0c73c469c68746eb44243ca71a590 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 8 Mar 2025 11:09:31 +0100 Subject: [PATCH] Fix whatever ther fuck cursor cooked up IDIOT --- main.go | 66 +++++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 54 deletions(-) diff --git a/main.go b/main.go index cde8069..9d04f05 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "log" "os" "path/filepath" - "sort" "strings" "sync" "sync/atomic" @@ -29,6 +28,12 @@ func init() { log.Lmicroseconds|log.Lshortfile) } +type ExtData struct { + ext string + binaryCount int + textCount int +} + func main() { flag.Parse() dir := flag.Arg(0) @@ -58,16 +63,12 @@ func main() { scanner := bufio.NewScanner(f) if scanner.Scan() { ext := filepath.Ext(file) - key := ext + extData, _ := extensionTypeCount.LoadOrStore(ext, &ExtData{ext: ext, binaryCount: 0, textCount: 0}) if IsStringBinary(scanner.Text()) { - key += " (binary)" - count, _ := extensionTypeCount.LoadOrStore(key, 0) - extensionTypeCount.Store(key, count.(int)+1) + extData.(*ExtData).binaryCount++ //log.Printf("Binary file: %s (%s)", file, ext) } else { - key += " (text)" - count, _ := extensionTypeCount.LoadOrStore(key, 0) - extensionTypeCount.Store(key, count.(int)+1) + extData.(*ExtData).textCount++ //log.Printf("Text file: %s (%s)", file, ext) } } else if err := scanner.Err(); err != nil { @@ -79,56 +80,13 @@ func main() { } wg.Wait() - // Create a map to store raw extension names and their binary vs text counts - extensionBinaryTextCount := make(map[string][2]int) - - // Collect all raw extensions and their counts extensionTypeCount.Range(func(key, value any) bool { - keyStr := key.(string) - count := value.(int) - - // Check if it's a text file (has " (text)" suffix) - if strings.HasSuffix(keyStr, " (text)") { - baseExt := strings.TrimSuffix(keyStr, " (text)") - counts, exists := extensionBinaryTextCount[baseExt] - if !exists { - counts = [2]int{0, 0} - } - counts[1] = count // index 1 for text count - extensionBinaryTextCount[baseExt] = counts - } else { - // Binary file - counts, exists := extensionBinaryTextCount[keyStr] - if !exists { - counts = [2]int{0, 0} - } - counts[0] = count // index 0 for binary count - extensionBinaryTextCount[keyStr] = counts + extData := value.(*ExtData) + if extData.binaryCount > extData.textCount*2 { + log.Printf("Extension: %s, Binary Count: %d, Text Count: %d", extData.ext, extData.binaryCount, extData.textCount) } return true }) - - // Get all extensions that have more binary occurrences than text - var binaryDominantExts []string - for ext, counts := range extensionBinaryTextCount { - binaryCount := counts[0] - textCount := counts[1] - - if binaryCount > textCount { - binaryDominantExts = append(binaryDominantExts, ext) - } - } - - // Sort the extensions - sort.Strings(binaryDominantExts) - - // Print only the extensions that are more likely to be binary - fmt.Println("Extensions that are predominantly binary:") - for _, ext := range binaryDominantExts { - counts := extensionBinaryTextCount[ext] - fmt.Printf("Extension: %s, Binary Count: %d, Text Count: %d\n", - ext, counts[0], counts[1]) - } } func IsStringBinary(s string) bool {