Xin hat geschrieben:nufan hat geschrieben:Xin hat geschrieben:Gehst Du die längere Liste selbst noch an?
Ja, ich werde das nach mal alles prüfen. Aber ich weiß nicht, ob ich auch für alle Beispiele Zeit habe...
Rausnehmen, kompilieren, gucken, ob das Ergebnis mit der Beschreibung übereinstimmt.
Mache ich aber wie gesagt auch noch, bevor ich den Link zu Wikipedia trage.
Zumindest den Syntax kann man mit folgendem Skript prüfen:
Code: Alles auswählen
#!/usr/bin/env perl
use strict;
use HTML::Entities;
use LWP::Simple;
my %data;
foreach my $ns (@ARGV) {
foreach(split "\n", get("http://www.proggen.org/doku.php?id=" . $ns . ":start&do=index")) {
if(/title=\"$ns:(.+?)\"/) {
$data{$ns}{$1} = &extractCode(HTML::Entities::decode(get("http://proggen.org/doku.php?id=$ns:$1&do=edit&rev=")));
}
}
}
&compileCode();
unlink "main.o";
unlink "main.cpp";
sub compileCode {
foreach (keys %data) {
my %ns = %{$data{$_}};
foreach my $code (keys %ns) {
if(defined $ns{$code}) {
open my $file, ">main.cpp" or die "Error creating file: $!\n";
print $file $ns{$code};
close $file;
print "Compiling $_:$code\n";
system "g++ -c main.cpp -Wall";
print "\n";
}
}
}
}
sub extractCode {
my ($html, $found, $example, $code) = (shift, 0, 0, "");
foreach(split "\n", $html) {
if(/===== Beispiel =====/) {
$example = 1;
}
elsif($example and /\<code(.*?)\>(.*?)/) {
$code = $2;
$found = 1;
}
elsif($found and /(.*?)<\/code>/) {
return ($code . $1);
}
elsif($found) {
$code .= $_;
}
}
return undef;
}
Aufruf:
Ausgabe:
Code: Alles auswählen
Compiling c:lib:stdio:fflush
Compiling c:lib:stdio:fgets
main.cpp: In function ‘int main()’:
main.cpp:11: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
main.cpp:12: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
main.cpp:13: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
Compiling c:lib:stdio:remove
Compiling c:lib:stdio:setvbuf
Compiling c:lib:stdio:ftell
Compiling c:lib:stdio:vfprintf
Compiling c:lib:stdio:vsprintf
main.cpp: In function ‘int error(const char*, ...)’:
main.cpp:16: error: ‘strerr’ was not declared in this scope
Compiling c:lib:stdio:sscanf
Compiling c:lib:stdio:getc
Compiling c:lib:stdio:rename
main.cpp: In function ‘int main()’:
main.cpp:9: error: ‘oldname’ was not declared in this scope
main.cpp:9: error: ‘newname’ was not declared in this scope
Compiling c:lib:stdio:fopen
main.cpp: In function ‘int main()’:
main.cpp:8: error: ‘EXIT_SUCCESS’ was not declared in this scope
Compiling c:lib:stdio:clearerr
Compiling c:lib:stdio:fclose
Compiling c:lib:stdio:ungetc
Compiling c:lib:stdio:setbuf
Compiling c:lib:stdio:putchar
Compiling c:lib:stdio:fsetpos
Compiling c:lib:stdio:puts
Compiling c:lib:stdio:ferror
Compiling c:lib:stdio:fseek
Compiling c:lib:stdio:fwrite
Compiling c:lib:stdio:tmpfile
Compiling c:lib:stdio:tmpnam
Compiling c:lib:stdio:scanf
Compiling c:lib:stdio:vprintf
Compiling c:lib:stdio:feof
Compiling c:lib:stdio:printf
Compiling c:lib:stdio:sprintf
Compiling c:lib:stdio:fprintf
Compiling c:lib:stdio:fgetpos
Compiling c:lib:stdio:putc
Compiling c:lib:stdio:fscanf
Compiling c:lib:stdio:getchar
Compiling c:lib:stdio:perror
Compiling c:lib:stdio:gets
main.cpp: In function ‘int main()’:
main.cpp:11: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
main.cpp:12: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
main.cpp:13: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘char*’
Compiling c:lib:stdio:fread
Compiling c:lib:stdio:fgetc
Compiling c:lib:stdio:freopen
Compiling c:lib:stdio:rewind
Compiling c:lib:stdio:fputc
Compiling c:lib:stdio:fputs
So, und weil das ganze jetzt überhaupt keine Aussage über die Sinnhaftigkeit des Codes gibt, werde ich alles nochmal per Hand durchgehn ^^