mirror of https://github.com/davatorium/rofi.git
Use getdelim instead of custom fgets function.
This commit is contained in:
parent
880f8731be
commit
c7dcb4821a
|
@ -59,27 +59,22 @@ typedef struct _DmenuModePrivateData
|
|||
|
||||
static char **get_dmenu ( unsigned int *length )
|
||||
{
|
||||
const unsigned int buf_size = 1024;
|
||||
char buffer[buf_size];
|
||||
char **retv = NULL;
|
||||
char *buffer_end = NULL;
|
||||
unsigned int rvlength = 1;
|
||||
char **retv = NULL;
|
||||
unsigned int rvlength = 1;
|
||||
|
||||
*length = 0;
|
||||
|
||||
while ( ( buffer_end = fgets_s ( buffer, buf_size, stdin, (char) config.separator ) ) != NULL ) {
|
||||
gchar *data = NULL;
|
||||
size_t data_l = 0;
|
||||
while ( ( getdelim ( &data, &data_l, config.separator, stdin ) > 0 ) ) {
|
||||
if ( rvlength < ( *length + 2 ) ) {
|
||||
rvlength *= 2;
|
||||
retv = g_realloc ( retv, ( rvlength ) * sizeof ( char* ) );
|
||||
}
|
||||
|
||||
size_t blength = buffer_end - &( buffer[0] );
|
||||
|
||||
char *copy = g_malloc0 ( blength + 1 );
|
||||
memcpy ( copy, buffer, blength );
|
||||
|
||||
retv[( *length )] = copy;
|
||||
retv[( *length )] = data; //copy;
|
||||
retv[( *length ) + 1] = NULL;
|
||||
data = NULL;
|
||||
data_l = 0;
|
||||
|
||||
( *length )++;
|
||||
// Stop when we hit 2³¹ entries.
|
||||
|
|
|
@ -55,32 +55,6 @@ void cmd_set_arguments ( int argc, char **argv )
|
|||
stored_argv = argv;
|
||||
}
|
||||
|
||||
/**
|
||||
* `fgets` implementation with custom separator.
|
||||
*/
|
||||
char* fgets_s ( char* s, unsigned int n, FILE *iop, char sep )
|
||||
{
|
||||
// Map these to registers.
|
||||
register int c = EOF;
|
||||
register char* cs;
|
||||
cs = s;
|
||||
// read until EOF or buffer is full.
|
||||
while ( --n > 0 && ( c = getc ( iop ) ) != EOF ) {
|
||||
// put the input char into the current pointer position, then increment it
|
||||
// if a newline entered, break
|
||||
if ( ( *cs++ = c ) == sep ) {
|
||||
// Whipe separator
|
||||
cs[-1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Always, 0 terminate the buffer.
|
||||
*cs = '\0';
|
||||
// if last read was end of file and current index is start, we are done:
|
||||
// Return NULL.
|
||||
return ( c == EOF && cs == s ) ? NULL : cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param info To Match information on.
|
||||
* @param res The string being generated.
|
||||
|
|
|
@ -749,7 +749,7 @@ static void menu_refilter ( MenuState *state )
|
|||
* If number of threads > 1 and there are enough (> 20000) items, spawn threads.
|
||||
* For large lists with 8 threads I see a factor three speedup of the whole function.
|
||||
*/
|
||||
unsigned int nt = MAX( 1, MIN ( state->num_lines / 1000, config.threads ));
|
||||
unsigned int nt = MAX ( 1, MIN ( state->num_lines / 1000, config.threads ) );
|
||||
thread_state states[nt];
|
||||
GThread *threads[nt];
|
||||
unsigned int steps = ( state->num_lines + nt ) / nt;
|
||||
|
|
Loading…
Reference in New Issue