3 İşlemeler 2284fe6e38 ... e7b8e5f57c

Yazar SHA1 Mesaj Tarih
  Arne Babenhauserheide e7b8e5f57c better help 4 yıl önce
  Arne Babenhauserheide cfb2cb8e1e better help output 4 yıl önce
  Arne Babenhauserheide 7957d08ece add minimal commandline handling to example 4 yıl önce
4 değiştirilmiş dosya ile 95 ekleme ve 5 silme
  1. 41 1
      fcp-example.scm
  2. 40 1
      fcp-example.w
  3. 7 2
      fcp.scm
  4. 7 1
      fcp.w

+ 41 - 1
fcp-example.scm

@@ -7,6 +7,7 @@ exec -a "${0}" guile -L $(dirname $(realpath "$0")) -e '(fcp-example)' -c '' "${
 
 ;; for emacs (defun test-this-file () (interactive) (save-current-buffer) (async-shell-command (concat (buffer-file-name (current-buffer)) " --test")))
 
+
 (define-module (fcp-example)
     #:export (main))
 
@@ -18,11 +19,14 @@ exec -a "${0}" guile -L $(dirname $(realpath "$0")) -e '(fcp-example)' -c '' "${
              send-message processor-put! processor-delete!
              printing-passthrough-processor printing-discarding-processor 
              discarding-processor processor-nodehello-printer
-             processor-datafound-getdata 
+             processor-datafound-getdata
+             node-ip-set! node-port-set!
              task-id
              call-with-fcp-connection with-fcp-connection)
+    (only (ice-9 pretty-print) pretty-print)
     (only (srfi srfi-1) first second third assoc)
     (only (srfi srfi-26) cut)
+    (srfi srfi-37 );; commandline handling
     (only (rnrs bytevectors) string->utf8 utf8->string))
 
 
@@ -68,7 +72,43 @@ exec -a "${0}" guile -L $(dirname $(realpath "$0")) -e '(fcp-example)' -c '' "${
   (processor-put! record-successful-download)
   (processor-put! remove-successful-tasks-from-queue))
 
+
+;; commandline handling via srfi-37
+(define options
+    (list
+        (option '(#\V "version") #f #f
+            (λ (opt name args loads)
+                (display "Guile FCP version 0.2\n")
+                (quit)))
+        (option '(#\h "help") #f #f
+            (λ (opt name args loads)
+                (format #t "Usage: ~a [options] 
+                
+Options: 
+    -h --help                                 show this dialog
+    -V --version                              show the version
+     -H IP_OR_HOSTNAME --host=IP_OR_HOSTNAME  set the node address
+    -P PORT --port=PORT                       set the FCP port
+" (car (program-arguments)))
+                (quit)))
+        (option '(#\P "port") #t #f
+            (λ (opt name arg loads)
+                (node-port-set! arg)
+                loads))
+        (option '(#\H "host") #t #f
+            (λ (opt name arg loads)
+                (node-ip-set! arg)
+                loads))))
+
+
 (define (main args)
+  (define arguments
+    (args-fold (cdr args)
+              options
+              (lambda (opt name arg loads)
+                (error "Unrecognized option `~A'" name))
+              (lambda (op loads) (cons op loads))
+              '()))
   (setup-handlers)
   ;; open the FCP connection. Anything inside this scope can
   ;; communicate directly with Freenet via FCP, other interaction

+ 40 - 1
fcp-example.w

@@ -18,11 +18,14 @@ import
              . send-message processor-put! processor-delete!
              . printing-passthrough-processor printing-discarding-processor 
              . discarding-processor processor-nodehello-printer
-             . processor-datafound-getdata 
+             . processor-datafound-getdata
+             . node-ip-set! node-port-set!
              . task-id
              . call-with-fcp-connection with-fcp-connection
+    only (ice-9 pretty-print) pretty-print
     only (srfi srfi-1) first second third assoc
     only (srfi srfi-26) cut
+    srfi srfi-37 ;; commandline handling
     only (rnrs bytevectors) string->utf8 utf8->string
 
 
@@ -68,7 +71,43 @@ define : setup-handlers
   processor-put! record-successful-download
   processor-put! remove-successful-tasks-from-queue
 
+
+;; commandline handling via srfi-37
+define options
+    list
+        option '(#\V "version") #f #f
+            λ (opt name args loads)
+                display "Guile FCP version 0.2\n"
+                quit
+        option '(#\h "help") #f #f
+            λ (opt name args loads)
+                format #t "Usage: ~a [options] 
+                
+Options: 
+    -h --help                                 show this dialog
+    -V --version                              show the version
+     -H IP_OR_HOSTNAME --host=IP_OR_HOSTNAME  set the node address
+    -P PORT --port=PORT                       set the FCP port
+" : car : program-arguments
+                quit
+        option '(#\P "port") #t #f
+            λ (opt name arg loads)
+                node-port-set! arg
+                . loads
+        option '(#\H "host") #t #f
+            λ (opt name arg loads)
+                node-ip-set! arg
+                . loads
+
+
 define : main args
+  define arguments
+    args-fold : cdr args
+              . options
+              lambda : opt name arg loads
+                error "Unrecognized option `~A'" name
+              lambda (op loads) : cons op loads
+              . '()
   setup-handlers
   ;; open the FCP connection. Anything inside this scope can
   ;; communicate directly with Freenet via FCP, other interaction

+ 7 - 2
fcp.scm

@@ -17,7 +17,8 @@ exec -a "${0}" guile -L $(dirname $(realpath "$0")) -e '(fcp)' -c '' "${@}"
       send-message processor-put! processor-delete!
       printing-passthrough-processor printing-discarding-processor 
       discarding-processor processor-nodehello-printer
-      processor-datafound-getdata 
+      processor-datafound-getdata
+      node-ip-set! node-port-set!
       task-id
       call-with-fcp-connection with-fcp-connection))
 
@@ -539,7 +540,11 @@ Options:
          #t)
        (else #f))))
        
-    
+(define (node-ip-set! node-ip)
+    (set! ip node-ip))
+(define (node-port-set! node-port)
+    (set! port node-port))
+
 (define (main args)
   (define put-task (task-id))
   (define get-task (task-id))

+ 7 - 1
fcp.w

@@ -26,6 +26,7 @@ define-module : fcp
       . discarding-processor processor-nodehello-printer
       . processor-datafound-getdata 
       . task-id
+      . node-ip-set! node-port-set!
       . call-with-fcp-connection with-fcp-connection
 
 define version "0.0.0 just-do-it"
@@ -545,7 +546,12 @@ define : final-action? args
          test
          . #t
        else #f
-       
+
+define : node-port-set! node-port
+    set! port node-port
+define : node-ip-set! node-ip
+    set! ip node-ip
+
     
 define : main args
   define put-task : task-id