bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-indent] Windows


From: Peter Harris
Subject: [Bug-indent] Windows
Date: Thu, 22 May 2003 17:40:21 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312

Windows has a bizarre method of finding the user's home directory.

The attached patch adds this method.

Peter Harris
diff -cr indent-2.2.9\src\args.c indent-2.2.9-pjh\src\args.c
*** indent-2.2.9\src\args.c     Sun Nov 10 16:02:48 2002
--- indent-2.2.9-pjh\src\args.c Wed Feb 12 17:24:09 2003
***************
*** 35,40 ****
--- 35,46 ----
  /* Argument scanning and profile reading code.  Default parameters are set
   * here as well. */
  
+ #ifdef _WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #include <userenv.h>
+ #undef ERROR
+ #endif
+ 
  #include <ctype.h>
  #include <stdio.h>
  #include <stdlib.h>
***************
*** 1051,1056 ****
--- 1057,1083 ----
  
  #define PROFILE_ENV_NAME "INDENT_PROFILE"
  
+ void try_homedir(char *homedir)
+ {
+     FILE        * f       = NULL;
+     static char   prof[]  = INDENT_PROFILE;
+     char *fname;
+ 
+     fname = xmalloc (strlen (homedir) + strlen(PROFILE_FORMAT) + sizeof 
(prof));
+     sprintf (fname, PROFILE_FORMAT, homedir, prof);
+     
+     if ((f = fopen (fname, "r")) != NULL)
+     {
+         scan_profile (f);
+         (void) fclose (f);
+     }
+     else
+     {
+         free (fname);
+         fname = NULL;
+     }
+ }
+ 
  /* set_profile looks for ./.indent.pro or $HOME/.indent.pro, in
   * that order, and reads the options given in that file.  Return the
   * path of the file read.
***************
*** 1098,1117 ****
      
              if (homedir)
              {
!                 fname = xmalloc (strlen (homedir) + strlen(PROFILE_FORMAT) + 
sizeof (prof));
!                 sprintf (fname, PROFILE_FORMAT, homedir, prof);
!                 
!                 if ((f = fopen (fname, "r")) != NULL)
!                 {
!                     scan_profile (f);
!                     (void) fclose (f);
!                 }
!                 else
!                 {
!                     free (fname);
!                     fname = NULL;
                  }
              }
          }
      }
      
--- 1125,1150 ----
      
              if (homedir)
              {
!                 try_homedir(homedir);
!             }
! #ifdef _WIN32
!             else
!             {
!                 HANDLE hUser;
!                 if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, 
&hUser)) {
!                     DWORD size = 0;
!                     GetUserProfileDirectory(hUser, &size, &size);
!                     if (size) {
!                         homedir = xmalloc(size + 1);
!                         homedir[size] = 0;
!                         if (GetUserProfileDirectory(hUser, homedir, &size))
!                             try_homedir(homedir);
!                         free(homedir);
!                     }
!                     CloseHandle(hUser);
                  }
              }
+ #endif
          }
      }
      

reply via email to

[Prev in Thread] Current Thread [Next in Thread]