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

cms_dup.cc

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

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