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