diff --git a/Makefile b/Makefile index 30f37c8..204b760 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file + rm -vf *.o sudokuloeser diff --git a/main.c b/main.c index 5c209fa..6242f78 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,7 @@ #include "output.h" #include "output_std.h" #include "output_nstd.h" +#include "html.h" #include #include #include @@ -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 Output-File\n"); printf(" -O 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 Output-File\n"); printf(" -O Overlay for non-standard files\n"); printf(" -p Plaintext\n"); diff --git a/output.h b/output.h index 56958a2..be7357d 100644 --- a/output.h +++ b/output.h @@ -1,8 +1,6 @@ #ifndef output_h__ #define output_h__ -#include "main.h" - /** * Write the sudoku to a file * @param fn The Filename diff --git a/todo.txt b/todo.txt index 1b4bf12..4e4e014 100644 --- a/todo.txt +++ b/todo.txt @@ -1 +1,2 @@ -- HTML-Output +- move #include "types.h" to header files +- unique ids for header diff --git a/tohtml.pl b/tohtml.pl deleted file mode 100644 index 24dd388..0000000 --- a/tohtml.pl +++ /dev/null @@ -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 = ; - $_ = 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\n"; - for($j=0;$j<9;$j++) { - print "\t\t\t\t" , substr($sud[$i],$j,1) , "\n"; - } - print "\t\t\t\n"; - } - printFoot(); -} - -sub printHead { - print < - - - Sudoku (solved) - - - - -EOT -} - -sub printFoot { - print < - - -EOT -} diff --git a/types.h b/types.h index 9a53870..2a9466d 100644 --- a/types.h +++ b/types.h @@ -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__ */ \ No newline at end of file