Esempio n. 1
0
/** Check if directory completion is needed */
static gboolean
check_is_cd (const char *text, int lc_start, input_complete_t flags)
{
    char *p, *q;

    SHOW_C_CTX ("check_is_cd");

    if ((flags & INPUT_COMPLETE_CD) == 0)
        return FALSE;

    /* Skip initial spaces */
    p = (char *) text;
    q = (char *) text + lc_start;
    while (p < q && p[0] != '\0' && str_isspace (p))
        str_next_char (&p);

    /* Check if the command is "cd" and the cursor is after it */
    return (p[0] == 'c' && p[1] == 'd' && str_isspace (p + 2) && p + 2 < q);
}
Esempio n. 2
0
static void
fetch_hosts (const char *filename)
{
    FILE *file = fopen (filename, "r");
    char buffer[256], *name;
    char *lc_start;
    char *bi;

    if (!file)
        return;

    while (fgets (buffer, 255, file) != NULL)
    {
        /* Skip to first character. */
        for (bi = buffer; bi[0] != '\0' && str_isspace (bi); str_next_char (&bi));

        /* Ignore comments... */
        if (bi[0] == '#')
            continue;
        /* Handle $include. */
        if (!strncmp (bi, "$include ", 9))
        {
            char *includefile = bi + 9;
            char *t;

            /* Find start of filename. */
            while (*includefile && whitespace (*includefile))
                includefile++;
            t = includefile;

            /* Find end of filename. */
            while (t[0] != '\0' && !str_isspace (t))
                str_next_char (&t);
            *t = '\0';

            fetch_hosts (includefile);
            continue;
        }

        /* Skip IP #s. */
        while (bi[0] != '\0' && !str_isspace (bi))
            str_next_char (&bi);

        /* Get the host names separated by white space. */
        while (bi[0] != '\0' && bi[0] != '#')
        {
            while (bi[0] != '\0' && str_isspace (bi))
                str_next_char (&bi);
            if (bi[0] == '#')
                continue;
            for (lc_start = bi; bi[0] != '\0' && !str_isspace (bi); str_next_char (&bi));

            if (bi - lc_start == 0)
                continue;

            name = g_strndup (lc_start, bi - lc_start);
            {
                char **host_p;

                if (hosts_p - hosts >= hosts_alloclen)
                {
                    int j;

                    j = hosts_p - hosts;
                    hosts_alloclen += 30;
                    hosts = g_renew (char *, hosts, hosts_alloclen + 1);
                    hosts_p = hosts + j;
                }
                for (host_p = hosts; host_p < hosts_p; host_p++)
                    if (!strcmp (name, *host_p))
                        break;  /* We do not want any duplicates */
                if (host_p == hosts_p)
                {
                    *(hosts_p++) = name;
                    *hosts_p = NULL;
                }
                else
                    g_free (name);
            }
        }
    }