[Libreoffice-commits] core.git: Branch 'private/tbsdy/workbench' - 2 commits - Repository.mk sal/Executable_getenvvars.mk sal/Executable_setgetenv.mk sal/Executable_terminateprocess.mk sal/Module_sal.mk sal/workben
Chris Sherlock
chris.sherlock79 at gmail.com
Sun Aug 13 14:07:04 UTC 2017
Repository.mk | 2
sal/Executable_getenvvars.mk | 31 +++++++++++
sal/Executable_setgetenv.mk | 31 +++++++++++
sal/Executable_terminateprocess.mk | 31 +++++++++++
sal/Module_sal.mk | 2
sal/workben/osl/batchwait.bat | 23 ++++++++
sal/workben/osl/batchwait.sh | 6 ++
sal/workben/osl/getenvvars.cxx | 47 +++++++++++++++++
sal/workben/osl/setgetenv.cxx | 52 +++++++++++++++++++
sal/workben/osl/terminateprocess.cxx | 92 +++++++++++++++++++++++++++++++++++
10 files changed, 317 insertions(+)
New commits:
commit d068beca518ff4b01b154e8b9ca95bb52f46f8be
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Mon Aug 14 00:04:20 2017 +1000
sal workben: set and get an environment variable
Change-Id: Ifcd5eaf2fbc75752e574081dc736ecf4529e5d22
diff --git a/Repository.mk b/Repository.mk
index 7d3b865816eb..abeeaa24a5bd 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -85,6 +85,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
processcmdlineargs \
executeprocess \
terminateprocess \
+ setgetenv \
))
$(eval $(call gb_Helper_register_executables_for_install,SDK,sdk, \
diff --git a/sal/Executable_getenvvars.mk b/sal/Executable_getenvvars.mk
new file mode 100644
index 000000000000..d82a0b420808
--- /dev/null
+++ b/sal/Executable_getenvvars.mk
@@ -0,0 +1,31 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,getenvvars))
+
+$(eval $(call gb_Executable_set_include,getenvvars,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/sal/inc \
+))
+
+$(eval $(call gb_Library_add_defs,getenvvars,\
+ -DSAL_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Executable_use_libraries,getenvvars,\
+ sal \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,getenvvars,\
+ sal/workben/osl/getenvvars \
+))
+
+$(call gb_Executable_get_clean_target,getenvvars) :
+ rm -f $(WORKDIR)/LinkTarget/Executable/getenvvars
+# vim: set ts=4 sw=4 et:
diff --git a/sal/Executable_setgetenv.mk b/sal/Executable_setgetenv.mk
new file mode 100644
index 000000000000..6aa4135f073e
--- /dev/null
+++ b/sal/Executable_setgetenv.mk
@@ -0,0 +1,31 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,setgetenv))
+
+$(eval $(call gb_Executable_set_include,setgetenv,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/sal/inc \
+))
+
+$(eval $(call gb_Library_add_defs,setgetenv,\
+ -DSAL_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Executable_use_libraries,setgetenv,\
+ sal \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,setgetenv,\
+ sal/workben/osl/setgetenv \
+))
+
+$(call gb_Executable_get_clean_target,setgetenv) :
+ rm -f $(WORKDIR)/LinkTarget/Executable/setgetenv
+# vim: set ts=4 sw=4 et:
diff --git a/sal/Module_sal.mk b/sal/Module_sal.mk
index 292321d3cbca..5d6563861b82 100644
--- a/sal/Module_sal.mk
+++ b/sal/Module_sal.mk
@@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_targets,sal,\
Executable_processcmdlineargs \
Executable_executeprocess \
Executable_terminateprocess \
+ Executable_setgetenv \
))
$(eval $(call gb_Module_add_check_targets,sal,\
diff --git a/sal/workben/osl/getenvvars.cxx b/sal/workben/osl/getenvvars.cxx
new file mode 100644
index 000000000000..c29c20379bbe
--- /dev/null
+++ b/sal/workben/osl/getenvvars.cxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/main.h>
+#include <osl/process.h>
+#include <osl/thread.h>
+
+#include <cstdio>
+#include <wchar.h>
+
+SAL_IMPLEMENT_MAIN()
+{
+ sal_Unicode **ppustrEnvVars=nullptr;
+
+ fprintf(stdout, "Getting environment variables.\n");
+
+ osl_getAllEnvironment(ppustrEnvVars);
+
+ do
+ {
+ fprintf(stdout, "In loop\n");
+ if (wcslen(reinterpret_cast< wchar_t* >(ppustrEnvVars)) == 0)
+ break;
+ fprintf(stdout, " %S", reinterpret_cast< wchar_t* >(ppustrEnvVars));
+ ppustrEnvVars += sizeof(wchar_t) * (wcslen(reinterpret_cast< wchar_t* >(ppustrEnvVars)) + 1);
+ } while(true);
+
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/workben/osl/setgetenv.cxx b/sal/workben/osl/setgetenv.cxx
new file mode 100644
index 000000000000..481d460674ec
--- /dev/null
+++ b/sal/workben/osl/setgetenv.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/main.h>
+#include <rtl/ustring.h>
+#include <osl/thread.h>
+
+#include <osl/process.h>
+
+#include <cstdio>
+
+SAL_IMPLEMENT_MAIN()
+{
+ rtl_uString *pustrEnvVar = nullptr;
+ rtl_uString *pustrEnvValue = nullptr;
+ rtl_uString *pustrRetrieveValue = nullptr;
+
+ fprintf(stdout, "Setting and getting environment variable\n");
+
+ rtl_uString_newFromAscii(&pustrEnvVar, "animalname");
+ rtl_uString_newFromAscii(&pustrEnvValue, "sasquatch");
+
+ osl_setEnvironment(pustrEnvVar, pustrEnvValue);
+ osl_getEnvironment(pustrEnvVar, &pustrRetrieveValue);
+
+ rtl_String *pstrVal=nullptr;
+
+ rtl_uString2String(&pstrVal,
+ rtl_uString_getStr(pustrRetrieveValue), rtl_uString_getLength(pustrRetrieveValue),
+ osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ fprintf(stdout, "Retrieved value is %s\n", rtl_string_getStr(pstrVal));
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 22c93860edc6a8f2543cb3f30115655df588fa7a
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Sun Aug 13 22:55:47 2017 +1000
sal workben: Demonstrate osl_terminateProcess()
Change-Id: I5e7ed1cd08c2d426151afaf4de620b4412c6e9b1
diff --git a/Repository.mk b/Repository.mk
index 8413facda420..7d3b865816eb 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -84,6 +84,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
getprocessinfo \
processcmdlineargs \
executeprocess \
+ terminateprocess \
))
$(eval $(call gb_Helper_register_executables_for_install,SDK,sdk, \
diff --git a/sal/Executable_terminateprocess.mk b/sal/Executable_terminateprocess.mk
new file mode 100644
index 000000000000..9bf751171516
--- /dev/null
+++ b/sal/Executable_terminateprocess.mk
@@ -0,0 +1,31 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,terminateprocess))
+
+$(eval $(call gb_Executable_set_include,terminateprocess,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/sal/inc \
+))
+
+$(eval $(call gb_Library_add_defs,terminateprocess,\
+ -DSAL_DLLIMPLEMENTATION \
+))
+
+$(eval $(call gb_Executable_use_libraries,terminateprocess,\
+ sal \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,terminateprocess,\
+ sal/workben/osl/terminateprocess \
+))
+
+$(call gb_Executable_get_clean_target,terminateprocess) :
+ rm -f $(WORKDIR)/LinkTarget/Executable/terminateprocess
+# vim: set ts=4 sw=4 et:
diff --git a/sal/Module_sal.mk b/sal/Module_sal.mk
index 4f6118210247..292321d3cbca 100644
--- a/sal/Module_sal.mk
+++ b/sal/Module_sal.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Module_add_targets,sal,\
Executable_getprocessinfo \
Executable_processcmdlineargs \
Executable_executeprocess \
+ Executable_terminateprocess \
))
$(eval $(call gb_Module_add_check_targets,sal,\
diff --git a/sal/workben/osl/batchwait.bat b/sal/workben/osl/batchwait.bat
new file mode 100755
index 000000000000..36d9eedaa1b4
--- /dev/null
+++ b/sal/workben/osl/batchwait.bat
@@ -0,0 +1,23 @@
+rem
+rem This file is part of the LibreOffice project.
+rem
+rem This Source Code Form is subject to the terms of the Mozilla Public
+rem License, v. 2.0. If a copy of the MPL was not distributed with this
+rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
+rem
+rem This file incorporates work covered by the following license notice:
+rem
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed
+rem with this work for additional information regarding copyright
+rem ownership. The ASF licenses this file to you under the Apache
+rem License, Version 2.0 (the "License"); you may not use this file
+rem except in compliance with the License. You may obtain a copy of
+rem the License at http://www.apache.org/licenses/LICENSE-2.0 .
+rem
+ at echo off
+cls
+:start
+echo "Hello world"
+pause
+goto start
diff --git a/sal/workben/osl/batchwait.sh b/sal/workben/osl/batchwait.sh
new file mode 100755
index 000000000000..65b62907b468
--- /dev/null
+++ b/sal/workben/osl/batchwait.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+while true
+do
+ echo "Hello world"
+ sleep 1
+done
diff --git a/sal/workben/osl/terminateprocess.cxx b/sal/workben/osl/terminateprocess.cxx
new file mode 100644
index 000000000000..4b51bb2f2ff5
--- /dev/null
+++ b/sal/workben/osl/terminateprocess.cxx
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+#include <sal/main.h>
+#include <sal/log.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/alloc.h>
+#include <osl/thread.h>
+#include <osl/file.h>
+
+#include <osl/process.h>
+
+#include <cstdio>
+
+SAL_IMPLEMENT_MAIN()
+{
+ oslProcess aProcess;
+
+ fprintf(stdout, "Execute process.\n");
+
+ rtl_uString *pustrExePath = nullptr;
+ osl_getExecutableFile(&pustrExePath);
+
+ rtl_uString *pTempExePath = nullptr;
+ sal_uInt32 nLastChar;
+
+ nLastChar = rtl_ustr_lastIndexOfChar(rtl_uString_getStr(pustrExePath), SAL_PATHDELIMITER);
+ rtl_uString_newReplaceStrAt(&pTempExePath, pustrExePath, nLastChar, rtl_ustr_getLength(rtl_uString_getStr(pustrExePath)), nullptr);
+ rtl_freeMemory(pustrExePath);
+ pustrExePath = pTempExePath;
+
+#if defined(_WIN32)
+# define BATCHFILE "\\..\\sal\\workben\\osl\\batchwait.bat"
+# define BATCHFILE_LENGTH 39
+#else
+# define BATCHFILE "/../../../sal/workben/osl/batchwait.sh"
+# define BATCHFILE_LENGTH 38
+#endif
+
+ rtl_uString_newConcatAsciiL(&pustrExePath, pustrExePath, BATCHFILE, BATCHFILE_LENGTH);
+
+ oslProcessError osl_error = osl_executeProcess(
+ pustrExePath, // process to execute
+ nullptr, // no arguments
+ 0, // no arguments
+ osl_Process_NORMAL, // process execution mode
+ nullptr, // security context is current user
+ nullptr, // current working directory inherited from parent process
+ nullptr, // no environment variables
+ 0, // no environment variables
+ &aProcess); // process handle
+
+ rtl_freeMemory(pustrExePath);
+
+ if (osl_error != osl_Process_E_None)
+ fprintf(stderr, "Process failed\n");
+
+ fprintf(stdout, " Process running...\n");
+ osl_error = osl_terminateProcess(aProcess);
+ if (osl_error == osl_Process_E_None)
+ {
+ fprintf(stdout, " ...process terminated.\n");
+ }
+ else
+ {
+ fprintf(stderr, " ... process could not be terminated.\n");
+ osl_joinProcess(aProcess);
+ }
+
+ osl_freeProcessHandle(aProcess);
+
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list