Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Cole committed Nov 12, 2023
1 parent 1b5aefb commit be8c69c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 43 deletions.
92 changes: 49 additions & 43 deletions YSI_Core/y_testing/y_testing_entry.inc
Original file line number Diff line number Diff line change
Expand Up @@ -401,49 +401,55 @@ stock
//#define _Q@y0000%0\32; _Q@y0000
//#define _y@Q0000%0\32; _y@Q0000

/*-------------------------------------------------------------------------*//**
* <library>y_testing</library>
* <param name="a">The first string to compare.</param>
* <param name="b">The second string to compare.</param>
* <remarks>
* A wrapper for <c>strcmp</c> that takes a pointer instead of a string.
* </remarks>
*//*------------------------------------------------------------------------**/

native Testing_StrCmp__(const a[], b, bool:ignoreCase = false, length = cellmax) = strcmp;

/*-------------------------------------------------------------------------*//**
* <library>y_testing</library>
* <param name="name">Name of the current test.</param>
* <remarks>
* If <c>JUST_TEST</c> is defined this confirms whether the current test is
* in the list of desired tests.
* </remarks>
*//*------------------------------------------------------------------------**/

static stock bool:Testing_ShouldRun(const name[], ...)
{
new
n = numargs() - 1,
addr,
str;
#emit ADDR.pri __param1_offset
#emit STOR.S.pri addr
while (n--)
{
#emit LREF.S.pri addr
#emit STOR.S.pri str
addr += cellbytes;
if (Testing_StrCmp__(name, str) == 0)
{
return true;
}
}
return false;
}

// Detect multiple parameters and convert them all to strings.
#define Testing_ShouldRun(%0""#%1,%2) Testing_ShouldRun(%0#%1,""#%2)
///*-------------------------------------------------------------------------*//**
// * <library>y_testing</library>
// * <param name="a">The first string to compare.</param>
// * <param name="b">The second string to compare.</param>
// * <remarks>
// * A wrapper for <c>strcmp</c> that takes a pointer instead of a string.
// * </remarks>
// *//*------------------------------------------------------------------------**/
//
//native Testing_StrCmp__(const a[], b, bool:ignoreCase = false, length = cellmax) = strcmp;
//
///*-------------------------------------------------------------------------*//**
// * <library>y_testing</library>
// * <param name="name">Name of the current test.</param>
// * <remarks>
// * If <c>JUST_TEST</c> is defined this confirms whether the current test is
// * in the list of desired tests.
// * </remarks>
// *//*------------------------------------------------------------------------**/
//
//static stock bool:Testing_ShouldRun(const name[], ...)
//{
// new
// n = numargs() - 1,
// addr,
// str;
// #emit ADDR.pri __param1_offset
// #emit STOR.S.pri addr
// while (n--)
// {
// #emit LREF.S.pri addr
// #emit STOR.S.pri str
// addr += cellbytes;
// if (Testing_StrCmp__(name, str) == 0)
// {
// return true;
// }
// }
// return false;
//}
//
//// Detect multiple parameters and convert them all to strings.
//#define Testing_ShouldRun(%0""#%1,%2) Testing_ShouldRun(%0#%1,""#%2)

// Until I work out the macro for `Testing_ShouldRun` to stringise multiple
// arguments, despite them being given in `JUST_TEST`, which is evaluated later
// in the pre-processing step, just alias this to `strcmp` and stick with the
// old method.
#define Testing_ShouldRun(%0,%1) (!strcmp(%0,%1))

/*-------------------------------------------------------------------------*//**
* <library>y_testing</library>
Expand Down
18 changes: 18 additions & 0 deletions YSI_Storage/y_ini/y_ini_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1690,46 +1690,55 @@ INI_ReadFile_cont:

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_yyyy, y_ini:y_ini_reading_nyyy>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_yyy> called: %s, %s", key, value);
@.YSI_g_sCB_issss(YSI_g_sExtra, YSI_g_sFile, YSI_g_sTag, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_yyyn, y_ini:y_ini_reading_nyyn>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_yyn> called: %s, %s", key, value);
@.YSI_g_sCB_isss(YSI_g_sExtra, YSI_g_sTag, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_yyny, y_ini:y_ini_reading_nyny>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_yny> called: %s, %s", key, value);
@.YSI_g_sCB_isss(YSI_g_sExtra, YSI_g_sFile, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_yynn, y_ini:y_ini_reading_nynn>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_ynn> called: %s, %s", key, value);
@.YSI_g_sCB_iss(YSI_g_sExtra, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_ynyy, y_ini:y_ini_reading_nnyy>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_nyy> called: %s, %s", key, value);
@.YSI_g_sCB_ssss(YSI_g_sFile, YSI_g_sTag, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_ynyn, y_ini:y_ini_reading_nnyn>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_nyn> called: %s, %s", key, value);
@.YSI_g_sCB_sss(YSI_g_sTag, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_ynny, y_ini:y_ini_reading_nnny>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_nny> called: %s, %s", key, value);
@.YSI_g_sCB_sss(YSI_g_sFile, key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_reading_ynnn, y_ini:y_ini_reading_nnnn>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_reading_nnn> called: %s, %s", key, value);
@.YSI_g_sCB_ss(key, value);
}

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_writing_slow>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_writing_slow> called: %s, %s", key, value);
// Used when reading. Checks if the key is being overwritten, and if not
// writes it out to the new file.
INI_WriteTag(YSI_g_sCurrentFile, YSI_g_sTag, YSI_g_sFormat);
Expand All @@ -1746,15 +1755,21 @@ static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_writing_sl
// Not deleted.
if (INI_KeyListGetValue(mem))
{
Debug_Print6("INI_HandleEntry<y_ini:y_ini_writing_slow> updated");
INI_KeyListRemove(prev, mem),
INI_KeyListMakeWritable(mem),
fwrite(YSI_g_sCurrentFile, INI_KeyListGetKey(mem)),
// Remove this from the list.
free(mem);
}
else
{
Debug_Print6("INI_HandleEntry<y_ini:y_ini_writing_slow> deleted");
}
}
else
{
Debug_Print6("INI_HandleEntry<y_ini:y_ini_writing_slow> unchanged");
// Write the entry.
fwrite(YSI_g_sCurrentFile, key),
fwrite(YSI_g_sCurrentFile, "="),
Expand All @@ -1765,6 +1780,7 @@ static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_writing_sl

static stock INI_HandleEntry(const key[], const value[]) <y_ini:y_ini_writing_fast>
{
Debug_Print5("INI_HandleEntry<y_ini:y_ini_writing_fast> called: %s, %s", key, value);
// Nothing in the current tag is being overwritten, just dump this
// key/value pair straight to disk with no extra checks.
INI_WriteTag(YSI_g_sCurrentFile, YSI_g_sTag, YSI_g_sFormat);
Expand Down Expand Up @@ -2079,12 +2095,14 @@ static stock INI_Flush_(INI:file)
// You can't delete the no-tag tag.
if (INI_TagListGetEntries(YSI_g_sCurrentTag))
{
Debug_Print5("INI_Flush_: Writing slow");
// Slightly slower, as for every key we need to check if there is a
// new value being written.
state y_ini:y_ini_writing_slow;
}
else
{
Debug_Print5("INI_Flush_: Writing fast");
// Nothing to write, just copy all the existing data.
YSI_g_sCurrentTag = NO_ALLOC;
}
Expand Down
18 changes: 18 additions & 0 deletions YSI_Storage/y_ini/y_ini_tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -951,25 +951,43 @@ public INI_PUB_Inl_(string:name[], string:value[])
fclose(f);
}

printf("a:");
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
{
while (fread(f, str)) printf(str);
fclose(f);
}

new INI:i = INI_Open(MakeYINITestPath("test10.ini"));
INI_SetTag(i, "tag_with_parent");
INI_RemoveEntry(i, "value");
INI_Close(i);

printf("b:");
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
{
while (fread(f, str)) printf(str);
fclose(f);
}

f = fopen(MakeYINITestPath("test10.ini"), io_read);
ASSERT(!!f);
if (f)
{
fread(f, str);
printf("Read file: %s", str);
StripNL(str);
ASSERT_SAME(str, "[tag_with_parent]");
fread(f, str);
printf("Read file: %s", str);
StripNL(str);
ASSERT_SAME(str, "value_four=Some_semi_colons");
fread(f, str);
printf("Read file: %s", str);
StripNL(str);
ASSERT_SAME(str, "value_three=Some\\;semi\\;colons");
fread(f, str);
printf("Read file: %s", str);
StripNL(str);
ASSERT_SAME(str, "");
fclose(f);
Expand Down

0 comments on commit be8c69c

Please sign in to comment.