Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : //########################################
22 :
23 :
24 : #if ( defined WNT ) // Windows
25 : # define UNICODE
26 : # define _UNICODE
27 : # define WIN32_LEAN_AND_MEAN
28 : # include <windows.h>
29 : # include <tchar.h>
30 : #else
31 : # include <unistd.h>
32 : #endif
33 :
34 : #include <stdio.h>
35 : #include <stdlib.h>
36 : #include <iostream>
37 : #include <fstream>
38 : #include <string.h>
39 :
40 : #include <rtl/ustring.hxx>
41 :
42 : #ifdef UNX
43 : #if defined( MACOSX )
44 : # include <crt_externs.h>
45 : # define environ (*_NSGetEnviron())
46 : # else
47 : extern char** environ;
48 : # endif
49 : #endif
50 :
51 : //########################################
52 :
53 :
54 : #ifdef WNT
55 : # define SLEEP(t) (Sleep((t)*1000))
56 : #else
57 : # define SLEEP(t) (sleep((t)))
58 : #endif
59 :
60 : //########################################
61 0 : void wait_for_seconds(char* time)
62 : {
63 0 : SLEEP(atoi(time));
64 0 : }
65 :
66 : //########################################
67 :
68 : #ifdef WNT
69 : //########################################
70 : void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size)
71 : {
72 : LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW);
73 : WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL);
74 : }
75 : //########################################
76 : void dump_env(char* file_path)
77 : {
78 : LPTSTR env = reinterpret_cast<LPTSTR>(
79 : GetEnvironmentStrings());
80 : LPTSTR p = env;
81 :
82 : std::ofstream file(file_path);
83 :
84 : char buffer[32767];
85 : while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p)))
86 : {
87 : w_to_a(p, buffer, sizeof(buffer));
88 : file << buffer << '\0';
89 : p += l + 1;
90 : }
91 : FreeEnvironmentStrings(env);
92 : }
93 : #else
94 2 : void dump_env(char* file_path)
95 : {
96 2 : std::ofstream file(file_path);
97 1475 : for (int i = 0; NULL != environ[i]; ++i)
98 1475 : file << environ[i] << '\0';
99 2 : }
100 : #endif
101 :
102 : //########################################
103 2 : int main(int argc, char* argv[])
104 : {
105 2 : if (argc > 2)
106 : {
107 2 : if (0 == strcmp("-join", argv[1]))
108 0 : wait_for_seconds(argv[2]);
109 2 : else if (0 == strcmp("-env", argv[1]))
110 2 : dump_env(argv[2]);
111 : }
112 :
113 2 : return 0;
114 6 : }
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|