File: vibfiles.c

package info (click to toggle)
ncbi-tools6 6.1.20080302-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 82,968 kB
  • ctags: 87,656
  • sloc: ansic: 1,216,658; cpp: 6,248; xml: 3,390; sh: 2,663; perl: 531; csh: 480; makefile: 424; lisp: 81
file content (769 lines) | stat: -rw-r--r-- 17,055 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*   vibfiles.c
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*            National Center for Biotechnology Information (NCBI)
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government do not place any restriction on its use or reproduction.
*  We would, however, appreciate having the NCBI and the author cited in
*  any work or product based on this material
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
* ===========================================================================
*
* File Name:  vibfiles.c
*
* Author:  Jonathan Kans
*
* Version Creation Date:   7/1/91
*
* $Revision: 6.3 $
*
* File Description: 
*       Vibrant file functions
*
* Modifications:  
* --------------------------------------------------------------------------
* $Log: vibfiles.c,v $
* Revision 6.3  2003/09/02 21:26:56  kans
* ReadChar and CloseString do not rely on feof, which does not work on Mac OS X
*
* Revision 6.2  2002/06/13 16:15:13  kans
* fix includes for OS_UNIX_DARWIN with WIN_MAC (EN) - still bug in vibutils.c file dialog
*
* Revision 6.1  1999/03/11 20:26:27  vakatov
* Get in-sync the printf's format and args in some functions
*
* Revision 5.1  1997/01/29 16:41:22  kans
* using StringNCpy_0
* ==========================================================================
*/

#include <vibtypes.h>
#include <vibprocs.h>
#include <vibincld.h>

#ifdef VAR_ARGS
#include <varargs.h>
#else
#include <stdarg.h>
#endif

Nlm_Boolean  Nlm_fileDone = TRUE;
Nlm_Int2     Nlm_fileError = 0;
Nlm_Char     Nlm_termCH = '\0';

static Nlm_Int2  charCount;

static void Nlm_DrawACharacter (Nlm_Char ch)

{
  Nlm_WindoW  w;

  w = Nlm_FrontWindow ();
  Nlm_DoSendChar ((Nlm_GraphiC) w, ch, TRUE);
}

static Nlm_Char Nlm_ReadCharFromTerm (void)

{
  Nlm_Char     ch;
/*#ifdef OS_MAC*/
#ifdef WIN_MAC 
  EventRecord  event;
#endif
#ifdef WIN_MSWIN
  MSG          msg;
  HWND         hwnd;
#endif

  ch = '\0';
/*#ifdef OS_MAC*/
#ifdef WIN_MAC
  while (ch == '\0') {
    if (GetNextEvent (keyDownMask + autoKeyMask, &event)) {
      ch = (Nlm_Char) (event.message % 256);
    }
  }
  Nlm_DrawACharacter (ch);
  if (ch == '\3') {
    ch = '\0';
  }
#endif
#ifdef WIN_MSWIN
  hwnd = GetFocus ();
  if (hwnd != NULL) {
    hwnd = GetParent (hwnd);
    if (hwnd != NULL) {
      SetFocus (hwnd);
    }
  }
  while (ch == '\0') {
    while (PeekMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE)) {
      if (GetMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP)) {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
      }
    }
    while (PeekMessage (&msg, NULL, WM_CHAR, WM_CHAR, PM_NOREMOVE)) {
      if (GetMessage (&msg, NULL, WM_CHAR, WM_CHAR)) {
        ch = (Nlm_Char) msg.wParam;
      }
    }
    if (ch == '\r') {
      ch = '\n';
    }
  }
  Nlm_DrawACharacter (ch);
#endif
#ifdef WIN_MOTIF
#endif
  return ch;
}

extern Nlm_Char Nlm_ReadChar (FILE *f)

{
  Nlm_Char  ch;
  int       getcrsult;

  ch = '\0';
  Nlm_fileDone = FALSE;
  if (f != NULL) {
    getcrsult = fgetc (f);
    ch = (Nlm_Char) getcrsult;
    if (getcrsult == EOF /* && feof (f) */) {
      ch = '\0';
    }
  } else {
    ch = Nlm_ReadCharFromTerm ();
  }
  Nlm_fileDone = (Nlm_Boolean) (ch != '\0');
  return ch;
}

extern void Nlm_WriteChar (FILE *f, Nlm_Char ch)

{
  if (f != NULL) {
    Nlm_fileError = fputc (ch, f);
    Nlm_fileDone = (Nlm_Boolean) (Nlm_fileError == 0 || ferror (f) == 0);
  } else {
    Nlm_DrawACharacter (ch);
    Nlm_fileError = FALSE;
    Nlm_fileDone = TRUE;
  }
}

extern void Nlm_WriteLn (FILE *f)

{
  Nlm_WriteChar (f, '\n');
}

static void Nlm_OpenString (FILE *f, Nlm_CharPtr str,
                            Nlm_Boolean ignore, size_t maxsize)

{
  Nlm_fileDone = FALSE;
  if (str != NULL && maxsize > 0) {
    str [0] = '\0';
  }
  charCount = 0;
  do {
    Nlm_termCH = Nlm_ReadChar (f);
  } while (Nlm_termCH == ' ' && ignore);
}

static void Nlm_InsertNextChar (FILE *f, Nlm_CharPtr str,
                                Nlm_Boolean ignore, size_t maxsize)

{
  do {
    if (charCount == 0 && ignore && Nlm_termCH == ' ') {
    } else if (Nlm_termCH == '\b') {
      if (charCount > 0) {
        charCount--;
      }
    } else if (charCount < (Nlm_Int2) maxsize && Nlm_termCH != '\0') {
      str [charCount] = Nlm_termCH;
      charCount++;
    }
    Nlm_termCH = Nlm_ReadChar (f);
  } while (Nlm_termCH == '\b' || (charCount == 0 && ignore && Nlm_termCH == ' '));
}

static void Nlm_CloseString (FILE *f, Nlm_CharPtr str, size_t maxsize)

{
  if (charCount <= (Nlm_Int2) maxsize) {
    str [charCount] = '\0';
  }
  Nlm_fileDone = (Nlm_Boolean) /* (! feof (f)) */ (Nlm_termCH != '\0');
}

extern void Nlm_ReadString (FILE *f, Nlm_CharPtr str, size_t maxsize)

{
  Nlm_fileDone = FALSE;
  if (str != NULL) {
    Nlm_OpenString (f, str, TRUE, maxsize);
    while (Nlm_termCH > ' ') {
      Nlm_InsertNextChar (f, str, TRUE, maxsize);
    }
    Nlm_CloseString (f, str, maxsize);
  }
}

extern void Nlm_ReadField (FILE *f, Nlm_CharPtr str, size_t maxsize)

{
  Nlm_fileDone = FALSE;
  if (str != NULL) {
    Nlm_OpenString (f, str, TRUE, maxsize);
    while (Nlm_termCH >= ' ') {
      Nlm_InsertNextChar (f, str, TRUE, maxsize);
    }
    Nlm_CloseString (f, str, maxsize);
  }
}

extern void Nlm_ReadLine (FILE *f, Nlm_CharPtr str, size_t maxsize)

{
  Nlm_fileDone = FALSE;
  if (str != NULL) {
    Nlm_OpenString (f, str, FALSE, maxsize);
    while (Nlm_termCH != '\n' && Nlm_termCH != '\r' && Nlm_termCH != '\0') {
      Nlm_InsertNextChar (f, str, FALSE, maxsize);
    }
    Nlm_CloseString (f, str, maxsize);
  }
}

extern void Nlm_WriteString (FILE *f, Nlm_CharPtr str)

{
  Nlm_Int2  i;

  Nlm_fileDone = FALSE;
  if (str != NULL) {
    i = 0;
    while (str [i] != '\0') {
      Nlm_WriteChar (f, str [i]);
      i++;
    }
  }
}

extern void Nlm_ReadText (FILE *f, Nlm_CharPtr str, size_t maxsize)

{
  Nlm_ReadLine (f, str, maxsize);
}

#ifdef VAR_ARGS
void CDECL Nlm_WriteText (f, format, va_alist)
  FILE *f;
  char *format;
  va_dcl
#else
void CDECL Nlm_WriteText (FILE *f, char *format, ...)
#endif

{
  va_list  args;
  char     buf[120];

#ifdef VAR_ARGS
  va_start(args);
#else
  va_start(args, format);
#endif
  vsprintf(buf, format, args);
  va_end(args);

  Nlm_WriteString (f, buf);
}

#ifdef VAR_ARGS
void CDECL Nlm_WriteLog (format, va_alist)
  char *format;
  va_dcl
#else
void CDECL Nlm_WriteLog (char *format, ...)
#endif

{
  va_list  args;
  char     buf[120];
  FILE     *f;

#ifdef VAR_ARGS
  va_start(args);
#else
  va_start(args, format);
#endif
  vsprintf(buf, format, args);
  va_end(args);

  f = Nlm_FileOpen ("LogFile", "a");
  if (f != NULL) {
    Nlm_WriteString (f, buf);
    Nlm_FileClose (f);
  }
}

extern Nlm_Uint2 Nlm_ReadCard (FILE *f)

{
  Nlm_Uint2  cardval;
  Nlm_Char   ioStr [256];

  Nlm_fileDone = FALSE;
  cardval = 0;
  Nlm_ReadString (f, ioStr, sizeof (ioStr));
  if (Nlm_fileDone) {
    Nlm_fileDone = Nlm_StrToCard (ioStr, &cardval);
  }
  return cardval;
}

extern void Nlm_WriteCard (FILE *f, Nlm_Uint2 cardval, Nlm_Int2 length)

{
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  Nlm_CardToStr (cardval, ioStr, length, sizeof (ioStr));
  Nlm_WriteString (f, ioStr);
}

extern Nlm_Int2 Nlm_ReadInt (FILE *f)

{
  Nlm_Int2  intval;
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  intval = 0;
  Nlm_ReadString (f, ioStr, sizeof (ioStr));
  if (Nlm_fileDone) {
    Nlm_fileDone = Nlm_StrToInt (ioStr, &intval);
  }
  return intval;
}

extern void Nlm_WriteInt (FILE *f, Nlm_Int2 intval, Nlm_Int2 length)

{
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  Nlm_IntToStr (intval, ioStr, length, sizeof (ioStr));
  Nlm_WriteString (f, ioStr);
}

extern Nlm_Int4 Nlm_ReadLong (FILE *f)

{
  Nlm_Int4  longval;
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  longval = 0;
  Nlm_ReadString (f, ioStr, sizeof (ioStr));
  if (Nlm_fileDone) {
    Nlm_fileDone = Nlm_StrToLong (ioStr, &longval);
  }
  return longval;
}

extern void Nlm_WriteLong (FILE *f, Nlm_Int4 longval, Nlm_Int2 length)

{
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  Nlm_LongToStr (longval, ioStr, length, sizeof (ioStr));
  Nlm_WriteString (f, ioStr);
}

extern Nlm_FloatLo Nlm_ReadReal (FILE *f)

{
  Nlm_FloatHi  doubleval;
  Nlm_Char     ioStr [256];
  Nlm_FloatLo  realval;

  Nlm_fileDone = FALSE;
  doubleval = 0.0;
  Nlm_ReadString (f, ioStr, sizeof (ioStr));
  if (Nlm_fileDone) {
    Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
  }
  realval = (Nlm_FloatLo) doubleval;
  return realval;
}

extern void Nlm_WriteReal (FILE *f, Nlm_FloatLo realval,
                           Nlm_Int2 length, Nlm_Int2 dec)

{
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  Nlm_RealToStr (realval, ioStr, length, dec, sizeof (ioStr));
  Nlm_WriteString (f, ioStr);
}

extern Nlm_FloatHi Nlm_ReadDouble (FILE *f)

{
  Nlm_FloatHi  doubleval;
  Nlm_Char     ioStr [256];

  Nlm_fileDone = FALSE;
  doubleval = 0.0;
  Nlm_ReadString (f, ioStr, sizeof (ioStr));
  if (Nlm_fileDone) {
    Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
  }
  return doubleval;
}

extern void Nlm_WriteDouble (FILE *f, Nlm_FloatHi doubleval,
                             Nlm_Int2 length, Nlm_Int2 dec)

{
  Nlm_Char  ioStr [256];

  Nlm_fileDone = FALSE;
  Nlm_DoubleToStr (doubleval, ioStr, length, dec, sizeof (ioStr));
  Nlm_WriteString (f, ioStr);
}

extern Nlm_Boolean Nlm_StrToCard (Nlm_CharPtr str, Nlm_Uint2Ptr cardval)

{
  Nlm_Char      ch;
  Nlm_Int2      i;
  Nlm_Int2      len;
  Nlm_Char      local [64];
  Nlm_Boolean   nodigits;
  Nlm_Boolean   rsult;
  unsigned int  val;

  rsult = FALSE;
  if (cardval != NULL) {
    *cardval = (Nlm_Uint2) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && cardval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%u", &val) == 1) {
        *cardval = (Nlm_Uint2) val;
      }
    }
  }
  return rsult;
}

extern Nlm_Boolean Nlm_StrToInt (Nlm_CharPtr str, Nlm_Int2Ptr intval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  int          val;

  rsult = FALSE;
  if (intval != NULL) {
    *intval = (Nlm_Int2) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ' || ch == '+' || ch == '-') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && intval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%d", &val) == 1) {
        *intval = (Nlm_Int2) val;
      }
    }
  }
  return rsult;
}

extern Nlm_Boolean Nlm_StrToLong (Nlm_CharPtr str, Nlm_Int4Ptr longval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long int     val;

  rsult = FALSE;
  if (longval != NULL) {
    *longval = (Nlm_Int4) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ' || ch == '+' || ch == '-') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && longval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%ld", &val) == 1) {
        *longval = val;
      }
    }
  }
  return rsult;
}

extern Nlm_Boolean Nlm_StrToPtr (Nlm_CharPtr str, Nlm_VoidPtr PNTR ptrval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long         val;

  rsult = FALSE;
  if (ptrval != NULL) {
    *ptrval = NULL;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && ptrval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      if (sscanf (local, "%ld", &val) == 1) {
        *ptrval = (Nlm_VoidPtr) val;
      }
    }
  }
  return rsult;
}

extern Nlm_Boolean Nlm_StrToReal (Nlm_CharPtr str, Nlm_FloatLoPtr realval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  float        val;

  rsult = FALSE;
  if (realval != NULL) {
    *realval = (Nlm_FloatLo) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == '+' || ch == '-' || ch == '.' || ch == 'E' || ch == 'e') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && realval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      for (i = 0; i < len; i++) {
        local [i] = TO_UPPER (local [i]);
      }
      if (sscanf (local, "%f", &val) == 1) {
        *realval = val;
      }
    }
  }
  return rsult;
}

extern Nlm_Boolean Nlm_StrToDouble (Nlm_CharPtr str, Nlm_FloatHiPtr doubleval)

{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  double       val;

  rsult = FALSE;
  if (doubleval != NULL) {
    *doubleval = (Nlm_FloatHi) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == '+' || ch == '-' || ch == '.' || ch == 'E' || ch == 'e') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && doubleval != NULL) {
      Nlm_StringNCpy_0 (local, str, sizeof (local));
      for (i = 0; i < len; i++) {
        local [i] = TO_UPPER (local [i]);
      }
      if (sscanf (local, "%lf", &val) == 1) {
        *doubleval = val;
      }
    }
  }
  return rsult;
}

extern void Nlm_CardToStr (Nlm_Uint2 cardval, Nlm_CharPtr str,
                           Nlm_Int2 length, size_t maxsize)
{
  Nlm_Char  temp [80];

  sprintf (temp, "%*u", length, (int)cardval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}

extern void Nlm_IntToStr (Nlm_Int2 intval, Nlm_CharPtr str,
                          Nlm_Int2 length, size_t maxsize)

{
  Nlm_Char  temp [80];

  sprintf (temp, "%*d", length, intval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}

extern void Nlm_LongToStr (Nlm_Int4 longval, Nlm_CharPtr str,
                           Nlm_Int2 length, size_t maxsize)

{
  Nlm_Char  temp [80];

  sprintf (temp, "%*ld", length, (long)longval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}

extern void Nlm_PtrToStr (Nlm_VoidPtr ptrval, Nlm_CharPtr str,
                          Nlm_Int2 length, size_t maxsize)

{
  Nlm_Char  temp [80];

  sprintf (temp, "%*ld", length, (long) ptrval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}

extern void Nlm_RealToStr (Nlm_FloatLo realval, Nlm_CharPtr str,
                           Nlm_Int2 length, Nlm_Int2 dec,
                           size_t maxsize)

{
  Nlm_Char  temp [80];

  sprintf (temp, "%*.*f", length, dec, (float)realval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}

extern void Nlm_DoubleToStr (Nlm_FloatHi doubleval, Nlm_CharPtr str,
                             Nlm_Int2 length, Nlm_Int2 dec,
                             size_t maxsize)

{
  Nlm_Char  temp [80];

  sprintf (temp, "%*.*lf", length, dec, (double)doubleval);
  Nlm_StringNCpy_0 (str, temp, maxsize);
}