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

rcs_prnt.cc

Go to the documentation of this file.
00001 #include "rcs_defs.hh"          /* _Windows, RCS_FAR, EXTERN_C_STD_HEADERS */
00002 
00003 #ifdef DEBUG_MEMORY
00004 #include "dbg_mem.h"            // DEBUG_MALLOC, DEBUG_FREE
00005 #else
00006 #define DEBUG_MALLOC(x) malloc(x)
00007 #define DEBUG_FREE(x) free(x)
00008 #endif
00009 
00010 #ifdef EXTERN_C_STD_HEADERS
00011 extern "C"
00012 {
00013 #endif
00014 
00015 #ifdef VXWORKS
00016 #include "vxWorks.h"
00017 #endif
00018 
00019 
00020 #ifdef USING_VARARGS
00021 #include <varargs.h>            /* va_list, va_start(), va_end() */
00022 #else
00023 #include <stdarg.h>             /* va_list, va_start(), va_end() */
00024 #endif
00025 
00026 #ifndef NO_STDIO
00027 #include <stdio.h>              /* __printf()'s */
00028 #endif
00029 
00030 #include <string.h>             /* strchr(), memmove() */
00031 #include <stdlib.h>             /* malloc(), free(), realloc() */
00032 #ifndef UNDER_CE
00033 #include <errno.h>              // errno()
00034 #endif
00035 #ifdef VXWORKS
00036 #include <logLib.h>             /* logMsg() */
00037 #endif
00038 
00039 
00040 #ifdef VXWORKS
00041 #include <taskLib.h>            /* taskIdSelf() */
00042 #else
00043 #include <sys/types.h>
00044 #ifdef UNIX_LIKE_PLAT
00045 #include <unistd.h>             /* getpid() */
00046 #endif
00047 #endif
00048 
00049 #ifdef EXTERN_C_STD_HEADERS
00050 }
00051 #endif
00052 
00053 #ifdef UNDER_CE
00054 #include <winbase.h>            // OutputDebugString()
00055 #endif
00056 
00057 #ifdef _Windows
00058 #include <windows.h>            /* MessageBox() */
00059 #endif
00060 
00061 #include "rcs_prnt.hh"
00062 #include "linklist.hh"
00063 
00064 #ifdef UNDER_CE
00065 #include "rcs_ce.h"
00066 #ifndef EOF
00067 #define EOF (-1)
00068 #endif
00069 #endif
00070 
00071 #ifndef _TIMER_H
00072 extern "C" double RCS_EXPORT etime (void);
00073 #endif
00074 
00075 RCS_LINKED_LIST RCS_FAR *rcs_print_list = NULL;
00076 char RCS_FAR **rcs_lines_table = NULL;
00077 void (RCS_PASCAL RCS_FAR * rcs_print_notify) () = NULL;
00078 #ifndef UNDER_CE
00079 #if !defined(_Windows) || defined(WIN32)
00080 RCS_PRINT_DESTINATION_TYPE rcs_print_destination = RCS_PRINT_TO_STDOUT;
00081 #else
00082 RCS_PRINT_DESTINATION_TYPE rcs_print_destination = RCS_PRINT_TO_LIST;
00083 #endif
00084 #else
00085 RCS_PRINT_DESTINATION_TYPE rcs_print_destination = RCS_PRINT_TO_LIST;
00086 #endif
00087 
00088 #ifdef WIN32
00089 BOOL AllocConsoleCalled = FALSE;
00090 BOOL AllocConsoleRetVal = FALSE;
00091 HANDLE OutputHandle = NULL;
00092 #endif
00093 
00094 int max_rcs_errors_to_print = 30;
00095 int rcs_errors_printed = 0;
00096 
00097 long rcs_print_mode_flags = PRINT_RCS_ERRORS;
00098 #ifndef UNDER_CE
00099 FILE *rcs_print_file_stream = NULL;
00100 char rcs_print_file_name[80] = "rcs_out.txt";
00101 #endif
00102 
00103 char last_error_bufs[4][100];
00104 int error_bufs_initialized = 0;
00105 int last_error_buf_filled = 0;
00106 
00107 
00108 void RCS_EXPORT
00109 set_rcs_print_destination (RCS_PRINT_DESTINATION_TYPE _dest)
00110 {
00111   if (rcs_print_destination == RCS_PRINT_TO_NULL)
00112     {
00113       rcs_errors_printed = 0;
00114     }
00115   rcs_print_destination = _dest;
00116 }
00117 
00118 RCS_PRINT_DESTINATION_TYPE RCS_EXPORT
00119 get_rcs_print_destination ()
00120 {
00121   return (rcs_print_destination);
00122 }
00123 
00124 #ifdef USING_DECLSPEC
00125 RCS_EXPORT char RCS_FAR **
00126 get_rcs_lines_table ()
00127 #else
00128 char RCS_FAR **RCS_EXPORT
00129 get_rcs_lines_table ()
00130 #endif
00131 {
00132   return (rcs_lines_table);
00133 }
00134 
00135 #ifdef USING_DECLSPEC
00136 RCS_EXPORT RCS_LINKED_LIST RCS_FAR *
00137 get_rcs_print_list ()
00138 #else
00139 RCS_LINKED_LIST RCS_FAR *RCS_EXPORT
00140 get_rcs_print_list ()
00141 #endif
00142 {
00143   return (rcs_print_list);
00144 }
00145 
00146 int RCS_EXPORT
00147 get_rcs_print_list_size ()
00148 {
00149   if (NULL != rcs_print_list)
00150     {
00151       return (rcs_print_list->list_size);
00152     }
00153   else
00154     {
00155       return (-1);
00156     }
00157 }
00158 void RCS_EXPORT
00159 set_rcs_print_list_sizing (int _new_max_size,
00160                            LIST_SIZING_MODE _new_sizing_mode)
00161 {
00162   if (NULL == rcs_print_list)
00163     {
00164       rcs_print_list = new RCS_LINKED_LIST;
00165     }
00166   if (NULL != rcs_print_list)
00167     {
00168       rcs_print_list->set_list_sizing_mode (_new_max_size, _new_sizing_mode);
00169     }
00170 }
00171 void RCS_EXPORT
00172 set_rcs_print_notify (RCS_PRINT_NOTIFY_FUNC_PTR _rcs_print_notify)
00173 {
00174   rcs_print_notify = _rcs_print_notify;
00175 }
00176 
00177 void RCS_EXPORT
00178 clean_print_list ()
00179 {
00180   if (NULL != rcs_print_list)
00181     {
00182       delete rcs_print_list;
00183       rcs_print_list = NULL;
00184     }
00185 }
00186 
00187 void RCS_EXPORT
00188 output_print_list (int output_func (char RCS_FAR *))
00189 {
00190   if (NULL != rcs_print_list)
00191     {
00192       char *string_from_list;
00193       string_from_list = (char *) rcs_print_list->get_head ();
00194       while (NULL != string_from_list)
00195         {
00196           if (output_func (string_from_list) != EOF)
00197             {
00198               break;
00199             }
00200           string_from_list = (char *) rcs_print_list->get_next ();
00201         }
00202     }
00203 }
00204 
00205 int RCS_EXPORT
00206 count_characters_in_print_list ()
00207 {
00208   int count = 0;
00209   if (NULL != rcs_print_list)
00210     {
00211       char *string_from_list;
00212       string_from_list = (char *) rcs_print_list->get_head ();
00213       while (NULL != string_from_list)
00214         {
00215           count += strlen (string_from_list);
00216           string_from_list = (char *) rcs_print_list->get_next ();
00217         }
00218     }
00219   return (count);
00220 }
00221 
00222 int RCS_EXPORT
00223 count_lines_in_print_list ()
00224 {
00225   int count = 1;
00226   if (NULL != rcs_print_list)
00227     {
00228       char *string_from_list;
00229       string_from_list = (char *) rcs_print_list->get_head ();
00230       while (NULL != string_from_list)
00231         {
00232           char *line;
00233           line = strchr (string_from_list, '\n');
00234           while (NULL != line)
00235             {
00236               count++;
00237               line = strchr (line + 1, '\n');
00238             }
00239           string_from_list = (char *) rcs_print_list->get_next ();
00240         }
00241     }
00242   return (count);
00243 }
00244 
00245 void RCS_EXPORT
00246 convert_print_list_to_lines ()
00247 {
00248   char *temp_buf = NULL;
00249   static int last_id_converted = -1;
00250   if (NULL != rcs_print_list)
00251     {
00252       char *string_from_list;
00253       if (-1 == last_id_converted)
00254         {
00255           string_from_list = (char *) rcs_print_list->get_head ();
00256         }
00257       else
00258         {
00259           string_from_list =
00260             (char *) rcs_print_list->get_first_newer (last_id_converted);
00261         }
00262       while (NULL != string_from_list)
00263         {
00264           char *next_line;
00265           next_line = strchr (string_from_list, '\n');
00266           if (NULL == next_line)
00267             {
00268               if (NULL == temp_buf)
00269                 {
00270                   temp_buf = (char *) malloc (strlen (string_from_list) + 1);
00271                   strcpy (temp_buf, string_from_list);
00272                 }
00273               else
00274                 {
00275                   temp_buf = (char *) realloc (temp_buf,
00276                                                strlen (temp_buf)
00277                                                + strlen (string_from_list) +
00278                                                1);
00279                   strcat (temp_buf, string_from_list);
00280                 }
00281               rcs_print_list->delete_current_node ();
00282             }
00283           else
00284             {
00285               if (temp_buf != NULL)
00286                 {
00287                   temp_buf = (char *) realloc (temp_buf,
00288                                                strlen (temp_buf)
00289                                                + strlen (string_from_list) +
00290                                                1);
00291                   strcat (temp_buf, string_from_list);
00292                   rcs_print_list->delete_current_node ();
00293                   rcs_print_list->store_after_current_node (temp_buf,
00294                                                             strlen (temp_buf)
00295                                                             + 1, 1);
00296                   DEBUG_FREE (temp_buf);
00297                   temp_buf = NULL;
00298                 }
00299               else if (next_line[1] != 0)
00300                 {
00301                   rcs_print_list->store_after_current_node (next_line + 1,
00302                                                             strlen (next_line
00303                                                                     + 1) + 1,
00304                                                             1);
00305                   next_line[1] = 0;
00306                 }
00307             }
00308           string_from_list = (char *) rcs_print_list->get_next ();
00309         }
00310     }
00311   last_id_converted = rcs_print_list->get_newest_id ();
00312   if (temp_buf != NULL)
00313     {
00314       rcs_print_list->store_at_tail (temp_buf, strlen (temp_buf) + 1, 1);
00315       DEBUG_FREE (temp_buf);
00316       temp_buf = NULL;
00317     }
00318 }
00319 
00320 void RCS_EXPORT
00321 update_lines_table ()
00322 {
00323   if (NULL != rcs_lines_table)
00324     {
00325       DEBUG_FREE (rcs_lines_table);
00326       rcs_lines_table = NULL;
00327     }
00328   if (NULL != rcs_print_list)
00329     {
00330       convert_print_list_to_lines ();
00331       rcs_lines_table = (char RCS_FAR **) malloc (sizeof (char *)
00332                                                   *
00333                                                   rcs_print_list->list_size);
00334       if (NULL != rcs_print_list)
00335         {
00336           char *string_from_list;
00337           string_from_list = (char *) rcs_print_list->get_head ();
00338           int i = 0;
00339           while (NULL != string_from_list)
00340             {
00341               rcs_lines_table[i] = string_from_list;
00342               i++;
00343               string_from_list = (char *) rcs_print_list->get_next ();
00344             }
00345         }
00346     }
00347 }
00348 
00349 #ifdef USING_DECLSPEC
00350 RCS_EXPORT char RCS_FAR *
00351 strip_control_characters (char RCS_FAR * _dest, char RCS_FAR * _src)
00352 #else
00353 char RCS_FAR *RCS_EXPORT
00354 strip_control_characters (char RCS_FAR * _dest, char RCS_FAR * _src)
00355 #endif
00356 {
00357   static char line_buffer[255];
00358   char *destination;
00359 #ifndef UNDER_CE
00360   char *control_char_loc;
00361   if (NULL == _dest)
00362     {
00363       destination = line_buffer;
00364       if (strlen (_src) < 255)
00365         {
00366           strcpy (line_buffer, _src);
00367         }
00368       else
00369         {
00370           if (NULL == strpbrk (_src, "\n\r\t\b"))
00371             {
00372               return (_src);
00373             }
00374           else
00375             {
00376               return (NULL);
00377             }
00378         }
00379     }
00380   else
00381     {
00382       destination = _dest;
00383       if (_dest != _src)
00384         {
00385 #ifndef __CENTERLINE__          /*  CenterLine messed up string.h for C++ so that memmove will be undefined. */
00386           memmove (_dest, _src, strlen (_src));
00387 #else
00388           strcpy (line_buffer, _src);
00389           strcpy (_dest, line_buffer);
00390 #endif
00391         }
00392     }
00393   control_char_loc = strpbrk (destination, "\n\r\t\b");
00394   while (NULL != control_char_loc)
00395     {
00396       *control_char_loc = ' ';  /* Replace control character with SPACE */
00397       control_char_loc = strpbrk (control_char_loc, "\n\r\t\b");
00398     }
00399 #else
00400   if (NULL == _dest)
00401     {
00402       destination = line_buffer;
00403     }
00404   else
00405     {
00406       destination = _dest;
00407     }
00408   strcpy (destination, _src);
00409 #endif
00410   return (destination);
00411 
00412 }
00413 
00414 
00415 
00416 /* In windows DLLs for Microsoft Visual C++ sscanf is not supported so
00417 use separate_words to parse the string followed by commands like strtod to
00418 convert each word. */
00419 int RCS_EXPORT
00420 separate_words (char RCS_FAR ** _dest, int _max, char RCS_FAR * _src)
00421 {
00422   static char word_buffer[256];
00423   int i;
00424   if (NULL == _dest || NULL == _src)
00425     {
00426       return -1;
00427     }
00428   if (strlen (_src) > 255)
00429     {
00430       return -1;
00431     }
00432   strcpy (word_buffer, _src);
00433   _dest[0] = strtok (word_buffer, " \n\r\t");
00434   for (i = 0; NULL != _dest[i] && i < _max - 1; i++)
00435     {
00436       _dest[i + 1] = strtok (NULL, " \n\r\t");
00437     }
00438   if (_dest[_max - 1] == NULL && i == _max - 1)
00439     {
00440       i--;
00441     }
00442   return (i + 1);
00443 }
00444 
00445 int RCS_EXPORT
00446 rcs_vprint (char RCS_FAR * _fmt, va_list _args, int save_string)
00447 {
00448   static char temp_string[256];
00449 
00450   if (NULL == _fmt)
00451     {
00452       return (EOF);
00453     }
00454   if (strlen (_fmt) > 200)      /* Might overflow temp_string. */
00455     {
00456       return (EOF);
00457     }
00458 #ifndef UNDER_CE
00459   if (EOF == (int) vsprintf (temp_string, _fmt, _args))
00460     {
00461       return (EOF);
00462     }
00463 #else
00464   if (EOF == (int) RCS_CE_VSPRINTF (temp_string, _fmt, _args))
00465     {
00466       return (EOF);
00467     }
00468 #endif
00469   if (save_string)
00470     {
00471       if (!error_bufs_initialized)
00472         {
00473           memset (last_error_bufs[0], 0, 100);
00474           memset (last_error_bufs[1], 0, 100);
00475           memset (last_error_bufs[2], 0, 100);
00476           memset (last_error_bufs[3], 0, 100);
00477           error_bufs_initialized = 1;
00478         }
00479       last_error_buf_filled++;
00480       last_error_buf_filled %= 4;
00481       strncpy (last_error_bufs[last_error_buf_filled], temp_string, 99);
00482     }
00483   return (rcs_fputs (temp_string));
00484 }
00485 
00486 int RCS_EXPORT
00487 rcs_puts (char RCS_FAR * _str)
00488 {
00489   int retval, retval2;
00490   retval = rcs_fputs (_str);
00491   if (retval != EOF)
00492     {
00493       retval2 = rcs_fputs ("\n");
00494       if (retval2 != EOF)
00495         {
00496           retval += retval;
00497         }
00498       else
00499         {
00500           retval = EOF;
00501         }
00502     }
00503   return (retval);
00504 }
00505 
00506 int RCS_EXPORT
00507 rcs_fputs (char RCS_FAR * _str)
00508 {
00509   int retval = EOF;
00510   if (NULL != _str)
00511     {
00512       if (0 == _str[0])
00513         {
00514           return (0);
00515         }
00516       switch (rcs_print_destination)
00517         {
00518 #ifdef VXWORKS
00519         case RCS_PRINT_TO_LOGGER:
00520           retval = logMsg (_str, 0, 0, 0, 0, 0, 0);
00521           break;
00522 #else
00523         case RCS_PRINT_TO_LOGGER:
00524 #endif
00525 
00526         case RCS_PRINT_TO_STDOUT:
00527 #ifndef _WINDLL
00528 #ifdef UNDER_CE
00529 #ifdef UNICODE
00530           wchar_t wstr[256];
00531           RCS_CE_ASCII_TO_UNICODE (wstr, _str, 256);
00532           OutputDebugString (wstr);
00533 #else
00534           OutputDebugString (_str);
00535 #endif
00536 #else
00537 #ifdef WIN32
00538           if (!AllocConsoleCalled)
00539             {
00540               AllocConsoleRetVal = AllocConsole ();
00541               AllocConsoleCalled = TRUE;
00542             }
00543           OutputHandle = GetStdHandle (STD_OUTPUT_HANDLE);
00544           if (NULL == OutputHandle)
00545             {
00546               retval = fputs (_str, stdout);
00547               fflush (stdout);
00548             }
00549           else
00550             {
00551               DWORD bytes_written;
00552               WriteConsole (OutputHandle, _str, strlen (_str),
00553                             (LPDWORD) & bytes_written, NULL);
00554               retval = (int) bytes_written;
00555             }
00556 #else
00557           retval = fputs (_str, stdout);
00558           fflush (stdout);
00559 #endif
00560 #endif
00561 #endif
00562           break;
00563 
00564         case RCS_PRINT_TO_STDERR:
00565 #ifndef UNDER_CE
00566           retval = fputs (_str, stderr);
00567           fflush (stderr);
00568 #endif
00569           break;
00570 
00571         case RCS_PRINT_TO_LIST:
00572           if (NULL == rcs_print_list)
00573             {
00574               rcs_print_list = new RCS_LINKED_LIST;
00575               if (NULL != rcs_print_list)
00576                 {
00577                   rcs_print_list->set_list_sizing_mode (256,
00578                                                         DELETE_FROM_HEAD);
00579                 }
00580             }
00581           if (NULL != rcs_print_list)
00582             {
00583               if (-1 ==
00584                   rcs_print_list->store_at_tail (_str,
00585                                                  (retval =
00586                                                   strlen (_str)) + 1, 1))
00587                 {
00588                   retval = EOF;
00589                 }
00590             }
00591           break;
00592         case RCS_PRINT_TO_NULL:
00593           retval = strlen (_str);
00594           break;
00595         case RCS_PRINT_TO_FILE:
00596 #ifndef UNDER_CE
00597           if (NULL == rcs_print_file_stream)
00598             {
00599               if (NULL == rcs_print_file_name)
00600                 {
00601                   return EOF;
00602                 }
00603               rcs_print_file_stream = fopen (rcs_print_file_name, "a+");
00604             }
00605           if (NULL == rcs_print_file_stream)
00606             {
00607               return EOF;
00608             }
00609           retval = fputs (_str, rcs_print_file_stream);
00610           fflush (rcs_print_file_stream);
00611 #endif
00612           break;
00613 
00614 #if  defined(_Windows) && !defined(gnuwin32)
00615         case RCS_PRINT_TO_MESSAGE_BOX:
00616 #ifdef UNICODE
00617           wchar_t wstr2[256];
00618           RCS_CE_ASCII_TO_UNICODE (wstr2, _str, 256);
00619           retval = strlen (_str);
00620           if (IDOK != MessageBox (NULL, wstr2, TEXT ("RCS Message"), MB_OK))
00621             {
00622               retval = EOF;
00623             }
00624 #else
00625           retval = strlen (_str);
00626           if (IDOK != MessageBox (NULL, _str, "RCS Message", MB_OK))
00627             {
00628               retval = EOF;
00629             }
00630 #endif
00631           break;
00632 #endif
00633 
00634         default:
00635           break;
00636         }
00637       if (NULL != rcs_print_notify)
00638         {
00639           (*rcs_print_notify) ();
00640         }
00641     }
00642   return (retval);
00643 }
00644 
00645 void RCS_EXPORT
00646 close_rcs_printing ()
00647 {
00648 #ifndef UNDER_CE
00649   switch (rcs_print_destination)
00650     {
00651     case RCS_PRINT_TO_LIST:
00652       clean_print_list ();
00653       break;
00654 
00655     case RCS_PRINT_TO_FILE:
00656       if (NULL != rcs_print_file_stream)
00657         {
00658           fclose (rcs_print_file_stream);
00659           rcs_print_file_stream = NULL;
00660         }
00661       break;
00662     default:
00663       break;
00664     }
00665 #endif
00666   return;
00667 }
00668 
00669 int RCS_EXPORT
00670 set_rcs_print_file (char RCS_FAR * _file_name)
00671 {
00672 #ifndef UNDER_CE
00673   if (_file_name == NULL)
00674     {
00675       return -1;
00676     }
00677   if (strlen (_file_name) > 80)
00678     {
00679       return -1;
00680     }
00681   strcpy (rcs_print_file_name, _file_name);
00682   if (NULL != rcs_print_file_stream)
00683     {
00684       fclose (rcs_print_file_stream);
00685     }
00686   rcs_print_file_stream = fopen (rcs_print_file_name, "a+");
00687   if (NULL == rcs_print_file_stream)
00688     {
00689       return -1;
00690     }
00691 #endif
00692   return 0;
00693 }
00694 
00695 int RCS_EXPORT
00696 rcs_print (char RCS_FAR * _fmt, ...)
00697 {
00698   static char temp_buffer[256];
00699   int retval;
00700   va_list args;
00701   if (strlen (_fmt) > 250)
00702     {
00703       return EOF;
00704     }
00705   va_start (args, _fmt);
00706 #ifdef sparcworks_sun4          // this platform has vsprintf defined as
00707   // char *vsprintf(char *, const char *, va_list);
00708   // it should be
00709   // int vsprintf(char *, const char *, va_list);
00710   vsprintf (temp_buffer, _fmt, args);
00711   va_end (args);
00712 #else
00713 #ifndef UNDER_CE
00714   retval = vsprintf (temp_buffer, _fmt, args);
00715 #else
00716   retval = RCS_CE_VSPRINTF (temp_buffer, _fmt, args);
00717 #endif
00718   va_end (args);
00719   if (retval == (EOF))
00720     {
00721       return EOF;
00722     }
00723 #endif
00724   retval = rcs_fputs (temp_buffer);
00725   return (retval);
00726 }
00727 
00728 #ifndef DO_NOT_USE_RCS_PRINT_ERROR_NEW
00729 
00730 static const char *rcs_error_filename = NULL;
00731 static int rcs_error_linenum = -1;
00732 int RCS_EXPORT
00733 set_print_rcs_error_info (const char *file, int line)
00734 {
00735   rcs_error_filename = file;
00736   rcs_error_linenum = line;
00737   return (0);
00738 }
00739 
00740 
00741 int RCS_EXPORT
00742 print_rcs_error_new (char RCS_FAR * _fmt, ...)
00743 {
00744   int retval = 0;
00745   va_list args;
00746   va_start (args, _fmt);
00747   if ((rcs_print_mode_flags & PRINT_RCS_ERRORS)
00748       && ((max_rcs_errors_to_print >= rcs_errors_printed)
00749           || max_rcs_errors_to_print < 0))
00750     {
00751       if (NULL != rcs_error_filename && rcs_error_linenum > 0)
00752         {
00753           rcs_print ("%s %d: ", rcs_error_filename, rcs_error_linenum);
00754           rcs_error_filename = NULL;
00755           rcs_error_linenum = -1;
00756         }
00757       retval = rcs_vprint (_fmt, args, 1);
00758       if (max_rcs_errors_to_print == rcs_errors_printed &&
00759           max_rcs_errors_to_print >= 0)
00760         {
00761           rcs_print ("\nMaximum number of errors to print exceeded!\n");
00762         }
00763     }
00764   if (rcs_print_destination != RCS_PRINT_TO_NULL)
00765     {
00766       rcs_errors_printed++;
00767     }
00768   va_end (args);
00769   return (retval);
00770 }
00771 
00772 #endif
00773 
00774 
00775 int RCS_EXPORT
00776 rcs_print_debug (long flag_to_check, char RCS_FAR * _fmt, ...)
00777 {
00778   int retval = 0;
00779   int pid = 0;
00780   va_list args;
00781   va_start (args, _fmt);
00782 
00783   if (flag_to_check & rcs_print_mode_flags)
00784     {
00785 #ifdef WIN32
00786       pid = GetCurrentProcessId ();
00787 #else
00788 #ifndef VXWORKS
00789       pid = getpid ();
00790 #else
00791       pid = taskIdSelf ();
00792 #endif
00793 #endif
00794       rcs_print ("(time=%f,pid=%d): ", etime (), pid);
00795       retval = rcs_vprint (_fmt, args, 0);
00796     }
00797   va_end (args);
00798   return (retval);
00799 }
00800 
00801 void RCS_EXPORT
00802 set_rcs_print_flag (long flag_to_set)
00803 {
00804   rcs_print_mode_flags |= flag_to_set;
00805 }
00806 
00807 void RCS_EXPORT
00808 clear_rcs_print_flag (long flag_to_clear)
00809 {
00810   rcs_print_mode_flags &= ~(flag_to_clear);
00811 }
00812 
00813 
00814 
00815 int RCS_EXPORT
00816 rcs_print_sys_error (int error_source, char RCS_FAR * _fmt, ...)
00817 {
00818   static char temp_string[256];
00819   static char message_string[512];
00820   va_list args;
00821   va_start (args, _fmt);
00822 
00823 
00824   if (NULL == _fmt)
00825     {
00826       return (EOF);
00827     }
00828   if (strlen (_fmt) > 200)      /* Might overflow temp_string. */
00829     {
00830       return (EOF);
00831     }
00832 #ifndef UNDER_CE
00833   if (EOF == (int) vsprintf (temp_string, _fmt, args))
00834     {
00835       return (EOF);
00836     }
00837 #else
00838   if (EOF == (int) RCS_CE_VSPRINTF (temp_string, _fmt, args))
00839     {
00840       return (EOF);
00841     }
00842 #endif
00843   va_end (args);
00844   if (max_rcs_errors_to_print == rcs_errors_printed &&
00845       max_rcs_errors_to_print >= 0)
00846     {
00847       rcs_print ("\nMaximum number of errors to print exceeded!\n");
00848     }
00849   rcs_errors_printed++;
00850   if (max_rcs_errors_to_print <= rcs_errors_printed &&
00851       max_rcs_errors_to_print >= 0)
00852     {
00853       return (EOF);
00854     }
00855 
00856   switch (error_source)
00857     {
00858     case ERRNO_ERROR_SOURCE:
00859 #ifndef UNDER_CE
00860       sprintf (message_string, "%s %d %s\n", temp_string, errno,
00861                strerror (errno));
00862 #endif
00863       rcs_puts (message_string);
00864       break;
00865 
00866 #ifndef UNDER_CE
00867 #ifdef WIN32
00868     case GETLASTERROR_ERROR_SOURCE:
00869       {
00870         char *msgBuf = NULL;
00871         DWORD errCode = GetLastError ();
00872         FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
00873                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, errCode,
00874                        MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
00875                        (LPTSTR) & msgBuf, 0, NULL);
00876         if (NULL != msgBuf)
00877           {
00878             sprintf (message_string, "%s %d %s\n", temp_string, errCode,
00879                      msgBuf);
00880           }
00881         else
00882           {
00883             sprintf (message_string, "%s %d\n", temp_string, errCode);
00884           }
00885       }
00886       rcs_puts (message_string);
00887       break;
00888 
00889     case WSAGETLASTERROR_ERROR_SOURCE:
00890       {
00891         char *msgBuf = NULL;
00892         DWORD errCode = WSAGetLastError ();
00893         FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
00894                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, errCode,
00895                        MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
00896                        (LPTSTR) & msgBuf, 0, NULL);
00897         if (NULL != msgBuf)
00898           {
00899             sprintf (message_string, "%s %d %s\n", temp_string, errCode,
00900                      msgBuf);
00901           }
00902         else
00903           {
00904             sprintf (message_string, "%s %d\n", temp_string, errCode);
00905           }
00906       }
00907       rcs_puts (message_string);
00908       break;
00909 
00910 #endif
00911 #endif
00912 
00913     default:
00914       rcs_puts (temp_string);
00915       break;
00916     }
00917   return (strlen (temp_string));
00918 }
00919 
00920 
00921 #ifdef rcs_print_error
00922 #undef rcs_print_error
00923 #endif
00924 extern "C"
00925 {
00926   int RCS_EXPORT rcs_print_error (char RCS_FAR * _fmt, ...);
00927 }
00928 
00929 int RCS_EXPORT
00930 rcs_print_error (char RCS_FAR * _fmt, ...)
00931 {
00932   int retval = 0;
00933   va_list args;
00934 
00935   va_start (args, _fmt);
00936   if ((rcs_print_mode_flags & PRINT_RCS_ERRORS)
00937       && ((max_rcs_errors_to_print >= rcs_errors_printed)
00938           || max_rcs_errors_to_print < 0))
00939     {
00940       retval = rcs_vprint (_fmt, args, 1);
00941       if (max_rcs_errors_to_print == rcs_errors_printed &&
00942           max_rcs_errors_to_print >= 0)
00943         {
00944           rcs_print ("\nMaximum number of errors to print exceeded!\n");
00945         }
00946     }
00947   if (rcs_print_destination != RCS_PRINT_TO_NULL)
00948     {
00949       rcs_errors_printed++;
00950     }
00951   va_end (args);
00952   return (retval);
00953 }

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