File: mactopl.c

package info (click to toggle)
nethack 3.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,468 kB
  • sloc: ansic: 266,495; cpp: 13,652; yacc: 2,903; perl: 1,426; lex: 581; sh: 535; xml: 372; awk: 98; makefile: 68; fortran: 51; sed: 11
file content (66 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download | duplicates (5)
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
55
56
57
58
59
60
61
62
63
64
65
66
/* NetHack 3.6	mactopl.c	$NHDT-Date: 1432512797 2015/05/25 00:13:17 $  $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
/* NetHack may be freely redistributed.  See license for details. */

#include "hack.h"
#include "mactty.h"
#include "macwin.h"
#include "macpopup.h"

char
queued_resp(char *resp)
{
    char buf[30];
    if (try_key_queue(buf)) {
        if (!resp || strchr(resp, buf[0]))
            return buf[0];
        if (digit(buf[0]) && strchr(resp, '#')) {
            yn_number = atoi(buf);
            return '#';
        }
    }
    return '\0';
}

char
topl_yn_function(const char *query, const char *resp, char def)
{
    char buf[30];
    char c = queued_resp((char *) resp);
    if (!c) {
        enter_topl_mode((char *) query);
        topl_set_resp((char *) resp, def);

        do {
            c = readchar();
            if (c && resp && !strchr(resp, c)) {
                nhbell();
                c = '\0';
            }
        } while (!c);

        topl_set_resp("", '\0');
        leave_topl_mode(buf);
        if (c == '#')
            yn_number = atoi(buf);
    }
    return c;
}

char
mac_yn_function(query, resp, def)
const char *query, *resp;
char def;
/*
 *   Generic yes/no function. 'def' is the default (returned by space or
 *   return; 'esc' returns 'q', or 'n', or the default, depending on
 *   what's in the string. The 'query' string is printed before the user
 *   is asked about the string.
 *   If resp is NULL, any single character is accepted and returned.
 */
{
    return topl_yn_function(query, resp, def);
}

/* mactopl.c */