Hi,
I haven't programed in C in a few years. I have been doing a lot of shell scripting, I.E. not really programming anything heavy. :o
That said, I have a script that gives hourly usage statistics for our email server. It runs w-a-y to slow as a script for my impatience, and needs to be converted to C. That and some Windows admins have expressed interest in it. Porting to C would be easier to cross compile that a script. :rolleyes:
In the shell script I have an output function where I can pass text color, formatting (4.3f, 6s, etc.) and value.
Shell Code
output{
printf "\033[$1m%$2\033[0m" $3
}
Here's what I have in C so far.
int output(int clr,float val){ // Add in the format if possible
switch (clr) {
case 0: printf("%c[%dm %2.3f ", 0x1B, 33, val); // print Yellow (Lower than average usage)
break;
case 1: printf("%c[%dm %2.3f ", 0x1B, 32, val); // print Green (Medium)
break;
case 2: printf("%c[%dm %2.3f ", 0x1B, 31, val); // print Red (High)
break;
case 3: printf("%c[%dm %2.3f ", 0x1B, 0, val); // print White (All else)
break;
}
}
Is there a way to pass the format parameter as a variable? I.E. pearl uses something like this %${fmt}f. Can this be done in C?
There are 5 columns, each can have their own color, width, format(d,s,f...) and value.
Obviously, the colors won't show up here. But you get the idea.
Hour Count APM AMBPM MBytes
----+-----+---+-----+-------
00 485 8 0.64 38.45
01 511 9 0.06 3.51
02 517 9 0.07 4.43
...
It's not a show stopper, but it would save me from having to create routines for every different format.
Any help would be greatly appreciated.
Thank You