summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile24
-rw-r--r--tools/sudoku_generator.174
-rw-r--r--tools/sudoku_generator.cpp63
3 files changed, 138 insertions, 23 deletions
diff --git a/tools/Makefile b/tools/Makefile
index edd5432..eb5f63c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -17,7 +17,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-# $Id: Makefile 140 2008-06-30 22:10:38Z tom $
+# $Id: Makefile 161 2008-11-23 00:18:02Z tom $
# Define STATIC_LINK=1 to force static linking
#STATIC_LINK = 1
@@ -27,7 +27,8 @@
PROGRAM = sudoku_generator
-SRCS = ../puzzle.cpp ../generator.cpp ../solver.cpp ../backtrack.cpp ../history.cpp
+SRCS = ../puzzle.cpp ../generator.cpp ../solver.cpp ../backtrack.cpp \
+ ../history.cpp
VERSION = $(shell sed -ne '/static .* VERSION *=/s/^.*"\(.*\)".*$$/\1/p' \
../sudoku.cpp)
@@ -44,6 +45,20 @@ ifdef WITH_TEST
DEFINES += -DWITH_TEST
endif
+### Directories:
+
+prefix = /usr/local
+bindir = $(prefix)/bin
+mandir = $(prefix)/share/man
+man1dir = $(mandir)/man1
+
+### Tools:
+
+INSTALL = install
+INSTALL_DIRS = $(INSTALL) -d
+INSTALL_PROG = $(INSTALL)
+INSTALL_DATA = $(INSTALL) -m u=rw,g=r,o=r
+
### Targets:
all: $(PROGRAM)
@@ -51,5 +66,10 @@ all: $(PROGRAM)
$(PROGRAM): $(PROGRAM).cpp $(SRCS) $(SRCS:%.cpp=%.h)
$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $@ $(PROGRAM).cpp $(SRCS)
+install: all
+ $(INSTALL_DIRS) $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
+ $(INSTALL_PROG) $(PROGRAM) $(DESTDIR)$(bindir)/
+ $(INSTALL_DATA) $(PROGRAM).1 $(DESTDIR)$(man1dir)/
+
clean:
@-rm -f $(PROGRAM) core* *~
diff --git a/tools/sudoku_generator.1 b/tools/sudoku_generator.1
new file mode 100644
index 0000000..4bc9e50
--- /dev/null
+++ b/tools/sudoku_generator.1
@@ -0,0 +1,74 @@
+.\"
+.\" Sudoku: A plug-in for the Video Disk Recorder
+.\"
+.\" Copyright (C) 2008, Thomas Günther <tom@toms-cafe.de>
+.\"
+.\" This program 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 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+.\"
+.\" $Id: sudoku_generator.1 161 2008-11-23 00:18:02Z tom $
+.\"
+.TH sudoku_generator "1" "November 2008" "sudoku_generator 0.3.3" "User Commands"
+
+.SH NAME
+sudoku_generator \- generate and solve Sudoku puzzles
+
+.SH SYNOPSIS
+.B sudoku_generator
+[\fI-n|--non-sym\fR] [\fI-d|--dump\fR] [\fIgivens_count\fR]
+.br
+.B sudoku_generator
+\fI-s|--solve|-p|--print\fR \fIsudoku_dump\fR
+
+.SH DESCRIPTION
+.B sudoku_generator
+generates, solves and prints Number Place puzzles, so called Sudokus.
+A Sudoku puzzle consists of 9 x 9 cells subdivided into 9 regions with 3 x 3
+cells. The rules are simple. There have to be the numbers from 1 to 9 in every
+row, column and region.
+
+.TP
+\fBgivens_count\fR
+Number of givens (<= 81). Default is 36.
+Generation of Sudoku puzzles with less than 26 givens takes very long.
+.TP
+\fBsudoku_dump\fR
+String with 81 * 1\-9 or _ (+ ignored).
+
+.SH OPTIONS
+.TP
+\fB\-n\fR, \fB\-\-non\-sym\fR
+Generate a non\-symmetric Sudoku puzzle. Default is symmetric.
+.TP
+\fB\-d\fR, \fB\-\-dump\fR
+Dump the generated Sudoku puzzle (don't print).
+.TP
+\fB\-s\fR, \fB\-\-solve\fR \fIsudoku_dump\fR
+Solve a Sudoku puzzle.
+.TP
+\fB\-p\fR, \fB\-\-print\fR \fIsudoku_dump\fR
+Print a Sudoku puzzle.
+.TP
+\fB\-v\fR, \fB\-\-version\fR
+Print version information and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Print help message and exit.
+
+.SH COPYRIGHT
+Copyright \(co 2005-2008, Thomas G\(:unther <tom@toms-cafe.de>
+.br
+This GPL program comes with ABSOLUTELY NO WARRANTY;
+this is free software, and you are welcome to redistribute it
+under certain conditions; see the source for details.
diff --git a/tools/sudoku_generator.cpp b/tools/sudoku_generator.cpp
index fdd3e30..8b563f5 100644
--- a/tools/sudoku_generator.cpp
+++ b/tools/sudoku_generator.cpp
@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * $Id: sudoku_generator.cpp 117 2008-03-21 17:57:50Z tom $
+ * $Id: sudoku_generator.cpp 161 2008-11-23 00:18:02Z tom $
*/
#include "../puzzle.h"
@@ -30,15 +30,24 @@
using namespace Sudoku;
-void print_copyleft(unsigned int givens_count)
+int print_version()
+{
+ printf("sudoku_generator %s\n"
+ "Copyright (C) 2005-2008, Thomas Günther <tom@toms-cafe.de>\n"
+ "This GPL program comes with ABSOLUTELY NO WARRANTY;\n"
+ "this is free software, and you are welcome to redistribute it\n"
+ "under certain conditions; see the source for details.\n", VERSION);
+ return 0;
+}
+
+void print_description(unsigned int givens_count)
{
printf("Sudoku with %d givens generated by sudoku_generator %s\n"
- " Copyright (C) 2005, Thomas Günther <tom@toms-cafe.de>\n"
- " This puzzle can be used without any limitations.\n"
+ " This puzzle can be used without any limitations.\n"
"\n", givens_count, VERSION);
}
-void print_usage()
+int print_usage()
{
printf("Usage: sudoku_generator [-n|--non-sym] [-d|--dump] [<givens_count>]\n"
" Generate a Sudoku puzzle.\n"
@@ -60,9 +69,13 @@ void print_usage()
" Perform some test procedures.\n"
"\n"
#endif
+ " sudoku_generator -v|--version\n"
+ " Print version information and exit.\n"
+ "\n"
" sudoku_generator -h|--help\n"
- " Print this help.\n"
+ " Print this help message and exit.\n"
"\n");
+ return 2;
}
void print_sudoku(const Numbers* sudoku_list[], unsigned int count,
@@ -108,7 +121,7 @@ void print_sudoku(const Numbers* sudoku_list[], unsigned int count,
}
printf("\n");
if (givens_count != 0)
- print_copyleft(givens_count);
+ print_description(givens_count);
}
void print_sudoku(const Numbers& sudoku, unsigned int givens_count = 0)
@@ -305,19 +318,21 @@ int main(int argc, char* argv[])
#ifdef WITH_TEST
{ "test", no_argument, NULL, 't' },
#endif
+ { "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL }
};
#ifdef WITH_TEST
- static const char* options = "ndspth";
+ static const char* options = "ndsptvh";
#else
- static const char* options = "ndsph";
+ static const char* options = "ndspvh";
#endif
bool non_sym = false;
bool dump = false;
bool solve = false;
bool print = false;
bool test = false;
+ bool version = false;
bool help = false;
bool error = false;
int c;
@@ -332,33 +347,39 @@ int main(int argc, char* argv[])
#ifdef WITH_TEST
case 't': test = true; break;
#endif
+ case 'v': version = true; break;
case 'h': help = true; break;
default: error = true;
}
}
int arg_count = argc - optind;
+ bool generate = non_sym || dump ||
+ (arg_count == 0 && !test && !version && !help);
unsigned int givens_count = 36;
- if ((arg_count == 0 ||
- (arg_count == 1 && sscanf(argv[optind], "%u", &givens_count) == 1)) &&
- givens_count > 0 && givens_count <= SDIM &&
- !solve && !print && !test && !help && !error)
+ if (arg_count == 1 && sscanf(argv[optind], "%u", &givens_count) == 1)
+ generate = true;
+
+ if ((generate ? 1 : 0) + (solve ? 1 : 0) + (print ? 1 : 0) + (test ? 1 : 0) +
+ (version ? 1 : 0) + (help ? 1 : 0) > 1 || error)
+ return print_usage();
+
+ if (generate && 0 < givens_count && givens_count <= SDIM)
return generate_puzzle(givens_count, non_sym, dump);
- if (solve && arg_count == 1 && strlen(argv[optind]) >= SDIM &&
- !non_sym && !dump && !test && !help && !error)
+ if (solve && arg_count == 1 && strlen(argv[optind]) >= SDIM)
return solve_puzzle(argv[optind]);
- if (print && arg_count == 1 && strlen(argv[optind]) >= SDIM &&
- !non_sym && !dump && !test && !help && !error)
+ if (print && arg_count == 1 && strlen(argv[optind]) >= SDIM)
return print_puzzle(argv[optind]);
#ifdef WITH_TEST
- if (test && arg_count == 0 &&
- !non_sym && !dump && !print && !help && !error)
+ if (test)
return test_sudoku();
#endif
- print_usage();
- return 2;
+ if (version)
+ return print_version();
+
+ return print_usage();
}