Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

cms_aup.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002 * File: cms_aup.cc
00003 * Author(s): Will Shackleford, Fred Proctor
00004 * Purpose: Provides the interface to CMS used by NML update functions including
00005 * a CMS update function for all the basic C data types to convert NMLmsgs to XDR.
00006 *
00007 * NOTES:
00008 * There are no update functions for enumerations, or pointers.
00009 * The update function for long doubles is included, but it is recommended that
00010 * doubles be used instead of long doubles since they will be faster and
00011 * the increased range and precision of long doubles will be lost anyway.
00012 ****************************************************************************/
00013 
00014 #include "rcs_defs.hh"          /* EXTERN_C_STD_HEADERS */
00015 
00016 
00017 #ifdef EXTERN_C_STD_HEADERS
00018 extern "C"
00019 {
00020 #endif
00021 
00022 #include <errno.h>              /* errno global variable */
00023 #include <limits.h>             /* SHORT_MIN, SHOR_MAX, . . . */
00024 #include <float.h>              /* FLT_MIN, FLT_MAX */
00025 #include <string.h>             /* memcpy(), strerror() */
00026 #include <stdlib.h>             /* strtol(), strtoul(), strtod() */
00027 #ifdef CenterLine               // CenterLine headers messed up the defintion of these functions
00028   char *strerror (int errnum);
00029   unsigned long strtoul (const char *, char **, int);
00030 #endif
00031 #include <stdio.h>              /* sprintf() */
00032 #include <ctype.h>              /* isspace() */
00033 
00034 #ifdef EXTERN_C_STD_HEADERS
00035 }
00036 #endif
00037 
00038 #ifdef sparcworks_sun4
00039 extern "C"
00040 {
00041   unsigned long strtoul (const char *, char **, int);
00042 }
00043 #endif
00044 
00045 #include "cms.hh"               /* class CMS */
00046 #include "cms_aup.hh"           /* class CMS_ASCII_UPDATER  */
00047 #include "rcs_prnt.hh"          /* rcs_print_error() */
00048 #include "dbg_mem.h"            /* DEBUG_FREE,DEBUG_MALLOC,DEBUG_CALLOC */
00049 
00050 
00051 // This function exists because sparcworks_sun4 header files
00052 // define free as int free(char *) instead of void free(void *);
00053 static void
00054 corrected_free (void *ptr)
00055 {
00056 #ifdef sparcworks_sun4
00057   DEBUG_FREE ((char *) ptr);
00058 #else
00059   DEBUG_FREE (ptr);
00060 #endif
00061 }
00062 
00063 #define DEFAULT_WARNING_COUNT_MAX 100
00064 
00065 /* Member functions for CMS_ASCII_UPDATER Class */
00066 CMS_ASCII_UPDATER::CMS_ASCII_UPDATER (CMS * _cms_parent):CMS_UPDATER (_cms_parent)
00067 {
00068   /* Set pointers to NULL. */
00069   begin_current_string = (char *) NULL;
00070   end_current_string = (char *) NULL;
00071   max_length_current_string = 0;
00072 
00073   /* Store and validate constructors arguments. */
00074   cms_parent = _cms_parent;
00075   if (NULL == cms_parent)
00076     {
00077       rcs_print_error ("CMS parent for updater is NULL.\n");
00078       return;
00079     }
00080 
00081   /* Allocate the encoded header too large, */
00082   /* and find out what size it really is. */
00083   encoded_header =
00084     DEBUG_MALLOC (cms_encoded_data_explosion_factor * sizeof (CMS_HEADER));
00085   if (encoded_header == NULL)
00086     {
00087       rcs_print_error ("CMS:can't malloc encoded_header");
00088       status = CMS_CREATE_ERROR;
00089       return;
00090     }
00091 
00092   /* If queuing is enabled, then initialize streams for */
00093   /* encoding and decoding the header with the queue information. */
00094   if (cms_parent->queuing_enabled)
00095     {
00096       /* Allocate the encoded header too large, */
00097       /* and find out what size it really is. */
00098       encoded_queuing_header =
00099         DEBUG_MALLOC (neutral_size_factor * sizeof (CMS_QUEUING_HEADER));
00100     }
00101   warning_count = 0;
00102   warning_count_max = DEFAULT_WARNING_COUNT_MAX;
00103 }
00104 
00105 CMS_ASCII_UPDATER::~CMS_ASCII_UPDATER ()
00106 {
00107   if (NULL != encoded_data && !using_external_encoded_data)
00108     {
00109       corrected_free (encoded_data);
00110       encoded_data = NULL;
00111     }
00112   if (NULL != encoded_header)
00113     {
00114       corrected_free (encoded_header);
00115       encoded_header = NULL;
00116     }
00117   if (NULL != encoded_queuing_header)
00118     {
00119       corrected_free (encoded_queuing_header);
00120       encoded_queuing_header = NULL;
00121     }
00122 }
00123 
00124 
00125 int
00126 CMS_ASCII_UPDATER::set_mode (CMS_UPDATER_MODE _mode)
00127 {
00128   CMS_UPDATER::set_mode (_mode);
00129   mode = _mode;
00130   switch (mode)
00131     {
00132     case CMS_NO_UPDATE:
00133       begin_current_string = end_current_string = (char *) NULL;
00134       max_length_current_string = 0;
00135       length_current_string = 0;
00136       break;
00137 
00138     case CMS_ENCODE_DATA:
00139       begin_current_string = end_current_string = (char *) encoded_data;
00140       max_length_current_string = neutral_size_factor * size;
00141       if (max_length_current_string > cms_parent->max_encoded_message_size)
00142         {
00143           max_length_current_string = cms_parent->max_encoded_message_size;
00144         }
00145       length_current_string = 0;
00146       encoding = 1;
00147       break;
00148 
00149     case CMS_DECODE_DATA:
00150       begin_current_string = end_current_string = (char *) encoded_data;
00151       max_length_current_string = neutral_size_factor * size;
00152       if (max_length_current_string > cms_parent->max_encoded_message_size)
00153         {
00154           max_length_current_string = cms_parent->max_encoded_message_size;
00155         }
00156       length_current_string = 0;
00157       encoding = 0;
00158       break;
00159 
00160     case CMS_ENCODE_HEADER:
00161       begin_current_string = end_current_string = (char *) encoded_header;
00162       max_length_current_string = neutral_size_factor * sizeof (CMS_HEADER);
00163       length_current_string = 0;
00164       encoding = 1;
00165       break;
00166 
00167     case CMS_DECODE_HEADER:
00168       begin_current_string = end_current_string = (char *) encoded_header;
00169       max_length_current_string = neutral_size_factor * sizeof (CMS_HEADER);
00170       length_current_string = 0;
00171       encoding = 0;
00172       break;
00173 
00174     case CMS_ENCODE_QUEUING_HEADER:
00175       begin_current_string = end_current_string =
00176         (char *) encoded_queuing_header;
00177       max_length_current_string =
00178         neutral_size_factor * sizeof (CMS_QUEUING_HEADER);
00179       length_current_string = 0;
00180       encoding = 1;
00181       break;
00182 
00183     case CMS_DECODE_QUEUING_HEADER:
00184       begin_current_string = end_current_string =
00185         (char *) encoded_queuing_header;
00186       max_length_current_string =
00187         neutral_size_factor * sizeof (CMS_QUEUING_HEADER);
00188       length_current_string = 0;
00189       encoding = 0;
00190       break;
00191 
00192     default:
00193       rcs_print_error ("CMS updater in invalid mode.\n");
00194       return (-1);
00195     }
00196   return (0);
00197 }
00198 
00199 int
00200 CMS_ASCII_UPDATER::check_pointer (char RCS_HUGE * _pointer, long _bytes)
00201 {
00202   if (NULL == cms_parent || NULL == begin_current_string
00203       || NULL == end_current_string)
00204     {
00205       rcs_print_error ("CMS_ASCII_UPDATER: Required pointer is NULL.\n");
00206       return (-1);
00207     }
00208   if (length_current_string + _bytes * neutral_size_factor >
00209       max_length_current_string)
00210     {
00211       rcs_print_error
00212         ("CMS_ASCII_UPDATER: length of current string(%ld) + bytes to add of(%d) exceeds maximum of %ld.\n",
00213          length_current_string, _bytes * neutral_size_factor,
00214          max_length_current_string);
00215       return (-1);
00216     }
00217   return (cms_parent->check_pointer (_pointer, _bytes));
00218 }
00219 
00220 /* Repositions the data buffer to the very beginning */
00221 void
00222 CMS_ASCII_UPDATER::rewind ()
00223 {
00224   CMS_UPDATER::rewind ();
00225   end_current_string = begin_current_string;
00226   length_current_string = 0;
00227   if (NULL != cms_parent)
00228     {
00229       cms_parent->format_size = 0;
00230     }
00231 }
00232 
00233 
00234 int
00235 CMS_ASCII_UPDATER::get_encoded_msg_size ()
00236 {
00237   return (length_current_string);
00238 }
00239 
00240 /* Safe strlen function. */
00241 int
00242 safe_strlen (char *string, int max)
00243 {
00244   int retval;
00245 
00246   if (string == NULL)
00247     {
00248       return (-1);
00249     }
00250 
00251   retval = 0;
00252   while (string[retval])
00253     {
00254       if (isspace (string[retval]))
00255         break;
00256       retval++;
00257       if (retval >= max)
00258         {
00259           return (-1);
00260         }
00261     }
00262   return retval;
00263 }
00264 
00265 /* Char functions */
00266 
00267 CMS_STATUS CMS_ASCII_UPDATER::update (char &x)
00268 {
00269   /* Check to see if the pointers are in the proper range. */
00270   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (char)))
00271     {
00272       return (CMS_UPDATE_ERROR);
00273     }
00274 
00275   if (encoding)
00276     {
00277       end_current_string[0] = x;
00278     }
00279   else
00280     {
00281       x = end_current_string[0];
00282     }
00283   end_current_string += 1;
00284   length_current_string += 1;
00285 
00286   return (status);
00287 }
00288 
00289 CMS_STATUS CMS_ASCII_UPDATER::update (char *x, unsigned int len)
00290 {
00291   /* Check to see if the pointers are in the proper range. */
00292   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (char) * len))
00293     {
00294       return (status = CMS_UPDATE_ERROR);
00295     }
00296 
00297   if (encoding)
00298     {
00299       memcpy (end_current_string, x, len);
00300     }
00301   else
00302     {
00303       memcpy (x, end_current_string, len);
00304     }
00305   end_current_string += len;
00306   length_current_string += len;
00307   return (status);
00308 }
00309 
00310 /* Char functions */
00311 
00312 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned char &x)
00313 {
00314   /* Check to see if the pointers are in the proper range. */
00315   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned char)))
00316     {
00317       return (status = CMS_UPDATE_ERROR);
00318     }
00319 
00320   if (encoding)
00321     {
00322       end_current_string[0] = x;
00323     }
00324   else
00325     {
00326       x = end_current_string[0];
00327     }
00328   end_current_string += 1;
00329   length_current_string += 1;
00330 
00331   return (status);
00332 }
00333 
00334 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned char *x, unsigned int len)
00335 {
00336   /* Check to see if the pointers are in the proper range. */
00337   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (unsigned char) * len))
00338     {
00339       return (status = CMS_UPDATE_ERROR);
00340     }
00341 
00342   if (encoding)
00343     {
00344       memcpy (end_current_string, x, len);
00345     }
00346   else
00347     {
00348       memcpy (x, end_current_string, len);
00349     }
00350   end_current_string += len;
00351   length_current_string += len;
00352   return (status);
00353 }
00354 
00355 /* Short functions */
00356 
00357 CMS_STATUS CMS_ASCII_UPDATER::update (short &x)
00358 {
00359   /* Check to see if the pointers are in the proper range. */
00360   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (short)))
00361     {
00362       return (status = CMS_UPDATE_ERROR);
00363     }
00364 
00365   if (encoding)
00366     {
00367       end_current_string[7] = 0;
00368       sprintf (end_current_string, "%-6d", x);
00369       if (end_current_string[7] != 0 && warning_count < warning_count_max)
00370         {
00371           warning_count++;
00372           rcs_print_error
00373             ("CMS_ASCII_UPDATER: (warning) short with value %-6d caused an overflow.\n",
00374              x);
00375         }
00376       end_current_string[7] = 0;
00377     }
00378   else
00379     {
00380       if (-1 == safe_strlen (end_current_string, 8))
00381         {
00382           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00383           return (status = CMS_UPDATE_ERROR);
00384         }
00385       errno = 0;
00386       long
00387         number = strtol (end_current_string, (char **) NULL, 10);
00388       if (errno != 0)
00389         {
00390           rcs_print_error
00391             ("CMS_ASCII_UPDATER: Error %ld: %s occured during strtol of(%s).\n",
00392              errno, strerror (errno), end_current_string);
00393           return (status = CMS_UPDATE_ERROR);
00394         }
00395       if ((number < SHRT_MIN || SHRT_MAX < number)
00396           && warning_count < warning_count_max)
00397         {
00398           warning_count++;
00399           rcs_print_error
00400             ("CMS_ASCII_UPDATER:  (warning) Number %d out of range for short(%d,%d)\n",
00401              number, SHRT_MIN, SHRT_MAX);
00402         }
00403       x = (short) number;
00404     }
00405   end_current_string += 8;
00406   length_current_string += 8;
00407 
00408   return (status);
00409 }
00410 
00411 CMS_STATUS CMS_ASCII_UPDATER::update (short *x, unsigned int len)
00412 {
00413   /* Check to see if the pointers are in the proper range. */
00414   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (short) * len))
00415     {
00416       return (status = CMS_UPDATE_ERROR);
00417     }
00418 
00419   for (unsigned int i = 0; i < len; i++)
00420     {
00421       if (CMS_UPDATE_ERROR == update (x[i]))
00422         {
00423           return (status = CMS_UPDATE_ERROR);
00424         }
00425     }
00426   return (status);
00427 }
00428 
00429 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned short &x)
00430 {
00431   /* Check to see if the pointers are in the proper range. */
00432   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (short)))
00433     {
00434       return (status = CMS_UPDATE_ERROR);
00435     }
00436 
00437   if (encoding)
00438     {
00439       end_current_string[7] = 0;
00440       sprintf (end_current_string, "%-6d", x);
00441       if (end_current_string[7] != 0 && warning_count < warning_count_max)
00442         {
00443           warning_count++;
00444           rcs_print_error
00445             ("CMS_ASCII_UPDATER: (warning) unsigned short with value %-6d caused an overflow.\n",
00446              x);
00447         }
00448       end_current_string[7] = 0;
00449     }
00450   else
00451     {
00452       if (-1 == safe_strlen (end_current_string, 8))
00453         {
00454           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00455           return (status = CMS_UPDATE_ERROR);
00456         }
00457       errno = 0;
00458       unsigned long
00459         number = strtoul (end_current_string, (char **) NULL, 10);
00460       if (errno != 0)
00461         {
00462           rcs_print_error
00463             ("CMS_ASCII_UPDATER: Error %ld: %s occured during strtoul of (%s).\n",
00464              errno, strerror (errno), end_current_string);
00465           return (status = CMS_UPDATE_ERROR);
00466         }
00467       if (number > USHRT_MAX && warning_count < warning_count_max)
00468         {
00469           warning_count++;
00470           rcs_print_error
00471             ("CMS_ASCII_UPDATER: Number %d out of range for unsigned short(0,%d)\n",
00472              number, USHRT_MAX);
00473         }
00474       x = (unsigned short) number;
00475     }
00476   end_current_string += 8;
00477   length_current_string += 8;
00478 
00479   return (status);
00480 }
00481 
00482 
00483 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned short *x, unsigned int len)
00484 {
00485   /* Check to see if the pointers are in the proper range. */
00486   if (-1 ==
00487       check_pointer ((char RCS_HUGE *) x, sizeof (unsigned short) * len))
00488     {
00489       return (status = CMS_UPDATE_ERROR);
00490     }
00491 
00492   for (unsigned int i = 0; i < len; i++)
00493     {
00494       if (CMS_UPDATE_ERROR == update (x[i]))
00495         {
00496           return (status = CMS_UPDATE_ERROR);
00497         }
00498     }
00499   return (status);
00500 }
00501 
00502 /* Int  functions */
00503 
00504 CMS_STATUS CMS_ASCII_UPDATER::update (int &x)
00505 {
00506   /* Check to see if the pointers are in the proper range. */
00507   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (int)))
00508     {
00509       return (status = CMS_UPDATE_ERROR);
00510     }
00511 
00512   if (encoding)
00513     {
00514       if (x > 9999999 && warning_count < warning_count_max)
00515         {
00516           warning_count++;
00517           rcs_print_error
00518             ("CMS_ASCII_UPDATER: int %d is too large. (Use type long.)\n", x);
00519         }
00520       end_current_string[7] = 0;
00521       sprintf (end_current_string, "%-6d", x);
00522       if (end_current_string[7] != 0 && warning_count < warning_count_max)
00523         {
00524           warning_count++;
00525           rcs_print_error
00526             ("CMS_ASCII_UPDATER: (warning) int with value %-6d caused an overflow.\n",
00527              x);
00528         }
00529       end_current_string[7] = 0;
00530     }
00531   else
00532     {
00533       if (-1 == safe_strlen (end_current_string, 8))
00534         {
00535           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00536           return (status = CMS_UPDATE_ERROR);
00537         }
00538       errno = 0;
00539       long
00540         number = strtol (end_current_string, (char **) NULL, 10);
00541       if (errno != 0)
00542         {
00543           rcs_print_error
00544             ("CMS_ASCII_UPDATER: Error %ld: occured during strtol of (%s).\n",
00545              errno, strerror (errno), end_current_string);
00546           return (status = CMS_UPDATE_ERROR);
00547         }
00548       if ((number < ((long) INT_MIN)) || (((long) INT_MAX) < number)
00549           && warning_count < warning_count_max)
00550         {
00551           warning_count++;
00552           rcs_print_error
00553             ("CMS_ASCII_UPDATER: (warning) Number %ld out of range for int(%ld,%ld)\n",
00554              number, INT_MIN, INT_MAX);
00555         }
00556       x = (int) number;
00557     }
00558   end_current_string += 8;
00559   length_current_string += 8;
00560 
00561   return (status);
00562 }
00563 
00564 CMS_STATUS CMS_ASCII_UPDATER::update (int *x, unsigned int len)
00565 {
00566   /* Check to see if the pointers are in the proper range. */
00567   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (int) * len))
00568     {
00569       return (status = CMS_UPDATE_ERROR);
00570     }
00571 
00572   for (unsigned int i = 0; i < len; i++)
00573     {
00574       if (CMS_UPDATE_ERROR == update (x[i]))
00575         {
00576           return (status = CMS_UPDATE_ERROR);
00577         }
00578     }
00579   return (status);
00580 }
00581 
00582 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned int &x)
00583 {
00584   /* Check to see if the pointers are in the proper range. */
00585   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned int)))
00586     {
00587       return (status = CMS_UPDATE_ERROR);
00588     }
00589 
00590   if (encoding)
00591     {
00592       if (x > 9999999 && warning_count < warning_count_max)
00593         {
00594           warning_count++;
00595           rcs_print_error
00596             ("CMS_ASCII_UPDATER: unsigned int %d is too large. (Use type long.)\n",
00597              x);
00598         }
00599       end_current_string[7] = 0;
00600       sprintf (end_current_string, "%-6d", x);
00601       if (end_current_string[7] != 0 && warning_count < warning_count_max)
00602         {
00603           warning_count++;
00604           rcs_print_error
00605             ("CMS_ASCII_UPDATER: (warning)unsigned int with value %-6d caused an overflow.\n",
00606              x);
00607         }
00608       end_current_string[7] = 0;
00609     }
00610   else
00611     {
00612       if (-1 == safe_strlen (end_current_string, 8))
00613         {
00614           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00615           return (status = CMS_UPDATE_ERROR);
00616         }
00617       errno = 0;
00618       unsigned long
00619         number = strtoul (end_current_string, (char **) NULL, 10);
00620       if (errno != 0)
00621         {
00622           rcs_print_error
00623             ("CMS_ASCII_UPDATER: Error %ld:%s occured during strtoul of (%s).\n",
00624              errno, strerror (errno), end_current_string);
00625           return (status = CMS_UPDATE_ERROR);
00626         }
00627       if (UINT_MAX < number && warning_count < warning_count_max)
00628         {
00629           rcs_print_error
00630             ("CMS_ASCII_UPDATER: Number %d out of range for unsigned int (0,%d)\n",
00631              number, UINT_MAX);
00632         }
00633       x = (unsigned int) number;
00634     }
00635   end_current_string += 8;
00636   length_current_string += 8;
00637 
00638   return (status);
00639 }
00640 
00641 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned int *x, unsigned int len)
00642 {
00643   /* Check to see if the pointers are in the proper range. */
00644   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (unsigned int) * len))
00645     {
00646       return (status = CMS_UPDATE_ERROR);
00647     }
00648 
00649   for (unsigned int i = 0; i < len; i++)
00650     {
00651       if (CMS_UPDATE_ERROR == update (x[i]))
00652         {
00653           return (status = CMS_UPDATE_ERROR);
00654         }
00655     }
00656   return (status);
00657 }
00658 
00659 /* Long functions */
00660 
00661 CMS_STATUS CMS_ASCII_UPDATER::update (long &x)
00662 {
00663   /* Check to see if the pointers are in the proper range. */
00664   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (long)))
00665     {
00666       return (status = CMS_UPDATE_ERROR);
00667     }
00668 
00669   if (encoding)
00670     {
00671       end_current_string[15] = 0;
00672       sprintf (end_current_string, "%-14ld", x);
00673       if (end_current_string[15] != 0 && warning_count < warning_count_max)
00674         {
00675           warning_count++;
00676           rcs_print_error
00677             ("CMS_ASCII_UPDATER: (warning) long with value %-14ld caused an overflow\n",
00678              x);
00679         }
00680       end_current_string[15] = 0;
00681     }
00682   else
00683     {
00684       if (-1 == safe_strlen (end_current_string, 16))
00685         {
00686           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00687           return (status = CMS_UPDATE_ERROR);
00688         }
00689       errno = 0;
00690       long
00691         number = strtol (end_current_string, (char **) NULL, 10);
00692       if (errno != 0)
00693         {
00694           rcs_print_error
00695             ("CMS_ASCII_UPDATER: Error %ld occured during strtol.\n", errno);
00696           return (status = CMS_UPDATE_ERROR);
00697         }
00698       x = number;
00699     }
00700   end_current_string += 16;
00701   length_current_string += 16;
00702 
00703   return (status);
00704 }
00705 
00706 CMS_STATUS CMS_ASCII_UPDATER::update (long *x, unsigned int len)
00707 {
00708   /* Check to see if the pointers are in the proper range. */
00709   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (long) * len))
00710     {
00711       return (status = CMS_UPDATE_ERROR);
00712     }
00713 
00714   for (unsigned int i = 0; i < len; i++)
00715     {
00716       if (CMS_UPDATE_ERROR == update (x[i]))
00717         {
00718           return (status = CMS_UPDATE_ERROR);
00719         }
00720     }
00721   return (status);
00722 }
00723 
00724 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned long &x)
00725 {
00726   /* Check to see if the pointers are in the proper range. */
00727   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned long)))
00728     {
00729       return (status = CMS_UPDATE_ERROR);
00730     }
00731 
00732   if (encoding)
00733     {
00734       end_current_string[15] = 0;
00735       sprintf (end_current_string, "%-14ld", x);
00736       if (end_current_string[15] != 0 && warning_count < warning_count_max)
00737         {
00738           warning_count++;
00739           rcs_print_error
00740             ("CMS_ASCII_UPDATER: (warning) unsigned long with value %-14ld caused an overflow\n",
00741              x);
00742         }
00743       end_current_string[15] = 0;
00744     }
00745   else
00746     {
00747       if (-1 == safe_strlen (end_current_string, 16))
00748         {
00749           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00750           return (status = CMS_UPDATE_ERROR);
00751         }
00752       errno = 0;
00753       unsigned long
00754         number = strtoul (end_current_string, (char **) NULL, 10);
00755       if (errno != 0)
00756         {
00757           rcs_print_error
00758             ("CMS_ASCII_UPDATER: Error %ld:%s occured during strtoul of(%s).\n",
00759              errno, strerror (errno), end_current_string);
00760           return (status = CMS_UPDATE_ERROR);
00761         }
00762       x = number;
00763     }
00764   end_current_string += 16;
00765   length_current_string += 16;
00766 
00767   return (status);
00768 }
00769 
00770 CMS_STATUS CMS_ASCII_UPDATER::update (unsigned long *x, unsigned int len)
00771 {
00772   /* Check to see if the pointers are in the proper range. */
00773   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (unsigned long) * len))
00774     {
00775       return (status = CMS_UPDATE_ERROR);
00776     }
00777 
00778   for (unsigned int i = 0; i < len; i++)
00779     {
00780       if (CMS_UPDATE_ERROR == update (x[i]))
00781         {
00782           return (status = CMS_UPDATE_ERROR);
00783         }
00784     }
00785   return (status);
00786 }
00787 
00788 /* Float functions */
00789 
00790 CMS_STATUS CMS_ASCII_UPDATER::update (float &x)
00791 {
00792   /* Check to see if the pointers are in the proper range. */
00793   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (float)))
00794     {
00795       return (status = CMS_UPDATE_ERROR);
00796     }
00797 
00798   if (encoding)
00799     {
00800       end_current_string[15] = 0;
00801       sprintf (end_current_string, "%-13.7e", x);
00802       if (end_current_string[15] != 0 && warning_count < warning_count_max)
00803         {
00804           warning_count++;
00805           rcs_print_error
00806             ("CMS_ASCII_UPDATER: (warning) float with value %-13.7e caused an overflow\n",
00807              x);
00808         }
00809       end_current_string[15] = 0;
00810     }
00811   else
00812     {
00813       if (-1 == safe_strlen (end_current_string, 16))
00814         {
00815           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00816           return (status = CMS_UPDATE_ERROR);
00817         }
00818       errno = 0;
00819       double
00820         number = strtod (end_current_string, (char **) NULL);
00821       if (errno != 0)
00822         {
00823           rcs_print_error
00824             ("CMS_ASCII_UPDATER: Error %ld occured during strtol.\n", errno);
00825           return (status = CMS_UPDATE_ERROR);
00826         }
00827       if ((number < -FLT_MAX || FLT_MAX < number) &&
00828           warning_count < warning_count_max)
00829         {
00830           warning_count++;
00831           rcs_print_error
00832             ("CMS_ASCII_UPDATER: (warning) Number %lf out of range for float(%f,%f)\n",
00833              number, -FLT_MAX, FLT_MAX);
00834         }
00835       x = (float) number;
00836     }
00837   end_current_string += 16;
00838   length_current_string += 16;
00839 
00840   return (status);
00841 }
00842 
00843 CMS_STATUS CMS_ASCII_UPDATER::update (float *x, unsigned int len)
00844 {
00845   /* Check to see if the pointers are in the proper range. */
00846   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (float) * len))
00847     {
00848       return (status = CMS_UPDATE_ERROR);
00849     }
00850 
00851   for (unsigned int i = 0; i < len; i++)
00852     {
00853       if (CMS_UPDATE_ERROR == update (x[i]))
00854         {
00855           return (status = CMS_UPDATE_ERROR);
00856         }
00857     }
00858   return (status);
00859 }
00860 
00861 /* Double functions */
00862 
00863 CMS_STATUS CMS_ASCII_UPDATER::update (double &x)
00864 {
00865   /* Check to see if the pointers are in the proper range. */
00866   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (double)))
00867     {
00868       return (status = CMS_UPDATE_ERROR);
00869     }
00870 
00871   if (encoding)
00872     {
00873       end_current_string[15] = 0;
00874       sprintf (end_current_string, "%-13.7e", x);
00875       if (end_current_string[15] != 0 && warning_count < warning_count_max)
00876         {
00877           warning_count++;
00878           rcs_print_error
00879             ("CMS_ASCII_UPDATER: (warning) double with value %-13.7e caused an overflow\n",
00880              x);
00881         }
00882       end_current_string[15] = 0;
00883     }
00884   else
00885     {
00886       if (-1 == safe_strlen (end_current_string, 16))
00887         {
00888           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00889           return (status = CMS_UPDATE_ERROR);
00890         }
00891       errno = 0;
00892       double
00893         number = strtod (end_current_string, (char **) NULL);
00894       if (errno != 0)
00895         {
00896           rcs_print_error
00897             ("CMS_ASCII_UPDATER: Error %ld occured during strtol.\n", errno);
00898           return (status = CMS_UPDATE_ERROR);
00899         }
00900       x = number;
00901     }
00902   end_current_string += 16;
00903   length_current_string += 16;
00904 
00905   return (status);
00906 }
00907 
00908 CMS_STATUS CMS_ASCII_UPDATER::update (double *x, unsigned int len)
00909 {
00910   /* Check to see if the pointers are in the proper range. */
00911   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (double) * len))
00912     {
00913       return (status = CMS_UPDATE_ERROR);
00914     }
00915 
00916   for (unsigned int i = 0; i < len; i++)
00917     {
00918       if (CMS_UPDATE_ERROR == update (x[i]))
00919         {
00920           return (status = CMS_UPDATE_ERROR);
00921         }
00922     }
00923   return (status);
00924 }
00925 
00926 /* long double functions */
00927 
00928 CMS_STATUS CMS_ASCII_UPDATER::update (long double &x)
00929 {
00930   /* Check to see if the pointers are in the proper range. */
00931   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (long double)))
00932     {
00933       return (status = CMS_UPDATE_ERROR);
00934     }
00935 
00936   if (encoding)
00937     {
00938       end_current_string[15] = 0;
00939       sprintf (end_current_string, "%-13.7e", (double) x);
00940       if (end_current_string[15] != 0 && warning_count < warning_count_max)
00941         {
00942           warning_count++;
00943           rcs_print_error
00944             ("CMS_ASCII_UPDATER: (warning) long double with value %-13.7e caused an overflow\n",
00945              x);
00946         }
00947       end_current_string[15] = 0;
00948     }
00949   else
00950     {
00951       if (-1 == safe_strlen (end_current_string, 16))
00952         {
00953           rcs_print_error ("CMS_ASCII_UPDATER: String is too long.\n");
00954           return (status = CMS_UPDATE_ERROR);
00955         }
00956       errno = 0;
00957       double
00958         number = strtod (end_current_string, (char **) NULL);
00959       if (errno != 0)
00960         {
00961           rcs_print_error
00962             ("CMS_ASCII_UPDATER: Error %ld occured during strtol.\n", errno);
00963           return (status = CMS_UPDATE_ERROR);
00964         }
00965       x = (long double) number;
00966     }
00967   end_current_string += 16;
00968   length_current_string += 16;
00969 
00970   return (status);
00971 }
00972 
00973 CMS_STATUS CMS_ASCII_UPDATER::update (long double *x, unsigned int len)
00974 {
00975   /* Check to see if the pointers are in the proper range. */
00976   if (-1 == check_pointer ((char RCS_HUGE *) x, sizeof (long double) * len))
00977     {
00978       return (status = CMS_UPDATE_ERROR);
00979     }
00980 
00981   for (unsigned int i = 0; i < len; i++)
00982     {
00983       if (CMS_UPDATE_ERROR == update (x[i]))
00984         {
00985           return (status = CMS_UPDATE_ERROR);
00986         }
00987     }
00988   return (status);
00989 }

Generated on Sun Dec 2 15:56:48 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001