fix building with MSVC
[reactos.git] / reactos / subsys / system / notepad / main.c
index 75ecb84..be3ba17 100644 (file)
  *
  */
 
-#define UNICODE
-#define _UNICODE
-
-#define _CRT_SECURE_NO_DEPRECATE
-
-#include <windows.h>
-#include <stdio.h>
-#include <tchar.h>
-
-#include "main.h"
-#include "dialog.h"
-#include "notepad_res.h"
+#include <notepad.h>
 
 NOTEPAD_GLOBALS Globals;
 static ATOM aFINDMSGSTRING;
@@ -48,7 +37,7 @@ VOID SetFileName(LPCWSTR szFileName)
 {
     lstrcpy(Globals.szFileName, szFileName);
     Globals.szFileTitle[0] = 0;
-    GetFileTitle(szFileName, Globals.szFileTitle, sizeof(Globals.szFileTitle));
+    GetFileTitle(szFileName, Globals.szFileTitle, wcslen(Globals.szFileTitle));
 }
 
 /***********************************************************************
@@ -440,8 +429,8 @@ static void HandleCommandLine(LPWSTR cmdline)
     if (*cmdline)
     {
         /* file name is passed in the command line */
-        LPCWSTR file_name;
-        BOOL file_exists;
+        LPCWSTR file_name = NULL;
+        BOOL file_exists = FALSE;
         WCHAR buf[MAX_PATH];
 
         if (cmdline[0] == '"')
@@ -450,12 +439,12 @@ static void HandleCommandLine(LPWSTR cmdline)
             cmdline[lstrlen(cmdline) - 1] = 0;
         }
 
-        if (FileExists(cmdline))
+        file_name = cmdline;
+        if (FileExists(file_name))
         {
             file_exists = TRUE;
-            file_name = cmdline;
         }
-        else
+        else if (!HasFileExtension(cmdline))
         {
             static const WCHAR txtW[] = { '.','t','x','t',0 };
 
@@ -463,14 +452,13 @@ static void HandleCommandLine(LPWSTR cmdline)
             if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW)))
             {
                 file_exists = FALSE;
-                file_name = cmdline;
             }
             else
             {
                 lstrcpyn(buf, cmdline, MAX_PATH - lstrlen(txtW) - 1);
                 lstrcat(buf, txtW);
                 file_name = buf;
-                file_exists = FileExists(buf);
+                file_exists = FileExists(file_name);
             }
         }