~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to testsuite/tests/lib-scanf-2/tscanf2_slave.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 21:35:08 UTC
  • mfrom: (1.1.11 upstream) (12.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110421213508-kg34453aqmb0moha
* Fixes related to -output-obj with g++ (in debian/patches):
  - add Declare-primitive-name-table-as-const-char
  - add Avoid-multiple-declarations-in-generated-.c-files-in
  - fix Embed-bytecode-in-C-object-when-using-custom: the closing
    brace for extern "C" { ... } was missing in some cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* A very simple slave:
 
2
   - read the string " Ping" on stdin,
 
3
   - then print the string "-pong" on stderr,
 
4
   - and send it back on stdout
 
5
   - until reading the string "stop" on stdin,
 
6
   - then print the string "!\n" on stderr,
 
7
   - send back the string "OK, bye!" on stdout,
 
8
   - and die.
 
9
 
 
10
   Use the communication module Test_scanf2_io. *)
 
11
 
 
12
open Tscanf2_io;;
 
13
 
 
14
let ib = Scanf.Scanning.from_channel stdin;;
 
15
let ob = Buffer.create 1024
 
16
and oc = stdout;;
 
17
 
 
18
let send_string_pong ob = send_string ob oc "-pong";;
 
19
let send_string_okbye ob = send_string ob oc "OK, bye!";;
 
20
 
 
21
while true do
 
22
  let s = receive_string ib in
 
23
  match s with
 
24
  | " Ping" -> Printf.eprintf "-pong"; flush stderr; send_string_pong ob
 
25
  | "stop" -> Printf.eprintf "!\n"; flush stderr; send_string_okbye ob; exit 0
 
26
  | s -> failwith ("Slave: unbound string " ^ s)
 
27
done
 
28
;;