This is very similar to what my frontend does (JFront).
I keep track of properties of the game, then copy/paste the default.cfg based on they type of game.
IE, you can configure all 4way games once. Take a 4way game, go into the config, and press create 4_player button... Run the game. Configure as default, and exit. From now on, any game that has a 4way controller, it will copy that default.cfg to mame before starting.
It also allows you to store different configs based on what control panel your running.
For instance... I have a 'classic' control panel. It has a 4way, then buttons for asteroids, then a 4way diagonal (qbert).
So for my 4player controlpanel, my 4way games are set to use player two (middle joystick) and up notleft notright setup. Then when I change to my classic control panel, it uses the 4 way joystick. Then for qbert, I used the config for this game (since that and congobongo are the only ones to use that joystick).
Other settings.
2player_8way_6buttons to swap all streetfighter kicks and punches (because I still say mame got it wrong... punchs on top). So one setting and their all done.
1player, 2player, 3player - these all have player 1 as the second joystick (middle left). ignoring my far left joystick.
plus you can configure them. So I have a property input=MK for all the mortal kombat games just for them.
would this solve your problems?