dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/image winres_writer.c, NONE, 1.1 Makefil


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/image winres_writer.c, NONE, 1.1 Makefile.am, 1.16, 1.17 image.h, 1.28, 1.29 winres_reader.c, 1.2, 1.3
Date: Tue, 08 Jul 2003 20:53:25 -0400

Update of /cvsroot/dotgnu-pnet/pnet/image
In directory subversions:/tmp/cvs-serv10981/image

Modified Files:
        Makefile.am image.h winres_reader.c 
Added Files:
        winres_writer.c 
Log Message:


Put some of the support code in place for writing win32 resources
and icons (not complete yet).


--- NEW FILE ---
/*
 * winres_writer.c - Write the data in the ".rsrc" section of an IL binary.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * 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 General Public License for more details.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "image.h"

#ifdef  __cplusplus
extern  "C" {
#endif

ILResourceSection *ILResourceSectionCreateWriter(ILImage *image)
{
        ILResourceSection *section;
        section = (ILResourceSection *)ILMalloc(sizeof(ILResourceSection));
        if(section)
        {
                section->image = image;
                section->data = 0;
                section->length = 0;
                section->rootDirectory = (ILResourceEntry *)
                        ILMalloc(sizeof(ILResourceEntry));
                if(!(section->rootDirectory))
                {
                        ILFree(section);
                        return 0;
                }
                section->rootDirectory->isDirectory = 1;
                section->rootDirectory->isMallocData = 0;
                section->rootDirectory->isNumeric = 0;
                section->rootDirectory->name = 0;
                section->rootDirectory->nameLen = 0;
                section->rootDirectory->children = 0;
                section->rootDirectory->next = 0;
                section->rootDirectory->data = 0;
                section->rootDirectory->length = 0;
        }
        return section;
}

/*
 * Insert an entry into the resource tree, with a specific name.
 */
static void *InsertEntry(ILResourceEntry *parent, ILResourceEntry *prev,
                                                 const char *name)
{
        /* TODO */
        return 0;
}

void *ILResourceSectionAddEntry(ILResourceSection *section, const char *name)
{
        ILResourceEntry *parent;
        ILResourceEntry *entry;
        ILResourceEntry *prev;
        int posn, cmp;

        /* Search down the hierarchy for the specified entry */
        entry = section->rootDirectory;
        parent = entry;
        prev = 0;
        while(entry != 0)
        {
                if(*name == '/')
                {
                        ++name;
                        continue;
                }
                else if(*name == '\0')
                {
                        break;
                }
                posn = 0;
                while(name[posn] != '\0' && name[posn] != '/')
                {
                        ++posn;
                }
                parent = entry;
                entry = entry->children;
                prev = 0;
                while(entry != 0)
                {
                        if(entry->nameLen == posn)
                        {
                                cmp = ILStrNICmp(entry->name, name, posn);
                        }
                        else if(entry->nameLen < posn)
                        {
                                cmp = ILStrNICmp(entry->name, name, 
entry->nameLen);
                                if(!cmp)
                                {
                                        cmp = -1;
                                }
                        }
                        else
                        {
                                cmp = ILStrNICmp(entry->name, name, posn);
                                if(!cmp)
                                {
                                        cmp = 1;
                                }
                        }
                        if(!cmp)
                        {
                                /* Go down a level: we already have this name */
                                break;
                        }
                        else if(cmp < 0)
                        {
                                /* This is where we need to insert the new 
entry */
                                return InsertEntry(parent, prev, name);
                        }
                        prev = entry;
                        entry = entry->next;
                }
                if(!entry)
                {
                        /* Insert the new entry at the end of the current level 
*/
                        return InsertEntry(parent, prev, name);
                }
                name += posn;
        }

        /* We already have a leaf entry with this name */
        return entry;
}

int ILResourceSectionAddBytes(void *entry, const void *buffer, int len)
{
        /* TODO */
        return 1;
}

void ILResourceSectionFlush(ILResourceSection *section, ILWriter *writer)
{
        /* TODO */
}

#ifdef  __cplusplus
};
#endif

Index: Makefile.am
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/Makefile.am,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** Makefile.am 7 Jul 2003 12:44:50 -0000       1.16
--- Makefile.am 9 Jul 2003 00:53:21 -0000       1.17
***************
*** 40,43 ****
--- 40,44 ----
                                           uncompress.c \
                                           winres_reader.c \
+                                          winres_writer.c \
                                           writer.c
  

Index: image.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/image.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** image.h     7 Jul 2003 12:44:50 -0000       1.28
--- image.h     9 Jul 2003 00:53:21 -0000       1.29
***************
*** 232,235 ****
--- 232,265 ----
  
  /*
+  * Information about a resource entry.
+  */
+ typedef struct _tagILResourceEntry ILResourceEntry;
+ struct _tagILResourceEntry
+ {
+       int                                     isDirectory : 1;
+       int                                     isMallocData : 1;
+       int                                     isNumeric : 1;
+       char                       *name;
+       int                                     nameLen;
+       ILResourceEntry    *children;
+       ILResourceEntry    *next;
+       unsigned char      *data;
+       unsigned long           length;
+ 
+ };
+ 
+ /*
+  * Information about the resource section.
+  */
+ struct _tagILResourceSection
+ {
+       ILImage                    *image;
+       unsigned char      *data;
+       unsigned long           length;
+       ILResourceEntry    *rootDirectory;
+ 
+ };
+ 
+ /*
   * Subclass of ILImage which is used when building an image in memory.
   */
***************
*** 375,379 ****
  };
  
! #endif /* !REDUCED_STDIO */
  
  /*
--- 405,409 ----
  };
  
! #endif /* IL_USE_WRITER */
  
  /*

Index: winres_reader.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/winres_reader.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** winres_reader.c     8 Jul 2003 10:14:38 -0000       1.2
--- winres_reader.c     9 Jul 2003 00:53:22 -0000       1.3
***************
*** 26,57 ****
  
  /*
-  * Information about a resource entry.
-  */
- typedef struct _tagILResourceEntry ILResourceEntry;
- struct _tagILResourceEntry
- {
-       int                                     isDirectory;
-       char                       *name;
-       int                                     nameLen;
-       ILResourceEntry    *children;
-       ILResourceEntry    *next;
-       unsigned char      *data;
-       unsigned long           length;
- 
- };
- 
- /*
-  * Information about the resource section.
-  */
- struct _tagILResourceSection
- {
-       ILImage                    *image;
-       unsigned char      *data;
-       unsigned long           length;
-       ILResourceEntry    *rootDirectory;
- 
- };
- 
- /*
   * Read the name of a resource from the resource section.
   */
--- 26,29 ----
***************
*** 116,119 ****
--- 88,95 ----
                current = next;
        }
+       if(entry->isMallocData && entry->data)
+       {
+               ILFree(entry->data);
+       }
        ILFree(entry);
  }
***************
*** 139,144 ****
        }
        entry->isDirectory = 0;
        entry->name = name;
!       entry->nameLen = strlen(name);
        entry->children = 0;
        entry->next = 0;
--- 115,122 ----
        }
        entry->isDirectory = 0;
+       entry->isMallocData = 0;
+       entry->isNumeric = 0;
        entry->name = name;
!       entry->nameLen = (name ? strlen(name) : 0);
        entry->children = 0;
        entry->next = 0;
***************
*** 190,193 ****
--- 168,173 ----
        }
        dir->isDirectory = 1;
+       dir->isMallocData = 0;
+       dir->isNumeric = 0;
        dir->name = name;
        dir->children = 0;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]