style(core): for loops stylization

This commit is contained in:
Masahiko AMANO 2023-01-20 15:41:47 +03:00
parent d90570962b
commit 0db444b65c
3 changed files with 9 additions and 18 deletions

View File

@ -65,7 +65,7 @@ int sappyou_load(Sappyou *sappyou) {
temp.holes = calloc(temp.hole_cnt, sizeof(Tanzaku *));
size_t max_string_len = SIZE_MAX;
Tanzaku *current_tanzaku = temp.database;
for (uint64_t i = 0, r = temp.hole_cnt; i < temp.size; i++) {
for (uint64_t i = 0, r = temp.hole_cnt; i < temp.size; i++, current_tanzaku++) {
if (fgetc(temp.file) != 0) {
current_tanzaku->id = i;
if (fread(&current_tanzaku->created_ts, 8, 1, temp.file) != 1 ||
@ -86,7 +86,6 @@ int sappyou_load(Sappyou *sappyou) {
r--;
temp.holes[r] = current_tanzaku;
}
current_tanzaku++;
}
if (fflush(temp.file) == 0) {
sappyou->file = NULL;
@ -111,7 +110,7 @@ int sappyou_save(Sappyou *sappyou) {
return 1;
}
Tanzaku *current_tanzaku = sappyou->database;
for (uint64_t i = 0; i < sappyou->size; i++) {
for (uint64_t i = 0; i < sappyou->size; i++, current_tanzaku++) {
if (current_tanzaku->id != HOLE_ID) {
if (fputc(0xff, sappyou->file) == EOF ||
fwrite(&current_tanzaku->created_ts, 8, 1, sappyou->file) != 1 ||
@ -125,7 +124,6 @@ int sappyou_save(Sappyou *sappyou) {
} else if (fputc(0, sappyou->file) == EOF) {
return 1;
}
current_tanzaku++;
}
return fflush(sappyou->file);
}

View File

@ -64,7 +64,7 @@ int sasahyou_load(Sasahyou *sasahyou) {
temp.holes = calloc(temp.hole_cnt, sizeof(Sasa *));
size_t max_path_len = SIZE_MAX;
Sasa *current_sasa = temp.database;
for (uint64_t i = 0, r = temp.hole_cnt; i < temp.size; i++) {
for (uint64_t i = 0, r = temp.hole_cnt; i < temp.size; i++, current_sasa++) {
if (fgetc(temp.file) != 0) {
current_sasa->id = i;
if (fread(&current_sasa->created_ts, 8, 1, temp.file) != 1 ||
@ -83,7 +83,6 @@ int sasahyou_load(Sasahyou *sasahyou) {
r--;
temp.holes[r] = current_sasa;
}
current_sasa++;
}
if (fflush(temp.file) == 0) {
sasahyou->file = NULL;
@ -108,7 +107,7 @@ int sasahyou_save(Sasahyou *sasahyou) {
return 1;
}
Sasa *current_sasa = sasahyou->database;
for (uint64_t i = 0; i < sasahyou->size; i++) {
for (uint64_t i = 0; i < sasahyou->size; i++, current_sasa++) {
if (current_sasa->id != HOLE_ID) {
if (fputc(0xff, sasahyou->file) == EOF ||
fwrite(&current_sasa->created_ts, 8, 1, sasahyou->file) != 1 ||
@ -119,7 +118,6 @@ int sasahyou_save(Sasahyou *sasahyou) {
} else if (fputc(0, sasahyou->file) == EOF) {
return 1;
}
current_sasa++;
}
return fflush(sasahyou->file);
}

View File

@ -55,7 +55,7 @@ int shoppyou_load(Shoppyou *shoppyou) {
}
temp.database = calloc(temp.size, sizeof(Kazari));
Kazari *current_kazari = temp.database;
for (uint64_t i = 0; i < temp.size; i++) {
for (uint64_t i = 0; i < temp.size; i++, current_kazari++) {
if (fread(&current_kazari->created_ts, 8, 1, temp.file) != 1 ||
fread(&current_kazari->sasa_id, 8, 1, temp.file) != 1 ||
fread(&current_kazari->tanzaku_id, 8, 1, temp.file) != 1) {
@ -63,7 +63,6 @@ int shoppyou_load(Shoppyou *shoppyou) {
shoppyou_free(&temp);
return 1;
}
current_kazari++;
}
if (fflush(temp.file) == 0) {
shoppyou->file = NULL;
@ -90,7 +89,7 @@ int shoppyou_save(Shoppyou *shoppyou) {
return 1;
}
Kazari *current_kazari = shoppyou->database;
for (uint64_t i = 0; i < shoppyou->size; i++) {
for (uint64_t i = 0; i < shoppyou->size; i++, current_kazari++) {
if (shoppyou->database[i].sasa_id != HOLE_ID && shoppyou->database[i].tanzaku_id != HOLE_ID) {
if (fwrite(&current_kazari->created_ts, 8, 1, shoppyou->file) != 1 ||
fwrite(&current_kazari->sasa_id, 8, 1, shoppyou->file) != 1 ||
@ -98,7 +97,6 @@ int shoppyou_save(Shoppyou *shoppyou) {
return 1;
}
}
current_kazari++;
}
return fflush(shoppyou->file);
}
@ -151,7 +149,7 @@ int kazari_rem(Shoppyou *shoppyou, uint64_t sasa_id, uint64_t tanzaku_id) {
return 1;
}
Kazari *current_kazari = shoppyou->database;
for (uint64_t i = 0; i < shoppyou->size; i++) {
for (uint64_t i = 0; i < shoppyou->size; i++, current_kazari++) {
if (current_kazari->sasa_id == sasa_id && current_kazari->tanzaku_id == tanzaku_id) {
current_kazari->sasa_id = HOLE_ID;
current_kazari->tanzaku_id = HOLE_ID;
@ -161,7 +159,6 @@ int kazari_rem(Shoppyou *shoppyou, uint64_t sasa_id, uint64_t tanzaku_id) {
shoppyou->modified_ts = time(NULL);
return 0;
}
current_kazari++;
}
return 1;
}
@ -172,7 +169,7 @@ int kazari_rem_by_sasa(Shoppyou *shoppyou, uint64_t sasa_id) {
}
Kazari *current_kazari = shoppyou->database;
_Bool changed = 0;
for (uint64_t i = 0; i < shoppyou->size; i++) {
for (uint64_t i = 0; i < shoppyou->size; i++, current_kazari++) {
if (current_kazari->sasa_id == sasa_id) {
current_kazari->sasa_id = HOLE_ID;
current_kazari->tanzaku_id = HOLE_ID;
@ -181,7 +178,6 @@ int kazari_rem_by_sasa(Shoppyou *shoppyou, uint64_t sasa_id) {
shoppyou->holes[shoppyou->hole_cnt - 1] = current_kazari;
changed = 1;
}
current_kazari++;
}
if (changed) {
shoppyou->modified_ts = time(NULL);
@ -196,7 +192,7 @@ int kazari_rem_by_tanzaku(Shoppyou *shoppyou, uint64_t tanzaku_id) {
}
Kazari *current_kazari = shoppyou->database;
_Bool changed = 0;
for (uint64_t i = 0; i < shoppyou->size; i++) {
for (uint64_t i = 0; i < shoppyou->size; i++, current_kazari++) {
if (current_kazari->tanzaku_id == tanzaku_id) {
current_kazari->sasa_id = HOLE_ID;
current_kazari->tanzaku_id = HOLE_ID;
@ -205,7 +201,6 @@ int kazari_rem_by_tanzaku(Shoppyou *shoppyou, uint64_t tanzaku_id) {
shoppyou->holes[shoppyou->hole_cnt - 1] = current_kazari;
changed = 1;
}
current_kazari++;
}
if (changed) {
shoppyou->modified_ts = time(NULL);