use "slightly" more paranoid compilation flags to avoid more errors.
The makefile may need some tweaks to detect if $(CC) is gcc and if it's a
recent enough version.
fix compilation warnings:
* missing static
* #if 0 an unused function
* add missing const.
* add missing casts.
use <getopt.h> rather than custom definitions.
Makefile | 2 -
mbox-helper.c | 83 +++++++++++++++++++++++++---------------------------------
2 files changed, 38 insertions(+), 47 deletions(-)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@210
9869982d-c50d-0410-be91-
f2a2ec7c7c7b
+CFLAGS=-O2 -g -fstrict-aliasing -Wall -Wextra -Werror -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wsign-compare -Wunused -Wno-unused-parameter -Wuninitialized -Winit-self -Wpointer-arith -Wredundant-decls -Wformat-nonliteral -Wno-format-zero-length -Wno-format-y2k -Wmissing-format-attribute -Wbad-function-cast -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wdeclaration-after-statement
all: mbox-helper Makefile
all: mbox-helper Makefile
#include <string.h>
#include <ctype.h>
#include <locale.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
+#include <stdbool.h>
+#include <getopt.h>
/** Macros
*/
#define LTRIM(pos) while (isspace(*pos)) { pos++; }
#define STRTOLOWER(str, ptr) for (ptr = str ; *ptr ; ptr++) { *ptr = tolower(*ptr); }
/** Macros
*/
#define LTRIM(pos) while (isspace(*pos)) { pos++; }
#define STRTOLOWER(str, ptr) for (ptr = str ; *ptr ; ptr++) { *ptr = tolower(*ptr); }
-/** Boolean
- */
-typedef char bool;
-#define TRUE ((bool)(-1))
-#define FALSE ((bool)(0))
-
/** MBox pointer
*/
typedef struct
/** MBox pointer
*/
typedef struct
-MBox *openMBox(char *filename)
+static MBox *openMBox(char *filename)
mbox->messageId = 0;
mbox->messageBeginning = 0;
mbox->line = NULL;
mbox->messageId = 0;
mbox->messageBeginning = 0;
mbox->line = NULL;
return mbox;
}
/** Close a mbox
*/
return mbox;
}
/** Close a mbox
*/
-void closeMBox(MBox *mbox)
+static void closeMBox(MBox *mbox)
/** Read a line in a file
*/
/** Read a line in a file
*/
-char *readLine(MBox *mbox)
+static char *readLine(MBox *mbox)
{
int length;
mbox->lastLine = mbox->currentLine;
mbox->currentLine = ftell(mbox->fp);
{
int length;
mbox->lastLine = mbox->currentLine;
mbox->currentLine = ftell(mbox->fp);
if (!mbox->line) {
mbox->line = (char*)malloc(1001);
if (!mbox->line) {
mbox->line = (char*)malloc(1001);
+#if 0 /* unused right now */
/** Return to the last line
*/
/** Return to the last line
*/
-bool lastLine(MBox *mbox)
+static bool lastLine(MBox *mbox)
{
if (mbox->lastLine != -1) {
fseek(mbox->fp, mbox->lastLine, SEEK_SET);
mbox->lastLine = -1;
readLine(mbox);
{
if (mbox->lastLine != -1) {
fseek(mbox->fp, mbox->lastLine, SEEK_SET);
mbox->lastLine = -1;
readLine(mbox);
-bool readFrom_(MBox *mbox)
+static bool readFrom_(MBox *mbox)
{
if (!mbox->isFrom_) {
readLine(mbox);
}
{
if (!mbox->isFrom_) {
readLine(mbox);
}
- if (!mbox->isFrom_) {
- return FALSE;
- }
- return TRUE;
+ return !!mbox->isFrom_;
-void readMessage(MBox *mbox, bool display)
+static void readMessage(MBox *mbox, bool display)
{
if (!readFrom_(mbox)) {
return;
{
if (!readFrom_(mbox)) {
return;
/** Read the headers of a message
*/
/** Read the headers of a message
*/
-void readHeaders(MBox *mbox, char **headers, int hdrsize)
+static void readHeaders(MBox *mbox, char **headers, int hdrsize)
{
char *current = NULL;
char *pos, *ptr;
{
char *current = NULL;
char *pos, *ptr;
}
size = pos - mbox->line;
for (i = 0 ; i < hdrsize ; i++) {
}
size = pos - mbox->line;
for (i = 0 ; i < hdrsize ; i++) {
- if (strlen(headers[i]) == size && strcasestr(mbox->line, headers[i]) == mbox->line) {
+ if ((int)strlen(headers[i]) == size && strcasestr(mbox->line, headers[i]) == mbox->line) {
current = (char*)malloc(size + 1);
strcpy(current, headers[i]);
current[size] = '\0';
current = (char*)malloc(size + 1);
strcpy(current, headers[i]);
current[size] = '\0';
/** Go back to the beginning of the file
*/
/** Go back to the beginning of the file
*/
-void rewindMBox(MBox *mbox)
+static void rewindMBox(MBox *mbox)
{
fseek(mbox->fp, 0, SEEK_SET);
mbox->messageId = 0;
{
fseek(mbox->fp, 0, SEEK_SET);
mbox->messageId = 0;
/** Go back to the beginning of the message
*/
/** Go back to the beginning of the message
*/
-bool rewindMessage(MBox *mbox)
+static bool rewindMessage(MBox *mbox)
}
fseek(mbox->fp, mbox->messageBeginning, SEEK_SET);
mbox->currentLine = -1;
}
fseek(mbox->fp, mbox->messageBeginning, SEEK_SET);
mbox->currentLine = -1;
/** Move to the given offset
*/
/** Move to the given offset
*/
-bool goToOffset(MBox *mbox, int offset, int index)
+static bool goToOffset(MBox *mbox, int offset, int idx)
{
fseek(mbox->fp, offset, SEEK_SET);
mbox->currentLine = -1;
mbox->lastLine = -1;
mbox->messageBeginning = offset;
{
fseek(mbox->fp, offset, SEEK_SET);
mbox->currentLine = -1;
mbox->lastLine = -1;
mbox->messageBeginning = offset;
- mbox->messageId = index;
readLine(mbox);
if (!mbox->isFrom_) {
readLine(mbox);
if (!mbox->isFrom_) {
}
/** Move to the given message number
*/
}
/** Move to the given message number
*/
-bool goToMessage(MBox *mbox, int index)
+static bool goToMessage(MBox *mbox, int idx)
- if (mbox->messageId > index) {
+ if (mbox->messageId > idx) {
- } else if(mbox->messageId == index) {
+ } else if(mbox->messageId == idx) {
} else if (!mbox->isFrom_) {
while (!feof(mbox->fp) && !mbox->isFrom_) {
readLine(mbox);
}
if (feof(mbox->fp)) {
} else if (!mbox->isFrom_) {
while (!feof(mbox->fp) && !mbox->isFrom_) {
readLine(mbox);
}
if (feof(mbox->fp)) {
- while (mbox->messageId < index && !feof(mbox->fp)) {
- readMessage(mbox, FALSE);
+ while (mbox->messageId < idx && !feof(mbox->fp)) {
+ readMessage(mbox, false);
- if (mbox->messageId == index) {
- return TRUE;
+ if (mbox->messageId == idx) {
+ return true;
}
/** Display the program help
*/
}
/** Display the program help
*/
{
printf("Usage: mbox-helper [action] [options] -f filename [header1 [header2 ...]]\n"
"Actions: only the last action given is applied\n"
{
printf("Usage: mbox-helper [action] [options] -f filename [header1 [header2 ...]]\n"
"Actions: only the last action given is applied\n"
/** Display an error message
* This function display the giver error, then show the program help and exit the program
*/
/** Display an error message
* This function display the giver error, then show the program help and exit the program
*/
-void error(char *message)
+static void error(const char *message)
{
fprintf(stderr, "Invalid parameters: %s\n", message);
help();
{
fprintf(stderr, "Invalid parameters: %s\n", message);
help();
int headerNb = 0;
char *endptr;
MBox *mbox;
int headerNb = 0;
char *endptr;
MBox *mbox;
-
- /* getopt variables */
- extern char *optarg;
- extern int optind, optopt;
while ((c = getopt(argc, argv, ":bcdp:hm:f:")) != -1) {
switch (c) {
while ((c = getopt(argc, argv, ":bcdp:hm:f:")) != -1) {
switch (c) {
break;
}
goToMessage(mbox, fmid);
break;
}
goToMessage(mbox, fmid);
- readMessage(mbox, TRUE);
+ readMessage(mbox, true);
break;
case 'c':
while (!feof(mbox->fp)) {
break;
case 'c':
while (!feof(mbox->fp)) {