mirror of
https://github.com/git/git.git
synced 2024-11-05 16:52:59 +01:00
de61cebde7
* jk/common-main-2.8: mingw: declare main()'s argv as const common-main: call git_setup_gettext() common-main: call restore_sigpipe_to_default() common-main: call sanitize_stdfds() common-main: call git_extract_argv0_path() add an extra level of indirection to main()
52 lines
934 B
C
52 lines
934 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 cmd_main(int argc, const 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;
|
|
}
|