shithub: puzzles

Download patch

ref: 79a5378b5adc46ee33ba34d55738f916fb8adfc9
parent: b443a84efe1a03fc0e06cf71b1a0632c5a3c99a3
author: Asher Gordon <AsDaGo@posteo.net>
date: Sat Dec 28 22:31:34 EST 2019

Improve const-correctness in printing API.

Most of the functions in printing.c do not modify their 'document *'
argument, and therefore can declare them as 'const'.

--- a/printing.c
+++ b/printing.c
@@ -90,7 +90,7 @@
 	doc->got_solns = true;
 }
 
-static void get_puzzle_size(document *doc, struct puzzle *pz,
+static void get_puzzle_size(const document *doc, struct puzzle *pz,
 			    float *w, float *h, float *scale)
 {
     float ww, hh, ourscale;
@@ -119,7 +119,7 @@
 /*
  * Calculate the the number of pages for a document.
  */
-int document_npages(document *doc)
+int document_npages(const document *doc)
 {
     int ppp;			       /* puzzles per page */
     int pages, passes;
@@ -134,7 +134,7 @@
 /*
  * Begin a document.
  */
-void document_begin(document *doc, drawing *dr)
+void document_begin(const document *doc, drawing *dr)
 {
     print_begin_doc(dr, document_npages(doc));
 }
@@ -142,7 +142,7 @@
 /*
  * End a document.
  */
-void document_end(document *doc, drawing *dr)
+void document_end(const document *doc, drawing *dr)
 {
     print_end_doc(dr);
 }
@@ -150,7 +150,7 @@
 /*
  * Print a single page of a document.
  */
-void document_print_page(document *doc, drawing *dr, int page_nr)
+void document_print_page(const document *doc, drawing *dr, int page_nr)
 {
     int ppp;			       /* puzzles per page */
     int pages;
@@ -282,7 +282,7 @@
 /*
  * Having accumulated a load of puzzles, actually do the printing.
  */
-void document_print(document *doc, drawing *dr)
+void document_print(const document *doc, drawing *dr)
 {
     int page, pages;
     pages = document_npages(doc);
--- a/puzzles.h
+++ b/puzzles.h
@@ -527,11 +527,11 @@
 void document_free(document *doc);
 void document_add_puzzle(document *doc, const game *game, game_params *par,
 			 game_state *st, game_state *st2);
-int document_npages(document *doc);
-void document_begin(document *doc, drawing *dr);
-void document_end(document *doc, drawing *dr);
-void document_print_page(document *doc, drawing *dr, int page_nr);
-void document_print(document *doc, drawing *dr);
+int document_npages(const document *doc);
+void document_begin(const document *doc, drawing *dr);
+void document_end(const document *doc, drawing *dr);
+void document_print_page(const document *doc, drawing *dr, int page_nr);
+void document_print(const document *doc, drawing *dr);
 
 /*
  * ps.c