xref: /AOO41X/main/soldep/inc/soldep/command.hxx (revision 53a9af0a251b18e3c3b23eacf3a4922b098ea5c4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef COMMAND_HXX
25 #define COMMAND_HXX
26 
27 #include <iostream>
28 
29 #include <tools/stream.hxx>
30 #define STRLEN 100
31 #ifndef UNX
32 #define TMPNAME "\\command.tmp"
33 #else
34 #define TMPNAME "/tmp/command.tmp"
35 #endif
36 
37 /** Different types of spawnable programs
38 */
39 enum ExeType
40 {
41     EXE,    /// programm is a native executable
42     BAT,    /// programm is a DOS-Batch
43     BTM     /// programm is a 4DOS-Batch
44 };
45 
46 #define COMMAND_NOTFOUND    0x0001
47 #define COMMAND_TOOBIG      0x0002
48 #define COMMAND_INVALID     0x0004
49 #define COMMAND_NOEXEC      0x0008
50 #define COMMAND_NOMEM       0x0010
51 #define COMMAND_UNKNOWN     0x0020
52 
53 #ifdef WNT
54 #define COMMAND_SHELL   "4nt.exe"
55 #endif
56 #ifdef OS2
57 #define COMMAND_SHELL  "4os2.exe"
58 #endif
59 #ifdef UNX
60 #define COMMAND_SHELL   "csh"
61 #endif
62 
63 class CommandLine;
64 class LogWindow;
65 
66 class CommandLine
67 {
68 friend class ChildProcess;
69 private:
70     char            *CommandBuffer;
71     char            *ComShell;
72     char            **ppArgv;
73     sal_Bool            bTmpWrite;
74 
75 public:
76                     CommandLine(sal_Bool bTmpWrite = sal_False);
77                     CommandLine(const char *, sal_Bool bTmpWrite = sal_False);
78                     CommandLine(const CommandLine&, sal_Bool bTmpWrite = sal_False);
79     virtual         ~CommandLine();
80 
81     int             nArgc;
82 
83     CommandLine&    operator=(const CommandLine&);
84     CommandLine&    operator=(const char *);
85     void            BuildCommand(const char *);
GetCommand(void)86     char**          GetCommand(void) { return ppArgv; }
87     void            Strtokens(const char *);
88     void            Print();
89 };
90 
91 /** Declares and spawns a child process.
92     The spawned programm could be a native executable or a schell script.
93 */
94 class CCommand
95 {
96 private:
97     ByteString          aCommandLine;
98     ByteString          aCommand;
99     char                *pArgv;
100     char                **ppArgv;
101     sal_uIntPtr             nArgc;
102     int                 nError;
103 
104 protected:
105     void            ImplInit();
106     void            Initpp( sal_uIntPtr nCount, ByteString &rStr );
107 
108 public:
109                     /** Creates the process specified without spawning it
110                         @param rString specifies the programm or shell scrip
111                     */
112                     CCommand( ByteString &rString );
113 
114                     /** Creates the process specified without spawning it
115                         @param pChar specifies the programm or shell scrip
116                     */
117                     CCommand( const char *pChar );
118 
119                     /** Try to find the given programm in specified path
120                         @param sEnv specifies the current search path, defaulted by environment
121                         @param sItem specifies the system shell
122                         @return the Location (when programm was found)
123                     */
124     static ByteString   Search( ByteString sEnv,
125                                     ByteString sItem = COMMAND_SHELL );
126 
127                     /** Spawns the Process
128                         @return 0 when spawned without errors, otherwise a error code
129                     */
130     operator int();
131 
GetCommandLine_()132     ByteString          GetCommandLine_() { return aCommandLine; }
GetCommand()133     ByteString          GetCommand() { return aCommand; }
134 
GetCommandStr()135     char**  GetCommandStr() { return ppArgv; }
136 };
137 
138 #define COMMAND_EXECUTE_WINDOW  0x0000001
139 #define COMMAND_EXECUTE_CONSOLE 0x0000002
140 #define COMMAND_EXECUTE_HIDDEN  0x0000004
141 #define COMMAND_EXECUTE_START   0x0000008
142 #define COMMAND_EXECUTE_WAIT    0x0000010
143 #define COMMAND_EXECUTE_REMOTE  0x1000000
144 
145 typedef sal_uIntPtr CommandBits;
146 
147 /** Allowes to spawn programms hidden, waiting etc.
148     @see CCommand
149 */
150 class CCommandd : public CCommand
151 {
152     CommandBits     nFlag;
153 public:
154                     CCommandd( ByteString &rString, CommandBits nBits );
155                     CCommandd( const char *pChar, CommandBits nBits );
156     operator int();
157 };
158 
159 #endif
160