-
-
Save kevin-dong-nai-jia/834e3d16c3c7f0f8496ef23945dbf7ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include "src/list/extd-ccdll.h" | |
int main(int argc, char **argv) | |
{ | |
int argi; | |
if ((argc != 3) || | |
((argi = atoi(argv[2])) < 0)) | |
exit(EXIT_FAILURE); | |
FILE *fptr; | |
char *name = argv[1]; | |
if (!(fptr = fopen(name, "rt"))) | |
fprintf(stderr, "argv[1]: no such file\n"); | |
else | |
{ | |
char *line; | |
ssize_t byte; | |
size_t zero = 0; | |
ccdll(char*) list; | |
ccdll_init(list); | |
while ((line = NULL, | |
byte = getline(&line, &zero, fptr)) != -1) | |
ccdll_push_back(list, line); | |
free (line); | |
fclose(fptr); | |
#define SCMP_CCDLL_PREFETCH(a, b) \ | |
(strncmp(SREF_NEXT(a), SREF_NEXT(b), argi) <= 0) | |
ccdll_sort_prefetch_extd(list, SCMP_CCDLL_PREFETCH); | |
CCDLL_INCR_EXTD(line, list, free(*line)) | |
printf("%s", *line); | |
ccdll_free(list); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment