<commit_before>/* **************************************************************** *
 *                                                                  *
 *  APRX -- 2nd generation APRS iGate and digi with                 *
 *          minimal requirement of esoteric facilities or           *
 *          libraries of any kind beyond UNIX system libc.          *
 *                                                                  *
 * (c) <NAME> - OH2MQK,  2007-2014                            *
 *                                                                  *
 * **************************************************************** */

#include "aprx.h"

#ifndef DISABLE_IGATE
const char *aprsis_login;
#endif


char *config_SKIPSPACE(char *Y) {
	assert(Y != NULL);
	while (*Y == ' ' || *Y == '\t')
		++Y;
	return Y;
}

// return 0 for failures, 1 for OK.
int validate_callsign_input(char *callsign, int strict) {
	int i = strlen(callsign);
	char *p = callsign;
	char c = 0;
	int seen_minus = 0;
	int ssid = 0;

	for ( ; *p ; ++p ) {
		c = *p;
		if ('a' <= c && c <= 'z') {
			// Presuming ASCII
			c -= ('a'-'A');
			*p = c; // Side-effect: translates the callsign to uppercase
		}
		if (!seen_minus && c == '-') {
			if (p == callsign || p[1] == 0)
				return 0; // Hyphen is at beginning or at end!
			if ((p - callsign) > 6)
				return 0; // Hyphen too far!  Max 6 characters preceding it.
			seen_minus = 1;
			continue;
		} else if (seen_minus && c == '-') {
			return 0; // Seen a hyphen again!
		}

		// The "SSID" value can be alphanumeric here!

		if (!seen_minus) {
			// Callsign prefix
			if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) {
				// Valid character!
			} else {
				return 0; // Invalid characters in callsign part
			}
		} else {
			// SSID tail
			if (strict) {
				if ('0' <= c && c <= '9') {
					// Valid character!
					ssid = ssid * 10 + c - '0';
					if (ssid > 15) { // SSID value range: 0 .. 15
						return 0;
					}
				} else {
					return 0; // Invalid characters in SSID part
				}
			} else { // non-strict
				if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) {
					// Valid character!
				} else {
					return 0; // Invalid characters in SSID part
				}
			}
		}
	}
	if (i > 3 && (callsign[i - 1] == '0' && callsign[i - 2] == '-')) {
		callsign[i - 2] = 0;
		/* If tailed with "-0" SSID, chop it off.. */
	}
	return 1;
}

/* SKIPTEXT:
 *
 *  Detect "/' -> scan until matching double quote
 *    Process \-escapes on string: \xFD, \n, \", \'
 *  Detect non-eol, non-space(tab): scan until eol, or white-space
 *    No \-escapes
 *
 *  Will thus stop when found non-quoted space/tab, or
 *  end of line/string.
 */

char *config_SKIPTEXT(char *Y, int *lenp) {
	char *O;
	char endc;
	int  len;

	assert(Y != NULL);

	O = Y;
	endc = *Y;
	len = 0;

	if (*Y == '"' || *Y == '\'') {
		++Y;
		while (*Y && *Y != endc) {
			if (*Y == '\\') {<commit_msg>Raise config syntax error for N0CALL/NOCALL<commit_after>/* **************************************************************** *
 *                                                                  *
 *  APRX -- 2nd generation APRS iGate and digi with                 *
 *          minimal requirement of esoteric facilities or           *
 *          libraries of any kind beyond UNIX system libc.          *
 *                                                                  *
 * (c) <NAME> - OH2MQK,  2007-2014                            *
 *                                                                  *
 * **************************************************************** */

#include "aprx.h"

#ifndef DISABLE_IGATE
const char *aprsis_login;
#endif


char *config_SKIPSPACE(char *Y) {
	assert(Y != NULL);
	while (*Y == ' ' || *Y == '\t')
		++Y;
	return Y;
}

// Validate the callsign configured for APRX
// Ensure that it meets the requirements for an APRS callsign
// and if it is also a valid AX.25 callsign if strict is true.
//
// return 0 for failures, 1 for OK.
int validate_callsign_input(char *callsign, int strict) {
	int i = strlen(callsign);
	char *p = callsign;
	char c = 0;
	int seen_minus = 0;
	int ssid = 0;

	for ( ; *p ; ++p ) {
		c = *p;
		if ('a' <= c && c <= 'z') {
			// Presuming ASCII
			c -= ('a'-'A');
			*p = c; // Side-effect: translates the callsign to uppercase
		}
		if (!seen_minus && c == '-') {
			if (p == callsign || p[1] == 0)
				return 0; // Hyphen is at beginning or at end!
			if ((p - callsign) > 6)
				return 0; // Hyphen too far!  Max 6 characters preceding it.
			seen_minus = 1;
			continue;
		} else if (seen_minus && c == '-') {
			return 0; // Seen a hyphen again!
		}

		// The "SSID" value can be alphanumeric here!

		if (!seen_minus) {
			// Callsign prefix
			if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) {
				// Valid character!
			} else {
				return 0; // Invalid characters in callsign part
			}
		} else {
			// SSID tail
			if (strict) {
				if ('0' <= c && c <= '9') {
					// Valid character!
					ssid = ssid * 10 + c - '0';
					if (ssid > 15) { // SSID value range: 0 .. 15
						return 0;
					}
				} else {
					return 0; // Invalid characters in SSID part
				}
			} else { // non-strict
				if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) {
					// Valid character!
				} else {
					return 0; // Invalid characters in SSID part
				}
			}
		}
	}
	if (i > 3 && (callsign[i - 1] == '0' && callsign[i - 2] == '-')) {
		callsign[i - 2] = 0;
		/* If tailed with "-0" SSID, chop it off.. */
	}

	// Check for invalid default callsigns
	if (strncmp(callsign, "N0CALL", 6) == 0) {
		return 0;
	}
	if (strncmp(callsign, "NOCALL", 6) == 0) {
		return 0;
	}

	return 1;
}

/* SKIPTEXT:
 *
 *  Detect "/' -> scan until matching double quote
 *    Process \-escapes on string: \xFD, \n, \", \'
 *  Detect non-eol, non-space(tab): scan until eol, or white-space
 *    No \-escapes
 *
 *  Will thus stop when found non-quoted space/tab, or
 *  end of line/string.
 */

char *config_SKIPTEXT(char *Y, int *lenp) {
	char *O;
	char endc;
	int  len;

	assert(Y != NULL);

	O = Y;
	endc = *Y;
	len = 0;

	if (*Y == '"' || *Y == '\'') {
		++Y;
		while (*Y && *Y != endc) {
			if (*Y == '\\') {
{'fraction_non_alphanumeric': 0.20499108734402852, 'fraction_numerical': 0.017825311942959002, 'mean_word_length': 1.768954688200987, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4238164', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2095, 'n_words': 673}