added pdf_compare_obj().

Fri, 07 Mar 2003 11:02:31 +0000

author
eric
date
Fri, 07 Mar 2003 11:02:31 +0000
changeset 82
abb03c7f4aab
parent 81
0fc65859d436
child 83
bbc7dd27aa5b

added pdf_compare_obj().

pdf_prim.c file | annotate | diff | revisions
pdf_prim.h file | annotate | diff | revisions
     1.1 diff -r 0fc65859d436 -r abb03c7f4aab pdf_prim.c
     1.2 --- a/pdf_prim.c	Fri Mar 07 11:02:12 2003 +0000
     1.3 +++ b/pdf_prim.c	Fri Mar 07 11:02:31 2003 +0000
     1.4 @@ -4,7 +4,7 @@
     1.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.6   *
     1.7   * PDF routines
     1.8 - * $Id: pdf_prim.c,v 1.6 2003/03/04 17:58:36 eric Exp $
     1.9 + * $Id: pdf_prim.c,v 1.7 2003/03/07 03:02:31 eric Exp $
    1.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    1.11   *
    1.12   * This program is free software; you can redistribute it and/or modify
    1.13 @@ -357,6 +357,38 @@
    1.14  }
    1.15  
    1.16  
    1.17 +int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2)
    1.18 +{
    1.19 +  if (o1->type == PT_IND_REF)
    1.20 +    o1 = pdf_deref_ind_obj (o1);
    1.21 +
    1.22 +  if (o2->type == PT_IND_REF)
    1.23 +    o2 = pdf_deref_ind_obj (o2);
    1.24 +
    1.25 +  pdf_assert (o1->type == o2->type);
    1.26 +
    1.27 +  switch (o1->type)
    1.28 +    {
    1.29 +    case PT_INTEGER:
    1.30 +      if (o1->val.integer < o2->val.integer)
    1.31 +	return (-1);
    1.32 +      if (o1->val.integer > o2->val.integer)
    1.33 +	return (1);
    1.34 +      return (0);
    1.35 +    case PT_REAL:
    1.36 +      if (o1->val.real < o2->val.real)
    1.37 +	return (-1);
    1.38 +      if (o1->val.real > o2->val.real)
    1.39 +	return (1);
    1.40 +      return (0);
    1.41 +    case PT_STRING:
    1.42 +      return (strcmp (o1->val.string, o2->val.string));
    1.43 +    default:
    1.44 +      pdf_fatal ("invalid object type for comparison\n");
    1.45 +    }
    1.46 +}
    1.47 +
    1.48 +
    1.49  static int name_char_needs_quoting (char c)
    1.50  {
    1.51    return ((c < '!')  || (c > '~')  || (c == '/') || (c == '\\') ||
     2.1 diff -r 0fc65859d436 -r abb03c7f4aab pdf_prim.h
     2.2 --- a/pdf_prim.h	Fri Mar 07 11:02:12 2003 +0000
     2.3 +++ b/pdf_prim.h	Fri Mar 07 11:02:31 2003 +0000
     2.4 @@ -4,7 +4,7 @@
     2.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     2.6   *
     2.7   * PDF routines
     2.8 - * $Id: pdf_prim.h,v 1.5 2003/03/04 17:58:36 eric Exp $
     2.9 + * $Id: pdf_prim.h,v 1.6 2003/03/07 03:02:31 eric Exp $
    2.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    2.11   *
    2.12   * This program is free software; you can redistribute it and/or modify
    2.13 @@ -88,6 +88,10 @@
    2.14  void pdf_set_real (struct pdf_obj *obj, double val);
    2.15  
    2.16  
    2.17 +/* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */
    2.18 +int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2);
    2.19 +
    2.20 +
    2.21  /* The callback will be called when the stream data is to be written to the
    2.22     file.  app_data will be passed as an argument to the callback. */
    2.23  struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,