<commit_before>package cddb

import (
	"fmt"
	"log"
	"strconv"
)

type QueryCmd struct {
	discID       string
	trackCount   int
	offsets      []int
	totalSeconds int
	language     string
	country      string
}

type ReadCmd struct {
	category string
	discID   string
	language string
	country  string
}

var syntaxError error = fmt.Errorf("%v", cddbStatus(500, "Command syntax error", true))

func logSyntaxError(cmdArray []string) {
	log.Println("syntax error:")
	log.Println(cmdArray)
}

func createQueryCmd(cmdArray []string) (queryCmd QueryCmd, err error) {
	if len(cmdArray) < 4 {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	queryCmd.discID = cmdArray[0]
	queryCmd.trackCount, err = strconv.Atoi(cmdArray[1])
	if err != nil {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	if len(cmdArray[2:len(cmdArray)-1]) != queryCmd.trackCount {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	for i := 0; i < queryCmd.trackCount; i++ {
		offset, err := strconv.Atoi(cmdArray[i+2])
		if err != nil {
			logSyntaxError(cmdArray)
			return QueryCmd{}, syntaxError
		}
		queryCmd.offsets = append(queryCmd.offsets, offset)
	}

	if queryCmd.offsets[0] == 0 {
		for i := range queryCmd.offsets {
			queryCmd.offsets[i] += 150
		}
	}

	queryCmd.totalSeconds, err = strconv.Atoi(cmdArray[len(cmdArray)-1])
	if err != nil {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	queryCmd.offsets = append(queryCmd.offsets, queryCmd.totalSeconds*75)
	queryCmd.trackCount += 1

	return queryCmd, nil
}

func createReadCmd(cmdArray []string) (readCmd ReadCmd, err error) {
	if len(cmdArray) != 2 {
		logSyntaxError(cmdArray)
		return ReadCmd{}, syntaxError
	}

	readCmd.category = cmdArray[0]
	readCmd.discID = cmdArray[1]

	return readCmd, nil
}<commit_msg>Add leadout before fixing offsets<commit_after>package cddb

import (
	"fmt"
	"log"
	"strconv"
)

type QueryCmd struct {
	discID       string
	trackCount   int
	offsets      []int
	totalSeconds int
	language     string
	country      string
}

type ReadCmd struct {
	category string
	discID   string
	language string
	country  string
}

var syntaxError error = fmt.Errorf("%v", cddbStatus(500, "Command syntax error", true))

func logSyntaxError(cmdArray []string) {
	log.Println("syntax error:")
	log.Println(cmdArray)
}

func createQueryCmd(cmdArray []string) (queryCmd QueryCmd, err error) {
	if len(cmdArray) < 4 {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	queryCmd.discID = cmdArray[0]
	queryCmd.trackCount, err = strconv.Atoi(cmdArray[1])
	if err != nil {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	if len(cmdArray[2:len(cmdArray)-1]) != queryCmd.trackCount {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}

	for i := 0; i < queryCmd.trackCount; i++ {
		offset, err := strconv.Atoi(cmdArray[i+2])
		if err != nil {
			logSyntaxError(cmdArray)
			return QueryCmd{}, syntaxError
		}
		queryCmd.offsets = append(queryCmd.offsets, offset)
	}
	
	queryCmd.totalSeconds, err = strconv.Atoi(cmdArray[len(cmdArray)-1])
	if err != nil {
		logSyntaxError(cmdArray)
		return QueryCmd{}, syntaxError
	}
	
	queryCmd.offsets = append(queryCmd.offsets, queryCmd.totalSeconds*75)

	if queryCmd.offsets[0] == 0 {
		for i := range queryCmd.offsets {
			queryCmd.offsets[i] += 150
		}
	}

	return queryCmd, nil
}

func createReadCmd(cmdArray []string) (readCmd ReadCmd, err error) {
	if len(cmdArray) != 2 {
		logSyntaxError(cmdArray)
		return ReadCmd{}, syntaxError
	}

	readCmd.category = cmdArray[0]
	readCmd.discID = cmdArray[1]

	return readCmd, nil
}
{'fraction_non_alphanumeric': 0.11890243902439024, 'fraction_numerical': 0.011917960088691795, 'mean_word_length': 4.276315789473684, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1251096', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1273, 'n_words': 296}