Changeset 2645 for neercs


Ignore:
Timestamp:
Aug 2, 2008, 2:29:15 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • Move the end of options parsing into handle_command_line
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/main.c

    r2642 r2645  
    8080{
    8181    struct screen_list *screen_list = NULL;
    82     int i, args, s=0;
     82    int i, args;
    8383    long long unsigned int last_key_time = 0;
    8484    int mainret = -1;
     
    9595    }
    9696
    97     if(args==0)
    98         args = 1;
    99 
    100 
    101     s = handle_command_line(argc, argv, screen_list);
    102     if(s<0) goto end;
    103 
    104     if(s < argc - 1)
    105     {
    106         screen_list->to_start = (char**)malloc((argc-s)*sizeof(char*));
    107         if(!screen_list->to_start)
    108         {
    109             fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
    110             goto end;
    111         }
    112         for(i=0; i<(argc-1) - s; i++)
    113         {
    114             screen_list->to_start[i] = strdup(argv[i+s+1]);
    115         }
    116         screen_list->to_start[argc-1-s] = NULL;
    117     }
     97    if(handle_command_line(argc, argv, screen_list) < 0)
     98        goto end;
    11899
    119100    /* Read global configuration first */
     
    130111    {
    131112        char **sockets;
    132         if(screen_list->nb_to_grab || (argc-1 > s))
     113        if(screen_list->nb_to_grab || screen_list->to_start)
    133114        {
    134115            fprintf(stderr, "-R can not be associated with commands or pids!\n");
     
    434415int handle_command_line(int argc, char *argv[], struct screen_list *screen_list)
    435416{
    436     int s = 0;
     417    int s = 0, i;
    437418    for(;;)
    438419    {
     
    524505        }
    525506    }
     507    if(s >= 0 && s < argc - 1)
     508    {
     509        screen_list->to_start = (char**)malloc((argc-s)*sizeof(char*));
     510        if(!screen_list->to_start)
     511        {
     512            fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
     513            return -1;
     514        }
     515        for(i=0; i<(argc-1) - s; i++)
     516        {
     517            screen_list->to_start[i] = strdup(argv[i+s+1]);
     518        }
     519        screen_list->to_start[argc-1-s] = NULL;
     520    }
    526521    return s;
    527522}
Note: See TracChangeset for help on using the changeset viewer.