s3270 - Write text to session, not inside an input field - mainframe

I have an interesting problem interfacing to an IBM mainframe based CICS application. I can login and write to input fields successfully using s3270 and x3270if. However, the CICS system I am working with expects certain commands to simply be written to the "screen", not a proper input field. I am using the String() function to write to input fields, but I cannot seem to find a function that will simply write a string to a given screen position.
Has anyone dealt with a similar scenario and can provide me with some pointers?

With 3270, there is no such thing as "write to the screen," as opposed to writing to a field. A formatted 3270 buffer is a set of fields, each with a certain set of attributes. You cannot write to an arbitrary screen position unless there is an unprotected field that includes that position. That's 3270 specs, that's how 3270 hardware worked, that's how 3270 emulators work, and any API you may be using for working with 3270 emulators will just expose that.
(You may have an unformatted buffer with 3270, but I gather that's not the situation you are facing, since then you would be able to write to any screen position - the buffer is essentially one big field.)
So you need to figure out how the screen you are trying to write to is formatted, and where its fields are, and where the application expects its input. If you can just run the emulation and type the input according to whatever instructions you have then it should be straightforward - wherever your input goes, that's where you should put it programmatically.

Related

Script to paste a specific string into a text field with a hotkey

I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.

Ncurses getnStr with existing base string

I have written a program that uses ncurses for the UI and the function mvwgetnstr to read in a string from a window. I want to allow users to make edits to the text they enter, so if they enter foo they can later go back and append bar. I cannot figure out how to do this with the curses API, the getnstr function only takes in a char buffer and length variable. Any ideas? I started making my own string input function, but it's difficult to keep everything constrained within the window.
It depends on what you want. There are many possible ways to organize a program:
getnstr reads the buffer from the standard screen (a window)
The wgetnstr function accepts a buffer from a given window. Using a separate window (or subwindow) reduces the problem of updates for the edited buffer interfering with other things on the screen.
getnstr editing is crude. If you use the form library (which in turn uses ncurses), that allows you to do more than just append/remove characters from the end of the input buffer.
write your own input-function, which can get complicated. The dialog program does this.
The ncurses-examples might be helpful for reading and seeing how to build up a suitable input function.

Creating a Print Monitor / Print Handler

I'm having trouble getting started with building a Print Monitor / Print Handler for Windows using Visual Studio 2012 Ultimate with WDK 8. Basically, this is what I am trying to accomplish:
Create a print monitor (something an application can print to) that will generate a file with the content that should be printed (like the default XPS printer or a PDF printer), and then invokes the print handler
Create a print handler that will parse the generated file and do certain actions with it (check to see if certain text is present, upload the file online, etc)
I feel like the print handler part should not be too hard, but starting with the print monitor is what I'm stuck at. What would I do within VS12? I see options for "Printer Driver V4", "Printer Driver V4 Property Bag", and "Printer XPS Render Filter". Should I use one of those templates, and, if so, what would I do within them? Anything pointing me in the right direction would be appreciated!
EDIT:
Just some more clarification - I only need the text from the print output, but I've read from various sources that getting text-only output leads to no output at all from sources like Firefox, etc since they print text as glyphs.
I will be using the print handler to parse the text for keywords and then upload that information to a web server in a specific format. The print monitor just needs to capture and save the text information from whatever application is printing.
As you pointed out in your comments, some applications such as Firefox print using glyph indices instead of characters. In fact, quite a few do and it's becoming more common. What you need is a print driver. The good news is Microsoft has already written it for you and provided you with sample source code in the WDK. Start by reviewing this to understand your options. The Unidriver is perhaps a little simpler but the Postscript driver has the advantage of generating output that can readily be transformed to PDF or other formats that retain text information (as opposed to raster page images that lose all text information). As far as I'm concerned, don't even think about XPS; it's just an all around disaster.
To handle glyph indices, what you'll need to do is add code to the driver's OEMTextOut function that uses the font's cmap tables to translate glyph indices back into character codes. I'm unaware of any public domain libraries that parse font files, so you'll likely have to write your own code to do this. (Hint: If you support only OpenType/TrueType fonts, you'll cover 99% of all printing applications).
Getting the Microsoft sample code to build, install and run is mostly straightforward, but if you're new to the WDK and installing print drivers, plan on spending a week or more on just that. The glyph index translation part is far more complex and you should plan on spending a lot more time on that.

Serialized Printing Method

I am looking for a method by which I can print one document, and have a field that is incremented on each copy printed. I currently run linux, so bash in concert with several programs might be the way to go, but I'm just not sure where to start.
I have a document that is used for our business that currently is hand stamped for serialization... We would like to simply print them but cant find a method by which to increment a specific field. I would like to use either a PDF or an ODF/ODT for the document.
Thanks for any help you can give!
How is the document produced at the first place?
If you master that process, you could certainly add serialization at that level. For instance if using LibreOffice you could do that in LibreOffice. If using a text formatter (like LaTeX, Lout, ....) just emit the formatting instructions (e.g. the .tex or .lout source file) with some unique counting (perhaps simpler to do in some scripting language like Python or Ocaml).
Then run the relevant tool to get a .pdf file.

how can I extract text contents from GUI apps in linux?

I want to extract text contents from GUI apps,here are 2 examples::
example 1:
Suppose I opened firefox, and input url : www.google.com
how can I extract the string "www.google.com" from firefox using my own app ?
example 2:
open calculator(using gcalctool),then input 1+1
How can I extract the string "1+1" of calculator from my own program?
in brief ,what I want is to find out whether there is a way to extract the text contents from any widget of an GUI application
Thanks
I don't think there's a generic way to do this, at least not a very elegant one.
Some inelegant ideas:
You might be able to modify the X window system or even some toolkit framework to extract what is being displayed in specific window elements as text.
You could take a screenshot and use an OCR library to convert the pixels back into text for the interesting areas.
You could recompile the apps of interest to add some kind of mechanism for asking them questions.
You could use something like xtest to inject events highlighting the region of interest and copying it to the clipboard.
I believe firefox and gcalctool are for examples only and you just want to know in general how to pass output of one application to other application.
There are many ways to do that on Linux, like:
piping
application1 | application2
btw here is the Firefox command line manual if you want to start firefox on Ubuntu with a URL. eg:
firefox "$url"
where $url is a variable whose value can be www.mozilla.org
That sounds difficult. Supposing you're running X11, you can very easily grab a window picture ( see "man xwd"); however there is no easy way to get to the text unless it's selected and therefore copied to the clipboard.
Alternatively, if you only want to capture user input, this is quite easy to do, too, by activation the X11 record extension: put this in your /etc/X11/xorg.conf:
Section "Module"
Load "record"
#Load other modules you need ...
EndSection
though it may prove difficult to use too, see example code for Xorg/X11 record extension fails

Resources