#!/usr/bin/env python3

import sys
import re

def escape(inp):
    return inp

offset = int(sys.argv[2])

print('{| class="wikitable"')
print(f"! <translate><!--T:{offset+1}--> Setting</translate>")
print(f"! <translate><!--T:{offset+2}--> Description</translate>")
print(f"! <translate><!--T:{offset+3}--> Default</translate>")
print(f"! <translate><!--T:{offset+4}--> Min</translate>")
print(f"! <translate><!--T:{offset+5}--> Max</translate>")

settings = {
    "bindaddr": 0,
    "br_cached_best_serverinfo_url": 1,
    "br_demo_fetch_info": 2,
    "br_demo_sort": 3,
    "br_demo_sort_order": 4,
    "br_exclude_string": 5,
    "br_filter_connecting_players": 6,
    "br_filter_country": 7,
    "br_filter_country_index": 8,
    "br_filter_empty": 9,
    "br_filter_exclude_countries": 10,
    "br_filter_exclude_countries_kog": 11,
    "br_filter_exclude_types": 12,
    "br_filter_exclude_types_kog": 13,
    "br_filter_friends": 14,
    "br_filter_full": 15,
    "br_filter_gametype": 16,
    "br_filter_gametype_strict": 17,
    "br_filter_pw": 18,
    "br_filter_serveraddress": 19,
    "br_filter_spectators": 20,
    "br_filter_string": 21,
    "br_filter_unfinished_map": 22,
    "br_indicate_finished": 23,
    "br_location": 24,
    "br_max_requests": 25,
    "br_sort": 26,
    "br_sort_order": 27,
    "cl_afk_emote": 28,
    "cl_airjumpindicator": 29,
    "cl_antiping": 30,
    "cl_antiping_grenade": 31,
    "cl_antiping_gunfire": 32,
    "cl_antiping_limit": 33,
    "cl_antiping_players": 34,
    "cl_antiping_smooth": 35,
    "cl_antiping_weapons": 36,
    "cl_asset_emoticons": 37,
    "cl_asset_extras": 38,
    "cl_asset_game": 39,
    "cl_asset_hud": 40,
    "cl_asset_particles": 41,
    "cl_assets_entities": 42,
    "cl_authed_player_color": 43,
    "cl_auto_csv": 44,
    "cl_auto_csv_max": 45,
    "cl_auto_demo_max": 46,
    "cl_auto_demo_on_connect": 47,
    "cl_auto_demo_record": 48,
    "cl_auto_race_record": 49,
    "cl_auto_screenshot": 50,
    "cl_auto_screenshot_max": 51,
    "cl_auto_statboard_screenshot": 52,
    "cl_auto_statboard_screenshot_max": 53,
    "cl_autoswitch_weapons": 54,
    "cl_autoswitch_weapons_out_of_ammo": 55,
    "cl_background_color": 56,
    "cl_background_entities": 57,
    "cl_background_entities_color": 58,
    "cl_background_show_tiles_layers": 59,
    "cl_camera_speed": 60,
    "cl_chat_old": 61,
    "cl_chat_reset": 62,
    "cl_chat_teamcolors": 63,
    "cl_config_version": 64,
    "cl_confirm_disconnect_time": 65,
    "cl_confirm_quit_time": 66,
    "cl_contact_port": 67,
    "cl_ddrace_scoreboard": 68,
    "cl_default_zoom": 69,
    "cl_demo_assume_race": 70,
    "cl_demo_keyboard_shortcuts": 71,
    "cl_demo_name": 72,
    "cl_demo_show_speed": 73,
    "cl_demo_slice_begin": 74,
    "cl_demo_slice_end": 75,
    "cl_download_community_skins": 76,
    "cl_download_skins": 77,
    "cl_dummy": 78,
    "cl_dummy_control": 79,
    "cl_dummy_copy_moves": 80,
    "cl_dummy_fire": 81,
    "cl_dummy_hammer": 82,
    "cl_dummy_hook": 83,
    "cl_dummy_jump": 84,
    "cl_dummy_port": 85,
    "cl_dummy_resetonswitch": 86,
    "cl_dummy_restore_weapon": 87,
    "cl_dummy_timeout_code": 88,
    "cl_dyncam": 89,
    "cl_dyncam_deadzone": 90,
    "cl_dyncam_follow_factor": 91,
    "cl_dyncam_max_distance": 92,
    "cl_dyncam_min_distance": 93,
    "cl_dyncam_mousesens": 94,
    "cl_dyncam_smoothness": 95,
    "cl_dyncam_stabilizing": 96,
    "cl_editor": 97,
    "cl_editor_dilate": 98,
    "cl_enable_ping_color": 99,
    "cl_eye_duration": 100,
    "cl_eye_wheel": 101,
    "cl_fat_skins": 102,
    "cl_freezebars_alpha_inside_freeze": 103,
    "cl_friends_ignore_clan": 104,
    "cl_hook_coll_alpha": 105,
    "cl_hook_coll_color_hookable_coll": 106,
    "cl_hook_coll_color_no_coll": 107,
    "cl_hook_coll_color_tee_coll": 108,
    "cl_hook_coll_size": 109,
    "cl_input_fifo": 110,
    "cl_kill_message_highlight_color": 111,
    "cl_kill_message_normal_color": 112,
    "cl_languagefile": 113,
    "cl_laser_door_inner_color": 114,
    "cl_laser_door_outline_color": 115,
    "cl_laser_freeze_inner_color": 116,
    "cl_laser_freeze_outline_color": 117,
    "cl_laser_rifle_inner_color": 118,
    "cl_laser_rifle_outline_color": 119,
    "cl_laser_sg_inner_color": 120,
    "cl_laser_sg_outline_color": 121,
    "cl_limit_max_zoom_level": 122,
    "cl_map_download_connect_timeout_ms": 123,
    "cl_map_download_low_speed_limit": 124,
    "cl_map_download_low_speed_time": 125,
    "cl_map_download_url": 126,
    "cl_menu_map": 127,
    "cl_message_client_color": 128,
    "cl_message_color": 129,
    "cl_message_friend": 130,
    "cl_message_friend_color": 131,
    "cl_message_highlight_color": 132,
    "cl_message_system_color": 133,
    "cl_message_team_color": 134,
    "cl_motd_time": 135,
    "cl_mouse_deadzone": 136,
    "cl_mouse_followfactor": 137,
    "cl_mouse_max_distance": 138,
    "cl_mouse_min_distance": 139,
    "cl_nameplates": 140,
    "cl_nameplates_always": 141,
    "cl_nameplates_clan": 142,
    "cl_nameplates_clan_size": 143,
    "cl_nameplates_friendmark": 144,
    "cl_nameplates_ids": 145,
    "cl_nameplates_own": 146,
    "cl_nameplates_size": 147,
    "cl_nameplates_strong": 148,
    "cl_nameplates_teamcolors": 149,
    "cl_old_gun_position": 150,
    "cl_overlay_entities": 151,
    "cl_port": 152,
    "cl_predict": 153,
    "cl_predict_dummy": 154,
    "cl_predict_freeze": 155,
    "cl_prediction_margin": 156,
    "cl_print_broadcasts": 157,
    "cl_print_motd": 158,
    "cl_race_binds_set": 159,
    "cl_race_ghost": 160,
    "cl_race_ghost_server_control": 161,
    "cl_race_record_server_control": 162,
    "cl_race_save_ghost": 163,
    "cl_race_show_ghost": 164,
    "cl_reconnect_full": 165,
    "cl_reconnect_timeout": 166,
    "cl_refresh_rate": 167,
    "cl_refresh_rate_inactive": 168,
    "cl_replay_length": 169,
    "cl_replays": 170,
    "cl_rotation_radius": 171,
    "cl_rotation_speed": 172,
    "cl_run_on_join": 173,
    "cl_same_clan_color": 174,
    "cl_save_settings": 175,
    "cl_scoreboard_on_death": 176,
    "cl_show_broadcasts": 177,
    "cl_show_chat_friends": 178,
    "cl_show_chat_system": 179,
    "cl_show_direction": 180,
    "cl_show_freeze_bars": 181,
    "cl_show_hook_coll_other": 182,
    "cl_show_hook_coll_own": 183,
    "cl_show_ids": 184,
    "cl_show_local_time_always": 185,
    "cl_show_ninja": 186,
    "cl_show_others": 187,
    "cl_show_others_alpha": 188,
    "cl_show_start_menu_images": 189,
    "cl_show_votes_after_voting": 190,
    "cl_show_welcome": 191,
    "cl_showchat": 192,
    "cl_showemotes": 193,
    "cl_showfps": 194,
    "cl_showhud": 195,
    "cl_showhud_ddrace": 196,
    "cl_showhud_dummy_actions": 197,
    "cl_showhud_healthammo": 198,
    "cl_showhud_jumps_indicator": 199,
    "cl_showhud_player_angle": 200,
    "cl_showhud_player_position": 201,
    "cl_showhud_player_speed": 202,
    "cl_showhud_score": 203,
    "cl_showhud_timer": 204,
    "cl_showkillmessages": 205,
    "cl_shownotifications": 206,
    "cl_showpred": 207,
    "cl_showquads": 208,
    "cl_showrecord": 209,
    "cl_skin_community_download_url": 210,
    "cl_skin_download_url": 211,
    "cl_skin_filter_string": 212,
    "cl_skin_prefix": 213,
    "cl_skip_start_menu": 214,
    "cl_smooth_zoom_time": 215,
    "cl_text_entities": 216,
    "cl_text_entities_size": 217,
    "cl_threadsoundloading": 218,
    "cl_timeout_code": 219,
    "cl_timeout_seed": 220,
    "cl_unpredicted_shadow": 221,
    "cl_vanilla_skins_only": 222,
    "cl_video_crf": 223,
    "cl_video_pausewithdemo": 224,
    "cl_video_preset": 225,
    "cl_video_recorder_fps": 226,
    "cl_video_show_direction": 227,
    "cl_video_show_hook_coll_other": 228,
    "cl_video_showchat": 229,
    "cl_video_showhud": 230,
    "cl_video_sound_enable": 231,
    "cl_warning_teambalance": 232,
    "conn_timeout": 233,
    "conn_timeout_protection": 234,
    "console_enable_colors": 235,
    "console_output_level": 236,
    "dbg_curl": 237,
    "dbg_dummies": 238,
    "dbg_gfx": 239,
    "dbg_graphs": 240,
    "dbg_hitch": 241,
    "dbg_stress": 242,
    "dbg_stress_server": 243,
    "dbg_tuning": 244,
    "debug": 245,
    "dummy_clan": 246,
    "dummy_color_body": 247,
    "dummy_color_feet": 248,
    "dummy_country": 249,
    "dummy_default_eyes": 250,
    "dummy_name": 251,
    "dummy_skin": 252,
    "dummy_use_custom_color": 253,
    "ec_auth_timeout": 254,
    "ec_bantime": 255,
    "ec_bindaddr": 256,
    "ec_output_level": 257,
    "ec_password": 258,
    "ec_port": 259,
    "ed_limit_max_zoom_level": 260,
    "ed_showkeys": 261,
    "ed_smooth_zoom_time": 262,
    "ed_zoom_target": 263,
    "events": 264,
    "gfx_3d_texture_analysis_ran": 265,
    "gfx_3d_texture_analysis_renderer": 266,
    "gfx_3d_texture_analysis_version": 267,
    "gfx_asyncrender_old": 268,
    "gfx_backend": 269,
    "gfx_backgroundrender": 270,
    "gfx_borderless": 271,
    "gfx_color_depth": 272,
    "gfx_desktop_height": 273,
    "gfx_desktop_width": 274,
    "gfx_display_all_video_modes": 275,
    "gfx_driver_is_blocked": 276,
    "gfx_finish": 277,
    "gfx_fsaa_samples": 278,
    "gfx_fullscreen": 279,
    "gfx_gl_major": 280,
    "gfx_gl_minor": 281,
    "gfx_gl_patch": 282,
    "gfx_gl_texture_lod_bias": 283,
    "gfx_gpu_name": 284,
    "gfx_high_detail": 285,
    "gfx_highdpi": 286,
    "gfx_noclip": 287,
    "gfx_quad_as_triangle": 288,
    "gfx_refresh_rate": 289,
    "gfx_render_thread_count": 290,
    "gfx_screen": 291,
    "gfx_screen_height": 292,
    "gfx_screen_refresh_rate": 293,
    "gfx_screen_width": 294,
    "gfx_text_overlay": 295,
    "gfx_vsync": 296,
    "http_allow_insecure": 297,
    "inp_controller_absolute": 298,
    "inp_controller_enable": 299,
    "inp_controller_guid": 300,
    "inp_controller_sens": 301,
    "inp_controller_tolerance": 302,
    "inp_controller_x": 303,
    "inp_controller_y": 304,
    "inp_ignored_modifiers": 305,
    "inp_ime_native_ui": 306,
    "inp_mousesens": 307,
    "inp_translated_keys": 308,
    "logappend": 309,
    "logfile": 310,
    "loglevel": 311,
    "password": 312,
    "player_clan": 313,
    "player_color_body": 314,
    "player_color_feet": 315,
    "player_country": 316,
    "player_default_eyes": 317,
    "player_name": 318,
    "player_skin": 319,
    "player_use_custom_color": 320,
    "snd_ambient_volume": 321,
    "snd_background_music_volume": 322,
    "snd_buffer_size": 323,
    "snd_chat": 324,
    "snd_chat_volume": 325,
    "snd_enable": 326,
    "snd_enable_music": 327,
    "snd_game": 328,
    "snd_game_volume": 329,
    "snd_gun": 330,
    "snd_highlight": 331,
    "snd_long_pain": 332,
    "snd_nonactive_mute": 333,
    "snd_rate": 334,
    "snd_servermessage": 335,
    "snd_team_chat": 336,
    "snd_volume": 337,
    "steam_name": 338,
    "sv_announcement_filename": 339,
    "sv_announcement_interval": 340,
    "sv_announcement_random": 341,
    "sv_auto_demo_max": 342,
    "sv_auto_demo_record": 343,
    "sv_banned_versions": 344,
    "sv_chat_delay": 345,
    "sv_chat_initial_delay": 346,
    "sv_chat_penalty": 347,
    "sv_chat_threshold": 348,
    "sv_client_suggestion": 349,
    "sv_client_suggestion_bot": 350,
    "sv_client_suggestion_old": 351,
    "sv_conn_logging_server": 352,
    "sv_connlimit": 353,
    "sv_connlimit_time": 354,
    "sv_ddrace_rules": 355,
    "sv_ddrace_tune_reset": 356,
    "sv_deepfly": 357,
    "sv_default_timer_type": 358,
    "sv_demo_chat": 359,
    "sv_destroy_bullets_on_death": 360,
    "sv_destroy_lasers_on_death": 361,
    "sv_dnsbl": 362,
    "sv_dnsbl_ban": 363,
    "sv_dnsbl_chat": 364,
    "sv_dnsbl_host": 365,
    "sv_dnsbl_key": 366,
    "sv_dnsbl_vote": 367,
    "sv_dragger_range": 368,
    "sv_emoticon_delay": 369,
    "sv_emotional_tees": 370,
    "sv_endless_drag": 371,
    "sv_endless_super_hook": 372,
    "sv_eye_emote_change_delay": 373,
    "sv_fast_download": 374,
    "sv_freeze_delay": 375,
    "sv_hide_score": 376,
    "sv_high_bandwidth": 377,
    "sv_hit": 378,
    "sv_hostname": 379,
    "sv_inactivekick": 380,
    "sv_inactivekick_time": 381,
    "sv_info_change_delay": 382,
    "sv_input_fifo": 383,
    "sv_invite": 384,
    "sv_invite_frequency": 385,
    "sv_ipv4only": 386,
    "sv_join_vote_delay": 387,
    "sv_kill_delay": 388,
    "sv_kill_protection": 389,
    "sv_map": 390,
    "sv_map_vote": 391,
    "sv_map_window": 392,
    "sv_mapupdaterate": 393,
    "sv_max_afk_time": 394,
    "sv_max_clients": 395,
    "sv_max_clients_per_ip": 396,
    "sv_max_team_size": 397,
    "sv_min_team_size": 398,
    "sv_motd": 399,
    "sv_name": 400,
    "sv_nameless_score": 401,
    "sv_netlimit": 402,
    "sv_netlimit_alpha": 403,
    "sv_no_weak_hook": 404,
    "sv_old_laser": 405,
    "sv_old_teleport_hook": 406,
    "sv_old_teleport_weapons": 407,
    "sv_pause_frequency": 408,
    "sv_pause_messages": 409,
    "sv_pauseable": 410,
    "sv_plasma_per_sec": 411,
    "sv_plasma_range": 412,
    "sv_player_demo_record": 413,
    "sv_port": 414,
    "sv_practice": 415,
    "sv_rcon_bantime": 416,
    "sv_rcon_helper_password": 417,
    "sv_rcon_max_tries": 418,
    "sv_rcon_mod_password": 419,
    "sv_rcon_password": 420,
    "sv_rcon_vote": 421,
    "sv_region_name": 422,
    "sv_register": 423,
    "sv_register_extra": 424,
    "sv_register_url": 425,
    "sv_rejoin_team_0": 426,
    "sv_reload_when_empty": 427,
    "sv_rescue": 428,
    "sv_rescue_delay": 429,
    "sv_reserved_slots": 430,
    "sv_reserved_slots_auth_level": 431,
    "sv_reserved_slots_pass": 432,
    "sv_reset_file": 433,
    "sv_reset_pickups": 434,
    "sv_rules_line1": 435,
    "sv_rules_line10": 436,
    "sv_rules_line2": 437,
    "sv_rules_line3": 438,
    "sv_rules_line4": 439,
    "sv_rules_line5": 440,
    "sv_rules_line6": 441,
    "sv_rules_line7": 442,
    "sv_rules_line8": 443,
    "sv_rules_line9": 444,
    "sv_save_worse_scores": 445,
    "sv_savegames": 446,
    "sv_saveswapgames_delay": 447,
    "sv_saveswapgames_penalty": 448,
    "sv_send_votes_per_tick": 449,
    "sv_server_info_per_second": 450,
    "sv_server_type": 451,
    "sv_shotgun_bullet_sound": 452,
    "sv_show_all_default": 453,
    "sv_show_others": 454,
    "sv_show_others_default": 455,
    "sv_shutdown_when_empty": 456,
    "sv_sixup": 457,
    "sv_skill_level": 458,
    "sv_slash_me": 459,
    "sv_solo_server": 460,
    "sv_spam_mute_duration": 461,
    "sv_spamprotection": 462,
    "sv_spectator_slots": 463,
    "sv_sql_queries_delay": 464,
    "sv_sql_servername": 465,
    "sv_sqlite_file": 466,
    "sv_strict_spectate_mode": 467,
    "sv_suicide_penalty": 468,
    "sv_swap": 469,
    "sv_swap_timeout": 470,
    "sv_team": 471,
    "sv_team_change_delay": 472,
    "sv_tee_historian": 473,
    "sv_tele_others_auth_level": 474,
    "sv_teleport_hold_hook": 475,
    "sv_teleport_lose_weapons": 476,
    "sv_test_cmds": 477,
    "sv_time_in_broadcast_interval": 478,
    "sv_tournament_mode": 479,
    "sv_tune_reset": 480,
    "sv_use_sql": 481,
    "sv_use_upnp": 482,
    "sv_van_conn_per_second": 483,
    "sv_vanilla_antispoof": 484,
    "sv_vote_delay": 485,
    "sv_vote_kick": 486,
    "sv_vote_kick_bantime": 487,
    "sv_vote_kick_delay": 488,
    "sv_vote_kick_min": 489,
    "sv_vote_majority": 490,
    "sv_vote_map_delay": 491,
    "sv_vote_max_total": 492,
    "sv_vote_pause": 493,
    "sv_vote_pause_time": 494,
    "sv_vote_spectate": 495,
    "sv_vote_spectate_rejoindelay": 496,
    "sv_vote_time": 497,
    "sv_vote_veto_time": 498,
    "sv_vote_yes_percentage": 499,
    "sv_warmup": 500,
    "sv_welcome": 501,
    "ui_close_window_after_changing_setting": 502,
    "ui_color": 503,
    "ui_colorize_gametype": 504,
    "ui_colorize_ping": 505,
    "ui_controller_sens": 506,
    "ui_demo_selected": 507,
    "ui_mousesens": 508,
    "ui_page": 509,
    "ui_server_address": 510,
    "ui_settings_page": 511,
    "ui_smooth_scroll_time": 512,
    "ui_toolbox_page": 513,
    "ui_unread_news": 514,
    # add new settings below here with increasing numbers
    "sv_emoticon_ms_delay": 515,
    "sv_global_emoticon_ms_delay": 516,
    "cl_multiview_sensitivity": 517,
    "cl_multiview_use_freeview": 518,
    "cl_multiview_zoom_smoothness": 519,
    "stdout_output_level": 520,
    "ed_autosave_interval": 521,
    "ed_autosave_max": 522,
    "cl_video_pause_on_start": 523,
}

names = {}
results = []

def getValue(x):
    return escape(x.lstrip()).replace("SERVERINFO_LEVEL_MIN", "0").replace("SERVERINFO_LEVEL_MAX", "2").replace("MAX_CLIENTS", "64")

for line in sys.stdin:
  if sys.argv[1] not in line:
    continue

  x = re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', line)
  y = line.split('"')
  name = x[1].lstrip()
  idx = offset + 100 + settings[name] * 5

  if "MACRO_CONFIG_STR" in line:
    result = (escape(name), idx, escape(y[-2]), getValue(x[3].lstrip()), "", "")
  elif "MACRO_CONFIG_INT" in line:
    result = (escape(name), idx, escape(y[-2]), getValue(x[2].lstrip()), getValue(x[3]), getValue(x[4]))
  elif "MACRO_CONFIG_COL" in line:
    result = (escape(name), idx, escape(y[-2]), getValue(x[2].lstrip()), "", "")

  line = "|-\n"
  if y[-2].strip() == "":
      line += f"| {result[0]}\n| {result[2]}\n| {result[3]}\n| {result[4]}\n| {result[5]}"
  else:
      line += "| %s\n| <translate><!--T:%s--> %s</translate>\n| %s\n| %s\n| %s" % result

  if name in names:
    # Always use the last one we find, first ones are platform specific ifdefs
    results[names[name]] = line
  else:
    names[name] = len(results)
    results.append(line)

for line in results:
  print(line)

print('|}')
