Changeset 4033 for neercs


Ignore:
Timestamp:
Nov 25, 2009, 12:47:40 PM (10 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added basic and non-working python interpreter
Location:
neercs/trunk/src
Files:
1 added
1 deleted
5 edited

Legend:

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

    r4026 r4033  
    55                 term.c grab.c effects.c wm.c screensaver.c attach.c \
    66                 configuration.c mytrace.c mytrace.h input.c lock.c server.c \
    7                  client.c screen_list.c help.c python.c             
     7                 client.c screen_list.c help.c interpreter.c             
    88neercs_CFLAGS = @CACA_CFLAGS@ @PYTHON3_CFLAGS@
    99neercs_LDADD = @CACA_LIBS@ @UTIL_LIBS@ @PAM_LIBS@ @PYTHON3_LIBS@
  • neercs/trunk/src/input.c

    r4027 r4033  
    182182    case 'e':
    183183        screen_list->python_command = 1;
    184         screen_list->command_props.x = 0;
    185         screen_list->command_props.y = 0;
     184        screen_list->interpreter_props.x = 0;
     185        screen_list->interpreter_props.y = 0;
    186186        break;
    187187#endif
  • neercs/trunk/src/neercs.h

    r4027 r4033  
    144144};
    145145
    146 struct command_props
    147 {
     146struct interpreter_props
     147{
     148    /* Input box */
    148149        int x, y;
    149150    int size;
    150151    char *command;
     152    char *output;
    151153};
    152154
    153155struct screen_list
    154156{
     157    int outfd;                   /* Debug */
    155158    int wm_type;                 /* Window manager type */
    156159    int in_bell;                 /* Bell occuring in a window  */
     
    192195    struct cube_props cube;      /* Cube */
    193196    long long unsigned int last_switch; /* Cube */
    194     struct command_props command_props;
     197    struct interpreter_props interpreter_props;
    195198
    196199    /* ScreenSaver stuff */
     
    272275void refresh_screens(struct screen_list *screen_list);
    273276int update_screens_contents(struct screen_list* screen_list);
     277int install_fds(struct screen_list *screen_list);
    274278long long get_us(void);
    275279
     
    316320void draw_help(struct screen_list *screen_list);
    317321int help_handle_key(struct screen_list *screen_list, unsigned int c);
    318 #ifdef USE_PYTHON
    319 int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
    320 void draw_python_command(struct screen_list *screen_list);
    321 #endif
    322322int update_window_list(int c, struct screen_list *screen_list);
    323323void draw_list(struct screen_list *screen_list);
     
    360360int get_key_value(char *line, struct option *option);
    361361int fill_config(struct screen_list *screen_list);
     362
     363
     364/* Python interpreter */
     365#ifdef USE_PYTHON
     366int python_init(struct screen_list *sl);
     367int python_close(struct screen_list *sl);
     368int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
     369void draw_python_command(struct screen_list *screen_list);
     370#endif
    362371
    363372#if defined DEBUG
  • neercs/trunk/src/screen_list.c

    r4027 r4033  
    9898   
    9999    screen_list->python_command = 0;
    100     screen_list->command_props.x = 0;
    101     screen_list->command_props.y = 0;
    102     screen_list->command_props.command = NULL;
    103     screen_list->command_props.size = 0;
     100    screen_list->interpreter_props.x = 0;
     101    screen_list->interpreter_props.y = 0;
     102    screen_list->interpreter_props.command = NULL;
     103    screen_list->interpreter_props.size = 0;
    104104   
    105105    screen_list->recurrent_list = NULL;
  • neercs/trunk/src/server.c

    r4026 r4033  
    212212
    213213
    214    
     214
    215215    screen_list->last_key_time = 0;
    216216    screen_list->attached = 0;
     
    220220
    221221    server_init(screen_list);
     222#ifdef USE_PYTHON
     223    python_init(screen_list);
     224#endif
    222225
    223226    for (;;)
     
    300303    free_screen_list(screen_list);
    301304
     305#ifdef USE_PYTHON
     306    python_close(screen_list);
     307#endif
     308   
    302309    exit(0);
    303310}
     
    453460    if (screen_list->help)
    454461    {
    455         return help_handle_key(screen_list, c); 
     462        return help_handle_key(screen_list, c);
    456463    }
    457464#ifdef USE_PYTHON
    458         if(screen_list->python_command)
    459     {
    460         return python_command_handle_key(screen_list, c);   
    461     }
    462 #endif
    463    
     465    if (screen_list->python_command)
     466    {
     467        return python_command_handle_key(screen_list, c);
     468    }
     469#endif
     470
    464471    /* CTRL-A has been pressed before, handle this as a command, except that
    465      CTRL-A a sends literal CTRL-A */
     472       CTRL-A a sends literal CTRL-A */
    466473    if (screen_list->command && (c != 'a'))
    467474    {
     
    527534}
    528535
     536
     537int install_fds(struct screen_list *screen_list)
     538{
     539    int fd;
     540    close(0);
     541    close(1);
     542    close(2);
     543    fd = open("/dev/null", O_RDWR, 0);
     544    if (fd < 0)
     545    {
     546        perror("Failed to open /dev/null");
     547        return -2;
     548    }
     549    dup2(fd, 0);
     550#ifndef DEBUG
     551    dup2(fd, 1);
     552    dup2(fd, 2);
     553    if (fd > 2)
     554        close(fd);
     555#else
     556    if (fd != 0)
     557        close(fd);
     558    screen_list->outfd =
     559        open("/tmp/neercs-debug.txt", O_TRUNC | O_RDWR | O_CREAT,
     560             S_IRUSR | S_IWUSR);
     561    dup2(screen_list->outfd, 1);
     562    dup2(screen_list->outfd, 2);
     563    if (screen_list->outfd > 2)
     564        close(screen_list->outfd);
     565#endif
     566        return 0;
     567}
     568
    529569int start_server(struct screen_list *screen_list)
    530570{
     
    539579    if (pid == 0)
    540580    {
    541         int fd;
    542         close(0);
    543         close(1);
    544         close(2);
    545         fd = open("/dev/null", O_RDWR, 0);
    546         if (fd < 0)
    547         {
    548             perror("Failed to open /dev/null");
    549             return -2;
    550         }
    551         dup2(fd, 0);
    552 #ifndef DEBUG
    553         dup2(fd, 1);
    554         dup2(fd, 2);
    555         if (fd > 2)
    556             close(fd);
    557 #else
    558         if (fd != 0)
    559             close(fd);
    560         fd = open("/tmp/neercs-debug.txt", O_TRUNC | O_RDWR | O_CREAT,
    561                   S_IRUSR | S_IWUSR);
    562         dup2(fd, 1);
    563         dup2(fd, 2);
    564         if (fd > 2)
    565             close(fd);
    566 #endif
     581        int r = install_fds(screen_list);
     582        if(r) return r;
    567583        setsid();
    568584
     
    570586        /* Never returns */
    571587    }
    572    
     588
    573589    return 0;
    574590}
Note: See TracChangeset for help on using the changeset viewer.