<commit_before>;; Copyright (c) 2013-2014 by <NAME>, All Rights Reserved.


(define (has-arg? arg args)
  (memp (lambda (s) (string=? s arg)) args))

(define (get-arg-val arg args)
  (let loop ((args args))
    (cond ((null? args) #f)
          ((string=? arg (car args))
           (if (null? (cdr args))
               (error "Argument expects a parameter." arg)
               (cadr args)))
          (else (loop (cdr args))))))

(define *valid-command-line-options* '("-e" "-c" "-x" "-ld-options" "-cc-options" "-v" "-h"))

(define (valid-command-line-option? opt)
  (member opt *valid-command-line-options*))

(define (assert-command-line-options args)
  (let loop ((args args))
    (if (null? args) #t
        (begin (if (char=? (string-ref (car args) 0) #\-)
                   (if (not (valid-command-line-option? (car args)))
                       (error "Invalid command line option." (car args))))
               (loop (cdr args))))))

(define (show-usage)
  (println "Usage: slogan [options]")
  (println "             (to start the interactive REPL)")
  (println "or     slogan [options] script")
  (println "             (to execute or compile a slogan script)")
  (println "where options include: ")
  (println "     -e            Execute a script.")
  (println "     -c            Compile a script into a dynamically loadable object file.")
  (println "     -x            Compile a script into an executable binary.")
  (println "     -ld-options   Additional options that will be passed to the system linker.")
  (println "     -cc-options   Additional options that will be passed to the system C compiler.") 
  (println "     -v            Display version information.")
  (println "     -h            Print this help.")
  (println))

(define (show-version)
  (println "slogan version \"" *major-version* "." *minor-version* "-" *release-name* "\"")
  (println))

(define (show-version-and-quit)
  (show-version)
  (exit 0))

(define (show-usage-and-quit)
  (show-usage)
  (exit 0))

(define (execute-script scriptname)
  (run-slgn-script scriptname))

(define (execute-script-and-quit scriptname)
  (execute-script scriptname)
  (exit 0))

(define (compile-script scriptname args exe)
  (let ((ld-options (get-arg-val "-ld-options" args))
        (cc-options (get-arg-val "-cc-options" args)))
    (if exe (compile scriptname exe: #t ld_options: ld-options
                     cc_options: cc-options)
        (compile scriptname assemble: #t ld_options: ld-options
                 cc_options: cc-options))))
  
(define (compile-script-and-quit scriptname args #!optional exe)
  (compile-script scriptname args exe)
  (exit 0))

(define (process-args args)
  (assert-command-line-options args)
  (if (has-arg? "-h" args)
      (show-usage-and-quit))
  (if (has-arg? "-v" args)
      (show-version-and-quit))
  (if (has-arg? "-e" args)
      (execute-script-and-quit (get-arg-val "-e" args)))
  (if (has-arg? "-c" args)
      (compile-script-and-quit (get-arg-val "-c" args) args))
  (if (has-arg? "-x" args)
      (compile-script-and-quit (get-arg-val "-x" args) args #t))
  (repl (current-input-port)))

(process-args (command-line))<commit_msg>command line option to launch repl.<commit_after>;; Copyright (c) 2013-2014 by <NAME>, All Rights Reserved.


(define (has-arg? arg args)
  (memp (lambda (s) (string=? s arg)) args))

(define (get-arg-val arg args)
  (let loop ((args args))
    (cond ((null? args) #f)
          ((string=? arg (car args))
           (if (null? (cdr args))
               (error "Argument expects a parameter." arg)
               (cadr args)))
          (else (loop (cdr args))))))

(define *valid-command-line-options* '("-e" "-c" "-x" "-ld-options" "-cc-options" "-v" "-h" "-r"))

(define (valid-command-line-option? opt)
  (member opt *valid-command-line-options*))

(define (assert-command-line-options args)
  (let loop ((args args))
    (if (null? args) #t
        (begin (if (char=? (string-ref (car args) 0) #\-)
                   (if (not (valid-command-line-option? (car args)))
                       (error "Invalid command line option." (car args))))
               (loop (cdr args))))))

(define (show-usage)
  (println "Usage: slogan [options]")
  (println "             (to start the interactive REPL)")
  (println "or     slogan [options] script")
  (println "             (to execute or compile a slogan script)")
  (println "where options include: ")
  (println "     -e            Execute a script.")
  (println "     -c            Compile a script into a dynamically loadable object file.")
  (println "     -x            Compile a script into an executable binary.")
  (println "     -ld-options   Additional options that will be passed to the system linker.")
  (println "     -cc-options   Additional options that will be passed to the system C compiler.") 
  (println "     -r            Launch REPL after performing other options.")
  (println "     -v            Display version information and quit.")
  (println "     -h            Print this help and quit.")
  (println))

(define (show-version)
  (println "slogan version \"" *major-version* "." *minor-version* "-" *release-name* "\"")
  (println))

(define (execute-script scriptname)
  (run-slgn-script scriptname))

(define (compile-script scriptname args exe)
  (let ((ld-options (get-arg-val "-ld-options" args))
        (cc-options (get-arg-val "-cc-options" args)))
    (if exe (compile scriptname exe: #t ld_options: ld-options
                     cc_options: cc-options)
        (compile scriptname assemble: #t ld_options: ld-options
                 cc_options: cc-options))))

(define (command-line-has-options? args)
  (memp (lambda (s) (char=? (string-ref s 0) #\-)) args))

(define (process-args args)
  (assert-command-line-options args)
  (if (has-arg? "-h" args)
      (show-usage))
  (if (has-arg? "-v" args)
      (show-version))
  (if (has-arg? "-e" args)
      (execute-script (get-arg-val "-e" args)))
  (if (has-arg? "-c" args)
      (compile-script (get-arg-val "-c" args) args))
  (if (has-arg? "-x" args)
      (compile-script (get-arg-val "-x" args) args #t))
  (if (command-line-has-options? args)
      (if (has-arg? "-r" args)
          (repl (current-input-port))
          (exit 0))
      (repl (current-input-port))))

(process-args (command-line))
{'fraction_non_alphanumeric': 0.16352699066012347, 'fraction_numerical': 0.0037992718062371377, 'mean_word_length': 2.48868028713418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3250284', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2027, 'n_words': 632}