Esempio n. 1
0
File: utils.c Progetto: MUME/mudlle
static void vlog_message(const char *fname, const char *nname, int line,
                         bool is_warning, const char *msg, va_list va)
{
  strbuf_t sb = SBNULL;

  if (fname != NULL)
    {
      bool use_fname = !use_nicename || nname == NULL;

      sb_printf(&sb, "%s:", use_fname ? fname : nname);
      if (line > 0)
        sb_printf(&sb, "%d:", line);
      sb_addc(&sb, ' ');
    }
  if (is_warning)
    sb_addstr(&sb, "warning: ");
  if (!use_nicename && fname != NULL && nname != NULL
      && strcmp(nname, fname) != 0)
    sb_printf(&sb, "[%s] ", nname);
  sb_vprintf(&sb, msg, va);
  if (mudout) pflush(mudout);
  pprintf(muderr, "%s\n", sb_str(&sb));
  if (muderr) pflush(muderr);
  sb_free(&sb);
  if (!is_warning)
    erred = true;
}
Esempio n. 2
0
static void
demo_panels(InitPanel myInit, FillPanel myFill)
{
    int itmp;
    PANEL *px[MAX_PANELS + 1];
    char buffer[BUFSIZ];

    scrollok(stdscr, FALSE);	/* we don't want stdscr to scroll! */
    refresh();

    myInit();
    memset(px, 0, sizeof(px));

    while (get_command(px, buffer, sizeof(buffer))) {
	int limit = (int) strlen(buffer);
	for (itmp = 0; itmp < limit; itmp += 3) {
	    do_panel(px, buffer + itmp, myFill);
	}
	pflush();
    }
#if NO_LEAKS
    for (itmp = 1; itmp <= MAX_PANELS; ++itmp) {
	my_remove_panel(px, itmp);
    }
#endif
}
Esempio n. 3
0
static void
canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
{
    int which = cmd[1] - '0';

    saywhat(cmd);
    switch (*cmd) {
    case 'h':
	hide_panel(px[which]);
	break;
    case 's':
	show_panel(px[which]);
	break;
    case 't':
	top_panel(px[which]);
	break;
    case 'b':
	bottom_panel(px[which]);
	break;
    case 'd':
	rmpanel(px[which]);
	break;
    }
    pflush();
    wgetch(stdscr);
}
Esempio n. 4
0
void
minclude(			/* include a file */
char  *fname
)
{
    pflush();
    pglob(PINCL, 1, fname);
}
Esempio n. 5
0
void
mopenseg(			/* open a segment */
char  *sname
)
{
    pflush();
    pglob(POPEN, 0, sname);
}
Esempio n. 6
0
void
msetpat(		/* set a pattern */
int  pn,
char  *pat
)
{
    pflush();
    pglob(PSET, pn+4, pat);
}
Esempio n. 7
0
void
mtriangle(	/* fill a triangle */
int  xmin, int ymin, int xmax, int ymax,
int  d, int pat, int color
)
{
    pflush();
    cura0 = (let_dir(d)<<4 & 060) | (pat<<2 & 014) | (color & 03);
    pprim(PTFILL, cura0, xmin, ymin, xmax, ymax, NULL);
}
Esempio n. 8
0
void
mrectangle(	/* fill a rectangle */
int  xmin, int ymin, int xmax, int ymax,
int  pat, int color
)
{
    pflush();
    cura0 = (pat<<2 & 014) | (color & 03);
    pprim(PRFILL, cura0, xmin, ymin, xmax, ymax, NULL);
}
Esempio n. 9
0
void
mvstr(	/* vector string */
int  xmin, int ymin, int xmax, int ymax,
char  *s,
int  d, int thick, int color
)
{
    pflush();
    cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
    pprim(PVSTR, cura0, xmin, ymin, xmax, ymax, s);
}
Esempio n. 10
0
void
msegment(	/* segment */
int  xmin, int ymin, int xmax, int ymax,
char  *sname,
int  d, int thick, int color
)
{
    pflush();
    cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03);
    pprim(PSEG, cura0, xmin, ymin, xmax, ymax, sname);
}
Esempio n. 11
0
void handler(int signum)
{
        pflush();
        fprintf(stderr, "%s %s:%d: %s: signum = %d\n", level[notice], __FILE__, __LINE__, __func__, signum);

        if (signum == SIGINT || signum == SIGTERM || signum == SIGSEGV)
        {
                quit = true;
        }
        return ;
}
Esempio n. 12
0
void
mline(		/* start a line */
int  x, int y,
int  type, int thick, int color
)
{
    pflush();
    cura0 = (type<<4 & 060) | (thick<<2 & 014) | (color & 03);
    curx = x;
    cury = y;
}
Esempio n. 13
0
void
mpoly(		/* start a polygon */
int  x, int y,
int  border, int pat, int color
)
{
    pflush();
    cura0 = (border<<6 & 0100) | (pat<<2 & 014) | (color & 03);
    cap = curargs;
    inpoly = TRUE;
    putdec(x);
    *cap++ = ' ';
    putdec(y);
}
Esempio n. 14
0
static void
do_panel(PANEL * px[MAX_PANELS + 1],
	 NCURSES_CONST char *cmd,
	 FillPanel myFill)
{
    int which = cmd[1] - '0';

    if (which < 1 || which > MAX_PANELS) {
	beep();
	return;
    }

    if (log_in != 0) {
	pflush();
    }

    saywhat(cmd);
    switch (*cmd) {
    case 'b':
	my_bottom_panel(px[which]);
	break;
    case 'c':
	my_create_panel(px, which, myFill);
	break;
    case 'd':
	my_remove_panel(px, which);
	break;
    case 'h':
	my_hide_panel(px[which]);
	break;
    case 'm':
	my_move_panel(px, which, FALSE);
	break;
    case 'M':
	my_move_panel(px, which, TRUE);
	break;
    case 'r':
	my_resize_panel(px, which, myFill);
	break;
    case 's':
	my_show_panel(px[which]);
	break;
    case 't':
	my_top_panel(px[which]);
	break;
    }
}
Esempio n. 15
0
pnote()
{
	register struct process *pp;
	int flags, omask;

	neednote = 0;
	for (pp = proclist.p_next; pp != PNULL; pp = pp->p_next) {
		if (pp->p_flags & PNEEDNOTE) {
			omask = sigblock(sigmask(SIGCHLD));
			pp->p_flags &= ~PNEEDNOTE;
			flags = pprint(pp, NUMBER|NAME|REASON);
			if ((flags&(PRUNNING|PSTOPPED)) == 0)
				pflush(pp);
			(void) sigsetmask(omask);
		}
	}
}
Esempio n. 16
0
static void
my_create_panel(PANEL ** pans, int which, FillPanel myFill)
{
    PANEL *pan = 0;
    int code;
    short pair = (short) which;
    short fg = (short) ((pair == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
    short bg = pair;
    int x0, y0, x1, y1;

    init_pair(pair, fg, bg);

    /* remove the old panel, if any */
    my_remove_panel(pans, which);

    /* get the position of one corner */
    wmove(stdscr, getmaxy(stdscr) / 2, getmaxx(stdscr) / 2);
    getyx(stdscr, y0, x0);
    while ((code = get_position("First corner", "", which, &x0, &y0)) == 0) {
	;
    }

    if (code > 0) {
	char also[80];
	sprintf(also, " (first %d,%d)", y0, x0);
	/* get the position of the opposite corner */
	while ((code = get_position("Opposite corner",
				    also, which, &x1, &y1)) == 0) {
	    ;
	}

	if (code > 0) {
	    int tly = MIN(y0, y1);
	    int tlx = MIN(x0, x1);
	    pan = mkpanel(pair, ABS(y1 - y0) + 1, ABS(x1 - x0) + 1, tly, tlx);
	    /* finish */
	    myFill(pan);
	    pans[which] = pan;
	    pflush();
	    wmove(stdscr, y1, x1);
	}
    }
}
Esempio n. 17
0
/** Exported function to flush a file descriptor's buffer
 *    uses pflush() internally
**/
size_t fflush(int fd)
{
  size_t rx_bytes = 0;
  size_t sret = 0;
  int ret = 0;

  PrintfInfo* pInfo = getPrintfInfo(fd);
  if (pInfo == NULL)
  {
    return (-1);
  }

  sret = pflush(pInfo);
  if (sret == -1)
  {
    _terminate(1);
  }

  return (sret);
}
Esempio n. 18
0
size_t printfProcessString(PrintfInfo* pInfo, const char* str)
{
  size_t ret = 0;
  size_t ret2 = 0;
  size_t i = 0;

  if (pInfo == NULL)
  {
    return (-1);
  }
  if (str == NULL)
  {
    return (0);
  }

  for (i = 0; str[i] != '\0'; i++)
  {
    _PUT_CHAR(pInfo, str[i]);
    if (pInfo->end >= pInfo->bufSize)
    {
      if (pInfo->fd == -1) //i.e. its snprintf
      {
        return (pInfo->bufSize);
      }

      ret2 = pflush(pInfo);
      if (ret2 == -1)
      {
        _terminate(1);
      }
      ret += ret2;
    }
  }   
 
  if (pInfo->fd == -1)
  {
    return (i);
  }

  return (ret);
}
Esempio n. 19
0
magic2()
{
	struct pxhdr pxhd;

	if  (magichdr.a_magic != 0407)
		panic ( "magic2" );
	pflush();
	magichdr.a_data = ( unsigned ) lc - magichdr.a_text;
	magichdr.a_data -= sizeof (struct exec);
	pxhd.objsize = ( ( unsigned ) lc) - HEADER_BYTES;
	pxhd.symtabsize = nlhdrsize();
	magichdr.a_data += pxhd.symtabsize;
	(void) time((long *) (&pxhd.maketime));
	pxhd.magicnum = MAGICNUM;
	if (lseek(ofil, (off_t)0, 0) == -1)
		perror("magic2: lseek1"), panic("magic2");
	write(ofil, (char *) (&magichdr), sizeof(struct exec));
	if (lseek(ofil, (off_t)(HEADER_BYTES - sizeof(pxhd)), 0) == -1)
		perror("magic2: lseek2"), panic("magic2");
	write(ofil, (char *) (&pxhd), sizeof (pxhd));
}
Esempio n. 20
0
void
mtext(		/* matrix string */
int  x, int y,
char  *s,
int  cpi,
int  color
)
{
    pflush();
    cura0 = (color & 03);
    if (cpi < 10) {
	cura0 += 04;
	cpi *= 2;
    }
    if (cpi > 11)
	cura0 += 020;
    if (cpi > 14)
	cura0 += 020;
    if (cpi > 18)
	cura0 += 020;
    pprim(PMSTR, cura0, x, y, x, y, s);
}
Esempio n. 21
0
static void
my_move_panel(PANEL ** pans, int which, bool continuous)
{
    if (pans[which] != 0) {
	int code;
	int y0, x0;
	int y1, x1;
	WINDOW *win = panel_window(pans[which]);
	char also[80];

	getbegyx(win, y0, x0);
	sprintf(also, " (start %d,%d)", y0, x0);
	wmove(stdscr, y0, x0);
	while ((code = get_position("Move panel", also, which, &x1, &y1)) == 0) {
	    if (continuous) {
		move_panel(pans[which], y1, x1);
		pflush();
	    }
	}
	if (code > 0) {
	    move_panel(pans[which], y1, x1);
	}
    }
}
Esempio n. 22
0
int
main(int argc, char **argv)
{
    int c;
    char *cp, *dp;
    int ch;

    while ((ch = getopt(argc, argv, "-2")) != -1)
        switch (ch) {
        case '-':
            suppresul = 1;
            break;
        case '2':
            printall = 1;
            break;
        default:
            usage();
        }
    argc -= optind;
    argv += optind;

    do {
        if (argc > 0) {
            close(0);
            if (!(f = fopen(argv[0], "r"))) {
                fflush(stdout);
                err(1, "%s", argv[0]);
            }
            argc--;
            argv++;
        }
        for (;;) {
            c = getc(stdin);
            if (c == -1) {
                pflush(outline);
                fflush(stdout);
                break;
            }
            switch (c) {
            case '\n':
                if (outline >= 265)
                    pflush(62);
                outline += 2;
                outcol = 0;
                continue;
            case '\016':
            case '\017':
                continue;
            case 033:
                c = getc(stdin);
                switch (c) {
                case '9':
                    if (outline >= 266)
                        pflush(62);
                    outline++;
                    continue;
                case '8':
                    if (outline >= 1)
                        outline--;
                    continue;
                case '7':
                    outline -= 2;
                    if (outline < 0)
                        outline = 0;
                    continue;
                default:
                    continue;
                }
            case '\b':
                if (outcol)
                    outcol--;
                continue;
            case '\t':
                outcol += 8;
                outcol &= ~7;
                outcol--;
                c = ' ';
            default:
                if (outcol >= 132) {
                    outcol++;
                    continue;
                }
                cp = &page[outline][outcol];
                outcol++;
                if (c == '_') {
                    if (suppresul)
                        continue;
                    cp += 132;
                    c = '-';
                }
                if (*cp == 0) {
                    *cp = c;
                    dp = cp - outcol;
                    for (cp--; cp >= dp && *cp == 0; cp--)
                        *cp = ' ';
                } else if (plus(c, *cp) || plus(*cp, c))
                    *cp = '+';
                else if (*cp == ' ' || *cp == 0)
                    *cp = c;
                continue;
            }
        }
    } while (argc > 0);
    fflush(stdout);
    exit(0);
}
Esempio n. 23
0
void
mcloseseg(void)			/* close current segment */
{
    pflush();
    pglob(PCLOSE, 0200, NULL);
}
Esempio n. 24
0
/*
 * pchild - called at interrupt level by the SIGCHLD signal
 *	indicating that at least one child has terminated or stopped
 *	thus at least one wait system call will definitely return a
 *	childs status.  Top level routines (like pwait) must be sure
 *	to mask interrupts when playing with the proclist data structures!
 */
pchild()
{
	register struct process *pp;
	register struct process	*fp;
	register int pid;
	union wait w;
	int jobflags;
	struct rusage ru;

loop:
	pid = wait3(&w, (setintr ? WNOHANG|WUNTRACED:WNOHANG), &ru);
	if (pid <= 0) {
		if (errno == EINTR) {
			errno = 0;
			goto loop;
		}
		pnoprocesses = pid == -1;
		return;
	}
	for (pp = proclist.p_next; pp != PNULL; pp = pp->p_next)
		if (pid == pp->p_pid)
			goto found;
	goto loop;
found:
	if (pid == atoi(value("child")))
		unsetv("child");
	pp->p_flags &= ~(PRUNNING|PSTOPPED|PREPORTED);
	if (WIFSTOPPED(w)) {
		pp->p_flags |= PSTOPPED;
		pp->p_reason = w.w_stopsig;
	} else {
		if (pp->p_flags & (PTIME|PPTIME) || adrof("time"))
			(void) gettimeofday(&pp->p_etime, (struct timezone *)0);
		pp->p_rusage = ru;
		if (WIFSIGNALED(w)) {
			if (w.w_termsig == SIGINT)
				pp->p_flags |= PINTERRUPTED;
			else
				pp->p_flags |= PSIGNALED;
			if (w.w_coredump)
				pp->p_flags |= PDUMPED;
			pp->p_reason = w.w_termsig;
		} else {
			pp->p_reason = w.w_retcode;
			if (pp->p_reason != 0)
				pp->p_flags |= PAEXITED;
			else
				pp->p_flags |= PNEXITED;
		}
	}
	jobflags = 0;
	fp = pp;
	do {
		if ((fp->p_flags & (PPTIME|PRUNNING|PSTOPPED)) == 0 &&
		    !child && adrof("time") &&
		    fp->p_rusage.ru_utime.tv_sec+fp->p_rusage.ru_stime.tv_sec >=
		     atoi(value("time")))
			fp->p_flags |= PTIME;
		jobflags |= fp->p_flags;
	} while ((fp = fp->p_friends) != pp);
	pp->p_flags &= ~PFOREGND;
	if (pp == pp->p_friends && (pp->p_flags & PPTIME)) {
		pp->p_flags &= ~PPTIME;
		pp->p_flags |= PTIME;
	}
	if ((jobflags & (PRUNNING|PREPORTED)) == 0) {
		fp = pp;
		do {
			if (fp->p_flags&PSTOPPED)
				fp->p_flags |= PREPORTED;
		} while((fp = fp->p_friends) != pp);
		while(fp->p_pid != fp->p_jobid)
			fp = fp->p_friends;
		if (jobflags&PSTOPPED) {
			if (pcurrent && pcurrent != fp)
				pprevious = pcurrent;
			pcurrent = fp;
		} else
			pclrcurr(fp);
		if (jobflags&PFOREGND) {
			if (jobflags & (PSIGNALED|PSTOPPED|PPTIME) ||
#ifdef IIASA
			    jobflags & PAEXITED ||
#endif
			    !eq(dcwd->di_name, fp->p_cwd->di_name)) {
				;	/* print in pjwait */
			}
/*
		else if ((jobflags & (PTIME|PSTOPPED)) == PTIME)
				ptprint(fp);
*/
		} else {
			if (jobflags&PNOTIFY || adrof("notify")) {
				printf("\215\n");
				(void) pprint(pp, NUMBER|NAME|REASON);
				if ((jobflags&PSTOPPED) == 0)
					pflush(pp);
			} else {
				fp->p_flags |= PNEEDNOTE;
				neednote++;
			}
		}
	}
	goto loop;
}
Esempio n. 25
0
int main(int argc, char **argv)
{
    int itmp, y;

    if (argc > 1 && atol(argv[1]))
        nap_msec = atol(argv[1]);

#ifdef XCURSES
    Xinitscr(argc, argv);
#else
    initscr();
#endif
    backfill();

    for (y = 0; y < 5; y++)
    {
        p1 = mkpanel(10, 10, 0, 0);
        set_panel_userptr(p1, "p1");

        p2 = mkpanel(14, 14, 5, 5);
        set_panel_userptr(p2, "p2");

        p3 = mkpanel(6, 8, 12, 12);
        set_panel_userptr(p3, "p3");

        p4 = mkpanel(10, 10, 10, 30);
        w4 = panel_window(p4);
        set_panel_userptr(p4, "p4");

        p5 = mkpanel(10, 10, 13, 37);
        w5 = panel_window(p5);
        set_panel_userptr(p5, "p5");

        fill_panel(p1);
        fill_panel(p2);
        fill_panel(p3);
        fill_panel(p4);
        fill_panel(p5);
        hide_panel(p4);
        hide_panel(p5);
        pflush();
        wait_a_while(nap_msec);

        saywhat("h3 s1 s2 s4 s5;");
        move_panel(p1, 0, 0);
        hide_panel(p3);
        show_panel(p1);
        show_panel(p2);
        show_panel(p4);
        show_panel(p5);
        pflush();
        wait_a_while(nap_msec);

        saywhat("s1;");
        show_panel(p1);
        pflush();
        wait_a_while(nap_msec);

        saywhat("s2;");
        show_panel(p2);
        pflush();
        wait_a_while(nap_msec);

        saywhat("m2;");
        move_panel(p2, 10, 10);
        pflush();
        wait_a_while(nap_msec);

        saywhat("s3;");
        show_panel(p3);
        pflush();
        wait_a_while(nap_msec);

        saywhat("m3;");
        move_panel(p3, 5, 5);
        pflush();
        wait_a_while(nap_msec);

        saywhat("b3;");
        bottom_panel(p3);
        pflush();
        wait_a_while(nap_msec);

        saywhat("s4;");
        show_panel(p4);
        pflush();
        wait_a_while(nap_msec);

        saywhat("s5;");
        show_panel(p5);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t3;");
        top_panel(p3);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t1;");
        top_panel(p1);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t2;");
        top_panel(p2);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t3;");
        top_panel(p3);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t4;");
        top_panel(p4);
        pflush();
        wait_a_while(nap_msec);

        for (itmp = 0; itmp < 6; itmp++)
        {
            saywhat("m4;");
            mvwaddstr(w4, 3, 1, mod[itmp]);
            move_panel(p4, 4, itmp * 10);
            mvwaddstr(w5, 4, 1, mod[itmp]);
            pflush();
            wait_a_while(nap_msec);

            saywhat("m5;");
            mvwaddstr(w4, 4, 1, mod[itmp]);
            move_panel(p5, 7, itmp * 10 + 6);
            mvwaddstr(w5, 3, 1, mod[itmp]);
            pflush();
            wait_a_while(nap_msec);
        }

        saywhat("m4;");
        move_panel(p4, 4, itmp * 10);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t5;");
        top_panel(p5);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t2;");
        top_panel(p2);
        pflush();
        wait_a_while(nap_msec);

        saywhat("t1;");
        top_panel(p1);
        pflush();
        wait_a_while(nap_msec);

        saywhat("d2;");
        rmpanel(p2);
        pflush();
        wait_a_while(nap_msec);

        saywhat("h3;");
        hide_panel(p3);
        pflush();
        wait_a_while(nap_msec);

        saywhat("d1;");
        rmpanel(p1);
        pflush();
        wait_a_while(nap_msec);

        saywhat("d4; ");
        rmpanel(p4);
        pflush();
        wait_a_while(nap_msec);

        saywhat("d5; ");
        rmpanel(p5);
        pflush();
        wait_a_while(nap_msec);

        if (nap_msec == 1)
            break;

        nap_msec = 100L;
    }

    endwin();

    return 0;
}   /* end of main */
Esempio n. 26
0
File: pmsh.c Progetto: pdsouza/pmsh
int main(int argc, char** argv) {
    ssize_t cmd_size;
    int i;
    int pipefd[2], fin, fout;
    char buf[BUFFER_SIZE];
    char *cmd;
    char **args;
    job *j;
    job_list = init_list();
    msg_q = init_list();
    pid_t pgid;

    /* initial setup */
    shell_pgid = getpgid(0);
    sync_pwd();

    /* disable (ignore) job control signals */
    signal(SIGTTOU, SIG_IGN);
    signal(SIGTTIN, SIG_IGN);
    signal(SIGTERM, SIG_IGN);
    signal(SIGTSTP, SIG_IGN);
    signal(SIGINT,  SIG_IGN);

    set_handler();

    /*** Shell loop ***/
    for(;;) {

        /* Print out queued messages */
        for(i=0;i<msg_q->size;i++) {
            message *m = (message *) get(msg_q, i);
            printf("%s: %s\n", m->status ? "Finished" : "Stopped", m->msg);
        }

        // clear the queue
        while(msg_q->size > 0)
            free(del(msg_q,0));

        /* TODO: shell print macro */
        printf("%s %s %s ", SHELL, pwd, PROMPT);
        fflush(stdout);

        do 
            cmd_size = read(STDIN_FILENO, buf, BUFFER_SIZE);
        while(cmd_size == -1 && errno == EINTR); // ignore system call interrupts

        if(cmd_size == -1) {
            perror("read");
            continue;
        } else if(cmd_size == 0) { // EOF (quit)
            write(STDOUT_FILENO, EXIT_MSG, STRING_SIZE(EXIT_MSG));
            cleanup();
            _exit(EXIT_SUCCESS);
        } else if(cmd_size == 1 && buf[0] == '\n') {
            continue;
        }

        if(buf[cmd_size-1] != '\n') { // overflow 
            write(STDOUT_FILENO, OFLOW_MSG, STRING_SIZE(OFLOW_MSG));
            pflush();
            continue;
        }

        buf[cmd_size-1] = '\0'; // strip the newline

        j = parse(buf);
        if(j == (job *) NULL) {
            printf("Invalid redirections you moron!\n");
            continue;
        } 

        args = j->cmds[0];
        if (!my_strcmp(args[0], "fg")) {
            do_fg(args);
            free_job(j);
            continue;
        } else if (!my_strcmp(args[0], "bg")) {
            do_bg(args);
            free_job(j);
            continue;
        } else if (!my_strcmp(args[0], "jobs")) {
            print_bg(job_list);
            free_job(j);
            continue;
        } else if (!my_strcmp(args[0], "cd")) {
            do_cd(args);
            free_job(j);
            continue;
        }

        j->job_id = gen_job_id(job_list);
        j->running = 1;
        j->complete = 0;
        push(job_list, JOB, (void *)j);
    
        pgid = 0; // set the job pgid to be the first child's pid

        fin = STDIN_FILENO;
        for(i=0;i<(j->numcmds);i++) {
            args = j->cmds[i];
            cmd = args[0];

            if(i + 1 < (j->numcmds)) { // not last process in job
                //printf("Creating a pipe!\n");
                if(pipe(pipefd) == -1) {
                    perror("pipe");
                    exit(EXIT_FAILURE);
                }
                fout = pipefd[1];
            }
            else
                fout = STDOUT_FILENO;

            /*printf("Forking %s\n", cmd);
            k = 0;
            while( args[k] != (char *) NULL ) {
                printf("\targv[%d] = %s\n", k, args[k]);
                ++k;
            }*/

            pid = fork();
            if(pid == -1) {
                perror("fork");
                continue;
            }

            /*** CHILD ***/
            if(!pid) {

                // <
                if(j->fin[i] != (char *) NULL) {
                    if( (fin = open(j->fin[i], O_RDONLY)) == -1 ) {
                        perror("open");
                    }
                }
                // >
                if(j->fout[i] != (char *) NULL) {
                    if( (fout = open(j->fout[i], O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1 ) {
                        perror("open");
                    }
                }

                exec_process(cmd, args, pgid, fin, fout, j->fg); 
            }
            
            /*** PARENT ***/
            else {
                if(!pgid) { // set to first child's pid (process group leader)
                    pgid = pid;
                    j->pgid = pgid;
                    //printf("Set job's pgid to %d\n", pgid);
                }

                process *proc = malloc(sizeof(process));
                proc->complete = 0;
                proc->pid = pid;
                proc->pgid = pgid;
                push(j->pid_list, PROCESS, (void *)proc);
                
                if( setpgid(pid, pgid) == -1 ) {
                    perror("setpgid");
                    _exit(EXIT_FAILURE);
                }

            }

            if(fin != STDIN_FILENO)
                close(fin);
            if(fout != STDOUT_FILENO)
                close(fout);

            fin = pipefd[0];
        }

        //print_jobs();

        if(j->fg) {  // foreground

            // give terminal control to job
            if( tcsetpgrp(STDIN_FILENO, pgid) == -1 ) {
                perror("tcsetpgrp");
                _exit(EXIT_FAILURE);
            }

            // wait for job to finish
            jwait(j);

            // give pmsh terminal control again
            if( tcsetpgrp(STDIN_FILENO, shell_pgid) == -1 ) {
                perror("tcsetpgrp");
                _exit(EXIT_FAILURE);
            }
        }
        else  {      // background
            printf("Running: %s\n", j->rawcmd);
        }
    }
}
Esempio n. 27
0
void
mdone(void)				/* end of graphics metafile */
{
    pflush();
    pglob(PEOF, 0200, NULL);
}
Esempio n. 28
0
void
mendpage(void)			/* end of page */
{
    pflush();
    pglob(PEOP, 0200, NULL);
}
Esempio n. 29
0
static void
show_panels(PANEL * px[MAX_PANELS + 1])
{
    static const char *help[] =
    {
	"",
	"Commands are letter/digit pairs.  Digits are the panel number.",
	"",
	"  b - put the panel on the bottom of the stack",
	"  c - create the panel",
	"  d - delete the panel",
	"  h - hide the panel",
	"  m - move the panel (M for continuous move)",
	"  r - resize the panel",
	"  s - show the panel",
	"  b - put the panel on the top of the stack"
    };

    struct {
	bool valid;
	bool hidden;
	PANEL *above;
	PANEL *below;
    } table[MAX_PANELS + 1];

    WINDOW *win;
    PANEL *pan;
    int j;

    memset(table, 0, sizeof(table));
    for (j = 1; j <= MAX_PANELS; ++j) {
	table[j].valid = (px[j] != 0);
	if (table[j].valid) {
	    table[j].hidden = panel_hidden(px[j]);
	    table[j].above = panel_above(px[j]);
	    table[j].below = panel_below(px[j]);
	}
    }

    if ((win = newwin(LINES - 1, COLS, 0, 0)) != 0) {
	keypad(win, TRUE);
	if ((pan = new_panel(win)) != 0) {
	    werase(win);
	    MvWPrintw(win, 0, 0, "Panels:\n");
	    for (j = 1; j <= MAX_PANELS; ++j) {
		if (table[j].valid) {
		    wprintw(win, " %d:", j);
		    if (table[j].hidden) {
			waddstr(win, " hidden");
		    } else {
			if (table[j].above) {
			    wprintw(win, " above %d",
				    which_panel(px, table[j].above));
			}
			if (table[j].below) {
			    wprintw(win, "%s below %d",
				    table[j].above ? "," : "",
				    which_panel(px, table[j].below));
			}
		    }
		    waddch(win, '\n');
		}
	    }
	    for (j = 0; j < (int) SIZEOF(help); ++j) {
		if (wprintw(win, "%s\n", help[j]) == ERR)
		    break;
	    }
	    wgetch(win);
	    del_panel(pan);
	    pflush();
	}
	delwin(win);
    }
}
Esempio n. 30
0
int
main(int argc, char *argv[])
{
	wint_t c;
	wchar_t *cp, *dp;
	int ch, i, w;

	setlocale(LC_ALL, "");

	while ((ch = getopt(argc, argv, "-2")) != -1)
		switch (ch) {
		case '-':
			suppresul = 1;
			break;
		case '2':
			printall = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	do {
		if (argc > 0) {
			if (freopen(argv[0], "r", stdin) == NULL) {
				fflush(stdout);
				err(1, "%s", argv[0]);
			}
			argc--;
			argv++;
		}
		for (;;) {
			c = getwc(stdin);
			if (c == WEOF) {
				pflush(outline);
				fflush(stdout);
				break;
			}
			switch (c) {
			case '\n':
				if (outline >= 265)
					pflush(62);
				outline += 2;
				outcol = 0;
				continue;
			case '\016':
			case '\017':
				continue;
			case 033:
				c = getwc(stdin);
				switch (c) {
				case '9':
					if (outline >= 266)
						pflush(62);
					outline++;
					continue;
				case '8':
					if (outline >= 1)
						outline--;
					continue;
				case '7':
					outline -= 2;
					if (outline < 0)
						outline = 0;
					continue;
				default:
					continue;
				}
			case '\b':
				if (outcol)
					outcol--;
				continue;
			case '\t':
				outcol += 8;
				outcol &= ~7;
				outcol--;
				c = ' ';
			default:
				if ((w = wcwidth(c)) <= 0)
					w = 1;	/* XXX */
				if (outcol + w > 132) {
					outcol += w;
					continue;
				}
				cp = &page[outline][outcol];
				outcol += w;
				if (c == '_') {
					if (suppresul)
						continue;
					cp += 132;
					c = '-';
				}
				if (*cp == 0) {
					for (i = 0; i < w; i++)
						cp[i] = c;
					dp = cp - (outcol - w);
					for (cp--; cp >= dp && *cp == 0; cp--)
						*cp = ' ';
				} else {
					if (plus(c, *cp) || plus(*cp, c))
						*cp = '+';
					else if (*cp == ' ' || *cp == 0) {
						for (i = 1; i < w; i++)
							if (cp[i] != ' ' &&
							    cp[i] != 0)
								goto cont;
						for (i = 0; i < w; i++)
							cp[i] = c;
					}
				}
cont:
				continue;
			}
		}
		if (ferror(stdin))
			err(1, NULL);
	} while (argc > 0);
	fflush(stdout);
	exit(0);
}