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)  

counters.c
Go to the documentation of this file.
1 /* counters.c - Routines to access TeX variables that contain TeX counters
2 
3 Copyright (C) 2001-2002 The Free Software Foundation
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 This file is available from http://sourceforge.net/projects/latex2rtf/
20 */
21 
22 #include <stdlib.h>
23 #include <string.h>
24 #include "main.h"
25 #include "util.h"
26 #include "counters.h"
27 
28 #define MAX_COUNTERS 50
29 
30 struct {
31  char * name;
32  int number;
34 
35 static int iCounterCount = 0;
36 
37 static int
39 /**************************************************************************
40  purpose: checks to see if a named TeX counter exists
41  returns: the array index of the named TeX counter
42 **************************************************************************/
43 {
44  int i=0;
45 
46  while(i < iCounterCount && strstr(Counters[i].name,s)==NULL)
47  i++;
48 
49  if (i==iCounterCount)
50  return -1;
51  else
52  return i;
53 }
54 
55 static void
56 newCounter(char *s, int n)
57 /**************************************************************************
58  purpose: allocates and initializes a named TeX counter
59 **************************************************************************/
60 {
62  fprintf(stderr,"Too many counters, ignoring %s", s);
63  return;
64  }
65 
66  Counters[iCounterCount].number=n;
68 
70  fprintf(stderr, "\nCannot allocate name for counter \\%s\n", s);
71  exit(1);
72  }
73 
74  iCounterCount++;
75 }
76 
77 void
79 /**************************************************************************
80  purpose: increments a TeX counter (or initializes to 1)
81 **************************************************************************/
82 {
83  int i;
84  i = existsCounter(s);
85 
86  if (i<0)
87  newCounter(s, 1);
88  else
89  Counters[i].number++;
90 }
91 
92 void
93 setCounter(char * s, int n)
94 /**************************************************************************
95  purpose: allocates (if necessary) and sets a named TeX counter
96 **************************************************************************/
97 {
98  int i;
99  i = existsCounter(s);
100 
101  if (i<0)
102  newCounter(s, n);
103  else
104  Counters[i].number = n;
105 }
106 
107 int
108 getCounter(char * s)
109 /**************************************************************************
110  purpose: retrieves a named TeX counter
111 **************************************************************************/
112 {
113  int i;
114  i = existsCounter(s);
115 
116  if (i<0) {
117  fprintf(stderr, "No counter of type <%s>", s);
118  return 0;
119  }
120 
121  return Counters[i].number;
122 }
123 
#define strdup
Definition: Utility.h:167
#define n
Definition: t4ht.c:1290
static int iCounterCount
Definition: counters.c:35
static void newCounter(char *s, int n)
Definition: counters.c:56
struct @178 Counters[50]
char * name
Definition: counters.c:31
static int existsCounter(char *s)
Definition: counters.c:38
void incrementCounter(char *s)
Definition: counters.c:78
int number
Definition: counters.c:32
void setCounter(char *s, int n)
Definition: counters.c:93
int getCounter(char *s)
Definition: counters.c:108
#define MAX_COUNTERS
Definition: counters.c:28
#define s
Definition: afcover.h:80
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
char * strstr()
#define fprintf
Definition: mendex.h:64