chiark / gitweb /
Improve const-correctness in printing API.
authorAsher Gordon <AsDaGo@posteo.net>
Sun, 29 Dec 2019 08:31:34 +0000 (03:31 -0500)
committerSimon Tatham <anakin@pobox.com>
Mon, 30 Dec 2019 08:10:34 +0000 (08:10 +0000)
Most of the functions in printing.c do not modify their 'document *'
argument, and therefore can declare them as 'const'.

printing.c
puzzles.h

index 3f0810a1769bb3b2d77b966ea9d49e8e59bb9b16..d1a3badaaac6b6130e16f8ba44623d01164e6907 100644 (file)
@@ -90,7 +90,7 @@ void document_add_puzzle(document *doc, const game *game, game_params *par,
        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 @@ static void get_puzzle_size(document *doc, struct puzzle *pz,
 /*
  * 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 @@ int document_npages(document *doc)
 /*
  * 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 @@ void document_begin(document *doc, drawing *dr)
 /*
  * 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 @@ void document_end(document *doc, drawing *dr)
 /*
  * 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 @@ void document_print_page(document *doc, drawing *dr, int page_nr)
 /*
  * 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);
index 7c7882a302aee3f49dc41a717be54d4810d4b4a6..daec081c8dfb4103a3038a19098955db211b09ef 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -527,11 +527,11 @@ document *document_new(int pw, int ph, float userscale);
 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