123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #include <opc/opc.h>
- #include <stdio.h>
- #ifdef WIN32
- #include <io.h>
- #include <fcntl.h>
- #endif
- #ifdef WIN32
- #include <crtdbg.h>
- #endif
- int main( int argc, const char* argv[] )
- {
- #ifdef WIN32
- _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- #endif
- #ifdef WIN32
- _setmode( _fileno( stdout ), _O_BINARY );
- #endif
- if (OPC_ERROR_NONE==opcInitLibrary() && 3==argc) {
- opcContainer *c=NULL;
- if (NULL!=(c=opcContainerOpen(_X(argv[1]), OPC_OPEN_READ_ONLY, NULL, NULL))) {
- opcPart part=OPC_PART_INVALID;
- if ((part=opcPartFind(c, _X(argv[2]), NULL, 0))!=OPC_PART_INVALID) {
- opcContainerInputStream *stream=NULL;
- if ((stream=opcContainerOpenInputStream(c, part))!=NULL){
- opc_uint8_t buf[100];
- opc_uint32_t len=0;
- while((len=opcContainerReadInputStream(stream, buf, sizeof(buf)))>0) {
- fwrite(buf, sizeof(opc_uint8_t), len, stdout);
- }
- opcContainerCloseInputStream(stream);
- } else {
- fprintf(stderr, "ERROR: part \"%s\" could not be opened for reading.\n", argv[2]);
- }
- } else {
- fprintf(stderr, "ERROR: part \"%s\" could not be opened in \"%s\".\n", argv[2], argv[1]);
- }
- opcContainerClose(c, OPC_CLOSE_NOW);
- } else {
- fprintf(stderr, "ERROR: file \"%s\" could not be opened.\n", argv[1]);
- }
- opcFreeLibrary();
- } else if (2==argc) {
- fprintf(stderr, "ERROR: initialization of libopc failed.\n");
- } else {
- fprintf(stderr, "opc_extract FILENAME PART\n\n");
- fprintf(stderr, "Sample: opc_extract test.docx word/document.xml\n");
- }
- #ifdef WIN32
- OPC_ASSERT(!_CrtDumpMemoryLeaks());
- #endif
- return 0;
- }
|