File bcal-gcc15.patch of Package bcal
Index: bcal-2.4/src/bcal.c
===================================================================
--- bcal-2.4.orig/src/bcal.c
+++ bcal-2.4/src/bcal.c
@@ -20,6 +20,7 @@
#include <ctype.h>
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -31,9 +32,6 @@
#include "dslib.h"
#include "log.h"
-#define TRUE 1
-#define FALSE !TRUE
-
#define SECTOR_SIZE 512 /* 0x200 */
#define MAX_HEAD 16 /* 0x10 */
#define MAX_SECTOR 63 /* 0x3f */
@@ -44,7 +42,6 @@
#define MAX_BITS 128
#define ALIGNMENT_MASK_4BIT 0xF
-typedef unsigned char bool;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
@@ -172,8 +169,8 @@ static size_t bstrlcpy(char *dest, const
static bool program_exit(const char *str)
{
if (!strcmp(str, "exit") || !strcmp(str, "quit"))
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
/*
@@ -439,31 +436,31 @@ static bool ischarvalid(char ch, uint ba
{
if (ch == '0' || ch == '1') {
*val = ch - '0';
- return TRUE;
+ return true;
}
} else if (base == 16) {
if (ch >= '0' && ch <= '9') {
*val = ch - '0';
- return TRUE;
+ return true;
}
if (ch >= 'a' && ch <= 'f') {
*val = (ch - 'a') + 10;
- return TRUE;
+ return true;
}
if (ch >= 'A' && ch <= 'F') {
*val = (ch - 'A') + 10;
- return TRUE;
+ return true;
}
} else if (base == 10) {
if (ch >= '0' && ch <= '9') {
*val = ch - '0';
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/*
@@ -1027,32 +1024,32 @@ static bool chs2lba(char *chs, maxuint_t
/* Fail if CHS is omitted */
if (token_no < 3) {
log(ERROR, "CHS missing\n");
- return FALSE;
+ return false;
}
if (!param[3]) {
log(ERROR, "MAX_HEAD = 0\n");
- return FALSE;
+ return false;
}
if (!param[4]) {
log(ERROR, "MAX_SECTOR = 0\n");
- return FALSE;
+ return false;
}
if (!param[2]) {
log(ERROR, "S = 0\n");
- return FALSE;
+ return false;
}
if (param[1] > param[3]) {
log(ERROR, "H > MAX_HEAD\n");
- return FALSE;
+ return false;
}
if (param[2] > param[4]) {
log(ERROR, "S > MAX_SECTOR\n");
- return FALSE;
+ return false;
}
*lba = (maxuint_t)param[3] * param[4] * param[0]; /* MH * MS * C */
@@ -1064,7 +1061,7 @@ static bool chs2lba(char *chs, maxuint_t
printf(" C:%lu H:%lu S:%lu MAX_HEAD:%lu MAX_SECTOR:%lu\n",
param[0], param[1], param[2], param[3], param[4]);
- return TRUE;
+ return true;
}
static bool lba2chs(char *lba, t_chs *p_chs)
@@ -1103,17 +1100,17 @@ static bool lba2chs(char *lba, t_chs *p_
/* Fail if LBA is omitted */
if (!token_no) {
log(ERROR, "LBA missing\n");
- return FALSE;
+ return false;
}
if (!param[1]) {
log(ERROR, "MAX_HEAD = 0\n");
- return FALSE;
+ return false;
}
if (!param[2]) {
log(ERROR, "MAX_SECTOR = 0\n");
- return FALSE;
+ return false;
}
/* L / (MS * MH) */
@@ -1122,14 +1119,14 @@ static bool lba2chs(char *lba, t_chs *p_
p_chs->h = (ulong)((param[0] / param[2]) % param[1]);
if (p_chs->h > MAX_HEAD) {
log(ERROR, "H > MAX_HEAD\n");
- return FALSE;
+ return false;
}
/* (L % MS) + 1 */
p_chs->s = (ulong)((param[0] % param[2]) + 1);
if (p_chs->s > MAX_SECTOR) {
log(ERROR, "S > MAX_SECTOR\n");
- return FALSE;
+ return false;
}
printf("\033[1mLBA2CHS\033[0m\n LBA:%s ",
@@ -1137,7 +1134,7 @@ static bool lba2chs(char *lba, t_chs *p_
printf("MAX_HEAD:%s ", getstr_u128(param[1], uint_buf));
printf("MAX_SECTOR:%s\n", getstr_u128(param[2], uint_buf));
- return TRUE;
+ return true;
}
static void show_basic_sizes()
@@ -1318,7 +1315,7 @@ static int infix2postfix(char *exp, queu
char *token = strtok(exp, " ");
static Data tokenData, ct;
int balanced = 0;
- bool tokenize = TRUE;
+ bool tokenize = true;
tokenData.p[0] = '\0';
tokenData.unit = 0;
@@ -1391,7 +1388,7 @@ static int infix2postfix(char *exp, queu
tokenData.unit = 1;
log(DEBUG, "unit found\n");
} else
- tokenize = FALSE; /* We already toknized here */
+ tokenize = false; /* We already toknized here */
/* Enqueue operands */
log(DEBUG, "tokenData: %s %d\n", tokenData.p, tokenData.unit);
@@ -1403,7 +1400,7 @@ static int infix2postfix(char *exp, queu
if (tokenize)
token = strtok(NULL, " ");
else
- tokenize = TRUE;
+ tokenize = true;
log(DEBUG, "token: %s\n", token);
}
@@ -2062,7 +2059,7 @@ int main(int argc, char **argv)
ulong sectorsz = SECTOR_SIZE;
if (getenv("BCAL_USE_CALC"))
- cfg.calc = TRUE;
+ cfg.calc = true;
opterr = 0;
rl_bind_key('\t', rl_insert);
diff --git a/src/bcal.c b/src/bcal.c
index 57dfb1e..7b3de31 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
+#include <getopt.h>
#include <readline/history.h>
#include <readline/readline.h>
#include "dslib.h"