Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Tool zum Entfernen von IFDEFs? (https://www.delphipraxis.net/46322-tool-zum-entfernen-von-ifdefs.html)

Dani 22. Mai 2005 19:55


Tool zum Entfernen von IFDEFs?
 
Kennt jemand ein Tool mit dem man {edit: automatisch} IFDEFs/IFNDEFs samt überflüssigem Code aus Units entfernen kann? Als Beispiel jemand der mit Delphi 7 nur für MS Windows programmiert ->

Vorher:
Delphi-Quellcode:
type
  {$IFDEF LINUX}
    {$IFNDEF VCL6ORABOVE}
    THandle = LongWord; //D6.System
    {$ENDIF}
  TIdThreadPriority = -20..19;
  {$ENDIF}
  {$IFDEF MSWINDOWS}
    {$IFNDEF VCL6ORABOVE}
    THandle = Windows.THandle;
    {$ENDIF}
  TIdThreadPriority = TThreadPriority;
  {$ENDIF}
Nachher:
Delphi-Quellcode:
type
  TIdThreadPriority = TThreadPriority;
Gruß,

Robert Marquardt 23. Mai 2005 04:55

Re: Tool zum Entfernen von IFDEFs?
 
Dier JVCL verwendet dazu ein externes Tool.
Ich glaube das ist dieses hier http://www.sf.net/projects/dpp32

Olli 23. Mai 2005 05:13

Re: Tool zum Entfernen von IFDEFs?
 
Also ich benutze dazu Perl ;)
Code:
#!/usr/bin/perl
##############################################################################
##
## Simple perl script to filter only a single DEFINE symbol from the input
## file.
##
##############################################################################
my ($param1, $param2) = @ARGV;

if ((-z $param1) || ($param2 eq ''))
{
  print <DATA>;
  exit;
}
my $positive = 1;
# Open and read and close the file
open(FILE, $param1) or die;
$x = join('', <FILE>);
close(FILE);
# Check wether the symbol is negated or not
if ($param2 =~ /^!(.+)$/i)
{
  $param2 = $1;
  $positive = 0;
}
# According to the commandline evaluate the symbol
if ($positive != 0)
{
  # Replace all IFDEF ELSE ENDIF statements
  $x =~ s/\{\$IFDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ELSE[\t\s]+[~]{0,1}$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$1/gism;
  $x =~ s/\{\$IFNDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ELSE[\t\s]+[~]{0,1}$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$2/gism;
  # Replace all IFDEF ENDIF statements
  $x =~ s/\{\$IFDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$1/gism;
  $x =~ s/\{\$IFNDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*//gism;
}
else # If the symbol was negated at the commandline
{
  # Replace all IFDEF ELSE ENDIF statements
  $x =~ s/\{\$IFDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ELSE[\t\s]+[~]{0,1}$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$2/gism;
  $x =~ s/\{\$IFNDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ELSE[\t\s]+[~]{0,1}$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$1/gism;
  # Replace all IFDEF ENDIF statements
  $x =~ s/\{\$IFDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*//gism;
  $x =~ s/\{\$IFNDEF[\t\s]+$param2\}[\t\s\n]*(.+?)\{\$ENDIF[\t\s]+[~]{0,1}$param2\}[\t\s\n]*/$1/gism;
}
# Output to STDOUT
print "$x";
__END__
Syntax:

  simple_pp.pl <filename> [!]<symbol>

Output is printed to STDOUT. If you want to treat multiple symbols simply run
the script multiple times.

The exclamation mark in front of the symbol can be used to undefine the
respective symbol - otherwise it will be defined.

Any DEFINE or UNDEF directives concerning the given symbol inside the input
file will be ignored. Only commandline is taken.
Bedienungsanleitung ist enthalten ;)

Ist von hier. Ich weiß nicht wie Robert das sieht, aber ich denke mal dadurch, daß ich es ins CVS eingecheckt hatte, ist es automatisch unter MPL.

Robert Marquardt 23. Mai 2005 06:48

Re: Tool zum Entfernen von IFDEFs?
 
Das haengt davon ab ob es ein Bestandteil der JVCL sein soll oder nicht.
Die Tools sind genaugenommen nicht Bestandteil der JVCL.
Reine GPL-Sourcen als Komponenten waeren nicht moeglich. Dual-licensing MPL/GPL sind sogar erwuenscht.

Olli 23. Mai 2005 06:52

Re: Tool zum Entfernen von IFDEFs?
 
Zitat:

Zitat von Robert Marquardt
Das haengt davon ab ob es ein Bestandteil der JVCL sein soll oder nicht.
Die Tools sind genaugenommen nicht Bestandteil der JVCL.
Reine GPL-Sourcen als Komponenten waeren nicht moeglich. Dual-licensing MPL/GPL sind sogar erwuenscht.

Also meinetwegen kann das auch Triple- oder sonstwas -licensed sein ;) Soll ich das noch ins Script schreiben und neu einchecken?
Übrigens: JCL, nicht JVCL, im Falle meines Perlscripts.


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:03 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz