merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / osl / process / osl_process_child.cxx
blobfe3759c42cffc10ce9fc3fb236c6d82dc3917671
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_process_child.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 //########################################
35 // includes
37 #if ( defined WNT ) // Windows
38 #include <tools/prewin.h>
39 # define UNICODE
40 # define _UNICODE
41 # define WIN32_LEAN_AND_MEAN
42 // # include <windows.h>
43 # include <tchar.h>
44 #include <tools/postwin.h>
45 #else
46 # include <unistd.h>
47 #endif
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <iostream>
52 #include <fstream>
54 #include <rtl/ustring.hxx>
56 //########################################
57 // defines
59 #ifdef WNT
60 # define SLEEP(t) (Sleep((t)*1000))
61 #else
62 # define SLEEP(t) (sleep((t)))
63 #endif
65 //########################################
66 void wait_for_seconds(char* time)
68 SLEEP(atoi(time));
71 //########################################
73 #ifdef WNT
74 //########################################
75 void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size)
77 LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW);
78 WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL);
80 //########################################
81 void dump_env(char* file_path)
83 LPTSTR env = reinterpret_cast<LPTSTR>(
84 GetEnvironmentStrings());
85 LPTSTR p = env;
87 std::ofstream file(file_path);
89 char buffer[32767];
90 while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p)))
92 w_to_a(p, buffer, sizeof(buffer));
93 file << buffer << std::endl;
94 p += l + 1;
96 FreeEnvironmentStrings(env);
98 #else
99 extern char** environ;
101 void dump_env(char* file_path)
103 std::ofstream file(file_path);
104 for (int i = 0; NULL != environ[i]; i++)
105 file << environ[i] << std::endl;
107 #endif
109 //########################################
110 int main(int argc, char* argv[])
112 rtl::OUString s;
114 //t_print("Parameter: ");
115 printf("child process Parameter: ");
116 for (int i = 1; i < argc; i++)
117 printf("%s ", argv[i]);
118 printf("\n");
120 if (argc > 2)
122 if (0 == strcmp("-join", argv[1]))
124 wait_for_seconds(argv[2]);
126 else if (0 == strcmp("-env", argv[1]))
128 dump_env(argv[2]);
132 return (0);