Ticket #261: utils.scm.diff

File utils.scm.diff, 3.0 KB (added by felix winkelmann, 14 years ago)
  • utils.scm

    old new  
    136136# include <windows.h>
    137137# define C_HAS_MESSAGE_BOX 1
    138138static int
    139 C_confirmation_dialog(char *msg, char *caption, int def)
     139C_confirmation_dialog(char *msg, char *caption, int def, int abort)
    140140{
    141141  int d = 0, r;
     142  int t = abort ? MB_YESNOCANCEL : MB_YESNO;
    142143
    143144  switch(def) {
    144145  case 0: d = MB_DEFBUTTON1; break;
     
    146147  case 2: d = MB_DEFBUTTON3;
    147148  }
    148149
    149   r = MessageBox(NULL, msg, caption, MB_YESNOCANCEL | MB_ICONQUESTION | d);
     150  r = MessageBox(NULL, msg, caption, t | MB_ICONQUESTION | d);
    150151
    151152  switch(r) {
    152153  case IDYES: return 1;
     
    157158#else
    158159# define C_HAS_MESSAGE_BOX 0
    159160static int
    160 C_confirmation_dialog(char *msg, char *caption, int def) { return -1; }
     161C_confirmation_dialog(char *msg, char *caption, int def, int abort) { return -1; }
    161162#endif
    162163<#
    163164
    164165(define-foreign-variable C_HAS_MESSAGE_BOX bool)
    165166
    166167(define yes-or-no?
    167   (let ((dialog (foreign-lambda int "C_confirmation_dialog" c-string c-string int)))
     168  (let ((dialog (foreign-lambda int "C_confirmation_dialog" c-string c-string int bool)))
    168169    (lambda (str #!key default title (abort reset))
    169       (define (get-input)
    170         (if (and C_HAS_MESSAGE_BOX (not (##sys#fudge 4))) ; C_gui_mode
    171             (let ((r (dialog
    172                       str
    173                       (or title "CHICKEN Runtime")
    174                       (cond ((string-ci=? default "yes") 0)
    175                             ((string-ci=? default "no") 1)
    176                             (else 2)))))
    177               (case r
    178                 ((0) "no")
    179                 ((1) "yes")
    180                 (else "abort")))
    181             (string-trim-both (read-line))))
    182       (let loop ()
    183         (printf "~%~A (yes/no/abort) " str)
    184         (when default (printf "[~A] " default))
    185         (flush-output)
    186         (let ((ln (get-input)))
    187           (cond ((eof-object? ln) (set! ln "abort"))
    188                 ((and default (string=? "" ln)) (set! ln default)) )
    189           (cond ((string-ci=? "yes" ln) #t)
    190                 ((string-ci=? "no" ln) #f)
    191                 ((string-ci=? "abort" ln) (abort))
    192                 (else
    193                  (printf "~%Please enter \"yes\", \"no\" or \"abort\".~%")
    194                  (loop) ) ) ) ) ) ) )
     170      (let ((gui (and C_HAS_MESSAGE_BOX (not (##sys#fudge 4))))) ; C_gui_mode
     171        (define (get-input)
     172          (if gui
     173              (let ((r (dialog
     174                        str
     175                        (or title "CHICKEN Runtime")
     176                        (cond ((not default) 3)
     177                              ((string-ci=? default "yes") 0)
     178                              ((string-ci=? default "no") 1)
     179                              (else 2))
     180                        abort)))
     181                (case r
     182                  ((0) "no")
     183                  ((1) "yes")
     184                  (else "abort")))
     185              (string-trim-both (read-line))))
     186        (let loop ()
     187          (unless gui
     188            (printf "~%~A (yes/no~a) " str (if abort "/abort" ""))
     189            (when default (printf "[~A] " default))
     190            (flush-output))
     191          (let ((ln (get-input)))
     192            (cond ((eof-object? ln) (set! ln "abort"))
     193                  ((and default (string=? "" ln)) (set! ln default)) )
     194            (cond ((string-ci=? "yes" ln) #t)
     195                  ((string-ci=? "no" ln) #f)
     196                  ((and abort (string-ci=? "abort" ln)) (abort))
     197                  (else
     198                   (if abort
     199                       (printf "~%Please enter \"yes\" or \"no\".~%")
     200                       (printf "~%Please enter \"yes\", \"no\" or \"abort\".~%"))
     201                   (loop) ) ) ) ) ) ) ) )
    195202