Added a couple of files
This commit is contained in:
parent
28dbaf55a9
commit
5e77244e0f
160
ppthtml/ppthtml.h
Normal file
160
ppthtml/ppthtml.h
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
|
||||||
|
#ifndef PPTHTML_H
|
||||||
|
#define PPTHTML_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <vector.h>
|
||||||
|
|
||||||
|
#undef MAX
|
||||||
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
|
||||||
|
#define TYPE_STRING 0x1e /* 30, VT_LPSTR */
|
||||||
|
#define SUMMARY_ID(x) ((x) & 0xff)
|
||||||
|
|
||||||
|
typedef uint32_t OlePos;
|
||||||
|
typedef int32_t OleSPos;
|
||||||
|
typedef struct _List List;
|
||||||
|
typedef void* pointer;
|
||||||
|
typedef const void *gconstpointer;
|
||||||
|
typedef int gboolean;
|
||||||
|
|
||||||
|
/* definitions for vector array */
|
||||||
|
typedef vector ole_vector;
|
||||||
|
/** The initial size of a ole_vector. */
|
||||||
|
#define OLE_VECTOR_SIZE 10
|
||||||
|
/** The growth factor of a ole_vector. */
|
||||||
|
#define OLE_VECTOR_FACTOR 2
|
||||||
|
#define resize_ole_vector(v, size) \
|
||||||
|
vector_resize(v, size, sizeof(OleSummarySection))
|
||||||
|
#define create_ole_vector(v) \
|
||||||
|
vector_create(v, OLE_VECTOR_SIZE, sizeof(OleSummarySection))
|
||||||
|
#define destroy_ole_vector(v) \
|
||||||
|
vector_destroy(v)
|
||||||
|
#define append_ole(v, token) \
|
||||||
|
vector_append(v, token, 0, OLE_VECTOR_FACTOR)
|
||||||
|
#define insert_ole(v, token, pos) \
|
||||||
|
vector_insert(v, token, pos, 0, OLE_VECTOR_FACTOR)
|
||||||
|
#define insert_ole_space(v, pos, n) \
|
||||||
|
vector_insert_space(v, OleSummarySection, pos, n, 0, OLE_VECTOR_FACTOR)
|
||||||
|
#define ole_at(v, index) \
|
||||||
|
element_at(v, index, OleSummarySection)
|
||||||
|
#define ole_delete(v, pos) \
|
||||||
|
vector_delete(v, OleSummarySection, pos)
|
||||||
|
|
||||||
|
/* definitions for vector array */
|
||||||
|
typedef vector item_vector;
|
||||||
|
/** The initial size of a item_vector. */
|
||||||
|
#define ITEM_VECTOR_SIZE 10
|
||||||
|
/** The growth factor of a item_vector. */
|
||||||
|
#define ITEM_VECTOR_FACTOR 2
|
||||||
|
#define resize_item_vector(v, size) \
|
||||||
|
vector_resize(v, size, sizeof(item_t))
|
||||||
|
#define create_item_vector(v) \
|
||||||
|
vector_create(v, ITEM_VECTOR_SIZE, sizeof(item_t))
|
||||||
|
#define destroy_item_vector(v) \
|
||||||
|
vector_destroy(v)
|
||||||
|
#define append_item(v, token) \
|
||||||
|
vector_append(v, token, 0, ITEM_VECTOR_FACTOR)
|
||||||
|
#define insert_item(v, token, pos) \
|
||||||
|
vector_insert(v, token, pos, 0, ITEM_VECTOR_FACTOR)
|
||||||
|
#define insert_item_space(v, pos, n) \
|
||||||
|
vector_insert_space(v, item_t, pos, n, 0, ITEM_VECTOR_FACTOR)
|
||||||
|
#define item_at(v, index) \
|
||||||
|
element_at(v, index, item_t)
|
||||||
|
#define item_delete(v, pos) \
|
||||||
|
vector_delete(v, item_t, pos)
|
||||||
|
|
||||||
|
|
||||||
|
/* memory allocation functions */
|
||||||
|
|
||||||
|
#define allocate_mem(type, count) \
|
||||||
|
((type *) malloc((unsigned) sizeof (type) * (count)))
|
||||||
|
|
||||||
|
#define GET_UINT16(p) (uint16_t)(*((const uint8_t *)(p)+0) | \
|
||||||
|
(*((const uint8_t *)(p)+1)<<8))
|
||||||
|
|
||||||
|
#define GET_UINT32(p) (uint32_t)(*((const uint8_t *)(p)+0) | \
|
||||||
|
(*((const uint8_t *)(p)+1)<<8) | \
|
||||||
|
(*((const uint8_t *)(p)+2)<<16) | \
|
||||||
|
(*((const uint8_t *)(p)+3)<<24))
|
||||||
|
|
||||||
|
const uint32_t sum_fmtid[4] = {
|
||||||
|
0xF29F85E0,
|
||||||
|
0x10684FF9,
|
||||||
|
0x000891AB,
|
||||||
|
0xD9B3272B
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Property Set IDs
|
||||||
|
* The SummaryInformation stream contains the SummaryInformation property set.
|
||||||
|
* The DocumentSummaryInformation stream contains both the
|
||||||
|
* DocumentSummaryInformation and the UserDefined property sets as sections.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
OLE_PS_SUMMARY_INFO,
|
||||||
|
OLE_PS_DOCUMENT_SUMMARY_INFO,
|
||||||
|
OLE_PS_USER_DEFINED_SUMMARY_INFO
|
||||||
|
} PropertySetID;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
OLE_ERR_OK,
|
||||||
|
OLE_ERR_EXIST,
|
||||||
|
OLE_ERR_INVALID,
|
||||||
|
OLE_ERR_FORMAT,
|
||||||
|
OLE_ERR_PERM,
|
||||||
|
OLE_ERR_MEM,
|
||||||
|
OLE_ERR_SPACE,
|
||||||
|
OLE_ERR_NOTEMPTY,
|
||||||
|
OLE_ERR_BADARG
|
||||||
|
}OleErr;
|
||||||
|
|
||||||
|
/* SummaryInformation Stream Properties */
|
||||||
|
/* String properties */
|
||||||
|
typedef enum {
|
||||||
|
|
||||||
|
OLE_SUMMARY_TITLE = 0x1002,
|
||||||
|
OLE_SUMMARY_SUBJECT = 0x1003,
|
||||||
|
OLE_SUMMARY_AUTHOR = 0x1004,
|
||||||
|
OLE_SUMMARY_KEYWORDS = 0x1005,
|
||||||
|
OLE_SUMMARY_COMMENTS = 0x1006
|
||||||
|
|
||||||
|
} OleSummaryPID;
|
||||||
|
|
||||||
|
struct _List
|
||||||
|
{
|
||||||
|
pointer data;
|
||||||
|
List *next;
|
||||||
|
List *prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t class_id[16];
|
||||||
|
ole_vector * sections;
|
||||||
|
item_vector * items;
|
||||||
|
List * write_items;
|
||||||
|
gboolean read_mode;
|
||||||
|
COLEFILE *s;
|
||||||
|
PropertySetID ps_id;
|
||||||
|
} OleSummary;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t props;
|
||||||
|
uint32_t bytes;
|
||||||
|
PropertySetID ps_id;
|
||||||
|
} OleSummarySection;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t id;
|
||||||
|
PropertySetID ps_id;
|
||||||
|
} item_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
252
ppthtml/vector.h
Normal file
252
ppthtml/vector.h
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file vector.h
|
||||||
|
* @brief Functions for creating and manipulating vectors.
|
||||||
|
*
|
||||||
|
* A vector is an array that can be resized to meet changing storage
|
||||||
|
* requirements. Usage is typically as follows:
|
||||||
|
|
||||||
|
\include vector_test.c
|
||||||
|
|
||||||
|
|
||||||
|
*
|
||||||
|
* @author Jon Schutz
|
||||||
|
* @date 05-Feb-2001
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef __VECTOR_H
|
||||||
|
#define __VECTOR_H /* To stop multiple inclusions. */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/** Vector */
|
||||||
|
typedef struct _vector {
|
||||||
|
/** The array to hold the data. */
|
||||||
|
void *array;
|
||||||
|
/** The size of the array. */
|
||||||
|
size_t array_size;
|
||||||
|
/** The used size, assuming vector_append is the only operation
|
||||||
|
which adds elements to the vector. */
|
||||||
|
size_t index;
|
||||||
|
} vector;
|
||||||
|
|
||||||
|
|
||||||
|
/** Add a new item to the end of a vector.
|
||||||
|
|
||||||
|
@param v The vector to which to add an item.
|
||||||
|
@param item The item to add.
|
||||||
|
@param increment The capacity to add when the array is resized.
|
||||||
|
Should be >0, or at least =0 if factor>1.
|
||||||
|
@param factor The factor by which to increase storage when the array is
|
||||||
|
resized. Should be >1, or at least =1 if increment>0.
|
||||||
|
@return 0 on success, -1 if vector_resize() fails.
|
||||||
|
*/
|
||||||
|
#define vector_append(v, item, increment, factor) \
|
||||||
|
({ \
|
||||||
|
int rv=0; \
|
||||||
|
\
|
||||||
|
if ((v)->index >= (v)->array_size) \
|
||||||
|
rv = vector_resize((v), \
|
||||||
|
(v)->array_size * factor + increment, sizeof(item)); \
|
||||||
|
if (0 == rv) \
|
||||||
|
((typeof(item) *)(v)->array)[(v)->index++] = item; \
|
||||||
|
rv; \
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Insert space for several items into a vector at the given
|
||||||
|
position. No items are actually inserted.
|
||||||
|
|
||||||
|
If the given position exceeds the current end index of the array,
|
||||||
|
the new end index, then item is inserted before the specified
|
||||||
|
position and the end index points to the next position after the
|
||||||
|
inserted item.
|
||||||
|
|
||||||
|
If necessary, the vector is resized to accommodate the request.
|
||||||
|
|
||||||
|
@param v The vector to which to insert space.
|
||||||
|
@param item An instance or type of the items in the vector.
|
||||||
|
@param pos The position at which to insert space.
|
||||||
|
@param n The number of items for which to insert space.
|
||||||
|
@param increment The capacity to add when the array is resized.
|
||||||
|
Should be >0, or at least =0 if factor>1.
|
||||||
|
@param factor The factor by which to increase storage when the array is
|
||||||
|
resized. Should be >1, or at least =1 if increment>0.
|
||||||
|
@return 0 on success, -1 if vector_resize() fails.
|
||||||
|
*/
|
||||||
|
#define vector_insert_space(v, item, pos, n, increment, factor) \
|
||||||
|
({ \
|
||||||
|
int _rv=0; \
|
||||||
|
int new_end = ((pos)>(v)->index)?((pos)+(n)):((v)->index+(n)); \
|
||||||
|
if (new_end > (v)->array_size) { \
|
||||||
|
size_t new_size = (v)->array_size * factor + increment; \
|
||||||
|
if (new_end > new_size) \
|
||||||
|
new_size = new_end; \
|
||||||
|
_rv = vector_resize((v), new_size, sizeof(item)); \
|
||||||
|
} \
|
||||||
|
if (0 == _rv) { \
|
||||||
|
if ((v)->index > pos) { \
|
||||||
|
memmove(((char *)(v)->array) + sizeof(item)*((pos)+(n)), \
|
||||||
|
((char *)(v)->array) + sizeof(item)*(pos), \
|
||||||
|
sizeof(item)*((v)->index - pos)); \
|
||||||
|
(v)->index += (n); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
(v)->index = new_end; \
|
||||||
|
} \
|
||||||
|
_rv; \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/** Add a new item to the vector at a given position. The item is
|
||||||
|
inserted before the specified position.
|
||||||
|
|
||||||
|
If the given position exceeds the current end index of the array,
|
||||||
|
the new end index, the item is inserted before the specified
|
||||||
|
position and the end index points to the next position after the
|
||||||
|
inserted item.
|
||||||
|
|
||||||
|
If necessary, the vector is resized to accommodate the request.
|
||||||
|
|
||||||
|
@param v The vector to which to insert an item.
|
||||||
|
@param item The item to insert.
|
||||||
|
@param pos The position at which to insert the item.
|
||||||
|
@param increment The capacity to add when the array is resized.
|
||||||
|
Should be >0, or at least =0 if factor>1.
|
||||||
|
@param factor The factor by which to increase storage when the array is
|
||||||
|
resized. Should be >1, or at least =1 if increment>0.
|
||||||
|
@return 0 on success, -1 if vector_resize() fails.
|
||||||
|
*/
|
||||||
|
#define vector_insert(v, item, pos, increment, factor) \
|
||||||
|
({ \
|
||||||
|
const int c_pos = pos; \
|
||||||
|
int rv = vector_insert_space(v, item, pos, 1, increment, factor); \
|
||||||
|
if (0 == rv) { \
|
||||||
|
((typeof(item) *)(v)->array)[c_pos] = item; \
|
||||||
|
} \
|
||||||
|
rv; \
|
||||||
|
}) \
|
||||||
|
|
||||||
|
/** Delete several item from a vector.
|
||||||
|
|
||||||
|
@param v The vector in which to delete the item.
|
||||||
|
@param item An instance or type of the item to delete.
|
||||||
|
@param pos The first position at which to delete.
|
||||||
|
@param n The number of items to delete.
|
||||||
|
*/
|
||||||
|
#define vector_delete_n(v, item, pos, n) \
|
||||||
|
if ((v)->index > ((pos) + (n))) { \
|
||||||
|
memmove((v)->array + sizeof(item)*(pos), \
|
||||||
|
(v)->array + sizeof(item)*((pos)+(n)), \
|
||||||
|
sizeof(item)*((v)->index - (pos) - (n))); \
|
||||||
|
(v)->index -= (n); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
(v)->index = pos;
|
||||||
|
|
||||||
|
/** Delete an item from a vector.
|
||||||
|
|
||||||
|
@param v The vector in which to delete the item.
|
||||||
|
@param item An instance or type of the item to delete.
|
||||||
|
@param pos The position at which to delete.
|
||||||
|
*/
|
||||||
|
#define vector_delete(v, item, pos) \
|
||||||
|
vector_delete_n(v, item, pos, 1)
|
||||||
|
|
||||||
|
|
||||||
|
/** Access a member of a vector.
|
||||||
|
@param v The vector to access
|
||||||
|
@param index The index to read.
|
||||||
|
@param element_type The type name or an instance of the
|
||||||
|
type of which the vector is comprised.
|
||||||
|
|
||||||
|
@return v[index]
|
||||||
|
*/
|
||||||
|
#define element_at(v, index, element_type) \
|
||||||
|
(((typeof(element_type) *)(v)->array)[index])
|
||||||
|
|
||||||
|
/** Reverse items in a vector.
|
||||||
|
@param v The vector in which to reverse items.
|
||||||
|
@param item The type name or an instance of the
|
||||||
|
type of which the vector is comprised.
|
||||||
|
@param start The starting index of the sequence to be reversed.
|
||||||
|
@param end The index following the end of the sequence to be
|
||||||
|
reversed.
|
||||||
|
*/
|
||||||
|
#define vector_reverse(v, item, start, end) { \
|
||||||
|
int _i; \
|
||||||
|
int _half = (end-start)/2; \
|
||||||
|
typeof(item) _temp; \
|
||||||
|
for (_i=0; _i<_half; _i++) { \
|
||||||
|
_temp = element_at(v, (start)+_i, item); \
|
||||||
|
element_at(v, (start)+_i, item) = element_at(v, (end)-_i-1, item); \
|
||||||
|
element_at(v, (end)-_i-1, item) = _temp; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
int vector_resize(vector *v, size_t size, size_t element_size);
|
||||||
|
int vector_create(vector *v, size_t size, size_t element_size);
|
||||||
|
void vector_destroy(vector *v);
|
||||||
|
|
||||||
|
|
||||||
|
/** Finds the next unused slot in a vector, by comparing the contents
|
||||||
|
* of a given \a field with \a thing that indicates a free slot.
|
||||||
|
*
|
||||||
|
* @param v The vector to search through.
|
||||||
|
* @param item The type of data held by the vector.
|
||||||
|
* @param field A field of a struct which is held in the vector's array.
|
||||||
|
* @param thing If the contents of the above field match this thing, we
|
||||||
|
* have found an unused slot.
|
||||||
|
*
|
||||||
|
* @return the index of the first unused slot.
|
||||||
|
**/
|
||||||
|
#define vector_find_next_free_slot(v, item, field, thing) \
|
||||||
|
({ \
|
||||||
|
int i = 0; \
|
||||||
|
if ((NULL != (v)->array) && (0 < (v)->index)) \
|
||||||
|
for (i = 0; i < (v)->index; i++) \
|
||||||
|
if (thing == ((typeof(item) *)(v)->array)[i]field) \
|
||||||
|
break; \
|
||||||
|
i; \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a \a token of type \a item into \a v, in the first location in
|
||||||
|
* \a v whose \a field matches \a thing. If all \a v->index slots in \a
|
||||||
|
* v are in use, a new element is inserted at the end of the vector and
|
||||||
|
* \a v->index is incremented, otherwise, \a token is inserted at the
|
||||||
|
* first available slot, and \a v->index is left unchanged. An
|
||||||
|
* extension of the "vector" class, which can be used when
|
||||||
|
* "vector_delete" is not suitable (e.g. if the index into the vector
|
||||||
|
* is being remembered by external software, then vector_delete will not
|
||||||
|
* work, because it deletes from the middle of a vector and moves all
|
||||||
|
* the top entries down to fill the vacated slot(s)).
|
||||||
|
*
|
||||||
|
* @param v Vector into which we will insert the token.
|
||||||
|
* @param token The object to store in the vector.
|
||||||
|
* @param item The data-type of the token that we're inserting.
|
||||||
|
* @param size The size of the token that we're inserting.
|
||||||
|
* @param field A field of a struct which is held in the vector's array.
|
||||||
|
* (May be empty if not using a struct).
|
||||||
|
* @param thing If the contents of the above field match this thing, we
|
||||||
|
* have found an unused slot.
|
||||||
|
*
|
||||||
|
* @return The location of the slot in the vector where the data was
|
||||||
|
* stored.
|
||||||
|
**/
|
||||||
|
#define vector_store(v, token, item, size,field, thing) \
|
||||||
|
({ \
|
||||||
|
int pos = vector_find_next_free_slot(v, item,field, thing); \
|
||||||
|
if (pos == (v)->index) \
|
||||||
|
/* Increment (v)->index */ \
|
||||||
|
vector_append((v), token, size, 1); \
|
||||||
|
else \
|
||||||
|
/* Ignore (v)->index */ \
|
||||||
|
element_at((v), pos, item) = token; \
|
||||||
|
pos; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#endif /* __VECTOR_H */
|
Loading…
Reference in New Issue
Block a user