- Improved comments
[privoxy.git] / w32log.c
1 const char w32log_rcs[] = "$Id: w32log.c,v 1.10 2001/05/31 21:37:11 jongfoster Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/w32log.c,v $
5  *
6  * Purpose     :  Functions for creating and destroying the log window,
7  *                ouputting strings, processing messages and so on.
8  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Written by and Copyright (C) 1999 Adam Lock
13  *                <locka@iol.ie>
14  *
15  *                This program is free software; you can redistribute it 
16  *                and/or modify it under the terms of the GNU General
17  *                Public License as published by the Free Software
18  *                Foundation; either version 2 of the License, or (at
19  *                your option) any later version.
20  *
21  *                This program is distributed in the hope that it will
22  *                be useful, but WITHOUT ANY WARRANTY; without even the
23  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
24  *                PARTICULAR PURPOSE.  See the GNU General Public
25  *                License for more details.
26  *
27  *                The GNU General Public License should be included with
28  *                this file.  If not, you can view it at
29  *                http://www.gnu.org/copyleft/gpl.html
30  *                or write to the Free Software Foundation, Inc., 59
31  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  *
33  * Revisions   :
34  *    $Log: w32log.c,v $
35  *    Revision 1.10  2001/05/31 21:37:11  jongfoster
36  *    GUI changes to rename "permissions file" to "actions file".
37  *
38  *    Revision 1.9  2001/05/31 17:33:13  oes
39  *
40  *    CRLF -> LF
41  *
42  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
43  *    Unified blocklist/imagelist/permissionslist.
44  *    File format is still under discussion, but the internal changes
45  *    are (mostly) done.
46  *
47  *    Also modified interceptor behaviour:
48  *    - We now intercept all URLs beginning with one of the following
49  *      prefixes (and *only* these prefixes):
50  *        * http://i.j.b/
51  *        * http://ijbswa.sf.net/config/
52  *        * http://ijbswa.sourceforge.net/config/
53  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
54  *    - Internal changes so that intercepted and fast redirect pages
55  *      are not replaced with an image.
56  *    - Interceptors now have the option to send a binary page direct
57  *      to the client. (i.e. ijb-send-banner uses this)
58  *    - Implemented show-url-info interceptor.  (Which is why I needed
59  *      the above interceptors changes - a typical URL is
60  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
61  *      The previous mechanism would not have intercepted that, and
62  *      if it had been intercepted then it then it would have replaced
63  *      it with an image.)
64  *
65  *    Revision 1.7  2001/05/26 01:26:34  jongfoster
66  *    New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
67  *    This #define cannot be set from ./configure - there's no point, it
68  *    doesn't work yet.  See feature request # 425722
69  *
70  *    Revision 1.6  2001/05/26 00:31:30  jongfoster
71  *    Fixing compiler warning about comparing signed/unsigned.
72  *
73  *    Revision 1.5  2001/05/26 00:28:36  jongfoster
74  *    Automatic reloading of config file.
75  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
76  *    Most of the global variables have been moved to a new
77  *    struct configuration_spec, accessed through csp->config->globalname
78  *    Most of the globals remaining are used by the Win32 GUI.
79  *
80  *    Revision 1.4  2001/05/22 18:56:28  oes
81  *    CRLF -> LF
82  *
83  *    Revision 1.3  2001/05/20 15:07:54  jongfoster
84  *    File is now ignored if _WIN_CONSOLE is defined.
85  *
86  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
87  *    Version 2.9.4 checkin.
88  *    - Merged popupfile and cookiefile, and added control over PCRS
89  *      filtering, in new "permissionsfile".
90  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
91  *      file error you now get a message box (in the Win32 GUI) rather
92  *      than the program exiting with no explanation.
93  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
94  *      skipping.
95  *    - Removed tabs from "config"
96  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
97  *    - Bumped up version number.
98  *
99  *    Revision 1.1.1.1  2001/05/15 13:59:07  oes
100  *    Initial import of version 2.9.3 source tree
101  *
102  *
103  *********************************************************************/
104 \f
105
106 #include "config.h"
107
108 #include <assert.h>
109 #include <stdio.h>
110
111 #include <windows.h>
112 #include <richedit.h>
113
114 #include "project.h"
115 #include "w32log.h"
116 #include "w32taskbar.h"
117 #include "w32rulesdlg.h"
118 #include "win32.h"
119 #include "w32res.h"
120 #include "jcc.h"
121 #include "miscutil.h"
122 #include "errlog.h"
123
124 const char w32res_h_rcs[] = W32RES_H_VERSION;
125
126 #ifdef __MINGW32__
127 #include "cygwin.h"
128 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
129 #endif
130
131 const char w32log_h_rcs[] = W32LOG_H_VERSION;
132
133 #ifndef _WIN_CONSOLE /* entire file */
134
135 /*
136  * Timers and the various durations
137  */
138 #define TIMER_ANIM_ID               1
139 #define TIMER_ANIM_TIME             100
140 #define TIMER_ANIMSTOP_ID           2
141 #define TIMER_ANIMSTOP_TIME         1000
142 #define TIMER_CLIPBUFFER_ID         3
143 #define TIMER_CLIPBUFFER_TIME       1000
144 #define TIMER_CLIPBUFFER_FORCE_ID   4
145 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
146
147 /*
148  * Styles of text that can be output
149  */
150 #define STYLE_NONE      0
151 #define STYLE_HIGHLIGHT 1
152 #define STYLE_LINK      2
153 #define STYLE_HEADER    3
154
155 /*
156  * Number of frames of animation in tray activity sequence
157  */
158 #define ANIM_FRAMES 8
159
160 #define DEFAULT_MAX_BUFFER_LINES    200
161 #define DEFAULT_LOG_FONT_NAME       "MS Sans Serif"
162 #define DEFAULT_LOG_FONT_SIZE       8
163
164 /*
165  * These values affect the way the log window behaves, they should be read
166  * from a file but for the moment, they are hardcoded here. Some options are
167  * configurable through the UI.
168  */
169
170 /* Indicates whether task bar shows activity animation */
171 BOOL g_bShowActivityAnimation = 1;
172
173 /* Indicates if the log window appears on the task bar */
174 BOOL g_bShowOnTaskBar = 0;
175
176 /* Indicates whether closing the log window really just hides it */
177 BOOL g_bCloseHidesWindow = 1;
178
179 /* Indicates if messages are logged at all */
180 BOOL g_bLogMessages = 1;
181
182 /* Indicates whether log messages are highlighted */
183 BOOL g_bHighlightMessages = 1;
184
185 /* Indicates if buffer is limited in size */
186 BOOL g_bLimitBufferSize = 1;
187
188 /* Maximum number of lines allowed in buffer when limited */
189 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
190
191 /* Font to use */
192 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
193
194 /* Size of font to use */
195 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
196
197
198 /* FIXME: this is a kludge */
199
200 const char * g_actions_file = NULL;
201 #ifdef PCRS
202 const char * g_re_filterfile = NULL;
203 #endif
204 #ifdef TRUST_FILES
205 const char * g_trustfile = NULL;
206 #endif /* def TRUST_FILES */
207
208 /* FIXME: end kludge */
209
210
211 #ifdef REGEX
212 /* Regular expression for detected URLs */
213 #define RE_URL "http:[^ \n\r]*"
214
215 /*
216  * Regular expressions that are used to perform highlight in the log window
217  */
218 static struct _Pattern
219 {
220    const char *str;
221    int style;
222    regex_t buffer;
223 } patterns_to_highlight[] =
224 {
225    /* url headers */
226    { RE_URL,                STYLE_LINK },
227 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
228    /* interesting text to highlight */
229    { "crunch!",           STYLE_HIGHLIGHT },
230    /* http headers */
231    { "referer:",            STYLE_HEADER },
232    { "proxy-connection:",   STYLE_HEADER },
233    { "proxy-agent:",        STYLE_HEADER },
234    { "user-agent:",         STYLE_HEADER },
235    { "host:",               STYLE_HEADER },
236    { "accept:",             STYLE_HEADER },
237    { "accept-encoding:",    STYLE_HEADER },
238    { "accept-language:",    STYLE_HEADER },
239    { "accept-charset:",     STYLE_HEADER },
240    { "accept-ranges:",      STYLE_HEADER },
241    { "date:",               STYLE_HEADER },
242    { "cache-control:",      STYLE_HEADER },
243    { "cache-last-checked:", STYLE_HEADER },
244    { "connection:",         STYLE_HEADER },
245    { "content-type",        STYLE_HEADER },
246    { "content-length",      STYLE_HEADER },
247    { "cookie",              STYLE_HEADER },
248    { "last-modified:",      STYLE_HEADER },
249    { "pragma:",             STYLE_HEADER },
250    { "server:",             STYLE_HEADER },
251    { "etag:",               STYLE_HEADER },
252    { "expires:",            STYLE_HEADER },
253    { "warning:",            STYLE_HEADER },
254    /* this is the terminator statement - do not delete! */
255    { NULL,                  STYLE_NONE }
256 };
257 #endif /* def REGEX */
258
259
260 /*
261  * Public variables
262  */
263 HWND g_hwndLogFrame;
264
265 /*
266  * Private variables
267  */
268 static CRITICAL_SECTION g_criticalsection;
269 static HWND g_hwndTray;
270 static HWND g_hwndLogBox;
271 static WNDPROC g_fnLogBox;
272 static HICON g_hiconAnim[ANIM_FRAMES];
273 static HICON g_hiconIdle;
274 static HICON g_hiconApp;
275 static int g_nAnimFrame;
276 static BOOL g_bClipPending = FALSE;
277 static int g_nRichEditVersion = 0;
278
279 /*
280  * Private functions
281  */
282 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
283 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
284 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
285 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
286 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
287 static BOOL InitRichEdit(void);
288 static void LogClipBuffer(void);
289 static void LogCreatePatternMatchingBuffers(void);
290 static void LogDestroyPatternMatchingBuffers(void);
291 static int LogPutStringNoMatch(const char *pszText, int style);
292
293
294 /*********************************************************************
295  *
296  * Function    :  InitLogWindow
297  *
298  * Description :  Initialise the log window.
299  *
300  * Parameters  :  None
301  *
302  * Returns     :  Always TRUE (there should be error checking on the resources).
303  *
304  *********************************************************************/
305 BOOL InitLogWindow(void)
306 {
307    int i;
308
309    /* Load the icons */
310    g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
311    for (i = 0; i < ANIM_FRAMES; i++)
312    {
313       g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
314    }
315    g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
316
317    /* Create the user interface */
318    g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
319    g_hwndTray = CreateTrayWindow(g_hInstance);
320    TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
321
322    /* Create pattern matching buffers (for highlighting */
323    LogCreatePatternMatchingBuffers();
324
325    /* Create a critical section to protect multi-threaded access to certain things */
326    InitializeCriticalSection(&g_criticalsection);
327
328    return TRUE;
329
330 }
331
332
333 /*********************************************************************
334  *
335  * Function    :  TermLogWindow
336  *
337  * Description :  Cleanup the logwindow.
338  *
339  * Parameters  :  None
340  *
341  * Returns     :  N/A
342  *
343  *********************************************************************/
344 void TermLogWindow(void)
345 {
346    int i;
347
348    LogDestroyPatternMatchingBuffers();
349
350    TrayDeleteIcon(g_hwndTray, 1);
351    DeleteObject(g_hiconApp);
352    DeleteObject(g_hiconIdle);
353    for (i = 0; i < ANIM_FRAMES; i++)
354    {
355       DeleteObject(g_hiconAnim[i]);
356    }
357
358 }
359
360
361 /*********************************************************************
362  *
363  * Function    :  LogCreatePatternMatchingBuffers
364  *
365  * Description :  Compile the pattern matching buffers.
366  *
367  * Parameters  :  None
368  *
369  * Returns     :  N/A
370  *
371  *********************************************************************/
372 void LogCreatePatternMatchingBuffers(void)
373 {
374 #ifdef REGEX
375    int i;
376    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
377    {
378       regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
379    }
380 #endif
381
382 }
383
384
385 /*********************************************************************
386  *
387  * Function    :  LogDestroyPatternMatchingBuffers
388  *
389  * Description :  Free up the pattern matching buffers.
390  *
391  * Parameters  :  None
392  *
393  * Returns     :  N/A
394  *
395  *********************************************************************/
396 void LogDestroyPatternMatchingBuffers(void)
397 {
398 #ifdef REGEX
399    int i;
400    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
401    {
402       regfree(&patterns_to_highlight[i].buffer);
403    }
404 #endif
405
406 }
407
408
409 /*********************************************************************
410  *
411  * Function    :  LogGetURLUnderCursor
412  *
413  * Description :  Returns the URL from under the cursor (remember to free it!).
414  *
415  * Parameters  :  None
416  *
417  * Returns     :  NULL or a pointer to an URL string.
418  *
419  *********************************************************************/
420 char *LogGetURLUnderCursor(void)
421 {
422    char *szResult = NULL;
423 #ifdef REGEX
424    regex_t re;
425    POINT ptCursor;
426    POINTL ptl;
427    DWORD nPos;
428    DWORD nWordStart = 0;
429    DWORD nWordEnd = 0;
430
431    regcomp(&re, RE_URL, REG_ICASE);
432
433    /* Get the position of the cursor over the text window */
434    GetCursorPos(&ptCursor);
435    ScreenToClient(g_hwndLogBox, &ptCursor);
436    ptl.x = ptCursor.x;
437    ptl.y = ptCursor.y;
438
439    /* Search backwards and fowards to obtain the word that is highlighted */
440    nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
441    nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
442    nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
443
444    /* Compare the string to the pattern */
445    if (nWordEnd > nWordStart)
446    {
447       TEXTRANGE range;
448       regmatch_t match;
449
450       range.chrg.cpMin = nWordStart;
451       range.chrg.cpMax = nWordEnd;
452       range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
453       SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
454
455       if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
456       {
457          szResult = range.lpstrText;
458       }
459       else
460       {
461          free(range.lpstrText);
462       }
463
464       regfree(&re);
465    }
466 #endif
467    return szResult;
468
469 }
470
471
472 /*********************************************************************
473  *
474  * Function    :  LogPutString
475  *
476  * Description :  Inserts text into the logging window.  This is really
477  *                a REGEXP aware wrapper function to `LogPutStringNoMatch'.
478  *
479  * Parameters  :
480  *          1  :  pszText = pointer to string going to the log window
481  *
482  * Returns     :  1 => success, else the return code from `LogPutStringNoMatch'.
483  *                FIXME: this is backwards to the rest of IJB and to common
484  *                programming practice.  Please use 0 => success instead.
485  *
486  *********************************************************************/
487 int LogPutString(const char *pszText)
488 {
489 #ifdef REGEX
490    int i;
491 #endif
492    int result = 0;
493
494    if (pszText == NULL || strlen(pszText) == 0)
495    {
496       return 1;
497    }
498
499    if (!g_bLogMessages)
500    {
501       return 1;
502    }
503
504    /* Critical section stops multiple threads doing nasty interactions that
505     * foul up the highlighting and output.
506     */
507    EnterCriticalSection(&g_criticalsection);
508
509 #ifdef REGEX
510    if (g_bHighlightMessages)
511    {
512       regmatch_t match;
513
514       /* First things first, regexp scan for various things that we would like highlighted */
515       for (i = 0; patterns_to_highlight[i].str != NULL; i++)
516       {
517          if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
518          {
519             char *pszBefore = NULL;
520             char *pszMatch = NULL;
521             char *pszAfter = NULL;
522             int nMatchSize;
523
524             /* Split the string up into pieces representing the strings, before
525                at and after the matching pattern
526              */
527             if (match.rm_so > 0)
528             {
529                pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
530                memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
531                strncpy(pszBefore, pszText, match.rm_so);
532             }
533             if (match.rm_eo < (regoff_t)strlen(pszText))
534             {
535                pszAfter = strdup(&pszText[match.rm_eo]);
536             }
537             nMatchSize = match.rm_eo - match.rm_so;
538             pszMatch = (char *)malloc(nMatchSize + 1);
539             strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
540             pszMatch[nMatchSize] = '\0';
541
542             /* Recursively call LogPutString */
543             if (pszBefore)
544             {
545                LogPutString(pszBefore);
546                free(pszBefore);
547             }
548             if (pszMatch)
549             {
550                LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
551                free(pszMatch);
552             }
553             if (pszAfter)
554             {
555                LogPutString(pszAfter);
556                free(pszAfter);
557             }
558
559             result = 1;
560             goto end;
561          }
562       }
563    }
564 #endif
565
566    result = LogPutStringNoMatch(pszText, STYLE_NONE);
567
568 #ifdef REGEX
569 end:
570 #endif
571    LeaveCriticalSection(&g_criticalsection);
572
573    return result;
574
575 }
576
577
578 /*********************************************************************
579  *
580  * Function    :  LogPutStringNoMatch
581  *
582  * Description :  Puts a string into the logging window.
583  *
584  * Parameters  :
585  *          1  :  pszText = pointer to string going to the log window
586  *          2  :  style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
587  *
588  * Returns     :  Always 1 => success.
589  *                FIXME: this is backwards to the rest of IJB and to common
590  *                programming practice.  Please use 0 => success instead.
591  *
592  *********************************************************************/
593 int LogPutStringNoMatch(const char *pszText, int style)
594 {
595    CHARRANGE range;
596    CHARFORMAT format;
597    int nTextLength;
598
599    assert(g_hwndLogBox);
600    if (g_hwndLogBox == NULL)
601    {
602       return 1;
603    }
604
605    /* TODO preserve existing selection */
606
607    /* Go to the end of the text */
608    nTextLength = GetWindowTextLength(g_hwndLogBox);
609    range.cpMin = nTextLength;
610    range.cpMax = nTextLength;
611    SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
612
613    /* Apply a formatting style */
614    memset(&format, 0, sizeof(format));
615    format.cbSize = sizeof(format);
616    format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
617    format.yHeight = (g_nFontSize * 1440) / 72;
618    strcpy(format.szFaceName, g_szFontFaceName);
619    if (style == STYLE_NONE)
620    {
621       /* DO NOTHING */
622       format.dwEffects |= CFE_AUTOCOLOR;
623    }
624    else if (style == STYLE_HEADER)
625    {
626       format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
627    }
628    else if (style == STYLE_HIGHLIGHT)
629    {
630       format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
631    }
632    else if (style == STYLE_LINK)
633    {
634       format.dwEffects |= CFE_UNDERLINE;
635       format.crTextColor = RGB(0, 0, 255);
636    }
637    SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
638
639    /* Append text to the end */
640    SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
641
642    /* TODO Restore the old selection */
643
644    /* Purge buffer */
645    if (strchr(pszText, '\n') != NULL)
646    {
647       SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
648       if (!g_bClipPending)
649       {
650          /* Set the force clip timer going. This timer ensures clipping is done
651             intermittently even when there is a sustained burst of logging
652          */
653          SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
654       }
655       g_bClipPending = TRUE;
656    }
657
658    return 1;
659
660 }
661
662
663 /*********************************************************************
664  *
665  * Function    :  LogShowActivity
666  *
667  * Description :  Start the spinner.
668  *
669  * Parameters  :  None
670  *
671  * Returns     :  N/A
672  *
673  *********************************************************************/
674 void LogShowActivity(void)
675 {
676    /* Start some activity timers */
677    if (g_bShowActivityAnimation)
678    {
679       SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
680       SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
681    }
682
683 }
684
685
686 /*********************************************************************
687  *
688  * Function    :  LogClipBuffer
689  *
690  * Description :  Prunes old lines from the log.
691  *
692  * Parameters  :  None
693  *
694  * Returns     :  N/A
695  *
696  *********************************************************************/
697 void LogClipBuffer(void)
698 {
699    int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
700    if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
701    {
702       /* Compute the range representing the lines to be deleted */
703       LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
704       LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
705       CHARRANGE range;
706       range.cpMin = 0;
707       range.cpMax = nLastChar;
708
709       /* TODO get current selection */
710
711       /* TODO adjust and clip old selection against range to be deleted */
712
713       /* Select range and erase it (turning off autoscroll to prevent
714          nasty scrolling) */
715       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
716       SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
717       SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
718       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
719
720       /* Restore old selection */
721    }
722
723 }
724
725
726 /*********************************************************************
727  *
728  * Function    :  CreateHiddenLogOwnerWindow
729  *
730  * Description :  Creates a hidden owner window that stops the log
731  *                window appearing in the task bar.
732  *
733  * Parameters  :
734  *          1  :  hInstance = application's instance handle
735  *
736  * Returns     :  Handle to newly created window.
737  *
738  *********************************************************************/
739 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
740 {
741    static const char *szWndName = "JunkbusterLogLogOwner";
742    WNDCLASS wc;
743    HWND hwnd;
744
745    wc.style          = 0;
746    wc.lpfnWndProc    = LogOwnerWindowProc;
747    wc.cbClsExtra     = 0;
748    wc.cbWndExtra     = 0;
749    wc.hInstance      = hInstance;
750    wc.hIcon          = 0;
751    wc.hCursor        = 0;
752    wc.hbrBackground  = 0;
753    wc.lpszMenuName   = 0;
754    wc.lpszClassName  = szWndName;
755
756    RegisterClass(&wc);
757
758    hwnd = CreateWindow(szWndName, szWndName,
759       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
760       CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
761
762    return hwnd;
763
764 }
765
766
767 /*********************************************************************
768  *
769  * Function    :  LogOwnerWindowProc
770  *
771  * Description :  Dummy procedure that does nothing special.
772  *
773  * Parameters  :
774  *          1  :  hwnd = window handle
775  *          2  :  uMsg = message number
776  *          3  :  wParam = first param for this message
777  *          4  :  lParam = next param for this message
778  *
779  * Returns     :  Same as `DefWindowProc'.
780  *
781  *********************************************************************/
782 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
783 {
784    return DefWindowProc(hwnd, uMsg, wParam, lParam);
785
786 }
787
788
789 /*********************************************************************
790  *
791  * Function    :  CreateLogWindow
792  *
793  * Description :  Create the logging window.
794  *
795  * Parameters  :
796  *          1  :  hInstance = application's instance handle
797  *          2  :  nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
798  *
799  * Returns     :  Handle to newly created window.
800  *
801  *********************************************************************/
802 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
803 {
804    static const char *szWndName = "JunkbusterLogWindow";
805    static const char *szWndTitle = "Junkbuster";
806
807    HWND hwnd = NULL;
808    HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
809    HWND hwndChild = NULL;
810    RECT rcClient;
811    WNDCLASSEX wc;
812
813    memset(&wc, 0, sizeof(wc));
814    wc.cbSize         = sizeof(wc);
815    wc.style          = CS_DBLCLKS;
816    wc.lpfnWndProc    = LogWindowProc;
817    wc.cbClsExtra     = 0;
818    wc.cbWndExtra     = 0;
819    wc.hInstance      = hInstance;
820    wc.hIcon          = g_hiconApp;
821    wc.hCursor        = 0;
822    wc.hbrBackground  = 0;
823    wc.lpszMenuName   = MAKEINTRESOURCE(IDR_LOGVIEW);
824    wc.lpszClassName  = szWndName;
825    wc.hbrBackground  = GetStockObject(WHITE_BRUSH);
826    RegisterClassEx(&wc);
827
828    hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
829       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
830       CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
831
832    /* Now create a child list box */
833    GetClientRect(hwnd, &rcClient);
834
835    /* Create a rich edit control */
836    InitRichEdit();
837    g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
838       ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
839       rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
840       hwnd, NULL, hInstance, NULL);
841 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
842
843    /* Subclass the control to catch certain messages */
844    g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
845    SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
846
847    /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
848    if (!g_bShowOnTaskBar &&
849          (nCmdShow == SW_SHOWMINIMIZED ||
850           nCmdShow == SW_MINIMIZE ||
851           nCmdShow == SW_SHOWMINNOACTIVE))
852    {
853       nCmdShow = SW_HIDE;
854    }
855
856    ShowWindow(hwnd, nCmdShow);
857    UpdateWindow(hwnd);
858
859    GetClientRect(g_hwndLogFrame, &rcClient);
860    SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
861
862    return hwnd;
863
864 }
865
866
867 /*********************************************************************
868  *
869  * Function    :  InitRichEdit
870  *
871  * Description :  Initialise the rich edit control library.
872  *
873  * Parameters  :  None
874  *
875  * Returns     :  TRUE => success, FALSE => failure.
876  *                FIXME: this is backwards to the rest of IJB and to common
877  *                programming practice.  Please use 0 => success instead.
878  *
879  *********************************************************************/
880 BOOL InitRichEdit(void)
881 {
882    static HINSTANCE hInstRichEdit;
883    if (hInstRichEdit == NULL)
884    {
885       g_nRichEditVersion = 0;
886       hInstRichEdit = LoadLibraryA("RICHED20.DLL");
887       if (hInstRichEdit)
888       {
889          g_nRichEditVersion = _RICHEDIT_VER;
890       }
891       else
892       {
893          hInstRichEdit = LoadLibraryA("RICHED32.DLL");
894          if (hInstRichEdit)
895          {
896             g_nRichEditVersion = 0x0100;
897          }
898       }
899    }
900    return (hInstRichEdit != NULL) ? TRUE : FALSE;
901
902 }
903
904
905 /*********************************************************************
906  *
907  * Function    :  ShowLogWindow
908  *
909  * Description :  Shows or hides the log window.  We will also raise the
910  *                window on a show command in case it is buried.
911  *
912  * Parameters  :
913  *          1  :  bShow = TRUE to show, FALSE to mimize/hide
914  *
915  * Returns     :  N/A
916  *
917  *********************************************************************/
918 void ShowLogWindow(BOOL bShow)
919 {
920    if (bShow)
921    {
922       SetForegroundWindow(g_hwndLogFrame);
923       SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
924    }
925    else if (g_bShowOnTaskBar)
926    {
927       ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
928    }
929    else
930    {
931       ShowWindow(g_hwndLogFrame, SW_HIDE);
932    }
933
934 }
935
936
937 /*********************************************************************
938  *
939  * Function    :  EditFile
940  *
941  * Description :  Opens the specified setting file for editing.
942  *
943  * Parameters  :
944  *          1  :  filename = filename from the config (aka junkbstr.txt) file.
945  *
946  * Returns     :  N/A
947  *
948  *********************************************************************/
949 void EditFile(const char *filename)
950 {
951    if (filename)
952    {
953       ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
954    }
955
956 }
957
958
959 /*--------------------------------------------------------------------------*/
960 /* Windows message handlers                                                 */
961 /*--------------------------------------------------------------------------*/
962
963
964 /*********************************************************************
965  *
966  * Function    :  OnLogRButtonUp
967  *
968  * Description :  Handler for WM_RBUTTONUP messages.
969  *
970  * Parameters  :
971  *          1  :  nModifier = wParam from mouse message (unused)
972  *          2  :  x = x coordinate of the mouse event
973  *          3  :  y = y coordinate of the mouse event
974  *
975  * Returns     :  N/A
976  *
977  *********************************************************************/
978 void OnLogRButtonUp(int nModifier, int x, int y)
979 {
980    HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
981    if (hMenu != NULL)
982    {
983       HMENU hMenuPopup = GetSubMenu(hMenu, 0);
984 #ifdef WIN_GUI_EDIT
985       char *szURL;
986 #endif /* def WIN_GUI_EDIT */
987
988       /* Check if there is a selection */
989       CHARRANGE range;
990       SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
991       if (range.cpMin == range.cpMax)
992       {
993          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
994       }
995       else
996       {
997          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
998       }
999
1000 #ifdef WIN_GUI_EDIT
1001       /* Check if cursor is over a link */
1002       szURL = LogGetURLUnderCursor();
1003       if (szURL)
1004       {
1005          MENUITEMINFO item;
1006          TCHAR szMenuItemTemplate[1000];
1007          char *szMenuItem;
1008
1009          memset(&item, 0, sizeof(item));
1010          item.cbSize = sizeof(item);
1011          item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
1012          item.fType = MFT_STRING;
1013          item.fState = MFS_ENABLED;
1014          item.wID = ID_NEW_BLOCKER;
1015
1016          /* Put the item into the menu */
1017          memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
1018          LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
1019
1020          szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
1021          sprintf(szMenuItem, szMenuItemTemplate, szURL);
1022
1023          item.dwTypeData = szMenuItem;
1024          item.cch = strlen(szMenuItem);
1025
1026          InsertMenuItem(hMenuPopup, 1, TRUE, &item);
1027
1028          SetDefaultRule(szURL);
1029
1030          free(szURL);
1031       }
1032 #endif /* def WIN_GUI_EDIT */
1033
1034       /* Display the popup */
1035       TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1036       DestroyMenu(hMenu);
1037    }
1038
1039 }
1040
1041
1042 /*********************************************************************
1043  *
1044  * Function    :  OnLogCommand
1045  *
1046  * Description :  Handler for WM_COMMAND messages.
1047  *
1048  * Parameters  :
1049  *          1  :  nCommand = the command portion of the menu selection event
1050  *
1051  * Returns     :  N/A
1052  *
1053  *********************************************************************/
1054 void OnLogCommand(int nCommand)
1055 {
1056    switch (nCommand)
1057    {
1058       case ID_SHOWWINDOW:
1059          ShowLogWindow(TRUE);
1060          break;
1061
1062       case ID_FILE_EXIT:
1063          PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1064          break;
1065
1066       case ID_EDIT_COPY:
1067          SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1068          break;
1069
1070       case ID_VIEW_CLEARLOG:
1071          SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1072          break;
1073
1074       case ID_VIEW_LOGMESSAGES:
1075          g_bLogMessages = !g_bLogMessages;
1076          /* SaveLogSettings(); */
1077          break;
1078
1079       case ID_VIEW_MESSAGEHIGHLIGHTING:
1080          g_bHighlightMessages = !g_bHighlightMessages;
1081          /* SaveLogSettings(); */
1082          break;
1083
1084       case ID_VIEW_LIMITBUFFERSIZE:
1085          g_bLimitBufferSize = !g_bLimitBufferSize;
1086          /* SaveLogSettings(); */
1087          break;
1088
1089       case ID_VIEW_ACTIVITYANIMATION:
1090          g_bShowActivityAnimation = !g_bShowActivityAnimation;
1091          /* SaveLogSettings(); */
1092          break;
1093
1094 #ifdef TOGGLE
1095       /* by haroon - change toggle to its opposite value */
1096       case ID_TOGGLE_IJB:
1097          g_bToggleIJB = !g_bToggleIJB;
1098          if (g_bToggleIJB)
1099          {
1100             log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1101          }
1102          else
1103          {
1104             log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1105          }
1106          break;
1107 #endif
1108
1109       case ID_TOOLS_EDITJUNKBUSTER:
1110          EditFile(configfile);
1111          break;
1112
1113       case ID_TOOLS_EDITACTIONS:
1114          EditFile(g_actions_file);
1115          break;
1116
1117 #ifdef PCRS
1118       case ID_TOOLS_EDITPERLRE:
1119          EditFile(g_re_filterfile);
1120          break;
1121 #endif
1122
1123 #ifdef TRUST_FILES
1124       case ID_TOOLS_EDITTRUST:
1125          EditFile(g_trustfile);
1126          break;
1127 #endif /* def TRUST_FILES */
1128
1129 #ifdef WIN_GUI_EDIT
1130       case ID_NEW_BLOCKER:
1131          ShowRulesDialog(g_hwndLogFrame);
1132          break;
1133 #endif /* def WIN_GUI_EDIT */
1134
1135       case ID_HELP_GPL:
1136          ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1137          break;
1138
1139       case ID_HELP_FAQ:
1140          ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1141          break;
1142
1143       case ID_HELP_MANUAL:
1144          ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1145          break;
1146
1147       case ID_HELP_STATUS:
1148          ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1149          break;
1150
1151       case ID_HELP_ABOUTJUNKBUSTER:
1152          MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1153          break;
1154
1155       default:
1156          /* DO NOTHING */
1157          break;
1158    }
1159
1160 }
1161
1162
1163 /*********************************************************************
1164  *
1165  * Function    :  OnLogInitMenu
1166  *
1167  * Description :  Handler for WM_INITMENU messages.  Enable, disable,
1168  *                check, and/or uncheck menu options as apropos.
1169  *
1170  * Parameters  :
1171  *          1  :  hmenu = handle to menu to "make current"
1172  *
1173  * Returns     :  N/A
1174  *
1175  *********************************************************************/
1176 void OnLogInitMenu(HMENU hmenu)
1177 {
1178    /* Only enable editors if there is a file to edit */
1179    EnableMenuItem(hmenu, ID_TOOLS_EDITACTIONS, MF_BYCOMMAND | (g_actions_file ? MF_ENABLED : MF_GRAYED));
1180 #ifdef PCRS
1181    EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1182 #endif
1183 #ifdef TRUST_FILES
1184    EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1185 #endif /* def TRUST_FILES */
1186
1187    /* Check/uncheck options */
1188    CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1189    CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1190    CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1191    CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1192 #ifdef TOGGLE
1193    /* by haroon - menu item for Enable toggle on/off */
1194    CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1195 #endif
1196
1197 }
1198
1199
1200 /*********************************************************************
1201  *
1202  * Function    :  OnLogTimer
1203  *
1204  * Description :  Handler for WM_TIMER messages.
1205  *
1206  * Parameters  :
1207  *          1  :  nTimer = timer id (animation start/stop or clip buffer)
1208  *
1209  * Returns     :  N/A
1210  *
1211  *********************************************************************/
1212 void OnLogTimer(int nTimer)
1213 {
1214    switch (nTimer)
1215    {
1216       case TIMER_ANIM_ID:
1217          TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1218          break;
1219
1220       case TIMER_ANIMSTOP_ID:
1221          g_nAnimFrame = 0;
1222          TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1223          KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1224          KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1225          break;
1226
1227       case TIMER_CLIPBUFFER_ID:
1228       case TIMER_CLIPBUFFER_FORCE_ID:
1229          LogClipBuffer();
1230          g_bClipPending = FALSE;
1231          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1232          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1233          break;
1234
1235       default:
1236          /* DO NOTHING */
1237          break;
1238    }
1239
1240 }
1241
1242
1243 /*********************************************************************
1244  *
1245  * Function    :  LogRichEditProc
1246  *
1247  * Description :  Window subclass routine handles some events for the rich edit control.
1248  *
1249  * Parameters  :
1250  *          1  :  hwnd = window handle of the rich edit control
1251  *          2  :  uMsg = message number
1252  *          3  :  wParam = first param for this message
1253  *          4  :  lParam = next param for this message
1254  *
1255  * Returns     :  Appropriate M$ window message handler codes.
1256  *
1257  *********************************************************************/
1258 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1259 {
1260    switch (uMsg)
1261    {
1262       case WM_RBUTTONUP:
1263       {
1264          POINT pt;
1265          pt.x = LOWORD(lParam);
1266          pt.y = HIWORD(lParam);
1267          ClientToScreen(hwnd, &pt);
1268          OnLogRButtonUp(wParam, pt.x, pt.y);
1269       }
1270       return 0;
1271    }
1272    return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1273
1274 }
1275
1276
1277 /*********************************************************************
1278  *
1279  * Function    :  LogWindowProc
1280  *
1281  * Description :  Windows call back routine handles events on the log window.
1282  *
1283  * Parameters  :
1284  *          1  :  hwnd = handle of the logging window
1285  *          2  :  uMsg = message number
1286  *          3  :  wParam = first param for this message
1287  *          4  :  lParam = next param for this message
1288  *
1289  * Returns     :  Appropriate M$ window message handler codes.
1290  *
1291  *********************************************************************/
1292 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1293 {
1294    switch (uMsg)
1295    {
1296       case WM_CREATE:
1297          return 0;
1298
1299       case WM_CLOSE:
1300          /* This is the end - beautiful friend - the end */
1301          DestroyWindow(g_hwndLogBox);
1302          DestroyWindow(g_hwndLogFrame);
1303          return 0;
1304
1305       case WM_DESTROY:
1306          PostQuitMessage(0);
1307          return 0;
1308
1309       case WM_SHOWWINDOW:
1310       case WM_SIZE:
1311          /* Resize the logging window to fit the new frame */
1312          if (g_hwndLogBox)
1313          {
1314             RECT rc;
1315             GetClientRect(g_hwndLogFrame, &rc);
1316             SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1317          }
1318          return 0;
1319
1320       case WM_INITMENU:
1321          OnLogInitMenu((HMENU) wParam);
1322          return 0;
1323
1324       case WM_TIMER:
1325          OnLogTimer(wParam);
1326          return 0;
1327
1328       case WM_COMMAND:
1329          OnLogCommand(LOWORD(wParam));
1330          return 0;
1331
1332       case WM_SYSCOMMAND:
1333          switch (wParam)
1334          {
1335             case SC_CLOSE:
1336                if (g_bCloseHidesWindow)
1337                {
1338                   ShowLogWindow(FALSE);
1339                   return 0;
1340                }
1341                break;
1342             case SC_MINIMIZE:
1343                ShowLogWindow(FALSE);
1344                return 0;
1345          }
1346          break;
1347    }
1348
1349    return DefWindowProc(hwnd, uMsg, wParam, lParam);
1350
1351 }
1352
1353 #endif /* ndef _WIN_CONSOLE - entire file */
1354
1355 /*
1356   Local Variables:
1357   tab-width: 3
1358   end:
1359 */