[poppler] cpp/tests goo/gtypes.h utils/CMakeLists.txt utils/Makefile.am utils/parseargs.c utils/parseargs.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Aug 31 14:16:41 PDT 2010


 cpp/tests/CMakeLists.txt |    2 
 cpp/tests/Makefile.am    |    2 
 goo/gtypes.h             |    7 -
 utils/CMakeLists.txt     |    2 
 utils/Makefile.am        |    2 
 utils/parseargs.c        |  208 -----------------------------------------------
 utils/parseargs.cc       |  208 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 216 insertions(+), 215 deletions(-)

New commits:
commit ae79fc504c5424be2fa21dbc5498ced4db6e5dd3
Author: Albert Astals Cid <aacid at kde.org>
Date:   Tue Aug 31 22:14:57 2010 +0100

    Make GBool a bool instead of an int
    
    Passes the regression tests and might make things faster and use a bit
    less memory

diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt
index f718290..85e20fb 100644
--- a/cpp/tests/CMakeLists.txt
+++ b/cpp/tests/CMakeLists.txt
@@ -18,5 +18,5 @@ macro(CPP_ADD_SIMPLETEST exe)
 endmacro(CPP_ADD_SIMPLETEST)
 
 
-cpp_add_simpletest(poppler-dump poppler-dump.cpp ${CMAKE_SOURCE_DIR}/utils/parseargs.c)
+cpp_add_simpletest(poppler-dump poppler-dump.cpp ${CMAKE_SOURCE_DIR}/utils/parseargs.cc)
 target_link_libraries(poppler-dump poppler)
diff --git a/cpp/tests/Makefile.am b/cpp/tests/Makefile.am
index 5066889..87a4f7a 100644
--- a/cpp/tests/Makefile.am
+++ b/cpp/tests/Makefile.am
@@ -14,7 +14,7 @@ noinst_PROGRAMS =				\
 	poppler-dump
 
 poppler_dump_SOURCES = \
-	$(top_srcdir)/utils/parseargs.c		\
+	$(top_srcdir)/utils/parseargs.cc	\
 	poppler-dump.cpp
 poppler_dump_LDADD = $(LDADDS)
 
diff --git a/goo/gtypes.h b/goo/gtypes.h
index a6887ad..b7a2dd2 100644
--- a/goo/gtypes.h
+++ b/goo/gtypes.h
@@ -14,6 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2010 Patrick Spendrin <ps_ml at gmx.de>
+// Copyright (C) 2010 Albert Astals Cid <aacid at kde.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -27,9 +28,9 @@
  * These have stupid names to avoid conflicts with some (but not all)
  * C++ compilers which define them.
  */
-typedef int GBool;
-#define gTrue 1
-#define gFalse 0
+typedef bool GBool;
+#define gTrue true
+#define gFalse false
 
 #ifdef _MSC_VER
 #pragma warning(disable: 4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index f8e8f4c..7b44b05 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -1,6 +1,6 @@
 
 set(common_srcs
-  parseargs.c
+  parseargs.cc
 )
 set(common_libs
   poppler
diff --git a/utils/Makefile.am b/utils/Makefile.am
index e57c71b..56f2cfd 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -57,7 +57,7 @@ dist_man1_MANS =				\
 	pdftohtml.1				\
 	$(pdftoppm_manpage)
 
-common = parseargs.c parseargs.h
+common = parseargs.cc parseargs.h
 
 pdffonts_SOURCES =				\
 	pdffonts.cc				\
diff --git a/utils/parseargs.c b/utils/parseargs.c
deleted file mode 100644
index c5f3007..0000000
--- a/utils/parseargs.c
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * parseargs.h
- *
- * Command line argument parser.
- *
- * Copyright 1996-2003 Glyph & Cog, LLC
- */
-
-/*========================================================================
-
- Modified under the Poppler project - http://poppler.freedesktop.org
-
- Poppler project changes to this file are under the GPLv2 or later license
-
- All changes made under the Poppler project to this file are licensed
- under GPL version 2 or later
-
- Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
-
- To see a description of the changes please see the Changelog file that
- came with your tarball or type make ChangeLog if you are building from git
-
-========================================================================*/
-
-#include <stdio.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include "parseargs.h"
-
-#include "goo/gstrtod.h"
-
-static const ArgDesc *findArg(const ArgDesc *args, char *arg);
-static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]);
-
-GBool parseArgs(const ArgDesc *args, int *argc, char *argv[]) {
-  const ArgDesc *arg;
-  int i, j;
-  GBool ok;
-
-  ok = gTrue;
-  i = 1;
-  while (i < *argc) {
-    if (!strcmp(argv[i], "--")) {
-      --*argc;
-      for (j = i; j < *argc; ++j)
-	argv[j] = argv[j+1];
-      break;
-    } else if ((arg = findArg(args, argv[i]))) {
-      if (!grabArg(arg, i, argc, argv))
-	ok = gFalse;
-    } else {
-      ++i;
-    }
-  }
-  return ok;
-}
-
-void printUsage(char *program, char *otherArgs, const ArgDesc *args) {
-  const ArgDesc *arg;
-  char *typ;
-  int w, w1;
-
-  w = 0;
-  for (arg = args; arg->arg; ++arg) {
-    if ((w1 = strlen(arg->arg)) > w)
-      w = w1;
-  }
-
-  fprintf(stderr, "Usage: %s [options]", program);
-  if (otherArgs)
-    fprintf(stderr, " %s", otherArgs);
-  fprintf(stderr, "\n");
-
-  for (arg = args; arg->arg; ++arg) {
-    fprintf(stderr, "  %s", arg->arg);
-    w1 = 9 + w - strlen(arg->arg);
-    switch (arg->kind) {
-    case argInt:
-    case argIntDummy:
-      typ = " <int>";
-      break;
-    case argFP:
-    case argFPDummy:
-      typ = " <fp>";
-      break;
-    case argString:
-    case argStringDummy:
-      typ = " <string>";
-      break;
-    case argFlag:
-    case argFlagDummy:
-    default:
-      typ = "";
-      break;
-    }
-    fprintf(stderr, "%-*s", w1, typ);
-    if (arg->usage)
-      fprintf(stderr, ": %s", arg->usage);
-    fprintf(stderr, "\n");
-  }
-}
-
-static const ArgDesc *findArg(const ArgDesc *args, char *arg) {
-  const ArgDesc *p;
-
-  for (p = args; p->arg; ++p) {
-    if (p->kind < argFlagDummy && !strcmp(p->arg, arg))
-      return p;
-  }
-  return NULL;
-}
-
-static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]) {
-  int n;
-  int j;
-  GBool ok;
-
-  ok = gTrue;
-  n = 0;
-  switch (arg->kind) {
-  case argFlag:
-    *(GBool *)arg->val = gTrue;
-    n = 1;
-    break;
-  case argInt:
-    if (i + 1 < *argc && isInt(argv[i+1])) {
-      *(int *)arg->val = atoi(argv[i+1]);
-      n = 2;
-    } else {
-      ok = gFalse;
-      n = 1;
-    }
-    break;
-  case argFP:
-    if (i + 1 < *argc && isFP(argv[i+1])) {
-      *(double *)arg->val = gatof(argv[i+1]);
-      n = 2;
-    } else {
-      ok = gFalse;
-      n = 1;
-    }
-    break;
-  case argString:
-    if (i + 1 < *argc) {
-      strncpy((char *)arg->val, argv[i+1], arg->size - 1);
-      ((char *)arg->val)[arg->size - 1] = '\0';
-      n = 2;
-    } else {
-      ok = gFalse;
-      n = 1;
-    }
-    break;
-  default:
-    fprintf(stderr, "Internal error in arg table\n");
-    n = 1;
-    break;
-  }
-  if (n > 0) {
-    *argc -= n;
-    for (j = i; j < *argc; ++j)
-      argv[j] = argv[j+n];
-  }
-  return ok;
-}
-
-GBool isInt(char *s) {
-  if (*s == '-' || *s == '+')
-    ++s;
-  while (isdigit(*s))
-    ++s;
-  if (*s)
-    return gFalse;
-  return gTrue;
-}
-
-GBool isFP(char *s) {
-  int n;
-
-  if (*s == '-' || *s == '+')
-    ++s;
-  n = 0;
-  while (isdigit(*s)) {
-    ++s;
-    ++n;
-  }
-  if (*s == '.')
-    ++s;
-  while (isdigit(*s)) {
-    ++s;
-    ++n;
-  }
-  if (n > 0 && (*s == 'e' || *s == 'E')) {
-    ++s;
-    if (*s == '-' || *s == '+')
-      ++s;
-    n = 0;
-    if (!isdigit(*s))
-      return gFalse;
-    do {
-      ++s;
-    } while (isdigit(*s));
-  }
-  if (*s)
-    return gFalse;
-  return gTrue;
-}
diff --git a/utils/parseargs.cc b/utils/parseargs.cc
new file mode 100644
index 0000000..c5f3007
--- /dev/null
+++ b/utils/parseargs.cc
@@ -0,0 +1,208 @@
+/*
+ * parseargs.h
+ *
+ * Command line argument parser.
+ *
+ * Copyright 1996-2003 Glyph & Cog, LLC
+ */
+
+/*========================================================================
+
+ Modified under the Poppler project - http://poppler.freedesktop.org
+
+ Poppler project changes to this file are under the GPLv2 or later license
+
+ All changes made under the Poppler project to this file are licensed
+ under GPL version 2 or later
+
+ Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
+
+ To see a description of the changes please see the Changelog file that
+ came with your tarball or type make ChangeLog if you are building from git
+
+========================================================================*/
+
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "parseargs.h"
+
+#include "goo/gstrtod.h"
+
+static const ArgDesc *findArg(const ArgDesc *args, char *arg);
+static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]);
+
+GBool parseArgs(const ArgDesc *args, int *argc, char *argv[]) {
+  const ArgDesc *arg;
+  int i, j;
+  GBool ok;
+
+  ok = gTrue;
+  i = 1;
+  while (i < *argc) {
+    if (!strcmp(argv[i], "--")) {
+      --*argc;
+      for (j = i; j < *argc; ++j)
+	argv[j] = argv[j+1];
+      break;
+    } else if ((arg = findArg(args, argv[i]))) {
+      if (!grabArg(arg, i, argc, argv))
+	ok = gFalse;
+    } else {
+      ++i;
+    }
+  }
+  return ok;
+}
+
+void printUsage(char *program, char *otherArgs, const ArgDesc *args) {
+  const ArgDesc *arg;
+  char *typ;
+  int w, w1;
+
+  w = 0;
+  for (arg = args; arg->arg; ++arg) {
+    if ((w1 = strlen(arg->arg)) > w)
+      w = w1;
+  }
+
+  fprintf(stderr, "Usage: %s [options]", program);
+  if (otherArgs)
+    fprintf(stderr, " %s", otherArgs);
+  fprintf(stderr, "\n");
+
+  for (arg = args; arg->arg; ++arg) {
+    fprintf(stderr, "  %s", arg->arg);
+    w1 = 9 + w - strlen(arg->arg);
+    switch (arg->kind) {
+    case argInt:
+    case argIntDummy:
+      typ = " <int>";
+      break;
+    case argFP:
+    case argFPDummy:
+      typ = " <fp>";
+      break;
+    case argString:
+    case argStringDummy:
+      typ = " <string>";
+      break;
+    case argFlag:
+    case argFlagDummy:
+    default:
+      typ = "";
+      break;
+    }
+    fprintf(stderr, "%-*s", w1, typ);
+    if (arg->usage)
+      fprintf(stderr, ": %s", arg->usage);
+    fprintf(stderr, "\n");
+  }
+}
+
+static const ArgDesc *findArg(const ArgDesc *args, char *arg) {
+  const ArgDesc *p;
+
+  for (p = args; p->arg; ++p) {
+    if (p->kind < argFlagDummy && !strcmp(p->arg, arg))
+      return p;
+  }
+  return NULL;
+}
+
+static GBool grabArg(const ArgDesc *arg, int i, int *argc, char *argv[]) {
+  int n;
+  int j;
+  GBool ok;
+
+  ok = gTrue;
+  n = 0;
+  switch (arg->kind) {
+  case argFlag:
+    *(GBool *)arg->val = gTrue;
+    n = 1;
+    break;
+  case argInt:
+    if (i + 1 < *argc && isInt(argv[i+1])) {
+      *(int *)arg->val = atoi(argv[i+1]);
+      n = 2;
+    } else {
+      ok = gFalse;
+      n = 1;
+    }
+    break;
+  case argFP:
+    if (i + 1 < *argc && isFP(argv[i+1])) {
+      *(double *)arg->val = gatof(argv[i+1]);
+      n = 2;
+    } else {
+      ok = gFalse;
+      n = 1;
+    }
+    break;
+  case argString:
+    if (i + 1 < *argc) {
+      strncpy((char *)arg->val, argv[i+1], arg->size - 1);
+      ((char *)arg->val)[arg->size - 1] = '\0';
+      n = 2;
+    } else {
+      ok = gFalse;
+      n = 1;
+    }
+    break;
+  default:
+    fprintf(stderr, "Internal error in arg table\n");
+    n = 1;
+    break;
+  }
+  if (n > 0) {
+    *argc -= n;
+    for (j = i; j < *argc; ++j)
+      argv[j] = argv[j+n];
+  }
+  return ok;
+}
+
+GBool isInt(char *s) {
+  if (*s == '-' || *s == '+')
+    ++s;
+  while (isdigit(*s))
+    ++s;
+  if (*s)
+    return gFalse;
+  return gTrue;
+}
+
+GBool isFP(char *s) {
+  int n;
+
+  if (*s == '-' || *s == '+')
+    ++s;
+  n = 0;
+  while (isdigit(*s)) {
+    ++s;
+    ++n;
+  }
+  if (*s == '.')
+    ++s;
+  while (isdigit(*s)) {
+    ++s;
+    ++n;
+  }
+  if (n > 0 && (*s == 'e' || *s == 'E')) {
+    ++s;
+    if (*s == '-' || *s == '+')
+      ++s;
+    n = 0;
+    if (!isdigit(*s))
+      return gFalse;
+    do {
+      ++s;
+    } while (isdigit(*s));
+  }
+  if (*s)
+    return gFalse;
+  return gTrue;
+}


More information about the poppler mailing list