Ignore:
Timestamp:
Oct 17, 2001, 11:15:22 AM (24 years ago)
Author:
phaller
Message:

SHELL32 WINE resync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/shell32_main.c

    r5861 r7085  
    1 /* $Id: shell32_main.c,v 1.5 2001-06-01 08:22:10 sandervl Exp $ */
     1/* $Id: shell32_main.c,v 1.6 2001-10-17 09:15:21 phaller Exp $ */
    22/*
    33 *                              Shell basics
     
    4646 * CommandLineToArgvW                   [SHELL32.7]
    4747 */
    48 LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
    49 {       LPWSTR  *argv,s,t;
    50         int     i;
    51         TRACE("\n");
    52 
    53         /* to get writeable copy */
    54         cmdline = HEAP_strdupW( GetProcessHeap(), 0, cmdline);
    55         s=cmdline;i=0;
    56         while (*s)
    57         { /* space */
    58           if (*s==0x0020)
    59           { i++;
    60             s++;
    61             while (*s && *s==0x0020)
    62               s++;
    63             continue;
    64           }
    65           s++;
    66         }
    67         argv=(LPWSTR*)HeapAlloc( GetProcessHeap(), 0, sizeof(LPWSTR)*(i+1) );
    68         s=t=cmdline;
    69         i=0;
    70         while (*s)
    71         { if (*s==0x0020)
    72           { *s=0;
    73             argv[i++]=HEAP_strdupW( GetProcessHeap(), 0, t );
    74             *s=0x0020;
    75             while (*s && *s==0x0020)
    76               s++;
    77             t=s;
    78             continue;
    79           }
    80           s++;
    81         }
    82         if (*t)
    83           argv[i++]=(LPWSTR)HEAP_strdupW( GetProcessHeap(), 0, t );
    84 
    85         HeapFree( GetProcessHeap(), 0, cmdline );
    86         argv[i]=NULL;
    87         *numargs=i;
    88         return argv;
    89 }
    90 
     48 /*************************************************************************
     49* CommandLineToArgvW[SHELL32.@]
     50*
     51* We must interpret the quotes in the command line to rebuild the argv
     52* array correctly:
     53* - arguments are separated by spaces or tabs
     54* - quotes serve as optional argument delimiters
     55*   '"a b"'   -> 'a b'
     56* - escaped quotes must be converted back to '"'
     57*   '\"'      -> '"'
     58* - an odd number of '\'s followed by '"' correspond to half that number
     59*   of '\' followed by a '"' (extension of the above)
     60*   '\\\"'    -> '\"'
     61*   '\\\\\"'  -> '\\"'
     62* - an even number of '\'s followed by a '"' correspond to half that number
     63*   of '\', plus a regular quote serving as an argument delimiter (which
     64*   means it does not appear in the result)
     65*   'a\\"b c"'   -> 'a\b c'
     66*   'a\\\\"b c"' -> 'a\\b c'
     67* - '\' that are not followed by a '"' are copied literally
     68*   'a\b'     -> 'a\b'
     69*   'a\\b'    -> 'a\\b'
     70*
     71* Note:
     72* '\t' == 0x0009
     73* ' '  == 0x0020
     74* '"'  == 0x0022
     75* '\\' == 0x005c
     76*/
     77LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
     78{
     79  DWORD argc;
     80  HGLOBAL hargv;
     81  LPWSTR  *argv;
     82  LPCWSTR cs;
     83  LPWSTR arg,s,d;
     84  LPWSTR cmdline;
     85  int in_quotes,bcount;
     86 
     87  if (*lpCmdline==0) {
     88  /* Return the path to the executable */
     89    DWORD size;
     90   
     91    hargv=0;
     92    size=16;
     93    do {
     94      size*=2;
     95      hargv=GlobalReAlloc(hargv, size, 0);
     96      argv=GlobalLock(hargv);
     97    } while (GetModuleFileNameW((HMODULE)0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0);
     98    argv[0]=(LPWSTR)(argv+1);
     99    if (numargs)
     100      *numargs=2;
     101   
     102    return argv;
     103  }
     104 
     105  /* to get a writeable copy */
     106  argc=0;
     107  bcount=0;
     108  in_quotes=0;
     109  cs=lpCmdline;
     110  while (1) {
     111    if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
     112    /* space */
     113      argc++;
     114      /* skip the remaining spaces */
     115      while (*cs==0x0009 || *cs==0x0020) {
     116        cs++;
     117      }
     118      if (*cs==0)
     119        break;
     120      bcount=0;
     121      continue;
     122    } else if (*cs==0x005c) {
     123    /* '\', count them */
     124      bcount++;
     125    } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
     126    /* unescaped '"' */
     127      in_quotes=!in_quotes;
     128      bcount=0;
     129    } else {
     130    /* a regular character */
     131      bcount=0;
     132    }
     133    cs++;
     134  }
     135  /* Allocate in a single lump, the string array, and the strings that go with it.
     136  * This way the caller can make a single GlobalFree call to free both, as per MSDN.
     137    */
     138    hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
     139  argv=GlobalLock(hargv);
     140  if (!argv)
     141    return NULL;
     142  cmdline=(LPWSTR)(argv+argc);
     143  strcpyW(cmdline, lpCmdline);
     144 
     145  argc=0;
     146  bcount=0;
     147  in_quotes=0;
     148  arg=d=s=cmdline;
     149  while (*s) {
     150    if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
     151    /* Close the argument and copy it */
     152      *d=0;
     153      argv[argc++]=arg;
     154     
     155      /* skip the remaining spaces */
     156      do {
     157        s++;
     158      } while (*s==0x0009 || *s==0x0020);
     159     
     160      /* Start with a new argument */
     161      arg=d=s;
     162      bcount=0;
     163    } else if (*s==0x005c) {
     164    /* '\\' */
     165      *d++=*s++;
     166      bcount++;
     167    } else if (*s==0x0022) {
     168    /* '"' */
     169      if ((bcount & 1)==0) {
     170      /* Preceeded by an even number of '\', this is half that
     171        * number of '\', plus a quote which we erase.
     172          */
     173          d-=bcount/2;
     174        in_quotes=!in_quotes;
     175        s++;
     176      } else {
     177      /* Preceeded by an odd number of '\', this is half that
     178        * number of '\' followed by a '"'
     179          */
     180          d=d-bcount/2-1;
     181        *d++='"';
     182        s++;
     183      }
     184      bcount=0;
     185    } else {
     186    /* a regular character */
     187      *d++=*s++;
     188      bcount=0;
     189    }
     190  }
     191  if (*arg) {
     192    *d='\0';
     193    argv[argc]=arg;
     194  }
     195  if (numargs)
     196    *numargs=argc;
     197 
     198  return argv;
     199}
    91200
    92201/*************************************************************************
     
    373482{
    374483    ICONINFO IconInfo;
    375     HICON hDupIcon = NULL;
     484    HICON hDupIcon = 0;
    376485
    377486    TRACE("(%04x, %04x)\n", hInstance, hIcon);
     
    546655               return TRUE;
    547656          case ABM_REMOVE:
    548                CloseHandle(data->hWnd);
     657               FIXME("ABM_REMOVE broken\n");
     658               /* FIXME: this is wrong; should it be DestroyWindow instead? */
     659               /*CloseHandle(data->hWnd);*/
    549660               return TRUE;
    550661          case ABM_SETAUTOHIDEBAR:
     
    654765                hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
    655766                SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
     767                if (!hIconTitleFont)
     768                {
     769                  LOGFONTA logFont;
     770                  SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
     771                  hIconTitleFont = CreateFontIndirectA( &logFont );
     772                }
    656773                SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
    657774                while (*pstr)
     
    680797    case WM_LBTRACKPOINT:
    681798        hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
    682         if( (INT16)GetKeyState16( VK_CONTROL ) < 0 )
     799        if( (INT16)GetKeyState( VK_CONTROL ) < 0 )
    683800      { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
    684801        { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
     
    689806
    690807                    if( pstr )
    691             { HCURSOR16 hCursor = LoadCursor16( 0, MAKEINTRESOURCE16(OCR_DRAGOBJECT) );
     808            { HCURSOR hCursor = LoadCursorA( 0, MAKEINTRESOURCEA(OCR_DRAGOBJECT) );
    692809                        SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
    693810                        SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
     
    867984 */
    868985void    (* WINAPI pDLLInitComctl)(LPVOID);
    869 
    870 LPVOID  (* WINAPI  pCOMCTL32_Alloc) (INT); 
    871 BOOL    (* WINAPI  pCOMCTL32_Free) (LPVOID); 
     986LPVOID  (* WINAPI pCOMCTL32_Alloc) (INT);
     987BOOL    (* WINAPI pCOMCTL32_Free) (LPVOID);
     988
     989/* 2001-10-17 @@@PH
     990   either me or VAC308 seems to be confused here:
     991   if complains about redeclaration of the corresponding functions
     992   in commctrl.h
     993   
     994   Even more strangely, all variables "pFunction" are automatically
     995   percieved as "Function".
     996*/
     997#if 0
     998HDPA    (* WINAPI lpDPA_Create) (INT);
     999INT     (* WINAPI lpDPA_InsertPtr) (const HDPA, INT, LPVOID);
     1000BOOL    (* WINAPI lpDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM);
     1001LPVOID  (* WINAPI lpDPA_GetPtr) (const HDPA, INT);
     1002BOOL    (* WINAPI lpDPA_Destroy) (const HDPA);
     1003INT     (* WINAPI lpDPA_Search) (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
     1004LPVOID  (* WINAPI lpDPA_DeletePtr) (const HDPA hdpa, INT i);
     1005HANDLE  (* WINAPI lpCreateMRUListA) (LPVOID lpcml);
     1006DWORD   (* WINAPI lpFreeMRUListA) (HANDLE hMRUList);
     1007INT     (* WINAPI lpAddMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData);
     1008INT     (* WINAPI lpFindMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
     1009INT     (* WINAPI lpEnumMRUListA) (HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
     1010#endif
    8721011
    8731012static HINSTANCE        hComctl32;
     
    9081047
    9091048            /* comctl32 */
     1049            pDLLInitComctl=(void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
    9101050            pCOMCTL32_Alloc=(void*)GetProcAddress(hComctl32, (LPCSTR)71L);
    911             pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
    912 
    913             /* initialize the common controls */
     1051            pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
     1052#if 0
     1053            lpDPA_Create=(void*)GetProcAddress(hComctl32, (LPCSTR)328L);
     1054            lpDPA_Destroy=(void*)GetProcAddress(hComctl32, (LPCSTR)329L);
     1055            lpDPA_GetPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)332L);
     1056            lpDPA_InsertPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)334L);
     1057            lpDPA_DeletePtr=(void*)GetProcAddress(hComctl32, (LPCSTR)336L);
     1058            lpDPA_Sort=(void*)GetProcAddress(hComctl32, (LPCSTR)338L);
     1059            lpDPA_Search=(void*)GetProcAddress(hComctl32, (LPCSTR)339L);
     1060            lpCreateMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)151L /*"CreateMRUListA"*/);
     1061            lpFreeMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)152L /*"FreeMRUList"*/);
     1062            lpAddMRUData=(void*)GetProcAddress(hComctl32, (LPCSTR)167L /*"AddMRUData"*/);
     1063            lpFindMRUData=(void*)GetProcAddress(hComctl32, (LPCSTR)169L /*"FindMRUData"*/);
     1064            lpEnumMRUListA=(void*)GetProcAddress(hComctl32, (LPCSTR)154L /*"EnumMRUListA"*/);
     1065#endif
     1066            /* initialize the common controls */
     1067            if (pDLLInitComctl)
     1068            {
     1069              pDLLInitComctl(NULL);
     1070            }
    9141071            InitCommonControlsEx(NULL);
    9151072
Note: See TracChangeset for help on using the changeset viewer.