[gimp/bug-357818: 1/11] Bug 357818 - TWAIN plug-in - Changed only SPACE, TAB, CR, LF



commit 204efe8b26128c82a18a013baa3a060fd013d728
Author: Jens M. Plonka <jens plonka gmx de>
Date:   Fri Jun 3 00:27:53 2016 +0200

    Bug 357818 - TWAIN plug-in - Changed only SPACE, TAB, CR, LF
    
    Adapted to 2.8 by Dieter Verfaillie <dieterv optionexplicit be>
    Applying a slightly changed patch to accommodate for the code changes since the original patch had been 
made.

 plug-ins/twain/tw_func.c  |  321 +++++++++++++++++++++++++--------------------
 plug-ins/twain/tw_func.h  |   38 +++---
 plug-ins/twain/tw_local.h |   22 ++--
 plug-ins/twain/tw_util.c  |   17 ++-
 plug-ins/twain/tw_win.c   |  210 ++++++++++++++++--------------
 5 files changed, 329 insertions(+), 279 deletions(-)
---
diff --git a/plug-ins/twain/tw_func.c b/plug-ins/twain/tw_func.c
index 671ab47..8192048 100644
--- a/plug-ins/twain/tw_func.c
+++ b/plug-ins/twain/tw_func.c
@@ -61,7 +61,7 @@
 
 #include "config.h"
 
-#include <glib.h>              /* Needed when compiling with gcc */
+#include <glib.h>   /* Needed when compiling with gcc */
 
 #include "tw_func.h"
 #include "tw_util.h"
@@ -71,7 +71,8 @@
  * Twain error code to string mappings
  */
 static int twainErrorCount = 0;
-static char *twainErrors[] = {
+static char *twainErrors[] =
+{
   "No error",
   "Failure due to unknown causes",
   "Not enough memory to perform operation",
@@ -130,7 +131,7 @@ float FIX32ToFloat(TW_FIX32 fix32)
  * with the specified error code.
  */
 char *
-twainError(int errorCode)
+twainError (int errorCode)
 {
   /* Check whether we've counted */
   if (twainErrorCount == 0)
@@ -149,7 +150,7 @@ twainError(int errorCode)
  * Return the current TWAIN error message.
  */
 char *
-currentTwainError(pTW_SESSION twSession)
+currentTwainError (pTW_SESSION twSession)
 {
   TW_STATUS twStatus;
 
@@ -159,47 +160,50 @@ currentTwainError(pTW_SESSION twSession)
                            (TW_MEMREF) &twStatus);
 
   /* Return the mapped error code */
-  return twainError(twStatus.ConditionCode);
+  return twainError (twStatus.ConditionCode);
 }
 
-
 /*
  * getImage
  *
  * This is a "high-level" function that can be called in order
  * to take all of the steps necessary to kick off an image-transfer
- * from a user-specified TWAIN datasource.  The data will be passed
+ * from a user-specified TWAIN datasource. The data will be passed
  * back to the callback function specified in the session structure.
  */
 int
-getImage(pTW_SESSION twSession)
+getImage (pTW_SESSION twSession)
 {
   /* Do some sanity checking first and bail
    * if necessary.
    */
 
-  if (!twainIsAvailable()) {
+  if (!twainIsAvailable ())
+  {
     LogMessage("TWAIN is not available for image capture\n");
     return FALSE;
   }
 
   /* One step at a time */
-  if (!openDSM(twSession)) {
+  if (!openDSM (twSession))
+  {
     LogMessage("Unable to open data source manager\n");
     return FALSE;
   }
 
-  if (!selectDS(twSession)) {
+  if (!selectDS (twSession))
+  {
     LogMessage("Data source not selected\n");
     return FALSE;
   }
 
-  if (!openDS(twSession)) {
+  if (!openDS (twSession))
+  {
     LogMessage("Unable to open datasource\n");
     return FALSE;
   }
 
-  requestImageAcquire(twSession, TRUE);
+  requestImageAcquire (twSession, TRUE);
 
   return TRUE;
 }
@@ -210,7 +214,7 @@ getImage(pTW_SESSION twSession)
  * Open the data source manager
  */
 int
-openDSM(pTW_SESSION twSession)
+openDSM (pTW_SESSION twSession)
 {
   /* Make sure that we aren't already open */
   if (DSM_IS_OPEN(twSession))
@@ -218,11 +222,12 @@ openDSM(pTW_SESSION twSession)
 
   /* Open the data source manager */
   twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-                           DG_CONTROL, DAT_PARENT, MSG_OPENDSM,
-                           (TW_MEMREF) &(twSession->hwnd));
+      DG_CONTROL, DAT_PARENT, MSG_OPENDSM,
+      (TW_MEMREF) &(twSession->hwnd));
 
   /* Check the return code */
-  switch (twSession->twRC) {
+  switch (twSession->twRC)
+  {
     case TWRC_SUCCESS:
       /* We are now at state 3 */
       twSession->twainState = 3;
@@ -245,37 +250,39 @@ openDSM(pTW_SESSION twSession)
  * interface.
  */
 int
-selectDS(pTW_SESSION twSession)
+selectDS (pTW_SESSION twSession)
 {
   /* The datasource manager must be open */
-  if (DSM_IS_CLOSED(twSession)) {
+  if (DSM_IS_CLOSED(twSession))
+  {
     LogMessage("Can't select data source with closed source manager\n");
     return FALSE;
   }
 
   /* Ask TWAIN to present the source select dialog */
   twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
-                           DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT,
-                           (TW_MEMREF) DS_IDENTITY(twSession));
+      DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT,
+      (TW_MEMREF) DS_IDENTITY(twSession));
 
   /* Check the return to determine what the user decided
    * to do.
    */
-  switch (twSession->twRC) {
-  case TWRC_SUCCESS:
-    LogMessage("Data source %s selected\n", DS_IDENTITY(twSession)->ProductName);
-    return TRUE;
-    break;
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      LogMessage ("Data source %s selected\n", DS_IDENTITY(twSession)->ProductName);
+      return TRUE;
+      break;
 
-  case TWRC_CANCEL:
-    LogMessage("User cancelled TWAIN source selection\n");
-    break;
+    case TWRC_CANCEL:
+      LogMessage ("User cancelled TWAIN source selection\n");
+      break;
 
-  case TWRC_FAILURE:
-  default:
-    LogMessage("Error \"%s\" during TWAIN source selection\n",
+    case TWRC_FAILURE:
+    default:
+      LogMessage ("Error \"%s\" during TWAIN source selection\n",
               currentTwainError(twSession));
-    break;
+      break;
   }
 
   return FALSE;
@@ -310,18 +317,20 @@ selectDefaultDS(pTW_SESSION twSession)
  * Open a data source using the TWAIN user interface.
  */
 int
-openDS(pTW_SESSION twSession)
+openDS (pTW_SESSION twSession)
 {
   TW_IDENTITY *dsIdentity;
 
   /* The datasource manager must be open */
-  if (DSM_IS_CLOSED(twSession)) {
+  if (DSM_IS_CLOSED(twSession))
+  {
     LogMessage("openDS: Cannot open data source... manager closed\n");
     return FALSE;
   }
 
   /* Is the data source already open? */
-  if (DS_IS_OPEN(twSession)) {
+  if (DS_IS_OPEN(twSession))
+  {
     LogMessage("openDS: Data source already open\n");
     return TRUE;
   }
@@ -335,24 +344,25 @@ openDS(pTW_SESSION twSession)
   /* Check the return to determine what the user decided
    * to do.
         */
-  switch (twSession->twRC) {
-  case TWRC_SUCCESS:
-    /* We are now in TWAIN state 4 */
-    twSession->twainState = 4;
-    LogMessage("Data source %s opened\n", DS_IDENTITY(twSession)->ProductName);
-    LogMessage("\tVersion.MajorNum = %d\n", dsIdentity->Version.MajorNum);
-    LogMessage("\tVersion.MinorNum = %d\n", dsIdentity->Version.MinorNum);
-    LogMessage("\tVersion.Info = %s\n", dsIdentity->Version.Info);
-    LogMessage("\tProtocolMajor = %d\n", dsIdentity->ProtocolMajor);
-    LogMessage("\tProtocolMinor = %d\n", dsIdentity->ProtocolMinor);
-    LogMessage("\tManufacturer = %s\n", dsIdentity->Manufacturer);
-    LogMessage("\tProductFamily = %s\n", dsIdentity->ProductFamily);
-    return TRUE;
-    break;
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      /* We are now in TWAIN state 4 */
+      twSession->twainState = 4;
+      LogMessage("Data source %s opened\n", DS_IDENTITY(twSession)->ProductName);
+      LogMessage("\tVersion.MajorNum = %d\n", dsIdentity->Version.MajorNum);
+      LogMessage("\tVersion.MinorNum = %d\n", dsIdentity->Version.MinorNum);
+      LogMessage("\tVersion.Info = %s\n", dsIdentity->Version.Info);
+      LogMessage("\tProtocolMajor = %d\n", dsIdentity->ProtocolMajor);
+      LogMessage("\tProtocolMinor = %d\n", dsIdentity->ProtocolMinor);
+      LogMessage("\tManufacturer = %s\n", dsIdentity->Manufacturer);
+      LogMessage("\tProductFamily = %s\n", dsIdentity->ProductFamily);
+      return TRUE;
+      break;
 
-  default:
-    LogMessage("Error \"%s\" opening data source\n", currentTwainError(twSession));
-    break;
+    default:
+      LogMessage("Error \"%s\" opening data source\n", currentTwainError(twSession));
+      break;
   }
 
   return FALSE;
@@ -362,7 +372,7 @@ openDS(pTW_SESSION twSession)
  * setBufferedXfer
  */
 static int
-setBufferedXfer(pTW_SESSION twSession)
+setBufferedXfer (pTW_SESSION twSession)
 {
   TW_CAPABILITY bufXfer;
   pTW_ONEVALUE pvalOneValue;
@@ -374,12 +384,12 @@ setBufferedXfer(pTW_SESSION twSession)
   /* Create the capability information */
   bufXfer.Cap = ICAP_XFERMECH;
   bufXfer.ConType = TWON_ONEVALUE;
-  bufXfer.hContainer = twainAllocHandle(sizeof(TW_ONEVALUE));
+  bufXfer.hContainer = twainAllocHandle (sizeof(TW_ONEVALUE));
 
-  pvalOneValue = (pTW_ONEVALUE) twainLockHandle(bufXfer.hContainer);
+  pvalOneValue = (pTW_ONEVALUE) twainLockHandle (bufXfer.hContainer);
   pvalOneValue->ItemType = TWTY_UINT16;
   pvalOneValue->Item = TWSX_MEMORY;
-  twainUnlockHandle(bufXfer.hContainer);
+  twainUnlockHandle (bufXfer.hContainer);
 
   /* Make the call to the source manager */
   twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
@@ -387,7 +397,7 @@ setBufferedXfer(pTW_SESSION twSession)
                            (TW_MEMREF) &bufXfer);
 
   /* Free the container */
-  twainFreeHandle(bufXfer.hContainer);
+  twainFreeHandle (bufXfer.hContainer);
 
   /* Let the caller know what happened */
   return (twSession->twRC==TWRC_SUCCESS);
@@ -401,10 +411,11 @@ setBufferedXfer(pTW_SESSION twSession)
  * an image to actually be transferred.
  */
 int
-requestImageAcquire(pTW_SESSION twSession, gboolean showUI)
+requestImageAcquire (pTW_SESSION twSession, gboolean showUI)
 {
   /* Make sure in the correct state */
-  if (DS_IS_CLOSED(twSession)) {
+  if (DS_IS_CLOSED(twSession))
+  {
     LogMessage("Can't acquire image with closed datasource\n");
     return FALSE;
   }
@@ -412,7 +423,8 @@ requestImageAcquire(pTW_SESSION twSession, gboolean showUI)
   twainSetupCallback(twSession);
 
   /* Set the transfer mode */
-  if (setBufferedXfer(twSession)) {
+  if (setBufferedXfer (twSession))
+  {
     TW_USERINTERFACE ui;
 
     /* Set the UI information */
@@ -426,16 +438,21 @@ requestImageAcquire(pTW_SESSION twSession, gboolean showUI)
                              DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS,
                              (TW_MEMREF) &ui);
 
-    if (twSession->twRC == TWRC_SUCCESS) {
+    if (twSession->twRC == TWRC_SUCCESS)
+    {
       /* We are now at a new twain state */
       twSession->twainState = 5;
 
       return TRUE;
-    } else {
+    }
+       else
+    {
       LogMessage("Error during data source enable\n");
       return FALSE;
     }
-  } else {
+  }
+  else
+  {
     LogMessage("Unable to set buffered transfer mode: %s\n",
               currentTwainError(twSession));
     return FALSE;
@@ -451,12 +468,12 @@ int
 disableDS(pTW_SESSION twSession)
 {
     TW_USERINTERFACE ui;
-
-       /* Verify the datasource is enabled */
-       if (DS_IS_DISABLED(twSession)) {
-               LogMessage("disableDS: Data source not enabled\n");
-               return TRUE;
-       }
+  /* Verify the datasource is enabled */
+  if (DS_IS_DISABLED(twSession))
+  {
+    LogMessage("disableDS: Data source not enabled\n");
+    return TRUE;
+  }
 
     /* Set the UI information */
     ui.ShowUI = TRUE;
@@ -468,12 +485,15 @@ disableDS(pTW_SESSION twSession)
                              DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS,
                              (TW_MEMREF) &ui);
 
-    if (twSession->twRC == TWRC_SUCCESS) {
+    if (twSession->twRC == TWRC_SUCCESS)
+    {
       /* We are now at a new twain state */
       twSession->twainState = 4;
 
       return TRUE;
-    } else {
+    }
+    else
+    {
       LogMessage("Error during data source disable\n");
       return FALSE;
     }
@@ -486,10 +506,11 @@ disableDS(pTW_SESSION twSession)
  * specified session.
  */
 int
-closeDS(pTW_SESSION twSession)
+closeDS (pTW_SESSION twSession)
 {
   /* Can't close a closed data source */
-  if (DS_IS_CLOSED(twSession)) {
+  if (DS_IS_CLOSED(twSession))
+  {
     LogMessage("closeDS: Data source already closed\n");
     return TRUE;
   }
@@ -502,17 +523,18 @@ closeDS(pTW_SESSION twSession)
   /* Check the return to determine what the user decided
    * to do.
         */
-  switch (twSession->twRC) {
-  case TWRC_SUCCESS:
-    /* We are now in TWAIN state 3 */
-    twSession->twainState = 3;
-    LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName);
-    return TRUE;
-    break;
+  switch (twSession->twRC)
+  {
+    case TWRC_SUCCESS:
+      /* We are now in TWAIN state 3 */
+      twSession->twainState = 3;
+      LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName);
+      return TRUE;
+      break;
 
-  default:
-    LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession));
-    break;
+    default:
+      LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession));
+      break;
   }
 
   return FALSE;
@@ -524,12 +546,15 @@ closeDS(pTW_SESSION twSession)
  * Close the data source manager
  */
 int
-closeDSM(pTW_SESSION twSession)
+closeDSM (pTW_SESSION twSession)
 {
-  if (DSM_IS_CLOSED(twSession)) {
+  if (DSM_IS_CLOSED(twSession))
+  {
     LogMessage("closeDSM: Source Manager not open\n");
     return FALSE;
-  } else {
+  }
+  else
+  {
     if (DS_IS_OPEN(twSession)) {
       LogMessage("closeDSM: Can't close source manager with open source\n");
       return FALSE;
@@ -542,9 +567,8 @@ closeDSM(pTW_SESSION twSession)
                                LogMessage("CloseDSM failure -- %s\n", currentTwainError(twSession));
       }
       else {
-
-                               /* We are now in state 2 */
-                               twSession->twainState = 2;
+        /* We are now in state 2 */
+        twSession->twainState = 2;
       }
     }
   }
@@ -560,10 +584,10 @@ closeDSM(pTW_SESSION twSession)
  * Begin an image transfer.
  */
 static int
-beginImageTransfer(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
+beginImageTransfer (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
 {
   /* Clear our structures */
-  memset(imageInfo, 0, sizeof(TW_IMAGEINFO));
+  memset (imageInfo, 0, sizeof (TW_IMAGEINFO));
 
   /* Query the image information */
   twSession->twRC = callDSM(
@@ -572,7 +596,8 @@ beginImageTransfer(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
                            (TW_MEMREF) imageInfo);
 
   /* Check the return code */
-  if (twSession->twRC != TWRC_SUCCESS) {
+  if (twSession->twRC != TWRC_SUCCESS)
+  {
     LogMessage("Get Image Info failure - %s\n", currentTwainError(twSession));
 
     return FALSE;
@@ -580,7 +605,7 @@ beginImageTransfer(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
 
   /* Call the begin transfer callback if registered */
   if (twSession->transferFunctions->txfrBeginCb)
-    if (!(*twSession->transferFunctions->txfrBeginCb)(imageInfo, twSession->clientData))
+    if (!(*twSession->transferFunctions->txfrBeginCb) (imageInfo, twSession->clientData))
       return FALSE;
 
   /* We should continue */
@@ -596,15 +621,15 @@ beginImageTransfer(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
  * from State 6 to 7.  Return the reason for exiting the transfer.
  */
 static void
-transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
+transferImage (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
 {
   TW_SETUPMEMXFER setupMemXfer;
   TW_IMAGEMEMXFER imageMemXfer;
   char *buffer;
 
   /* Clear our structures */
-  memset(&setupMemXfer, 0, sizeof(TW_SETUPMEMXFER));
-  memset(&imageMemXfer, 0, sizeof(TW_IMAGEMEMXFER));
+  memset (&setupMemXfer, 0, sizeof (TW_SETUPMEMXFER));
+  memset (&imageMemXfer, 0, sizeof (TW_IMAGEMEMXFER));
 
   /* Find out how the source would like to transfer... */
   twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
@@ -618,7 +643,8 @@ transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
   imageMemXfer.Memory.TheMem = (TW_MEMREF) buffer;
 
   /* Get the data */
-  do {
+  do
+  {
     /* Setup for the memory transfer */
     imageMemXfer.Compression = TWON_DONTCARE16;
     imageMemXfer.BytesPerRow = TWON_DONTCARE32;
@@ -634,15 +660,17 @@ transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
                              (TW_MEMREF) &imageMemXfer);
 
     if ((twSession->twRC == TWRC_SUCCESS) ||
-       (twSession->twRC == TWRC_XFERDONE)) {
+        (twSession->twRC == TWRC_XFERDONE))
+    {
       /* Call the callback function */
       if (!(*twSession->transferFunctions->txfrDataCb) (
                                                        imageInfo,
                                                        &imageMemXfer,
-                                                       twSession->clientData)) {
-       /* Callback function requested to cancel */
-       twSession->twRC = TWRC_CANCEL;
-       break;
+                                                       twSession->clientData))
+      {
+        /* Callback function requested to cancel */
+        twSession->twRC = TWRC_CANCEL;
+        break;
       }
     }
   } while (twSession->twRC == TWRC_SUCCESS);
@@ -658,7 +686,7 @@ transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
  * Return the count of pending transfers.
  */
 static int
-endPendingTransfer(pTW_SESSION twSession)
+endPendingTransfer (pTW_SESSION twSession)
 {
   TW_PENDINGXFERS pendingXfers;
 
@@ -678,7 +706,7 @@ endPendingTransfer(pTW_SESSION twSession)
  * Cancel all pending image transfers.
  */
 void
-cancelPendingTransfers(pTW_SESSION twSession)
+cancelPendingTransfers (pTW_SESSION twSession)
 {
   TW_PENDINGXFERS pendingXfers;
 
@@ -694,7 +722,7 @@ cancelPendingTransfers(pTW_SESSION twSession)
  * of pending images.
  */
 static int
-endImageTransfer(pTW_SESSION twSession, int *pendingCount)
+endImageTransfer (pTW_SESSION twSession, int *pendingCount)
 {
   gboolean continueTransfers;
   int exitCode = twSession->twRC;
@@ -702,17 +730,18 @@ endImageTransfer(pTW_SESSION twSession, int *pendingCount)
   /* Have now exited the transfer for some reason... Figure out
    * why and what to do about it
    */
-  switch (twSession->twRC) {
-  case TWRC_XFERDONE:
-  case TWRC_CANCEL:
+  switch (twSession->twRC)
+  {
+    case TWRC_XFERDONE:
+    case TWRC_CANCEL:
     LogMessage("Xfer done received\n");
-    *pendingCount = endPendingTransfer(twSession);
-    break;
+      *pendingCount = endPendingTransfer(twSession);
+      break;
 
-  case TWRC_FAILURE:
-    LogMessage("Failure received\n");
-    *pendingCount = endPendingTransfer(twSession);
-    break;
+    case TWRC_FAILURE:
+      LogMessage("Failure received\n");
+      *pendingCount = endPendingTransfer(twSession);
+      break;
   }
 
   /* Call the end transfer callback */
@@ -732,7 +761,7 @@ endImageTransfer(pTW_SESSION twSession, int *pendingCount)
  * datasource.
  */
 static void
-transferImages(pTW_SESSION twSession)
+transferImages (pTW_SESSION twSession)
 {
   TW_IMAGEINFO imageInfo;
   int pendingCount;
@@ -740,7 +769,8 @@ transferImages(pTW_SESSION twSession)
   /* Check the image transfer callback function
    * before even attempting to do the transfer
    */
-  if (!twSession->transferFunctions || !twSession->transferFunctions->txfrDataCb) {
+  if (!twSession->transferFunctions || !twSession->transferFunctions->txfrDataCb)
+  {
     LogMessage("Attempting image transfer without callback function\n");
     return;
   }
@@ -753,18 +783,19 @@ transferImages(pTW_SESSION twSession)
     (*twSession->transferFunctions->preTxfrCb)(twSession->clientData);
 
   /* Loop through the available images */
-  do {
+  do
+  {
     /* Move to the new state */
     twSession->twainState = 6;
 
     /* Begin the image transfer */
-    if (!beginImageTransfer(twSession, &imageInfo))
+    if (!beginImageTransfer (twSession, &imageInfo))
       continue;
 
     /* Call the image transfer function */
     transferImage(twSession, &imageInfo);
 
-  } while (endImageTransfer(twSession, &pendingCount));
+  } while (endImageTransfer (twSession, &pendingCount));
 
   /*
    * Inform our application that we are done
@@ -776,30 +807,31 @@ transferImages(pTW_SESSION twSession)
 }
 
 void
-processTwainMessage(TW_UINT16 message, pTW_SESSION twSession)
+processTwainMessage (TW_UINT16 message, pTW_SESSION twSession)
 {
-  switch (message) {
-  case MSG_XFERREADY:
-    LogMessage("Source says that data is ready\n");
-    transferImages(twSession);
-    break;
-
-  case MSG_CLOSEDSREQ:
-    /* Disable the datasource, Close the Data source
-     * and close the data source manager
+  switch (message)
+  {
+    case MSG_XFERREADY:
+      LogMessage("Source says that data is ready\n");
+      transferImages (twSession);
+      break;
+
+    case MSG_CLOSEDSREQ:
+      /* Disable the datasource, Close the Data source
+       * and close the data source manager
+       */
+      LogMessage("CloseDSReq\n");
+      disableDS (twSession);
+      closeDS (twSession);
+      closeDSM (twSession);
+      break;
+
+    /* No message from the Source to the App break;
+     * possible new message
      */
-    LogMessage("CloseDSReq\n");
-    disableDS(twSession);
-    closeDS(twSession);
-    closeDSM(twSession);
-    break;
-
-  /* No message from the Source to the App break;
-   * possible new message
-   */
-  case MSG_NULL:
-  default:
-    break;
+    case MSG_NULL:
+    default:
+      break;
   }
 }
 
@@ -813,7 +845,8 @@ processTwainMessage(TW_UINT16 message, pTW_SESSION twSession)
  * Create a new TWAIN session.
  */
 pTW_SESSION
-newSession(pTW_IDENTITY appIdentity) {
+newSession (pTW_IDENTITY appIdentity)
+{
   /* Create the structure */
   pTW_SESSION session = g_new (TW_SESSION, 1);
 
@@ -826,7 +859,7 @@ newSession(pTW_IDENTITY appIdentity) {
   session->dsIdentity->ProductName[0] = '\0';
   session->transferFunctions = NULL;
 
-  if (twainIsAvailable())
+  if (twainIsAvailable ())
     session->twainState = 2;
   else
     session->twainState = 0;
diff --git a/plug-ins/twain/tw_func.h b/plug-ins/twain/tw_func.h
index bd7ff27..4778d91 100644
--- a/plug-ins/twain/tw_func.h
+++ b/plug-ins/twain/tw_func.h
@@ -207,31 +207,31 @@ typedef struct _TWAIN_SESSION {
 #define DS_IS_DISABLED(tw_session) (tw_session->twainState < 5)
 
 /* Function declarations */
-char *twainError(int);
-char *currentTwainError(pTW_SESSION);
-int getImage(pTW_SESSION);
-int loadTwainLibrary(pTW_SESSION);
+char *          twainError (int);
+char *          currentTwainError (pTW_SESSION);
+int             getImage (pTW_SESSION);
+int             loadTwainLibrary (pTW_SESSION);
 int unloadTwainLibrary(pTW_SESSION twSession);
-int openDSM(pTW_SESSION);
-int selectDS(pTW_SESSION);
-int selectDefaultDS(pTW_SESSION);
-int openDS(pTW_SESSION);
-int requestImageAcquire(pTW_SESSION, gboolean);
-int disableDS(pTW_SESSION);
-int closeDS(pTW_SESSION);
-int closeDSM(pTW_SESSION);
-void cancelPendingTransfers(pTW_SESSION);
+int             openDSM (pTW_SESSION);
+int             selectDS (pTW_SESSION);
+int             selectDefaultDS (pTW_SESSION);
+int             openDS (pTW_SESSION);
+int             requestImageAcquire (pTW_SESSION, gboolean);
+int             disableDS (pTW_SESSION);
+int             closeDS (pTW_SESSION);
+int             closeDSM (pTW_SESSION);
+void            cancelPendingTransfers (pTW_SESSION);
 int scanImage (void);
 
 TW_FIX32 FloatToFIX32(float);
-float FIX32ToFloat(TW_FIX32);
+float           FIX32ToFloat(TW_FIX32);
 
-void processTwainMessage(TW_UINT16 message, pTW_SESSION twSession);
+void            processTwainMessage (TW_UINT16 message, pTW_SESSION twSession);
 
-pTW_SESSION newSession(pTW_IDENTITY);
-void registerWindowHandle(pTW_SESSION, TW_HANDLE);
-void registerTransferCallbacks(pTW_SESSION, pTXFR_CB_FUNCS, void *);
-void setClientData(pTW_SESSION session, void *clientData);
+pTW_SESSION     newSession (pTW_IDENTITY);
+void            registerWindowHandle(pTW_SESSION, TW_HANDLE);
+void            registerTransferCallbacks(pTW_SESSION, pTXFR_CB_FUNCS, void *);
+void            setClientData(pTW_SESSION session, void *clientData);
 pTW_SESSION initializeTwain(void);
 
 #ifdef G_OS_WIN32
diff --git a/plug-ins/twain/tw_local.h b/plug-ins/twain/tw_local.h
index 45b2fca..30094eb 100644
--- a/plug-ins/twain/tw_local.h
+++ b/plug-ins/twain/tw_local.h
@@ -29,18 +29,22 @@
 
 /* Functions which the platform-independent code will call */
 
-TW_UINT16 callDSM(pTW_IDENTITY, pTW_IDENTITY,
-                 TW_UINT32, TW_UINT16,
-                 TW_UINT16, TW_MEMREF);
-
-int twainIsAvailable(void);
-void twainQuitApplication (void);
-gboolean twainSetupCallback (pTW_SESSION twSession);
+TW_UINT16 callDSM (
+    pTW_IDENTITY,
+    pTW_IDENTITY,
+    TW_UINT32,
+    TW_UINT16,
+    TW_UINT16,
+    TW_MEMREF);
+
+int       twainIsAvailable(void);
+void      twainQuitApplication (void);
+gboolean  twainSetupCallback (pTW_SESSION twSession);
 
 TW_HANDLE twainAllocHandle(size_t size);
 TW_MEMREF twainLockHandle (TW_HANDLE handle);
-void twainUnlockHandle (TW_HANDLE handle);
-void twainFreeHandle (TW_HANDLE handle);
+void      twainUnlockHandle (TW_HANDLE handle);
+void      twainFreeHandle (TW_HANDLE handle);
 
 int twainMain (void);
 int scanImage (void);
diff --git a/plug-ins/twain/tw_util.c b/plug-ins/twain/tw_util.c
index 4d4ce2b..43ee831 100644
--- a/plug-ins/twain/tw_util.c
+++ b/plug-ins/twain/tw_util.c
@@ -82,7 +82,7 @@ FILE *logFile = NULL;
  * LogMessage
  */
 void
-LogMessage(char *format, ...)
+LogMessage (char *format, ...)
 {
   va_list args;
   time_t time_of_day;
@@ -92,15 +92,16 @@ LogMessage(char *format, ...)
   if (!logFile)
     logFile = g_fopen(DEBUG_LOGFILE, "w");
 
-  time_of_day = time(NULL);
-  ctime_string = ctime(&time_of_day);
+  time_of_day = time (NULL);
+  ctime_string = ctime (&time_of_day);
   ctime_string[19] = '\0';
 
-  fprintf(logFile, "[%s] ", (ctime_string + 11));
-  va_start(args, format);
-  vfprintf(logFile, format, args);
-  fflush(logFile);
-  va_end(args);
+  fprintf (logFile, "[%s] ", (ctime_string + 11));
+
+  va_start (args, format);
+  vfprintf (logFile, format, args);
+  fflush (logFile);
+  va_end (args);
 }
 
 void
diff --git a/plug-ins/twain/tw_win.c b/plug-ins/twain/tw_win.c
index 43d5d9d..f8477e6 100644
--- a/plug-ins/twain/tw_win.c
+++ b/plug-ins/twain/tw_win.c
@@ -35,10 +35,10 @@
 #include "tw_util.h"
 #include "tw_local.h"
 
-LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
 
-int twainMessageLoop(pTW_SESSION);
-int TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession);
+int twainMessageLoop (pTW_SESSION);
+int TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession);
 
 extern GimpPlugInInfo PLUG_IN_INFO;
 extern pTW_SESSION initializeTwain ();
@@ -52,28 +52,28 @@ extern void setRunMode(char *argv[]);
 #define WM_TRANSFER_IMAGE (WM_USER + 100)
 
 /* main bits */
-static HWND        hwnd = NULL;
-static HINSTANCE   hInst = NULL;
+static HWND         hwnd  = NULL;
+static HINSTANCE    hInst = NULL;
 
 /* Storage for the DLL handle */
-static HINSTANCE hDLL = NULL;
+static HINSTANCE    hDLL  = NULL;
 
 /* Storage for the entry point into the DSM */
 static DSMENTRYPROC dsmEntryPoint = NULL;
 
-
 /*
  * callDSM
  *
  * Call the specified function on the data source manager.
  */
 TW_UINT16
-callDSM(pTW_IDENTITY pOrigin,
-       pTW_IDENTITY pDest,
-       TW_UINT32    DG,
-       TW_UINT16    DAT,
-       TW_UINT16    MSG,
-       TW_MEMREF    pData)
+callDSM (
+    pTW_IDENTITY pOrigin,
+    pTW_IDENTITY pDest,
+    TW_UINT32    DG,
+    TW_UINT16    DAT,
+    TW_UINT16    MSG,
+    TW_MEMREF    pData)
 {
   /* Call the function */
   return (*dsmEntryPoint) (pOrigin, pDest, DG, DAT, MSG, pData);
@@ -85,20 +85,21 @@ callDSM(pTW_IDENTITY pOrigin,
  * Return boolean indicating whether TWAIN is available
  */
 int
-twainIsAvailable(void)
+twainIsAvailable (void)
 {
   /* Already loaded? */
-  if (dsmEntryPoint) {
+  if (dsmEntryPoint)
+  {
     return TRUE;
   }
 
   /* Attempt to load the library */
-  hDLL = LoadLibrary(TWAIN_DLL_NAME);
+  hDLL = LoadLibrary (TWAIN_DLL_NAME);
   if (hDLL == NULL)
     return FALSE;
 
   /* Look up the entry point for use */
-  dsmEntryPoint = (DSMENTRYPROC) GetProcAddress(hDLL, "DSM_Entry");
+  dsmEntryPoint = (DSMENTRYPROC) GetProcAddress (hDLL, "DSM_Entry");
   if (dsmEntryPoint == NULL)
     return FALSE;
 
@@ -108,7 +109,7 @@ twainIsAvailable(void)
 TW_HANDLE
 twainAllocHandle (size_t size)
 {
-  return GlobalAlloc(GHND, size);
+  return GlobalAlloc (GHND, size);
 }
 
 TW_MEMREF
@@ -142,11 +143,12 @@ twainSetupCallback (pTW_SESSION twSession)
  * Unload the TWAIN dynamic link library
  */
 int
-unloadTwainLibrary(pTW_SESSION twSession)
+unloadTwainLibrary (pTW_SESSION twSession)
 {
   /* Explicitly free the SM library */
-  if (hDLL) {
-    FreeLibrary(hDLL);
+  if (hDLL)
+  {
+    FreeLibrary (hDLL);
     hDLL=NULL;
   }
 
@@ -170,32 +172,34 @@ unloadTwainLibrary(pTW_SESSION twSession)
  * Returns FALSE if the application should skip processing of this message
  */
 int
-TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession)
+TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession)
 {
-  TW_EVENT   twEvent;
+  TW_EVENT twEvent;
 
   twSession->twRC = TWRC_NOTDSEVENT;
 
   /* Only ask Source Manager to process event if there is a Source connected. */
-  if (DSM_IS_OPEN(twSession) && DS_IS_OPEN(twSession)) {
-               /*
-                * A Source provides a modeless dialog box as its user interface.
-                * The following call relays Windows messages down to the Source's
-                * UI that were intended for its dialog box.  It also retrieves TWAIN
-                * messages sent from the Source to our Application.
-                */
-               twEvent.pEvent = (TW_MEMREF) lpMsg;
+  if (DSM_IS_OPEN(twSession) && DS_IS_OPEN(twSession))
+  {
+    /*
+     * A Source provides a modeless dialog box as its user interface.
+     * The following call relays Windows messages down to the Source's
+     * UI that were intended for its dialog box. It also retrieves TWAIN
+     * messages sent from the Source to our Application.
+     */
+    twEvent.pEvent = (TW_MEMREF) lpMsg;
                twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
                        DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT,
                        (TW_MEMREF) &twEvent);
 
-               /* Check the return code */
-               if (twSession->twRC == TWRC_NOTDSEVENT) {
-                       return FALSE;
-               }
+    /* Check the return code */
+    if (twSession->twRC == TWRC_NOTDSEVENT)
+    {
+      return FALSE;
+    }
 
-               /* Process the message as necessary */
-               processTwainMessage(twEvent.TWMessage, twSession);
+    /* Process the message as necessary */
+    processTwainMessage (twEvent.TWMessage, twSession);
   }
 
   /* tell the caller what happened */
@@ -210,14 +214,16 @@ TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession)
  * the application exits.
  */
 int
-twainMessageLoop(pTW_SESSION twSession)
+twainMessageLoop (pTW_SESSION twSession)
 {
   MSG msg;
 
-  while (GetMessage(&msg, NULL, 0, 0)) {
-    if (DS_IS_CLOSED(twSession) || !TwainProcessMessage(&msg, twSession)) {
-      TranslateMessage((LPMSG)&msg);
-      DispatchMessage(&msg);
+  while (GetMessage(&msg, NULL, 0, 0))
+  {
+    if (DS_IS_CLOSED(twSession) || !TwainProcessMessage (&msg, twSession))
+    {
+      TranslateMessage ((LPMSG) &msg);
+      DispatchMessage (&msg);
     }
   }
 
@@ -231,29 +237,30 @@ twainMessageLoop(pTW_SESSION twSession)
  * GetLastError.
  */
 void
-LogLastWinError(void)
+LogLastWinError (void)
 {
-       LPVOID lpMsgBuf;
-
-       FormatMessage(
-               FORMAT_MESSAGE_ALLOCATE_BUFFER |
-               FORMAT_MESSAGE_FROM_SYSTEM |
-               FORMAT_MESSAGE_IGNORE_INSERTS,
-               NULL,
-               GetLastError(),
-               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
-               (LPTSTR) &lpMsgBuf,
-               0,
-               NULL
-               );
+  LPVOID lpMsgBuf;
+
+  FormatMessage (
+      FORMAT_MESSAGE_ALLOCATE_BUFFER |
+      FORMAT_MESSAGE_FROM_SYSTEM |
+      FORMAT_MESSAGE_IGNORE_INSERTS,
+      NULL,
+      GetLastError (),
+      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+      (LPTSTR) &lpMsgBuf,
+      0,
+      NULL
+  );
 
        LogMessage("%s\n", lpMsgBuf);
 
-       /* Free the buffer. */
-       LocalFree( lpMsgBuf );
+  /* Free the buffer. */
+  LocalFree ( lpMsgBuf );
 }
 
-void twainQuitApplication ()
+void
+twainQuitApplication ()
 {
   PostQuitMessage (0);
 }
@@ -273,10 +280,11 @@ void twainQuitApplication ()
  * datasource.
  */
 int APIENTRY
-WinMain(HINSTANCE hInstance,
-       HINSTANCE hPrevInstance,
-       LPSTR     lpCmdLine,
-       int       nCmdShow)
+WinMain (
+    HINSTANCE hInstance,
+    HINSTANCE hPrevInstance,
+    LPSTR     lpCmdLine,
+    int       nCmdShow)
 {
 
   /*
@@ -301,7 +309,7 @@ WinMain(HINSTANCE hInstance,
    * Now, call gimp_main... This is what the MAIN() macro
    * would usually do.
    */
-  return gimp_main(&PLUG_IN_INFO, __argc, __argv);
+  return gimp_main (&PLUG_IN_INFO, __argc, __argv);
 }
 
 /*
@@ -309,7 +317,8 @@ WinMain(HINSTANCE hInstance,
  *
  * allow to build as console app as well
  */
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
 {
 #ifdef _DEBUG
   /* When in debug version, we allow different run modes...
@@ -322,7 +331,7 @@ int main (int argc, char *argv[])
    * Now, call gimp_main... This is what the MAIN() macro
    * would usually do.
    */
-  return gimp_main(&PLUG_IN_INFO, __argc, __argv);
+  return gimp_main (&PLUG_IN_INFO, __argc, __argv);
 }
 
 /*
@@ -331,7 +340,7 @@ int main (int argc, char *argv[])
  * Initialize window data and register the window class
  */
 BOOL
-InitApplication(HINSTANCE hInstance)
+InitApplication (HINSTANCE hInstance)
 {
   WNDCLASS wc;
   BOOL retValue;
@@ -345,18 +354,18 @@ InitApplication(HINSTANCE hInstance)
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
-  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
+  wc.hCursor = LoadCursor (NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
   wc.lpszClassName = APP_NAME;
   wc.lpszMenuName = NULL;
 
   /* Register the window class and stash success/failure code. */
-  retValue = RegisterClass(&wc);
+  retValue = RegisterClass (&wc);
 
   /* Log error */
   if (!retValue)
-    LogLastWinError();
+    LogLastWinError ();
 
   return retValue;
 }
@@ -368,27 +377,29 @@ InitApplication(HINSTANCE hInstance)
  * interface with the TWAIN datasource.
  */
 BOOL
-InitInstance(HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
+InitInstance (HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
 {
   /* Create our window */
-  hwnd = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW,
-                     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
-                     NULL, NULL, hInstance, NULL);
+  hwnd = CreateWindow (APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW,
+      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
+      NULL, NULL, hInstance, NULL);
 
-  if (!hwnd) {
+  if (!hwnd)
+  {
     return (FALSE);
   }
 
   /* Register our window handle with the TWAIN
    * support.
    */
-  registerWindowHandle(twSession, hwnd);
+  registerWindowHandle (twSession, hwnd);
 
   /* Schedule the image transfer by posting a message */
-  PostMessage(hwnd, WM_TRANSFER_IMAGE, 0, 0);
+  PostMessage (hwnd, WM_TRANSFER_IMAGE, 0, 0);
+
+  ShowWindow (hwnd, nCmdShow);
 
-  ShowWindow(hwnd, nCmdShow);
-  UpdateWindow(hwnd);
+  UpdateWindow (hwnd);
 
   return TRUE;
 }
@@ -403,17 +414,17 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, pTW_SESSION twSession)
  * operate.
  */
 int
-twainMain()
+twainMain ()
 {
   /* Initialize the twain information */
   pTW_SESSION twSession = initializeTwain();
 
   /* Perform instance initialization */
-  if (!InitApplication(hInst))
+  if (!InitApplication (hInst))
     return (FALSE);
 
   /* Perform application initialization */
-  if (!InitInstance(hInst, SHOW_WINDOW, twSession))
+  if (!InitInstance (hInst, SHOW_WINDOW, twSession))
     return (FALSE);
 
   /*
@@ -421,7 +432,7 @@ twainMain()
    * This call will not return until the application
    * exits.
    */
-  return twainMessageLoop(twSession);
+  return twainMessageLoop (twSession);
 }
 
 /*
@@ -430,23 +441,24 @@ twainMain()
  * Process window message for the main window.
  */
 LRESULT CALLBACK
-WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
-  switch (message) {
-
-  case WM_TRANSFER_IMAGE:
-    /* Get an image */
-    scanImage ();
-    break;
-
-  case WM_DESTROY:
-    LogMessage("Exiting application\n");
-    PostQuitMessage(0);
-    break;
-
-  default:
-    return (DefWindowProc(hWnd, message, wParam, lParam));
+  switch (message)
+  {
+    case WM_TRANSFER_IMAGE:
+      /* Get an image */
+      scanImage ();
+      break;
+
+    case WM_DESTROY:
+      LogMessage("Exiting application\n");
+      PostQuitMessage (0);
+      break;
+
+    default:
+      return (DefWindowProc (hWnd, message, wParam, lParam));
   }
+
   return 0;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]