mirror of
https://git.familie-radermacher.ch/linux/ptouch-print.git
synced 2025-05-13 15:22:56 +00:00
cosmetic changes (some are overdue since many years)
This commit is contained in:
parent
f56d7ea740
commit
53987c4150
@ -1,10 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(ptouch-print C)
|
||||
|
||||
# Configure CMake
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# Configure required dependencies
|
||||
find_package(Gettext REQUIRED)
|
||||
find_package(GD REQUIRED)
|
||||
@ -15,18 +16,41 @@ find_package(Intl REQUIRED)
|
||||
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
|
||||
|
||||
# Configure project executable
|
||||
add_executable(ptouch-print)
|
||||
add_executable(${PROJECT_NAME})
|
||||
|
||||
target_sources(ptouch-print PUBLIC
|
||||
version.h
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_BINARY_DIR} # HB9HEI - location of generated version.h
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${GD_INCLUDE_DIR}
|
||||
${LIBUSB_INCLUDE_DIRS}
|
||||
${Intl_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
${GD_LIBRARIES}
|
||||
${LIBUSB_LIBRARIES}
|
||||
${LIBUSB_LINK_LIBRARIES}
|
||||
${Intl_LIBRARY}
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
include/ptouch.h
|
||||
include/gettext.h
|
||||
src/libptouch.c
|
||||
src/ptouch-print.c
|
||||
)
|
||||
|
||||
# Configure compiler
|
||||
target_compile_options(ptouch-print PUBLIC
|
||||
add_dependencies(${PROJECT_NAME}
|
||||
git-version
|
||||
)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
||||
LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}"
|
||||
USING_CMAKE=1
|
||||
PACKAGE="ptouch-print"
|
||||
)
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC
|
||||
-g
|
||||
-Wall
|
||||
-Wextra
|
||||
@ -35,37 +59,11 @@ target_compile_options(ptouch-print PUBLIC
|
||||
-fPIC
|
||||
)
|
||||
|
||||
target_compile_definitions(ptouch-print PUBLIC
|
||||
LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}"
|
||||
USING_CMAKE=1
|
||||
PACKAGE="ptouch-print"
|
||||
# HB9HEI - custom target that produces version.h (req. cmake 3.0)
|
||||
add_custom_target(git-version ALL
|
||||
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake
|
||||
)
|
||||
|
||||
target_include_directories(ptouch-print PUBLIC
|
||||
include
|
||||
${GD_INCLUDE_DIR}
|
||||
${LIBUSB_INCLUDE_DIRS}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${Intl_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Configure linker
|
||||
target_link_libraries(ptouch-print
|
||||
${GD_LIBRARIES}
|
||||
${LIBUSB_LIBRARIES}
|
||||
${LIBUSB_LINK_LIBRARIES}
|
||||
${Intl_LIBRARY}
|
||||
)
|
||||
|
||||
# Add a custom command that produces version.h, plus a dummy output that's
|
||||
# not produced, in order to force gitversion.cmake to always be re-run
|
||||
# before the build
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
|
||||
${CMAKE_BINARY_DIR}/_version.h
|
||||
COMMAND ${CMAKE_COMMAND} -P
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr")
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
# HB9HEI - required for autogen version.h
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
# Get commit hash
|
||||
execute_process(COMMAND git log --format='%H' -n 1
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
||||
@ -35,11 +38,11 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(VERSION "const char* GIT_BRANCH=\"${GIT_BRANCH}\";
|
||||
const char* GIT_COMMIT=\"${GIT_COMMIT_SHORT}\";
|
||||
const char* GIT_COMMITS=\"${GIT_COMMITS}\";
|
||||
const char* GIT_TAG=\"${GIT_TAG}\";
|
||||
const char* VERSION=\"${GIT_TAG}-r${GIT_COMMITS}-g${GIT_COMMIT_SHORT}${GIT_DIFF}\";
|
||||
set(VERSION "#define GIT_BRANCH \"${GIT_BRANCH}\"
|
||||
#define GIT_COMMIT \"${GIT_COMMIT_SHORT}\"
|
||||
#define GIT_COMMITS \"${GIT_COMMITS}\"
|
||||
#define GIT_TAG \"${GIT_TAG}\"
|
||||
#define VERSION \"${GIT_TAG}.r${GIT_COMMITS}.g${GIT_COMMIT_SHORT}${GIT_DIFF}\"
|
||||
")
|
||||
|
||||
message(DEBUG "Generated Version: \"${VERSION}\"")
|
||||
|
@ -114,7 +114,7 @@ int ptouch_open(ptouch_dev *ptdev)
|
||||
libusb_free_device_list(devs, 1);
|
||||
return -1;
|
||||
}
|
||||
for (int k=0; ptdevs[k].vid > 0; k++) {
|
||||
for (int k=0; ptdevs[k].vid > 0; ++k) {
|
||||
if ((desc.idVendor == ptdevs[k].vid) && (desc.idProduct == ptdevs[k].pid) && (ptdevs[k].flags >= 0)) {
|
||||
fprintf(stderr, _("%s found on USB bus %d, device %d\n"),
|
||||
ptdevs[k].name,
|
||||
@ -255,7 +255,7 @@ int ptouch_eject(ptouch_dev ptdev)
|
||||
void ptouch_rawstatus(uint8_t raw[32])
|
||||
{
|
||||
fprintf(stderr, _("debug: dumping raw status bytes\n"));
|
||||
for (int i=0; i<32; i++) {
|
||||
for (int i=0; i<32; ++i) {
|
||||
fprintf(stderr, "%02x ", raw[i]);
|
||||
if (((i+1) % 16) == 0) {
|
||||
fprintf(stderr, "\n");
|
||||
@ -281,7 +281,7 @@ int ptouch_getstatus(ptouch_dev ptdev)
|
||||
fprintf(stderr, _("read error: %s\n"), libusb_error_name(r));
|
||||
return -1;
|
||||
}
|
||||
tries++;
|
||||
++tries;
|
||||
if (tries > 10) {
|
||||
fprintf(stderr, _("timeout while waiting for status response\n"));
|
||||
return -1;
|
||||
@ -291,7 +291,7 @@ int ptouch_getstatus(ptouch_dev ptdev)
|
||||
if (buf[0]==0x80 && buf[1]==0x20) {
|
||||
memcpy(ptdev->status, buf, 32);
|
||||
ptdev->tape_width_px=0;
|
||||
for (i=0; tape_info[i].mm > 0; i++) {
|
||||
for (i=0; tape_info[i].mm > 0; ++i) {
|
||||
if (tape_info[i].mm == buf[10]) {
|
||||
ptdev->tape_width_px=tape_info[i].px;
|
||||
}
|
||||
@ -359,7 +359,7 @@ int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
|
||||
void ptouch_list_supported()
|
||||
{
|
||||
printf("Supported printers (some might have quirks)\n");
|
||||
for (int i=0; ptdevs[i].vid > 0; i++) {
|
||||
for (int i=0; ptdevs[i].vid > 0; ++i) {
|
||||
if ((ptdevs[i].flags & FLAG_PLITE) != FLAG_PLITE) {
|
||||
printf("\t%s\n", ptdevs[i].name);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ int find_fontsize(int want_px, char *font, char *text)
|
||||
int save=0;
|
||||
int brect[8];
|
||||
|
||||
for (int i=4; ; i++) {
|
||||
for (int i=4; ; ++i) {
|
||||
if (gdImageStringFT(NULL, &brect[0], -1, font, i, 0.0, 0, 0, text) != NULL) {
|
||||
break;
|
||||
}
|
||||
@ -244,7 +244,7 @@ gdImage *render_text(char *font, char *line[], int lines, int tape_width)
|
||||
fsz=fontsize;
|
||||
printf(_("setting font size=%i\n"), fsz);
|
||||
} else {
|
||||
for (i=0; i<lines; i++) {
|
||||
for (i=0; i<lines; ++i) {
|
||||
if ((tmp=find_fontsize(tape_width/lines, font, line[i])) < 0) {
|
||||
printf(_("could not estimate needed font size\n"));
|
||||
return NULL;
|
||||
@ -255,7 +255,7 @@ gdImage *render_text(char *font, char *line[], int lines, int tape_width)
|
||||
}
|
||||
printf(_("choosing font size=%i\n"), fsz);
|
||||
}
|
||||
for(i=0; i<lines; i++) {
|
||||
for(i=0; i<lines; ++i) {
|
||||
tmp=needed_width(line[i], font_file, fsz);
|
||||
if (tmp > x) {
|
||||
x=tmp;
|
||||
@ -267,7 +267,7 @@ gdImage *render_text(char *font, char *line[], int lines, int tape_width)
|
||||
/* gdImageStringFT(im,brect,fg,fontlist,size,angle,x,y,string) */
|
||||
/* find max needed line height for ALL lines */
|
||||
int max_height=0;
|
||||
for (i=0; i<lines; i++) {
|
||||
for (i=0; i<lines; ++i) {
|
||||
if ((p=gdImageStringFT(NULL, &brect[0], -black, font, fsz, 0.0, 0, 0, line[i])) != NULL) {
|
||||
printf(_("error in gdImageStringFT: %s\n"), p);
|
||||
}
|
||||
@ -287,7 +287,7 @@ gdImage *render_text(char *font, char *line[], int lines, int tape_width)
|
||||
/* calculate unused pixels */
|
||||
int unused_px = tape_width - (max_height * lines);
|
||||
/* now render lines */
|
||||
for (i=0; i<lines; i++) {
|
||||
for (i=0; i<lines; ++i) {
|
||||
int ofs=get_baselineoffset(line[i], font_file, fsz);
|
||||
//int pos=((i)*(tape_width/(lines)))+(max_height)-ofs-1;
|
||||
int pos=((i)*(tape_width/(lines)))+(max_height)-ofs;
|
||||
@ -412,7 +412,7 @@ int parse_args(int argc, char **argv)
|
||||
{
|
||||
int lines, i;
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
for (i=1; i<argc; ++i) {
|
||||
if (*argv[i] != '-') {
|
||||
break;
|
||||
}
|
||||
@ -424,7 +424,7 @@ int parse_args(int argc, char **argv)
|
||||
}
|
||||
} else if (strcmp(&argv[i][1], "-fontsize") == 0) {
|
||||
if (i+1<argc) {
|
||||
i++;
|
||||
++i;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
}
|
||||
@ -442,22 +442,22 @@ int parse_args(int argc, char **argv)
|
||||
continue; /* not done here */
|
||||
} else if (strcmp(&argv[i][1], "-image") == 0) {
|
||||
if (i+1<argc) {
|
||||
i++;
|
||||
++i;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
}
|
||||
} else if (strcmp(&argv[i][1], "-pad") == 0) {
|
||||
if (i+1<argc) {
|
||||
i++;
|
||||
++i;
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
}
|
||||
} else if (strcmp(&argv[i][1], "-text") == 0) {
|
||||
for (lines=0; (lines < MAX_LINES) && (i < argc); lines++) {
|
||||
for (lines=0; (lines < MAX_LINES) && (i < argc); ++lines) {
|
||||
if ((i+1 >= argc) || (argv[i+1][0] == '-')) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
++i;
|
||||
}
|
||||
} else if (strcmp(&argv[i][1], "-version") == 0) {
|
||||
printf(_("ptouch-print version %s by Dominic Radermacher\n"), VERSION);
|
||||
@ -498,7 +498,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
tape_width=ptouch_get_tape_width(ptdev);
|
||||
for (i=1; i<argc; i++) {
|
||||
for (i=1; i<argc; ++i) {
|
||||
if (*argv[i] != '-') {
|
||||
break;
|
||||
}
|
||||
@ -540,11 +540,11 @@ int main(int argc, char *argv[])
|
||||
gdImageDestroy(im);
|
||||
im = NULL;
|
||||
} else if (strcmp(&argv[i][1], "-text") == 0) {
|
||||
for (lines=0; (lines < MAX_LINES) && (i < argc); lines++) {
|
||||
for (lines=0; (lines < MAX_LINES) && (i < argc); ++lines) {
|
||||
if ((i+1 >= argc) || (argv[i+1][0] == '-')) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
++i;
|
||||
line[lines]=argv[i];
|
||||
}
|
||||
if (lines) {
|
||||
|
Loading…
Reference in New Issue
Block a user