Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[e8a4ca]: mcload.c Maximize Restore History

Download this file

mcload.c    126 lines (110 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* mcload.c
*
* $Id$
*
* Copyright (C) 2006, Keith Marshall
*
* This file implements the `mc_load' function, which is used by `gencat'
* to load the messages from an existing message catalogue, reconstructing
* the original internal dictionary structure from which it was compiled.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
* Last modification: 30-Dec-2006
*
*
* This is free software. It is provided AS IS, in the hope that it may
* be useful, but WITHOUT WARRANTY OF ANY KIND, not even an IMPLIED WARRANTY
* of MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE.
*
* Permission is granted to redistribute this software, either "as is" or
* in modified form, under the terms of the GNU General Public License, as
* published by the Free Software Foundation; either version 2, or (at your
* option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to the
* Free Software Foundation, 51 Franklin St - Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <gencat.h>
#include <msgcat.h>
#include <mctab.h>
#include <platform.h>
#define mkptr(TYPE,PTR,OFFSET) (TYPE)((char *)(PTR) + (OFFSET))
struct msgdict *mc_load( const char *name )
{
int fd;
struct stat catinfo;
struct msgdict *retptr = NULL;
errno = 0;
if( ((fd = mc_validate( name )) >= 0)
&& ((fstat( fd, &catinfo ) == 0))
&& ((catinfo.st_size > MINGW32_CATGETS_ST_SIZE_MIN))
&& ((retptr = mc_malloc( sizeof( struct msgdict ))) != NULL)
&& ((retptr->base = mc_malloc( catinfo.st_size )) != NULL)
&& ((read( fd, retptr->base, catinfo.st_size ) == catinfo.st_size)) )
{
struct msgdict *this = retptr;
struct key *setptr = ((MSGCAT *)(this->base))->mc.index;
int numsets = mkptr( struct key *, this->base, setptr->offset ) - setptr;
struct key *msgptr = setptr + numsets;
/* All initial message dictionary entries have `lineno' field set to zero,
* indicating their source to be the named message catalogue being updated.
*/
retptr->lineno = 0;
/* Step through all message sets listed in the index...
*/
while( numsets-- )
{
int msgcount;
this->set = setptr++->setnum;
msgcount = mkptr( struct key *, this->base, setptr->offset ) - msgptr;
while( msgcount-- )
{
this->msg = msgptr->msgnum;
this->loc = msgptr++->offset;
if( numsets | msgcount )
{
if( (this->link = mc_malloc( sizeof( struct msgdict ))) == NULL )
{
for( this = retptr; this != NULL; this = retptr )
{
retptr = this->link;
if( (retptr == NULL) && (this->base != NULL) )
free( this->base );
free( this );
}
return NULL;
}
*(this->link) = *this;
this->len = msgptr->offset - this->loc;
this = this->link;
}
else
{
this->len = catinfo.st_size - this->loc;
this->link = NULL;
}
}
}
close( fd );
}
else if( retptr != NULL )
{
if( retptr->base != NULL )
free( retptr->base );
free( retptr );
retptr = NULL;
}
return retptr;
}
/* $RCSfile$Revision$: end of file */