mirror of
https://github.com/git/git.git
synced 2024-11-30 21:44:02 +08:00
84d32bf767
Sparse issues 68 errors (two errors for each main() function) such as the following: SP git.c git.c:510:5: error: too many arguments for function mingw_main git.c:510:5: error: symbol 'mingw_main' redeclared with different type \ (originally declared at git.c:510) - different argument counts The errors are caused by the 'main' macro used by the MinGW build to provide a replacement main() function. The original main function is effectively renamed to 'mingw_main' and is called from the new main function. The replacement main is used to execute certain actions common to all git programs on MinGW (e.g. ensure the standard I/O streams are in binary mode). In order to suppress the errors, we change the macro to include the parameters in the declaration of the mingw_main function. Unfortunately, this change provokes both sparse and gcc to complain about 9 calls to mingw_main(), such as the following: CC git.o git.c: In function 'main': git.c:510: warning: passing argument 2 of 'mingw_main' from \ incompatible pointer type git.c:510: note: expected 'const char **' but argument is of \ type 'char **' In order to suppress these warnings, since both of the main functions need to be declared with the same prototype, we change the declaration of the 9 main functions, thus: int main(int argc, char **argv) Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
53 lines
924 B
C
53 lines
924 B
C
#include "cache.h"
|
|
#include "mergesort.h"
|
|
|
|
struct line {
|
|
char *text;
|
|
struct line *next;
|
|
};
|
|
|
|
static void *get_next(const void *a)
|
|
{
|
|
return ((const struct line *)a)->next;
|
|
}
|
|
|
|
static void set_next(void *a, void *b)
|
|
{
|
|
((struct line *)a)->next = b;
|
|
}
|
|
|
|
static int compare_strings(const void *a, const void *b)
|
|
{
|
|
const struct line *x = a, *y = b;
|
|
return strcmp(x->text, y->text);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct line *line, *p = NULL, *lines = NULL;
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
for (;;) {
|
|
if (strbuf_getwholeline(&sb, stdin, '\n'))
|
|
break;
|
|
line = xmalloc(sizeof(struct line));
|
|
line->text = strbuf_detach(&sb, NULL);
|
|
if (p) {
|
|
line->next = p->next;
|
|
p->next = line;
|
|
} else {
|
|
line->next = NULL;
|
|
lines = line;
|
|
}
|
|
p = line;
|
|
}
|
|
|
|
lines = llist_mergesort(lines, get_next, set_next, compare_strings);
|
|
|
|
while (lines) {
|
|
printf("%s", lines->text);
|
|
lines = lines->next;
|
|
}
|
|
return 0;
|
|
}
|