Author: jmorlan Date: Sat Feb 21 21:12:16 2009 New Revision: 39699
URL: http://svn.reactos.org/svn/reactos?rev=39699&view=rev Log: Clean up DirReadParam a bit, reworked so that the code for adding a filename parameter doesn't need to be duplicated 3 times. Should handle quotes properly now (bug 4177)
Modified: trunk/reactos/base/shell/cmd/dir.c
Modified: trunk/reactos/base/shell/cmd/dir.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=39... ============================================================================== --- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Sat Feb 21 21:12:16 2009 @@ -250,18 +250,13 @@ LPTSTR temp;
/* Initialize parameter array */ - if(!params) - return FALSE; *params = NULL; *entries = 0; - ptrStart = NULL; - ptrEnd = NULL;
/* Initialize variables; */ cCurSwitch = _T(' '); bNegative = FALSE; bPNegative = FALSE; - bIntoQuotes = FALSE;
/* We suppose that switch parameters were given to avoid setting them to default @@ -348,75 +343,45 @@ cCurSwitch = _T(' ');
} - else if ((cCurSwitch == _T(' ')) || (cCurSwitch == _T('P'))) + else if (cCurSwitch == _T(' ')) { /* 2nd section (see README_DIR.txt) */ /* We are expecting parameter or the unknown */
if (cCurChar == _T('/')) cCurSwitch = _T('/'); - - /* Process a spacer */ else if (cCurChar == _T(' ')) - { - if (!bIntoQuotes) - { - cCurSwitch = _T(' '); - if(ptrStart && ptrEnd) - { - temp = cmd_alloc(((ptrEnd - ptrStart) + 2) * sizeof (TCHAR)); - if(!temp) - return FALSE; - memcpy(temp, ptrStart, ((ptrEnd - ptrStart) + 2) * sizeof (TCHAR)); - temp[(ptrEnd - ptrStart + 1)] = _T('\0'); - if(!add_entry(entries, params, temp)) - { - cmd_free(temp); - freep(*params); - return FALSE; - } - - cmd_free(temp); - - ptrStart = NULL; - ptrEnd = NULL; - } - } - - } - else if (cCurChar == _T('"')) - { - /* Process a quote */ - bIntoQuotes = !bIntoQuotes; - if(!bIntoQuotes) - ptrEnd = Line; - } + /* do nothing */; else { - /* Process a character for parameter */ - if ((cCurSwitch == _T(' ')) && ptrStart && ptrEnd) - { - temp = cmd_alloc(((ptrEnd - ptrStart) + 2) * sizeof (TCHAR)); - if(!temp) - return FALSE; - memcpy(temp, ptrStart, ((ptrEnd - ptrStart) + 2) * sizeof (TCHAR)); - temp[(ptrEnd - ptrStart + 1)] = _T('\0'); - if(!add_entry(entries, params, temp)) - { - cmd_free(temp); - freep(*params); - return FALSE; - } - + /* This is a file/directory name parameter. Find its end */ + ptrStart = Line; + bIntoQuotes = FALSE; + while (*Line) + { + if (!bIntoQuotes && (*Line == _T('/') || *Line == _T(' '))) + break; + bIntoQuotes ^= (*Line == _T('"')); + Line++; + } + ptrEnd = Line; + + /* Copy it to the entries list */ + temp = cmd_alloc((ptrEnd - ptrStart + 1) * sizeof (TCHAR)); + if(!temp) + return FALSE; + memcpy(temp, ptrStart, (ptrEnd - ptrStart) * sizeof (TCHAR)); + temp[ptrEnd - ptrStart] = _T('\0'); + StripQuotes(temp); + if(!add_entry(entries, params, temp)) + { cmd_free(temp); - - ptrStart = NULL; - ptrEnd = NULL; - } - cCurSwitch = _T('P'); - if(!ptrStart) - ptrStart = ptrEnd = Line; - ptrEnd = Line; + freep(*params); + return FALSE; + } + + cmd_free(temp); + continue; } } else @@ -564,26 +529,6 @@
Line++; } - /* Terminate the parameters */ - if(ptrStart && ptrEnd) - { - temp = cmd_alloc((ptrEnd - ptrStart + 2) * sizeof(TCHAR)); - if(!temp) - return FALSE; - memcpy(temp, ptrStart, (ptrEnd - ptrStart + 1) * sizeof(TCHAR)); - temp[(ptrEnd - ptrStart + 1)] = _T('\0'); - if(!add_entry(entries, params, temp)) - { - cmd_free(temp); - freep(*params); - return FALSE; - } - - cmd_free(temp); - - ptrStart = NULL; - ptrEnd = NULL; - }
/* Calculate the switches with no switch paramater */ if (!(lpFlags->stAttribs.bParSetted)) @@ -597,7 +542,7 @@ lpFlags->stOrderBy.eCriteria[0] = ORDER_NAME; lpFlags->stOrderBy.bCriteriaRev[0] = FALSE; } - if (!(lpFlags->stOrderBy.bParSetted)) + if (!(lpFlags->stTimeField.bParSetted)) lpFlags->stTimeField.eTimeField = TF_MODIFIEDDATE ;
/* Calculate the unsetted switches (the "-" prefixed)*/