#!/usr/bin/perl
#
# **************************************************************
# *                  SIMUSOL PROYECT                           *
# *                                                            *
# *         Table extension for:                               *
# *         C++ Mathematical Expression Toolkit Library        *
# *         which is located in:                               *
# * URL: http://www.partow.net/programming/exprtk/index.html   *
# *                                                            *
# *   The extension was developed by                           *
# *   Diego.Saravia@gmail.com, 2016                            *
# *   and could be used in the same terms of the toolkit       *
# *   or every free license with copyleft needed.              *
# *   http://www.simusol.org                                   *
# **************************************************************
# This file is part of Table.
#
#    Table is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Table is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Table.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use Cwd 'abs_path';
use File::Basename;
use File::Slurp ;
use Pod::Usage;
use Getopt::Long;

    ## Parse options
    my %opt;
    GetOptions(\%opt, "help|?", "man", "flag1", "version")  ||  pod2usage(2);
    pod2usage(1)  if ($opt{help});
    if ($opt{version}){
        print "Version 3\n";
	exit;
    };
    pod2usage(-exitval => 0, -verbose => 2)  if ($opt{man});

    ## Check for too many filenames
    pod2usage("$0: Too many files given.\n")  if (@ARGV > 2);


=pod
 
=head1 NAME

   Find dir

=head1 SYNOPSIS

    find dir

     Options:
       -help            brief help message
       -man             full documentation

=head1 OPTIONS

=over 4

=item B<-help>
    finddir2
    Print a brief help message and exits.

=item B<-man>

    Prints the manual page and exits.

=back

=head1 DESCRIPTION

    finddir2 

    B<This program> will read the given input file(s) and do something
    useful with the contents thereof.
 
=cut



#print " $ARGV[0] $ARGV[1]\n";

#my $ac=scalar @ARGV;
#if ($ac<2){
#    print STDERR "Cantidad insuficiente de argumentos\n";
#    exit;
#}



# este esta bueno!!!!
#my $dirname = dirname(__FILE__);
#print "DIRNAME $dirname\n";
#my $r=abs_path($dirname);
#print "DIRNAME $dirname, $r\n";
#

my $path=abs_path($0);
my ($name,$path2) = fileparse($path);
$path2=~s/\/$//;
my ($namedir,$path3) = fileparse($path2);
print "PATHS $name - $namedir  - $path3\n";


my $file="finddir.c";
my $text=File::Slurp::read_file($file);
$text=~/dir=(.+);/;
my $pe=$1;
my $pathcom="\"$path3\"";
print "$pe | $pathcom \n";
if ($pe ne $pathcom){
    $text=~s/dir=.+;/dir=$pathcom;/;
    File::Slurp::write_file($file,$text);
    #File::Slurp::edit_file { ~s/dir=.+;/dir=$pathcom;/ } "$file";
}
