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