File: command-line-demo.thp

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (54 lines) | stat: -rw-r--r-- 1,950 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;; -*-theme-*-

;; Copyright (C) 2022 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

;; Expected results: translation and running OK


(define-proper-program (examples command-line-demo)

  (import (standard-library core)
	  (standard-library command-line-parser)
	  (standard-library list-utilities)
	  (standard-library console-io))

  (define-main-proc (((l-args (:uniform-list <string>))) <none> nonpure)
    (let-mutable ((str-output-file <string> "")
		  (b-flag <boolean> #f)
		  (str-input-file <string> ""))
      (let* ((argdesc1
	      (create <argument-descriptor> #\f #f
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! b-flag #t))))
	     (argdesc2
	      (create <argument-descriptor> "flag" #f
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! b-flag #t))))
	     (argdesc3
	      (create <argument-descriptor> #\o #t
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! str-output-file str-option-arg))))
	     (argdesc4
	      (create <argument-descriptor> "output-file" #t
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! str-output-file str-option-arg))))
	     (proc-handle-proper-args
	      (lambda (((l-proper-args (:uniform-list <string>)))
		       <none> nonpure)
		(if (= (length l-proper-args) 1)
		    (set! str-input-file
			  (uniform-list-ref l-proper-args 0))
		    (console-display-line "Invalid number of input files."))))
	     (l-arg-descs
	      (list argdesc1 argdesc2 argdesc3 argdesc4))
	     (l-args1 (drop l-args 1)))
	(parse-command-line l-args1 l-arg-descs proc-handle-proper-args))
      (console-display "input file: ")
      (console-display-line str-input-file)
      (console-display "output file: ")
      (console-display-line str-output-file)
      (if b-flag
	  (console-display-line "flag set")
	  (console-display-line "flag unset")))))