From f7f273099c8798f70611550bfc06b417e5c28ac7 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 7 Oct 2002 16:45:23 +0000 Subject: [PATCH] Begin destabilisation in the wake of 0.53! This checkin contains the beginning of a Unix port. It's nowhere near done, and currently it won't even compile on Unix. But this represents the start of the process of separating out platform-specific code, and also contains the mkfiles.pl changes required to support a Unix makefile and a non-flat source tree. git-svn-id: svn://svn.tartarus.org/sgt/putty@1993 cda61777-01e9-0310-a592-d414129be87e --- Recipe | 5 +- mkfiles.pl | 116 ++++++++++++++++++++++++++++++++------- noise.c | 2 +- putty.h | 79 ++++++++------------------- puttyps.h | 15 +++++ terminal.c | 22 +++----- unicode.c | 2 + unix/pterm.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ unix/unix.h | 18 ++++++ unix/uxmisc.c | 17 ++++++ winstuff.h | 69 +++++++++++++++++++++++ 11 files changed, 429 insertions(+), 89 deletions(-) create mode 100644 puttyps.h create mode 100644 unix/pterm.c create mode 100644 unix/unix.h create mode 100644 unix/uxmisc.c diff --git a/Recipe b/Recipe index 551cfb55..3e918975 100644 --- a/Recipe +++ b/Recipe @@ -115,7 +115,8 @@ LIBS2 = LIBS ws2_32.lib # Definitions of actual programs. The program name, followed by a # colon, followed by a list of objects. Also in the list may be the -# keywords [G] for GUI or [C] for Console application. +# keywords [G] for Windows GUI app, [C] for Console app, [X] for +# X/GTK Unix app. putty : [G] GUITERM NONSSH SSH be_all MISC win_res.res LIBS1 puttytel : [G] GUITERM NONSSH be_nossh MISC win_res.res LIBS1 @@ -130,3 +131,5 @@ pageant : [G] pageant sshrsa sshpubk sshdes sshbn sshmd5 version tree234 puttygen : [G] puttygen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version + sshrand noise sshsha winstore misc winctrls sshrsa sshdss + sshpubk sshaes sshsh512 import winutils puttygen.res LIBS + +pterm : [X] pterm terminal wcwidth unicode uxmisc diff --git a/mkfiles.pl b/mkfiles.pl index 492a59d6..a31a633e 100755 --- a/mkfiles.pl +++ b/mkfiles.pl @@ -7,8 +7,12 @@ # files to compute #include dependencies. Finally, writes out the # various target Makefiles. +use FileHandle; + open IN, "Recipe" or die "unable to open Recipe file\n"; +@incdirs = ("", "unix/"); + $help = ""; # list of newline-free lines of help text %programs = (); # maps program name to listref of objects/resources %types = (); # maps program name to "G" or "C" @@ -55,7 +59,7 @@ while () { $i = shift @objs; if ($groups{$i}) { foreach $j (@{$groups{$i}}) { unshift @objs, $j; } - } elsif (($i eq "[G]" or $i eq "[C]") and defined $prog) { + } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[X]") and defined $prog) { $types{$prog} = substr($i,1,1); } else { push @$listref, $i; @@ -118,7 +122,8 @@ while (scalar @scanlist > 0) { next if defined $further{$file}; # skip if we've already done it $resource = ($file =~ /\.rc$/ ? 1 : 0); $further{$file} = []; - open IN, $file or die "unable to open source file $file\n"; + $dirfile = &findfile($file); + open IN, "$dirfile" or die "unable to open source file $file\n"; while () { chomp; /^\s*#include\s+\"([^\"]+)\"/ and do { @@ -156,24 +161,34 @@ foreach $i (keys %depends) { # Utility routines while writing out the Makefiles. +sub findfile { + my ($name) = @_; + my $dir, $i, $outdir = ""; + $i = 0; + foreach $dir (@incdirs) { + $outdir = $dir, $i++ if -f "$dir$name"; + } + die "multiple instances of source file $name\n" if $i > 1; + return "$outdir$name"; +} + sub objects { - my ($prog, $otmpl, $rtmpl, $ltmpl) = @_; + my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; my @ret; my ($i, $x, $y); @ret = (); foreach $i (@{$programs{$prog}}) { + $x = ""; if ($i =~ /^(.*)\.res/) { $y = $1; ($x = $rtmpl) =~ s/X/$y/; - push @ret, $x if $x ne ""; } elsif ($i =~ /^(.*)\.lib/) { $y = $1; ($x = $ltmpl) =~ s/X/$y/; - push @ret, $x if $x ne ""; } else { ($x = $otmpl) =~ s/X/$i/; - push @ret, $x if $x ne ""; } + push @ret, $x if $x ne ""; } return join " ", @ret; } @@ -192,19 +207,38 @@ sub splitline { } sub deps { - my ($otmpl, $rtmpl) = @_; + my ($otmpl, $rtmpl, $prefix, $dirsep) = @_; my ($i, $x, $y); + my @deps; foreach $i (sort keys %depends) { if ($i =~ /^(.*)\.res/) { + next if !defined $rtmpl; $y = $1; ($x = $rtmpl) =~ s/X/$y/; } else { ($x = $otmpl) =~ s/X/$i/; } - print &splitline(sprintf "%s: %s", $x, join " ", @{$depends{$i}}), "\n"; + @deps = @{$depends{$i}}; + @deps = map { + $_ = &findfile($_); + s/\//$dirsep/g; + $_ = $prefix . $_; + } @deps; + print &splitline(sprintf "%s: %s", $x, join " ", @deps), "\n"; } } +sub prognames { + my ($types) = @_; + my ($n); + my @ret; + @ret = (); + foreach $n (@prognames) { + push @ret, $n if index($types, $types{$n}) >= 0; + } + return @ret; +} + # Now we're ready to output the actual Makefiles. ##-- CygWin makefile @@ -240,9 +274,9 @@ print "%.res.o: %.rc\n". "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n". "\n"; -print &splitline("all:" . join "", map { " $_.exe" } @prognames); +print &splitline("all:" . join "", map { " $_.exe" } &prognames("GC")); print "\n\n"; -foreach $p (@prognames) { +foreach $p (&prognames("GC")) { $objstr = &objects($p, "X.o", "X.res.o", undef); print &splitline($p . ".exe: " . $objstr), "\n"; my $mw = $types{$p} eq "G" ? " -mwindows" : ""; @@ -250,7 +284,7 @@ foreach $p (@prognames) { print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n"; } -&deps("X.o", "X.res.o"); +&deps("X.o", "X.res.o", "", "\\"); print "\n". "version.o: FORCE;\n". @@ -304,15 +338,15 @@ print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r". " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n". "\n"; -print &splitline("all:" . join "", map { " $_.exe" } @prognames); +print &splitline("all:" . join "", map { " $_.exe" } &prognames("GC")); print "\n\n"; -foreach $p (@prognames) { +foreach $p (&prognames("GC")) { $objstr = &objects($p, "X.obj", "X.res", undef); print &splitline("$p.exe: " . $objstr . " $p.rsp"), "\n"; my $ap = ($types{$p} eq "G") ? "-aa" : "-ap"; print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$p.rsp\n\n"; } -foreach $p (@prognames) { +foreach $p (&prognames("GC")) { print $p, ".rsp: \$(MAKEFILE)\n"; $objstr = &objects($p, "X.obj", undef, undef); @objlist = split " ", $objstr; @@ -339,7 +373,7 @@ foreach $p (@prognames) { print "\techo " . &objects($p, undef, "X.res", undef) . " >> $p.rsp\n"; print "\n"; } -&deps("X.obj", "X.res"); +&deps("X.obj", "X.res", "", "\\"); print "\n". "version.o: FORCE\n". @@ -381,14 +415,14 @@ print ".rc.res:\n". "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n". "\n"; -print &splitline("all:" . join "", map { " $_.exe" } @prognames); +print &splitline("all:" . join "", map { " $_.exe" } &prognames("GC")); print "\n\n"; -foreach $p (@prognames) { +foreach $p (&prognames("GC")) { $objstr = &objects($p, "X.obj", "X.res", undef); print &splitline("$p.exe: " . $objstr . " $p.rsp"), "\n"; print "\tlink \$(LFLAGS) -out:$p.exe -map:$p.map \@$p.rsp\n\n"; } -foreach $p (@prognames) { +foreach $p (&prognames("GC")) { print $p, ".rsp: \$(MAKEFILE)\n"; $objstr = &objects($p, "X.obj", "X.res", "X.lib"); @objlist = split " ", $objstr; @@ -406,7 +440,7 @@ foreach $p (@prognames) { } print "\n"; } -&deps("X.obj", "X.res"); +&deps("X.obj", "X.res", "", "\\"); print "\n". "# Hack to force version.o to be rebuilt always\n". @@ -431,3 +465,47 @@ print "\t-del *.idb\n". "\t-del debug.log\n"; select STDOUT; close OUT; + +##-- X/GTK/Unix makefile +open OUT, ">unix/Makefile.gtk"; select OUT; +print +"# Makefile for PuTTY under X/GTK and Unix.\n". +"#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". +"# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; +# gcc command line option is -D not /D +($_ = $help) =~ s/=\/D/=-D/gs; +print $_; +print +"\n". +"# You can define this path to point at your tools if you need to\n". +"# TOOLPATH = /opt/gcc/bin\n". +"CC = \$(TOOLPATH)cc\n". +"\n". +&splitline("CFLAGS = -Wall -O2 -I. -I.. `gtk-config --cflags`")."\n". +"LDFLAGS = -s `gtk-config --libs`\n". +"\n". +".SUFFIXES:\n". +"\n". +"%.o: %.c\n". +"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n". +"\n"; +print &splitline("all:" . join "", map { " $_" } &prognames("X")); +print "\n\n"; +foreach $p (&prognames("X")) { + $objstr = &objects($p, "X.o", undef, undef); + print &splitline($p . ": " . $objstr), "\n"; + $libstr = &objects($p, undef, undef, "-lX"); + print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . + $objstr . " $libstr", 69), "\n\n"; +} +&deps("X.o", undef, "../", "/"); +print +"\n". +"version.o: FORCE;\n". +"# Hack to force version.o to be rebuilt always\n". +"FORCE:\n". +"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n". +"clean:\n". +"\trm -f *.o *.exe\n". +"\n"; +select STDOUT; close OUT; diff --git a/noise.c b/noise.c index a094d25e..141f111c 100644 --- a/noise.c +++ b/noise.c @@ -129,7 +129,7 @@ void noise_regular(void) * counter to the noise pool. It gets the scan code or mouse * position passed in. */ -void noise_ultralight(DWORD data) +void noise_ultralight(unsigned long data) { DWORD wintime; LARGE_INTEGER perftime; diff --git a/putty.h b/putty.h index 46e39c6f..67457be8 100644 --- a/putty.h +++ b/putty.h @@ -3,13 +3,23 @@ #include /* for FILENAME_MAX */ -#include "network.h" +/* + * Global variables. Most modules declare these `extern', but + * window.c will do `#define PUTTY_DO_GLOBALS' before including this + * module, and so will get them properly defined. + */ +#ifndef GLOBAL +#ifdef PUTTY_DO_GLOBALS +#define GLOBAL +#else +#define GLOBAL extern +#endif +#endif + +typedef struct config_tag Config; -#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY" -#define PUTTY_REG_PARENT "Software\\SimonTatham" -#define PUTTY_REG_PARENT_CHILD "PuTTY" -#define PUTTY_REG_GPARENT "Software" -#define PUTTY_REG_GPARENT_CHILD "SimonTatham" +#include "puttyps.h" +#include "network.h" /* * Global variables. Most modules declare these `extern', but @@ -88,7 +98,6 @@ #define ATTR_CUR_AND (~(ATTR_BOLD|ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS)) #define ATTR_CUR_XOR 0x00BA0000UL -typedef HDC Context; #define SEL_NL { 13, 10 } GLOBAL int rows, cols, savelines; @@ -117,11 +126,11 @@ GLOBAL int dbcs_screenfont; GLOBAL int font_codepage; GLOBAL int kbd_codepage; GLOBAL int line_codepage; -GLOBAL WCHAR unitab_scoacs[256]; -GLOBAL WCHAR unitab_line[256]; -GLOBAL WCHAR unitab_font[256]; -GLOBAL WCHAR unitab_xterm[256]; -GLOBAL WCHAR unitab_oemcp[256]; +GLOBAL wchar_t unitab_scoacs[256]; +GLOBAL wchar_t unitab_line[256]; +GLOBAL wchar_t unitab_font[256]; +GLOBAL wchar_t unitab_xterm[256]; +GLOBAL wchar_t unitab_oemcp[256]; GLOBAL unsigned char unitab_ctrl[256]; #define in_utf (utf || line_codepage==CP_UTF8) @@ -134,20 +143,6 @@ GLOBAL unsigned char unitab_ctrl[256]; #define LGTYP_PACKETS 3 /* logmode: SSH data packets */ GLOBAL char *logfile; -/* - * Window handles for the dialog boxes that can be running during a - * PuTTY session. - */ -GLOBAL HWND logbox; - -/* - * I've just looked in the windows standard headr files for WM_USER, there - * are hundreds of flags defined using the form WM_USER+123 so I've - * renumbered this NETEVENT value and the two in window.c - */ -#define WM_XUSER (WM_USER + 0x2000) -#define WM_NETEVENT (WM_XUSER + 5) - typedef enum { TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT, TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF, TS_LECHO, TS_RECHO, TS_PING, @@ -233,7 +228,7 @@ extern struct backend_list { Backend *backend; } backends[]; -typedef struct { +struct config_tag { /* Basic options */ char host[512]; int port; @@ -373,7 +368,7 @@ typedef struct { } sshbug_ignore1, sshbug_plainpw1, sshbug_rsa1, sshbug_hmac2, sshbug_derivekey2, sshbug_rsapad2, sshbug_dhgex2; -} Config; +}; /* * You can compile with -DSSH_DEFAULT to have ssh by default. @@ -456,31 +451,11 @@ void cleanup_exit(int); void noise_get_heavy(void (*func) (void *, int)); void noise_get_light(void (*func) (void *, int)); void noise_regular(void); -void noise_ultralight(DWORD data); +void noise_ultralight(unsigned long data); void random_save_seed(void); void random_destroy_seed(void); /* - * Exports from windlg.c. - */ -void defuse_showwindow(void); -int do_config(void); -int do_reconfig(HWND); -void do_defaults(char *, Config *); -void logevent(char *); -void showeventlog(HWND); -void showabout(HWND); -void verify_ssh_host_key(char *host, int port, char *keytype, - char *keystr, char *fingerprint); -void askcipher(char *ciphername, int cs); -int askappend(char *filename); -void registry_cleanup(void); -void force_normal(HWND hwnd); - -GLOBAL int nsessions; -GLOBAL char **sessions; - -/* * Exports from settings.c. */ void save_settings(char *section, int do_host, Config * cfg); @@ -578,12 +553,6 @@ extern int random_active; extern char ver[]; /* - * Exports from sizetip.c. - */ -void UpdateSizeTip(HWND src, int cx, int cy); -void EnableSizeTip(int bEnable); - -/* * Exports from unicode.c. */ #ifndef CP_UTF8 diff --git a/puttyps.h b/puttyps.h new file mode 100644 index 00000000..b64ecbd4 --- /dev/null +++ b/puttyps.h @@ -0,0 +1,15 @@ +#ifndef PUTTY_PUTTYPS_H +#define PUTTY_PUTTYPS_H + +#ifdef _WINDOWS + +#include +#include "winstuff.h" + +#else + +#include "unix.h" + +#endif + +#endif diff --git a/terminal.c b/terminal.c index a224afdd..b286efe1 100644 --- a/terminal.c +++ b/terminal.c @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -59,7 +57,7 @@ static unsigned long *disptext; /* buffer of text on real screen */ static unsigned long *dispcurs; /* location of cursor on real screen */ static unsigned long curstype; /* type of cursor on real screen */ -#define VBELL_TIMEOUT 100 /* millisecond len of visual bell */ +#define VBELL_TIMEOUT (TICKSPERSEC/10) /* visual bell lasts 1/10 sec */ struct beeptime { struct beeptime *next; @@ -918,7 +916,7 @@ static void toggle_mode(int mode, int query, int state) * effective visual bell, so that ESC[?5hESC[?5l will * always be an actually _visible_ visual bell. */ - ticks = GetTickCount(); + ticks = GETTICKCOUNT(); /* turn off a previous vbell to avoid inconsistencies */ if (ticks - vbell_startpoint >= VBELL_TIMEOUT) in_vbell = FALSE; @@ -1110,7 +1108,6 @@ void term_out(void) * buffer. */ if (printing) { - char cc = c; bufchain_add(&printer_buf, &c, 1); /* @@ -1317,7 +1314,7 @@ void term_out(void) } else *d++ = *s; } - lpage_send(CP_ACP, abuf, d - abuf, 0); + lpage_send(DEFAULT_CODEPAGE, abuf, d - abuf, 0); } break; case '\007': @@ -1325,7 +1322,7 @@ void term_out(void) struct beeptime *newbeep; unsigned long ticks; - ticks = GetTickCount(); + ticks = GETTICKCOUNT(); if (!beep_overloaded) { newbeep = smalloc(sizeof(struct beeptime)); @@ -1907,7 +1904,6 @@ void term_out(void) case ANSI_QUE('i'): compatibility(VT100); { - int i; if (esc_nargs != 1) break; if (esc_args[0] == 5 && *cfg.printer) { printing = TRUE; @@ -2800,7 +2796,7 @@ static void do_paint(Context ctx, int may_optimise) * Check the visual bell state. */ if (in_vbell) { - ticks = GetTickCount(); + ticks = GETTICKCOUNT(); if (ticks - vbell_startpoint >= VBELL_TIMEOUT) in_vbell = FALSE; } @@ -2995,7 +2991,7 @@ void term_blink(int flg) static long last_tblink = 0; long now, blink_diff; - now = GetTickCount(); + now = GETTICKCOUNT(); blink_diff = now - last_tblink; /* Make sure the text blinks no more than 2Hz */ @@ -3012,8 +3008,8 @@ void term_blink(int flg) blink_diff = now - last_blink; - /* Make sure the cursor blinks no faster than GetCaretBlinkTime() */ - if (blink_diff >= 0 && blink_diff < (long) GetCaretBlinkTime()) + /* Make sure the cursor blinks no faster than system blink rate */ + if (blink_diff >= 0 && blink_diff < (long) CURSORBLINK) return; last_blink = now; @@ -3714,7 +3710,7 @@ void term_paste() /* Don't wait forever to paste */ if (paste_hold) { - now = GetTickCount(); + now = GETTICKCOUNT(); paste_diff = now - last_paste; if (paste_diff >= 0 && paste_diff < 450) return; diff --git a/unicode.c b/unicode.c index 90faf590..e8542211 100644 --- a/unicode.c +++ b/unicode.c @@ -1,4 +1,6 @@ +#ifdef WINDOWS #include +#endif #include #include diff --git a/unix/pterm.c b/unix/pterm.c new file mode 100644 index 00000000..d29762a3 --- /dev/null +++ b/unix/pterm.c @@ -0,0 +1,173 @@ +/* + * pterm - a fusion of the PuTTY terminal emulator with a Unix pty + * back end, all running as a GTK application. Wish me luck. + */ + +#include +#include +#include +#include + +#define CAT2(x,y) x ## y +#define CAT(x,y) CAT2(x,y) +#define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)} + +#define lenof(x) (sizeof((x))/sizeof(*(x))) + +struct gui_data { + GtkWidget *area; + GdkFont *fonts[2]; /* normal and bold (for now!) */ + GdkGC *black_gc, *white_gc; +}; + +gint delete_window(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + /* + * FIXME: warn on close? + */ + return FALSE; +} + +gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data) +{ + struct gui_data *inst = (struct gui_data *)data; + + inst->fonts[0] = gdk_font_load("9x15t"); /* XXCONFIG */ + inst->fonts[1] = NULL; /* XXCONFIG */ + inst->black_gc = widget->style->black_gc; + inst->white_gc = widget->style->white_gc; + +#if 0 /* FIXME: get cmap from settings */ + /* + * Set up the colour map. + */ + inst->colmap = gdk_colormap_get_system(); + { + char *colours[] = { + "#cc0000", "#880000", "#ff0000", + "#cc6600", "#884400", "#ff7f00", + "#cc9900", "#886600", "#ffbf00", + "#cccc00", "#888800", "#ffff00", + "#00cc00", "#008800", "#00ff00", + "#008400", "#005800", "#00b000", + "#008484", "#005858", "#00b0b0", + "#00cccc", "#008888", "#00ffff", + "#0066cc", "#004488", "#007fff", + "#9900cc", "#660088", "#bf00ff", + "#cc00cc", "#880088", "#ff00ff", + "#cc9999", "#886666", "#ffbfbf", + "#cccc99", "#888866", "#ffffbf", + "#99cc99", "#668866", "#bfffbf", + "#9999cc", "#666688", "#bfbfff", + "#757575", "#4e4e4e", "#9c9c9c", + "#999999", "#666666", "#bfbfbf", + "#cccccc", "#888888", "#ffffff", + }; + ASSERT(sizeof(colours)/sizeof(*colours)==3*NCOLOURS); + gboolean success[3*NCOLOURS]; + int i; + + for (i = 0; i < 3*NCOLOURS; i++) { + if (!gdk_color_parse(colours[i], &inst->cols[i])) + g_error("4tris: couldn't parse colour \"%s\"\n", colours[i]); + } + + gdk_colormap_alloc_colors(inst->colmap, inst->cols, 3*NCOLOURS, + FALSE, FALSE, success); + for (i = 0; i < 3*NCOLOURS; i++) { + if (!success[i]) + g_error("4tris: couldn't allocate colour \"%s\"\n", colours[i]); + } + } +#endif + + return TRUE; +} + +gint expose_area(GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + struct gui_data *inst = (struct gui_data *)data; + + /* + * FIXME: pass the exposed rect to terminal.c which will call + * us back to do the actual painting. + */ + return FALSE; +} + +#define KEY_PRESSED(k) \ + (inst->keystate[(k) / 32] & (1 << ((k) % 32))) + +gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) +{ + struct gui_data *inst = (struct gui_data *)data; + + /* + * FIXME: all sorts of fun keyboard handling required here. + */ +} + +gint timer_func(gpointer data) +{ + struct gui_data *inst = (struct gui_data *)data; + + /* + * FIXME: we're bound to need this sooner or later! + */ + return TRUE; +} + +void destroy(GtkWidget *widget, gpointer data) +{ + gtk_main_quit(); +} + +gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data) +{ + /* + * FIXME: need to faff with the cursor shape. + */ +} + +int main(int argc, char **argv) +{ + GtkWidget *window; + struct gui_data the_inst; + struct gui_data *inst = &the_inst; /* so we always write `inst->' */ + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + inst->area = gtk_drawing_area_new(); + gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area), + 9*80, 15*24);/* FIXME: proper resizing stuff */ + + gtk_container_add(GTK_CONTAINER(window), inst->area); + + gtk_signal_connect(GTK_OBJECT(window), "destroy", + GTK_SIGNAL_FUNC(destroy), inst); + gtk_signal_connect(GTK_OBJECT(window), "delete_event", + GTK_SIGNAL_FUNC(delete_window), inst); + gtk_signal_connect(GTK_OBJECT(window), "key_press_event", + GTK_SIGNAL_FUNC(key_event), inst); + gtk_signal_connect(GTK_OBJECT(window), "key_release_event", + GTK_SIGNAL_FUNC(key_event), inst); + gtk_signal_connect(GTK_OBJECT(window), "focus_in_event", + GTK_SIGNAL_FUNC(focus_event), inst); + gtk_signal_connect(GTK_OBJECT(window), "focus_out_event", + GTK_SIGNAL_FUNC(focus_event), inst); + gtk_signal_connect(GTK_OBJECT(inst->area), "configure_event", + GTK_SIGNAL_FUNC(configure_area), inst); + gtk_signal_connect(GTK_OBJECT(inst->area), "expose_event", + GTK_SIGNAL_FUNC(expose_area), inst); + gtk_timeout_add(20, timer_func, inst); + gtk_widget_add_events(GTK_WIDGET(inst->area), + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); + + gtk_widget_show(inst->area); + gtk_widget_show(window); + + gtk_main(); + + return 0; +} diff --git a/unix/unix.h b/unix/unix.h new file mode 100644 index 00000000..6a40e4ab --- /dev/null +++ b/unix/unix.h @@ -0,0 +1,18 @@ +#ifndef PUTTY_UNIX_H +#define PUTTY_UNIX_H + +typedef void *Context; /* FIXME: probably needs changing */ + +/* Simple wraparound timer function */ +unsigned long getticks(void); /* based on gettimeofday(2) */ +#define GETTICKCOUNT getticks +#define TICKSPERSEC 1000000 /* gettimeofday returns microseconds */ +#define CURSORBLINK 400000 /* FIXME: need right way to do this */ + +#define WCHAR wchar_t +#define BYTE unsigned char + + +#define DEFAULT_CODEPAGE 0 /* FIXME: no idea how to do this */ + +#endif diff --git a/unix/uxmisc.c b/unix/uxmisc.c new file mode 100644 index 00000000..76401ea1 --- /dev/null +++ b/unix/uxmisc.c @@ -0,0 +1,17 @@ +/* + * PuTTY miscellaneous Unix stuff + */ + +#include +#include + +unsigned long getticks(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + /* + * This will wrap around approximately every 4000 seconds, i.e. + * just over an hour, which is more than enough. + */ + return tv.tv_sec * 1000000 + tv.tv_usec; +} diff --git a/winstuff.h b/winstuff.h index 6f080b3b..f21053f7 100644 --- a/winstuff.h +++ b/winstuff.h @@ -2,20 +2,58 @@ * winstuff.h: Windows-specific inter-module stuff. */ +#ifndef PUTTY_WINSTUFF_H +#define PUTTY_WINSTUFF_H + /* * Global variables. Most modules declare these `extern', but * window.c will do `#define PUTTY_DO_GLOBALS' before including this * module, and so will get them properly defined. */ +#ifndef GLOBAL #ifdef PUTTY_DO_GLOBALS #define GLOBAL #else #define GLOBAL extern #endif +#endif + +typedef struct config_tag Config; /* duplicated from putty.h */ + +#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY" +#define PUTTY_REG_PARENT "Software\\SimonTatham" +#define PUTTY_REG_PARENT_CHILD "PuTTY" +#define PUTTY_REG_GPARENT "Software" +#define PUTTY_REG_GPARENT_CHILD "SimonTatham" + +#define GETTICKCOUNT GetTickCount +#define CURSORBLINK GetCaretBlinkTime() +#define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */ + +#define DEFAULT_CODEPAGE CP_ACP + +typedef HDC Context; +/* + * Window handles for the dialog boxes that can be running during a + * PuTTY session. + */ +GLOBAL HWND logbox; + +/* + * The all-important instance handle. + */ GLOBAL HINSTANCE hinst; /* + * I've just looked in the windows standard headr files for WM_USER, there + * are hundreds of flags defined using the form WM_USER+123 so I've + * renumbered this NETEVENT value and the two in window.c + */ +#define WM_XUSER (WM_USER + 0x2000) +#define WM_NETEVENT (WM_XUSER + 5) + +/* * Exports from winctrls.c. */ @@ -45,6 +83,9 @@ struct prefslist { int dragging; }; +/* + * Exports from winctrls.c. + */ void ctlposinit(struct ctlpos *cp, HWND hwnd, int leftborder, int rightborder, int topborder); HWND doctl(struct ctlpos *cp, RECT r, @@ -95,3 +136,31 @@ void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid, char *e1stext, int e1sid, int e1id, char *e2stext, int e2sid, int e2id, char *btext, int bid); + +/* + * Exports from windlg.c. + */ +void defuse_showwindow(void); +int do_config(void); +int do_reconfig(HWND); +void do_defaults(char *, Config *); +void logevent(char *); +void showeventlog(HWND); +void showabout(HWND); +void verify_ssh_host_key(char *host, int port, char *keytype, + char *keystr, char *fingerprint); +void askcipher(char *ciphername, int cs); +int askappend(char *filename); +void registry_cleanup(void); +void force_normal(HWND hwnd); + +GLOBAL int nsessions; +GLOBAL char **sessions; + +/* + * Exports from sizetip.c. + */ +void UpdateSizeTip(HWND src, int cx, int cy); +void EnableSizeTip(int bEnable); + +#endif -- 2.11.0