Changeset 5ebff60 for set.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • set.c

    raf359b4 r5ebff60  
    1   /********************************************************************\
     1/********************************************************************\
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
     
    3030char *SET_INVALID = "nee";
    3131
    32 set_t *set_add( set_t **head, const char *key, const char *def, set_eval eval, void *data )
    33 {
    34         set_t *s = set_find( head, key );
    35        
     32set_t *set_add(set_t **head, const char *key, const char *def, set_eval eval, void *data)
     33{
     34        set_t *s = set_find(head, key);
     35
    3636        /* Possibly the setting already exists. If it doesn't exist yet,
    3737           we create it. If it does, we'll just change the default. */
    38         if( !s )
    39         {
    40                 if( ( s = *head ) )
    41                 {
     38        if (!s) {
     39                if ((s = *head)) {
    4240                        /* Sorted insertion. Special-case insertion at the start. */
    43                         if( strcmp( key, s->key ) < 0 )
    44                         {
    45                                 s = g_new0( set_t, 1 );
     41                        if (strcmp(key, s->key) < 0) {
     42                                s = g_new0(set_t, 1);
    4643                                s->next = *head;
    4744                                *head = s;
    48                         }
    49                         else
    50                         {
    51                                 while( s->next && strcmp( key, s->next->key ) > 0 )
     45                        } else {
     46                                while (s->next && strcmp(key, s->next->key) > 0) {
    5247                                        s = s->next;
     48                                }
    5349                                set_t *last_next = s->next;
    54                                 s->next = g_new0( set_t, 1 );
     50                                s->next = g_new0(set_t, 1);
    5551                                s = s->next;
    5652                                s->next = last_next;
    5753                        }
    58                 }
    59                 else
    60                 {
    61                         s = *head = g_new0( set_t, 1 );
    62                 }
    63                 s->key = g_strdup( key );
    64         }
    65        
    66         if( s->def )
    67         {
    68                 g_free( s->def );
     54                } else {
     55                        s = *head = g_new0(set_t, 1);
     56                }
     57                s->key = g_strdup(key);
     58        }
     59
     60        if (s->def) {
     61                g_free(s->def);
    6962                s->def = NULL;
    7063        }
    71         if( def ) s->def = g_strdup( def );
    72        
     64        if (def) {
     65                s->def = g_strdup(def);
     66        }
     67
    7368        s->eval = eval;
    7469        s->data = data;
    75        
     70
    7671        return s;
    7772}
    7873
    79 set_t *set_find( set_t **head, const char *key )
     74set_t *set_find(set_t **head, const char *key)
    8075{
    8176        set_t *s = *head;
    82        
    83         while( s )
    84         {
    85                 if( g_strcasecmp( s->key, key ) == 0 ||
    86                     ( s->old_key && g_strcasecmp( s->old_key, key ) == 0 ) )
     77
     78        while (s) {
     79                if (g_strcasecmp(s->key, key) == 0 ||
     80                    (s->old_key && g_strcasecmp(s->old_key, key) == 0)) {
    8781                        break;
     82                }
    8883                s = s->next;
    8984        }
    90        
     85
    9186        return s;
    9287}
    9388
    94 char *set_getstr( set_t **head, const char *key )
    95 {
    96         set_t *s = set_find( head, key );
    97        
    98         if( !s || ( !s->value && !s->def ) )
     89char *set_getstr(set_t **head, const char *key)
     90{
     91        set_t *s = set_find(head, key);
     92
     93        if (!s || (!s->value && !s->def)) {
    9994                return NULL;
    100        
    101         return set_value( s );
    102 }
    103 
    104 int set_getint( set_t **head, const char *key )
    105 {
    106         char *s = set_getstr( head, key );
     95        }
     96
     97        return set_value(s);
     98}
     99
     100int set_getint(set_t **head, const char *key)
     101{
     102        char *s = set_getstr(head, key);
    107103        int i = 0;
    108        
    109         if( !s )
    110                 return 0;
    111        
    112         if( sscanf( s, "%d", &i ) != 1 )
    113                 return 0;
    114        
     104
     105        if (!s) {
     106                return 0;
     107        }
     108
     109        if (sscanf(s, "%d", &i) != 1) {
     110                return 0;
     111        }
     112
    115113        return i;
    116114}
    117115
    118 int set_getbool( set_t **head, const char *key )
    119 {
    120         char *s = set_getstr( head, key );
    121        
    122         if( !s )
    123                 return 0;
    124        
    125         return bool2int( s );
    126 }
    127 
    128 int set_isvisible( set_t *set )
     116int set_getbool(set_t **head, const char *key)
     117{
     118        char *s = set_getstr(head, key);
     119
     120        if (!s) {
     121                return 0;
     122        }
     123
     124        return bool2int(s);
     125}
     126
     127int set_isvisible(set_t *set)
    129128{
    130129        /* the default value is not stored in value, only in def */
    131         return !( ( set->flags & SET_HIDDEN ) ||
    132                   ( ( set->flags & SET_HIDDEN_DEFAULT ) &&
    133                     ( set->value == NULL ) ) );
    134 }
    135 
    136 int set_setstr( set_t **head, const char *key, char *value )
    137 {
    138         set_t *s = set_find( head, key );
     130        return !((set->flags & SET_HIDDEN) ||
     131                 ((set->flags & SET_HIDDEN_DEFAULT) &&
     132                  (set->value == NULL)));
     133}
     134
     135int set_setstr(set_t **head, const char *key, char *value)
     136{
     137        set_t *s = set_find(head, key);
    139138        char *nv = value;
    140        
    141         if( !s )
     139
     140        if (!s) {
    142141                /*
    143142                Used to do this, but it never really made sense.
     
    145144                */
    146145                return 0;
    147        
    148         if( value == NULL && ( s->flags & SET_NULL_OK ) == 0 )
    149                 return 0;
    150        
     146        }
     147
     148        if (value == NULL && (s->flags & SET_NULL_OK) == 0) {
     149                return 0;
     150        }
     151
    151152        /* Call the evaluator. For invalid values, evaluators should now
    152153           return SET_INVALID, but previously this was NULL. Try to handle
    153154           that too if NULL is not an allowed value for this setting. */
    154         if( s->eval && ( ( nv = s->eval( s, value ) ) == SET_INVALID ||
    155                          ( ( s->flags & SET_NULL_OK ) == 0 && nv == NULL ) ) )
    156                 return 0;
    157        
    158         if( s->value )
    159         {
    160                 g_free( s->value );
     155        if (s->eval && ((nv = s->eval(s, value)) == SET_INVALID ||
     156                        ((s->flags & SET_NULL_OK) == 0 && nv == NULL))) {
     157                return 0;
     158        }
     159
     160        if (s->value) {
     161                g_free(s->value);
    161162                s->value = NULL;
    162163        }
    163        
     164
    164165        /* If there's a default setting and it's equal to what we're trying to
    165166           set, stick with s->value = NULL. Otherwise, remember the setting. */
    166         if( !s->def || ( strcmp( nv, s->def ) != 0 ) )
    167                 s->value = g_strdup( nv );
    168        
    169         if( nv != value )
    170                 g_free( nv );
    171        
     167        if (!s->def || (strcmp(nv, s->def) != 0)) {
     168                s->value = g_strdup(nv);
     169        }
     170
     171        if (nv != value) {
     172                g_free(nv);
     173        }
     174
    172175        return 1;
    173176}
    174177
    175 int set_setint( set_t **head, const char *key, int value )
    176 {
    177         char *s = g_strdup_printf( "%d", value );
    178         int retval = set_setstr( head, key, s );
    179         g_free( s );
     178int set_setint(set_t **head, const char *key, int value)
     179{
     180        char *s = g_strdup_printf("%d", value);
     181        int retval = set_setstr(head, key, s);
     182
     183        g_free(s);
    180184        return retval;
    181185}
    182186
    183 void set_del( set_t **head, const char *key )
     187void set_del(set_t **head, const char *key)
    184188{
    185189        set_t *s = *head, *t = NULL;
    186        
    187         while( s )
    188         {
    189                 if( g_strcasecmp( s->key, key ) == 0 )
     190
     191        while (s) {
     192                if (g_strcasecmp(s->key, key) == 0) {
    190193                        break;
    191                 s = (t=s)->next;
    192         }
    193         if( s )
    194         {
    195                 if( t )
     194                }
     195                s = (t = s)->next;
     196        }
     197        if (s) {
     198                if (t) {
    196199                        t->next = s->next;
    197                 else
     200                } else {
    198201                        *head = s->next;
    199                
    200                 g_free( s->key );
    201                 g_free( s->old_key );
    202                 g_free( s->value );
    203                 g_free( s->def );
    204                 g_free( s );
    205         }
    206 }
    207 
    208 int set_reset( set_t **head, const char *key )
     202                }
     203
     204                g_free(s->key);
     205                g_free(s->old_key);
     206                g_free(s->value);
     207                g_free(s->def);
     208                g_free(s);
     209        }
     210}
     211
     212int set_reset(set_t **head, const char *key)
    209213{
    210214        set_t *s;
    211        
    212         s = set_find( head, key );
    213         if( s )
    214                 return set_setstr( head, key, s->def );
    215        
     215
     216        s = set_find(head, key);
     217        if (s) {
     218                return set_setstr(head, key, s->def);
     219        }
     220
    216221        return 0;
    217222}
    218223
    219 char *set_eval_int( set_t *set, char *value )
     224char *set_eval_int(set_t *set, char *value)
    220225{
    221226        char *s = value;
    222        
     227
    223228        /* Allow a minus at the first position. */
    224         if( *s == '-' )
    225                 s ++;
    226        
    227         for( ; *s; s ++ )
    228                 if( !g_ascii_isdigit( *s ) )
     229        if (*s == '-') {
     230                s++;
     231        }
     232
     233        for (; *s; s++) {
     234                if (!g_ascii_isdigit(*s)) {
    229235                        return SET_INVALID;
    230        
     236                }
     237        }
     238
    231239        return value;
    232240}
    233241
    234 char *set_eval_bool( set_t *set, char *value )
    235 {
    236         return is_bool( value ) ? value : SET_INVALID;
    237 }
    238 
    239 char *set_eval_list( set_t *set, char *value )
     242char *set_eval_bool(set_t *set, char *value)
     243{
     244        return is_bool(value) ? value : SET_INVALID;
     245}
     246
     247char *set_eval_list(set_t *set, char *value)
    240248{
    241249        GSList *options = set->eval_data, *opt;
    242        
    243         for( opt = options; opt; opt = opt->next )
    244                 if( strcmp( value, opt->data ) == 0 )
     250
     251        for (opt = options; opt; opt = opt->next) {
     252                if (strcmp(value, opt->data) == 0) {
    245253                        return value;
    246        
     254                }
     255        }
     256
    247257        /* TODO: It'd be nice to show the user a list of allowed values,
    248258                 but we don't have enough context here to do that. May
    249259                 want to fix that. */
    250        
     260
    251261        return NULL;
    252262}
    253263
    254 char *set_eval_to_char( set_t *set, char *value )
    255 {
    256         char *s = g_new( char, 3 );
    257        
    258         if( *value == ' ' )
    259                 strcpy( s, " " );
    260         else
    261                 sprintf( s, "%c ", *value );
    262        
     264char *set_eval_to_char(set_t *set, char *value)
     265{
     266        char *s = g_new(char, 3);
     267
     268        if (*value == ' ') {
     269                strcpy(s, " ");
     270        } else {
     271                sprintf(s, "%c ", *value);
     272        }
     273
    263274        return s;
    264275}
    265276
    266 char *set_eval_oauth( set_t *set, char *value )
     277char *set_eval_oauth(set_t *set, char *value)
    267278{
    268279        account_t *acc = set->data;
    269        
    270         if( bool2int( value ) && strcmp( acc->pass, PASSWORD_PENDING ) == 0 )
     280
     281        if (bool2int(value) && strcmp(acc->pass, PASSWORD_PENDING) == 0) {
    271282                *acc->pass = '\0';
    272        
    273         return set_eval_bool( set, value );
    274 }
     283        }
     284
     285        return set_eval_bool(set, value);
     286}
Note: See TracChangeset for help on using the changeset viewer.