Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /src/common/c-string.sml
ViewVC logotype

View of /src/common/c-string.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 53 - (download) (annotate)
Fri Apr 4 19:09:36 2008 UTC (11 years, 8 months ago) by jhr
File size: 725 byte(s)
  move low-level utility code into common; start draw2d.
(* c-string.sml
 * COPYRIGHT (c) 2006 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.

signature C_STRING =
    type c_string = MLton.Pointer.t
    val strlen : c_string -> int
    val toML : c_string -> string option

structure CString : C_STRING =

    type c_string = MLton.Pointer.t

    fun getChar (s, i) = Byte.byteToChar (MLton.Pointer.getWord8 (s, i))

    fun strlen s = let
	  fun lp n = if getChar(s, n) = #"\000" then n else lp(n+1)
	    lp 0

  (* convert an C pointer to an SML string value *)
    fun toML (s : MLton.Pointer.t) = if (s = MLton.Pointer.null)
	  then NONE
	  else SOME(CharVector.tabulate (strlen s, fn i => getChar (s, i)))


ViewVC Help
Powered by ViewVC 1.0.0