summaryrefslogtreecommitdiff
path: root/gtk/gtkprintunixdialog.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2007-04-24 20:16:35 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2007-04-24 20:16:35 +0000
commit8f409578f267f4da34ffe57c26032acc6706bde7 (patch)
tree92479da91e0d856901a1df7883934ecfa61e74e8 /gtk/gtkprintunixdialog.c
parent18a9c78bf36be6e6c84a7fa8259b9daa4e8eb96f (diff)
downloadgtk+-8f409578f267f4da34ffe57c26032acc6706bde7.tar.gz
Parse half-open ranges like -2 or 3-, and be a bit more liberal about
2007-04-24 Matthias Clasen <mclasen@redhat.com> * gtk/gtkprintunixdialog.c (dialog_get_page_ranges): Parse half-open ranges like -2 or 3-, and be a bit more liberal about whitespace. (dialog_set_page_ranges): Support half-open ranges. * gtk/gtkprintoperation.c (print_pages_idle): Substitute the number of pages in half-open ranges. (preview_iface_is_selected): Support half-open ranges here, too. svn path=/trunk/; revision=17627
Diffstat (limited to 'gtk/gtkprintunixdialog.c')
-rw-r--r--gtk/gtkprintunixdialog.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 47d6c22e7a..e72d7c4b96 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -1652,22 +1652,33 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
p = text;
while (*p)
{
- start = (int)strtol (p, &next, 10);
- if (start < 1)
- start = 1;
+ while (isspace (*p)) p++;
+
+ if (*p == '-')
+ {
+ /* a half-open range like -2 */
+ start = 1;
+ }
+ else
+ {
+ start = (int)strtol (p, &next, 10);
+ if (start < 1)
+ start = 1;
+ p = next;
+ }
+
end = start;
- if (next != p)
- {
- p = next;
+ while (isspace (*p)) p++;
- if (*p == '-')
- {
- p++;
- end = (int)strtol (p, NULL, 10);
- if (end < start)
- end = start;
- }
+ if (*p == '-')
+ {
+ p++;
+ end = (int)strtol (p, &next, 10);
+ if (next == p) /* a half-open range like 2- */
+ end = 0;
+ else if (end < start)
+ end = start;
}
ranges[i].start = start - 1;
@@ -1685,6 +1696,9 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
*n_ranges_out = i;
+ for (i = 0; i < *n_ranges_out; i++)
+ g_print ("[%d, %d]\n", ranges[i].start, ranges[i].end);
+
return ranges;
}
@@ -1702,6 +1716,8 @@ dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
g_string_append_printf (s, "%d", ranges[i].start + 1);
if (ranges[i].end > ranges[i].start)
g_string_append_printf (s, "-%d", ranges[i].end + 1);
+ else if (ranges[i].end == -1)
+ g_string_append (s, "-");
if (i != n_ranges - 1)
g_string_append (s, ",");