[1076] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * gsdltools.cpp --
|
---|
| 4 | * A component of the Greenstone digital library software
|
---|
| 5 | * from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | * $Id: gsdltools.cpp 1176 2000-05-19 04:56:01Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*
|
---|
| 29 | $Log$
|
---|
[1176] | 30 | Revision 1.5 2000/05/19 04:56:01 sjboddie
|
---|
| 31 | added gsdl_system function for spawning off new processes under windows
|
---|
| 32 |
|
---|
[1146] | 33 | Revision 1.4 2000/05/04 05:16:23 sjboddie
|
---|
| 34 | Moved dm_safe from htmlutils to gsdltools. Also made it escape '\'
|
---|
| 35 | characters to prevent their mysterious disapearance from things like
|
---|
| 36 | windows filenames when they get passed through the macro expander.
|
---|
| 37 |
|
---|
[1076] | 38 | Revision 1.3 2000/04/06 19:58:01 cs025
|
---|
| 39 | Correcting a correction - reinstated all lib files due to silly
|
---|
| 40 | CVS confusion.
|
---|
| 41 |
|
---|
| 42 | Revision 1.1 2000/02/29 01:37:00 sjboddie
|
---|
| 43 | tidied up endianness
|
---|
| 44 |
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | #include "gsdltools.h"
|
---|
| 49 |
|
---|
| 50 | bool littleEndian() {
|
---|
| 51 | char s[2] = {'\xFE', '\xEF'};
|
---|
| 52 |
|
---|
| 53 | if (sizeof(unsigned short) == 2)
|
---|
| 54 | return *(unsigned short*)s == 0xEFFE;
|
---|
| 55 | else if (sizeof(unsigned int) == 2)
|
---|
| 56 | return *(unsigned int*)s == 0xEFFE;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[1146] | 59 | text_t dm_safe (const text_t &instring) {
|
---|
[1076] | 60 |
|
---|
[1146] | 61 | text_t outstring;
|
---|
| 62 | text_t::const_iterator here = instring.begin();
|
---|
| 63 | text_t::const_iterator end = instring.end();
|
---|
| 64 | while (here != end) {
|
---|
| 65 | if (*here == '_' || *here == '\\') outstring.push_back('\\');
|
---|
| 66 | outstring.push_back(*here);
|
---|
| 67 | here ++;
|
---|
| 68 | }
|
---|
| 69 | return outstring;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[1176] | 72 | // gsdl_system spawns a completely separate program (i.e. the calling
|
---|
| 73 | // program continues and terminates normally). Arguments containing special
|
---|
| 74 | // characters (e.g. '&') should be quoted with ""
|
---|
| 75 |
|
---|
| 76 | // on unix systems youcan get the same effext as this function by doing a
|
---|
| 77 | // system call and putting the spawned process in the background
|
---|
| 78 | // (e.g. system (funcname options &);
|
---|
| 79 |
|
---|
| 80 | #if defined (__WIN32__)
|
---|
| 81 | #include <windows.h>
|
---|
| 82 | void gsdl_system (char *cmd, ostream &logout) {
|
---|
| 83 |
|
---|
| 84 | STARTUPINFO ps = {sizeof(STARTUPINFO), NULL, NULL, NULL,
|
---|
| 85 | 0, 0, 0, 0, 0, 0,
|
---|
| 86 | 0, 0,
|
---|
| 87 | 0, 0, NULL,
|
---|
| 88 | NULL, NULL, NULL};
|
---|
| 89 | PROCESS_INFORMATION pi;
|
---|
| 90 | BOOL res = CreateProcess(NULL,
|
---|
| 91 | cmd,
|
---|
| 92 | NULL,
|
---|
| 93 | NULL,
|
---|
| 94 | FALSE,
|
---|
| 95 | DETACHED_PROCESS,
|
---|
| 96 | NULL,
|
---|
| 97 | NULL,
|
---|
| 98 | &ps,
|
---|
| 99 | &pi);
|
---|
| 100 | if (!res) {
|
---|
| 101 | logout << "Failed to start " << cmd << " process, error code " << GetLastError();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | CloseHandle(pi.hProcess);
|
---|
| 105 | CloseHandle(pi.hThread);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | #endif
|
---|