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)  

enc.c
Go to the documentation of this file.
1 /* enc.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-2008 Jan-Åke Larsson
22 
23 ************************************************************************/
24 
25 #include "dvipng.h"
26 
28 
29 static struct encoding* InitEncoding(char* encoding)
30 {
31  char *pos,*max,*buf,*enc_file;
32  int i;
33  struct encoding* encp=NULL;
34  struct filemmap fmmap;
35  boolean mmapfailed;
36 
37 #ifdef HAVE_KPSE_ENC_FORMATS
38  enc_file=kpse_find_file(encoding,kpse_enc_format,false);
39 #else
40  enc_file=kpse_find_file(encoding,kpse_tex_ps_header_format,false);
41 #endif
42  if (enc_file == NULL) {
43  Warning("encoding file %s could not be found",encoding);
44  return(NULL);
45  }
46  DEBUG_PRINT((DEBUG_FT|DEBUG_ENC),("\n OPEN ENCODING:\t'%s'", enc_file));
47  mmapfailed = MmapFile(enc_file,&fmmap);
48  free(enc_file);
49  if (mmapfailed)
50  return(NULL);
51  if ((encp = calloc(sizeof(struct encoding)+strlen(encoding)+1
52  +fmmap.size,1))==NULL) {
53  Warning("cannot alloc space for encoding",encoding);
54  UnMmapFile(&fmmap);
55  return(NULL);
56  }
57  encp->name=(char*)encp+sizeof(struct encoding);
58  strcpy(encp->name,encoding);
59  pos=fmmap.data;
60  max=fmmap.data+fmmap.size;
61  buf=encp->name+strlen(encoding)+1;
62 #define SKIPCOMMENT(x) if (*x=='%') while (x<max && *x!='\r' && *x!='\n') x++;
63  while(pos<max && *pos!='/') {
65  pos++;
66  }
67  pos++;
68  encp->charname[256]=buf;
69  while(pos<max && *pos!='[' && *pos!='%'
70  && *pos!=' ' && *pos!='\t' && *pos!='\r' && *pos!='\n')
71  *buf++=*pos++;
72  *buf++='\0';
73  DEBUG_PRINT(DEBUG_ENC,("\n PS ENCODING '%s'",
74  encp->charname[256]));
75  while (pos < max && *pos!='[') {
77  pos++;
78  }
79  while(pos<max && *pos!='/') {
81  pos++;
82  }
83  i=0;
84  while(pos<max && *pos!=']') {
85  pos++;
86  encp->charname[i++]=buf;
87  while(pos<max && *pos!='%' && *pos!=' ' \
88  && *pos!='\t' && *pos!='\r' && *pos!='\n')
89  *buf++=*pos++;
90  *buf++='\0';
91  DEBUG_PRINT(DEBUG_ENC,("\n PS ENCODING %d '%s'",
92  i-1,encp->charname[i-1]));
93  while(pos<max && *pos!='/' && *pos!=']') {
95  pos++;
96  }
97  }
98  UnMmapFile(&fmmap);
99  return(encp);
100 }
101 
102 
104 {
105  struct encoding *temp=encodingp;
106 
107  /* printf("{%s} \n",encoding); */
108  while(temp!=NULL && strcmp(encoding,temp->name)!=0)
109  temp=temp->next;
110  if (temp==NULL) {
112  if (temp!=NULL) {
113  temp->next=encodingp;
114  encodingp=temp;
115  }
116  }
117  return(temp);
118 }
119 
120 void ClearEncoding(void)
121 {
122  struct encoding *temp=encodingp;
123 
124  while(temp!=NULL) {
126  free(temp);
127  temp=encodingp;
128  }
129 }
@ kpse_enc_format
Definition: afm2pl.c:372
#define free(a)
Definition: decNumber.cpp:310
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
#define DEBUG_PRINT(str)
Definition: dvi2xx.h:670
int strcmp()
Definition: coll.cpp:143
char * strcpy()
char * temp
Definition: dvidvi.c:137
#define DEBUG_FT
Definition: dvipng.h:420
#define DEBUG_ENC
Definition: dvipng.h:421
void UnMmapFile(struct filemmap *fmmap)
Definition: misc.c:829
boolean MmapFile(char *filename, struct filemmap *fmmap)
Definition: misc.c:766
static struct encoding * InitEncoding(char *encoding)
Definition: enc.c:29
struct encoding * FindEncoding(char *encoding)
Definition: enc.c:103
void ClearEncoding(void)
Definition: enc.c:120
struct encoding * encodingp
Definition: enc.c:27
#define SKIPCOMMENT(x)
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
voidp calloc()
static FILE * enc_file
Definition: writet1.c:226
#define buf
@ kpse_tex_ps_header_format
Definition: types.h:133
const int * pos
Definition: combiners.h:905
#define max(a, b)
Definition: pbmto4425.c:11
char * charname[257]
Definition: dvipng.h:216
const char * name
Definition: afm2pl.c:168
struct encoding * next
Definition: dvipng.h:214
size_t size
Definition: dvipng.h:191
char * data
Definition: dvipng.h:190
*job_name strlen((char *) job_name) - 4)