/** * Parse the switcher string, into internal array of type Mode. * * String is split on separator ',' * First the three build-in modi are checked: window, run, ssh * if that fails, a script-switcher is created. */ static int add_mode ( const char * token ) { unsigned int index = num_modi; // Resize and add entry. modi = (Mode * *) g_realloc ( modi, sizeof ( Mode* ) * ( num_modi + 1 ) ); // Window switcher. #ifdef WINDOW_MODE if ( strcasecmp ( token, "window" ) == 0 ) { modi[num_modi] = &window_mode; num_modi++; } else if ( strcasecmp ( token, "windowcd" ) == 0 ) { modi[num_modi] = &window_mode_cd; num_modi++; } else #endif // WINDOW_MODE // SSh dialog if ( strcasecmp ( token, "ssh" ) == 0 ) { modi[num_modi] = &ssh_mode; num_modi++; } // Run dialog else if ( strcasecmp ( token, "run" ) == 0 ) { modi[num_modi] = &run_mode; num_modi++; } else if ( strcasecmp ( token, "drun" ) == 0 ) { modi[num_modi] = &drun_mode; num_modi++; } // combi dialog else if ( strcasecmp ( token, "combi" ) == 0 ) { modi[num_modi] = &combi_mode; num_modi++; } else { // If not build in, use custom modi. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { modi[num_modi] = sw; mode_set_config ( sw ); num_modi++; } else{ // Report error, don't continue. fprintf ( stderr, "Invalid script switcher: %s\n", token ); } } return ( index == num_modi ) ? -1 : (int) index; }
static void combi_mode_parse_switchers ( Mode *sw ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); char *savept = NULL; // Make a copy, as strtok will modify it. char *switcher_str = g_strdup ( config.combi_modi ); const char * const sep = ","; // Split token on ','. This modifies switcher_str. for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { // Resize and add entry. pd->switchers = (Mode * *) g_realloc ( pd->switchers, sizeof ( Mode* ) * ( pd->num_switchers + 1 ) ); // Window switcher. #ifdef WINDOW_MODE if ( strcasecmp ( token, "window" ) == 0 ) { pd->switchers[pd->num_switchers++] = &window_mode; } else if ( strcasecmp ( token, "windowcd" ) == 0 ) { pd->switchers[pd->num_switchers++] = &window_mode_cd; } else #endif // WINDOW_MODE // SSh dialog if ( strcasecmp ( token, "ssh" ) == 0 ) { pd->switchers[pd->num_switchers++] = &ssh_mode; } // Run dialog else if ( strcasecmp ( token, "run" ) == 0 ) { pd->switchers[pd->num_switchers++] = &run_mode; } else if ( strcasecmp ( token, "drun" ) == 0 ) { pd->switchers[pd->num_switchers++] = &drun_mode; } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { pd->switchers[pd->num_switchers++] = sw; } else{ // Report error, don't continue. fprintf ( stderr, "Invalid script switcher: %s\n", token ); token = NULL; } } // Keybinding. } // Free string that was modified by strtok_r g_free ( switcher_str ); }