Skip to content

Commit

Permalink
Indent to spaces
Browse files Browse the repository at this point in the history
for %i in (*.c *.h) do expand --tabs=4 %i >..\new\%i
  • Loading branch information
lifenjoiner committed Jun 21, 2022
1 parent c8f4667 commit 3859418
Show file tree
Hide file tree
Showing 58 changed files with 5,009 additions and 5,009 deletions.
350 changes: 175 additions & 175 deletions addresslist.c

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions addresslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

typedef struct _AddressList {

/* An array of `Address_Type' */
Array AddressList;
/* An array of `Address_Type' */
Array AddressList;

/* The `Counter' is used by `AddressList_Advance' and `AddressList_GetOne',
* see them.
*/
uint32_t Counter;
/* The `Counter' is used by `AddressList_Advance' and `AddressList_GetOne',
* see them.
*/
uint32_t Counter;

} AddressList;

Expand All @@ -30,8 +30,8 @@ int AddressList_Init(__in AddressList *a);
* 0 on success, a non-zero value otherwise.
*/

int AddressList_Add(__in AddressList *a,
__in Address_Type *Addr);
int AddressList_Add(__in AddressList *a,
__in Address_Type *Addr);
/* Description:
* Add an address in the form of `Address_Type' to an AddressList.
* Parameters:
Expand All @@ -47,10 +47,10 @@ sa_family_t AddressList_ConvertFromString(__out Address_Type *Out,
__in int DefaultPort
);

int AddressList_Add_From_String(__in AddressList *a,
__in const char *Addr_Port,
__in int DefaultPort
);
int AddressList_Add_From_String(__in AddressList *a,
__in const char *Addr_Port,
__in int DefaultPort
);
/* Description:
* Add an address in text to an AddressList.
* Parameters:
Expand All @@ -74,12 +74,12 @@ int AddressList_Advance(__in AddressList *a);
* The a->Counter before it increased.
*/

struct sockaddr *AddressList_GetOneBySubscript(__in AddressList *a,
__out_opt sa_family_t *family,
__in int Subscript);
struct sockaddr *AddressList_GetOneBySubscript(__in AddressList *a,
__out_opt sa_family_t *family,
__in int Subscript);

struct sockaddr *AddressList_GetOne(__in AddressList *a,
__out_opt sa_family_t *family);
struct sockaddr *AddressList_GetOne(__in AddressList *a,
__out_opt sa_family_t *family);
/* Description:
* Fetch an address from an AddressList. See the implementation for details.
* Parameters:
Expand All @@ -90,13 +90,13 @@ struct sockaddr *AddressList_GetOne(__in AddressList *a,
* The pointer to the fetched address.
*/

#define AddressList_GetNumberOfAddresses(a_ptr) ( Array_GetUsed(&((a_ptr)->AddressList)) )
#define AddressList_GetNumberOfAddresses(a_ptr) ( Array_GetUsed(&((a_ptr)->AddressList)) )

/* You should free the return value and *families when they are no longer needed. */
struct sockaddr **AddressList_GetPtrListOfFamily(AddressList *a, sa_family_t family);
struct sockaddr **AddressList_GetPtrList(AddressList *a, sa_family_t **families);

#define AddressList_Free(a_ptr) (Array_Free(&((a_ptr)->AddressList)))
#define AddressList_Free(a_ptr) (Array_Free(&((a_ptr)->AddressList)))
/* Description:
* Free an initialized AddressList.
* Return value:
Expand Down
212 changes: 106 additions & 106 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
/* if it grows down, the InitialCount will be ignored. Otherwise, TheFirstAddress will be ignored. */
int Array_Init(__in Array *a, __in int DataLength, __in int InitialCount, __in BOOL GrowsDown, __in void *TheFirstAddress /* The first means the biggest address*/)
{
if( InitialCount < 0)
return 1;

a->DataLength = DataLength;
a->Used = 0;

if( GrowsDown == FALSE )
{
if( InitialCount > 0 )
{
a->Data = SafeMalloc(DataLength * InitialCount);
if( a->Data == NULL )
return 2;

memset(a->Data, 0, DataLength * InitialCount);
} else {
a->Data = NULL;
}

a->Allocated = InitialCount;
} else {
a->Allocated = -1;
a->Data = TheFirstAddress;
}

return 0;
if( InitialCount < 0)
return 1;

a->DataLength = DataLength;
a->Used = 0;

if( GrowsDown == FALSE )
{
if( InitialCount > 0 )
{
a->Data = SafeMalloc(DataLength * InitialCount);
if( a->Data == NULL )
return 2;

memset(a->Data, 0, DataLength * InitialCount);
} else {
a->Data = NULL;
}

a->Allocated = InitialCount;
} else {
a->Allocated = -1;
a->Data = TheFirstAddress;
}

return 0;
}

/* Subscripts are always non-negative. */
void *Array_GetBySubscript(__in const Array *a, __in int Subscript)
{
if( Subscript >= 0 && Subscript < a->Used )
{
if( a->Allocated < 0 )
{
Subscript *= (-1);
}

return (void *)((a->Data) + (a->DataLength) * Subscript);
} else {
return NULL;
}
if( Subscript >= 0 && Subscript < a->Used )
{
if( a->Allocated < 0 )
{
Subscript *= (-1);
}

return (void *)((a->Data) + (a->DataLength) * Subscript);
} else {
return NULL;
}
}

void *Array_GetThis(__in Array *a, __in const void *Position)
Expand Down Expand Up @@ -88,95 +88,95 @@ void *Array_GetNext(__in Array *a, __in const void *Position)
/* Subscript returned */
int Array_PushBack(__in Array *a, __in_opt const void *Data, __in_opt void *Boundary /* Only used by grow down array */)
{
if( a->Allocated >= 0 )
{
if( a->Used == a->Allocated )
{
int NewCount = (a->Allocated) < 2 ? 2 : (a->Allocated) + (a->Allocated) / 2;

if( SafeRealloc((void **)&(a->Data), NewCount * (a->DataLength)) != 0 )
{
return -1;
}

a->Allocated = NewCount;
}

if( Data != NULL )
memcpy((a->Data) + (a->DataLength) * (a->Used), Data, a->DataLength);

return (a->Used)++;

} else {
if( Boundary != NULL && ((a->Data) + (-1) * (a->DataLength) * (a->Used)) < (char *)Boundary )
{
return -1;
} else {
if( Data != NULL )
{
memcpy((a->Data) + (-1) * (a->DataLength) * (a->Used), Data, a->DataLength);
}
return (a->Used)++;
}
}
if( a->Allocated >= 0 )
{
if( a->Used == a->Allocated )
{
int NewCount = (a->Allocated) < 2 ? 2 : (a->Allocated) + (a->Allocated) / 2;

if( SafeRealloc((void **)&(a->Data), NewCount * (a->DataLength)) != 0 )
{
return -1;
}

a->Allocated = NewCount;
}

if( Data != NULL )
memcpy((a->Data) + (a->DataLength) * (a->Used), Data, a->DataLength);

return (a->Used)++;

} else {
if( Boundary != NULL && ((a->Data) + (-1) * (a->DataLength) * (a->Used)) < (char *)Boundary )
{
return -1;
} else {
if( Data != NULL )
{
memcpy((a->Data) + (-1) * (a->DataLength) * (a->Used), Data, a->DataLength);
}
return (a->Used)++;
}
}
}

void *Array_SetToSubscript(Array *a, int Subscript, const void *Data)
{
if( a->Allocated >= 0 )
{
if( Subscript >= a->Allocated )
{
if( SafeRealloc((void **)&(a->Data), (Subscript + 1) * (a->DataLength)) != 0 )
return NULL;
if( a->Allocated >= 0 )
{
if( Subscript >= a->Allocated )
{
if( SafeRealloc((void **)&(a->Data), (Subscript + 1) * (a->DataLength)) != 0 )
return NULL;

a->Allocated = Subscript + 1;
}
a->Allocated = Subscript + 1;
}

memcpy((a->Data) + (a->DataLength) * Subscript, Data, a->DataLength);
memcpy((a->Data) + (a->DataLength) * Subscript, Data, a->DataLength);

if( a->Used < Subscript + 1 )
a->Used = Subscript + 1;
if( a->Used < Subscript + 1 )
a->Used = Subscript + 1;

return (a->Data) + (a->DataLength) * Subscript;
} else {
if( a->Used < Subscript + 1 )
{
a->Used = Subscript + 1;
}
return (a->Data) + (a->DataLength) * Subscript;
} else {
if( a->Used < Subscript + 1 )
{
a->Used = Subscript + 1;
}

memcpy((a->Data) + (-1) * (a->DataLength) * Subscript, Data, a->DataLength);
memcpy((a->Data) + (-1) * (a->DataLength) * Subscript, Data, a->DataLength);

return (a->Data) + (-1) * (a->DataLength) * Subscript;
}
return (a->Data) + (-1) * (a->DataLength) * Subscript;
}
}

void Array_Sort(Array *a, int (*Compare)(const void *, const void *))
{
if( a->Allocated < 0 )
{
qsort(a->Data - (a->Used * a->DataLength), a->Used, a->DataLength, Compare);
} else {
qsort(a->Data, a->Used, a->DataLength, Compare);
}
if( a->Allocated < 0 )
{
qsort(a->Data - (a->Used * a->DataLength), a->Used, a->DataLength, Compare);
} else {
qsort(a->Data, a->Used, a->DataLength, Compare);
}
}

void Array_Fill(Array *a, int Num, const void *DataSample)
{
int i;
for( i = 0; i < Num; ++i )
{
Array_SetToSubscript(a, i, DataSample);
}
int i;
for( i = 0; i < Num; ++i )
{
Array_SetToSubscript(a, i, DataSample);
}
}

void Array_Free(Array *a)
{
if( a->Allocated >= 0 )
{
SafeFree(a->Data);
}
a->Data = NULL;
a->Used = 0;
a->Allocated = 0;
if( a->Allocated >= 0 )
{
SafeFree(a->Data);
}
a->Data = NULL;
a->Used = 0;
a->Allocated = 0;
}
Loading

0 comments on commit 3859418

Please sign in to comment.