File: hello.st.in

package info (click to toggle)
gettext 0.18.1.1-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 70,628 kB
  • sloc: ansic: 333,297; sh: 51,604; makefile: 8,355; perl: 4,181; lisp: 3,357; yacc: 665; java: 613; cs: 578; sed: 369; objc: 337; cpp: 325; awk: 80; tcl: 63; pascal: 11; php: 8
file content (58 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
" Example for use of GNU gettext.
  This file is in the public domain.

  Source code of the GNU Smalltalk program.
"

"Unfortunately the PackageLoader method fileInPackage: is extra verbose:
 It outputs 'Loading package I18N'. This will be fixed in smalltalk-2.2.

PackageLoader fileInPackage: 'I18N' !

In the meantime, we use this workaround."

| saved sink |
saved := Transcript message.
sink := WriteStream with: String new.
Transcript message: sink -> #nextPutAll:.
PackageLoader fileInPackage: 'I18N'.
Transcript message: saved.
!

Object subclass: #Main
  instanceVariableNames: ''
  classVariableNames: 'NLS' 
  poolDictionaries: ''
  category: 'Program'
!
!Main methodsFor: 'running'!
run
  NLS := I18N Locale default messages domain: 'hello-smalltalk' localeDirectory: '@localedir@'.
  Transcript showCr: (NLS ? 'Hello, world!').
  Transcript showCr: ((NLS ? 'This program is running as process number %1.') bindWith: self getpid).
!


"Unfortunately I cannot define getpid like this - it gives
 'C function getpid not defined'.

SystemDictionary defineCFunc: 'getpid'
  withSelectorArgs: 'getpid'
  returning: #int
  args: #()
!

So let's define it through an external process."

!Main methodsFor: 'auxiliary stuff'!
getpid
  | stream pid |
  stream := FileDescriptor popen: 'echo $PPID' dir: #read.
  pid := stream contents asNumber.
  stream close.
  ^ pid
!
!


Main new run!