--- projects/cms/source/idar/idar.c 2003/03/30 22:16:20 1.7 +++ projects/cms/source/idar/idar.c 2003/04/02 15:41:01 1.10 @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -235,6 +236,77 @@ int cmp_cpu(machine_data_list_t *a, machine_data_list_ } } */ + +#ifndef HAVE_ATOLL +long long int atoll (const char *nptr){ + return strtoll (nptr, (char **) NULL, 10); +} +#endif + +#ifndef HAVE_STRLCPY +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif + FILE *create_tcp_connection(char *hostname, int port){ int sock; @@ -608,6 +680,7 @@ void display(machine_data_list_t *machine_data_list, d int x=1; if(*title){ + clear(); move (num_lines-3, 1); printw("Sorting by %-64s", display_config->sortby); @@ -778,10 +851,10 @@ int main(int argc, char **argv){ display_config.network_io_total_tx=1; display_config.network_io_total_rx=1; - display_config.network_all_stats=1; + display_config.network_all_stats=0; - display_config.disk_io_total_write=0; - display_config.disk_io_total_read=0; + display_config.disk_io_total_write=1; + display_config.disk_io_total_read=1; display_config.disk_io_all_stats=0; display_config.disk_total_used=0; @@ -905,12 +978,15 @@ int main(int argc, char **argv){ ch=getc(stdin); switch(ch){ + + /* Quit */ case 'Q': case 'q': endwin(); exit(0); break; + /* Sort by */ case 'C': sortby_ptr=cmp_cpu_used; strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); @@ -943,10 +1019,88 @@ int main(int argc, char **argv){ sortby_ptr=cmp_network_io_total; } break; + case 'D': + if(sortby_ptr==cmp_disk_io_total){ + strlcpy(display_config.sortby, DISKIOR, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total_read; + }else if(sortby_ptr==cmp_disk_io_total_read){ + strlcpy(display_config.sortby, DISKIOW, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total_write; + }else{ + strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); + sortby_ptr=cmp_disk_io_total; + } + break; - } + /* Display */ - title=1; + case 'd': + if(display_config.disk_io_total_read){ + display_config.disk_io_total_read=0; + display_config.disk_io_total_write=0; + }else{ + display_config.disk_io_total_read=1; + display_config.disk_io_total_write=1; + } + break; + case 'n': + if(display_config.network_io_total_rx){ + display_config.network_io_total_rx=0; + display_config.network_io_total_tx=0; + }else{ + display_config.network_io_total_rx=1; + display_config.network_io_total_tx=1; + } + break; + case 'm': + if(display_config.memory_used_pecent){ + display_config.memory_used_pecent=0; + }else{ + display_config.memory_used_pecent=1; + } + break; + + case 's': + if(display_config.swap_used_pecent){ + display_config.swap_used_pecent=0; + }else{ + display_config.swap_used_pecent=1; + } + break; + case 'l': + if(display_config.load_1){ + display_config.load_1=0; + }else{ + display_config.load_1=1; + } + break; + case 'p': + if(display_config.pages_in){ + display_config.pages_in=0; + display_config.pages_out=0; + }else{ + display_config.pages_in=1; + display_config.pages_out=1; + } + break; + case 'c': + if(display_config.cpu_used){ + display_config.cpu_used=0; + }else{ + display_config.cpu_used=1; + } + break; + + default: + /* Invalid key.. Ignore.. Set Title to -1, as the + * title++ will then make that "0" (false) so a + * screen redraw will not happen */ + title=-1; + break; + } + + /* Increment title so it becomes true (and making the screen update */ + title++; } if(FD_ISSET(data_fileno, &infds)){