15#if defined (HAVE_IO_H)
19#if defined (HAVE_UNISTD_H)
50#ifdef NON_CONST_PUTENV_PROTOTYPE
53# define PE_CONST const
68static void appendCstringWithQuotes (
vString *dest,
const char* cstr)
74 for (
const char *o = cstr; *o; o++)
85extern void externalSortTags (
const bool toStdout,
MIO *
tagFile)
87 const char *
const sortNormalCommand =
"sort -u";
88 const char *
const sortFoldedCommand =
"sort -u -f";
89 const char *sortCommand =
92 PE_CONST
char *
const sortOrder1 =
"LC_COLLATE=C";
93 PE_CONST
char *
const sortOrder2 =
"LC_ALL=C";
102#if defined (HAVE_SETENV) || defined (HAVE_PUTENV)
104 setenv (
"LC_COLLATE",
"C", 1);
105 setenv (
"LC_ALL",
"C", 1);
126 vStringCats (cmd,
" -o ");
135 const int fdstdin = 0;
138 fdsave = dup (fdstdin);
143 if (lseek (fdstdin, 0, SEEK_SET) != 0)
146 if (dup2 (fdsave, fdstdin) < 0)
168 const char*
const cannotSort =
"cannot sort tag file";
179 const char *
const line1 = *(
const char*
const*) one;
180 const char *
const line2 = *(
const char*
const*) two;
185static int compareTags (
const void *
const one,
const void *
const two)
187 const char *
const line1 = *(
const char*
const*) one;
188 const char *
const line2 = *(
const char*
const*) two;
190 return strcmp (line1, line2);
194 char **
const table,
const size_t numTags,
const bool toStdout,
bool newlineReplaced)
209 for (i = 0 ; i < numTags ; ++i)
214 if (i == 0 ||
Option.
xref || strcmp (table [i], table [i-1]) != 0)
216 if (
mio_puts (mio, table [i]) == EOF)
218 else if (newlineReplaced)
232 int (*cmpFunc)(
const void *,
const void *);
233 bool newlineReplaced =
false;
237 const size_t tableSize = numTags *
sizeof (
char *);
238 char **table = (
char **) malloc (tableSize);
246 for (i = 0 ; i < numTags && !
mio_eof (mio) ; )
255 else if (*
line ==
'\0' || strcmp (
line,
"\n") == 0)
259 const size_t stringSize = strlen (
line) + 1;
261 table [i] = (
char *) malloc (stringSize);
262 if (table [i] ==
NULL)
265 strcpy (table [i],
line);
266 if (table[i][stringSize - 2] ==
'\n')
268 table[i][stringSize - 2] =
'\0';
269 newlineReplaced =
true;
279 qsort (table, numTags,
sizeof (*table), cmpFunc);
283 PrintStatus ((
"sort memory: %ld bytes\n", (
long) mallocSize));
284 for (i = 0 ; i < numTags ; ++i)
#define DebugStatement(x)
const char * tagFileName(void)
void error(const errorSelection selection, const char *const format,...)
MIO * mio_new_fp(FILE *fp, MIOFCloseFunc close_func)
mio_new_fp: @fp: An opened #FILE object @close_func: (allow-none): Function used to close @fp when th...
int mio_getc(MIO *mio)
mio_getc: @mio: A MIO object
MIO * mio_new_file(const char *filename, const char *mode)
mio_new_file: @filename: Filename to open, same as the fopen()'s first argument @mode: Mode in which ...
int mio_seek(MIO *mio, long offset, int whence)
mio_seek: @mio: A MIO object @offset: Offset of the new place, from @whence @whence: Move origin.
int mio_eof(MIO *mio)
mio_eof: @mio: A MIO object
int mio_flush(MIO *mio)
mio_flush: @mio: A MIO object
FILE * mio_file_get_fp(MIO *mio)
mio_file_get_fp: @mio: A MIO object
int mio_puts(MIO *mio, const char *s)
mio_puts: @mio: A MIO object @s: The string to write
int mio_putc(MIO *mio, int c)
mio_putc: @mio: A MIO object : The character to write
int mio_unref(MIO *mio)
mio_unref: @mio: A MIO object
void verbose(const char *const format,...)
char * readLineRaw(vString *const vLine, MIO *const mio)
int struppercmp(const char *s1, const char *s2)
static int compareTags(const void *const one, const void *const two)
static int compareTagsFolded(const void *const one, const void *const two)
void failedSort(MIO *const mio, const char *msg)
static void writeSortedTags(char **const table, const size_t numTags, const bool toStdout, bool newlineReplaced)
void internalSortTags(const bool toStdout, MIO *mio, size_t numTags)
if(!stash_group_load_from_file(group, filename)) g_warning(_("Could not load keyfile %s!")
vString * vStringNew(void)
void vStringDelete(vString *const string)
void vStringCatS(vString *const string, const char *const s)
static void vStringPut(vString *const string, const int c)