src/compose/paths.c
static char *
resolve_name(const char *filename, enum resolve_name_direction direction,
             const char *name)
{
    int ret;
    bool ok;
    const char *xlocaledir;
    char path[512];
    FILE *file;
    char *string;
    size_t string_size;
    const char *end;
    const char *s, *left, *right;
    char *match;
    size_t left_len, right_len, name_len;

    xlocaledir = get_xlocaledir_path();

    ret = snprintf(path, sizeof(path), "%s/%s", xlocaledir, filename);
    if (ret < 0 || (size_t) ret >= sizeof(path))
        return false;

    file = fopen(path, "rb");
    if (!file)
        return false;

    ok = map_file(file, &string, &string_size);
    fclose(file);
    if (!ok)
        return false;

    s = string;
    end = string + string_size;
    name_len = strlen(name);
    match = NULL;

    while (s < end) {
        /* Skip spaces. */
        while (s < end && is_space(*s))
            s++;

        /* Skip comments. */
        if (s < end && *s == '#') {
            while (s < end && *s != '\n')
                s++;
            continue;
        }

        /* Get the left value. */
        left = s;
        while (s < end && !is_space(*s) && *s != ':')
            s++;
        left_len = s - left;

        /* There's an optional colon between left and right. */
        if (s < end && *s == ':')
            s++;

        /* Skip spaces. */
        while (s < end && is_space(*s))
            s++;

        /* Get the right value. */
        right = s;
        while (s < end && !is_space(*s))
            s++;
        right_len = s - right;

        /* Discard rest of line. */
        while (s < end && *s != '\n')
            s++;

        if (direction == LEFT_TO_RIGHT) {
            if (left_len == name_len && memcmp(left, name, left_len) == 0) {
                match = strndup(right, right_len);
                break;
            }
        }
        else if (direction == RIGHT_TO_LEFT) {
            if (right_len == name_len && memcmp(right, name, right_len) == 0) {
                match = strndup(left, left_len);
                break;
            }
        }
    }

    unmap_file(string, string_size);
    return match;
}
/*
 * Files like compose.dir have the format LEFT: RIGHT.  Lookup @name in
 * such a file and return its matching value, according to @direction.
 * @filename is relative to the xlocaledir.
 */
Files like compose.dir have the format LEFT: RIGHT.  Lookup @name in
such a file and return its matching value, according to @direction.
@filename is relative to the xlocaledir.
Files like compose . dir have the format LEFT : RIGHT . Lookup @name in such a file and return its matching value according to @direction . @filename is relative to the xlocaledir .
static char *
resolve_name(const char *filename, enum resolve_name_direction direction,
             const char *name)
{
    int ret;
    bool ok;
    const char *xlocaledir;
    char path[512];
    FILE *file;
    char *string;
    size_t string_size;
    const char *end;
    const char *s, *left, *right;
    char *match;
    size_t left_len, right_len, name_len;
    xlocaledir = get_xlocaledir_path();
    ret = snprintf(path, sizeof(path), "%s/%s", xlocaledir, filename);
    if (ret < 0 || (size_t) ret >= sizeof(path))
        return false;
    file = fopen(path, "rb");
    if (!file)
        return false;
    ok = map_file(file, &string, &string_size);
    fclose(file);
    if (!ok)
        return false;
    s = string;
    end = string + string_size;
    name_len = strlen(name);
    match = NULL;
    while (s < end) {
        while (s < end && is_space(*s))
            s++;
        if (s < end && *s == '#') {
            while (s < end && *s != '\n')
                s++;
            continue;
        }
        left = s;
        while (s < end && !is_space(*s) && *s != ':')
            s++;
        left_len = s - left;
        if (s < end && *s == ':')
            s++;
        while (s < end && is_space(*s))
            s++;
        right = s;
        while (s < end && !is_space(*s))
            s++;
        right_len = s - right;
        while (s < end && *s != '\n')
            s++;
        if (direction == LEFT_TO_RIGHT) {
            if (left_len == name_len && memcmp(left, name, left_len) == 0) {
                match = strndup(right, right_len);
                break;
            }
        }
        else if (direction == RIGHT_TO_LEFT) {
            if (right_len == name_len && memcmp(right, name, right_len) == 0) {
                match = strndup(left, left_len);
                break;
            }
        }
    }
    unmap_file(string, string_size);
    return match;
}
static char * resolve_name ( const char * filename , enum resolve_name_direction direction , const char * name ) { int ret ; bool ok ; const char * xlocaledir ; char path [ 512 ] ; FILE * file ; char * string ; size_t string_size ; const char * end ; const char * s , * left , * right ; char * match ; size_t left_len , right_len , name_len ; xlocaledir = get_xlocaledir_path ( ) ; ret = snprintf ( path , sizeof ( path ) , " " , xlocaledir , filename ) ; if ( ret < 0 || ( size_t ) ret >= sizeof ( path ) ) return false ; file = fopen ( path , " " ) ; if ( ! file ) return false ; ok = map_file ( file , & string , & string_size ) ; fclose ( file ) ; if ( ! ok ) return false ; s = string ; end = string + string_size ; name_len = strlen ( name ) ; match = NULL ; while ( s < end ) { while ( s < end && is_space ( * s ) ) s ++ ; if ( s < end && * s == ' ' ) { while ( s < end && * s != ' \n ' ) s ++ ; continue ; } left = s ; while ( s < end && ! is_space ( * s ) && * s != ' ' ) s ++ ; left_len = s - left ; if ( s < end && * s == ' ' ) s ++ ; while ( s < end && is_space ( * s ) ) s ++ ; right = s ; while ( s < end && ! is_space ( * s ) ) s ++ ; right_len = s - right ; while ( s < end && * s != ' \n ' ) s ++ ; if ( direction == LEFT_TO_RIGHT ) { if ( left_len == name_len && memcmp ( left , name , left_len ) == 0 ) { match = strndup ( right , right_len ) ; break ; } } else if ( direction == RIGHT_TO_LEFT ) { if ( right_len == name_len && memcmp ( right , name , right_len ) == 0 ) { match = strndup ( left , left_len ) ; break ; } } } unmap_file ( string , string_size ) ; return match ; }
Files like compose.dir have the format LEFT: RIGHT.
Files like compose . dir have the format LEFT : RIGHT .
/* Skip spaces. */ /* Skip comments. */ /* Get the left value. */ /* There's an optional colon between left and right. */ /* Skip spaces. */ /* Get the right value. */ /* Discard rest of line. */