1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-08-14 16:03:25 +00:00

coding style cosmetics

This commit is contained in:
Dominic Radermacher 2025-08-11 09:57:02 +02:00
parent 92c1e43f0c
commit d293e9427d

View File

@ -95,7 +95,7 @@ static struct argp_option options[] = {
{ "pad", 'p', "<n>", 0, "Add n pixels padding (blank tape)", 2}, { "pad", 'p', "<n>", 0, "Add n pixels padding (blank tape)", 2},
{ "chain", 10, 0, 0, "Skip final feed of label and any automatic cut", 2}, { "chain", 10, 0, 0, "Skip final feed of label and any automatic cut", 2},
{ "newline", 'n', "<line>", 0, "Add 1-4 lines for multiline text", 2}, { "newline", 'n', "<line>", 0, "Add 1-4 lines for multiline text", 2},
{ 0, 0, 0, 0, "other commands:", 3}, { 0, 0, 0, 0, "other commands:", 3},
{ "info", 20, 0, 0, "Show info about detected tape", 3}, { "info", 20, 0, 0, "Show info about detected tape", 3},
{ "list-supported", 21, 0, 0, "Show printers supported by this version", 3}, { "list-supported", 21, 0, 0, "Show printers supported by this version", 3},
@ -105,7 +105,7 @@ static struct argp_option options[] = {
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 }; static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
struct arguments arguments = { struct arguments arguments = {
.chain =false, .chain = false,
.copies = 1, .copies = 1,
.debug = false, .debug = false,
.info = false, .info = false,
@ -351,7 +351,7 @@ gdImage *render_text(char *font, char *line[], int lines, int print_width)
} }
printf(_("choosing font size=%i\n"), fsz); printf(_("choosing font size=%i\n"), fsz);
} }
for(i = 0; i < lines; ++i) { for (i = 0; i < lines; ++i) {
tmp = needed_width(line[i], arguments.font_file, fsz); tmp = needed_width(line[i], arguments.font_file, fsz);
if (tmp > x) { if (tmp > x) {
x = tmp; x = tmp;
@ -485,22 +485,22 @@ gdImage *img_padding(int print_width, int length)
void add_job(job_type_t type, int n, char *line) void add_job(job_type_t type, int n, char *line)
{ {
job_t *new_job = (job_t*)malloc(sizeof(job_t)); job_t *new_job = (job_t*)malloc(sizeof(job_t));
if(!new_job) { if (!new_job) {
fprintf(stderr, "Memory allocation failed\n"); fprintf(stderr, "Memory allocation failed\n");
return; return;
} }
new_job->type = type; new_job->type = type;
if(type == JOB_TEXT && n > MAX_LINES) { if (type == JOB_TEXT && n > MAX_LINES) {
n = MAX_LINES; n = MAX_LINES;
} }
new_job->n = n; new_job->n = n;
new_job->lines[0] = line; new_job->lines[0] = line;
for(int i=1; i<MAX_LINES; i++) for (int i=1; i<MAX_LINES; ++i) {
new_job->lines[i] = NULL; new_job->lines[i] = NULL;
}
new_job->next = NULL; new_job->next = NULL;
if(!last_added_job) { // just created the first job if (!last_added_job) { // just created the first job
jobs = last_added_job = new_job; jobs = last_added_job = new_job;
return; return;
} }
@ -534,10 +534,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
break; break;
case 'i': // image case 'i': // image
add_job(JOB_IMAGE, 1, arg); add_job(JOB_IMAGE, 1, arg);
break; break;
case 't': // text case 't': // text
add_job(JOB_TEXT, 1, arg); add_job(JOB_TEXT, 1, arg);
break; break;
case 'c': // cutmark case 'c': // cutmark
add_job(JOB_CUTMARK, 0, NULL); add_job(JOB_CUTMARK, 0, NULL);
break; break;
@ -548,12 +548,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
arguments->chain = true; arguments->chain = true;
break; break;
case 'n': // newline case 'n': // newline
if(!last_added_job || last_added_job->type != JOB_TEXT) { if (!last_added_job || last_added_job->type != JOB_TEXT) {
add_job(JOB_TEXT, 1, arg); add_job(JOB_TEXT, 1, arg);
break; break;
} }
if(last_added_job->n >= MAX_LINES) { // max number of lines reached if (last_added_job->n >= MAX_LINES) { // max number of lines reached
argp_failure(state, 1, EINVAL, _("Only up to %d lines are supported"), MAX_LINES); argp_failure(state, 1, EINVAL, _("Only up to %d lines are supported"), MAX_LINES);
break; break;
} }
@ -581,7 +581,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
default: default:
return ARGP_ERR_UNKNOWN; return ARGP_ERR_UNKNOWN;
} }
return 0; return 0;
} }
@ -623,7 +622,7 @@ int main(int argc, char *argv[])
print_width = arguments.forced_tape_width; print_width = arguments.forced_tape_width;
} }
if(arguments.info) { if (arguments.info) {
printf(_("maximum printing width for this printer is %ldpx\n"), ptouch_get_max_width(ptdev)); printf(_("maximum printing width for this printer is %ldpx\n"), ptouch_get_max_width(ptdev));
printf(_("maximum printing width for this tape is %ldpx\n"), ptouch_get_tape_width(ptdev)); printf(_("maximum printing width for this tape is %ldpx\n"), ptouch_get_tape_width(ptdev));
printf("media type = %02x (%s)\n", ptdev->status->media_type, pt_mediatype(ptdev->status->media_type)); printf("media type = %02x (%s)\n", ptdev->status->media_type, pt_mediatype(ptdev->status->media_type));
@ -637,16 +636,17 @@ int main(int argc, char *argv[])
exit(0); exit(0);
} }
// iterate through all print jobs // iterate through all print jobs
for(job_t *job = jobs; job != NULL; job = job->next) { for (job_t *job = jobs; job != NULL; job = job->next) {
if(arguments.debug) { if (arguments.debug) {
printf("job %p: type=%d | n=%d", job, job->type, job->n); printf("job %p: type=%d | n=%d", job, job->type, job->n);
for(int i=0; i<MAX_LINES; i++) for (int i=0; i<MAX_LINES; ++i) {
printf(" | %s", job->lines[i]); printf(" | %s", job->lines[i]);
}
printf(" | next=%p\n", job->next); printf(" | next=%p\n", job->next);
} }
switch(job->type) { switch (job->type) {
case JOB_IMAGE: case JOB_IMAGE:
if ((im = image_load(job->lines[0])) == NULL) { if ((im = image_load(job->lines[0])) == NULL) {
printf(_("failed to load image file\n")); printf(_("failed to load image file\n"));
@ -683,7 +683,7 @@ int main(int argc, char *argv[])
} }
// clean up job list // clean up job list
for(job_t *job = jobs; job != NULL; ) { for (job_t *job = jobs; job != NULL; ) {
job_t *next = job->next; job_t *next = job->next;
free(job); free(job);
job = next; job = next;