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