Wednesday, December 23, 2009

GNU Source-Highlight 3.1.2

In this new version of GNU Source-Highlight some new features were added:

  • infer language for files starting with <? and <!doctype
  • qmake based build system available is available to be used as an alternative to the configure based one; this is useful to compile source-highlight with MSVC for instance
  • searches for home directory correctly also on Windows systems
Besides this, many new language definitions were added:

asm




;
; screen handling primitives
;

.model large

.data

vseg dw 0b000h
vmode db ?
x dw 0
y dw 0
color db 07h
ofs dw 0
xhite db 8

; video information block



applescript




(*
TODO just a comment

foo bar
*)

displayName(choose file with prompt "Select a file:") --if double-clicked
return -- not needed, but shows that the script stops here when "run"

on open of finderObjects -- "open" handler triggered by drag'n'drop launches
repeat with i in (finderObjects) -- in case multiple objects dropped on applet
displayName(i) -- show file/folder's info
if folder of (info for i) is true then -- process folder's contents too
tell application "Finder" to set temp to (entire contents of i)
repeat with j in (temp)
display dialog j as string -- example of doing something with each item
end repeat
end if
end repeat
end open

if CurState is 0 then
connect configuration "pccard-serial"
end if

on GetParentPath(myPath)
set oldDelimiters to AppleScript's text item delimiters -- always preserve original delimiters
set AppleScript's text item delimiters to {":"}
set pathItems to text items of (myPath as text)
if last item of pathItems is "" then set pathItems to items 1 thru -2 of pathItems -- its a folder
set parentPath to ((reverse of the rest of reverse of pathItems) as string) & ":"
(* The above line works better than the more obvious set parentPath to ((items 1 thru -2 of pathItems) as string) & ":"
because it will not return an error when passed a path for a volume, i.e., "Macintosh HD:", but rather will return ":"
indicating the desktop is the root of the given path. Andy Bachorski <andyb@APPLE.COM> *)
set AppleScript's text item delimiters to oldDelimiters -- always restore original delimiters
return parentPath
end GetParentPath



awk




$6 !~ /^ack/ && $5 !~ /[SFR]/   {
# given a tcpdump ftp trace, output one line for each send
# in the form
# <send time> <seq no>
# where <send time> is the time packet was sent (in seconds with
# zero at time of first packet) and <seq no> is the tcp sequence
# number of the packet divided by 1024 (i.e., Kbytes sent).
#
# convert time to seconds
n = split ($1,t,":")
tim = t[1]*3600 + t[2]*60 + t[3]
if (! tzero) {
tzero = tim
OFS = "\t"
}
# get packet sequence number
i = index($6,":")
printf "%7.2f\t%g\n", tim-tzero, substr($6,1,i-1)/1024
}

BEGIN{
buffer = "";
}

/\015*$/ {
gsub(/\015*$/, "");
}

/^%%S NL/ {
print "";
next;
}



bat




@ECHO OFF
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
REM - THE BELOW LINE GIVES THE USER 3 CHOICES (DEFINED AFTER /C:)
CHOICE /N /C:123 PICK A NUMBER (1, 2, or 3)%1
REM - THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END
:THREE
ECHO YOU HAVE PRESSED THREE
GOTO END
:TWO
ECHO YOU HAVE PRESSED TWO
GOTO END
:ONE
ECHO YOU HAVE PRESSED ONE
:END

:: Renames a Text File with the Current Date as the Name
:: The File Extension is Kept
::
C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
REN %1.* %CUR-DATE%.*

IF "%1" == "" XCOPY B:\*.*
IF NOT "%1" == "" XCOPY B:\%1
ECHO.
C:\BATCH\DR

FOR %%F IN (%1 %2 %3 %4 %5 %6 %7 %8 %9) DO DEL %%F



clipper




Function MAIN()
LOCAL number
INPUT "Key in a number: " TO number
IF number % 2 = 0
? "You keyed in an even number"
? "I can prove it:"
? "the result of ",number," % 2 = 0 is ", number % 2 = 0
ELSE
? "You keyed in an odd number"
? "I can prove it:"
? "the result of ",number," % 2 = 0 is ", number % 2 = 0
ENDIF
RETURN

/* Load the table.dbf and table.cdx, on unix,
you should ensure that file extensions are on
lowercase.*/
USE table INDEX table VIA "DBFCDX"
REINDEX



cobol




      $ SET SOURCEFORMAT "FREE"
IDENTIFICATION DIVISION.
PROGRAM-ID. ShortestProgram.

PROCEDURE DIVISION.
DisplayPrompt.
DISPLAY "I did it".
STOP RUN.
* Uses the ACCEPT and DISPLAY verbs to accept a student record
* from the user and display some of the fields. Also shows how
* the ACCEPT may be used to get the system date and time.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.

PROCEDURE DIVISION.
DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num1.
DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.



D




#!/usr/bin/dmd -run
/* sh style script syntax is supported */

/* Hello World in D
To compile:
dmd hello.d
or to optimize:
dmd -O -inline -release hello.d
*/

/+
a nested /+
comment
+/
+/

a = /+ // +/ 1; // parses as if 'a = 1;'
a = /+ "+/" +/ 1"; // parses as if 'a = " +/ 1";'
a = /+ /* +/ */ 3; // parses as if 'a = */ 3;'

r"hello"
r"c:\root\foo.exe"
r"ab\n" // string is 4 characters, 'a', 'b', '\', 'n'

`hello`
`c:\root\foo.exe`
`ab\n` // string is 4 characters, 'a', 'b', '\', 'n'

x"0A" // same as "\x0A"
x"00 FBCD 32FD 0A" // same as "\x00\xFB\xCD\x32\xFD\x0A"

"hello"c // char[]
"hello"w // wchar[]
"hello"d // dchar[]

import std.stdio;

void main(string[] args)
{
writefln("Hello World, Reloaded");

// auto type inference and built-in foreach
foreach (argc, argv; args)
{
// Object Oriented Programming
auto cl = new CmdLin(argc, argv);
// Improved typesafe printf
writeln(cl.argnum, cl.suffix, " arg: ", cl.argv);
// Automatic or explicit memory management
delete cl;
}

// Nested structs and classes
struct specs
{
// all members automatically initialized
int count, allocated;
}

// Nested functions can refer to outer
// variables like args
specs argspecs()
{
specs* s = new specs;
// no need for '->'
s.count = args.length; // get length of array with .length
s.allocated = typeof(args).sizeof; // built-in native type properties
foreach (argv; args)
s.allocated += argv.length * typeof(argv[0]).sizeof;
return *s;
}

// built-in string and common string operations
writefln("argc = %d, " ~ "allocated = %d",
argspecs().count, argspecs().allocated);
}

class CmdLin
{
private int _argc;
private string _argv;

public:
this(int argc, string argv) // constructor
{
_argc = argc;
_argv = argv;
}

int argnum()
{
return _argc + 1;
}

string argv()
{
return _argv;
}

string suffix()
{
string suffix = "th";
switch (_argc)
{
case 0:
suffix = "st";
break;
case 1:
suffix = "nd";
break;
case 2:
suffix = "rd";
break;
default:
break;
}
return suffix;
}
}



erlang




-module(sudoku).
-author(vmiklos@frugalware.org).
-vsn('2009-11-10').
-compile(export_all).

% Return the value of Fun or an empty list based on the value of If.
% @spec fun_or_empty(If::bool(), Fun::fun() -> [any()]) -> Ret::[any()]
% Ret = Fun() if If is true, [] otherwise.
fun_or_empty(If, Fun) ->
case If of
true -> Fun();
_ -> []
end.

% Return a cell from a field.
% @spec field(I::integer(), J::integer(), Table::[any()], M::integer()) ->
% Ret::any()
% Table is a flatten list of lists, M is the length of a row,
% representing a matrix, Ret is the cell in the Ith row and Jth column.
field(I, J, Table, M) ->
P = (I-1)*M+J,
case P > length(Table) of
true -> 0;
_ -> lists:nth((I-1)*M+J, Table)
end.

% Return a cell from a field.
% @spec field(I::integer(), J::integer(), Table::[[any()]]) ->
% Ret::any()
% Ret is the cell in the Ith row and Jth column of Table.
field(I, J, Table) ->
lists:nth(J, lists:nth(I, Table)).



compiler output




no need to highlight this
c:\f\g\Makefile:1346:10: warning: overriding commands for target `styleformatter.h.texinfo' foo
/f/g/Makefile:1346:10: warning: overriding commands for target `styleformatter.h.texinfo' foo
/foo/bar/Makefile:1337: error: ignoring old commands for target 'styleformatter.h.texinfo' bar
\foo\bar\Makefile:1346: warning: overriding commands for target `styleformatter.h.texinfo'
Makefile:1337: warning: ignoring old commands for target `styleformatter.h.texinfo'



manifest files




Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.mindmap.diagram; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.mindmap.diagram.part.MindmapDiagramEditorPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.mindmap.diagram.edit.parts,
org.eclipse.mindmap.diagram.part,
org.eclipse.mindmap.diagram.providers
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.core.expressions,
org.eclipse.draw2d;visibility:=reexport,
org.eclipse.gmf.runtime.draw2d.ui;visibility:=reexport,
org.eclipse.mindmap;visibility:=reexport,
org.eclipse.mindmap.edit;visibility:=reexport,
org.eclipse.gef;visibility:=reexport,
org.eclipse.ocl.ecore;visibility:=reexport,
org.eclipse.emf.validation;visibility:=reexport,
org.eclipse.emf.validation.ocl;visibility:=reexport
Eclipse-LazyStart: true



vbscript




' The script can be called via

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

if AQresponse <> "" then
response.write(AQresponse)
else
response.write("ERROR")
end if

%>

' Actual script follows. This could be placed in a separate file,
' such as the smslib.asp file described above

<%
Dim method, secured, error_on_length, username, password, AQresponse
' User Editable Variables
secured = 0 ' Set to either 1 for SSL connection
' or 0 for normal connection.
error_on_length = 1 ' Whether to give and error on messages over 160 chracters.
' 1 for true, 0 for false.
username = "testusername" ' Your aql username, can either be set here
' or done on a per call basis from the function.
password = "testpassword" ' Your aql password, can either be set here
' or done on a per call basis from the function.

Dim objXMLHTTP, xml
message = replace(message," ","+")
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
if secured = null or secured = 0 then
xml.Open "POST", "http://gw1.aql.com/sms/sms_gw.php", False
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xml.Send "username=" & username & "&password=" & password & "&destination=" & destination &
"&message=" & message & "&originator=" & originator & "&flash=" & flash
else if secured = 1 then
xml.Open "POST", "https://gw1.aql.com/sms/sms_gw.php", False
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xml.Send "username=" & username & "&password=" & password & "&destination=" & destination &
"&message=" & message & "&originator=" & originator & "&flash=" & flash
else
call senderror(7)
end if
end if

AQresponse = xml.responseText
Set xml = nothing

End Function


%>




That's all for now :)

Sunday, December 06, 2009

Huawei E1692 in Linux Kubuntu 9.10 Karmic

In a previous post I blogged about sucessfully installing this Huawei E1692 Internet device in Ubuntu Jaunty. Now that I switched to Kubuntu Karmic I found out that this device was not recognized any more.

Fortunately, this was a known issue, and I found this blog post which summarizes the solution to use this device also in Ubuntu Karmic.

I followed the instructions, however, the device still didn't show up (in particular, it wasn't mounted as an external device so that I could run the installation procedure). Probably it's a problem of Kubuntu and not Ubuntu (and I don't have Ubuntu version of Karmic, but only the Kubuntu one), so I cannot tell for sure.

However, you only need to perform some manual steps and it works in Kubuntu as well.

First, you need to follow the instructions found in this blog post anyway.

First of all, by running dmesg after inserting the device you should see something like the following lines which, at least, tells you that the device is recognized (though not mounted):

[  664.188996] usb-storage: device found at 6                              
[ 664.188998] usb-storage: waiting for device to settle before scanning
[ 664.189997] scsi9 : SCSI emulation for USB Mass Storage devices
[ 664.190571] usb-storage: device found at 6
[ 664.190573] usb-storage: waiting for device to settle before scanning
[ 669.189727] usb-storage: device scan complete
[ 669.191577] scsi 8:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 669.191585] usb-storage: device scan complete
[ 669.194267] scsi 9:0:0:0: Direct-Access HUAWEI SD Storage 2.31 PQ: 0 ANSI: 2
[ 669.212737] sr1: scsi-1 drive
[ 669.213052] sr 8:0:0:0: Attached scsi CD-ROM sr1
[ 669.213215] sr 8:0:0:0: Attached scsi generic sg2 type 5
[ 669.214044] sd 9:0:0:0: Attached scsi generic sg3 type 0
[ 669.235684] sd 9:0:0:0: [sdb] Attached SCSI removable disk
In particular, this tells that the "CD" part of the device is represented by sr1, so you run
sudo mount -t iso9660 /dev/sr1 /mnt/
and then you can run the installation
sudo /mnt/install_linux
You should see a terminal window

and after that, you should see the applet


After the installation, the device is detected automatically by the system, the applet shows up, and you won't need to do the mount manually.

Hope this helps :-)