Implemented HTML-Output

main
Thomas Ba. 13 years ago
parent 37a08672f4
commit 2fe20adb91

@ -1,5 +1,11 @@
sudokuloeser: input.o input_nstd.o main.o output.o output_nstd.o output_std.o solver.o solver_nstd.o solver_std.o
gcc -lrt -o sudokuloeser input.o input_nstd.o main.o output.o output_nstd.o output_std.o solver.o solver_nstd.o solver_std.o
sudokuloeser: input.o input_nstd.o main.o output.o output_nstd.o output_std.o solver.o solver_nstd.o solver_std.o html.o
gcc -lrt -o sudokuloeser input.o input_nstd.o main.o output.o output_nstd.o output_std.o solver.o solver_nstd.o solver_std.o html.o
install: sudokuloeser
install -vDm755 sudokuloeser /usr/bin/sudokuloeser
uninstall:
rm /usr/bin/sudokuloeser
input.o: input.c
gcc -Wall -pedantic -c input.c
@ -19,6 +25,8 @@ solver_nstd.o: solver_nstd.c
gcc -Wall -pedantic -c solver_nstd.c
solver_std.o: solver_std.c
gcc -Wall -pedantic -c solver_std.c
html.o: html.c html.h
gcc -Wall -pedantic -c html.c
clean:
rm -vf *.o sudokuloeser
rm -vf *.o sudokuloeser

@ -29,6 +29,7 @@
#include "output.h"
#include "output_std.h"
#include "output_nstd.h"
#include "html.h"
#include <stdio.h>
#include <time.h>
#include <ctype.h>
@ -44,6 +45,7 @@ int main(int argc, char **argv) {
#endif
sudoku s={ {{0}}, {{0}}, {{0}}, {{{1}}}, 81 };
char st=0,ret=0;
int i,j;
#ifdef linux
struct timespec ts,te,l_ts,l_te;
long double t;
@ -64,6 +66,12 @@ int main(int argc, char **argv) {
fprintf(stderr,"Ungueltiges Dateiformat (Overlay)!\n");
return 2;
}
}else if(o.html == 1){
for(i=0;i<9;i++) {
for(j=0;j<9;j++) {
s.feld[i][j] = ((i/3)*3)+1+(j/3);
}
}
}
/* Aus Datei einlesen und Fehler auswerten */
st = s_einlesen(o.infile,&s,&o);
@ -114,7 +122,7 @@ int main(int argc, char **argv) {
if(!o.silent) printf("Loesung gefunden:\n\n");
}
o.ausgabe(&s,o.color);
if(o.outfile != NULL) s_write( o.outfile ,&s );
if(o.outfile != NULL) o.write( o.outfile ,&s );
}
#ifdef linux
if(!o.silent) {
@ -181,6 +189,9 @@ void readOptions(int argc, char **argv, options * o) {
print_help(argc,argv);
exit(0);
}
if(o->html != 0 && o->outfile == NULL) {
o->silent = 1;
}
o->infile = argv[optind];
}
void newStandard(options * o) {
@ -188,6 +199,7 @@ void newStandard(options * o) {
o->set_num = solver_set_num;
o->test = solver_test;
/* Check which out put to use */
o->write = s_write;
if(o->unicode) {
o->ausgabe = std_ausgabe_unicode;
}else if(o->plaintext) {
@ -195,12 +207,18 @@ void newStandard(options * o) {
}else{
o->ausgabe = std_ausgabe;
}
if(o->html) {
if(o->outfile == NULL)
o->ausgabe = out_html;
o->write = write_html;
}
}
void newNonStandard(options * o) {
o->check_nums = solver_nstd_check_nums;
o->set_num = solver_nstd_set_num;
o->test = solver_nstd_test;
/* Check which out put to use */
o->write = s_write;
if(o->unicode) {
o->ausgabe = nstd_ausgabe_unicode;
}else if(o->plaintext) {
@ -208,6 +226,11 @@ void newNonStandard(options * o) {
}else{
o->ausgabe = nstd_ausgabe;
}
if(o->html) {
if(o->outfile == NULL)
o->ausgabe = out_html;
o->write = write_html;
}
}
void print_help(int argc, char **argv) {
@ -217,6 +240,7 @@ void print_help(int argc, char **argv) {
printf("\033[0;1mOptions\033[0m\n");
printf(" -U Unicode borders\n");
printf(" -h This help\n");
printf(" -H HTML-Output");
printf(" -o <file> Output-File\n");
printf(" -O <file> Overlay for non-standard files\n");
printf(" -c No colors\n");
@ -234,6 +258,7 @@ printf("\033[0;1mUsage:\033[0m\n");
printf("\033[0;1mOptions\033[0m\n");
printf(" -U Unicode borders\n");
printf(" -h This help\n");
printf(" -H HTML-Output");
printf(" -o <file> Output-File\n");
printf(" -O <file> Overlay for non-standard files\n");
printf(" -p Plaintext\n");

@ -1,8 +1,6 @@
#ifndef output_h__
#define output_h__
#include "main.h"
/**
* Write the sudoku to a file
* @param fn The Filename

@ -1 +1,2 @@
- HTML-Output
- move #include "types.h" to header files
- unique ids for header

@ -1,72 +0,0 @@
#!/usr/bin/perl
my @overlay;
if( $#ARGV == 1) {
@overlay = readFile($ARGV[1]);
}else{
@overlay = (
"111222333",
"111222333",
"111222333",
"444555666",
"444555666",
"444555666",
"777888999",
"777888999",
"777888999"
);
}
my @sud = readFile($ARGV[0]);
&genHTML(@overlay,@sud);
sub readFile {
open FILE, "<", $_[0] or die $!;
binmode FILE;
@lines = <FILE>;
$_ = join("", @lines);
close FILE;
if( /([0-9]{9,9}\r?\n){8,8}([0-9]{9,9}\r?\n?)/ ) {
foreach(@lines) {
s/\r?\n//g
}
return @lines;
}
die "Konnte Datein nicht einlesen!\n";
}
sub genHTML {
printHead();
for($i=0;$i<9;$i++) {
print "\t\t\t<tr>\n";
for($j=0;$j<9;$j++) {
print "\t\t\t\t<td class=\"c" , substr($overlay[$i],$j,1) , "\">" , substr($sud[$i],$j,1) , "</td>\n";
}
print "\t\t\t</tr>\n";
}
printFoot();
}
sub printHead {
print <<EOT
<!DOCTYPE html>
<html>
<head>
<title>Sudoku (solved)</title>
<style type="text/css">
.c1{background:#c8ffc8}.c2{background:#ffff66}.c3{background:#83caff}.c4{background:#ff950e}.c5{background:#0084d1}.c6{background:#aecf00}.c7{background:#ffc8c8}.c8{background:#00ffff}.c9{background:#c8c8ff}
table{border-collapse:collapse}td{border:1px solid #000;height:3em;width:3em;text-align:center;vertical-align:middle;font-weight:bold}
</style>
</head>
<body>
<table>
EOT
}
sub printFoot {
print <<EOT
</table>
</body>
</html>
EOT
}

@ -23,6 +23,7 @@ typedef struct options {
void (*set_num)(sudoku*,int,int,int);
int (*test)(sudoku*,int,int,int);
void (*ausgabe)(sudoku*,int);
int (*write)(char*,sudoku*);
} options;
#endif /* types_h__ */
Loading…
Cancel
Save