diff options
Diffstat (limited to 'Build/source/texk/dvipng/dvi.c')
-rw-r--r-- | Build/source/texk/dvipng/dvi.c | 99 |
1 files changed, 30 insertions, 69 deletions
diff --git a/Build/source/texk/dvipng/dvi.c b/Build/source/texk/dvipng/dvi.c index 24814dbc3e4..811f8ed64f7 100644 --- a/Build/source/texk/dvipng/dvi.c +++ b/Build/source/texk/dvipng/dvi.c @@ -4,21 +4,22 @@ Part of the dvipng distribution - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/>. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. - Copyright (C) 2002-2008 Jan-Åke Larsson + Copyright (C) 2002-2006 Jan-Åke Larsson ************************************************************************/ @@ -93,7 +94,6 @@ void DVIInit(struct dvi_data* dvi) fstat(fileno(dvi->filep), &stat); dvi->mtime = stat.st_mtime; dvi->pagelistp=NULL; - dvi->flags = 0; } struct dvi_data* DVIOpen(char* dviname,char* outname) @@ -169,17 +169,12 @@ unsigned char* DVIGetCommand(struct dvi_data* dvi) /* Mmap is not appropriate here, we may want to read from half-written files. */ { - static unsigned char* command=NULL; - static uint32_t commlen=0; + static unsigned char command[STRSIZE]; + static unsigned char* lcommand = command; unsigned char *current = command; int length; uint32_t strlength=0; - if (commlen==0) { - commlen=STRSIZE; - if ((current=command=malloc(commlen))==NULL) - Fatal("cannot allocate memory for DVI command"); - } DEBUG_PRINT(DEBUG_DVI,("\n@%ld ", ftell(dvi->filep))); *(current++) = fgetc_follow(dvi->filep); length = dvi_commandlength[*command]; @@ -187,7 +182,7 @@ unsigned char* DVIGetCommand(struct dvi_data* dvi) Fatal("undefined DVI op-code %d",*command); while(current < command+length) *(current++) = fgetc_follow(dvi->filep); - switch (*command) { + switch (*command) { case XXX4: strlength = *(current - 4); case XXX3: @@ -205,57 +200,24 @@ unsigned char* DVIGetCommand(struct dvi_data* dvi) break; } if (strlength > 0) { /* Read string */ - if (strlength+1 + (uint32_t)length > commlen) { + if (lcommand!=command) { + free(lcommand); + lcommand=command; + } + if (strlength + (uint32_t)length > (uint32_t)STRSIZE) { /* string + command length exceeds that of buffer */ - commlen=strlength+1 + (uint32_t)length; - if ((command=realloc(command,commlen))==NULL) + if ((lcommand=malloc(length+strlength+1))==NULL) Fatal("cannot allocate memory for DVI command"); - current = command + length; + memcpy(lcommand,command,length); + current = lcommand + length; } - while(current < command+length+strlength) + while(current < lcommand+length+strlength) *(current++) = fgetc_follow(dvi->filep); - *current='\0'; - } - return(command); + return(lcommand); + } else + return(command); } -bool DVIIsNextPSSpecial(struct dvi_data* dvi) - /* This function checks if the next dvi command is a raw PS - special */ - /* Mmap is not appropriate here, we may want to read from - half-written files. */ -{ - long fpos; - uint32_t strlength=0; - bool israwps=false; - - DEBUG_PRINT(DEBUG_DVI,("\n CHECKING NEXT DVI COMMAND ")); - fpos=ftell(dvi->filep); - switch (fgetc_follow(dvi->filep)) { - case XXX4: - strlength = fgetc_follow(dvi->filep); - case XXX3: - strlength = strlength * 256 + fgetc_follow(dvi->filep); - case XXX2: - strlength = strlength * 256 + fgetc_follow(dvi->filep); - case XXX1: - strlength = strlength * 256 + fgetc_follow(dvi->filep); - } - if (strlength > 0) { - switch(fgetc_follow(dvi->filep)) { - case 'p': - if (strlength > 2 - && fgetc_follow(dvi->filep)=='s' - && fgetc_follow(dvi->filep)==':') - israwps=true; - break; - case '"': - israwps=true; - } - } - fseek(dvi->filep,fpos,SEEK_SET); - return(israwps); -} uint32_t CommandLength(unsigned char* command) { @@ -292,7 +254,9 @@ void SkipPage(struct dvi_data* dvi) case XXX1: case XXX2: case XXX3: case XXX4: DEBUG_PRINT(DEBUG_DVI,("NOSKIP CMD:\t%s %d", dvi_commands[*command], UNumRead(command+1, dvi_commandlength[*command]-1))); - SetSpecial((char*)command + dvi_commandlength[*command],0,0); + SetSpecial((char*)command + dvi_commandlength[*command], + UNumRead(command+1, dvi_commandlength[*command]-1), + 0,0); break; case BOP: case PRE: case POST: case POST_POST: Fatal("%s occurs within page", dvi_commands[*command]); @@ -330,8 +294,7 @@ struct page_list* InitPage(struct dvi_data* dvi) command=DVIGetCommand(dvi); } if ((tpagelistp = - malloc(sizeof(struct page_list) - +(csp+1-2)*sizeof(struct dvi_color)))==NULL) + malloc(sizeof(struct page_list)+(csp+1-2)*sizeof(struct dvi_color)))==NULL) Fatal("cannot allocate memory for new page entry"); tpagelistp->next = NULL; if ( *command == BOP ) { /* Init page */ @@ -447,7 +410,6 @@ void DVIClose(struct dvi_data* dvi) if (dvi!=NULL) { fclose(dvi->filep); DelPageList(dvi); - ClearPSHeaders(); free(dvi->outname); free(dvi->name); free(dvi); @@ -462,7 +424,6 @@ bool DVIReOpen(struct dvi_data* dvi) fclose(dvi->filep); dvi->filep=NULL; DelPageList(dvi); - ClearPSHeaders(); while(((dvi->filep = fopen(dvi->name,"rb")) == NULL) && followmode) { SLEEP; } |