Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/sh.file.c view on Meta::CPAN
}
else {
tchars.t_brkc = -1;
(void) ioctl(SHIN, TIOCSETC, (ioctl_t) & tchars);
}
#endif /* TERMIO */
}
/*
* Move back to beginning of current line
*/
static void
back_to_col_1()
{
#ifdef TERMIO
# ifdef POSIX
struct termios tty, tty_normal;
# else
struct termio tty, tty_normal;
# endif /* POSIX */
#else
struct sgttyb tty, tty_normal;
#endif /* TERMIO */
# ifdef BSDSIGS
sigmask_t omask = sigblock(sigmask(SIGINT));
# else
(void) sighold(SIGINT);
# endif /* BSDSIGS */
#ifdef TERMIO
# ifdef POSIX
(void) tcgetattr(SHOUT, &tty);
# else
(void) ioctl(SHOUT, TCGETA, (ioctl_t) &tty_normal);
# endif /* POSIX */
tty_normal = tty;
tty.c_iflag &= ~INLCR;
tty.c_oflag &= ~ONLCR;
# ifdef POSIX
(void) tcsetattr(SHOUT, TCSANOW, &tty);
# else
(void) ioctl(SHOUT, TCSETAW, (ioctl_t) &tty);
# endif /* POSIX */
(void) write(SHOUT, "\r", 1);
# ifdef POSIX
(void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
# else
(void) ioctl(SHOUT, TCSETAW, (ioctl_t) &tty_normal);
# endif /* POSIX */
#else
(void) ioctl(SHIN, TIOCGETP, (ioctl_t) & tty);
tty_normal = tty;
tty.sg_flags &= ~CRMOD;
(void) ioctl(SHIN, TIOCSETN, (ioctl_t) & tty);
(void) write(SHOUT, "\r", 1);
(void) ioctl(SHIN, TIOCSETN, (ioctl_t) & tty_normal);
#endif /* TERMIO */
# ifdef BSDSIGS
(void) sigsetmask(omask);
# else
(void) sigrelse(SIGINT);
# endif /* BSDISGS */
}
/*
* Push string contents back into tty queue
*/
static void
pushback(string)
Char *string;
{
register Char *p;
char c;
#ifdef TERMIO
# ifdef POSIX
struct termios tty, tty_normal;
# else
struct termio tty, tty_normal;
# endif /* POSIX */
#else
struct sgttyb tty, tty_normal;
#endif /* TERMIO */
#ifdef BSDSIGS
sigmask_t omask = sigblock(sigmask(SIGINT));
#else
(void) sighold(SIGINT);
#endif /* BSDSIGS */
#ifdef TERMIO
# ifdef POSIX
(void) tcgetattr(SHOUT, &tty);
# else
(void) ioctl(SHOUT, TCSETAW, (ioctl_t) &tty);
# endif /* POSIX */
tty_normal = tty;
tty.c_lflag &= ~(ECHOKE | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOCTL);
# ifdef POSIX
(void) tcsetattr(SHOUT, TCSANOW, &tty);
# else
(void) ioctl(SHOUT, TCSETAW, (ioctl_t) &tty);
# endif /* POSIX */
for (p = string; c = *p; p++)
(void) ioctl(SHOUT, TIOCSTI, (ioctl_t) & c);
# ifdef POSIX
(void) tcsetattr(SHOUT, TCSANOW, &tty_normal);
# else
(void) ioctl(SHOUT, TCSETAW, (ioctl_t) &tty_normal);
# endif /* POSIX */
(void) sigsetmask(omask);
#else
(void) ioctl(SHOUT, TIOCGETP, (ioctl_t) & tty);
tty_normal = tty;
tty.sg_flags &= ~ECHO;
(void) ioctl(SHOUT, TIOCSETN, (ioctl_t) & tty);
for (p = string; c = *p; p++)
(void) ioctl(SHOUT, TIOCSTI, (ioctl_t) & c);
(void) ioctl(SHOUT, TIOCSETN, (ioctl_t) & tty_normal);
#endif /* TERMIO */
# ifdef BSDSIGS
(void) sigsetmask(omask);
# else
(void) sigrelse(SIGINT);
# endif /* BSDISGS */
}
/*
* Concatenate src onto tail of des.
* Des is a string whose maximum length is count.
* Always null terminate.
*/
static void
catn(des, src, count)
register Char *des, *src;
register count;
{
while (--count >= 0 && *des)
des++;
while (--count >= 0)
if ((*des++ = *src++) == 0)
return;
*des = '\0';
}
/*
* Like strncpy but always leave room for trailing \0
* and always null terminate.
*/
static void
copyn(des, src, count)
register Char *des, *src;
register count;
{
while (--count >= 0)
if ((*des++ = *src++) == 0)
return;
*des = '\0';
}
static Char
filetype(dir, file)
Char *dir, *file;
{
Char path[MAXPATHLEN];
struct stat statb;
catn(Strcpy(path, dir), file, sizeof(path) / sizeof(Char));
if (lstat(short2str(path), &statb) == 0) {
switch (statb.st_mode & S_IFMT) {
case S_IFDIR:
return ('/');
case S_IFLNK:
if (stat(short2str(path), &statb) == 0 && /* follow it out */
S_ISDIR(statb.st_mode))
return ('>');
else
return ('@');
case S_IFSOCK:
return ('=');
exercises/compile-tcsh/tcsh-6.10.00/sh.file.c view on Meta::CPAN
extract_dir_and_name(path, dir, name)
Char *path, *dir, *name;
{
register Char *p;
p = Strrchr(path, '/');
if (p == NULL) {
copyn(name, path, MAXNAMLEN);
dir[0] = '\0';
}
else {
copyn(name, ++p, MAXNAMLEN);
copyn(dir, path, p - path);
}
}
/* atp vmsposix - I need to remove all the setpwent
* getpwent endpwent stuff. VMS_POSIX has getpwnam getpwuid
* and getlogin. This needs fixing. (There is no access to
* pw->passwd in VMS - a secure system benefit :-| )
*/
static Char *
getitem(dir_fd, looking_for_lognames)
DIR *dir_fd;
int looking_for_lognames;
{
register struct passwd *pw;
register struct dirent *dirp;
if (looking_for_lognames) {
#ifdef _VMS_POSIX
return (NULL);
#else
if ((pw = getpwent()) == NULL)
return (NULL);
return (str2short(pw->pw_name));
#endif /* atp vmsposix */
}
if (dirp = readdir(dir_fd))
return (str2short(dirp->d_name));
return (NULL);
}
static void
free_items(items)
register Char **items;
{
register int i;
for (i = 0; items[i]; i++)
xfree((ptr_t) items[i]);
xfree((ptr_t) items);
}
#ifdef BSDSIGS
# define FREE_ITEMS(items) { \
sigmask_t omask;\
\
omask = sigblock(sigmask(SIGINT));\
free_items(items);\
items = NULL;\
(void) sigsetmask(omask);\
}
#else
# define FREE_ITEMS(items) { \
(void) sighold(SIGINT);\
free_items(items);\
items = NULL;\
(void) sigrelse(SIGINT);\
}
#endif /* BSDSIGS */
/*
* Perform a RECOGNIZE or LIST command on string "word".
*/
static int
tsearch(word, command, max_word_length)
Char *word;
int max_word_length;
COMMAND command;
{
static Char **items = NULL;
register DIR *dir_fd;
register numitems = 0, ignoring = TRUE, nignored = 0;
register name_length, looking_for_lognames;
Char tilded_dir[MAXPATHLEN + 1], dir[MAXPATHLEN + 1];
Char name[MAXNAMLEN + 1], extended_name[MAXNAMLEN + 1];
Char *item;
#define MAXITEMS 1024
if (items != NULL)
FREE_ITEMS(items);
looking_for_lognames = (*word == '~') && (Strchr(word, '/') == NULL);
if (looking_for_lognames) {
#ifndef _VMS_POSIX
(void) setpwent();
#endif /*atp vmsposix */
copyn(name, &word[1], MAXNAMLEN); /* name sans ~ */
dir_fd = NULL;
}
else {
extract_dir_and_name(word, dir, name);
if (tilde(tilded_dir, dir) == 0)
return (0);
dir_fd = opendir(*tilded_dir ? short2str(tilded_dir) : ".");
if (dir_fd == NULL)
return (0);
}
again: /* search for matches */
name_length = Strlen(name);
for (numitems = 0; item = getitem(dir_fd, looking_for_lognames);) {
if (!is_prefix(name, item))
continue;
/* Don't match . files on null prefix match */
if (name_length == 0 && item[0] == '.' &&
!looking_for_lognames)
continue;
if (command == LIST) {
if (numitems >= MAXITEMS) {
( run in 0.718 second using v1.01-cache-2.11-cpan-b16cb0d3907 )