Changeset 2444


Ignore:
Timestamp:
Jun 16, 2008, 1:04:49 PM (15 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Changed command line parsing to sam's mygetopt.c
Location:
neercs/trunk/src
Files:
2 added
5 edited

Legend:

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

    r2431 r2444  
    77endif
    88
    9 neercs_SOURCES = neercs.h $(grab_c) main.c screens.c term.c effects.c wm.c
     9neercs_SOURCES = neercs.h $(grab_c) mygetopt.c main.c screens.c term.c effects.c wm.c
    1010neercs_CFLAGS = @CACA_CFLAGS@
    1111neercs_LDADD = @CACA_LIBS@ @UTIL_LIBS@
  • neercs/trunk/src/grab.c

    r2430 r2444  
    1616
    1717#include "neercs.h"
     18int grab_process(pid_t pid, char *ptyname, int ptyfd);
    1819
    1920static int memcpy_from_target(pid_t pid, void* dest, void* src, size_t n)
     
    125126    regs.ebx = oldfd;
    126127    regs.ecx = newfd;
    127    
     128
    128129    return do_syscall(pid, &regs);
    129130}
     
    149150
    150151    /* +4 because it's trcuncated on a multiple of 4 and we need 1 */
    151     memcpy_into_target(pid, target_page, path, strlen(path)+4); 
     152    memcpy_into_target(pid, target_page, path, strlen(path)+4);
    152153
    153154    regs.eax = SYS_open;
     
    155156    regs.ecx = O_RDWR;
    156157    regs.edx = 0755;
    157    
     158
    158159    if((ret = do_syscall(pid, &regs)) < 0)
    159160    {
     
    309310        }
    310311    }
    311    
     312
    312313    kill(pid, SIGWINCH);
    313314
  • neercs/trunk/src/main.c

    r2433 r2444  
    3131#   include <util.h> /* for OS X */
    3232#endif
     33#if !defined HAVE_GETOPT_LONG
     34#   include "mygetopt.h"
     35#elif defined HAVE_GETOPT_H
     36#   include <getopt.h>
     37#endif
     38#if defined HAVE_GETOPT_LONG
     39#   define mygetopt getopt_long
     40#   define myoptind optind
     41#   define myoptarg optarg
     42#   define myoption option
     43#endif
    3344#include <errno.h>
    3445#include <cucul.h>
     
    3647
    3748#include "neercs.h"
     49
     50
     51void version(void)
     52{
     53    printf("%s\n", PACKAGE_STRING);
     54    printf("Copyright (C) 2006, 2008 Sam Hocevar <sam@zoy.org>\n");
     55    printf("                         Jean-Yves Lamoureux <jylam@lnxscene.org>\n\n");
     56    printf("This is free software.  You may redistribute copies of it under the\n");
     57    printf("terms of the Do What The Fuck You Want To Public License, Version 2\n");
     58    printf("<http://sam.zoy.org/wtfpl/>.\n");
     59    printf("There is NO WARRANTY, to the extent permitted by law.\n");
     60    printf("\n");
     61    printf("For more informations, visit http://libcaca.zoy.org/wiki/neercs\n");
     62}
     63
    3864
    3965int main(int argc, char **argv)
     
    4369    struct screen_list *screen_list = NULL;
    4470    char *default_shell = NULL;
    45     int i, w, h, args;
     71    int i, w, h, args, s=0;
    4672    int eof = 0, refresh = 1, command = 0;
    4773
     
    6591    caca_set_cursor(dp, 1);
    6692
    67 
    6893    w = cucul_get_canvas_width(cv);
    6994    h = cucul_get_canvas_height(cv);
    70 
    7195
    7296
     
    94118    screen_list->pty = screen_list->prevpty = 0;
    95119
    96     for(i = 0; i < args; i++)
    97     {
    98         struct screen *tmp;
    99         if(argc < 2)
    100             tmp = create_screen(w, h, default_shell);
    101         else
    102         {
    103             if(!strcmp(argv[i + 1], "-P"))
     120    for(;;)
     121    {
     122        int option_index = 0;
     123        static struct myoption long_options[] =
    104124            {
    105125#ifdef USE_GRAB
    106                 if(i + 2 > argc)
    107                 {
    108                     fprintf(stderr, "-P needs a parameter !\n");
    109                     exit(1);
    110                 }
    111                 tmp = create_screen_grab(w, h, atoi(argv[i + 2]));
    112                 i++;
    113 #else
    114                 fprintf(stderr, "Grabbing process is not supported, sorry\n");
    115                 exit(1);
    116 #endif
    117             }
    118             else
    119                 tmp = create_screen(w, h, argv[i + 1]);
    120         }
    121 
    122         if(tmp)
    123         {
    124             if(add_screen(screen_list, tmp) < 0)
    125             {
    126                 fprintf(stderr, "Can't add %p to %p\n", tmp, screen_list);
    127             }
    128         }
    129         else
    130         {
    131             fprintf(stderr, "Can't create screen\n");
    132         }
    133     }
     126                { "pid",         1, NULL, 'P' },
     127#endif
     128                { "help",        0, NULL, 'h' },
     129                { "version",     0, NULL, 'v' },
     130            };
     131        int c = mygetopt(argc, argv, "P:hv", long_options, &option_index);
     132        if(c == -1)
     133            break;
     134
     135        switch(c)
     136        {
     137#ifdef USE_GRAB
     138        case 'P': /* --pid */
     139            add_screen(screen_list,create_screen_grab(w, h, atoi(myoptarg)));
     140            s+=2;
     141            break;
     142#endif
     143        case 'h': /* --help */
     144            //   usage(argc, argv);
     145            return 0;
     146            break;
     147        case 'v': /* --version */
     148            version();
     149            goto end;
     150            break;
     151        default:
     152            fprintf(stderr, "Unknow argument #%d\n", myoptind);
     153            return -1;
     154            break;
     155        }
     156    }
     157
     158
     159    if(s == 0 && argc<2)
     160    {
     161        add_screen(screen_list, create_screen(w, h, default_shell));
     162    }
     163
     164    /* Launch command line processes */
     165    for(i=0; i<(argc-1) - s; i++)
     166    {
     167        add_screen(screen_list, create_screen(w, h, argv[i+s+1]));
     168    }
     169
    134170
    135171    /* Windows are in a temporary state, resize them to the right dimensions */
     
    262298    }
    263299
     300end:
    264301    /* Clean up */
    265302    caca_free_display(dp);
  • neercs/trunk/src/neercs.h

    r2431 r2444  
    1616#include <stdint.h>
    1717#include <caca.h>
    18 
    19 #define CURRENTSCREEN screen_list->screen[screen_list->pty]
    20 
    2118
    2219enum wm_types
     
    7471
    7572
     73void version(void);
     74
     75
     76
    7677int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
    7778#ifdef USE_GRAB
  • neercs/trunk/src/term.c

    r2431 r2444  
    167167             * ECMA-48 5.4: Control sequences, and the code definitions are
    168168             * given in ECMA-48 8.3: Definition of control functions. */
    169 
     169            debug("Got command '%c'\n", buffer[i + final]);
    170170            switch(buffer[i + final])
    171171            {
     
    256256                break;
    257257            case 'r': /* SS  (0x72) - Scroll Screen FIXME */
    258 
     258                if(scrolled) break;
    259259                if((argv[0]==0 && argv[1]==0)  || scrolled) break;
    260260                for(j = argv[0]-1; j < argv[1]-1; j++)
Note: See TracChangeset for help on using the changeset viewer.