]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - maccfg.c
Missing dependency
[PuTTY.git] / maccfg.c
1 /* $Id: maccfg.c,v 1.1.2.5 1999/03/28 02:06:10 ben Exp $ */
2 /*
3  * maccfg.c -- Mac port configuration
4  */
5
6 #include <MacMemory.h>
7 #include <Resources.h>
8 #include <TextUtils.h>
9
10 #include <assert.h>
11 #include <string.h>
12
13 #include "putty.h"
14 #include "mac.h"
15 #include "macresid.h"
16
17 struct strloc {
18     short id, idx;
19 };
20
21 static void get_string(struct strloc *l, char *d, size_t maxlen) {
22     Str255 s;
23     int i, len;
24
25     GetIndString(s, l->id, l->idx);
26     len = s[0];
27     /* maxlen includes a terminator */
28     if (len > maxlen - 1)
29         len = maxlen - 1;
30     for (i = 0; i < len; i++)
31         d[i] = s[i + 1];
32     d[i] = '\0';
33 }
34
35 static void get_wordness(short id, short *dst) {
36     Handle h;
37
38     h = GetResource(PREF_wordness_type, id);
39     if (h == NULL || *h == NULL)
40         fatalbox ("Couldn't get wordness id %d (%d)", id, ResError());
41     memcpy(dst, *h, 256 * sizeof(short));
42 }
43
44 #pragma options align=mac68k
45 struct pSET {
46     unsigned long basic_flags;
47 #define CLOSE_ON_EXIT   0x80000000
48     unsigned long ssh_flags;
49 #define NO_PTY          0x80000000
50     unsigned long telnet_flags;
51 #define RFC_ENVIRON     0x80000000
52     unsigned long kbd_flags;
53 #define BKSP_IS_DELETE  0x80000000
54 #define RXVT_HOMEEND    0x40000000
55 #define LINUX_FUNKEYS   0x20000000
56 #define APP_CURSOR      0x10000000
57 #define APP_KEYPAD      0x08000000
58     unsigned long term_flags;
59 #define DEC_OM          0x80000000
60 #define WRAP_MODE       0x40000000
61 #define LFHASCR         0x20000000
62 #define WIN_NAME_ALWAYS 0x10000000
63     unsigned long colour_flags;
64 #define BOLD_COLOUR     0x80000000
65     unsigned long selection_flags;
66 #define IMPLICIT_COPY   0x80000000
67     struct strloc host;
68     long port;
69     long protocol;
70     struct strloc termtype, termspeed;
71     struct strloc environmt;
72     struct strloc username;
73     long width, height, savelines;
74     struct strloc font;
75     long font_height;
76     short colours_id;
77     short wordness_id;
78     unsigned short meta_modifiers;
79 };
80 #pragma options align=reset
81
82 /*
83  * Load a configuration from the current chain of resource files.
84  */
85 void mac_loadconfig(Config *cfg) {
86     Handle h;
87     struct pSET *s;
88
89     h = GetResource('pSET', PREF_settings);
90     if (h == NULL || *h == NULL)
91         fatalbox("Can't load settings");
92     HLock(h);
93     if (GetHandleSize(h) != sizeof(struct pSET))
94         fatalbox("Settings resource is wrong size (%d vs %d)",
95                  GetHandleSize(h), sizeof(struct pSET));
96     s = (struct pSET *)*h;
97     /* Basic */
98     get_string(&s->host, cfg->host, sizeof(cfg->host));
99     cfg->port = s->port;
100     cfg->protocol = s->protocol;
101     cfg->close_on_exit = (s->basic_flags & CLOSE_ON_EXIT) != 0;
102     /* SSH */
103     cfg->nopty = (s->ssh_flags & NO_PTY) != 0;
104     /* Telnet */
105     get_string(&s->termtype, cfg->termtype, sizeof(cfg->termtype));
106     get_string(&s->termspeed, cfg->termspeed, sizeof(cfg->termspeed));
107     get_string(&s->environmt, cfg->environmt, sizeof(cfg->environmt));
108     get_string(&s->username, cfg->username, sizeof(cfg->username));
109     cfg->rfc_environ = (s->telnet_flags & RFC_ENVIRON) != 0;
110     /* Keyboard */
111     cfg->bksp_is_delete = (s->kbd_flags & BKSP_IS_DELETE) != 0;
112     cfg->rxvt_homeend = (s->kbd_flags & RXVT_HOMEEND) != 0;
113     cfg->linux_funkeys = (s->kbd_flags & LINUX_FUNKEYS) != 0;
114     cfg->app_cursor = (s->kbd_flags & APP_CURSOR) != 0;
115     cfg->app_keypad = (s->kbd_flags & APP_KEYPAD) != 0;
116     cfg->meta_modifiers = s->meta_modifiers;
117     /* Terminal */
118     cfg->savelines = s->savelines;
119     cfg->dec_om = (s->term_flags & DEC_OM) != 0;
120     cfg->wrap_mode = (s->term_flags & WRAP_MODE) != 0;
121     cfg->lfhascr = (s->term_flags & LFHASCR) != 0;
122     cfg->win_name_always = (s->term_flags & WIN_NAME_ALWAYS) != 0;
123     cfg->width = s->width;
124     cfg->height = s->height;
125     get_string(&s->font, cfg->font, sizeof(cfg->font));
126     cfg->fontisbold = FALSE;            /* XXX */
127     cfg->fontheight = s->font_height;
128     cfg->vtmode = VT_POORMAN;           /* XXX */
129     /* Colour */
130     cfg->try_palette = FALSE;           /* XXX */
131     cfg->bold_colour = (s->colour_flags & BOLD_COLOUR) != 0;
132     cfg->colours = GetNewPalette(s->colours_id);
133     if (cfg->colours == NULL)
134         fatalbox("Failed to get default palette");
135     /* Selection */
136     cfg->implicit_copy = (s->selection_flags & IMPLICIT_COPY) != 0;
137     get_wordness(s->wordness_id, cfg->wordness);
138     HUnlock(h);
139     ReleaseResource(h);
140 }
141
142 /*
143  * Emacs magic:
144  * Local Variables:
145  * c-file-style: "simon"
146  * End:
147  */