Showing posts with label cygwin. Show all posts
Showing posts with label cygwin. Show all posts

Wednesday, February 07, 2018

[tbas] tbas basic interpreter

In my ample (NOT!) spare time, I'm helping out with a programming language project called tbas. I saw it advertised on comp.lang.basic.misc in September 2017 (yep, usenet is still going strong.)

The author is one Antonio Maschio from Italy.

You can get source, documentation and a CygWin binary from the main site. There are some examples on RosettaCode.

To give you an idea of the flavour of the language, the following is a simple CAESAR cipher implementation.

    LET MSG$ = ""
    LET OFFS = 0
    LINE INPUT "Message"; MSG$
    INPUT "Offset"; OFFS
    DIM TARG(LEN(MSG$))
    CHANGE MSG$ TO TARG
    FOR I = 1 TO UDIM(TARG)
        TARG(I) = TARG(I) + OFFS
    NEXT
    CHANGE TARG TO MSG$
    PRINT MSG$

An example of running the above

    >tbas CAESAR.BAS
    Message ? My dog's got fleas
    Offset ? 1
    Nz!eph(t!hpu!gmfbt

© Copyright Bruce M. Axtens, 2018

Thursday, December 20, 2007

[Visual BASIC 6] BOOST (v2)

I revisited BOOST this week. A friend had pointed out to me some time back that /P: and /L: were a bit of a pain when one wanted to speed something up quickly, or kill it quickly. So this version changes the command line handling.

This version also demonstrates how to kill a process. In fact it kills every process of the same name. I wish I'd had this a couple of years ago when I was doing stuff with Excel -- I'd end up with multiple Excel sessions which I would then have to kill off one-by-one through the Task Manager. (I eventually ended up installing Cygwin so that I could script the process.)

If you remember the original VBScript of BOOST and the first VB6 version, you'll see some similarities.

I've given up on using
setsubsys in favour of using VBAdvance (which is now freeware) to handle the compile-to-console-app process. I'm still compressing the app using UPX.

First a few constants and the declarations, found on
vb.mvps.org, for doing console I/O.



Next, a few supporting functions. First off the rank, is an invocation syntax display. Notice that priority can now be specified either by a number (0 to kill, 1-6 for low to realtime) or by name (kill, low, belownormal, normal, abovenormal, high, realtime).



Second, the command line parser. This splits on space and tab and is based on code found at
microsoft.public.vb.winapi



Third, the two routines which wrap the WMI functions to set priority and to kill process. The latter was found at
tek-tips. If I remember correctly, the places in each routine where it says
sComputer = "."
could, in fact, have some other computer's name. If you had sufficient privilege you could be tweaking or killing a process on someone else's machine.



Finally, the Main subroutine. Notice the additions to the priorities collection. Note also the change in the way the command line is handled.

Because there's no .Exists method on Collections, the .Item call is wrapped in an 'On Error' so that a non-existent item situation is caught appropriately.



What's next with this thing? I suppose one could explore the possibility of influencing the lives of applications on other computers:
BOOST Skype.exe kill /C:GUEST_01
There's also the fact that the commandline parser doesn't properly handle double-quoted names. If an .exe had a space it its name, you wouldn't be able use BOOST on it.

Finally, here's a short batch file (killall.bat) I use for killing applications en masse. It was originally designed to get around the 'typing the /P and /L' issue, but I'm so used to using it now ...



An example invocation:
killall excel.exe outlook.exe


© Copyright Bruce M. Axtens, 2007

Monday, August 29, 2005

[Cygwin] using Cygwin to make .cmd files. Eeeww...

Actually the whole thing is a bizarre mix of Cygwin, Win2k CMD and Euphoria. When I get some more time I'll go into the issue a little more deeply. Here's the line that the title refers to:

Wednesday, August 17, 2005

Once I wrote a global search and replace ...

... and now I find that a simple bit of unix command line replaces hundreds of lines of MoonRock BASIC.

$ for x in *.chk; do cat $x | sed -e s/Database=/Filename=/ > tmp; mv tmp $x; done

Get every file ending in .chk, pipe it through sed to change the relevant string, capture the result into a temporary file and then copy it over the original.

Tuesday, August 16, 2005

Cygwin again - Oh how I love the unix command line

$ getclip | gawk '{ print "convert.vbs /profile:" $1 ".cvt\ndaily.vbs /profile:" $1 ".dly\n" }' | putclip

It gets the word I put in the clipboard (selected and copied out of SciTe) and puts back on the clipboard the word as commands and filenames to be pasted back in. For example, I put

Marble_Bar

on the clipboard, reissue the command, and get

convert.vbs /profile:Marble_Bar.cvt
daily.vbs /profile:Marble_Bar.dly

Thursday, August 11, 2005

Cygwin, bash, grep, gawk, tclsh, VBScript

What a combination!! I've found Cygwin enormously helpful. Take the following snippet for example, which extracts the names of all the Subs and Functions from my library file into a file, and then hands that file on to a tcl script.
#!/bin/bash
grep -i '^Function ' StdFunctions.vbs >func.lst
grep -i '^Sub ' StdFunctions.vbs >> func.lst
cat func.lst | gawk -F " " '{ print $2 }' | gawk -F "(" '{ print $1 }' > Routines.lst
rm func.lst
tclsh routines.tcl
The output file, Routines.lst, looks like this (partially)
CreateMDB
OpenDatabase
OpenDatabase2
SelectSheet
GetColumnDownToEnd
GetColumnDownToLimit
RangeToArray
VectorToTwoDimArray
RelativeToAbsolute
MakeKey3
MakeKey4
TimeStamp
Zerofill
IsFile
IsINISection
GetINIString
Routines.tcl takes this, and an internally specified list of files to check (which I could have coded so as to specify on the commandline) and then tells me whether any of these routines are referred to in the list of files.
#!/bin/tclsh
set mm 0

proc searchFile {theFile theString} {
#puts "Searching $theFile for $theString"
set h [open $theFile r]
set d [split [read $h] \n]
close $h
set c 0
set m 0
foreach dline $d {
incr c
if {[string match -nocase "*${theString}*" $dline] == 1} then {
  set m 1
  #puts "$theFile $c: $dline"
}
}
return $m
}

set vlist [list Create.vbs Daily.vbs NewBatchPrepare.vbs convert.vbs]

set h [open Routines.lst r]
set flist [split [read $h] \n]
close $h

foreach fitem $flist {
if { $fitem == "" } { continue }
set mm 0

foreach vfile $vlist {
if { $vfile == "" } { continue }
#puts "To search for $fitem in $vfile"
set r [searchFile $vfile $fitem]
if {$r == 0} {
  #puts "No sign of $fitem in $vfile"
}
set mm [expr {$mm + $r}]
}
if { $mm < 1 } {
   puts "No sign at all of $fitem"
}
}
It's not foolproof. Some routines are used internally by StdFunctions.vbs. But it's helpful.