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: 6.3 $
33 *
34 * File Description:
35 * Vibrant file functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * $Log: vibfiles.c,v $
40 * Revision 6.3 2003/09/02 21:26:56 kans
41 * ReadChar and CloseString do not rely on feof, which does not work on Mac OS X
42 *
43 * Revision 6.2 2002/06/13 16:15:13 kans
44 * fix includes for OS_UNIX_DARWIN with WIN_MAC (EN) - still bug in vibutils.c file dialog
45 *
46 * Revision 6.1 1999/03/11 20:26:27 vakatov
47 * Get in-sync the printf's format and args in some functions
48 *
49 * Revision 5.1 1997/01/29 16:41:22 kans
50 * using StringNCpy_0
51 * ==========================================================================
52 */
53
54 #include <vibtypes.h>
55 #include <vibprocs.h>
56 #include <vibincld.h>
57
58 #ifdef VAR_ARGS
59 #include <varargs.h>
60 #else
61 #include <stdarg.h>
62 #endif
63
64 Nlm_Boolean Nlm_fileDone = TRUE;
65 Nlm_Int2 Nlm_fileError = 0;
66 Nlm_Char Nlm_termCH = '\0';
67
68 static Nlm_Int2 charCount;
69
Nlm_DrawACharacter(Nlm_Char ch)70 static void Nlm_DrawACharacter (Nlm_Char ch)
71
72 {
73 Nlm_WindoW w;
74
75 w = Nlm_FrontWindow ();
76 Nlm_DoSendChar ((Nlm_GraphiC) w, ch, TRUE);
77 }
78
Nlm_ReadCharFromTerm(void)79 static Nlm_Char Nlm_ReadCharFromTerm (void)
80
81 {
82 Nlm_Char ch;
83 /*#ifdef OS_MAC*/
84 #ifdef WIN_MAC
85 EventRecord event;
86 #endif
87 #ifdef WIN_MSWIN
88 MSG msg;
89 HWND hwnd;
90 #endif
91
92 ch = '\0';
93 /*#ifdef OS_MAC*/
94 #ifdef WIN_MAC
95 while (ch == '\0') {
96 if (GetNextEvent (keyDownMask + autoKeyMask, &event)) {
97 ch = (Nlm_Char) (event.message % 256);
98 }
99 }
100 Nlm_DrawACharacter (ch);
101 if (ch == '\3') {
102 ch = '\0';
103 }
104 #endif
105 #ifdef WIN_MSWIN
106 hwnd = GetFocus ();
107 if (hwnd != NULL) {
108 hwnd = GetParent (hwnd);
109 if (hwnd != NULL) {
110 SetFocus (hwnd);
111 }
112 }
113 while (ch == '\0') {
114 while (PeekMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE)) {
115 if (GetMessage (&msg, NULL, WM_KEYDOWN, WM_KEYUP)) {
116 TranslateMessage (&msg);
117 DispatchMessage (&msg);
118 }
119 }
120 while (PeekMessage (&msg, NULL, WM_CHAR, WM_CHAR, PM_NOREMOVE)) {
121 if (GetMessage (&msg, NULL, WM_CHAR, WM_CHAR)) {
122 ch = (Nlm_Char) msg.wParam;
123 }
124 }
125 if (ch == '\r') {
126 ch = '\n';
127 }
128 }
129 Nlm_DrawACharacter (ch);
130 #endif
131 #ifdef WIN_MOTIF
132 #endif
133 return ch;
134 }
135
Nlm_ReadChar(FILE * f)136 extern Nlm_Char Nlm_ReadChar (FILE *f)
137
138 {
139 Nlm_Char ch;
140 int getcrsult;
141
142 ch = '\0';
143 Nlm_fileDone = FALSE;
144 if (f != NULL) {
145 getcrsult = fgetc (f);
146 ch = (Nlm_Char) getcrsult;
147 if (getcrsult == EOF /* && feof (f) */) {
148 ch = '\0';
149 }
150 } else {
151 ch = Nlm_ReadCharFromTerm ();
152 }
153 Nlm_fileDone = (Nlm_Boolean) (ch != '\0');
154 return ch;
155 }
156
Nlm_WriteChar(FILE * f,Nlm_Char ch)157 extern void Nlm_WriteChar (FILE *f, Nlm_Char ch)
158
159 {
160 if (f != NULL) {
161 Nlm_fileError = fputc (ch, f);
162 Nlm_fileDone = (Nlm_Boolean) (Nlm_fileError == 0 || ferror (f) == 0);
163 } else {
164 Nlm_DrawACharacter (ch);
165 Nlm_fileError = FALSE;
166 Nlm_fileDone = TRUE;
167 }
168 }
169
Nlm_WriteLn(FILE * f)170 extern void Nlm_WriteLn (FILE *f)
171
172 {
173 Nlm_WriteChar (f, '\n');
174 }
175
Nlm_OpenString(FILE * f,Nlm_CharPtr str,Nlm_Boolean ignore,size_t maxsize)176 static void Nlm_OpenString (FILE *f, Nlm_CharPtr str,
177 Nlm_Boolean ignore, size_t maxsize)
178
179 {
180 Nlm_fileDone = FALSE;
181 if (str != NULL && maxsize > 0) {
182 str [0] = '\0';
183 }
184 charCount = 0;
185 do {
186 Nlm_termCH = Nlm_ReadChar (f);
187 } while (Nlm_termCH == ' ' && ignore);
188 }
189
Nlm_InsertNextChar(FILE * f,Nlm_CharPtr str,Nlm_Boolean ignore,size_t maxsize)190 static void Nlm_InsertNextChar (FILE *f, Nlm_CharPtr str,
191 Nlm_Boolean ignore, size_t maxsize)
192
193 {
194 do {
195 if (charCount == 0 && ignore && Nlm_termCH == ' ') {
196 } else if (Nlm_termCH == '\b') {
197 if (charCount > 0) {
198 charCount--;
199 }
200 } else if (charCount < (Nlm_Int2) maxsize && Nlm_termCH != '\0') {
201 str [charCount] = Nlm_termCH;
202 charCount++;
203 }
204 Nlm_termCH = Nlm_ReadChar (f);
205 } while (Nlm_termCH == '\b' || (charCount == 0 && ignore && Nlm_termCH == ' '));
206 }
207
Nlm_CloseString(FILE * f,Nlm_CharPtr str,size_t maxsize)208 static void Nlm_CloseString (FILE *f, Nlm_CharPtr str, size_t maxsize)
209
210 {
211 if (charCount <= (Nlm_Int2) maxsize) {
212 str [charCount] = '\0';
213 }
214 Nlm_fileDone = (Nlm_Boolean) /* (! feof (f)) */ (Nlm_termCH != '\0');
215 }
216
Nlm_ReadString(FILE * f,Nlm_CharPtr str,size_t maxsize)217 extern void Nlm_ReadString (FILE *f, Nlm_CharPtr str, size_t maxsize)
218
219 {
220 Nlm_fileDone = FALSE;
221 if (str != NULL) {
222 Nlm_OpenString (f, str, TRUE, maxsize);
223 while (Nlm_termCH > ' ') {
224 Nlm_InsertNextChar (f, str, TRUE, maxsize);
225 }
226 Nlm_CloseString (f, str, maxsize);
227 }
228 }
229
Nlm_ReadField(FILE * f,Nlm_CharPtr str,size_t maxsize)230 extern void Nlm_ReadField (FILE *f, Nlm_CharPtr str, size_t maxsize)
231
232 {
233 Nlm_fileDone = FALSE;
234 if (str != NULL) {
235 Nlm_OpenString (f, str, TRUE, maxsize);
236 while (Nlm_termCH >= ' ') {
237 Nlm_InsertNextChar (f, str, TRUE, maxsize);
238 }
239 Nlm_CloseString (f, str, maxsize);
240 }
241 }
242
Nlm_ReadLine(FILE * f,Nlm_CharPtr str,size_t maxsize)243 extern void Nlm_ReadLine (FILE *f, Nlm_CharPtr str, size_t maxsize)
244
245 {
246 Nlm_fileDone = FALSE;
247 if (str != NULL) {
248 Nlm_OpenString (f, str, FALSE, maxsize);
249 while (Nlm_termCH != '\n' && Nlm_termCH != '\r' && Nlm_termCH != '\0') {
250 Nlm_InsertNextChar (f, str, FALSE, maxsize);
251 }
252 Nlm_CloseString (f, str, maxsize);
253 }
254 }
255
Nlm_WriteString(FILE * f,Nlm_CharPtr str)256 extern void Nlm_WriteString (FILE *f, Nlm_CharPtr str)
257
258 {
259 Nlm_Int2 i;
260
261 Nlm_fileDone = FALSE;
262 if (str != NULL) {
263 i = 0;
264 while (str [i] != '\0') {
265 Nlm_WriteChar (f, str [i]);
266 i++;
267 }
268 }
269 }
270
Nlm_ReadText(FILE * f,Nlm_CharPtr str,size_t maxsize)271 extern void Nlm_ReadText (FILE *f, Nlm_CharPtr str, size_t maxsize)
272
273 {
274 Nlm_ReadLine (f, str, maxsize);
275 }
276
277 #ifdef VAR_ARGS
Nlm_WriteText(f,format,va_alist)278 void CDECL Nlm_WriteText (f, format, va_alist)
279 FILE *f;
280 char *format;
281 va_dcl
282 #else
283 void CDECL Nlm_WriteText (FILE *f, char *format, ...)
284 #endif
285
286 {
287 va_list args;
288 char buf[120];
289
290 #ifdef VAR_ARGS
291 va_start(args);
292 #else
293 va_start(args, format);
294 #endif
295 vsprintf(buf, format, args);
296 va_end(args);
297
298 Nlm_WriteString (f, buf);
299 }
300
301 #ifdef VAR_ARGS
Nlm_WriteLog(format,va_alist)302 void CDECL Nlm_WriteLog (format, va_alist)
303 char *format;
304 va_dcl
305 #else
306 void CDECL Nlm_WriteLog (char *format, ...)
307 #endif
308
309 {
310 va_list args;
311 char buf[120];
312 FILE *f;
313
314 #ifdef VAR_ARGS
315 va_start(args);
316 #else
317 va_start(args, format);
318 #endif
319 vsprintf(buf, format, args);
320 va_end(args);
321
322 f = Nlm_FileOpen ("LogFile", "a");
323 if (f != NULL) {
324 Nlm_WriteString (f, buf);
325 Nlm_FileClose (f);
326 }
327 }
328
Nlm_ReadCard(FILE * f)329 extern Nlm_Uint2 Nlm_ReadCard (FILE *f)
330
331 {
332 Nlm_Uint2 cardval;
333 Nlm_Char ioStr [256];
334
335 Nlm_fileDone = FALSE;
336 cardval = 0;
337 Nlm_ReadString (f, ioStr, sizeof (ioStr));
338 if (Nlm_fileDone) {
339 Nlm_fileDone = Nlm_StrToCard (ioStr, &cardval);
340 }
341 return cardval;
342 }
343
Nlm_WriteCard(FILE * f,Nlm_Uint2 cardval,Nlm_Int2 length)344 extern void Nlm_WriteCard (FILE *f, Nlm_Uint2 cardval, Nlm_Int2 length)
345
346 {
347 Nlm_Char ioStr [256];
348
349 Nlm_fileDone = FALSE;
350 Nlm_CardToStr (cardval, ioStr, length, sizeof (ioStr));
351 Nlm_WriteString (f, ioStr);
352 }
353
Nlm_ReadInt(FILE * f)354 extern Nlm_Int2 Nlm_ReadInt (FILE *f)
355
356 {
357 Nlm_Int2 intval;
358 Nlm_Char ioStr [256];
359
360 Nlm_fileDone = FALSE;
361 intval = 0;
362 Nlm_ReadString (f, ioStr, sizeof (ioStr));
363 if (Nlm_fileDone) {
364 Nlm_fileDone = Nlm_StrToInt (ioStr, &intval);
365 }
366 return intval;
367 }
368
Nlm_WriteInt(FILE * f,Nlm_Int2 intval,Nlm_Int2 length)369 extern void Nlm_WriteInt (FILE *f, Nlm_Int2 intval, Nlm_Int2 length)
370
371 {
372 Nlm_Char ioStr [256];
373
374 Nlm_fileDone = FALSE;
375 Nlm_IntToStr (intval, ioStr, length, sizeof (ioStr));
376 Nlm_WriteString (f, ioStr);
377 }
378
Nlm_ReadLong(FILE * f)379 extern Nlm_Int4 Nlm_ReadLong (FILE *f)
380
381 {
382 Nlm_Int4 longval;
383 Nlm_Char ioStr [256];
384
385 Nlm_fileDone = FALSE;
386 longval = 0;
387 Nlm_ReadString (f, ioStr, sizeof (ioStr));
388 if (Nlm_fileDone) {
389 Nlm_fileDone = Nlm_StrToLong (ioStr, &longval);
390 }
391 return longval;
392 }
393
Nlm_WriteLong(FILE * f,Nlm_Int4 longval,Nlm_Int2 length)394 extern void Nlm_WriteLong (FILE *f, Nlm_Int4 longval, Nlm_Int2 length)
395
396 {
397 Nlm_Char ioStr [256];
398
399 Nlm_fileDone = FALSE;
400 Nlm_LongToStr (longval, ioStr, length, sizeof (ioStr));
401 Nlm_WriteString (f, ioStr);
402 }
403
Nlm_ReadReal(FILE * f)404 extern Nlm_FloatLo Nlm_ReadReal (FILE *f)
405
406 {
407 Nlm_FloatHi doubleval;
408 Nlm_Char ioStr [256];
409 Nlm_FloatLo realval;
410
411 Nlm_fileDone = FALSE;
412 doubleval = 0.0;
413 Nlm_ReadString (f, ioStr, sizeof (ioStr));
414 if (Nlm_fileDone) {
415 Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
416 }
417 realval = (Nlm_FloatLo) doubleval;
418 return realval;
419 }
420
Nlm_WriteReal(FILE * f,Nlm_FloatLo realval,Nlm_Int2 length,Nlm_Int2 dec)421 extern void Nlm_WriteReal (FILE *f, Nlm_FloatLo realval,
422 Nlm_Int2 length, Nlm_Int2 dec)
423
424 {
425 Nlm_Char ioStr [256];
426
427 Nlm_fileDone = FALSE;
428 Nlm_RealToStr (realval, ioStr, length, dec, sizeof (ioStr));
429 Nlm_WriteString (f, ioStr);
430 }
431
Nlm_ReadDouble(FILE * f)432 extern Nlm_FloatHi Nlm_ReadDouble (FILE *f)
433
434 {
435 Nlm_FloatHi doubleval;
436 Nlm_Char ioStr [256];
437
438 Nlm_fileDone = FALSE;
439 doubleval = 0.0;
440 Nlm_ReadString (f, ioStr, sizeof (ioStr));
441 if (Nlm_fileDone) {
442 Nlm_fileDone = Nlm_StrToDouble (ioStr, &doubleval);
443 }
444 return doubleval;
445 }
446
Nlm_WriteDouble(FILE * f,Nlm_FloatHi doubleval,Nlm_Int2 length,Nlm_Int2 dec)447 extern void Nlm_WriteDouble (FILE *f, Nlm_FloatHi doubleval,
448 Nlm_Int2 length, Nlm_Int2 dec)
449
450 {
451 Nlm_Char ioStr [256];
452
453 Nlm_fileDone = FALSE;
454 Nlm_DoubleToStr (doubleval, ioStr, length, dec, sizeof (ioStr));
455 Nlm_WriteString (f, ioStr);
456 }
457
Nlm_StrToCard(Nlm_CharPtr str,Nlm_Uint2Ptr cardval)458 extern Nlm_Boolean Nlm_StrToCard (Nlm_CharPtr str, Nlm_Uint2Ptr cardval)
459
460 {
461 Nlm_Char ch;
462 Nlm_Int2 i;
463 Nlm_Int2 len;
464 Nlm_Char local [64];
465 Nlm_Boolean nodigits;
466 Nlm_Boolean rsult;
467 unsigned int val;
468
469 rsult = FALSE;
470 if (cardval != NULL) {
471 *cardval = (Nlm_Uint2) 0;
472 }
473 len = (Nlm_Int2) Nlm_StringLen (str);
474 if (len != 0) {
475 rsult = TRUE;
476 nodigits = TRUE;
477 for (i = 0; i < len; i++) {
478 ch = str [i];
479 if (ch == ' ') {
480 } else if (ch < '0' || ch > '9') {
481 rsult = FALSE;
482 } else {
483 nodigits = FALSE;
484 }
485 }
486 if (nodigits) {
487 rsult = FALSE;
488 }
489 if (rsult && cardval != NULL) {
490 Nlm_StringNCpy_0 (local, str, sizeof (local));
491 if (sscanf (local, "%u", &val) == 1) {
492 *cardval = (Nlm_Uint2) val;
493 }
494 }
495 }
496 return rsult;
497 }
498
Nlm_StrToInt(Nlm_CharPtr str,Nlm_Int2Ptr intval)499 extern Nlm_Boolean Nlm_StrToInt (Nlm_CharPtr str, Nlm_Int2Ptr intval)
500
501 {
502 Nlm_Char ch;
503 Nlm_Int2 i;
504 Nlm_Int2 len;
505 Nlm_Char local [64];
506 Nlm_Boolean nodigits;
507 Nlm_Boolean rsult;
508 int val;
509
510 rsult = FALSE;
511 if (intval != NULL) {
512 *intval = (Nlm_Int2) 0;
513 }
514 len = (Nlm_Int2) Nlm_StringLen (str);
515 if (len != 0) {
516 rsult = TRUE;
517 nodigits = TRUE;
518 for (i = 0; i < len; i++) {
519 ch = str [i];
520 if (ch == ' ' || ch == '+' || ch == '-') {
521 } else if (ch < '0' || ch > '9') {
522 rsult = FALSE;
523 } else {
524 nodigits = FALSE;
525 }
526 }
527 if (nodigits) {
528 rsult = FALSE;
529 }
530 if (rsult && intval != NULL) {
531 Nlm_StringNCpy_0 (local, str, sizeof (local));
532 if (sscanf (local, "%d", &val) == 1) {
533 *intval = (Nlm_Int2) val;
534 }
535 }
536 }
537 return rsult;
538 }
539
Nlm_StrToLong(Nlm_CharPtr str,Nlm_Int4Ptr longval)540 extern Nlm_Boolean Nlm_StrToLong (Nlm_CharPtr str, Nlm_Int4Ptr longval)
541
542 {
543 Nlm_Char ch;
544 Nlm_Int2 i;
545 Nlm_Int2 len;
546 Nlm_Char local [64];
547 Nlm_Boolean nodigits;
548 Nlm_Boolean rsult;
549 long int val;
550
551 rsult = FALSE;
552 if (longval != NULL) {
553 *longval = (Nlm_Int4) 0;
554 }
555 len = (Nlm_Int2) Nlm_StringLen (str);
556 if (len != 0) {
557 rsult = TRUE;
558 nodigits = TRUE;
559 for (i = 0; i < len; i++) {
560 ch = str [i];
561 if (ch == ' ' || ch == '+' || ch == '-') {
562 } else if (ch < '0' || ch > '9') {
563 rsult = FALSE;
564 } else {
565 nodigits = FALSE;
566 }
567 }
568 if (nodigits) {
569 rsult = FALSE;
570 }
571 if (rsult && longval != NULL) {
572 Nlm_StringNCpy_0 (local, str, sizeof (local));
573 if (sscanf (local, "%ld", &val) == 1) {
574 *longval = val;
575 }
576 }
577 }
578 return rsult;
579 }
580
Nlm_StrToPtr(Nlm_CharPtr str,Nlm_VoidPtr PNTR ptrval)581 extern Nlm_Boolean Nlm_StrToPtr (Nlm_CharPtr str, Nlm_VoidPtr PNTR ptrval)
582
583 {
584 Nlm_Char ch;
585 Nlm_Int2 i;
586 Nlm_Int2 len;
587 Nlm_Char local [64];
588 Nlm_Boolean nodigits;
589 Nlm_Boolean rsult;
590 long val;
591
592 rsult = FALSE;
593 if (ptrval != NULL) {
594 *ptrval = NULL;
595 }
596 len = (Nlm_Int2) Nlm_StringLen (str);
597 if (len != 0) {
598 rsult = TRUE;
599 nodigits = TRUE;
600 for (i = 0; i < len; i++) {
601 ch = str [i];
602 if (ch == ' ') {
603 } else if (ch < '0' || ch > '9') {
604 rsult = FALSE;
605 } else {
606 nodigits = FALSE;
607 }
608 }
609 if (nodigits) {
610 rsult = FALSE;
611 }
612 if (rsult && ptrval != NULL) {
613 Nlm_StringNCpy_0 (local, str, sizeof (local));
614 if (sscanf (local, "%ld", &val) == 1) {
615 *ptrval = (Nlm_VoidPtr) val;
616 }
617 }
618 }
619 return rsult;
620 }
621
Nlm_StrToReal(Nlm_CharPtr str,Nlm_FloatLoPtr realval)622 extern Nlm_Boolean Nlm_StrToReal (Nlm_CharPtr str, Nlm_FloatLoPtr realval)
623
624 {
625 Nlm_Char ch;
626 Nlm_Int2 i;
627 Nlm_Int2 len;
628 Nlm_Char local [64];
629 Nlm_Boolean nodigits;
630 Nlm_Boolean rsult;
631 float val;
632
633 rsult = FALSE;
634 if (realval != NULL) {
635 *realval = (Nlm_FloatLo) 0;
636 }
637 len = (Nlm_Int2) Nlm_StringLen (str);
638 if (len != 0) {
639 rsult = TRUE;
640 nodigits = TRUE;
641 for (i = 0; i < len; i++) {
642 ch = str [i];
643 if (ch == '+' || ch == '-' || ch == '.' || ch == 'E' || ch == 'e') {
644 } else if (ch < '0' || ch > '9') {
645 rsult = FALSE;
646 } else {
647 nodigits = FALSE;
648 }
649 }
650 if (nodigits) {
651 rsult = FALSE;
652 }
653 if (rsult && realval != NULL) {
654 Nlm_StringNCpy_0 (local, str, sizeof (local));
655 for (i = 0; i < len; i++) {
656 local [i] = TO_UPPER (local [i]);
657 }
658 if (sscanf (local, "%f", &val) == 1) {
659 *realval = val;
660 }
661 }
662 }
663 return rsult;
664 }
665
Nlm_StrToDouble(Nlm_CharPtr str,Nlm_FloatHiPtr doubleval)666 extern Nlm_Boolean Nlm_StrToDouble (Nlm_CharPtr str, Nlm_FloatHiPtr doubleval)
667
668 {
669 Nlm_Char ch;
670 Nlm_Int2 i;
671 Nlm_Int2 len;
672 Nlm_Char local [64];
673 Nlm_Boolean nodigits;
674 Nlm_Boolean rsult;
675 double val;
676
677 rsult = FALSE;
678 if (doubleval != NULL) {
679 *doubleval = (Nlm_FloatHi) 0;
680 }
681 len = (Nlm_Int2) Nlm_StringLen (str);
682 if (len != 0) {
683 rsult = TRUE;
684 nodigits = TRUE;
685 for (i = 0; i < len; i++) {
686 ch = str [i];
687 if (ch == '+' || ch == '-' || ch == '.' || ch == 'E' || ch == 'e') {
688 } else if (ch < '0' || ch > '9') {
689 rsult = FALSE;
690 } else {
691 nodigits = FALSE;
692 }
693 }
694 if (nodigits) {
695 rsult = FALSE;
696 }
697 if (rsult && doubleval != NULL) {
698 Nlm_StringNCpy_0 (local, str, sizeof (local));
699 for (i = 0; i < len; i++) {
700 local [i] = TO_UPPER (local [i]);
701 }
702 if (sscanf (local, "%lf", &val) == 1) {
703 *doubleval = val;
704 }
705 }
706 }
707 return rsult;
708 }
709
Nlm_CardToStr(Nlm_Uint2 cardval,Nlm_CharPtr str,Nlm_Int2 length,size_t maxsize)710 extern void Nlm_CardToStr (Nlm_Uint2 cardval, Nlm_CharPtr str,
711 Nlm_Int2 length, size_t maxsize)
712 {
713 Nlm_Char temp [80];
714
715 sprintf (temp, "%*u", length, (int)cardval);
716 Nlm_StringNCpy_0 (str, temp, maxsize);
717 }
718
Nlm_IntToStr(Nlm_Int2 intval,Nlm_CharPtr str,Nlm_Int2 length,size_t maxsize)719 extern void Nlm_IntToStr (Nlm_Int2 intval, Nlm_CharPtr str,
720 Nlm_Int2 length, size_t maxsize)
721
722 {
723 Nlm_Char temp [80];
724
725 sprintf (temp, "%*d", length, intval);
726 Nlm_StringNCpy_0 (str, temp, maxsize);
727 }
728
Nlm_LongToStr(Nlm_Int4 longval,Nlm_CharPtr str,Nlm_Int2 length,size_t maxsize)729 extern void Nlm_LongToStr (Nlm_Int4 longval, Nlm_CharPtr str,
730 Nlm_Int2 length, size_t maxsize)
731
732 {
733 Nlm_Char temp [80];
734
735 sprintf (temp, "%*ld", length, (long)longval);
736 Nlm_StringNCpy_0 (str, temp, maxsize);
737 }
738
Nlm_PtrToStr(Nlm_VoidPtr ptrval,Nlm_CharPtr str,Nlm_Int2 length,size_t maxsize)739 extern void Nlm_PtrToStr (Nlm_VoidPtr ptrval, Nlm_CharPtr str,
740 Nlm_Int2 length, size_t maxsize)
741
742 {
743 Nlm_Char temp [80];
744
745 sprintf (temp, "%*ld", length, (long) ptrval);
746 Nlm_StringNCpy_0 (str, temp, maxsize);
747 }
748
Nlm_RealToStr(Nlm_FloatLo realval,Nlm_CharPtr str,Nlm_Int2 length,Nlm_Int2 dec,size_t maxsize)749 extern void Nlm_RealToStr (Nlm_FloatLo realval, Nlm_CharPtr str,
750 Nlm_Int2 length, Nlm_Int2 dec,
751 size_t maxsize)
752
753 {
754 Nlm_Char temp [80];
755
756 sprintf (temp, "%*.*f", length, dec, (float)realval);
757 Nlm_StringNCpy_0 (str, temp, maxsize);
758 }
759
Nlm_DoubleToStr(Nlm_FloatHi doubleval,Nlm_CharPtr str,Nlm_Int2 length,Nlm_Int2 dec,size_t maxsize)760 extern void Nlm_DoubleToStr (Nlm_FloatHi doubleval, Nlm_CharPtr str,
761 Nlm_Int2 length, Nlm_Int2 dec,
762 size_t maxsize)
763
764 {
765 Nlm_Char temp [80];
766
767 sprintf (temp, "%*.*lf", length, dec, (double)doubleval);
768 Nlm_StringNCpy_0 (str, temp, maxsize);
769 }
770