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

SCM Repository

[sml3d] View of /trunk/sml3d/gen/gen-gl-glue/to-xml.sml
ViewVC logotype

View of /trunk/sml3d/gen/gen-gl-glue/to-xml.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 713 - (download) (annotate)
Thu Jan 21 03:52:32 2010 UTC (8 years, 10 months ago) by jhr
File size: 1801 byte(s)
  Fixed a bug for when there is a space between the function name and "(" in the prototype.
(* a little program to convert C prototypes to XML specifications
 * as used by the generation tool.
 *)

structure SS = Substring

fun parseLn ln = let
      fun trimWS ss = SS.dropl Char.isSpace (SS.dropr Char.isSpace ss)
      val ss = trimWS (SS.full ln)
    (* split at the prototype's "(" *)
      val (retTy, params) = SS.splitl (fn #"(" => false | _ => true) ss
    (* trim any whitespace between the function name and the "(" that we just removed *)
      val retTy = SS.dropr Char.isSpace retTy
    (* everything before the name is the return type *)
      val (retTy, name) = SS.splitr (not o Char.isSpace) retTy
      val params =
	    SS.tokens
	      (fn #"," => true | #"(" => true | #")" => true | #";" => true | _ => false)
		params
      fun doParam ss = let
	    val ss = trimWS ss
	    val (ty, name) = SS.splitr (fn #"*" => false | c => not(Char.isSpace c)) ss
	    in
	      (SS.string(trimWS ty), SS.string(trimWS name))
	    end
      val params = List.map doParam params
      in
	(SS.string(trimWS retTy), SS.string name, params)
      end

fun prLn ln = let
      val (retTy, name, params) = parseLn ln
      fun prParam (ty, name) = print(concat[
	      "\t  <param type=\"", ty, "\" name=\"", name, "\"/>\n"
	    ])
      in
	print(concat["\t<function name=\"", name, "\" returnType=\"", retTy, "\""]);
	case List.filter (fn ("", "void") => false | ("", "GLvoid") => false | _ => true) params
	 of [] => print "/>\n"
	  | l => (
	      print ">\n";
	      List.app prParam params;
	      print "\t</function>\n")
	(* end case *)
      end

fun doFile file = let
      val inS = TextIO.openIn file
      fun lp () = (case TextIO.inputLine inS
	     of NONE => ()
	      | SOME ln => (prLn ln; lp())
	    (* end case *))
      in
        lp();
	TextIO.closeIn inS
      end

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