return 0;\r
}\r
\r
-/* Strip CR and replace LF with NULL. */\r
-int unformat_double_null(TCHAR *dn, unsigned long dnlen, TCHAR **unformatted, unsigned long *newlen) {\r
+/* Strip CR and replace LF with NULL. */\r
+int unformat_double_null(TCHAR *formatted, unsigned long formattedlen, TCHAR **dn, unsigned long *newlen) {\r
unsigned long i, j;\r
*newlen = 0;\r
\r
- if (! dnlen) {\r
- *unformatted = 0;\r
+ /* Don't count trailing NULLs. */\r
+ for (i = 0; i < formattedlen; i++) {\r
+ if (! formatted[i]) {\r
+ formattedlen = i;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (! formattedlen) {\r
+ *dn = 0;\r
return 0;\r
}\r
\r
- for (i = 0; i < dnlen; i++) if (dn[i] != _T('\r')) ++*newlen;\r
+ for (i = 0; i < formattedlen; i++) if (formatted[i] != _T('\r')) ++*newlen;\r
\r
/* Skip blank lines. */\r
- for (i = 0; i < dnlen; i++) {\r
- if (dn[i] == _T('\r') && dn[i + 1] == _T('\n')) {\r
+ for (i = 0; i < formattedlen; i++) {\r
+ if (formatted[i] == _T('\r') && formatted[i + 1] == _T('\n')) {\r
/* This is the last CRLF. */\r
- if (i >= dnlen - 2) break;\r
+ if (i >= formattedlen - 2) break;\r
\r
/*\r
Strip at the start of the block or if the next characters are\r
CRLF too.\r
*/\r
- if (! i || (dn[i + 2] == _T('\r') && dn[i + 3] == _T('\n'))) {\r
- for (j = i + 2; j < dnlen; j++) dn[j - 2] = dn[j];\r
- dn[dnlen--] = _T('\0');\r
- dn[dnlen--] = _T('\0');\r
+ if (! i || (formatted[i + 2] == _T('\r') && formatted[i + 3] == _T('\n'))) {\r
+ for (j = i + 2; j < formattedlen; j++) formatted[j - 2] = formatted[j];\r
+ formatted[formattedlen--] = _T('\0');\r
+ formatted[formattedlen--] = _T('\0');\r
i--;\r
--*newlen;\r
}\r
/* Must end with two NULLs. */\r
*newlen += 2;\r
\r
- *unformatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));\r
- if (! *unformatted) return 1;\r
+ *dn = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));\r
+ if (! *dn) return 1;\r
\r
- for (i = 0, j = 0; i < dnlen; i++) {\r
- if (dn[i] == _T('\r')) continue;\r
- if (dn[i] == _T('\n')) (*unformatted)[j] = _T('\0');\r
- else (*unformatted)[j] = dn[i];\r
+ for (i = 0, j = 0; i < formattedlen; i++) {\r
+ if (formatted[i] == _T('\r')) continue;\r
+ if (formatted[i] == _T('\n')) (*dn)[j] = _T('\0');\r
+ else (*dn)[j] = formatted[i];\r
j++;\r
}\r
\r