Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/eXene/lib/protocol/xserver-addr.sml
ViewVC logotype

Annotation of /sml/trunk/src/eXene/lib/protocol/xserver-addr.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 (* xserver-addr.sml
2 :     *
3 :     * COPYRIGHT (c) 1990,1991 by John H. Reppy. See COPYRIGHT file for details.
4 :     *)
5 :    
6 :     structure XServerAddr : sig
7 :    
8 :     datatype server_addr
9 :     = UNIX of string (* ":dpy.scr" *)
10 :     | INET_Hostname of (string * int) (* "hostname:dpy.scr" *)
11 :     | INET_Addr of (string * int) (* "ddd.ddd.ddd.ddd:dpy.scr" *)
12 :    
13 :     exception BadAddr of string
14 :    
15 :     val getServerAddr : string -> {
16 :     addr : server_addr,
17 :     dpy_name : string,
18 :     screen : int
19 :     }
20 :    
21 :     end = struct
22 :    
23 :     structure SS = Substring
24 :     structure F = Format
25 :    
26 :     datatype server_addr
27 :     = UNIX of string (* ":dpy.scr" *)
28 :     | INET_Hostname of (string * int) (* "hostname:dpy.scr" *)
29 :     | INET_Addr of (string * int) (* "ddd.ddd.ddd.ddd:dpy.scr" *)
30 :    
31 :     exception BadAddr of string
32 :    
33 :     val xTCPPort = 6000
34 :     val xUNIXPath = "/tmp/.X11-unix/X"
35 :    
36 :     fun findChar c (s, j)= let
37 :     fun find i = if (String.sub(s, i) = c) then i else find(i+1)
38 :     in
39 :     (find j)
40 :     end
41 :    
42 :     fun mkUNIXAddr (dpyNum, scr) = {
43 :     addr = UNIX(xUNIXPath ^ (Int.toString dpyNum)),
44 :     dpy_name = F.format "unix:%d.%d" [F.INT dpyNum, F.INT scr],
45 :     screen = scr
46 :     }
47 :     fun mkINETAddr (host, dpyNum, scr) = if (Char.isDigit(String.sub(host, 0)))
48 :     then {
49 :     addr = INET_Addr(host, xTCPPort+dpyNum),
50 :     dpy_name = F.format "%s:%d.%d" [F.STR host, F.INT dpyNum, F.INT scr],
51 :     screen = scr
52 :     }
53 :     else {
54 :     addr = INET_Hostname(host, xTCPPort+dpyNum),
55 :     dpy_name = F.format "%s:%d.%d" [F.STR host, F.INT dpyNum, F.INT scr],
56 :     screen = scr
57 :     }
58 :    
59 :     fun getServerAddr "" = mkUNIXAddr(0, 0)
60 :     | getServerAddr s = let
61 :     fun cvtInt ss = (case (Int.scan StringCvt.DEC Substring.getc ss)
62 :     of NONE => raise BadAddr "expected integer"
63 :     | SOME(n, _) => n
64 :     (* end case *))
65 :     val (hostname, rest) = let
66 :     val (a, b) = SS.splitl (fn #":" => false | _ => true) (SS.all s)
67 :     in
68 :     (SS.string a, SS.triml 1 b)
69 :     end
70 :     val (dpy, scr) = (case SS.tokens (fn #"." => true | _ => false) rest
71 :     of [dpy] => (cvtInt dpy, 0)
72 :     | [dpy, scr] => (cvtInt dpy, cvtInt scr)
73 :     | [] => raise BadAddr "missing display"
74 :     | _ => raise BadAddr "badly formed address"
75 :     (* end case *))
76 :     in
77 :     case hostname
78 :     of "" => mkUNIXAddr(dpy, scr)
79 :     | "unix" => mkUNIXAddr(dpy, scr)
80 :     | name => mkINETAddr(name, dpy, scr)
81 :     (* end case *)
82 :     end
83 :    
84 :     end (* XServerAddr *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0