summaryrefslogtreecommitdiff
path: root/tools/inc/bootstrp/command.hxx
blob: 3b481371908bbde48a332d4138ef64ef3261c8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: command.hxx,v $
 * $Revision: 1.6.40.2 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef COMMAND_HXX
#define COMMAND_HXX

#include <iostream>

#include <tools/stream.hxx>
#define STRLEN 100
#ifndef UNX
#define TMPNAME "\\command.tmp"
#else
#define TMPNAME "/tmp/command.tmp"
#endif

/** Different types of spawnable programs
*/
enum ExeType
{
    EXE,    /// programm is a native executable
    BAT,    /// programm is a DOS-Batch
    BTM     /// programm is a 4DOS-Batch
};

#define COMMAND_NOTFOUND    0x0001
#define COMMAND_TOOBIG      0x0002
#define COMMAND_INVALID     0x0004
#define COMMAND_NOEXEC      0x0008
#define COMMAND_NOMEM       0x0010
#define COMMAND_UNKNOWN     0x0020

#ifdef WNT
#define COMMAND_SHELL   "4nt.exe"
#endif
#ifdef OS2
#define COMMAND_SHELL  "4os2.exe"
#endif
#ifdef UNX
#define COMMAND_SHELL   "csh"
#endif

class CommandLine;
class LogWindow;

class CommandLine
{
friend class ChildProcess;
private:
    char            *CommandBuffer;
    char            *ComShell;
    char            **ppArgv;
    BOOL            bTmpWrite;

public:
                    CommandLine(BOOL bTmpWrite = FALSE);
                    CommandLine(const char *, BOOL bTmpWrite = FALSE);
                    CommandLine(const CommandLine&, BOOL bTmpWrite = FALSE);
    virtual         ~CommandLine();

    int             nArgc;

    CommandLine&    operator=(const CommandLine&);
    CommandLine&    operator=(const char *);
    void            BuildCommand(const char *);
    char**          GetCommand(void) { return ppArgv; }
    void            Strtokens(const char *);
    void            Print();
};

static ByteString thePath( "PATH" );

/** Declares and spawns a child process.
    The spawned programm could be a native executable or a schell script.
*/
class CCommand
{
private:
    ByteString          aCommandLine;
    ByteString          aCommand;
    char                *pArgv;
    char                **ppArgv;
    ULONG               nArgc;
    int                 nError;

protected:
    void            ImplInit();
    void            Initpp( ULONG nCount, ByteString &rStr );

public:
                    /** Creates the process specified without spawning it
                        @param rString specifies the programm or shell scrip
                    */
                    CCommand( ByteString &rString );

                    /** Creates the process specified without spawning it
                        @param pChar specifies the programm or shell scrip
                    */
                    CCommand( const char *pChar );

                    /** Try to find the given programm in specified path
                        @param sEnv specifies the current search path, defaulted by environment
                        @param sItem specifies the system shell
                        @return the Location (when programm was found)
                    */
    static ByteString   Search( ByteString sEnv = thePath,
                                    ByteString sItem = COMMAND_SHELL );

                    /** Spawns the Process
                        @return 0 when spawned without errors, otherwise a error code
                    */
    operator int();

    ByteString          GetCommandLine_() { return aCommandLine; }
    ByteString          GetCommand() { return aCommand; }

    char**  GetCommandStr() { return ppArgv; }
};

#define COMMAND_EXECUTE_WINDOW  0x0000001
#define COMMAND_EXECUTE_CONSOLE 0x0000002
#define COMMAND_EXECUTE_HIDDEN  0x0000004
#define COMMAND_EXECUTE_START   0x0000008
#define COMMAND_EXECUTE_WAIT    0x0000010
#define COMMAND_EXECUTE_REMOTE  0x1000000

typedef ULONG CommandBits;

/** Allowes to spawn programms hidden, waiting etc.
    @see CCommand
*/
class CCommandd : public CCommand
{
    CommandBits     nFlag;
public:
                    CCommandd( ByteString &rString, CommandBits nBits );
                    CCommandd( const char *pChar, CommandBits nBits );
    operator int();
};

#endif