home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / vibfiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  15.1 KB  |  704 lines  |  [TEXT/R*ch]

  1. /*   vibfiles.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibfiles.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.5 $
  33. *
  34. * File Description: 
  35. *       Vibrant file functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef VAR_ARGS
  51. #include <varargs.h>
  52. #else
  53. #include <stdarg.h>
  54. #endif
  55.  
  56. Nlm_Boolean  Nlm_fileDone = TRUE;
  57. Nlm_Int2     Nlm_fileError = 0;
  58. Nlm_Char     Nlm_termCH = '\0';
  59.  
  60. static Nlm_Int2  charCount;
  61.  
  62. static void Nlm_DrawACharacter (Nlm_Char ch)
  63.  
  64. {
  65.   Nlm_WindoW  w;
  66.  
  67.   w = Nlm_FrontWindow ();
  68.   Nlm_DoSendChar ((Nlm_GraphiC) w, ch, TRUE);
  69. }
  70.  
  71. static Nlm_Char Nlm_ReadCharFromTerm (void)
  72.  
  73. {
  74.   Nlm_Char     ch;
  75. #ifdef OS_MAC
  76.   EventRecord  event;
  77. #endif
  78. #ifdef WIN_MSWIN
  79.   MSG          msg;
  80.   HWND         hwnd;
  81. #endif
  82.  
  83.   ch = '\0';
  84. #ifdef OS_MAC
  85.   while (ch == '\0') {
  86.     if (GetNextEvent (keyDownMask + autoKeyMask, &event)) {
  87.       ch = (Nlm_Char) (event.message % 256);
  88.     }
  89.   }
  90.   Nlm_DrawACharacter (ch);
  91.   if (ch == '\3') {
  92.     ch = '\0';
  93.   }
  94. #endif
  95. #ifdef WIN_MSWIN
  96.   hwnd = GetFocus ();
  97.   if (hwnd != NULL) {
  98.     hwnd = GetParent (hwnd);
  99.     if (hwnd != NULL) {
  100.       SetFocus (hwnd);
  101.     }
  102.   }
  103.   while (ch == '\0') {
  104.     while (PeekMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE)) {
  105.       if (GetMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP)) {
  106.         TranslateMessage (&msg);
  107.         DispatchMessage (&msg);
  108.       }
  109.     }
  110.     while (PeekMessage (&msg, NULL, WM_CHAR, WM_CHAR, PM_NOREMOVE)) {
  111.       if (GetMessage (&msg, NULL, WM_CHAR, WM_CHAR)) {
  112.         ch = (Nlm_Char) msg.wParam;
  113.       }
  114.     }
  115.     if (ch == '\r') {
  116.       ch = '\n';
  117.     }
  118.   }
  119.   Nlm_DrawACharacter (ch);
  120. #endif
  121. #ifdef WIN_MOTIF
  122. #endif
  123.   return ch;
  124. }
  125.  
  126. extern Nlm_Char Nlm_ReadChar (FILE *f)
  127.  
  128. {
  129.   Nlm_Char  ch;
  130.   int       getcrsult;
  131.  
  132.   ch = '\0';
  133.   Nlm_fileDone = FALSE;
  134.   if (f != NULL) {
  135.     getcrsult = fgetc (f);
  136.     ch = (Nlm_Char) getcrsult;
  137.     if (getcrsult == EOF && feof (f)) {
  138.       ch = '\0';
  139.     }
  140.   } else {
  141.     ch = Nlm_ReadCharFromTerm ();
  142.   }
  143.   Nlm_fileDone = (Nlm_Boolean) (ch != '\0');
  144.   return ch;
  145. }
  146.  
  147. extern void Nlm_WriteChar (FILE *f, Nlm_Char ch)
  148.  
  149. {
  150.   if (f != NULL) {
  151.     Nlm_fileError = fputc (ch, f);
  152.     Nlm_fileDone = (Nlm_Boolean) (Nlm_fileError == 0 || ferror (f) == 0);
  153.   } else {
  154.     Nlm_DrawACharacter (ch);
  155.     Nlm_fileError = FALSE;
  156.     Nlm_fileDone = TRUE;
  157.   }
  158. }
  159.  
  160. extern void Nlm_WriteLn (FILE *f)
  161.  
  162. {
  163.   Nlm_WriteChar (f, '\n');
  164. }
  165.  
  166. static void Nlm_OpenString (FILE *f, Nlm_CharPtr str,
  167.                             Nlm_Boolean ignore, Nlm_sizeT maxsize)
  168.  
  169. {
  170.   Nlm_fileDone = FALSE;
  171.   if (str != NULL && maxsize > 0) {
  172.     str [0] = '\0';
  173.   }
  174.   charCount = 0;
  175.   do {
  176.     Nlm_termCH = Nlm_ReadChar (f);
  177.   } while (Nlm_termCH == ' ' && ignore);
  178. }
  179.  
  180. static void Nlm_InsertNextChar (FILE *f, Nlm_CharPtr str,
  181.                                 Nlm_Boolean ignore, Nlm_sizeT maxsize)
  182.  
  183. {
  184.   do {
  185.     if (charCount == 0 && ignore && Nlm_termCH == ' ') {
  186.     } else if (Nlm_termCH == '\b') {
  187.       if (charCount > 0) {
  188.         charCount--;
  189.       }
  190.     } else if (charCount < (Nlm_Int2) maxsize && Nlm_termCH != '\0') {
  191.       str [charCount] = Nlm_termCH;
  192.       charCount++;
  193.     }
  194.     Nlm_termCH = Nlm_ReadChar (f);
  195.   } while (Nlm_termCH == '\b' || (charCount == 0 && ignore && Nlm_termCH == ' '));
  196. }
  197.  
  198. static void Nlm_CloseString (FILE *f, Nlm_CharPtr str, Nlm_sizeT maxsize)
  199.  
  200. {
  201.   if (charCount <= (Nlm_Int2) maxsize) {
  202.     str [charCount] = '\0';
  203.   }
  204.   Nlm_fileDone = (Nlm_Boolean) (! feof (f));
  205. }
  206.  
  207. extern void Nlm_ReadString (FILE *f, Nlm_CharPtr str, Nlm_sizeT maxsize)
  208.  
  209. {
  210.   Nlm_fileDone = FALSE;
  211.   if (str != NULL) {
  212.     Nlm_OpenString (f, str, TRUE, maxsize);
  213.     while (Nlm_termCH > ' ') {
  214.       Nlm_InsertNextChar (f, str, TRUE, maxsize);
  215.     }
  216.     Nlm_CloseString (f, str, maxsize);
  217.   }
  218. }
  219.  
  220. extern void Nlm_ReadField (FILE *f, Nlm_CharPtr str, Nlm_sizeT maxsize)
  221.  
  222. {
  223.   Nlm_fileDone = FALSE;
  224.   if (str != NULL) {
  225.     Nlm_OpenString (f, str, TRUE, maxsize);
  226.     while (Nlm_termCH >= ' ') {
  227.       Nlm_InsertNextChar (f, str, TRUE, maxsize);
  228.     }
  229.     Nlm_CloseString (f, str, maxsize);
  230.   }
  231. }
  232.  
  233. extern void Nlm_ReadLine (FILE *f, Nlm_CharPtr str, Nlm_sizeT maxsize)
  234.  
  235. {
  236.   Nlm_fileDone = FALSE;
  237.   if (str != NULL) {
  238.     Nlm_OpenString (f, str, FALSE, maxsize);
  239.     while (Nlm_termCH != '\n' && Nlm_termCH != '\r' && Nlm_termCH != '\0') {
  240.       Nlm_InsertNextChar (f, str, FALSE, maxsize);
  241.     }
  242.     Nlm_CloseString (f, str, maxsize);
  243.   }
  244. }
  245.  
  246. extern void Nlm_WriteString (FILE *f, Nlm_CharPtr str)
  247.  
  248. {
  249.   Nlm_Int2  i;
  250.  
  251.   Nlm_fileDone = FALSE;
  252.   if (str != NULL) {
  253.     i = 0;
  254.     while (str [i] != '\0') {
  255.       Nlm_WriteChar (f, str [i]);
  256.       i++;
  257.     }
  258.   }
  259. }
  260.  
  261. extern void Nlm_ReadText (FILE *f, Nlm_CharPtr str, Nlm_sizeT maxsize)
  262.  
  263. {
  264.   Nlm_ReadLine (f, str, maxsize);
  265. }
  266.  
  267. #ifdef VAR_ARGS
  268. void CDECL Nlm_WriteText (f, format, va_alist)
  269.   FILE *f;
  270.   char *format;
  271.   va_dcl
  272. #else
  273. void CDECL Nlm_WriteText (FILE *f, char *format, ...)
  274. #endif
  275.  
  276. {
  277.   va_list  args;
  278.   char     buf[120];
  279.  
  280. #ifdef VAR_ARGS
  281.   va_start(args);
  282. #else
  283.   va_start(args, format);
  284. #endif
  285.   vsprintf(buf, format, args);
  286.   va_end(args);
  287.  
  288.   Nlm_WriteString (f, buf);
  289. }
  290.  
  291. #ifdef VAR_ARGS
  292. void CDECL Nlm_WriteLog (format, va_alist)
  293.   char *format;
  294.   va_dcl
  295. #else
  296. void CDECL Nlm_WriteLog (char *format, ...)
  297. #endif
  298.  
  299. {
  300.   va_list  args;
  301.   char     buf[120];
  302.   FILE     *f;
  303.  
  304. #ifdef VAR_ARGS
  305.   va_start(args);
  306. #else
  307.   va_start(args, format);
  308. #endif
  309.   vsprintf(buf, format, args);
  310.   va_end(args);
  311.  
  312.   f = Nlm_FileOpen ("LogFile", "a");
  313.   if (f != NULL) {
  314.     Nlm_WriteString (f, buf);
  315.     Nlm_FileClose (f);
  316.   }
  317. }
  318.  
  319. extern Nlm_Uint2 Nlm_ReadCard (FILE *f)
  320.  
  321. {
  322.   Nlm_Uint2  cardval;
  323.   Nlm_Char   ioStr [256];
  324.  
  325.   Nlm_fileDone = FALSE;
  326.   cardval = 0;
  327.   Nlm_ReadString (f, ioStr, sizeof (ioStr));
  328.   if (Nlm_fileDone) {
  329.     Nlm_fileDone = Nlm_StrToCard (ioStr, &cardval);
  330.   }
  331.   return cardval;
  332. }
  333.  
  334. extern void Nlm_WriteCard (FILE *f, Nlm_Uint2 cardval, Nlm_Int2 length)
  335.  
  336. {
  337.   Nlm_Char  ioStr [256];
  338.  
  339.   Nlm_fileDone = FALSE;
  340.   Nlm_CardToStr (cardval, ioStr, length, sizeof (ioStr));
  341.   Nlm_WriteString (f, ioStr);
  342. }
  343.  
  344. extern Nlm_Int2 Nlm_ReadInt (FILE *f)
  345.  
  346. {
  347.   Nlm_Int2  intval;
  348.   Nlm_Char  ioStr [256];
  349.  
  350.   Nlm_fileDone = FALSE;
  351.   intval = 0;
  352.   Nlm_ReadString (f, ioStr, sizeof (ioStr));
  353.   if (Nlm_fileDone) {
  354.     Nlm_fileDone = Nlm_StrToInt (ioStr, &intval);
  355.   }
  356.   return intval;
  357. }
  358.  
  359. extern void Nlm_WriteInt (FILE *f, Nlm_Int2 intval, Nlm_Int2 length)
  360.  
  361. {
  362.   Nlm_Char  ioStr [256];
  363.  
  364.   Nlm_fileDone = FALSE;
  365.   Nlm_IntToStr (intval, ioStr, length, sizeof (ioStr));
  366.   Nlm_WriteString (f, ioStr);
  367. }
  368.  
  369. extern Nlm_Int4 Nlm_ReadLong (FILE *f)
  370.  
  371. {
  372.   Nlm_Int4  longval;
  373.   Nlm_Char  ioStr [256];
  374.  
  375.   Nlm_fileDone = FALSE;
  376.   longval = 0;
  377.   Nlm_ReadString (f, ioStr, sizeof (ioStr));
  378.   if (Nlm_fileDone) {
  379.     Nlm_fileDone = Nlm_StrToLong (ioStr, &longval);
  380.   }
  381.   return longval;
  382. }
  383.  
  384. extern void Nlm_WriteLong (FILE *f, Nlm_Int4 longval, Nlm_Int2 length)
  385.  
  386. {
  387.   Nlm_Char  ioStr [256];
  388.  
  389.   Nlm_fileDone = FALSE;
  390.   Nlm_LongToStr (longval, ioStr, length, sizeof (ioStr));
  391.   Nlm_WriteString (f, ioStr);
  392. }
  393.  
  394. extern Nlm_FloatLo Nlm_ReadReal (FILE *f)
  395.  
  396. {
  397.   Nlm_FloatHi  doubleval;
  398.   Nlm_Char     ioStr [256];
  399.   Nlm_FloatLo  realval;
  400.  
  401.   Nlm_fileDone = FALSE;
  402.   doubleval = 0.0;
  403.   Nlm_ReadString (f, ioStr, sizeof (ioStr));
  404.   if (Nlm_fileDone) {
  405.     Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
  406.   }
  407.   realval = (Nlm_FloatLo) doubleval;
  408.   return realval;
  409. }
  410.  
  411. extern void Nlm_WriteReal (FILE *f, Nlm_FloatLo realval,
  412.                            Nlm_Int2 length, Nlm_Int2 dec)
  413.  
  414. {
  415.   Nlm_Char  ioStr [256];
  416.  
  417.   Nlm_fileDone = FALSE;
  418.   Nlm_RealToStr (realval, ioStr, length, dec, sizeof (ioStr));
  419.   Nlm_WriteString (f, ioStr);
  420. }
  421.  
  422. extern Nlm_FloatHi Nlm_ReadDouble (FILE *f)
  423.  
  424. {
  425.   Nlm_FloatHi  doubleval;
  426.   Nlm_Char     ioStr [256];
  427.  
  428.   Nlm_fileDone = FALSE;
  429.   doubleval = 0.0;
  430.   Nlm_ReadString (f, ioStr, sizeof (ioStr));
  431.   if (Nlm_fileDone) {
  432.     Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
  433.   }
  434.   return doubleval;
  435. }
  436.  
  437. extern void Nlm_WriteDouble (FILE *f, Nlm_FloatHi doubleval,
  438.                              Nlm_Int2 length, Nlm_Int2 dec)
  439.  
  440. {
  441.   Nlm_Char  ioStr [256];
  442.  
  443.   Nlm_fileDone = FALSE;
  444.   Nlm_DoubleToStr (doubleval, ioStr, length, dec, sizeof (ioStr));
  445.   Nlm_WriteString (f, ioStr);
  446. }
  447.  
  448. extern Nlm_Boolean Nlm_StrToCard (Nlm_CharPtr str, Nlm_Uint2Ptr cardval)
  449.  
  450. {
  451.   Nlm_Char      ch;
  452.   Nlm_Int2      i;
  453.   Nlm_Int2      len;
  454.   Nlm_Char      local [64];
  455.   Nlm_Boolean   rsult;
  456.   unsigned int  val;
  457.  
  458.   rsult = FALSE;
  459.   if (cardval != NULL) {
  460.     *cardval = (Nlm_Uint2) 0;
  461.   }
  462.   len = (Nlm_Int2) Nlm_StringLen (str);
  463.   if (len != 0) {
  464.     rsult = TRUE;
  465.     for (i = 0; i < len; i++) {
  466.       ch = str [i];
  467.       if (ch == ' ') {
  468.       } else if (ch < '0' || ch > '9') {
  469.         rsult = FALSE;
  470.       }
  471.     }
  472.     if (rsult && cardval != NULL) {
  473.       Nlm_StringNCpy (local, str, sizeof (local));
  474.       sscanf (local, "%u", &val);
  475.       *cardval = (Nlm_Uint2) val;
  476.     }
  477.   }
  478.   return rsult;
  479. }
  480.  
  481. extern Nlm_Boolean Nlm_StrToInt (Nlm_CharPtr str, Nlm_Int2Ptr intval)
  482.  
  483. {
  484.   Nlm_Char     ch;
  485.   Nlm_Int2     i;
  486.   Nlm_Int2     len;
  487.   Nlm_Char     local [64];
  488.   Nlm_Boolean  rsult;
  489.   int          val;
  490.  
  491.   rsult = FALSE;
  492.   if (intval != NULL) {
  493.     *intval = (Nlm_Int2) 0;
  494.   }
  495.   len = (Nlm_Int2) Nlm_StringLen (str);
  496.   if (len != 0) {
  497.     rsult = TRUE;
  498.     for (i = 0; i < len; i++) {
  499.       ch = str [i];
  500.       if (ch == ' ' || ch == '+' || ch == '-') {
  501.       } else if (ch < '0' || ch > '9') {
  502.         rsult = FALSE;
  503.       }
  504.     }
  505.     if (rsult && intval != NULL) {
  506.       Nlm_StringNCpy (local, str, sizeof (local));
  507.       sscanf (local, "%d", &val);
  508.       *intval = (Nlm_Int2) val;
  509.     }
  510.   }
  511.   return rsult;
  512. }
  513.  
  514. extern Nlm_Boolean Nlm_StrToLong (Nlm_CharPtr str, Nlm_Int4Ptr longval)
  515.  
  516. {
  517.   Nlm_Char     ch;
  518.   Nlm_Int2     i;
  519.   Nlm_Int2     len;
  520.   Nlm_Char     local [64];
  521.   Nlm_Boolean  rsult;
  522.   long int     val;
  523.  
  524.   rsult = FALSE;
  525.   if (longval != NULL) {
  526.     *longval = (Nlm_Int4) 0;
  527.   }
  528.   len = (Nlm_Int2) Nlm_StringLen (str);
  529.   if (len != 0) {
  530.     rsult = TRUE;
  531.     for (i = 0; i < len; i++) {
  532.       ch = str [i];
  533.       if (ch == ' ' || ch == '+' || ch == '-') {
  534.       } else if (ch < '0' || ch > '9') {
  535.         rsult = FALSE;
  536.       }
  537.     }
  538.     if (rsult && longval != NULL) {
  539.       Nlm_StringNCpy (local, str, sizeof (local));
  540.       sscanf (local, "%ld", &val);
  541.       *longval = val;
  542.     }
  543.   }
  544.   return rsult;
  545. }
  546.  
  547. extern Nlm_Boolean Nlm_StrToPtr (Nlm_CharPtr str, Nlm_VoidPtr PNTR ptrval)
  548.  
  549. {
  550.   Nlm_Char     ch;
  551.   Nlm_Int2     i;
  552.   Nlm_Int2     len;
  553.   Nlm_Char     local [64];
  554.   Nlm_Boolean  rsult;
  555.   long         val;
  556.  
  557.   rsult = FALSE;
  558.   if (ptrval != NULL) {
  559.     *ptrval = NULL;
  560.   }
  561.   len = (Nlm_Int2) Nlm_StringLen (str);
  562.   if (len != 0) {
  563.     rsult = TRUE;
  564.     for (i = 0; i < len; i++) {
  565.       ch = str [i];
  566.       if (ch == ' ') {
  567.       } else if (ch < '0' || ch > '9') {
  568.         rsult = FALSE;
  569.       }
  570.     }
  571.     if (rsult && ptrval != NULL) {
  572.       Nlm_StringNCpy (local, str, sizeof (local));
  573.       sscanf (local, "%ld", &val);
  574.       *ptrval = (Nlm_VoidPtr) val;
  575.     }
  576.   }
  577.   return rsult;
  578. }
  579.  
  580. extern Nlm_Boolean Nlm_StrToReal (Nlm_CharPtr str, Nlm_FloatLoPtr realval)
  581.  
  582. {
  583.   Nlm_Char     ch;
  584.   Nlm_Int2     i;
  585.   Nlm_Int2     len;
  586.   Nlm_Char     local [64];
  587.   Nlm_Boolean  rsult;
  588.   float        val;
  589.  
  590.   rsult = FALSE;
  591.   if (realval != NULL) {
  592.     *realval = (Nlm_FloatLo) 0;
  593.   }
  594.   len = (Nlm_Int2) Nlm_StringLen (str);
  595.   if (len != 0) {
  596.     rsult = TRUE;
  597.     for (i = 0; i < len; i++) {
  598.       ch = str [i];
  599.       if ((ch < '0' || ch > '9') && ch != '+' && ch != '-' && ch != '.' && ch != 'E') {
  600.         rsult = FALSE;
  601.       }
  602.     }
  603.     if (rsult && realval != NULL) {
  604.       Nlm_StringNCpy (local, str, sizeof (local));
  605.       sscanf (local, "%f", &val);
  606.       *realval = val;
  607.     }
  608.   }
  609.   return rsult;
  610. }
  611.  
  612. extern Nlm_Boolean Nlm_StrToDouble (Nlm_CharPtr str, Nlm_FloatHiPtr doubleval)
  613.  
  614. {
  615.   Nlm_Char     ch;
  616.   Nlm_Int2     i;
  617.   Nlm_Int2     len;
  618.   Nlm_Char     local [64];
  619.   Nlm_Boolean  rsult;
  620.   double       val;
  621.  
  622.   rsult = FALSE;
  623.   if (doubleval != NULL) {
  624.     *doubleval = (Nlm_FloatHi) 0;
  625.   }
  626.   len = (Nlm_Int2) Nlm_StringLen (str);
  627.   if (len != 0) {
  628.     rsult = TRUE;
  629.     for (i = 0; i < len; i++) {
  630.       ch = str [i];
  631.       if ((ch < '0' || ch > '9') && ch != '+' && ch != '-' && ch != '.' && ch != 'E') {
  632.         rsult = FALSE;
  633.       }
  634.     }
  635.     if (rsult && doubleval != NULL) {
  636.       Nlm_StringNCpy (local, str, sizeof (local));
  637.       sscanf (local, "%lf", &val);
  638.       *doubleval = val;
  639.     }
  640.   }
  641.   return rsult;
  642. }
  643.  
  644. extern void Nlm_CardToStr (Nlm_Uint2 cardval, Nlm_CharPtr str,
  645.                            Nlm_Int2 length, Nlm_sizeT maxsize)
  646. {
  647.   Nlm_Char  temp [80];
  648.  
  649.   sprintf (temp, "%*u", length, cardval);
  650.   Nlm_StringNCpy (str, temp, maxsize);
  651. }
  652.  
  653. extern void Nlm_IntToStr (Nlm_Int2 intval, Nlm_CharPtr str,
  654.                           Nlm_Int2 length, Nlm_sizeT maxsize)
  655.  
  656. {
  657.   Nlm_Char  temp [80];
  658.  
  659.   sprintf (temp, "%*d", length, intval);
  660.   Nlm_StringNCpy (str, temp, maxsize);
  661. }
  662.  
  663. extern void Nlm_LongToStr (Nlm_Int4 longval, Nlm_CharPtr str,
  664.                            Nlm_Int2 length, Nlm_sizeT maxsize)
  665.  
  666. {
  667.   Nlm_Char  temp [80];
  668.  
  669.   sprintf (temp, "%*ld", length, longval);
  670.   Nlm_StringNCpy (str, temp, maxsize);
  671. }
  672.  
  673. extern void Nlm_PtrToStr (Nlm_VoidPtr ptrval, Nlm_CharPtr str,
  674.                           Nlm_Int2 length, Nlm_sizeT maxsize)
  675.  
  676. {
  677.   Nlm_Char  temp [80];
  678.  
  679.   sprintf (temp, "%*ld", length, (long) ptrval);
  680.   Nlm_StringNCpy (str, temp, maxsize);
  681. }
  682.  
  683. extern void Nlm_RealToStr (Nlm_FloatLo realval, Nlm_CharPtr str,
  684.                            Nlm_Int2 length, Nlm_Int2 dec,
  685.                            Nlm_sizeT maxsize)
  686.  
  687. {
  688.   Nlm_Char  temp [80];
  689.  
  690.   sprintf (temp, "%*.*f", length, dec, realval);
  691.   Nlm_StringNCpy (str, temp, maxsize);
  692. }
  693.  
  694. extern void Nlm_DoubleToStr (Nlm_FloatHi doubleval, Nlm_CharPtr str,
  695.                              Nlm_Int2 length, Nlm_Int2 dec,
  696.                              Nlm_sizeT maxsize)
  697.  
  698. {
  699.   Nlm_Char  temp [80];
  700.  
  701.   sprintf (temp, "%*.*lf", length, dec, doubleval);
  702.   Nlm_StringNCpy (str, temp, maxsize);
  703. }
  704.