diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-13 16:58:59 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-13 16:58:59 -0500 |
commit | 81349e26b25ad691d1cabb67d17d1d3ff1d8d6b4 (patch) | |
tree | 129213baeb184bdcf44e6edfcfb2792e61eec7ec | |
parent | 095bbf925334a6014dfa89bd6eee6448a836b1ff (diff) | |
download | NetNuke2-81349e26b25ad691d1cabb67d17d1d3ff1d8d6b4.tar.gz |
More ncurses work.
-rw-r--r-- | src/bus.c | 22 | ||||
-rw-r--r-- | src/curses.c | 29 | ||||
-rw-r--r-- | src/nukectl.c | 20 | ||||
-rw-r--r-- | src/output_redirect.c | 9 |
4 files changed, 44 insertions, 36 deletions
@@ -48,14 +48,14 @@ int scanbus_sysfs(nndevice_t** device) /* scan for scsi devices (and with libata enabled ... ide devices too) via sysfs */ if((access(scsi_path, F_OK)) != 0) { - COM(self, "Sysfs not available\n"); + COM(self, "Sysfs not available"); return 1; } pbase = opendir(scsi_path); if(!pbase) { - COM(self, "fatal opendir: %s\n", strerror(errno)); + COM(self, "fatal opendir: %s", strerror(errno)); exit(1); } @@ -76,7 +76,7 @@ int scanbus_sysfs(nndevice_t** device) fp = fopen(tmpstr, "r"); if(fp == NULL) { - COM(self, "Could not retrieve model information from %s: %s\n", tmpstr, strerror(errno)); + COM(self, "Could not retrieve model information from %s: %s", tmpstr, strerror(errno)); } else { @@ -91,7 +91,7 @@ int scanbus_sysfs(nndevice_t** device) fp = fopen(tmpstr, "r"); if(fp == NULL) { - COM(self, "Could not retrieve vendor information from %s: %s\n", tmpstr, strerror(errno)); + COM(self, "Could not retrieve vendor information from %s: %s", tmpstr, strerror(errno)); } else { @@ -107,7 +107,7 @@ int scanbus_sysfs(nndevice_t** device) pblock = opendir(tmpstr); if(!pblock) { - COM(self, "fatal opendir: %s\n", strerror(errno)); + COM(self, "fatal opendir: %s", strerror(errno)); exit(1); } @@ -127,7 +127,7 @@ int scanbus_sysfs(nndevice_t** device) { if((ioctl(fd, BLKGETSIZE, &device[i]->blks)) != 0) { - COM(self, "ioctl: could not retrieve block count for %s\n", device[i]->path); + COM(self, "ioctl: could not retrieve block count for %s", device[i]->path); device[i]->blks = 0; } close(fd); @@ -136,7 +136,7 @@ int scanbus_sysfs(nndevice_t** device) device[i]->blksz = 512; device[i]->sz = device[i]->blks * 512; - COM(self, "%s %s %s %llu\n", device[i]->vendor, device[i]->path, device[i]->model, (device[i]->blks * device[i]->blksz)); + COM(self, "%s %s %s %llu", device[i]->vendor, device[i]->path, device[i]->model, (device[i]->blks * device[i]->blksz)); ++i; } closedir(pbase); @@ -182,7 +182,7 @@ int scanbus(nndevice_t** device, int mask) device[j]->blksz = 512; printf("%s ", device[j]->path); - printf("%llu %llu %.2f\n", device[j]->blks, device[j]->sz, (double)device[j]->sz / (1024 * 1024 * 1024)); + printf("%llu %llu %.2f", device[j]->blks, device[j]->sz, (double)device[j]->sz / (1024 * 1024 * 1024)); } close(fd); @@ -216,7 +216,7 @@ int scanbus(nndevice_t** device, int mask) device[j]->blksz = 512; printf("%s ", device[j]->path); - printf("%llu %llu %.2f\n", device[j]->blks, device[j]->sz, (double)device[j]->sz / (1024 * 1024 * 1024)); + printf("%llu %llu %.2f", device[j]->blks, device[j]->sz, (double)device[j]->sz / (1024 * 1024 * 1024)); } close(fd); } @@ -244,13 +244,13 @@ int selectbus(char** flags) if(!strcmp(flags[i], "ide")) { mask |= BUS_IDE; - COM(self, "IDE (0x%02X)\n", mask); + COM(self, "IDE (0x%02X)", mask); } if(!strcmp(flags[i], "scsi")) { mask |= BUS_SCSI; - COM(self, "SCSI (0x%02X)\n", mask); + COM(self, "SCSI (0x%02X)", mask); } i++; diff --git a/src/curses.c b/src/curses.c index 362e57a..e0d7d16 100644 --- a/src/curses.c +++ b/src/curses.c @@ -71,6 +71,7 @@ extern nndevice_t** device; void* main_window_worker(void* args) { + COM(self, "Initialized"); pthread_t thread[MAXTHREAD]; int thread_count = 0; int i = 0; @@ -123,18 +124,18 @@ void* main_window_worker(void* args) /* Run check to see if any devices were returned */ if(device[0] == NULL) { - COM(self, "No devices detected\n"); + COM(self, "No devices detected"); exit(0); } COM(self, "Safety is %s", safety_flag ? "OFF" : "ON"); - if(device_timeout) COM(self, "%ds timeout set\n", device_timeout); - if(blksz_override) COM(self, "Forcing %d block size\n", blksz_override); + if(device_timeout) COM(self, "%ds timeout set", device_timeout); + if(blksz_override) COM(self, "Forcing %d block size", blksz_override); - COM(self, "Initializing mutex\n"); + COM(self, "Initializing mutex"); pthread_mutex_init(&lock_global, NULL); pthread_mutex_init(&lock_write, NULL); - COM(self, "Generating threads\n"); + COM(self, "Generating threads"); /* Tell the random generator to start */ nnrandinit(); @@ -143,24 +144,24 @@ void* main_window_worker(void* args) for( i = 0; device[i] != NULL ; i++ ) { thread[i] = (pthread_t)nnthread(device[i]); - COM(self, "thread id: %8X %8X\n", thread[i]); + COM(self, "thread id: %8X", thread[i]); } /* Catch up */ usleep(10000); /* Using the original device count, set thread_count and join all threads */ thread_count = i; - COM(self, "Joining %d thread%c\n", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b'); + COM(self, "Joining %d thread%c", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b'); for( i = 0 ; i < thread_count ; i++) { pthread_join(thread[i], NULL); } - COM(self, "Destroying mutex\n"); + COM(self, "Destroying mutex"); pthread_mutex_destroy(&lock_global); pthread_mutex_destroy(&lock_write); - COM(self, "Total bytes written: %lu\n", total_written_bytes); + COM(self, "Total bytes written: %lu", total_written_bytes); nnrandfree(); return NULL; @@ -174,24 +175,24 @@ void main_init() int startx = 0, starty = 0, width = 0, height = 0; cbreak(); - keypad(stdscr, TRUE); - - height = getmaxy(stdscr) / 2; - width = getmaxx(stdscr); + keypad(stdscr, TRUE); + height = getmaxy(stdscr) / 2; + width = getmaxx(stdscr); main_window = create_window(height, width, starty, startx); starty = getmaxy(stdscr) / 2; height = getmaxy(stdscr) / 2; width = getmaxx(stdscr); info_window = create_window(height, width, starty, startx); - //refresh(); pthread_mutex_init(&main_window_lock, NULL); pthread_create(&main_window_thread, NULL, main_window_worker, NULL); pthread_join(main_window_thread, NULL); pthread_mutex_destroy(&main_window_lock); + getch(); } +/* This will probably never get used... Or at least not soon enough. */ void main_deinit() { endwin(); diff --git a/src/nukectl.c b/src/nukectl.c index cf39f6c..40dcb4a 100644 --- a/src/nukectl.c +++ b/src/nukectl.c @@ -50,7 +50,7 @@ void ignore_device(char** list, nndevice_t** d) { if(!strncasecmp(d[i]->path, list[j], strlen(list[j]))) { - COM(self, "%s\n", list[j]); + COM(self, "%s", list[j]); memset(d[i], 0, sizeof(nndevice_t)); //memmove(d[end-1], d[i], sizeof(nndevice_t)); } @@ -88,7 +88,7 @@ void* wipe(void* device) int fd = open(d->path, O_WRONLY | O_SYNC); if(fd < 0) { - COM(self, "Unable to open %s: %s\n", d->path, strerror(errno)); + COM(self, "Unable to open %s: %s", d->path, strerror(errno)); return (int*)1; } COM(self, "%s, block size %d, blocks %llu, total bytes %llu", d->path, d->blksz, d->blks, d->sz); @@ -102,7 +102,7 @@ void* wipe(void* device) if(verbose_flag) { percent = (long double)((bytes_out / (long double)d->sz) * 100); - //COM(self, "%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_out, d->sz, percent); + //COM(self, "%s: %llu of %llu (%0.2Lf%%)", d->path, bytes_out, d->sz, percent); pthread_mutex_lock(&lock_global); mvwprintw(info_window, lrow, 2, "%s: %llu of %llu (%0.2Lf%%)\r", d->path, bytes_out, d->sz, percent); update_window(info_window); @@ -113,7 +113,7 @@ void* wipe(void* device) } } close(fd); - COM(self, "%s complete, wrote %llu bytes\n", d->path, bytes_out); + COM(self, "%s complete, wrote %llu bytes", d->path, bytes_out); pthread_exit(NULL); return NULL; @@ -124,7 +124,7 @@ pthread_t nnthread(nndevice_t* device) pthread_t thread; if((pthread_create(&thread, NULL, wipe, device)) != 0) { - COM(self, "Failed to create thread %lu\n", thread); + COM(self, "Failed to create thread %lu", thread); return 1; } @@ -158,11 +158,11 @@ int nnwrite(int fd, int bsize) void nnrandinit() { - COM(self, "Initializing random seed\n"); + COM(self, "Initializing random seed"); randfp = fopen("/dev/urandom", "r"); if(randfp == NULL) { - COM(self, "urandom: %s\n", strerror(errno)); + COM(self, "urandom: %s", strerror(errno)); return; } srand(nngetseed()); @@ -170,7 +170,7 @@ void nnrandinit() void nnrandfree() { - COM(self, "Closing urandom\n"); + COM(self, "Closing urandom"); fclose(randfp); } @@ -179,13 +179,13 @@ unsigned int nngetseed() if((fread(&randseed, 1, sizeof(int), randfp)) > 0) { if(verbose_flag) - COM(self, "(urandom) Seed is %lu\n", randseed); + COM(self, "(urandom) Seed is %lu", randseed); return randseed; } unsigned int t = time(NULL); if(verbose_flag) - COM(self, "(UNIX Epoch) Seed is %lu\n", t); + COM(self, "(UNIX Epoch) Seed is %lu", t); return t; } diff --git a/src/output_redirect.c b/src/output_redirect.c index 1aa70ed..b70ec7a 100644 --- a/src/output_redirect.c +++ b/src/output_redirect.c @@ -73,11 +73,15 @@ int COM(const char* func, char *format, ...) { snprintf(timestr, sizeof(timestr), "%02d-%02d-%02d %02d:%02d:%02d", logtm->tm_year+1900, logtm->tm_mon+1, logtm->tm_mday, logtm->tm_hour, logtm->tm_min, logtm->tm_sec); snprintf(tmpstr, sizeof(tmpstr), "%s _%s_: %s", timestr, func, str); - fprintf(logfp, "%s", tmpstr); + /* With ncurses we will need to append a newline character because + calls to COM don't have them */ + fprintf(logfp, "%s\n", tmpstr); fclose(logfp); + goto screen_out; } else { +screen_out: snprintf(tmpstr, sizeof(tmpstr), "_%s_: %s", func, str); //fprintf(stdout, "%s", tmpstr); pthread_mutex_lock(&main_window_lock); @@ -85,6 +89,9 @@ int COM(const char* func, char *format, ...) wprintw(main_window, "%s", tmpstr); wmove(main_window, printrow, 2); update_window(main_window); + if(printrow >= (getmaxy(main_window) / 2)) + wscrl(main_window, -1); + printrow++; pthread_mutex_unlock(&main_window_lock); } |