|
Packit Service |
f02b19 |
/*
|
|
Packit Service |
f02b19 |
* gnome-keyring
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Copyright (C) 2011 Collabora Ltd
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
f02b19 |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
f02b19 |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
f02b19 |
* the License, or (at your option) any later version.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit Service |
f02b19 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
f02b19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
f02b19 |
* Lesser General Public License for more details.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
f02b19 |
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Author: Stef Walter <stefw@collabora.co.uk>
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include "config.h"
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include "gcr-util.h"
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
#include <string.h>
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/**
|
|
Packit Service |
f02b19 |
* _gcr_util_parse_lines:
|
|
Packit Service |
f02b19 |
* @string: The string to parse lines from, will be modified
|
|
Packit Service |
f02b19 |
* @last_line: Whether or not we should run for last line or not
|
|
Packit Service |
f02b19 |
* @callback: Call for each line
|
|
Packit Service |
f02b19 |
* @user_data: Data for callback
|
|
Packit Service |
f02b19 |
*
|
|
Packit Service |
f02b19 |
* Calls callback for each line. If last_line, also sends the remainder
|
|
Packit Service |
f02b19 |
* data that comes after the last line break. \n and \r\n are line separators.
|
|
Packit Service |
f02b19 |
* Neither are included in data passed to callback.
|
|
Packit Service |
f02b19 |
*/
|
|
Packit Service |
f02b19 |
void
|
|
Packit Service |
f02b19 |
_gcr_util_parse_lines (GString *string, gboolean last_line,
|
|
Packit Service |
f02b19 |
GcrLineCallback callback, gpointer user_data)
|
|
Packit Service |
f02b19 |
{
|
|
Packit Service |
f02b19 |
gchar *ptr;
|
|
Packit Service |
f02b19 |
gchar *prev;
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
g_return_if_fail (string);
|
|
Packit Service |
f02b19 |
g_return_if_fail (callback);
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
/* Print all stderr lines as messages */
|
|
Packit Service |
f02b19 |
while ((ptr = strchr (string->str, '\n')) != NULL) {
|
|
Packit Service |
f02b19 |
*ptr = '\0';
|
|
Packit Service |
f02b19 |
if (ptr != string->str) {
|
|
Packit Service |
f02b19 |
prev = ptr - 1;
|
|
Packit Service |
f02b19 |
if (*prev == '\r')
|
|
Packit Service |
f02b19 |
*prev = '\0';
|
|
Packit Service |
f02b19 |
}
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
(callback) (string->str, user_data);
|
|
Packit Service |
f02b19 |
g_string_erase (string, 0, ptr - string->str + 1);
|
|
Packit Service |
f02b19 |
}
|
|
Packit Service |
f02b19 |
|
|
Packit Service |
f02b19 |
if (last_line && string->len) {
|
|
Packit Service |
f02b19 |
(callback) (string->str, user_data);
|
|
Packit Service |
f02b19 |
g_string_erase (string, 0, string->len);
|
|
Packit Service |
f02b19 |
}
|
|
Packit Service |
f02b19 |
}
|