コード例 #1
0
ファイル: ft_rev_params.c プロジェクト: StevenBR/c-piscine
int		main(int argc, char *argv[])
{
	unsigned int i;

	i = argc;
	while (i > 1)
	{
		put_filename(argv[i - 1]);
		ft_putchar('\n');
		i--;
	}
	return (0);
}
コード例 #2
0
ファイル: make-docfile.c プロジェクト: cpitclaudel/emacs
static void
scan_file (char *filename)
{
  ptrdiff_t len = strlen (filename);

  if (!generate_globals)
    put_filename (filename);
  if (len > 4 && !strcmp (filename + len - 4, ".elc"))
    scan_lisp_file (filename, "rb");
  else if (len > 3 && !strcmp (filename + len - 3, ".el"))
    scan_lisp_file (filename, "r");
  else
    scan_c_file (filename, "r");
}
コード例 #3
0
ファイル: svgancui.c プロジェクト: ApolloniaUK/PUAE
char *tui_filereq(char *s, char *oldfile, const char *title)
{
    char cwd[256];
    char *retval = fsbuf;
    char *tmp;
    int fin = 0;
    chtype moresave[6][2];

    /* Save wd */
    if (getcwd (cwd, 256) == NULL)
	return NULL;

    /* Change into directory of old file */
    strcpy (fsbuf, oldfile);
    tmp = strrchr (fsbuf, '/');
    if (tmp != NULL) {
	*tmp = 0;
	if (strlen (fsbuf) > 0)
	    chdir (fsbuf);
    }

    pattern = s;
    if (s[0] != '*')
	write_log ("Can't handle wildcard %s\n", s);
    if (s[1] != 0 && strchr (s+1, '*') != NULL)
	write_log ("Can't handle wildcard %s\n", s);
    for (;!fin;) {
	struct dirent **names;
	int i, w, n, l, yp, oldyp, s;

	maxlen = 0;
	n = scandir (".", &names, selectfn, my_alphasort);

	if (n <= 0)
	    return NULL;
	if (title != NULL && strlen (title) + 6 > maxlen)
	    maxlen = strlen (title) + 6;
	l = n;
	if (l > 15)
	    l = 15;
	yp = s = 0; oldyp = -1;
	w = tui_dlog (tui_cols () - maxlen - 8, 5, tui_cols () - 5, 5 + l + 1);
	tui_selwin (w); tui_drawbox (w);
	if (title)
	    mvwaddstr (currwin, 0, 2, title);
	for (i = 0; i < 6; i++) {
	    moresave[i][0] = mvwinch (currwin, 0, maxlen-3+i);
	    moresave[i][1] = mvwinch (currwin, l+1, maxlen-3+i);
	}
	for (;;) {
	    int c;
	    char tmp[256];
	    while (s < yp)
		yp--;
	    while (s >= yp + l)
		yp++;
	    if (oldyp != yp) {
		oldyp = yp;
		for (i = 0; i < l; i++) {
		    put_filename (names[i + yp]->d_name, 3, 2 + i, 0);
		}
	    }
	    put_filename (names[s]->d_name, 3, 2 + s - yp, A_STANDOUT);

	    if (yp == 0)
		for (i = 0; i < 6; i++)
		    mvwaddch (currwin, 0, maxlen-3+i, moresave[i][0]);
	    else
		mvwaddstr (currwin, 0, maxlen-3, "(more)");
	    if (yp + l == n)
		for (i = 0; i < 6; i++)
		    mvwaddch (currwin, l+1, maxlen-3+i, moresave[i][1]);
	    else
		mvwaddstr (currwin, l+1, maxlen-3, "(more)");

	    tui_refresh ();
	    c = getch ();
	    put_filename (names[s]->d_name, 3, 2 + s - yp, 0);
	    if (c == 27) {
		retval = NULL; fin = 1;
		break;
	    } else if (c == KEY_ENTER || c == 13 || c == ' ') {
		int err;

		if (strcmp (names[s]->d_name, ".") == 0) {
		    fin = 1;
		    strcpy (fsbuf, "");
		    break;
		}
		err = chdir (names[s]->d_name);

		if (err == 0)
		    break;
		else if (errno == ENOTDIR) {
		    fin = 1;
		    if (getcwd (fsbuf, 256) == NULL)
			retval = NULL;
		    if (strlen (fsbuf) + strlen (names[s]->d_name) + 2 >= 256)
			retval = NULL;
		    else {
			strcat(fsbuf, "/");
			strcat(fsbuf, names[s]->d_name);
		    }
		    break;
		} /* else what? */
	    }
	    switch (c) {
	     case KEY_UP:
		if (s > 0)
		    s--;
		break;
	     case KEY_DOWN:
		if (s + 1 < n)
		    s++;
		break;
	     case KEY_PPAGE:
		if (s > l)
		    s -= l;
		else
		    s = 0;
		break;
	     case KEY_NPAGE:
		if (s + l < n)
		    s += l;
		else
		    s = n - 1;
		break;
	     default:
		i = 0;
		if (names[s]->d_name[0] == c)
		    i = s+1;
		for (; i < n*2; i++) {
		    int j = i;
		    if (i >= n)
			j -= n;
		    if (names[j]->d_name[0] == c) {
			s = j;
			break;
		    }
		}
	    }
	}
#if 0
	/* @@@ is this right? */
	for (i = 0; i < n; i++)
	    free (names[i]);
	free (names);
#endif
	tui_dlogdie (w);
    }
    chdir (cwd);
    return retval;
}