w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ppagelist.c
Go to the documentation of this file.
1 /* ppagelist.c */
2 
3 /************************************************************************
4 
5  Part of the dvipng distribution
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as
9  published by the Free Software Foundation, either version 3 of the
10  License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this program. If not, see
19  <http://www.gnu.org/licenses/>.
20 
21  Copyright (C) 2002-2010 Jan-Åke Larsson
22 
23 ************************************************************************/
24 
25 #include "dvipng.h"
26 
27 /* Some code at the end of this file is adapted from dvips */
28 
30 static bool abspage=false, reverse=false;
31 bool no_ppage=true;
32 
33 /* dvips' behaviour:
34  * -pp outputs _all_ pages with the correct numbers,
35  * -p, -l outputs from the first occurrence of firstpage to the first
36  * occurrence of lastpage. Using '=' means absolute pagenumbers
37  */
38 
40 {
41  first=page;
42  abspage |= data;
43 }
45 {
46  last=page;
47  abspage |= data;
48 }
49 void Reverse(bool new)
50 {
51  reverse=new;
52 }
53 /*-->NextPPage*/
54 /**********************************************************************/
55 /**************************** NextPPage *****************************/
56 /**********************************************************************/
57 /* Return the page in turn on our queue */
58 /* (Implicitly, PAGE_POST is never in the pagelist) */
59 bool InPageList(int32_t i);
60 
61 struct page_list* NextPPage(void* dvi, struct page_list* page)
62 {
63  if (! reverse) { /*********** normal order */
64  if (page == NULL) { /* first call: find first page */
65  if (no_ppage)
66  return(NULL);
68  } else /* later calls: count up, except "last" page */
69  page=(last==page->count[abspage ? 0 : 10]) ? NULL : NextPage(dvi,page);
70  /* seek for pages in pagelist */
71  while (page!=NULL && ! InPageList(page->count[0]))
72  page=(last==page->count[abspage ? 0 : 10]) ? NULL : NextPage(dvi,page);
73  } else { /******************** reverse order */
74  if (page == NULL) { /* first call: find "last" page */
75  if (no_ppage)
76  return(NULL);
78  } else /* later calls: count down, except "first" page */
79  page=(first==page->count[abspage ? 0 : 10]) ? NULL : PrevPage(dvi,page);
80  /* seek for pages in pagelist */
81  while (page!=NULL && ! InPageList(page->count[0]))
82  page=(first==page->count[abspage ? 0 : 10]) ? NULL : PrevPage(dvi,page);
83  }
84  return(page);
85 }
86 
87 struct pp_list {
88  struct pp_list *next; /* next in a series of alternates */
89  int32_t ps_low, ps_high; /* allowed range */
90 } *ppages = 0; /* the list of allowed pages */
91 
92 /*-->InPageList*/
93 /**********************************************************************/
94 /****************************** InPageList **************************/
95 /**********************************************************************/
96 /* Return true iff i is one of the desired output pages */
97 
99 {
100  register struct pp_list *pl = ppages;
101 
102  while (pl) {
103  if ( i >= pl -> ps_low && i <= pl -> ps_high)
104  return(true); /* success */
105  pl = pl -> next;
106  }
107  return(false);
108 }
109 
110 static void ListPage(int32_t pslow, int32_t pshigh)
111 {
112  register struct pp_list *pl;
113 
114  /* Some added code, we want to reuse the list */
115  no_ppage=false;
116  pl = ppages;
117  while (pl != NULL && pl->ps_low <= pl->ps_high)
118  pl = pl->next;
119  if (pl == NULL) {
120  if ((pl = (struct pp_list *)malloc(sizeof(struct pp_list)))
121  ==NULL)
122  Fatal("cannot malloc memory for page queue");
123  pl -> next = ppages;
124  ppages = pl;
125  }
126  pl -> ps_low = pslow;
127  pl -> ps_high = pshigh;
128 }
129 
130 /* Parse a string representing a list of pages. Return 0 iff ok. As a
131  side effect, the page selection(s) is (are) prepended to ppages. */
132 
133 bool ParsePages(const char *s)
134 {
135  const char *c; /* conversion start */
136  char *t;
137  long int ps_low = PAGE_MINPAGE, ps_high = PAGE_MAXPAGE;
138 
139  while (*s==' ' || *s=='\t') s++;
140  while (*s!='\0') {
141  if (*s=='-' || *s==':') { /* range with no starting value */
143  c=s+1;
144  ps_high = strtol(c,&t,10);
145  s = t;
146  if (c==s) ps_high=PAGE_MAXPAGE; /* no number */
147  while (*s==' ' || *s=='\t') s++;
148  if (*s=='-' || *s==':') { /* Oh, range with negative starting value */
149  ps_low = -ps_high;
150  c=s+1;
151  ps_high = strtol(c,&t,10);
152  s = t;
153  if (c==s) ps_high=PAGE_MAXPAGE; /* no number */
154  }
155  } else { /* range with starting value, or singleton */
156  c=s;
157  ps_low = ps_high = strtol(c,&t,10);
158  s = t;
159  if (c==s)
160  return(true);
161  if (*s=='-' || *s==':') { /* range */
162  c=s+1;
163  ps_high = strtol(c,&t,10);
164  s = t;
165  if (c==s) ps_high=PAGE_MAXPAGE; /* no number */
166  }
167  }
169  while (*s==' ' || *s=='\t' || *s==',') s++;
170  }
171  return(false);
172 }
173 
174 /* Addition, we want to be able to clear the pplist */
175 void ClearPpList(void)
176 {
177  register struct pp_list *pl = ppages;
178 
179  while (pl) {
180  ppages=ppages->next;
181  free(pl);
182  pl = ppages;
183  }
186  abspage = false;
187  no_ppage=true;
188 }
189 
long __cdecl strtol(char const *_String, char **_EndPtr, int _Radix)
#define next(a)
Definition: aptex-macros.h:924
@ NextPage
Definition: dd.h:222
#define free(a)
Definition: decNumber.cpp:310
void Fatal()
struct rect data
Definition: dvipdfm.c:64
#define PAGE_MAXPAGE
Definition: dvipng.h:147
struct dvi_data * dvi
#define PAGE_LASTPAGE
Definition: dvipng.h:146
#define PAGE_FIRSTPAGE
Definition: dvipng.h:148
#define PAGE_MINPAGE
Definition: dvipng.h:149
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
#define c(n)
Definition: gpos-common.c:150
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
signed int int32_t
Definition: stdint.h:77
struct page_list * PrevPage(struct dvi_data *dvi, struct page_list *page)
Definition: dvi.c:414
struct page_list * FindPage(struct dvi_data *dvi, int32_t pagenum, boolean abspage)
Definition: dvi.c:420
#define malloc
Definition: alloca.c:91
struct pp_list * ppages
static boolean abspage
Definition: ppagelist.c:30
static boolean reverse
Definition: ppagelist.c:30
boolean InPageList(int32_t i)
Definition: ppagelist.c:98
boolean ParsePages(const char *s)
Definition: ppagelist.c:133
static int32_t last
Definition: ppagelist.c:29
static void ListPage(int32_t pslow, int32_t pshigh)
Definition: ppagelist.c:110
static int32_t first
Definition: ppagelist.c:29
void Reverse(boolean new)
Definition: ppagelist.c:49
void LastPage(int32_t page, boolean data)
Definition: ppagelist.c:44
void ClearPpList(void)
Definition: ppagelist.c:175
boolean no_ppage
Definition: ppagelist.c:31
struct page_list * NextPPage(void *dvi, struct page_list *page)
Definition: ppagelist.c:61
void FirstPage(int32_t page, boolean data)
Definition: ppagelist.c:39
Definition: mendex.h:14
struct pp_list * next
Definition: ppagelist.c:88
int32_t ps_low
Definition: ppagelist.c:89
int32_t ps_high
Definition: ppagelist.c:89
Definition: dvips.h:235
page
Definition: tex4ht.c:3916