initial commit

Wed, 01 Apr 2009 22:11:05 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 01 Apr 2009 22:11:05 +0100
changeset 0
0eef8cf74b80
child 1
524c02ebb2eb

initial commit

Makefile file | annotate | diff | revisions
dep/.keepme file | annotate | diff | revisions
obj/.keepme file | annotate | diff | revisions
src/hexdump.c file | annotate | diff | revisions
src/main.c file | annotate | diff | revisions
src/version.h.in file | annotate | diff | revisions
     1.1 diff -r 000000000000 -r 0eef8cf74b80 Makefile
     1.2 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 +++ b/Makefile	Wed Apr 01 22:11:05 2009 +0100
     1.4 @@ -0,0 +1,379 @@
     1.5 +# Phil's multiplatform makefile template
     1.6 +# With auto-incrementing build number and automatic version.h generation
     1.7 +# Version 1.4, 2009-01-27
     1.8 +#
     1.9 +# The latest version of this Makefile can be found at http://www.philpem.me.uk/
    1.10 +#
    1.11 +#
    1.12 +# Copyright (c) 2009 Philip Pemberton <code@philpem.me.uk>
    1.13 +#
    1.14 +# Permission is hereby granted, free of charge, to any person obtaining a copy
    1.15 +# of this software and associated documentation files (the "Software"), to deal
    1.16 +# in the Software without restriction, including without limitation the rights
    1.17 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.18 +# copies of the Software, and to permit persons to whom the Software is
    1.19 +# furnished to do so, subject to the following conditions:
    1.20 +#
    1.21 +# The above copyright notice and this permission notice shall be included in
    1.22 +# all copies or substantial portions of the Software.
    1.23 +#
    1.24 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.25 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.26 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.27 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.28 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.29 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.30 +# THE SOFTWARE.
    1.31 +#
    1.32 +#
    1.33 +# Instructions for use:
    1.34 +#   Run 'make init' to create the required directories
    1.35 +#   Add your source files to the 'SOURCES' list, and change the TARGET filename
    1.36 +#   Set the desired build type and platform in the BUILD_TYPE and PLATFORM
    1.37 +#     variables respectively
    1.38 +#   Set your project type (C only, or C++) in the SRC_TYPE variable
    1.39 +#   Add any libraries you need to link against to the 'LIB' list
    1.40 +#   Run 'make'
    1.41 +#
    1.42 +# Object files are created in the 'obj' subdirectory, from source code in the
    1.43 +# 'src' directory. Dependency files are created in the 'dep' directory from
    1.44 +# the same source code the object files are created from.
    1.45 +#
    1.46 +# Supported targets are:
    1.47 +#   all                 Build everything.
    1.48 +#   update-revision     Increment the build number without building anything.
    1.49 +#   clean-versioninfo   Delete src/version.h (will be rebuilt on the next
    1.50 +#                       'make all').
    1.51 +#   init                Initialise the build system for a new project.
    1.52 +#                       WARNING: overwrites .buildnum and src/version.h.in!
    1.53 +#   cleandep            Delete all dependency files.
    1.54 +#   clean               Delete all dependency, intermediate and target files.
    1.55 +#   tidy                Delete all dependency and intermediate files, leaving
    1.56 +#                       the target file intact.
    1.57 +#
    1.58 +# If you want to reset the build number to zero, delete '.buildnum'. This
    1.59 +# should be done whenever the major or minor version changes. Excluding
    1.60 +# .buildnum from version control may also be a good idea, depending on how
    1.61 +# you want your build numbers to work.
    1.62 +#
    1.63 +# The BUILD_TYPE variable contains the current build type. There are two
    1.64 +# supported build types:
    1.65 +#   debug       Debug mode - object files are compiled with debug information
    1.66 +#               and the target is left unstripped.
    1.67 +#   release     Release mode - object files are not compiled with debug info,
    1.68 +#               and the target is fed through strip to remove redundant
    1.69 +#               data.
    1.70 +#
    1.71 +# The PLATFORM variable contains the current target platform. There are two
    1.72 +# supported platforms:
    1.73 +#   linux       GNU/Linux with GNU Compiler Collection
    1.74 +#   win32       Windows 32-bit with MinGW
    1.75 +#
    1.76 +# The EXTSRC variable is used to specify other files to build. It is typically
    1.77 +# used to specify platform or build-type specific source files, e.g.
    1.78 +#
    1.79 +# ifeq ($(BUILD_TYPE),debug-memwatch)
    1.80 +#   CFLAGS += -g -ggdb
    1.81 +#   CPPFLAGS += -DMEMWATCH
    1.82 +#   INCPATH += ./memwatch
    1.83 +#   EXTSRC += memwatch/memwatch.c
    1.84 +# endif
    1.85 +#
    1.86 +# (example taken from one of my projects that allowed the use of Memwatch to
    1.87 +#  track down memory allocation/deallocation bugs)
    1.88 +#
    1.89 +
    1.90 +####
    1.91 +# Build configuration
    1.92 +####
    1.93 +
    1.94 +# version information -- major.minor.extra
    1.95 +# note that VER_EXTRA can be overridden on the command line, e.g.:
    1.96 +# make VER_EXTRA=12345 all
    1.97 +VER_MAJOR	= 0
    1.98 +VER_MINOR	= 0
    1.99 +VER_EXTRA	?= 
   1.100 +
   1.101 +# build platform: win32 or linux
   1.102 +PLATFORM	?=	linux
   1.103 +# build type: release or debug
   1.104 +BUILD_TYPE	?=	debug
   1.105 +
   1.106 +# target executable
   1.107 +TARGET		=	ptouch
   1.108 +
   1.109 +# source files that produce object files
   1.110 +SRC			=	main.c hexdump.c
   1.111 +
   1.112 +# source type - either "c" or "cpp" (C or C++)
   1.113 +SRC_TYPE	=	c
   1.114 +
   1.115 +# additional object files that don't necessarily include source
   1.116 +EXT_OBJ		=
   1.117 +# libraries to link in -- these will be specified as "-l" parameters, the -l
   1.118 +# is prepended automatically
   1.119 +#LIB			=	jpeg tiff png z
   1.120 +LIB			=
   1.121 +# library paths -- where to search for the above libraries
   1.122 +LIBPATH		=
   1.123 +# include paths -- where to search for #include files (in addition to the
   1.124 +# standard paths
   1.125 +INCPATH		=
   1.126 +# garbage files that should be deleted on a 'make clean' or 'make tidy'
   1.127 +GARBAGE		=
   1.128 +
   1.129 +# extra dependencies - files that we don't necessarily know how to build, but
   1.130 +# that are required for building the application; e.g. object files or
   1.131 +# libraries in sub or parent directories
   1.132 +EXTDEP		=
   1.133 +
   1.134 +####
   1.135 +# Win32 target-specific settings
   1.136 +####
   1.137 +ifeq ($(strip $(PLATFORM)),win32)
   1.138 +	# windows executables have a .exe suffix
   1.139 +	TARGET := $(addsuffix .exe,$(TARGET))
   1.140 +	# console mode application
   1.141 +	EXT_CFLAGS = -mconsole
   1.142 +	# additional libraries required by CImg on win32
   1.143 +	LIB += gdi32
   1.144 +endif
   1.145 +
   1.146 +####
   1.147 +# Linux target-specific settings
   1.148 +####
   1.149 +ifeq ($(strip $(PLATFORM)),linux)
   1.150 +	# additional libraries required by CImg on linux
   1.151 +	LIB += m pthread X11
   1.152 +endif
   1.153 +
   1.154 +
   1.155 +####
   1.156 +# Tool setup
   1.157 +####
   1.158 +MAKE	=	make
   1.159 +CC		=	gcc
   1.160 +CXX		=	g++
   1.161 +CFLAGS	=	-Wall -pedantic -std=gnu99 $(EXT_CFLAGS)
   1.162 +CXXFLAGS=	-Wall -pedantic $(EXT_CXXFLAGS)
   1.163 +LDFLAGS	=	$(EXT_LDFLAGS)
   1.164 +RM		=	rm
   1.165 +STRIP	=	strip
   1.166 +
   1.167 +###############################################################################
   1.168 +# You should not need to touch anything below here, unless you're adding a new
   1.169 +# platform or build type (or changing the version string format)
   1.170 +###############################################################################
   1.171 +
   1.172 +####
   1.173 +# A quick sanity check on the platform type
   1.174 +####
   1.175 +ifneq ($(PLATFORM),linux)
   1.176 +ifneq ($(PLATFORM),win32)
   1.177 +    $(error Platform '$(PLATFORM)' not supported. Supported platforms are: linux, win32)
   1.178 +endif
   1.179 +endif
   1.180 +
   1.181 +####
   1.182 +# Version info generation
   1.183 +####
   1.184 +# get the current build number
   1.185 +VER_BUILDNUM	= $(shell cat .buildnum)
   1.186 +
   1.187 +# there are two ways to get the SVN rev - use svnversion, or use svn info
   1.188 +# then pipe through awk. which one you use is up to you.
   1.189 +VER_SVNREV		= $(shell LANG=C svn info 2>/dev/null || echo 'Revision: 0' | awk '/^Revision:/ { print$$2 }' )
   1.190 +#VER_SVNREV		= $(shell svnversion .)
   1.191 +
   1.192 +# if the version string is "exported", then the CSD was not checked out of SVN
   1.193 +# note that if the CSD is not an SVN checkout, then @@svnrev@@ will be set to
   1.194 +# zero.
   1.195 +ifeq ($(VER_SVNREV),exported)
   1.196 +    VER_SVNREV	= 0
   1.197 +endif
   1.198 +
   1.199 +# start creating the revision string
   1.200 +VER_FULLSTR		= $(VER_MAJOR).$(VER_MINOR).$(VER_BUILDNUM)$(VER_EXTRA)
   1.201 +
   1.202 +# if this is an SVN release, include the SVN revision in the version string
   1.203 +ifneq ($(VER_SVNREV),0)
   1.204 +    VER_FULLSTR	+= (svn $(VER_SVNREV))
   1.205 +endif
   1.206 +
   1.207 +
   1.208 +####
   1.209 +# Build-type specific configuration
   1.210 +####
   1.211 +ifeq ($(BUILD_TYPE),debug)
   1.212 +	CFLAGS		+= -g -ggdb
   1.213 +	CXXFLAGS	+= -g -ggdb
   1.214 +else
   1.215 + ifeq ($(BUILD_TYPE),release)
   1.216 +	CFLAGS		+= -O2
   1.217 +	CXXFLAGS	+= -O2
   1.218 + else
   1.219 + 	$(error Unsupported build type: '$(BUILD_TYPE)')
   1.220 + endif
   1.221 +endif
   1.222 +
   1.223 +####
   1.224 +# rules
   1.225 +####
   1.226 +
   1.227 +# object files
   1.228 +OBJ		=	$(addprefix obj/, $(addsuffix .o, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .o, $(basename $(EXTSRC)))
   1.229 +
   1.230 +# dependency files
   1.231 +DEPFILES =	$(addprefix dep/, $(addsuffix .d, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .d, $(basename $(EXTSRC)))
   1.232 +
   1.233 +# path commands
   1.234 +LIBLNK	=	$(addprefix -l, $(LIB))
   1.235 +LIBPTH	=	$(addprefix -L, $(LIBPATH))
   1.236 +INCPTH	=	$(addprefix -I, $(INCPATH))
   1.237 +
   1.238 +CPPFLAGS +=	$(INCPTH)
   1.239 +
   1.240 +####
   1.241 +# Make sure there is at least one object file to be linked in
   1.242 +####
   1.243 +ifeq ($(strip $(OBJ)),)
   1.244 +    $(error Unable to build: no object or source files specified in Makefile)
   1.245 +endif
   1.246 +
   1.247 +####
   1.248 +# targets
   1.249 +####
   1.250 +.PHONY:	default all update-revision versionheader clean-versioninfo init cleandep clean tidy
   1.251 +
   1.252 +all:	update-revision
   1.253 +	@$(MAKE) versionheader
   1.254 +	$(MAKE) $(TARGET)
   1.255 +
   1.256 +# increment the current build number
   1.257 +NEWBUILD=$(shell expr $(VER_BUILDNUM) + 1)
   1.258 +update-revision:
   1.259 +	@echo $(NEWBUILD) > .buildnum
   1.260 +
   1.261 +versionheader:
   1.262 +	@sed -e 's/@@date@@/$(shell LC_ALL=C date)/g'			\
   1.263 +		 -e 's/@@time@@/$(shell LC_ALL=C date +%T)/g'		\
   1.264 +		 -e 's/@@whoami@@/$(shell whoami)/g'				\
   1.265 +		 -e 's/@@hostname@@/$(shell hostname)/g'			\
   1.266 +		 -e 's|@@compiler@@|$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -n 1 | sed -e "s;|;/;")|g'	\
   1.267 +		 -e 's/@@majorver@@/$(VER_MAJOR)/g'					\
   1.268 +		 -e 's/@@minorver@@/$(VER_MINOR)/g'					\
   1.269 +		 -e 's/@@extraver@@/$(subst \",,$(VER_EXTRA))/g'	\
   1.270 +		 -e 's/@@buildnum@@/$(VER_BUILDNUM)/g'				\
   1.271 +		 -e 's/@@buildtype@@/$(BUILD_TYPE)/g'				\
   1.272 +		 -e 's/@@svnrev@@/$(VER_SVNREV)/g'					\
   1.273 +		 -e 's/@@fullverstr@@/$(VER_FULLSTR)/g'				\
   1.274 +		 -e 's/@@cflags@@/$(CFLAGS)/g'						\
   1.275 +		 < src/version.h.in > src/version.h
   1.276 +
   1.277 +# version.h creation stuff based on code from the Xen makefile
   1.278 +clean-versioninfo:
   1.279 +	@if [ ! -r src/version.h -o -O src/version.h ]; then \
   1.280 +		rm -f src/version.h; \
   1.281 +	fi
   1.282 +	@echo 0 > .buildnum
   1.283 +
   1.284 +# initialise the build system for a new project
   1.285 +init:
   1.286 +	@mkdir -p src dep obj
   1.287 +	@echo 0 > .buildnum
   1.288 +	@echo '#define VER_COMPILE_DATE	"@@date@@"'				> src/version.h.in
   1.289 +	@echo '#define VER_COMPILE_TIME	"@@time@@"'				>> src/version.h.in
   1.290 +	@echo '#define VER_COMPILE_BY		"@@whoami@@"'		>> src/version.h.in
   1.291 +	@echo '#define VER_COMPILE_HOST	"@@hostname@@"'			>> src/version.h.in
   1.292 +	@echo '#define VER_COMPILER		"@@compiler@@"'			>> src/version.h.in
   1.293 +	@echo '#define VER_BUILD_TYPE		"@@buildtype@@"'	>> src/version.h.in
   1.294 +	@echo '#define VER_CFLAGS			"@@cflags@@"'		>> src/version.h.in
   1.295 +	@echo ''												>> src/version.h.in
   1.296 +	@echo '#define VER_MAJOR			@@majorver@@'		>> src/version.h.in
   1.297 +	@echo '#define VER_MINOR			@@minorver@@'		>> src/version.h.in
   1.298 +	@echo '#define VER_BUILDNUM		@@buildnum@@'			>> src/version.h.in
   1.299 +	@echo '#define VER_EXTRA			"@@extraver@@"'		>> src/version.h.in
   1.300 +	@echo '#define VER_SVNREV			@@svnrev@@'			>> src/version.h.in
   1.301 +	@echo ''												>> src/version.h.in
   1.302 +	@echo '#define VER_FULLSTR			"@@fullverstr@@"'	>> src/version.h.in
   1.303 +	@echo ''												>> src/version.h.in
   1.304 +	@echo Build system initialised
   1.305 +
   1.306 +# remove the dependency files
   1.307 +cleandep:
   1.308 +	-rm $(DEPFILES)
   1.309 +
   1.310 +# remove the dependency files and any target or intermediate build files
   1.311 +clean:	cleandep clean-versioninfo
   1.312 +	-rm $(OBJ) $(TARGET) $(GARBAGE)
   1.313 +
   1.314 +# remove any dependency or intermediate build files
   1.315 +tidy:	cleandep clean-versioninfo
   1.316 +	-rm $(OBJ) $(GARBAGE)
   1.317 +
   1.318 +#################################
   1.319 +
   1.320 +$(TARGET):	$(OBJ) $(EXTDEP)
   1.321 +ifeq ($(SRC_TYPE),c)
   1.322 +	$(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
   1.323 +else
   1.324 +	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
   1.325 +endif
   1.326 +ifeq ($(BUILD_TYPE),release)
   1.327 +	$(STRIP) $(TARGET)
   1.328 +endif
   1.329 +
   1.330 +###
   1.331 +# extra rules
   1.332 +# example:
   1.333 +#src/parser.c:	src/parser.h
   1.334 +
   1.335 +####
   1.336 +# make object files from C source files
   1.337 +obj/%.o:	src/%.c
   1.338 +	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
   1.339 +
   1.340 +##
   1.341 +# make object files from C++ source files
   1.342 +obj/%.o:	src/%.cc
   1.343 +	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
   1.344 +
   1.345 +obj/%.o:	src/%.cpp
   1.346 +	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
   1.347 +
   1.348 +###
   1.349 +# make C files from yacc/bison source
   1.350 +src/%.h src/%.c:	src/%.y
   1.351 +	$(YACC) $(YFLAGS) -d $<
   1.352 +	mv -f y.tab.c $*.c
   1.353 +	mv -f y.tab.h $*.h
   1.354 +
   1.355 +###
   1.356 +# make C files from lex/flex source
   1.357 +src/%.c:	src/%.l
   1.358 +	$(LEX) $(LFLAGS) -o$@ $<
   1.359 +
   1.360 +###
   1.361 +# make dependencies for our source files
   1.362 +dep/%.d:	src/%.c
   1.363 +	$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
   1.364 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   1.365 +		rm -f $@.$$$$
   1.366 +
   1.367 +dep/%.d:	src/%.cpp
   1.368 +	$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
   1.369 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   1.370 +		rm -f $@.$$$$
   1.371 +
   1.372 +dep/%.d:	src/%.cc
   1.373 +	$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
   1.374 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   1.375 +		rm -f $@.$$$$
   1.376 +
   1.377 +####
   1.378 +# pull in the dependency files, but only for 'make $(TARGET)'
   1.379 +####
   1.380 +
   1.381 +ifeq ($(MAKECMDGOALS),$(TARGET))
   1.382 +  -include $(DEPFILES)
   1.383 +endif
     2.1 diff -r 000000000000 -r 0eef8cf74b80 dep/.keepme
     3.1 diff -r 000000000000 -r 0eef8cf74b80 obj/.keepme
     4.1 diff -r 000000000000 -r 0eef8cf74b80 src/hexdump.c
     4.2 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 +++ b/src/hexdump.c	Wed Apr 01 22:11:05 2009 +0100
     4.4 @@ -0,0 +1,58 @@
     4.5 +#include <stdio.h>
     4.6 +#include <ctype.h>
     4.7 +#include <string.h>
     4.8 +
     4.9 +void hex_dump(void *data, int size)
    4.10 +{
    4.11 +    /* dumps size bytes of *data to stdout. Looks like:
    4.12 +     * [0000] 75 6E 6B 6E 6F 77 6E 20
    4.13 +     *                  30 FF 00 00 00 00 39 00 unknown 0.....9.
    4.14 +     * (in a single line of course)
    4.15 +     */
    4.16 +
    4.17 +    unsigned char *p = data;
    4.18 +    unsigned char c;
    4.19 +    int n;
    4.20 +    char bytestr[4] = {0};
    4.21 +    char addrstr[10] = {0};
    4.22 +    char hexstr[ 16*3 + 5] = {0};
    4.23 +    char charstr[16*1 + 5] = {0};
    4.24 +    for(n=1;n<=size;n++) {
    4.25 +        if (n%16 == 1) {
    4.26 +            /* store address for this line */
    4.27 +            snprintf(addrstr, sizeof(addrstr), "%.4x",
    4.28 +               ((unsigned int)p-(unsigned int)data) );
    4.29 +        }
    4.30 +            
    4.31 +        c = *p;
    4.32 +        if (isalnum(c) == 0) {
    4.33 +            c = '.';
    4.34 +        }
    4.35 +
    4.36 +        /* store hex str (for left side) */
    4.37 +        snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
    4.38 +        strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1);
    4.39 +
    4.40 +        /* store char str (for right side) */
    4.41 +        snprintf(bytestr, sizeof(bytestr), "%c", c);
    4.42 +        strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1);
    4.43 +
    4.44 +        if(n%16 == 0) { 
    4.45 +            /* line completed */
    4.46 +            printf("[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
    4.47 +            hexstr[0] = 0;
    4.48 +            charstr[0] = 0;
    4.49 +        } else if(n%8 == 0) {
    4.50 +            /* half line: add whitespaces */
    4.51 +            strncat(hexstr, "  ", sizeof(hexstr)-strlen(hexstr)-1);
    4.52 +            strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1);
    4.53 +        }
    4.54 +        p++; /* next byte */
    4.55 +    }
    4.56 +
    4.57 +    if (strlen(hexstr) > 0) {
    4.58 +        /* print rest of buffer if not empty */
    4.59 +        printf("[%4.4s]   %-50.50s  %s\n", addrstr, hexstr, charstr);
    4.60 +    }
    4.61 +}
    4.62 +
     5.1 diff -r 000000000000 -r 0eef8cf74b80 src/main.c
     5.2 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 +++ b/src/main.c	Wed Apr 01 22:11:05 2009 +0100
     5.4 @@ -0,0 +1,47 @@
     5.5 +#include <stdio.h>
     5.6 +#include <stdlib.h>
     5.7 +#include "hexdump.h"
     5.8 +
     5.9 +#define ESC 0x1b
    5.10 +
    5.11 +int main(int argc, char **argv)
    5.12 +{
    5.13 +	FILE *prn;
    5.14 +
    5.15 +	// check command line args
    5.16 +	if (argc < 2) {
    5.17 +		printf("ERROR: must specify device name\n");
    5.18 +		return -1;
    5.19 +	}
    5.20 +
    5.21 +	// open printer device
    5.22 +	if ((prn = fopen(argv[1], "r+b")) == NULL) {
    5.23 +		printf("ERROR: couldn't open printer device '%s'\n", argv[1]);
    5.24 +		return -1;
    5.25 +	}
    5.26 +
    5.27 +	// INITIALISE
    5.28 +	fprintf(prn, "%c%c", ESC, '@');
    5.29 +
    5.30 +	// REQUEST STATUS
    5.31 +	fprintf(prn, "%c%c%c", ESC, 'i', 'S');
    5.32 +
    5.33 +	// Read status buffer from printer
    5.34 +	unsigned char buf[32];
    5.35 +	int timeout = 128;
    5.36 +	do {
    5.37 +		fread(buf, 1, 32, prn);
    5.38 +	} while ((buf[0] != 0x80) && (timeout-- > 0));
    5.39 +
    5.40 +	if (timeout > 0) {
    5.41 +		printf("Printer status:\n");
    5.42 +		hex_dump(buf, 32);
    5.43 +	} else {
    5.44 +		printf("TIMEOUT\n");
    5.45 +		return -1;
    5.46 +	}
    5.47 +
    5.48 +	// Close the printer stream
    5.49 +	fclose(prn);
    5.50 +	return 0;
    5.51 +}
     6.1 diff -r 000000000000 -r 0eef8cf74b80 src/version.h.in
     6.2 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 +++ b/src/version.h.in	Wed Apr 01 22:11:05 2009 +0100
     6.4 @@ -0,0 +1,16 @@
     6.5 +#define VER_COMPILE_DATE	"@@date@@"
     6.6 +#define VER_COMPILE_TIME	"@@time@@"
     6.7 +#define VER_COMPILE_BY		"@@whoami@@"
     6.8 +#define VER_COMPILE_HOST	"@@hostname@@"
     6.9 +#define VER_COMPILER		"@@compiler@@"
    6.10 +#define VER_BUILD_TYPE		"@@buildtype@@"
    6.11 +#define VER_CFLAGS			"@@cflags@@"
    6.12 +
    6.13 +#define VER_MAJOR			@@majorver@@
    6.14 +#define VER_MINOR			@@minorver@@
    6.15 +#define VER_BUILDNUM		@@buildnum@@
    6.16 +#define VER_EXTRA			"@@extraver@@"
    6.17 +#define VER_SVNREV			@@svnrev@@
    6.18 +
    6.19 +#define VER_FULLSTR			"@@fullverstr@@"
    6.20 +