2 * Copyright 2006-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "SourceExporter.h"
17 SourceExporter::SourceExporter()
23 SourceExporter::~SourceExporter()
29 SourceExporter::Export(const Icon
* icon
, BPositionIO
* stream
)
32 status_t ret
= FlatIconExporter::Export(icon
, &buffer
);
36 return _Export((const uint8
*)buffer
.Buffer(), buffer
.BufferLength(),
42 SourceExporter::MIMEType()
44 return "text/x-source-code";
51 SourceExporter::_Export(const uint8
* source
, size_t sourceSize
,
52 BPositionIO
* stream
) const
56 sprintf(buffer
, "\nconst unsigned char kIconName[] = {\n");
57 size_t size
= strlen(buffer
);
59 ssize_t written
= stream
->Write(buffer
, size
);
61 return (status_t
)written
;
62 if (written
< (ssize_t
)size
)
66 const uint8
* b
= source
;
68 // print one line (12 values)
69 while (sourceSize
> 12) {
70 sprintf(buffer
, " 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x"
71 ", 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x"
72 ", 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,\n",
73 b
[0], b
[1], b
[2], b
[3],
74 b
[4], b
[5], b
[6], b
[7],
75 b
[8], b
[9], b
[10], b
[11]);
77 size
= strlen(buffer
);
78 written
= stream
->Write(buffer
, size
);
79 if (written
!= (ssize_t
)size
) {
83 ret
= (status_t
)written
;
90 // last line (up to 12 values)
91 if (ret
>= B_OK
&& sourceSize
> 0) {
92 for (size_t i
= 0; i
< sourceSize
; i
++) {
94 sprintf(buffer
, " 0x%.2x", b
[i
]);
96 sprintf(buffer
, ", 0x%.2x", b
[i
]);
97 size
= strlen(buffer
);
98 written
= stream
->Write(buffer
, size
);
99 if (written
!= (ssize_t
)size
) {
103 ret
= (status_t
)written
;
110 sprintf(buffer
, "\n};\n");
111 size
= strlen(buffer
);
112 written
= stream
->Write(buffer
, size
);
113 if (written
!= (ssize_t
)size
) {
117 ret
= (status_t
)written
;