<commit_before>#
# Language module for the wrapper generator for octave 2.0.  Most of these
# functions are called directly from the wrapper generator.
#
# Octave is a little difficult to handle because (like MATLAB) it can only
# define a single C function per mex file.  This means that the C function must
# take an additional argument of which sub-function to call.  We provide octave
# functions which supply the extra argument.
#
# Copyright (c) 1997 <NAME>.  This is distributed under the terms of the 
# perl artistic license (http://language.perl.com/misc/Artistic.html).
#
# Modifications 2007 <NAME> 
# This version contains three local fixes for plplot
# 1) Change _dim function to allow a zero length array (required by plstyl)
# 2) Alter string to std::string for compatibility with gcc3.2 and later
# 3) Add octave version checking - the syntax of print_usage has changed
#    from v2.1 to v2.9. This requires a file octave_version.pl which defines
#    the variable octave_version.
#

package octave;			# Everything should be in this package.

@function_names = ();		# This table translates function names and
				# their assigned IDs.  The extra numerical
				# argument to the mexFunction() indicates
				# which function the user actually wanted to
				# call.

$max_dimensions = 2;		# Maximum number of dimensions in tensors.

*pointer_type_code = *main::pointer_type_code;
				# Copy the definition of pointer_type_code
				# into this module.

#
# arg_pass(\%function_def, $argname)
#
# A C or C++ expression used to pass the argument to another function
# which does not know anything about the type of the argument.  For
# example, in the MATLAB module this function returns an expression for
# the mxArray type for a given argument.
#
sub arg_pass {
  my ($faa, $argname) = @_;	# Name the arguments.
  $faa->{args}{$argname}{oct_expr}; # Return the octave expression.
}

#
# arg_declare("arg_name_in_arglist")
# 
# This returns a C/C++ declaration appropriate for the argument passed
# using arg_pass.  For example, in the MATLAB module this function returns
# "mxArray *arg_name_in_arglist".
#
sub arg_declare {
  "const octave_value &$_[0]";
}


#
# declare_const("constant name", "class name", "<type>", "doc str")
#
# Output routines to make a given constant value accessible from the 
# interpreter.
# If "class name" is blank, this is a global constant.
#
sub declare_const {
				# This is not currently supported.
}


#
# error_dimension(\%function_def, $argname)
#
# A C statement (including the final semicolon, if not surrounded by braces)
# which indicates that an error has occured because the dimension of argument
# $argname was wrong.
#
sub error_dimension {
  "{ error(\"dimension mismatch in argument $_[1]\"); return retval; }"
				# Return whatever we've made so far, which
				# is probably an empty list.
}

#
# finish()
#
# Called after all functions have been wrapped, to close the output file and do
# whatever other cleanup is necessary.
#
sub finish {
  print OUTFILE qq[

//
// The main dispatch function.  This function calls the appropriate wrapper
// based on the value of the first argument.
//
DEFUN_DLD($octave_output_file, args, nargout, "See $stub_file for documentation")
{
  int function_id = int(args(0).double_value());
				// Get the function ID.
  switch (function_id)
  {
];
				# Output the beginning of the definition.
  foreach (0 .. @function_names-1) {
    print "  case $_: return $function_names[$_](args, nargout);\n";
  }
				# Dispatch appropriately.
  print "
  default: error(\"Illegal function ID parameter\"); return octave_value();
  }
}

";

  close(OUTFILE);		# Done with this file.
  close(STUBFILE);		# We're also done with the stub file.
}


#
# Begin the definition of a function.  Arguments:
# 1) The %function_def array.
#
sub function_start {

  require "octave_version.pl";
  our $octave_version;

  my $faa = $_[0];		# Access the argument.

  my $retstr;

  my $fname = $faa->{script_name} ||
    ($faa->{class} ? $faa->{class} . "_" : "") . $faa->{name};
				# Get octave's name for the function.
  $faa->{octave_name} = $fname;	# Remember that for later.

#
# Octave doesn't support modify variables, so we add an extra variable to
# the output argument list for each input modify variable.
#
  $retstr = sprintf("octave_value_list _wrap_%s(const octave_value_list &args, int %s)\n",
		    $fname,
		    (@{$faa->{outputs}} + @{$faa->{modifies}}) <= 1 ? '' : 'nargout');
				# Don't specify nargout unless we actually
				# need to test it.

  $retstr .= ("{\n" .
	      "  octave_value_list retval(" . @{$faa->{outputs}} . ", octave_value());\n" . # Where we return stuff.
				# Make sure we have right # of args:
	      "  if (args.length()-1 != " . (scalar(@{$faa->{inputs}}) + 
					     scalar(@{$faa->{modifies}})));
  $retstr .= " ||\n      nargout != " . (scalar(@{$faa->{outputs}}) + scalar(@{$faa->{modifies}}))
    unless (@{$faa->{outputs}}+@{$faa->{modifies}}) <= 1;
				# Permissible not to specify output args
				# if there is only one.
  @ver = split(/\./,$octave_version);
  if ($ver[0] >= 2 && $ver[1] >= 9) {
    $retstr .= (")\n" .
	      "  {\n" .
	      "    print_usage();\n" . # Give an error.
	      "    return retval;\n" . # Quit now.
	      "  }\n\n");
  }
  else {
    $retstr .= (")\n" .
	      "  {\n" .
	      "    print_usage(\"$fname\");\n" . # Give an error.
	      "    return retval;\n" . # Quit now.
	      "  }\n\n");
  }
#<commit_msg>Fix to wrap_octave to get the correct version of print_usage with octave  3.0. Thanks to Rafael for the fix.<commit_after>#
# Language module for the wrapper generator for octave 2.0.  Most of these
# functions are called directly from the wrapper generator.
#
# Octave is a little difficult to handle because (like MATLAB) it can only
# define a single C function per mex file.  This means that the C function must
# take an additional argument of which sub-function to call.  We provide octave
# functions which supply the extra argument.
#
# Copyright (c) 1997 <NAME>.  This is distributed under the terms of the 
# perl artistic license (http://language.perl.com/misc/Artistic.html).
#
# Modifications 2007 <NAME> 
# This version contains three local fixes for plplot
# 1) Change _dim function to allow a zero length array (required by plstyl)
# 2) Alter string to std::string for compatibility with gcc3.2 and later
# 3) Add octave version checking - the syntax of print_usage has changed
#    from v2.1 to v2.9. This requires a file octave_version.pl which defines
#    the variable octave_version.
#
# Modifications 2008 <NAME>
# Change 3) above is adapted for Octave v3.0


package octave;			# Everything should be in this package.

@function_names = ();		# This table translates function names and
				# their assigned IDs.  The extra numerical
				# argument to the mexFunction() indicates
				# which function the user actually wanted to
				# call.

$max_dimensions = 2;		# Maximum number of dimensions in tensors.

*pointer_type_code = *main::pointer_type_code;
				# Copy the definition of pointer_type_code
				# into this module.

#
# arg_pass(\%function_def, $argname)
#
# A C or C++ expression used to pass the argument to another function
# which does not know anything about the type of the argument.  For
# example, in the MATLAB module this function returns an expression for
# the mxArray type for a given argument.
#
sub arg_pass {
  my ($faa, $argname) = @_;	# Name the arguments.
  $faa->{args}{$argname}{oct_expr}; # Return the octave expression.
}

#
# arg_declare("arg_name_in_arglist")
# 
# This returns a C/C++ declaration appropriate for the argument passed
# using arg_pass.  For example, in the MATLAB module this function returns
# "mxArray *arg_name_in_arglist".
#
sub arg_declare {
  "const octave_value &$_[0]";
}


#
# declare_const("constant name", "class name", "<type>", "doc str")
#
# Output routines to make a given constant value accessible from the 
# interpreter.
# If "class name" is blank, this is a global constant.
#
sub declare_const {
				# This is not currently supported.
}


#
# error_dimension(\%function_def, $argname)
#
# A C statement (including the final semicolon, if not surrounded by braces)
# which indicates that an error has occured because the dimension of argument
# $argname was wrong.
#
sub error_dimension {
  "{ error(\"dimension mismatch in argument $_[1]\"); return retval; }"
				# Return whatever we've made so far, which
				# is probably an empty list.
}

#
# finish()
#
# Called after all functions have been wrapped, to close the output file and do
# whatever other cleanup is necessary.
#
sub finish {
  print OUTFILE qq[

//
// The main dispatch function.  This function calls the appropriate wrapper
// based on the value of the first argument.
//
DEFUN_DLD($octave_output_file, args, nargout, "See $stub_file for documentation")
{
  int function_id = int(args(0).double_value());
				// Get the function ID.
  switch (function_id)
  {
];
				# Output the beginning of the definition.
  foreach (0 .. @function_names-1) {
    print "  case $_: return $function_names[$_](args, nargout);\n";
  }
				# Dispatch appropriately.
  print "
  default: error(\"Illegal function ID parameter\"); return octave_value();
  }
}

";

  close(OUTFILE);		# Done with this file.
  close(STUBFILE);		# We're also done with the stub file.
}


#
# Begin the definition of a function.  Arguments:
# 1) The %function_def array.
#
sub function_start {

  require "octave_version.pl";
  our $octave_version;

  my $faa = $_[0];		# Access the argument.

  my $retstr;

  my $fname = $faa->{script_name} ||
    ($faa->{class} ? $faa->{class} . "_" : "") . $faa->{name};
				# Get octave's name for the function.
  $faa->{octave_name} = $fname;	# Remember that for later.

#
# Octave doesn't support modify variables, so we add an extra variable to
# the output argument list for each input modify variable.
#
  $retstr = sprintf("octave_value_list _wrap_%s(const octave_value_list &args, int %s)\n",
		    $fname,
		    (@{$faa->{outputs}} + @{$faa->{modifies}}) <= 1 ? '' : 'nargout');
				# Don't specify nargout unless we actually
				# need to test it.

  $retstr .= ("{\n" .
	      "  octave_value_list retval(" . @{$faa->{outputs}} . ", octave_value());\n" . # Where we return stuff.
				# Make sure we have right # of args:
	      "  if (args.length()-1 != " . (scalar(@{$faa->{inputs}}) + 
					     scalar(@{$faa->{modifies}})));
  $retstr .= " ||\n      nargout != " . (scalar(@{$faa->{outputs}}) + scalar(@{$faa->{modifies}}))
    unless (@{$faa->{outputs}}+@{$faa->{modifies}}) <= 1;
				# Permissible not to specify output args
				# if there is only one.
  @ver = split(/\./,$octave_version);
  if ($ver[0] >= 3 || ($ver[0] >= 2 && $ver[1] >= 9)) {
    $retstr .= (")\n" .
	      "  {\n" .
	      "    print_usage();\n" . # Give an error.
	      "    return retval;\n" . # Quit now.
	      "  }\n\n");
  }
  else {
    $retstr .= (")\n" .
	      "  {\n" .
	      "    print_usage(\"$fname\");\n" . # Give an error.
	      "    return retval;\n" . # Quit now.
	      "  }\n\n");
  }
#
{'fraction_non_alphanumeric': 0.12923519367304753, 'fraction_numerical': 0.0070998472184775775, 'mean_word_length': 3.303170920340294, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 45, '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': '6255741', 'n_tokens_mistral': 3802, 'n_tokens_neox': 3543, 'n_words': 1275}