<commit_before>#!/usr/bin/perl
#
# version.pl
#
# Parse the NASM version file and produce appropriate macros
#
# The NASM version number is assumed to consist of:
#
# <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
#
# ... where <tail> is not necessarily numeric, but if it is of the form
# -<digits> it is assumed to be a snapshot release.
#
# This defines the following macros:
#
# version.h:
# NASM_MAJOR_VER
# NASM_MINOR_VER
# NASM_SUBMINOR_VER	-- this is zero if no subminor
# NASM_PATCHLEVEL_VER	-- this is zero is no patchlevel
# NASM_SNAPSHOT		-- if snapshot
# NASM_VERSION_ID       -- version number encoded
# NASM_VER		-- whole version number as a string
#
# version.mac:
# __NASM_MAJOR__
# __NASM_MINOR__
# __NASM_SUBMINOR__
# __NASM_PATCHLEVEL__
# __NASM_SNAPSHOT__
# __NASM_VERSION_ID__
# __NASM_VER__
#

($what) = @ARGV;

$line = <STDIN>;
chomp $line;

undef $man, $min, $smin, $plvl, $tail;
$is_rc = 0;

if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
    $maj  = $1;
    $min  = $2;
    $tail = $3;
    if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
	$smin = $1;
	$tail = $2;
    }
    if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
	$plvl = $2;
	$tail = $3;
    } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
	$is_rc = 1;
	$plvl = $1;
	$tail = $2;
    }
} else {
    die "$0: Invalid input format\n";
}

if ($tail =~ /^\-([0-9]+)/) {
    $snapshot = $1;
} else {
    undef $snapshot;
}

$nmaj = $maj+0;   $nmin = $min+0;
$nsmin = $smin+0; $nplvl = $plvl+0;

if ($is_rc) {
    $nplvl += 90;
    if ($nsmin > 0) {
	$nsmin--;
    } else {
	$nsmin = 99;
	if ($nmin > 0) {
	    $nmin--;
	} else {
	    $nmin = 99;
	    $nmaj--;
	}
    }
}

$nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;

$mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
$mangled_ver .= sprintf(".%02d", $nsmin) if ($nsmin || $nplvl);
$mangled_ver .= '.'.$nplvl if ($nplvl != 0);
($mtail = $tail) =~ tr/-/./;
$mangled_ver .= $mtail;<commit_msg>For snapshot releases, expand out the mangled version numbers.<commit_after>#!/usr/bin/perl
#
# version.pl
#
# Parse the NASM version file and produce appropriate macros
#
# The NASM version number is assumed to consist of:
#
# <major>.<minor>[.<subminor>][pl<patchlevel>]]<tail>
#
# ... where <tail> is not necessarily numeric, but if it is of the form
# -<digits> it is assumed to be a snapshot release.
#
# This defines the following macros:
#
# version.h:
# NASM_MAJOR_VER
# NASM_MINOR_VER
# NASM_SUBMINOR_VER	-- this is zero if no subminor
# NASM_PATCHLEVEL_VER	-- this is zero is no patchlevel
# NASM_SNAPSHOT		-- if snapshot
# NASM_VERSION_ID       -- version number encoded
# NASM_VER		-- whole version number as a string
#
# version.mac:
# __NASM_MAJOR__
# __NASM_MINOR__
# __NASM_SUBMINOR__
# __NASM_PATCHLEVEL__
# __NASM_SNAPSHOT__
# __NASM_VERSION_ID__
# __NASM_VER__
#

($what) = @ARGV;

$line = <STDIN>;
chomp $line;

undef $man, $min, $smin, $plvl, $tail;
$is_rc = 0;

if ( $line =~ /^([0-9]+)\.([0-9]+)(.*)$/ ) {
    $maj  = $1;
    $min  = $2;
    $tail = $3;
    if ( $tail =~ /^\.([0-9]+)(.*)$/ ) {
	$smin = $1;
	$tail = $2;
    }
    if ( $tail =~ /^(pl|\.)([0-9]+)(.*)$/ ) {
	$plvl = $2;
	$tail = $3;
    } elsif ( $tail =~ /^rc([0-9]+)(.*)$/ ) {
	$is_rc = 1;
	$plvl = $1;
	$tail = $2;
    }
} else {
    die "$0: Invalid input format\n";
}

if ($tail =~ /^\-([0-9]+)/) {
    $snapshot = $1;
} else {
    undef $snapshot;
}

$nmaj = $maj+0;   $nmin = $min+0;
$nsmin = $smin+0; $nplvl = $plvl+0;

if ($is_rc) {
    $nplvl += 90;
    if ($nsmin > 0) {
	$nsmin--;
    } else {
	$nsmin = 99;
	if ($nmin > 0) {
	    $nmin--;
	} else {
	    $nmin = 99;
	    $nmaj--;
	}
    }
}

$nasm_id = ($nmaj << 24)+($nmin << 16)+($nsmin << 8)+$nplvl;

$mangled_ver = sprintf("%d.%02d", $nmaj, $nmin);
if ($nsmin || $nplvl || defined($snapshot)) {
    $mangled_ver .= sprintf(".%02d", $nsmin);
    if ($nplvl || defined($snapshot)) {
	$mangled_ver .= '.'.$nplvl;
    }
}
($mtail = $tail) =~ tr/-/./;
$mangled_ver .= $mtail;
{'fraction_non_alphanumeric': 0.22216586355566828, 'fraction_numerical': 0.023586101952827798, 'mean_word_length': 2.94005994005994, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 23, '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': '2295259', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1792, 'n_words': 406}