*/
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Forward referenced subroutines */
 
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Imported subroutines */
 
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 
 
 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 #include <windows.h>
 
-static char buf[100];
 int bacstat = 0;
 
 struct s_win32_arg {
        // when compiling with visual studio some strings are read-only 
        // and cause access violations. So we creat a tmp copy.
        char *_msg = (char *)alloca(len);
-       strncpy(_msg, msg, len-1);
-       _msg[len-1] = 0;
+       bstrncpy(_msg, msg, len);
        msg = _msg;
    }
    SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
    do_status(win32_sendit, (void *)&arg);
 }
 
-char *bac_status(int stat)
+char *bac_status(char *buf, int buf_len)
 {
    JCR *njcr;
    const char *termstat = _("Bacula Idle");
    struct s_last_job *job;
+   int stat = 0;                     /* Idle */
 
-   bacstat = 0;
    if (!last_jobs) {
-      return _("Bacula Terminated");
+      goto done;
+   }
+   Dmsg0(1000, "Begin bac_status jcr loop.\n");
+   lock_jcr_chain();
+   foreach_jcr(njcr) {
+      if (njcr->JobId != 0) {
+        stat = JS_Running;
+         termstat = _("Bacula Running");
+        free_locked_jcr(njcr);
+        break;
+      }
+      free_locked_jcr(njcr);
+   }
+   unlock_jcr_chain();
+   if (stat != 0) {
+      goto done;
    }
    if (last_jobs->size() > 0) {
       job = (struct s_last_job *)last_jobs->last();
+      stat = job->JobStatus;
       switch (job->JobStatus) {
       case JS_Canceled:
-        bacstat = -1;
          termstat = _("Last Job Canceled");
         break;
       case JS_ErrorTerminated:
-        bacstat = -1;
          termstat = _("Last Job Failed");
         break;
       default:
+        if (job->Errors) {
+            termstat = _("Last Job had Errors");
+        }
         break;
       }
    }
-   Dmsg0(1000, "Begin bac_status jcr loop.\n");
-   lock_jcr_chain();
-   foreach_jcr(njcr) {
-      if (njcr->JobId != 0) {
-        bacstat = 1;
-         termstat = _("Bacula Running");
-        free_locked_jcr(njcr);
-        break;
-      }
-      free_locked_jcr(njcr);
-   }
-   unlock_jcr_chain();
    Dmsg0(1000, "End bac_status jcr loop.\n");
-   bstrncpy(buf, termstat, sizeof(buf));
+done:
+   bacstat = stat;
+   if (buf) {
+      bstrncpy(buf, termstat, sizeof(buf));
+   }
    return buf;
 }
 
 
 winlib.a: $(BACOBJS) winres.res
        ar rcs $@ $(BACOBJS)
 
-winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico
+winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico
        windres $< -O coff -o $@
 
 winmain.o: winmain.cpp winbacula.h
 
 winlib.a: $(BACOBJS) winres.res
        ar rcs $@ $(BACOBJS)
 
-winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico
+winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico
        windres -DHAVE_MINGW $< -O coff -o $@
 
 winmain.o: winmain.cpp winbacula.h
 
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
 
    This file is patterned after the VNC Win32 code by ATT
   
-   Copyright (2000) Kern E. Sibbald
 */
 
 #ifndef HAVE_WIN32
 
 #define IDI_IDLE                        101
 #define IDI_RUNNING                     102
 #define IDI_JOB_ERROR                   103
-#define IDR_TRAYMENU                    104
+#define IDI_JOB_WARNING                 104
+#define IDR_TRAYMENU                    105
+#define IDB_BACULABMP                   106
 
 #define IDC_LIST                        1000
 #define IDC_NONYET_LABEL                1006
 #define IDD_EVENTS                      203
 
 
-#define IDB_BACULABMP                   106
 
 IDI_IDLE                ICON    DISCARDABLE     "idle.ico"
 IDI_RUNNING             ICON    DISCARDABLE     "running.ico"
 IDI_JOB_ERROR           ICON    DISCARDABLE     "error.ico"
+IDI_JOB_WARNING         ICON    DISCARDABLE     "warn.ico"
 
 /////////////////////////////////////////////////////////////////////////////
 //
 
 
 
 #include <lmcons.h>
+#undef PASCAL
 #include "winbacula.h"
 #include "winservice.h"
 #include "wintray.h"
 
 // by Kern E. Sibbald.  Many thanks to ATT and James Weatherall,
 // the original author, for providing an excellent template.
 //
-// Copyright (2000-2003) Kern E. Sibbald
+// Copyright 2000-2004, Kern E. Sibbald
 //
 
 
 // Header
 
 #include "wintray.h"
+#include "bacula.h"
+#include "jcr.h"
 
 // Constants
 #ifdef properties_implemented
 const char *MENU_CLASS_NAME = "Bacula Tray Icon";
 
 extern void terminate_filed(int sig);
-extern char *bac_status(int stat);
+extern char *bac_status(char *buf, int buf_len);
 extern int bacstat;
 
 // Implementation
    SetTimer(m_hwnd, 1, 5000, NULL);
 
    // Load the icons for the tray
-   m_idle_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE));
+   m_idle_icon    = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE));
    m_running_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_RUNNING));
-   m_error_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR));
+   m_error_icon   = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR));
+   m_warn_icon    = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_WARNING));
 
    // Load the popup menu
    m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
 void
 bacMenu::UpdateTrayIcon(int bacstat)
 {
-   (void *)bac_status(0);
+   (void *)bac_status(NULL, 0);
    SendTrayMsg(NIM_MODIFY, bacstat);
 }
 
 void
 bacMenu::SendTrayMsg(DWORD msg, int bacstat)
 {
+   struct s_last_job *job;
+   
    // Create the tray icon message
    m_nid.hWnd = m_hwnd;
    m_nid.cbSize = sizeof(m_nid);
    m_nid.uID = IDI_BACULA;                  // never changes after construction
-   if (bacstat == 0)
+   switch (bacstat) {
+   case 0:
       m_nid.hIcon = m_idle_icon;
-   else if (bacstat == 1)
+      break;
+   case JS_Running:
       m_nid.hIcon = m_running_icon;
-   else if (bacstat < 0)
+      break;
+   case JS_ErrorTerminated:
       m_nid.hIcon = m_error_icon;
+      break;
+   default:
+      if (last_jobs->size() > 0) {
+         job = (struct s_last_job *)last_jobs->last();
+         if (job->Errors) {
+            m_nid.hIcon = m_warn_icon;
+         } else {
+            m_nid.hIcon = m_idle_icon;
+         }
+      } else {
+         m_nid.hIcon = m_idle_icon;
+      }
+      break;
+   }
 
    m_nid.uFlags = NIF_ICON | NIF_MESSAGE;
    m_nid.uCallbackMessage = WM_TRAYNOTIFY;
 
    // Try to add the Bacula status to the tip string, if possible
    if (m_nid.uFlags & NIF_TIP) {
-       strncpy(m_nid.szTip, bac_status(0), (sizeof(m_nid.szTip)-1));
+       bac_status(m_nid.szTip, sizeof(m_nid.szTip));
    }
 
    // Send the message
       if (bacService::RunningAsService()) {
           // Attempt to add the icon if it's not already there
           _this->AddTrayIcon();
-          // Trigger a check of the current user
-//        PostMessage(hwnd, WM_USERCHANGED, 0, 0);
       }
 
       // Update the icon
       _this->UpdateTrayIcon(bacstat);
      break;
 
-#ifdef xxx_needed
-
-   // DEAL WITH NOTIFICATIONS FROM THE SERVER:
-   case WM_SRV_CLIENT_AUTHENTICATED:
-   case WM_SRV_CLIENT_DISCONNECT:
-      // Adjust the icon accordingly
-      _this->UpdateTrayIcon(bacstat);
-      return 0;
-#endif
-
    // STANDARD MESSAGE HANDLING
    case WM_CREATE:
       return 0;
       return 0;
 
    case WM_QUERYENDSESSION:
-           // Are we running as a system service?
-           // Or is the system shutting down (in which case we should check anyway!)
-           if ((!bacService::RunningAsService()) || (lParam == 0)) {
-                   // No, so we are about to be killed
+      // Are we running as a system service?
+      // Or is the system shutting down (in which case we should check anyway!)
+      if ((!bacService::RunningAsService()) || (lParam == 0)) {
+         // No, so we are about to be killed
 
-                   // If there are remote connections then we should verify
-                   // that the user is happy about killing them.
+         // If there are remote connections then we should verify
+         // that the user is happy about killing them.
 
-                   // Finally, post a quit message, just in case
-                   PostQuitMessage(0);
-                   return TRUE;
-           }
-
-           // Tell the OS that we've handled it anyway
-//         PostQuitMessage(0);
-           return TRUE;
+         // Finally, post a quit message, just in case
+         PostQuitMessage(0);
+         return TRUE;
+      }
+      return TRUE;
 
    
    default:
-           if (iMsg == MENU_ABOUTBOX_SHOW) {
-                   // External request to show our About dialog
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
-                   return 0;
-           }
-           if (iMsg == MENU_STATUS_SHOW) {
-                   // External request to show our status
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0);
-                   return 0;
-           }
-
-#ifdef xxx_needed
-           if (iMsg == MENU_EVENTS_SHOW) {
-                   // External request to show our Events dialogue
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_EVENTS, 0), 0);
-                   return 0;
-           }
-
-           if (iMsg == MENU_SERVICEHELPER_MSG) {
-                   // External ServiceHelper message.
-                   // This message holds a process id which we can use to
-                   // impersonate a specific user.  In doing so, we can load their
-                   // preferences correctly
-                   bacService::ProcessUserHelperMessage(wParam, lParam);
-
-                   // - Trigger a check of the current user
-                   PostMessage(hwnd, WM_USERCHANGED, 0, 0);
-                   return 0;
-           }
-           if (iMsg == MENU_ADD_CLIENT_MSG) {
-                   // Add Client message.  This message includes an IP address
-                   // of a listening client, to which we should connect.
-
-                   return 0;
-           }
-#endif
+      if (iMsg == MENU_ABOUTBOX_SHOW) {
+         // External request to show our About dialog
+         PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
+         return 0;
+      }
+      if (iMsg == MENU_STATUS_SHOW) {
+         // External request to show our status
+         PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0);
+         return 0;
+      }
    }
 
    // Message not recognised
 
 protected:
 
    // About dialog for this server
-   bacAbout                m_about;
+   bacAbout  m_about;
 
    // Status dialog for this server
-   bacStatus               m_status;
+   bacStatus m_status;
 
-   bacEvents               m_events;
+   bacEvents m_events;
 
-   HWND                    m_hwnd;
-   HMENU                   m_hmenu;
-   NOTIFYICONDATA          m_nid;
+   HWND  m_hwnd;
+   HMENU m_hmenu;
+   NOTIFYICONDATA m_nid;
 
    // The icon handles
-   HICON                   m_idle_icon;
-   HICON                   m_running_icon;
-   HICON                   m_error_icon;
+   HICON m_idle_icon;
+   HICON m_running_icon;
+   HICON m_error_icon;
+   HICON m_warn_icon;
 };
 
 
 
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Forward referenced subroutines */
 
  */
 struct s_last_job {
    dlink link;
-   int xNumJobs;                      /* no longer used */
+   int Errors;                        /* FD/SD errors */
    int JobType;
    int JobStatus;
    int JobLevel;
 
    for (;!quit;) {
       fd_set sockset;
       FD_ZERO(&sockset);
-      FD_SET(sockfd, &sockset);
+      FD_SET((unsigned)sockfd, &sockset);
       errno = 0;
       if ((stat = select(sockfd+1, &sockset, NULL, NULL, NULL)) < 0) {
         if (errno == EINTR || errno == EAGAIN) {
     * Wait for a connection from the client process.
     */
    FD_ZERO(&sockset);
-   FD_SET(bsock->fd, &sockset);
+   FD_SET((unsigned)bsock->fd, &sockset);
 
    for (;;) {
       /* 
 
    case JT_RESTORE:
    case JT_ADMIN:
       num_jobs_run++;
+      last_job.Errors = jcr->Errors;
       last_job.JobType = jcr->JobType;
       last_job.JobId = jcr->JobId;
       last_job.VolSessionId = jcr->VolSessionId;
 
 /* First and last resource ids */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 
 
 # Build installer
 #
 winbacula.exe: bacula
-       ${MAKENSIS} winbacula.nsi
+       ${MAKENSIS} /V2 winbacula.nsi
 
 
 Makefile: $(srcdir)/Makefile.in $(topdir)/config.status winbacula.nsi.in
 
 # PROP BASE Output_Dir "Debug"\r
 # PROP BASE Intermediate_Dir "Debug"\r
 # PROP BASE Target_Dir ""\r
-# PROP Use_MFC 2\r
+# PROP Use_MFC 0\r
 # PROP Use_Debug_Libraries 1\r
 # PROP Output_Dir "Debug"\r
 # PROP Intermediate_Dir "Debug"\r
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c\r
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../compat" /I "../.." /I "../../../../depkgs-win32/pthreads" /I "../../../../depkgs-win32/zlib" /I "." /D "_DEBUG" /D "_WINMAIN_" /D "PTW32_BUILD" /D "_AFXDLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_WIN32" /FR /FD /GZ /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../compat" /I "../.." /I "../../../../depkgs-win32/pthreads" /I "../../../../depkgs-win32/zlib" /I "." /D "_DEBUG" /D "_WINMAIN_" /D "PTW32_BUILD" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_WIN32" /FR /FD /GZ /c\r
 # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"\r
-# ADD RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
 BSC32=bscmake.exe\r
 # ADD BASE BSC32 /nologo\r
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 wsock32.lib pthreadVCE.lib zlib.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /out:"Debug/bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib"\r
+# ADD LINK32 user32.lib advapi32.lib gdi32.lib wsock32.lib shell32.lib pthreadVCE.lib zlib.lib kernel32.lib comdlg32.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /nodefaultlib:"MSVCRT.lib" /out:"Debug/bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib"\r
 \r
 !ENDIF \r
 \r
 
 NULL=nul
 !ENDIF 
 
+CPP=cl.exe
+RSC=rc.exe
+
 !IF  "$(CFG)" == "baculafd - Win32 Release"
 
 OUTDIR=.\Release
         -@erase "$(INTDIR)\bshm.obj"
         -@erase "$(INTDIR)\bsys.obj"
         -@erase "$(INTDIR)\btime.obj"
+        -@erase "$(INTDIR)\btimers.obj"
         -@erase "$(INTDIR)\compat.obj"
         -@erase "$(INTDIR)\cram-md5.obj"
         -@erase "$(INTDIR)\crc32.obj"
         -@erase "$(INTDIR)\smartall.obj"
         -@erase "$(INTDIR)\status.obj"
         -@erase "$(INTDIR)\StdAfx.obj"
-        -@erase "$(INTDIR)\btimers.obj"
         -@erase "$(INTDIR)\tree.obj"
         -@erase "$(INTDIR)\util.obj"
         -@erase "$(INTDIR)\var.obj"
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
-CPP=cl.exe
 CPP_PROJ=/nologo /MT /W3 /GX /O2 /I "../compat" /I "../.." /I "../../../../depkgs-win32/pthreads" /I "../../../../depkgs-win32/zlib" /I "." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
-
-.c{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cpp{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cxx{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.c{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cpp{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cxx{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-RSC=rc.exe
 RSC_PROJ=/l 0x409 /fo"$(INTDIR)\winres.res" /d "NDEBUG" 
 BSC32=bscmake.exe
 BSC32_FLAGS=/nologo /o"$(OUTDIR)\baculafd.bsc" 
 BSC32_SBRS= \
         
 LINK32=link.exe
-LINK32_FLAGS=user32.lib ADVAPI32.LIB gdi32.lib wsock32.lib shell32.lib pthreadVCE.lib zlib.lib /nologo /subsystem:windows /pdb:none /machine:I386 /nodefaultlib:"MSVCRT.lib" /out:"$(OUTDIR)\bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib" 
+LINK32_FLAGS=user32.lib advapi32.lib gdi32.lib wsock32.lib shell32.lib pthreadVCE.lib zlib.lib /nologo /subsystem:windows /pdb:none /machine:I386 /nodefaultlib:"MSVCRT.lib" /out:"$(OUTDIR)\bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib" 
 LINK32_OBJS= \
         "$(INTDIR)\alist.obj" \
         "$(INTDIR)\alloc.obj" \
         "$(INTDIR)\bshm.obj" \
         "$(INTDIR)\bsys.obj" \
         "$(INTDIR)\btime.obj" \
+        "$(INTDIR)\btimers.obj" \
         "$(INTDIR)\compat.obj" \
         "$(INTDIR)\cram-md5.obj" \
         "$(INTDIR)\crc32.obj" \
         "$(INTDIR)\smartall.obj" \
         "$(INTDIR)\status.obj" \
         "$(INTDIR)\StdAfx.obj" \
-        "$(INTDIR)\btimers.obj" \
         "$(INTDIR)\tree.obj" \
         "$(INTDIR)\util.obj" \
         "$(INTDIR)\var.obj" \
         -@erase "$(INTDIR)\bsys.sbr"
         -@erase "$(INTDIR)\btime.obj"
         -@erase "$(INTDIR)\btime.sbr"
+        -@erase "$(INTDIR)\btimers.obj"
+        -@erase "$(INTDIR)\btimers.sbr"
         -@erase "$(INTDIR)\compat.obj"
         -@erase "$(INTDIR)\compat.sbr"
         -@erase "$(INTDIR)\cram-md5.obj"
         -@erase "$(INTDIR)\status.sbr"
         -@erase "$(INTDIR)\StdAfx.obj"
         -@erase "$(INTDIR)\StdAfx.sbr"
-        -@erase "$(INTDIR)\btimers.obj"
-        -@erase "$(INTDIR)\btimers.sbr"
         -@erase "$(INTDIR)\tree.obj"
         -@erase "$(INTDIR)\tree.sbr"
         -@erase "$(INTDIR)\util.obj"
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
-CPP=cl.exe
-CPP_PROJ=/nologo /MDd /W3 /Gm /GX /ZI /Od /I "../compat" /I "../.." /I "../../../../depkgs-win32/pthreads" /I "../../../../depkgs-win32/zlib" /I "." /D "_DEBUG" /D "_WINMAIN_" /D "PTW32_BUILD" /D "_AFXDLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_WIN32" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c 
-
-.c{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cpp{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cxx{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.c{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cpp{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-.cxx{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $< 
-<<
-
-RSC=rc.exe
-RSC_PROJ=/l 0x409 /fo"$(INTDIR)\winres.res" /d "_DEBUG" /d "_AFXDLL" 
+CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I "../compat" /I "../.." /I "../../../../depkgs-win32/pthreads" /I "../../../../depkgs-win32/zlib" /I "." /D "_DEBUG" /D "_WINMAIN_" /D "PTW32_BUILD" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_WIN32" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c 
+RSC_PROJ=/l 0x409 /fo"$(INTDIR)\winres.res" /d "_DEBUG" 
 BSC32=bscmake.exe
 BSC32_FLAGS=/nologo /o"$(OUTDIR)\baculafd.bsc" 
 BSC32_SBRS= \
         "$(INTDIR)\bshm.sbr" \
         "$(INTDIR)\bsys.sbr" \
         "$(INTDIR)\btime.sbr" \
+        "$(INTDIR)\btimers.sbr" \
         "$(INTDIR)\compat.sbr" \
         "$(INTDIR)\cram-md5.sbr" \
         "$(INTDIR)\crc32.sbr" \
         "$(INTDIR)\smartall.sbr" \
         "$(INTDIR)\status.sbr" \
         "$(INTDIR)\StdAfx.sbr" \
-        "$(INTDIR)\btimers.sbr" \
         "$(INTDIR)\tree.sbr" \
         "$(INTDIR)\util.sbr" \
         "$(INTDIR)\var.sbr" \
 <<
 
 LINK32=link.exe
-LINK32_FLAGS=user32.lib ADVAPI32.LIB gdi32.lib shell32.lib wsock32.lib pthreadVCE.lib zlib.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /out:"$(OUTDIR)\bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib" 
+LINK32_FLAGS=user32.lib advapi32.lib gdi32.lib shell32.lib wsock32.lib pthreadVCE.lib zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /nodefaultlib:"MSVCRT.lib" /out:"$(OUTDIR)\bacula-fd.exe" /libpath:"../../../../depkgs-win32/pthreads" /libpath:"../../../../depkgs-win32/zlib" 
 LINK32_OBJS= \
         "$(INTDIR)\alist.obj" \
         "$(INTDIR)\alloc.obj" \
         "$(INTDIR)\bshm.obj" \
         "$(INTDIR)\bsys.obj" \
         "$(INTDIR)\btime.obj" \
+        "$(INTDIR)\btimers.obj" \
         "$(INTDIR)\compat.obj" \
         "$(INTDIR)\cram-md5.obj" \
         "$(INTDIR)\crc32.obj" \
         "$(INTDIR)\smartall.obj" \
         "$(INTDIR)\status.obj" \
         "$(INTDIR)\StdAfx.obj" \
-        "$(INTDIR)\btimers.obj" \
         "$(INTDIR)\tree.obj" \
         "$(INTDIR)\util.obj" \
         "$(INTDIR)\var.obj" \
 
 !ENDIF 
 
+.c{$(INTDIR)}.obj::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
+.cpp{$(INTDIR)}.obj::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
+.cxx{$(INTDIR)}.obj::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
+.c{$(INTDIR)}.sbr::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
+.cpp{$(INTDIR)}.sbr::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
+.cxx{$(INTDIR)}.sbr::
+   $(CPP) @<<
+   $(CPP_PROJ) $< 
+<<
+
 
 !IF "$(NO_EXTERNAL_DEPS)" != "1"
 !IF EXISTS("baculafd.dep")
         $(CPP) $(CPP_PROJ) $(SOURCE)
 
 
+!ENDIF 
+
+SOURCE=..\lib\btimers.cpp
+
+!IF  "$(CFG)" == "baculafd - Win32 Release"
+
+
+"$(INTDIR)\btimers.obj" : $(SOURCE) "$(INTDIR)"
+        $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+!ELSEIF  "$(CFG)" == "baculafd - Win32 Debug"
+
+
+"$(INTDIR)\btimers.obj" "$(INTDIR)\btimers.sbr" : $(SOURCE) "$(INTDIR)"
+        $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
 !ENDIF 
 
 SOURCE=..\compat\compat.cpp
 "$(INTDIR)\StdAfx.obj"  "$(INTDIR)\StdAfx.sbr" : $(SOURCE) "$(INTDIR)"
 
 
-!ENDIF 
-
-SOURCE=..\lib\btimers.cpp
-
-!IF  "$(CFG)" == "baculafd - Win32 Release"
-
-
-"$(INTDIR)\btimers.obj" : $(SOURCE) "$(INTDIR)"
-        $(CPP) $(CPP_PROJ) $(SOURCE)
-
-
-!ELSEIF  "$(CFG)" == "baculafd - Win32 Debug"
-
-
-"$(INTDIR)\btimers.obj"  "$(INTDIR)\btimers.sbr" : $(SOURCE) "$(INTDIR)"
-        $(CPP) $(CPP_PROJ) $(SOURCE)
-
-
 !ENDIF 
 
 SOURCE=..\lib\tree.cpp
 
 
 "$(INTDIR)\winres.res" : $(SOURCE) "$(INTDIR)"
-        $(RSC) /l 0x409 /fo"$(INTDIR)\winres.res" /i "..\..\filed\win32" /d "_DEBUG" /d "_AFXDLL" $(SOURCE)
+        $(RSC) /l 0x409 /fo"$(INTDIR)\winres.res" /i "..\..\filed\win32" /d "_DEBUG" $(SOURCE)
 
 
 !ENDIF 
 
 #include <basetsd.h>
 #include <stdarg.h>
 #include <sys/types.h>
-
-#ifdef HAVE_WXCONSOLE
-//#include <sys/stat.h>
-#endif
-
 #include <process.h>
 #include <direct.h>
 #include <winsock2.h>
 
 #include "getopt.h"
 
-#ifdef HAVE_MINGW
 #define HAVE_WIN32 1
-#else
+
+#ifndef HAVE_MINGW
 #ifdef HAVE_CYGWIN
 #error should not be used under cygwin...
 #else
-#define HAVE_WIN32 1
 #endif //HAVE_CYGWIN
 #endif //HAVE_MINGW
+
 typedef UINT64 u_int64_t;
 typedef UINT64 uint64_t;
 typedef INT64 int64_t;
 typedef unsigned short uint16_t;
 typedef signed short int16_t;
 typedef long time_t;
+typedef signed char int8_t;
+
 #if __STDC__
 #ifndef HAVE_MINGW
 typedef _dev_t dev_t;
 #else
 typedef long _off_t;            /* must be same as sys/types.h */
 #endif
-typedef signed char int8_t;
+
 #ifndef HAVE_MINGW
 #ifndef HAVE_WXCONSOLE
 typedef int BOOL;
 #define bool BOOL
 #endif
 #endif
+
 typedef double float64_t;
 typedef UINT32 u_int32_t;
 typedef unsigned char u_int8_t;
 #define S_IRUSR         S_IREAD
 #define S_IWUSR         S_IWRITE
 #define S_IXUSR         S_IEXEC
+#define S_ISREG(x)  (((x) & S_IFREG) == S_IFREG)
+#define S_ISDIR(x)  (((x) & S_IFDIR) == S_IFDIR)
+#define S_ISCHR(x) 0
+#define S_ISBLK(x) 0
+#define S_ISFIFO(x) 0
 #endif //HAVE_MINGW
 
 #define S_IRGRP         000040
 #define S_ISUID         004000
 #define S_ISGID         002000
 #define S_ISVTX         001000
-
-#ifndef HAVE_MINGW
-#define S_ISREG(x)  (((x) & S_IFREG) == S_IFREG)
-#define S_ISDIR(x)  (((x) & S_IFDIR) == S_IFDIR)
-#define S_ISCHR(x) 0
-#define S_ISBLK(x) 0
-#define S_ISFIFO(x) 0
-#endif //HAVE_MINGW
-
 #define S_ISSOCK(x) 0
 #define S_ISLNK(x)      0
 
-
 #if __STDC__
 #define O_RDONLY _O_RDONLY
 #define O_WRONLY _O_WRONLY
 #define toascii __toascii
 #define iscsymf __iscsymf
 #define iscsym  __iscsym
-
 #endif
-#define SIGUSR2 9999
+
 
 int umask(int);
 int lchown(const char *, uid_t uid, gid_t gid);
 int chown(const char *, uid_t uid, gid_t gid);
 int chmod(const char *, mode_t mode);
-#ifndef HAVE_MINGW
-int utime(const char *filename, struct utimbuf *buf);
-int open(const char *, int, int);
-#ifndef HAVE_WXCONSOLE
-ssize_t read(int fd, void *, size_t nbytes);
-ssize_t write(int fd, const void *, size_t nbytes);
-#endif
-int close(int fd);
-#endif //HAVE_MINGW
 off_t lseek(int, off_t, int);
 int inet_aton(const char *cp, struct in_addr *inp);
 int kill(int pid, int signo);
 int fork();
 int dup2(int, int);
 int waitpid(int, int *, int);
-#define WNOHANG 0
-#define WIFEXITED(x) 0
-#define WEXITSTATUS(x) x
-#define WIFSIGNALED(x) 0
-
-#define SIGKILL 9
-
-#define HAVE_OLD_SOCKOPT
 
 #ifndef HAVE_MINGW
+int utime(const char *filename, struct utimbuf *buf);
+int open(const char *, int, int);
 #define vsnprintf __vsnprintf
 int __vsnprintf(char *s, size_t count, const char *format, va_list args);
 
 
 #define sprintf __sprintf
 int __sprintf(char *str, const char *fmt, ...);
+
+#ifndef HAVE_WXCONSOLE
+ssize_t read(int fd, void *, size_t nbytes);
+ssize_t write(int fd, const void *, size_t nbytes);
+#endif
+
+int close(int fd);
 #endif //HAVE_MINGW
 
+
+#define WNOHANG 0
+#define WIFEXITED(x) 0
+#define WEXITSTATUS(x) x
+#define WIFSIGNALED(x) 0
+#define SIGKILL 9
+#define SIGUSR2 9999
+
+#define HAVE_OLD_SOCKOPT
+
 int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
 int nanosleep(const struct timespec*, struct timespec *);
-
 struct tm *localtime_r(const time_t *, struct tm *);
 struct tm *gmtime_r(const time_t *, struct tm *);
 long int random(void);
 
 #define mkdir(p, m) _mkdir(p)
 #define chdir win32_chdir
-
-#ifndef HAVE_MINGW
-int stat(const char *, struct stat *);
-#endif //HAVE_MINGW
 int syslog(int, const char *, const char *);
 #define LOG_DAEMON 0
 #define LOG_ERR 0
 
 #ifndef HAVE_MINGW
+int stat(const char *, struct stat *);
 #ifdef __cplusplus
 #define access _access
 extern "C" _CRTIMP int __cdecl _access(const char *, int);
 
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Forward referenced subroutines */