File: ocaml_pwd.ml

package info (click to toggle)
coq 8.16.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,596 kB
  • sloc: ml: 219,376; sh: 3,545; python: 3,231; ansic: 2,529; makefile: 767; lisp: 279; javascript: 63; xml: 24; sed: 2
file content (26 lines) | stat: -rw-r--r-- 656 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
21
22
23
24
25
26
open Arg

let quoted = ref false
let trailing_slash = ref false

let arguments = [
  "-quoted",Set quoted, "Quote path";
  "-trailing-slash",Set trailing_slash, "End the path with a /";
]
let subject = ref None
let set_subject x =
  if !subject <> None then
    failwith "only one path";
  subject := Some x

let _ =
  Arg.parse arguments set_subject "Usage:";
  let subject =
    match !subject with
    | None -> failwith "no path given";
    | Some x -> x in
  Sys.chdir subject;
  let dir = Sys.getcwd () in
  let dir = if !trailing_slash then dir ^ "/" else dir in
  let dir = if !quoted then Filename.quote dir else dir in
  Format.printf "%s%!" dir