<commit_before>package conf

import (
	"V-switch/tools"
	"fmt"
	"log"
	"net"
	"os"
	"strconv"
)

func ConfCheck() {

	ConfigItems := []string{
		"MTU",
		"DEVICENAME",
		"PORT",
		"QUEUE",
		"SWITCHID",
		"TTL",
	}

	OptionalItems := []string{
		"PUBLIC",
		"SEED",
	}

	// everything but 		"PUBLIC" and "SEED",

	for _, c_item := range ConfigItems {

		if !ConfigItemExists(c_item) {
			log.Printf("[CONF][SYNTAX] No %s in configuration. It is mandatory", c_item)
			os.Exit(1)
		}

	}

	// now some checks for syntax

	Mtu, MtuErr := strconv.Atoi(GetConfigItem("MTU"))

	if MtuErr != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of MTU ", GetConfigItem("MTU"))
		os.Exit(1)
	}

	if port, err := strconv.Atoi(GetConfigItem("PORT")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of PORT ", GetConfigItem("PORT"))
		os.Exit(1)
	} else {

		if (port > 65534) || (port < 10) {
			log.Println("[CONF][SYNTAX] Unacceptable value of PORT ", GetConfigItem("PORT"))
			os.Exit(1)
		}
	}

	if queue, err := strconv.Atoi(GetConfigItem("QUEUE")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of QUEUE ", GetConfigItem("QUEUE"))
		os.Exit(1)
	} else {

		if (queue > 2048) || (queue < 16) {
			log.Println("[CONF][SYNTAX] Unacceptable value of QUEUE ", GetConfigItem("QUEUE"))
			os.Exit(1)
		}
	}

	if ttl, err := strconv.Atoi(GetConfigItem("TTL")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of TTL ", GetConfigItem("TTL"))
		os.Exit(1)
	} else {

		if (ttl > 1000) || (ttl < 30) {
			log.Println("[CONF][SYNTAX] Unacceptable value of TTL ", GetConfigItem("TTL"))
			os.Exit(1)
		}
	}
<commit_msg>Config syntax check improved<commit_after>package conf

import (
	"V-switch/tools"
	"fmt"
	"log"
	"net"
	"os"
	"strconv"
)

func ConfCheck() {

	ConfigItems := []string{
		"MTU",
		"DEVICENAME",
		"PORT",
		"QUEUE",
		"SWITCHID",
		"TTL",
		"DEBUG",
		"DEVICEADDR",
		"DEVICEMASK",
	}

	OptionalItems := []string{
		"PUBLIC",
		"SEED",
	}

	// everything but 		"PUBLIC" and "SEED",

	for _, c_item := range ConfigItems {

		if !ConfigItemExists(c_item) {
			log.Printf("[CONF][SYNTAX] No %s in configuration. It is mandatory", c_item)
			os.Exit(1)
		}

	}

	// now some checks for syntax

	Mtu, MtuErr := strconv.Atoi(GetConfigItem("MTU"))

	if MtuErr != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of MTU ", GetConfigItem("MTU"))
		os.Exit(1)
	}

	if port, err := strconv.Atoi(GetConfigItem("PORT")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of PORT ", GetConfigItem("PORT"))
		os.Exit(1)
	} else {

		if (port > 65534) || (port < 10) {
			log.Println("[CONF][SYNTAX] Unacceptable value of PORT ", GetConfigItem("PORT"))
			os.Exit(1)
		}
	}

	if queue, err := strconv.Atoi(GetConfigItem("QUEUE")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of QUEUE ", GetConfigItem("QUEUE"))
		os.Exit(1)
	} else {

		if (queue > 2048) || (queue < 16) {
			log.Println("[CONF][SYNTAX] Unacceptable value of QUEUE ", GetConfigItem("QUEUE"))
			os.Exit(1)
		}
	}

	if ttl, err := strconv.Atoi(GetConfigItem("TTL")); err != nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of TTL ", GetConfigItem("TTL"))
		os.Exit(1)
	} else {

		if (ttl > 1000) || (ttl < 30) {
			log.Println("[CONF][SYNTAX] Unacceptable value of TTL ", GetConfigItem("TTL"))
			os.Exit(1)
		}
	}

	if ip := net.ParseIP(GetConfigItem("DEVICEADDR")); ip == nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of DEVICEADDR ", GetConfigItem("DEVICEADDR"))
		os.Exit(1)

	}

	if ip := net.ParseIP(GetConfigItem("DEVICEMASK")); ip == nil {
		log.Println("[CONF][SYNTAX] Unacceptable value of DEVICEMASK ", GetConfigItem("DEVICEMASK"))
		os.Exit(1)

	}

{'fraction_non_alphanumeric': 0.18399784482758622, 'fraction_numerical': 0.015086206896551725, 'mean_word_length': 3.9178807947019867, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7269167', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1469, 'n_words': 310}