Changeset 2426 for neercs


Ignore:
Timestamp:
Jun 15, 2008, 7:01:48 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • First attempt to grab a process when started with -P <pid>
Location:
neercs/trunk/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/Makefile.am

    r2402 r2426  
    22bin_PROGRAMS = neercs
    33
    4 neercs_SOURCES = neercs.h main.c screens.c term.c effects.c wm.c
     4neercs_SOURCES = neercs.h grab.c main.c screens.c term.c effects.c wm.c
    55neercs_CFLAGS = @CACA_CFLAGS@
    66neercs_LDADD = @CACA_LIBS@ @UTIL_LIBS@
  • neercs/trunk/src/main.c

    r2421 r2426  
    4343    struct screen_list *screen_list = NULL;
    4444    char *default_shell = NULL;
    45     int i, w, h, nt, args = 0;
     45    int i, w, h;
    4646    int eof = 0, refresh = 1, command = 0;
    4747
    48 
    49     nt = argc - 1;
    50     args = nt;
    51 
    52     if(nt == 0)
    53     {
    54         nt = 1;
    55     }
    56 
    5748    default_shell = getenv("SHELL");
    5849
    59     if(default_shell == NULL  && !args)
     50    if(default_shell == NULL  && argc < 2)
    6051    {
    6152        fprintf(stderr, "Environment variable SHELL not set and no arguments given. kthxbye.\n");
     
    9990    screen_list->pty = screen_list->prevpty = 0;
    10091
    101 
    102     for(i = 0; i < nt; i++)
     92    for(i = 0; i < argc-1; i++)
    10393    {
    10494        struct screen *tmp;
    105         if(args) tmp = create_screen(w, h, argv[i + 1]);
    106         else     tmp = create_screen(w, h, default_shell);
     95        if(argc < 2)
     96            tmp = create_screen(w, h, default_shell);
     97        else
     98        {
     99            if(!strcmp(argv[i + 1], "-P"))
     100            {
     101                if(i + 2 > argc)
     102                {
     103                    fprintf(stderr, "-P needs a parameter !\n");
     104                    exit(1);
     105                }
     106                tmp = create_screen_grab(w, h, atoi(argv[i + 2]));
     107                i++;
     108            }
     109            else
     110                tmp = create_screen(w, h, argv[i + 1]);
     111        }
    107112
    108113        if(tmp)
  • neercs/trunk/src/neercs.h

    r2421 r2426  
    1515
    1616#include <stdint.h>
    17 #include <cucul.h>
     17#include <caca.h>
    1818
    1919
     
    7676
    7777int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
     78int create_pty_grab(pid_t pid, unsigned int w, unsigned int h);
     79int grab_process(pid_t pid, int ptyfd);
    7880
    7981long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
     
    8789/* Screens management */
    8890struct screen* create_screen(int w, int h, char *command);
     91struct screen* create_screen_grab(int w, int h, int pid);
    8992int destroy_screen(struct screen *s);
    9093int add_screen(struct screen_list *list, struct screen *s);
     
    105108
    106109
    107 
    108 
    109110#if 0
    110111#   define debug(f, z...) fprintf(stderr, f "\n", z)
  • neercs/trunk/src/screens.c

    r2422 r2426  
    2828
    2929#include "neercs.h"
     30
     31struct screen* create_screen_grab(int w, int h, int pid)
     32{
     33    struct screen *s = (struct screen*) malloc(sizeof(struct screen));
     34
     35    s->cv = cucul_create_canvas(w, h);
     36    cucul_set_color_ansi(s->cv, CUCUL_BLACK, CUCUL_BLACK);
     37    cucul_clear_canvas(s->cv);
     38    s->init = 0;
     39
     40    s->buf = NULL;
     41    s->title = NULL;
     42    s->total = 0;
     43    s->w = w+1;
     44    s->h = h+1;
     45    s->bell = 0;
     46    s->pid = pid;
     47
     48    s->fd = create_pty_grab(pid, w, h);
     49
     50    if(s->fd < 0)
     51    {
     52        cucul_free_canvas(s->cv);
     53        free(s);
     54        return NULL;
     55    }
     56    return s;
     57}
    3058
    3159struct screen* create_screen(int w, int h, char *command)
  • neercs/trunk/src/term.c

    r2421 r2426  
    577577}
    578578
     579int create_pty_grab(pid_t pid, unsigned int w, unsigned int h)
     580{
     581    int fdm, fds;
     582
     583    int ret = openpty(&fdm, &fds, NULL, NULL, NULL);
     584
     585    if(ret < 0)
     586    {
     587        fprintf(stderr, "open() error\n");
     588        return -1;
     589    }
     590
     591    set_tty_size(0, w, h);
     592    grab_process(pid, fds);
     593
     594    fcntl(fdm, F_SETFL, O_NDELAY);
     595    return fdm;
     596}
     597
    579598int set_tty_size(int fd, unsigned int w, unsigned int h)
    580599{
Note: See TracChangeset for help on using the changeset viewer.