home *** CD-ROM | disk | FTP | other *** search
- #include "jam.h"
- #include "def.h"
- #include "stdio.h"
- #include "keyname.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
-
- /* Stuff in DOS.C munged to work in BSD like UNIX world...
- * And other UNIX particular functions (but sadly, not all as xwin.c
- * has spawn commands!)
- */
-
- /* Get directory listing from supplied path; this is bad
- * in that it uses ls vs internal scanning and is thus
- * quite stupid about directories, wildcards and the like.
- */
- void GetDiskDirectory(bp, inpath)
- BUFFER *bp;
- char *inpath;
- {
- BOOL found = FALSE;
- char buffer[512 + L_tmpnam + 1];
- char out[L_tmpnam+1];
- int r = FALSE;
- register int i;
- char shortpath[MAXPATH];
- char path[MAXPATH];
- char *wild = "*";
-
- WindowSleepCursor();
-
- /* find param, build cmd line
- */
- strcpy(path, inpath);
- for (i = strlen(path) -1; i >= 0; i--)
- if (path[i] == BDC1)
- {
- i++;
- break;
- }
-
- if (i >= 0)
- {
- strcpy(shortpath, &inpath[i]);
- if (i > 0)
- inpath[i - 1] = '\0';
- }
- else
- shortpath[i] = '\0';
- strcpy(path, inpath);
-
- #if 0
- for (i = 0; i < strlen(shortpath); i++)
- if (shortpath[i] == '*')
- {
- found = TRUE;
- break;
- }
- if (!found)
- strcat(shortpath, wild);
- #endif
-
- tmpnam(out);
- sprintf(buffer, "cd %s && ls -C %s > %s", path, shortpath, out);
- r = system(buffer);
- if (r == 127)
- {
- ewprintf("exec error");
- ttbeep();
- return;
- }
-
- if (ffropen(out) == FIOSUC)
- {
- char line[NLINE];
- int nbytes;
-
- while (ffgetline(line, NLINE, &nbytes) == FIOSUC)
- {
- line[nbytes] = '\0';
- addline(bp, line);
- }
- ffclose();
- }
- else
- ewprintf("I/O error creating list");
-
- /* cleanup
- */
- unlink(out);
- WindowNormalCursor();
- }
- BOOL fileisrdonly(s)
- char *s;
- {
- BOOL result = FALSE;
- struct stat statbuf;
- static int uid = -1, gid;
-
- if (uid == -1)
- {
- uid = getuid();
- gid = getgid();
- }
-
- if (!stat(s, &statbuf))
- {
- if (uid == statbuf.st_uid) /* own files */
- {
- result = (statbuf.st_mode & S_IWRITE) == 0;
- }
- else if (gid = statbuf.st_gid)
- {
- result = (statbuf.st_mode & S_IWGRP) == 0;
- }
- else
- {
- result = (statbuf.st_mode & S_IWOTH) == 0;
- }
- }
-
- return (result);
- }
-
- /* mail hackery
- */
- int sysmail(f, n)
- int f,n;
- {
- char *mm;
- static char mailer[L_tmpnam + 1] = {0};
- static char user[NBUFN + 1] = {0};
- char mailfilename[L_tmpnam + 2];
- char bufn[NBUFN], cmd[L_tmpnam * 3];
- int s;
- BUFFER *bp;
-
- if (!mailer[0])
- {
- mm = (char *)getenv("XNOTMAILER");
- if (!mm || !(*mm))
- {
- epreload("mailx");
- s = eread("Environment variable XNOTMAILER not set, use: ",
- mailer, L_tmpnam, EFNEW);
- if (s != TRUE)
- return(s);
- }
- else
- strcpy(mailer, mm);
- }
-
- tmpnam(mailfilename);
- s = eread("Mail buffer: %s", bufn, NBUFN, EFNEW|EFBUF, curbp->b_bname);
-
- if (s == FALSE)
- strcpy(bufn, curbp->b_bname);
- else if (s == ABORT)
- return (FALSE);
-
- if ((bp = bfind(bufn, FALSE)) == NULL)
- {
- ttbeep();
- ewprintf(nosuchbuffer);
- return FALSE;
- }
-
- epreload(user);
- s = eread("To: ", user, NBUFN, EFNEW);
- if (s != TRUE)
- return(FALSE);
-
- /* Yes, I realize 'mailx' might not be everywhere....and that it
- * is rude to have these system commands here as well as xwin.c, etc...
- */
- if (!writeout(bp, mailfilename))
- {
- ewprintf("Error writting file.");
- return(FALSE);
- }
- ewprintf("Sending buffer...");
- sprintf(cmd, "cat %s | %s %s", mailfilename, mailer, user);
- system(cmd);
- unlink(mailfilename);
- ewprintf("Buffer '%s' sent to '%s'", bufn, user);
- return (TRUE);
- }
-
- void anynewmail()
- {
- static char *mailpath = NULL;
- static char mailfile[NFILEN] = {0};
-
- if (!mailfile[0])
- {
- mailpath = (char *)getenv("MAIL");
-
- if (mailpath && *mailpath)
- strcpy(mailfile, mailpath);
- else
- {
- strcpy(mailfile, "/usr/mail/");
- strcat(mailfile, getenv("USER"));
- }
- }
-
- if (mailfile[0])
- {
- struct stat statbuf;
- static time_t lasttime = 0;
- static off_t lastsize = -1;
- BOOL oldsomemail = somemail;
-
- if (!stat(mailfile, &statbuf))
- {
- if ((lasttime =! 0) && (difftime(lasttime, statbuf.st_mtime)))
- {
- if ((statbuf.st_size != 0) && (lastsize != statbuf.st_size))
- if (!oldsomemail)
- {
- ttbeep();
- ttbeep();
- }
- }
- lasttime = statbuf.st_mtime;
- lastsize = statbuf.st_size;
- somemail = (statbuf.st_size == 0) ? FALSE : TRUE;
- if (oldsomemail != somemail)
- if (!eprompting)
- noop(); /* force update */
- }
- }
- }