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
|
//===============================================================
// General Purpose V Utilities
//
// Copyright (C) 1995,1996 Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
#include <v/vutil.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
//=============================>>> IntToStr <<<============================
void IntToStr(int intg, char* str)
{ // convert int intg to char string in str
LongToStr((long)intg, str);
}
//=============================>>> LongToStr <<<============================
long StrToLong(char* str)
{ // convert char string into long
long val = 0;
long neg = 1;
if (*str == '-')
{
neg = -1;
str++;
}
while (str && *str)
{
if (*str < '0' || *str > '9')
break;
val = (val * 10) + (*str - '0');
str++;
}
return neg*val;
}
//=============================>>> LongToStr <<<============================
void LongToStr(long intg, char* str)
{ // convert long intg to char string in str
long i;
long d, intval, j;
char k;
static char digits[] = "0123456789";
intval = intg >= 0L ? intg : (-intg);
str[0] = '\0';
i = 0;
do
{ // generate digits
i++;
d = intval % 10L; // mod 10
str[i] = digits[d];
intval = intval / 10L;
}
while (intval != 0L);
if (intg < 0L)
{ // then sign
str[++i] = '-';
}
for (j = 0 ; j < i ; j++ )
{ // then reverse
k = str[i];
str[i--] = str[j];
str[j] = k;
}
}
//=============================>>> ByteToStr <<<============================
void ByteToStr(unsigned char intg, char* str)
{ // convert byte intg to char string in str
int i;
int d, intval, j;
char k;
static char digits[] = "0123456789ABCDEF";
intval = intg;
str[0] = '\0';
i = 0;
do
{ // generate digits
i++;
d = intval % 16; // mod 10
str[i] = digits[d];
intval = intval / 16;
}
while (intval != 0);
for (j = 0 ; j < i ; j++ )
{ // then reverse
k = str[i];
str[i--] = str[j];
str[j] = k;
}
if (str[1] == 0) // one char only
{
str[1] = str[0]; str[2] = 0; str[0] = '0';
}
}
//=============================>>> vGetLocalTime <<<==========================
void vGetLocalTime(char* tm)
{
char buff[20];
time_t t;
t = time(0);
strftime(buff,20,"%r",localtime(&t));
strcpy(tm,buff);
}
//=============================>>> vGetLocalDate <<<==========================
void vGetLocalDate(char* tm)
{
char buff[20];
time_t t;
t = time(0);
strftime(buff,20,"%d %b %Y",localtime(&t));
strcpy(tm,buff);
}
|