Fix declaration-after-statement errors in ibus code.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 21 Aug 2014 23:22:46 -0400
changeset 91088200b1bdcf83
parent 9107 6485aa2e421c
child 9112 345a7d41dda9
Fix declaration-after-statement errors in ibus code.
src/core/linux/SDL_ibus.c
     1.1 --- a/src/core/linux/SDL_ibus.c	Thu Aug 21 23:15:17 2014 -0400
     1.2 +++ b/src/core/linux/SDL_ibus.c	Thu Aug 21 23:22:46 2014 -0400
     1.3 @@ -71,6 +71,7 @@
     1.4  {
     1.5      /* The text we need is nested weirdly, use dbus-monitor to see the structure better */
     1.6      const char *text = NULL;
     1.7 +    const char *struct_id = NULL;
     1.8      DBusMessageIter sub1, sub2;
     1.9  
    1.10      if (dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
    1.11 @@ -89,7 +90,6 @@
    1.12          return NULL;
    1.13      }
    1.14      
    1.15 -    const char *struct_id = NULL;
    1.16      dbus->message_iter_get_basic(&sub2, &struct_id);
    1.17      if (!struct_id || SDL_strncmp(struct_id, "IBusText", sizeof("IBusText")) != 0) {
    1.18          return NULL;
    1.19 @@ -129,10 +129,11 @@
    1.20          
    1.21      if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "CommitText")) {
    1.22          DBusMessageIter iter;
    1.23 +        const char *text;
    1.24  
    1.25          dbus->message_iter_init(msg, &iter);
    1.26          
    1.27 -        const char *text = IBus_GetVariantText(conn, &iter, dbus);
    1.28 +        text = IBus_GetVariantText(conn, &iter, dbus);
    1.29          if (text && *text) {
    1.30              char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
    1.31              size_t text_bytes = SDL_strlen(text), i = 0;
    1.32 @@ -150,8 +151,10 @@
    1.33      
    1.34      if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "UpdatePreeditText")) {
    1.35          DBusMessageIter iter;
    1.36 +        const char *text;
    1.37 +
    1.38          dbus->message_iter_init(msg, &iter);
    1.39 -        const char *text = IBus_GetVariantText(conn, &iter, dbus);
    1.40 +        text = IBus_GetVariantText(conn, &iter, dbus);
    1.41          
    1.42          if (text && *text) {
    1.43              char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
    1.44 @@ -185,14 +188,15 @@
    1.45  static char *
    1.46  IBus_ReadAddressFromFile(const char *file_path)
    1.47  {
    1.48 -    FILE *addr_file = fopen(file_path, "r");
    1.49 +    char addr_buf[1024];
    1.50 +    SDL_bool success = SDL_FALSE;
    1.51 +    FILE *addr_file;
    1.52 +
    1.53 +    addr_file = fopen(file_path, "r");
    1.54      if (!addr_file) {
    1.55          return NULL;
    1.56      }
    1.57  
    1.58 -    char addr_buf[1024];
    1.59 -    SDL_bool success = SDL_FALSE;
    1.60 -
    1.61      while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
    1.62          if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
    1.63              size_t sz = SDL_strlen(addr_buf);
    1.64 @@ -215,27 +219,34 @@
    1.65  static char *
    1.66  IBus_GetDBusAddressFilename(void)
    1.67  {
    1.68 +    SDL_DBusContext *dbus;
    1.69 +    const char *disp_env;
    1.70 +    char config_dir[PATH_MAX];
    1.71 +    char *display = NULL;
    1.72 +    const char *addr;
    1.73 +    const char *conf_env;
    1.74 +    char *key;
    1.75 +    char file_path[PATH_MAX];
    1.76 +
    1.77      if (ibus_addr_file) {
    1.78          return SDL_strdup(ibus_addr_file);
    1.79      }
    1.80      
    1.81 -    SDL_DBusContext *dbus = SDL_DBus_GetContext();
    1.82 -    
    1.83 +    dbus = SDL_DBus_GetContext();
    1.84      if (!dbus) {
    1.85          return NULL;
    1.86      }
    1.87      
    1.88      /* Use this environment variable if it exists. */
    1.89 -    const char *addr = SDL_getenv("IBUS_ADDRESS");
    1.90 +    addr = SDL_getenv("IBUS_ADDRESS");
    1.91      if (addr && *addr) {
    1.92          return SDL_strdup(addr);
    1.93      }
    1.94      
    1.95      /* Otherwise, we have to get the hostname, display, machine id, config dir
    1.96         and look up the address from a filepath using all those bits, eek. */
    1.97 -    const char *disp_env = SDL_getenv("DISPLAY");
    1.98 -    char *display = NULL;
    1.99 -    
   1.100 +    disp_env = SDL_getenv("DISPLAY");
   1.101 +
   1.102      if (!disp_env || !*disp_env) {
   1.103          display = SDL_strdup(":0.0");
   1.104      } else {
   1.105 @@ -262,10 +273,9 @@
   1.106          host = "unix";
   1.107      }
   1.108          
   1.109 -    char config_dir[PATH_MAX];
   1.110      SDL_memset(config_dir, 0, sizeof(config_dir));
   1.111      
   1.112 -    const char *conf_env = SDL_getenv("XDG_CONFIG_HOME");
   1.113 +    conf_env = SDL_getenv("XDG_CONFIG_HOME");
   1.114      if (conf_env && *conf_env) {
   1.115          SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
   1.116      } else {
   1.117 @@ -277,9 +287,8 @@
   1.118          SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
   1.119      }
   1.120      
   1.121 -    char *key = dbus->get_local_machine_id();
   1.122 -    
   1.123 -    char file_path[PATH_MAX];
   1.124 +    key = dbus->get_local_machine_id();
   1.125 +
   1.126      SDL_memset(file_path, 0, sizeof(file_path));
   1.127      SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s", 
   1.128                                                 config_dir, key, host, disp_num);
   1.129 @@ -329,7 +338,8 @@
   1.130  {
   1.131      const char *path = NULL;
   1.132      SDL_bool result = SDL_FALSE;
   1.133 -    
   1.134 +    DBusMessage *msg;
   1.135 +
   1.136      ibus_conn = dbus->connection_open_private(addr, NULL);
   1.137  
   1.138      if (!ibus_conn) {
   1.139 @@ -345,10 +355,7 @@
   1.140      
   1.141      dbus->connection_flush(ibus_conn);
   1.142  
   1.143 -    DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
   1.144 -                                                     IBUS_PATH,
   1.145 -                                                     IBUS_INTERFACE,
   1.146 -                                                     "CreateInputContext");
   1.147 +    msg = dbus->message_new_method_call(IBUS_SERVICE, IBUS_PATH, IBUS_INTERFACE, "CreateInputContext");
   1.148      if (msg) {
   1.149          const char *client_name = "SDL2_Application";
   1.150          dbus->message_append_args(msg,
   1.151 @@ -443,20 +450,23 @@
   1.152      
   1.153      if (dbus) {
   1.154          char *addr_file = IBus_GetDBusAddressFilename();
   1.155 +        char *addr;
   1.156 +        char *addr_file_dir;
   1.157 +
   1.158          if (!addr_file) {
   1.159              return SDL_FALSE;
   1.160          }
   1.161          
   1.162          ibus_addr_file = SDL_strdup(addr_file);
   1.163          
   1.164 -        char *addr = IBus_ReadAddressFromFile(addr_file);
   1.165 +        addr = IBus_ReadAddressFromFile(addr_file);
   1.166          
   1.167          if (inotify_fd < 0) {
   1.168              inotify_fd = inotify_init();
   1.169              fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
   1.170          }
   1.171          
   1.172 -        char *addr_file_dir = SDL_strrchr(addr_file, '/');
   1.173 +        addr_file_dir = SDL_strrchr(addr_file, '/');
   1.174          if (addr_file_dir) {
   1.175              *addr_file_dir = 0;
   1.176          }
   1.177 @@ -474,6 +484,8 @@
   1.178  void
   1.179  SDL_IBus_Quit(void)
   1.180  {   
   1.181 +    SDL_DBusContext *dbus;
   1.182 +
   1.183      if (input_ctx_path) {
   1.184          SDL_free(input_ctx_path);
   1.185          input_ctx_path = NULL;
   1.186 @@ -484,7 +496,7 @@
   1.187          ibus_addr_file = NULL;
   1.188      }
   1.189      
   1.190 -    SDL_DBusContext *dbus = SDL_DBus_GetContext();
   1.191 +    dbus = SDL_DBus_GetContext();
   1.192      
   1.193      if (dbus && ibus_conn) {
   1.194          dbus->connection_close(ibus_conn);
   1.195 @@ -578,11 +590,13 @@
   1.196  void
   1.197  SDL_IBus_UpdateTextRect(SDL_Rect *rect)
   1.198  {
   1.199 +    SDL_Window *focused_win = SDL_GetKeyboardFocus();
   1.200 +    int x = 0, y = 0;
   1.201 +    SDL_DBusContext *dbus;
   1.202 +
   1.203      if (rect) {
   1.204          SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
   1.205      }
   1.206 -    
   1.207 -    SDL_Window *focused_win = SDL_GetKeyboardFocus();
   1.208  
   1.209      if (!focused_win) {
   1.210          return;
   1.211 @@ -594,9 +608,7 @@
   1.212      if (!SDL_GetWindowWMInfo(focused_win, &info)) {
   1.213          return;
   1.214      }
   1.215 -    
   1.216 -    int x = 0, y = 0;
   1.217 -    
   1.218 +
   1.219      SDL_GetWindowPosition(focused_win, &x, &y);
   1.220     
   1.221  #if SDL_VIDEO_DRIVER_X11    
   1.222 @@ -615,7 +627,7 @@
   1.223      x += ibus_cursor_rect.x;
   1.224      y += ibus_cursor_rect.y;
   1.225          
   1.226 -    SDL_DBusContext *dbus = SDL_DBus_GetContext();
   1.227 +    dbus = SDL_DBus_GetContext();
   1.228      
   1.229      if (IBus_CheckConnection(dbus)) {
   1.230          DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,