Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r2e3a857 r89c11e7  
    7777       
    7878        return mktime(&tm);
    79 }
    80 
    81 time_t mktime_utc( struct tm *tp )
    82 {
    83         struct tm utc;
    84         time_t res, tres;
    85        
    86         tp->tm_isdst = -1;
    87         res = mktime( tp );
    88         /* Problem is, mktime() just gave us the GMT timestamp for the
    89            given local time... While the given time WAS NOT local. So
    90            we should fix this now.
    91            
    92            Now I could choose between messing with environment variables
    93            (kludgy) or using timegm() (not portable)... Or doing the
    94            following, which I actually prefer...
    95            
    96            tzset() may also work but in other places I actually want to
    97            use local time.
    98            
    99            FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */
    100         gmtime_r( &res, &utc );
    101         utc.tm_isdst = -1;
    102         if( utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min )
    103                 /* Sweet! We're in UTC right now... */
    104                 return res;
    105        
    106         tres = mktime( &utc );
    107         res += res - tres;
    108        
    109         /* Yes, this is a hack. And it will go wrong around DST changes.
    110            BUT this is more likely to be threadsafe than messing with
    111            environment variables, and possibly more portable... */
    112        
    113         return res;
    11479}
    11580
     
    649614        return ret;
    650615}
     616
     617char **split_command_parts( char *command )
     618{
     619        static char *cmd[IRC_MAX_ARGS+1];
     620        char *s, q = 0;
     621        int k;
     622       
     623        memset( cmd, 0, sizeof( cmd ) );
     624        cmd[0] = command;
     625        k = 1;
     626        for( s = command; *s && k < IRC_MAX_ARGS; s ++ )
     627                if( *s == ' ' && !q )
     628                {
     629                        *s = 0;
     630                        while( *++s == ' ' );
     631                        if( *s == '"' || *s == '\'' )
     632                        {
     633                                q = *s;
     634                                s ++;
     635                        }
     636                        if( *s )
     637                        {
     638                                cmd[k++] = s;
     639                                s --;
     640                        }
     641                        else
     642                        {
     643                                break;
     644                        }
     645                }
     646                else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
     647                {
     648                        char *cpy;
     649                       
     650                        for( cpy = s; *cpy; cpy ++ )
     651                                cpy[0] = cpy[1];
     652                }
     653                else if( *s == q )
     654                {
     655                        q = *s = 0;
     656                }
     657       
     658        /* Full zero-padding for easier argc checking. */
     659        while( k <= IRC_MAX_ARGS )
     660                cmd[k++] = NULL;
     661       
     662        return cmd;
     663}
Note: See TracChangeset for help on using the changeset viewer.