Skip to content

Commit

Permalink
starting to get some output
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed Dec 5, 2014
1 parent 52ec7a2 commit cc9331a
Show file tree
Hide file tree
Showing 10 changed files with 508 additions and 219 deletions.
23 changes: 22 additions & 1 deletion msoleps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"

"github.com/richardlehane/msoleps/sets"
"github.com/richardlehane/msoleps/types"
)

Expand Down Expand Up @@ -82,6 +83,26 @@ func (r *Reader) start(rdr io.Reader) error {
plen += len(psb.idsOffs)
}
r.Property = make([]*Property, plen)
var dict map[uint32]string
if r.pSetStream.FmtidA == types.MustGuidFromString("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}") {
dict = sets.SummaryInformation.Dict
} else {
dict = ps.dict
if dict == nil {
dict = make(map[uint32]string)
}
}
for i, v := range ps.idsOffs {
r.Property[i] = &Property{}
r.Property[i].Name = dict[v.id]
t, _ := types.Evaluate(r.buf[int(v.offset+r.pSetStream.OffsetA):])
if t.Type() == "CodeString" {
cs := t.(*types.CodeString)
cs.SetId(ps.code)
t = types.Type(cs)
}
r.Property[i].T = t
}
return nil
}

Expand All @@ -100,7 +121,7 @@ func (r *Reader) getPropertySet(o uint32) (*propertySet, error) {
dictOff = pSet.idsOffs[i].offset
case 0x00000001:
off := int(pSet.idsOffs[i].offset + o)
pSet.code = types.CodePageID(binary.LittleEndian.Uint16(r.buf[off : off+2]))
pSet.code = types.CodePageID(binary.LittleEndian.Uint16(r.buf[off+4 : off+6]))
}
}
if dictOff > 0 {
Expand Down
4 changes: 4 additions & 0 deletions msoleps_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package msoleps

import (
"fmt"
"os"
"testing"
)
Expand All @@ -18,6 +19,9 @@ func testFile(t *testing.T, path string) *Reader {
if err != nil {
t.Errorf("Error opening file; Returns error: ", err)
}
for _, prop := range doc.Property {
fmt.Printf("%s: %s\n", prop.Name, prop)
}
return doc
}

Expand Down
15 changes: 8 additions & 7 deletions property.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package msoleps
import "github.com/richardlehane/msoleps/types"

type Property struct {
Name string
FMTID types.Guid
sz int
raw []byte
types.Type
Name string
T types.Type
}

func (p *Property) Bytes() []byte {
return p.raw[:p.sz]
func (p *Property) String() string {
return p.T.String()
}

func (p *Property) Type() string {
return p.T.Type()
}

type propertySetStream struct {
Expand Down
9 changes: 2 additions & 7 deletions sets/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package sets

import "github.com/richardlehane/msoleps/types"

type IDName struct {
ID uint32
Name string
}

type PropertySetDef struct {
FMTID types.Guid
IDNames []IDName
FMTID types.Guid
Dict map[uint32]string
}
38 changes: 19 additions & 19 deletions sets/summaryInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import "github.com/richardlehane/msoleps/types"

var SummaryInformation = PropertySetDef{
types.MustGuidFromString("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"),
[]IDName{
IDName{0x00000002, "Title"},
IDName{0x00000003, "Subject"},
IDName{0x00000004, "Author"},
IDName{0x00000005, "Keywords"},
IDName{0x00000006, "Comments"},
IDName{0x00000007, "Template"},
IDName{0x00000008, "LastAuthor"},
IDName{0x00000009, "RevNumber"},
IDName{0x0000000A, "EditTime"},
IDName{0x0000000B, "LastPrinted"},
IDName{0x0000000C, "CreateTime"},
IDName{0x0000000D, "LastSaveTime"},
IDName{0x0000000E, "PageCount"},
IDName{0x0000000F, "WordCount"},
IDName{0x00000010, "CharCount"},
IDName{0x00000011, "Thumbnail"},
IDName{0x00000012, "AppName"},
IDName{0x00000011, "DocSecurity"},
map[uint32]string{
0x00000002: "Title",
0x00000003: "Subject",
0x00000004: "Author",
0x00000005: "Keywords",
0x00000006: "Comments",
0x00000007: "Template",
0x00000008: "LastAuthor",
0x00000009: "RevNumber",
0x0000000A: "EditTime",
0x0000000B: "LastPrinted",
0x0000000C: "CreateTime",
0x0000000D: "LastSaveTime",
0x0000000E: "PageCount",
0x0000000F: "WordCount",
0x00000010: "CharCount",
0x00000011: "Thumbnail",
0x00000012: "AppName",
0x00000013: "DocSecurity",
},
}
2 changes: 1 addition & 1 deletion types/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type Currency int64

func (c Currency) String() string {
return "$" + strconv.FormatFloat(float64(c)/10000, 'f', 4, 64)
return "$" + strconv.FormatFloat(float64(c)/10000, 'f', -1, 64)
}

func (c Currency) Type() string {
Expand Down
4 changes: 2 additions & 2 deletions types/currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "testing"

func TestCurrency(t *testing.T) {
var c Currency = 52500
if c.String() != "$5.2500" {
t.Errorf("Currency: expecting $5.2500, got %s", c.String())
if c.String() != "$5.25" {
t.Errorf("Currency: expecting $5.25, got %s", c.String())
}
}
186 changes: 174 additions & 12 deletions types/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,198 @@ import (
"strconv"
)

type Integer8 byte
type BOOL bool

func (i Integer8) Type() string {
func (i BOOL) Type() string {
return "Boolean"
}

func (i BOOL) String() string {
if i {
return "true"
}
return "false"
}

func MakeBOOL(b []byte) (Type, error) {
if len(b) < 2 {
return BOOL(false), ErrType
}
switch binary.LittleEndian.Uint16(b[:2]) {
case 0xFFFF:
return BOOL(true), nil
case 0x0000:
return BOOL(false), nil
}
return BOOL(false), ErrType
}

type I1 int8

func (i I1) Type() string {
return "Int8"
}

func (i Integer8) String() string {
func (i I1) String() string {
return strconv.Itoa(int(i))
}

func MakeInteger8(b []byte) (Type, error) {
func MakeI1(b []byte) (Type, error) {
if len(b) < 1 {
return Integer8(0), ErrType
return I1(0), ErrType
}
return Integer8(b[0]), nil
return I1(b[0]), nil
}

type Integer16 int16
type I2 int16

func (i Integer16) Type() string {
func (i I2) Type() string {
return "Int16"
}

func (i Integer16) String() string {
func (i I2) String() string {
return strconv.Itoa(int(i))
}

func MakeI2(b []byte) (Type, error) {
if len(b) < 2 {
return I2(0), ErrType
}
return I2(binary.LittleEndian.Uint16(b[:2])), nil
}

type I4 int32

func (i I4) Type() string {
return "Int32"
}

func (i I4) String() string {
return strconv.Itoa(int(i))
}

func MakeI4(b []byte) (Type, error) {
if len(b) < 4 {
return I4(0), ErrType
}
return I4(binary.LittleEndian.Uint32(b[:4])), nil
}

type I8 int64

func (i I8) Type() string {
return "Int64"
}

func (i I8) String() string {
return strconv.FormatInt(int64(i), 10)
}

func MakeI8(b []byte) (Type, error) {
if len(b) < 8 {
return I8(0), ErrType
}
return I8(binary.LittleEndian.Uint64(b[:8])), nil
}

type UI1 uint8

func (i UI1) Type() string {
return "Uint8"
}

func (i UI1) String() string {
return strconv.Itoa(int(i))
}

func MakeUI1(b []byte) (Type, error) {
if len(b) < 1 {
return UI1(0), ErrType
}
return UI1(b[0]), nil
}

type UI2 uint16

func (i UI2) Type() string {
return "Uint16"
}

func (i UI2) String() string {
return strconv.Itoa(int(i))
}

func MakeInteger16(b []byte) (Type, error) {
func MakeUI2(b []byte) (Type, error) {
if len(b) < 2 {
return Integer16(0), ErrType
return UI2(0), ErrType
}
return UI2(binary.LittleEndian.Uint16(b[:2])), nil
}

type UI4 uint32

func (i UI4) Type() string {
return "Uint32"
}

func (i UI4) String() string {
return strconv.FormatUint(uint64(i), 10)
}

func MakeUI4(b []byte) (Type, error) {
if len(b) < 4 {
return UI4(0), ErrType
}
return UI4(binary.LittleEndian.Uint32(b[:4])), nil
}

type UI8 uint64

func (i UI8) Type() string {
return "Uint64"
}

func (i UI8) String() string {
return strconv.FormatUint(uint64(i), 10)
}

func MakeUI8(b []byte) (Type, error) {
if len(b) < 8 {
return UI8(0), ErrType
}
return UI8(binary.LittleEndian.Uint64(b[:8])), nil
}

type R4 float32

func (i R4) Type() string {
return "Float32"
}

func (i R4) String() string {
return strconv.FormatFloat(float64(i), 'f', -1, 32)
}

func MakeR4(b []byte) (Type, error) {
if len(b) < 4 {
return R4(0), ErrType
}
return R4(binary.LittleEndian.Uint32(b[:4])), nil
}

type R8 float64

func (i R8) Type() string {
return "Float64"
}

func (i R8) String() string {
return strconv.FormatFloat(float64(i), 'f', -1, 64)
}

func MakeR8(b []byte) (Type, error) {
if len(b) < 8 {
return R8(0), ErrType
}
return Integer16(binary.LittleEndian.Uint16(b[:2])), nil
return R8(binary.LittleEndian.Uint64(b[:8])), nil
}
Loading

0 comments on commit cc9331a

Please sign in to comment.