File: variables.ml

package info (click to toggle)
misery 0.2-1.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 380 kB
  • ctags: 298
  • sloc: ml: 1,295; xml: 180; makefile: 94
file content (20 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let header_rexp = Str.regexp "^\\([a-zA-Z_-]*\\)=\\(.*\\)$"

let read_variables channel =
  let rec f acc =
    try
      let pos = pos_in channel in
      let line = input_line channel in
        if Str.string_match header_rexp line 0 then
        begin
          let variable = Str.matched_group 1 line in
          let value = Str.matched_group 2 line in
            Misc.verbose ("...read binding " ^ variable ^ "=" ^ value);
            f ((variable, value) :: acc)
        end
        else
          (seek_in channel pos; acc)
    with End_of_file -> acc
  in
    f []