<commit_before>package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"

	"github.com/xiegeo/modbusone"

	"github.com/fatih/color"
)

func runClient(c *modbusone.RTUClient) {
	//make these messages stand out with color
	println := color.New(color.FgYellow).PrintlnFunc()
	println(`Send requests by function code, address, and quantity.` +
		` such as "2 0 12" (base 10)`)
	reader := bufio.NewReader(os.Stdin)
	for {
		line, err := reader.ReadString('\n')
		if err != nil {
			println(err)
			continue
		}
		ts := strings.Split(line, " ")
		fc, a, q, err := parseRequest(ts)
		if err != nil {
			println(err)
			continue
		}
		reqs, err := modbusone.MakePDURequestHeaders(fc, a, q, nil)
		if err != nil {
			println(err)
			continue
		}
		n, err := modbusone.DoTransactions(c, c.SlaveID, reqs)
		if err != nil {
			println(err, "in request", n+1, "/", len(reqs), reqs[n])
			continue
		}
		println("finished", n, "requests")
	}
}

func parseRequest(ts []string) (fc modbusone.FunctionCode, address, quantity uint16, err error) {
	quantity = 1 //default value
	var n uint64

	if len(ts) == 0 {
		err = fmt.Errorf("function code required")
		return
	}
	n, err = strconv.ParseUint(ts[0], 10, 7)
	if err != nil {
		err = fmt.Errorf("function code %v parse error: %v", ts[0], err)
		return
	}
	fc = modbusone.FunctionCode(n)

	if len(ts) < 2 {
		return
	}
	n, err = strconv.ParseUint(ts[1], 10, 16)
	if err != nil {
		err = fmt.Errorf("address %v parse error: %v", ts[1], err)
		return
	}
	address = uint16(n)

	if len(ts) < 3 {
		return
	}
	n, err = strconv.ParseUint(ts[2], 10, 16)
	if err != nil {
		err = fmt.Errorf("quantity %v parse error: %v", ts[2], err)
		return
	}
	quantity = uint16(n)
	return
}
<commit_msg>remove end of line character<commit_after>package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"

	"github.com/xiegeo/modbusone"

	"github.com/fatih/color"
)

func runClient(c *modbusone.RTUClient) {
	//make these messages stand out with color
	println := color.New(color.FgYellow).PrintlnFunc()
	println(`Send requests by function code, address, and quantity.` +
		` such as "2 0 12" (base 10)`)
	reader := bufio.NewReader(os.Stdin)
	for {
		line, err := reader.ReadString('\n')
		line = strings.Trim(line, " \r\n")
		if err != nil {
			println(err)
			continue
		}
		ts := strings.Split(line, " ")
		fc, a, q, err := parseRequest(ts)
		if err != nil {
			println(err)
			continue
		}
		reqs, err := modbusone.MakePDURequestHeaders(fc, a, q, nil)
		if err != nil {
			println(err)
			continue
		}
		n, err := modbusone.DoTransactions(c, c.SlaveID, reqs)
		if err != nil {
			println(err, "in request", n+1, "/", len(reqs), reqs[n])
			continue
		}
		println("finished", n, "requests")
	}
}

func parseRequest(ts []string) (fc modbusone.FunctionCode, address, quantity uint16, err error) {
	quantity = 1 //default value
	var n uint64

	if len(ts) == 0 {
		err = fmt.Errorf("function code required")
		return
	}
	n, err = strconv.ParseUint(ts[0], 10, 7)
	if err != nil {
		err = fmt.Errorf("function code %v parse error: %v", ts[0], err)
		return
	}
	fc = modbusone.FunctionCode(n)

	if len(ts) < 2 {
		return
	}
	n, err = strconv.ParseUint(ts[1], 10, 16)
	if err != nil {
		err = fmt.Errorf("address %v parse error: %v", ts[1], err)
		return
	}
	address = uint16(n)

	if len(ts) < 3 {
		return
	}
	n, err = strconv.ParseUint(ts[2], 10, 16)
	if err != nil {
		err = fmt.Errorf("quantity %v parse error: %v", ts[2], err)
		return
	}
	quantity = uint16(n)
	return
}

{'fraction_non_alphanumeric': 0.1615208690680389, 'fraction_numerical': 0.02058319039451115, 'mean_word_length': 3.3902132998745294, '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': '781559', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1378, 'n_words': 369}