ReactOS 0.4.15-dev-7958-gcd0bb1a
Defragment.cpp File Reference
#include "Defragment.h"
Include dependency graph for Defragment.cpp:

Go to the source code of this file.

Functions

int FitName (wchar_t *destination, const wchar_t *path, const wchar_t *filename, uint32 totalWidth)
 

Function Documentation

◆ FitName()

int FitName ( wchar_t destination,
const wchar_t path,
const wchar_t filename,
uint32  totalWidth 
)

Definition at line 9 of file Defragment.cpp.

10{
11 uint32 pathLen=0;
12 uint32 fnLen=0;
13 uint32 halfTotLen=0;
14 uint32 len4fn=0; /* number of chars remaining for filename after path is applied */
15 uint32 len4path=0; /* number of chars for path before filename is applied */
16 wchar_t fmtStrPath[20]=L"";
17 wchar_t fmtStrFile[20]=L"";
18 wchar_t fmtString[40]=L"";
19
20 /*
21 assert (destination != NULL);
22 assert (path != NULL);
23 assert (filename != NULL);
24 assert (totalWidth != 0);
25 */
26
27 pathLen = wcslen(path);
28 fnLen = wcslen(filename);
29 if (!(totalWidth % 2))
30 halfTotLen=totalWidth / 2;
31 else
32 halfTotLen=(totalWidth-1) / 2; /* -1 because otherwise (halfTotLen*2) ==
33(totalWidth+1) which wouldn't be good */
34
35 /* determine how much width the path and filename each get */
36 if ( (pathLen >= halfTotLen) && (fnLen < halfTotLen) )
37 {
38 len4fn = fnLen;
39 len4path = (totalWidth - len4fn);
40 }
41
42 if ( (pathLen < halfTotLen) && (fnLen < halfTotLen) )
43 {
44 len4fn = fnLen;
45 len4path = pathLen;
46 }
47
48 if ( (pathLen >= halfTotLen) && (fnLen >= halfTotLen) )
49 {
50 len4fn = halfTotLen;
51 len4path = halfTotLen;
52 }
53
54 if ( (pathLen < halfTotLen) && (fnLen >= halfTotLen) )
55 {
56 len4path = pathLen;
57 len4fn = (totalWidth - len4path);
58 }
59 /*
60 if halfTotLen was adjusted above to avoid a rounding error, give the
61 extra wchar_t to the filename
62 */
63 if (halfTotLen < (totalWidth/2)) len4path++;
64
65 if (pathLen > len4path) swprintf (fmtStrPath, L"%%.%ds...\\", len4path-4);
66 else
67 swprintf (fmtStrPath, L"%%s");
68
69 if (fnLen > len4fn) swprintf (fmtStrFile, L"%%.%ds...", len4fn-3);
70 else
71 swprintf (fmtStrFile, L"%%s");
72
73 wcscpy (fmtString, fmtStrPath);
74 wcscat (fmtString, fmtStrFile);
75 /*swprintf (fmtString, L"%s%s", fmtStrPath, fmtStrFile);*/
76 swprintf (destination, fmtString, path,filename);
77
78 return (1);
79}
unsigned int uint32
Definition: types.h:32
#define swprintf
Definition: precomp.h:40
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const char * filename
Definition: ioapi.h:137
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by Defragment::Start().