sorted extracting commands trying to sort extra newline after each cmd

This commit is contained in:
specCon18 2025-03-26 18:21:48 -04:00
parent eb29d1560a
commit bfc0d43273
3 changed files with 108055 additions and 35253 deletions

22
main.go
View file

@ -35,20 +35,25 @@ func readFileLBL(file_path string) {
}
func extractCommand(line string) (string, string) {
re := regexp.MustCompile(`^(.*?)\s?\*(.*)`)
checksumRe := regexp.MustCompile(`^(.*?)\s?\*(.*)`)
commentRe := regexp.MustCompile(`^(.*?)\s?;(.*)`)
// Find matches
matchChecksum := re.FindStringSubmatch(line)
matchChecksum := checksumRe.FindStringSubmatch(line)
matchComment := commentRe.FindStringSubmatch(line)
if len(matchChecksum) > 0 {
// Return the two segments as separate values
// Check if matchChecksum has the required elements
if len(matchChecksum) > 2 {
return matchChecksum[1], matchChecksum[2]
} else if len(matchComment) > 2 {
return matchComment[1], matchComment[2]
} else {
return "", "" // Return empty strings if no match
// Return empty strings if no match
return line, ""
}
}
//TODO: P:0 convert to extractLineNumber returning like extractCommand does
func extractLineNumber(line string) (string, string) {
// Match line that starts with "N" followed by digits and an optional space
re := regexp.MustCompile(`^N(\d+)\s?(.*)`)
@ -68,7 +73,8 @@ func parseGcodeLine(line string){
//TODO: P:0 convert string to struct
if strings.HasPrefix(line,"N"){
n,l := extractLineNumber(line)
fmt.Println(n)
n = n
//fmt.Println(n)
parseGcodeLine(l)
//TODO: P:1 Write lookup table for G/M codes to get which params are required
} else if strings.HasPrefix(line, "G") || strings.HasPrefix(line,"M") {
@ -78,7 +84,7 @@ func parseGcodeLine(line string){
} else if strings.HasPrefix(line,"*"){
fmt.Println("is a checksum")
} else if strings.HasPrefix(line,";"){
fmt.Println("is a comment")
fmt.Sprintf("Comment: %s\n",line)
}
}

143282
out

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
N1116 M486 S0
N1116 M486 S0 *542
M486 A3DBenchy_id_0_copy_0
M486 S-1
M73 P0 R52