<commit_before>#!/usr/bin/perl

# Sets up the required environment variables from the mexopts.bat file (converting the appropriate ones to cygwin format)
# Usage:
#   eval `mex_cygwin_env.pl`
# or 
#   eval `mex_cygwin_env.pl /cygdrive/c/Users/russt/AppData/Roaming/MathWorks/MATLAB/R2013b/mexopts.bat`
#
# todo: handle MATLAB >= R2014a

if (@ARGV > 0) {
    $MEXOPTS_FILE = $ARGV[0];
} else {
    # recover it automatically
    $MEX = `which mex.bat`; chomp($MEX);
    $MEX = `cygpath -w "$MEX"`;  chomp($MEX); $MEX = "cmd.exe /c \"$MEX\"";  # seems to be more robust (otherwise, doesn't work in .bashrc during ssh login)
    $MEXOPTS_FILE = `$MEX -v | grep "Options file"`;
    $MEXOPTS_FILE =~ s/[^=]*=\s*//; chomp($MEXOPTS_FILE);
    #print "$MEXOPTS_FILE\n";
    die "Can't find your mex options file. Make sure mex.bat is in your path (MEX = $MEX).  MATLAB >= R2014a is not supported by this script yet.\n" if ($MEXOPTS_FILE eq "");
}

open(MEXOPTS,$MEXOPTS_FILE);

while (<MEXOPTS>) {
    chomp;
    if (m/^set/) {
	s/^set\s*//g;                   # zap set from start of line
	s/%([^%]+)%/\$\1/g;             # replace %VAR% with $VAR
	($var,$val) = split /=/;        
	$val =~ s/\"/\\\"/g;            # " -> \"
	$val = `echo "$val"`;           # use the shell to evaluate environment variables in the string
	$val =~ s/[^a-zA-Z0-9\\\/ \(\).:;-]//g;  # only let these characters through (had some issue with special characters)
	$ENV{$var} = "$val";            # set the environment variable (only for this process and children) for future references to that var
#	system("echo $var = \$$var\n");
    }
}

@vars_to_export_with_cygpath = ('PATH');
@vars_to_export_with_original_path = ('INCLUDE','LIB');
foreach $var (@vars_to_export_with_cygpath) {
    $val = `cygpath \"$ENV{$var}\"`;
    chomp $val;
    $val =~ s/;/:/g;
    print "export $var=\"$val\"\n";
}
foreach $var (@vars_to_export_with_original_path) {
    print "export $var=\"$ENV{$var}\"\n";
}

close(MEXOPTS)
<commit_msg>back to simpler mex invocation<commit_after>#!/usr/bin/perl

# Sets up the required environment variables from the mexopts.bat file (converting the appropriate ones to cygwin format)
# Usage:
#   eval `mex_cygwin_env.pl`
# or 
#   eval `mex_cygwin_env.pl /cygdrive/c/Users/russt/AppData/Roaming/MathWorks/MATLAB/R2013b/mexopts.bat`
#
# todo: handle MATLAB >= R2014a

if (@ARGV > 0) {
    $MEXOPTS_FILE = $ARGV[0];
} else {
    # recover it automatically
    $MEXOPTS_FILE = `mex.bat -v | grep "Options file"`;
    $MEXOPTS_FILE =~ s/[^=]*=\s*//; chomp($MEXOPTS_FILE);
    #print "$MEXOPTS_FILE\n";
    die "Can't find your mex options file. Make sure mex.bat is in your path (MEX = $MEX).  MATLAB >= R2014a is not supported by this script yet.\n" if ($MEXOPTS_FILE eq "");
}

open(MEXOPTS,$MEXOPTS_FILE);

while (<MEXOPTS>) {
    chomp;
    if (m/^set/) {
	s/^set\s*//g;                   # zap set from start of line
	s/%([^%]+)%/\$\1/g;             # replace %VAR% with $VAR
	($var,$val) = split /=/;        
	$val =~ s/\"/\\\"/g;            # " -> \"
	$val = `echo "$val"`;           # use the shell to evaluate environment variables in the string
	$val =~ s/[^a-zA-Z0-9\\\/ \(\).:;-]//g;  # only let these characters through (had some issue with special characters)
	$ENV{$var} = "$val";            # set the environment variable (only for this process and children) for future references to that var
#	system("echo $var = \$$var\n");
    }
}

@vars_to_export_with_cygpath = ('PATH');
@vars_to_export_with_original_path = ('INCLUDE','LIB');
foreach $var (@vars_to_export_with_cygpath) {
    $val = `cygpath \"$ENV{$var}\"`;
    chomp $val;
    $val =~ s/;/:/g;
    print "export $var=\"$val\"\n";
}
foreach $var (@vars_to_export_with_original_path) {
    print "export $var=\"$ENV{$var}\"\n";
}

close(MEXOPTS)

{'fraction_non_alphanumeric': 0.18198529411764705, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 3.047821466524973, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1841036', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1457, 'n_words': 372}