summaryrefslogtreecommitdiff
path: root/lib/receive_and_print.tcl
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
committerAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
commit47aa8b00b2b11df13a100489e0f904a4947177ef (patch)
treeb35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/receive_and_print.tcl
parent5b8466f7fae0e071c0f4eda13051c93313910028 (diff)
Import Upstream version 1.4.7
Diffstat (limited to 'lib/receive_and_print.tcl')
-rw-r--r--lib/receive_and_print.tcl102
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/receive_and_print.tcl b/lib/receive_and_print.tcl
new file mode 100644
index 0000000..1d082f3
--- /dev/null
+++ b/lib/receive_and_print.tcl
@@ -0,0 +1,102 @@
+#!/bin/sh
+# the next line restarts using wish \
+exec tclsh "$0" "$@"
+
+# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
+
+############################################################################
+# Copyright (C) 2011 by Martin Ošmera #
+# martin.osmera@gmail.com #
+# #
+# This program is free software; you can redistribute it and#or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation; either version 2 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program; if not, write to the #
+# Free Software Foundation, Inc., #
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+############################################################################
+
+# >>> File inclusion guard
+if { ! [ info exists _RECEIVE_AND_PRINT_TCL ] } {
+set _RECEIVE_AND_PRINT_TCL _
+# <<< File inclusion guard
+
+# --------------------------------------------------------------------------
+# DESCRIPTION
+# Send input read the send command to stdout
+#
+# USAGE:
+# set pid [exec -- tclsh receive_and_print.tcl [tk appname] final_cmd | some_command ?args? &]
+# * pid - Process identifier of $some_command
+# * args - Arguments for $some_command
+# * final_cmd - Command in local Tcl program to execute once when the script exits
+#
+# Once the receive_and_print (RAP) is started you can invoke ``print_line'' command available in it
+# to print any string to stdout. The command takes any number of arguments and prints them all into
+# the standard output.
+# --------------------------------------------------------------------------
+
+# Initialize
+encoding system {utf-8}
+package require Tk
+wm withdraw .
+wm command . "$argv0 $argv"
+wm client . [info hostname]
+
+# Parse agruments
+set source_app [lindex $argv 0]
+set final_cmd [lindex $argv 1]
+unset argv
+
+## Determinate the host OS
+set ::MICROSOFT_WINDOWS 0
+if {[string first {Windows} ${tcl_platform(os)}] != -1} {
+ # Note:
+ # Microsoft Windows is NOT a POSIX system and because of that we need
+ # to do some workarounds here in order to make the IDE functional there.
+ set ::MICROSOFT_WINDOWS 1
+}
+
+# Load dde - Dynamic Data Exchange on Microsoft Windows
+if {$::MICROSOFT_WINDOWS} {
+ package require dde
+}
+
+## Perform secure send command
+ # Secure means that it will not crash or something like that in case of any errors.
+ # But instead it will pop-up an error message to the user (Tk dialog).
+ # @parm List args - Arguments for the send command
+ # @return void
+proc secure_send args {
+ if {[catch {
+ eval "send $args"
+ } result]} then {
+ puts stderr "Unknown IO Error :: $result"
+ return 1
+
+ } else {
+ return 1
+ }
+}
+
+proc print_line {args} {
+ puts $args
+}
+
+if {!${::MICROSOFT_WINDOWS}} {
+ secure_send $source_app $final_cmd "{[tk appname]}"
+} else {
+ dde eval $source_app $final_cmd "{[tk appname]}"
+}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard