home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / bigb / part01 / misc.c < prev    next >
C/C++ Source or Header  |  1991-09-13  |  2KB  |  67 lines

  1. /* Assorted small routines */
  2.  
  3. #include "bigb.h"
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7. #include <pwd.h>
  8.  
  9. /* Construct a string representing the time given as a parameter */
  10. PUBLIC char *date(time_t the_time)
  11. {
  12.     char    *buffer;
  13.  
  14.     buffer=asctime(localtime(&the_time));
  15.     buffer[24]='\0';    /* Dump the \n */
  16.     return(buffer);
  17. }
  18.  
  19. /* Neaten up a string.  This removes all spaces,tabs and newlines, it also
  20.  * ensures that all text before the first '=' is lower case.
  21. */
  22. PUBLIC void neaten(char *data)
  23. {
  24.     char    buffer[128];
  25.     char    *ptr;
  26.     int     found_equals;
  27.  
  28.     /* This looks a bit strange but it is correct, this subroutine is used */
  29.     /* in 2 circumstances, 'variable=value' and plain 'value', the variable */
  30.     /* name needs to be made lower case but nothing else does, so if there */
  31.     /* is no equals sign set the found_equals flag to TRUE to stop any */
  32.     /* upper case -> lower case conversions from the start */
  33.  
  34.     if (strchr(data,'=') != CNULL)
  35.         found_equals = FALSE;
  36.     else
  37.         found_equals = TRUE;
  38.     
  39.     for (ptr=data ; *ptr!='\0' ; ptr++) {
  40.         if (*ptr == '=')
  41.             found_equals = TRUE;
  42.         if (!found_equals && isupper(*ptr))
  43.             *ptr = tolower(*ptr);
  44.         if (isspace(*ptr)) {    /* Remove all whitespace */
  45.             strcpy(buffer, ptr+1);
  46.             strcpy(ptr,buffer);
  47.         }
  48.     }
  49.  
  50.     /* If after all that it was a comment then nullify string */
  51.     if (*data == '#')
  52.         *data='\0';
  53. }
  54.  
  55. /* Print the warning message to the screen and log file */
  56. PUBLIC void print_warning(const char *text)
  57. {
  58.     /* Print to the stdout ( console ) , <BEEP> WARNING: message */
  59.     fprintf(error_display_chan,"%c%c%cWARNING: %s%c%c",
  60.         (char) 10, (char) 13,(char) 7,
  61.         text,
  62.         (char) 10, (char) 13);
  63.  
  64.     /* Print the raw warning to the log file */
  65.     fprintf(error_file_chan, "%s\n", text);
  66. }
  67.