home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / graphics-0.17 / dist-stat / subs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-13  |  1.8 KB  |  115 lines

  1. /*
  2.  * $Header: /files1/home/toy/src/stat/RCS/subs.c,v 1.1 90/08/31 14:51:24 toy Exp $
  3.  *
  4.  * $Log:    subs.c,v $
  5.  * Revision 1.1  90/08/31  14:51:24  toy
  6.  * Initial revision
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include "gps.h"
  14.  
  15. #ifndef    lint
  16. static char RCSID[] = "@(#) $Id: subs.c,v 1.1 90/08/31 14:51:24 toy Exp $";
  17. #endif
  18.  
  19. /*
  20.  * get_my_name
  21.  *
  22.  * Return the name of the current program, or set it to
  23.  * a default name.
  24.  */
  25.  
  26. #if    defined(__STDC__) || defined(__GNUC__)
  27. const char *
  28. get_my_name (const char *argv, const char *def_name)
  29. #else
  30. char *
  31. get_my_name (argv, def_name)
  32.      char *argv;
  33.      char *def_name;
  34. #endif
  35. {
  36.   const char *name;
  37.   if (argv == NULL)
  38.     {
  39.       name = def_name;
  40.     }
  41.   else
  42.     {
  43.       name = strrchr (argv, '/');
  44.       if (name == NULL)
  45.     {
  46.       name = argv;
  47.     }
  48.       else
  49.     {
  50.       name++;
  51.     }
  52.     }
  53.  
  54.   return name;
  55. }
  56.  
  57. /*
  58.  * get_number
  59.  *
  60.  * Read a floating point number from the specified file.  Any
  61.  * unknown characters are silently ignored.
  62.  *
  63.  * On return, EOF is returned for the end of file, 0 for some
  64.  * unspecified error, and 1 if the number was read correctly.
  65.  */
  66.  
  67. #if    defined(__STDC__) || defined(__GNUC__)
  68. int
  69. get_number (FILE * fp, double *value)
  70. #else
  71. int
  72. get_number (fp, value)
  73.      FILE *fp;
  74.      double *value;
  75. #endif
  76. {
  77.   int ch;
  78.  
  79.   /*
  80.    * Skip over any characters that can't be part of a
  81.    * number
  82.    */
  83.  
  84.   do
  85.     {
  86.       ch = getc (fp);
  87.   } while ((ch != EOF) && (ch != '-') && (ch != '.') && (!isdigit (ch)));
  88.  
  89.   if (ch != EOF)
  90.     {
  91.       ungetc (ch, fp);
  92.       ch = fscanf (fp, "%lf", value);
  93.     }
  94.   return ch;
  95. }
  96.  
  97. /*
  98.  * print_number
  99.  *
  100.  * Print the specified number to the given file.
  101.  */
  102.  
  103. #if    defined(__STDC__) || defined(__GNUC__)
  104. void
  105. print_number (FILE * fp, double value)
  106. #else
  107. void
  108. print_number (fp, value)
  109.      FILE *fp;
  110.      double value;
  111. #endif
  112. {
  113.   fprintf (fp, "%g\n", value);
  114. }
  115.