sync with sylpheed 0.6.3 release
[claws.git] / src / utils.c
index 0ee97f4ab2ef1fa93ef7941a5915606520e65e26..fa1fa5dd6185b37d39ab9a5c7f88450af9ee6345 100644 (file)
@@ -168,7 +168,17 @@ gint strcmp2(const gchar *s1, const gchar *s2)
        else
                return strcmp(s1, s2);
 }
-
+/* strstr with NULL-checking */
+gint strstr2(const gchar *s1, const gchar *s2)
+{
+       if (s1 == NULL || s2 == NULL)
+               return -1;
+       else
+               if( strstr(s1, s2) !=NULL) 
+                return 0;
+                else 
+                return -1;
+}
 /* compare paths */
 gint path_cmp(const gchar *s1, const gchar *s2)
 {
@@ -462,7 +472,7 @@ gboolean is_next_mbs(const wchar_t *s)
 {
        gint mbl;
        const wchar_t *wp;
-       gchar tmp[MB_CUR_MAX];
+       gchar tmp[MB_LEN_MAX];
 
        /* skip head space */
        for (wp = s; *wp != (wchar_t)0 && iswspace(*wp); wp++)
@@ -937,55 +947,45 @@ gboolean is_ascii_str(const guchar *str)
 
 gint get_quote_level(const gchar *str)
 {
-       size_t firstquotepos;
-       size_t lastquotepos = -1;
+       const gchar *first_pos;
+       const gchar *last_pos;
        const gchar *p = str;
-       const gchar *pos;
-       gint quotelevel = -1;
-       gint i = 0;
+       gint quote_level = -1;
 
        /* speed up line processing by only searching to the last '>' */
-       if ((pos = strchr(str, '>')) != NULL) {
-               firstquotepos = pos - str;
-               lastquotepos = strrchr(str, '>') - str + 1;
-
+       if ((first_pos = strchr(str, '>')) != NULL) {
                /* skip a line if it contains a '<' before the initial '>' */
-               if (memchr(str, '<', pos - str) != NULL)
+               if (memchr(str, '<', first_pos - str) != NULL)
                        return -1;
+               last_pos = strrchr(first_pos, '>');
        } else
                return -1;
 
-       while (i < lastquotepos) {
-               while (i < lastquotepos) {
-                       if (isspace(*p) || (*p == '\t')) {
+       while (p <= last_pos) {
+               while (p < last_pos) {
+                       if (isspace(*p))
                                p++;
-                               i++;
-                       } else
+                       else
                                break;
                }
-               if (i >= lastquotepos)
-                       break;
 
                if (*p == '>')
-                       quotelevel++;
-               else if ((*p != '-') && !isspace(*p) && (i < lastquotepos)) {
+                       quote_level++;
+               else if (*p != '-' && !isspace(*p) && p <= last_pos) {
                        /* any characters are allowed except '-' and space */
-                       while ((*p != '-') && (*p != '>') && !isspace(*p) &&
-                              (i < lastquotepos)) {
+                       while (*p != '-' && *p != '>' && !isspace(*p) &&
+                              p < last_pos)
                                p++;
-                               i++;
-                       }
                        if (*p == '>')
-                               quotelevel++;
-                       else if ((i >= lastquotepos) || isspace(*p))
+                               quote_level++;
+                       else
                                break;
                }
 
                p++;
-               i++;
        }
 
-       return quotelevel;
+       return quote_level;
 }
 
 GList *uri_list_extract_filenames(const gchar *uri_list)
@@ -1785,7 +1785,28 @@ gint execute_async(gchar *const argv[])
        return 0;
 }
 
-gint execute_command_line(const gchar *cmdline)
+gint execute_sync(gchar *const argv[])
+{
+       pid_t pid;
+
+       if ((pid = fork()) < 0) {
+               perror("fork");
+               return -1;
+       }
+
+       if (pid == 0) {         /* child process */
+               execvp(argv[0], argv);
+
+               perror("execvp");
+               _exit(1);
+       }
+
+       waitpid(pid, NULL, 0);
+
+       return 0;
+}
+
+gint execute_command_line(const gchar *cmdline, gboolean async)
 {
        gchar **argv;
        gint i;
@@ -1807,7 +1828,10 @@ gint execute_command_line(const gchar *cmdline)
                }
        }
 
-       ret = execute_async(argv);
+       if (async)
+               ret = execute_async(argv);
+       else
+               ret = execute_sync(argv);
        g_strfreev(argv);
 
        return ret;
@@ -1832,7 +1856,7 @@ gint open_uri(const gchar *uri, const gchar *cmdline)
                g_snprintf(buf, sizeof(buf), default_cmdline, uri);
        }
 
-       execute_command_line(buf);
+       execute_command_line(buf, TRUE);
 
        return 0;
 }
@@ -2009,7 +2033,7 @@ void log_verbosity_set(gboolean verbose)
                log_verbosity_count--;
 }
 
-void debug_print(const gchar *format, ...)
+void debug_print_real(const gchar *format, ...)
 {
        va_list args;
        gchar buf[BUFFSIZE];