1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org 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 Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sal.hxx" 30 31 //######################################## 32 // includes 33 34 #if ( defined WNT ) // Windows 35 #include <tools/prewin.h> 36 # define UNICODE 37 # define _UNICODE 38 # define WIN32_LEAN_AND_MEAN 39 // # include <windows.h> 40 # include <tchar.h> 41 #include <tools/postwin.h> 42 #else 43 # include <unistd.h> 44 #endif 45 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <iostream> 49 #include <fstream> 50 51 #include <rtl/ustring.hxx> 52 53 //######################################## 54 // defines 55 56 #ifdef WNT 57 # define SLEEP(t) (Sleep((t)*1000)) 58 #else 59 # define SLEEP(t) (sleep((t))) 60 #endif 61 62 //######################################## 63 void wait_for_seconds(char* time) 64 { 65 SLEEP(atoi(time)); 66 } 67 68 //######################################## 69 70 #ifdef WNT 71 //######################################## 72 void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size) 73 { 74 LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW); 75 WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL); 76 } 77 //######################################## 78 void dump_env(char* file_path) 79 { 80 LPTSTR env = reinterpret_cast<LPTSTR>( 81 GetEnvironmentStrings()); 82 LPTSTR p = env; 83 84 std::ofstream file(file_path); 85 86 char buffer[32767]; 87 while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p))) 88 { 89 w_to_a(p, buffer, sizeof(buffer)); 90 file << buffer << std::endl; 91 p += l + 1; 92 } 93 FreeEnvironmentStrings(env); 94 } 95 #else 96 extern char** environ; 97 98 void dump_env(char* file_path) 99 { 100 std::ofstream file(file_path); 101 for (int i = 0; NULL != environ[i]; i++) 102 file << environ[i] << std::endl; 103 } 104 #endif 105 106 //######################################## 107 int main(int argc, char* argv[]) 108 { 109 rtl::OUString s; 110 111 //t_print("Parameter: "); 112 printf("child process Parameter: "); 113 for (int i = 1; i < argc; i++) 114 printf("%s ", argv[i]); 115 printf("\n"); 116 117 if (argc > 2) 118 { 119 if (0 == strcmp("-join", argv[1])) 120 { 121 wait_for_seconds(argv[2]); 122 } 123 else if (0 == strcmp("-env", argv[1])) 124 { 125 dump_env(argv[2]); 126 } 127 } 128 129 return (0); 130 } 131 132