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)  

lengths.c
Go to the documentation of this file.
1 /* lengths.c - commands that access TeX variables that contain TeX lengths
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 Authors:
22  2001-2002 Scott Prahl
23 
24 By convention all the values stored should be twips 20 twips = 1 pt
25 */
26 
27 #include <stdlib.h>
28 #include <string.h>
29 #include "main.h"
30 #include "util.h"
31 #include "lengths.h"
32 #include "parser.h"
33 
34 #define MAX_LENGTHS 50
35 
36 struct {
37  char * name;
38  int distance;
40 
41 static int iLengthCount = 0;
42 
43 static int
44 existsLength(char * s)
45 /**************************************************************************
46  purpose: checks to see if a named TeX dimension exists
47  returns: the array index of the named TeX dimension
48 **************************************************************************/
49 {
50  int i=0;
51 
52  while(i < iLengthCount && strstr(Lengths[i].name,s)==NULL)
53  i++;
54 
55  if (i==iLengthCount)
56  return -1;
57  else
58  return i;
59 }
60 
61 static void
62 newLength(char *s, int d)
63 /**************************************************************************
64  purpose: allocates and initializes a named TeX dimension
65 **************************************************************************/
66 {
68  diagnostics(WARNING__,"Too many lengths, ignoring %s", s);
69  return;
70  }
71 
72  Lengths[iLengthCount].distance=d;
73  Lengths[iLengthCount].name=strdup(s);
74 
75  if (Lengths[iLengthCount].name==NULL) {
76  fprintf(stderr, "\nCannot allocate name for length \\%s\n", s);
77  exit(1);
78  }
79 
80  iLengthCount++;
81 }
82 
83 void
84 setLength(char * s, int d)
85 /**************************************************************************
86  purpose: allocates (if necessary) and sets a named TeX dimension
87 **************************************************************************/
88 {
89  int i;
90  i = existsLength(s);
91 
92  if (i<0)
93  newLength(s, d);
94  else
95  Lengths[i].distance = d;
96 }
97 
98 int
99 getLength(char * s)
100 /**************************************************************************
101  purpose: retrieves a named TeX dimension
102 **************************************************************************/
103 {
104  int i;
105  i = existsLength(s);
106 
107  if (i<0) {
108  diagnostics(WARNING__, "No length of type %s", s);
109  return 0;
110  }
111 
112  return Lengths[i].distance;
113 }
114 
115 void
117 {
118  int d;
119  char c;
120 
121  c = getNonSpace();
122  if (c == '=') /* optional '=' */
123  skipSpaces();
124  else
125  ungetTexChar(c);
126 
127  d = getDimension();
128  diagnostics(4, "CmdSetTexLength size = %d",d);
129 
130  switch (code){
131 
132  case SL_HOFFSET:
133  setLength("hoffset",d);
134  break;
135  case SL_VOFFSET:
136  setLength("voffset",d);
137  break;
138  case SL_PARINDENT:
139  setLength("parindent",d);
140  break;
141  case SL_PARSKIP:
142  setLength("parskip",d);
143  break;
144  case SL_BASELINESKIP:
145  setLength("baselineskip",d);
146  break;
147  case SL_TOPMARGIN:
148  setLength("topmargin",d);
149  break;
150  case SL_TEXTHEIGHT:
151  setLength("textheight",d);
152  break;
153  case SL_HEADHEIGHT:
154  setLength("headheight",d);
155  break;
156  case SL_HEADSEP:
157  setLength("headsep",d);
158  break;
159  case SL_TEXTWIDTH:
160  setLength("textwidth",d);
161  break;
162  case SL_ODDSIDEMARGIN:
163  setLength("oddsidemargin",d);
164  break;
165  case SL_EVENSIDEMARGIN:
166  setLength("evensidemargin",d);
167  break;
168  }
169 }
#define strdup
Definition: Utility.h:167
#define s
Definition: afcover.h:80
#define c(n)
Definition: gpos-common.c:150
#define d(n)
Definition: gpos-common.c:151
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
void exit()
char * strstr()
void diagnostics(int level, char *format,...)
Definition: main.c:469
#define WARNING__
Definition: main.h:32
#define fprintf
Definition: mendex.h:64
void skipSpaces(void)
char getNonSpace(void)
void ungetTexChar(char c)
int getDimension(void)
struct @182 Lengths[50]
static int existsLength(char *s)
Definition: lengths.c:44
#define MAX_LENGTHS
Definition: lengths.c:34
void CmdSetTexLength(int code)
Definition: lengths.c:116
int getLength(char *s)
Definition: lengths.c:99
char * name
Definition: lengths.c:37
static void newLength(char *s, int d)
Definition: lengths.c:62
void setLength(char *s, int d)
Definition: lengths.c:84
static int iLengthCount
Definition: lengths.c:41
int distance
Definition: lengths.c:38
#define SL_VOFFSET
Definition: lengths.h:2
#define SL_EVENSIDEMARGIN
Definition: lengths.h:12
#define SL_HEADHEIGHT
Definition: lengths.h:8
#define SL_PARINDENT
Definition: lengths.h:3
#define SL_TEXTWIDTH
Definition: lengths.h:10
#define SL_PARSKIP
Definition: lengths.h:4
#define SL_HOFFSET
Definition: lengths.h:1
#define SL_TOPMARGIN
Definition: lengths.h:6
#define SL_BASELINESKIP
Definition: lengths.h:5
#define SL_TEXTHEIGHT
Definition: lengths.h:7
#define SL_HEADSEP
Definition: lengths.h:9
#define SL_ODDSIDEMARGIN
Definition: lengths.h:11
Definition: inftrees.h:24