reduce code

This commit is contained in:
Hisham Muhammad 2011-11-05 04:55:05 +00:00
parent 88f6de2352
commit 3885648881
2 changed files with 48 additions and 52 deletions

View File

@ -11,63 +11,60 @@
/*{ /*{
typedef struct SignalItem_ {
const char* name;
int number;
} SignalItem;
typedef struct SignalsPanel_ { typedef struct SignalsPanel_ {
Panel super; Panel super;
ListItem** signals;
} SignalsPanel; } SignalsPanel;
}*/ }*/
#ifndef SIGNAL_COUNT
#define SIGNAL_COUNT 34
#endif
static void SignalsPanel_delete(Object* object) { static void SignalsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
SignalsPanel* this = (SignalsPanel*) object; SignalsPanel* this = (SignalsPanel*) object;
Panel_done(super); Panel_done(super);
free(this->signals);
free(this); free(this);
} }
static ListItem** Signal_getSignalTable() { static SignalItem signals[] = {
ListItem** signals = malloc(sizeof(ListItem*) * SIGNAL_COUNT); { .name = " 0 Cancel", .number = 0 },
signals[0] = ListItem_new(" 0 Cancel", 0); { .name = " 1 SIGHUP", .number = 1 },
signals[1] = ListItem_new(" 1 SIGHUP", 1); { .name = " 2 SIGINT", .number = 2 },
signals[2] = ListItem_new(" 2 SIGINT", 2); { .name = " 3 SIGQUIT", .number = 3 },
signals[3] = ListItem_new(" 3 SIGQUIT", 3); { .name = " 4 SIGILL", .number = 4 },
signals[4] = ListItem_new(" 4 SIGILL", 4); { .name = " 5 SIGTRAP", .number = 5 },
signals[5] = ListItem_new(" 5 SIGTRAP", 5); { .name = " 6 SIGABRT", .number = 6 },
signals[6] = ListItem_new(" 6 SIGABRT", 6); { .name = " 6 SIGIOT", .number = 6 },
signals[7] = ListItem_new(" 6 SIGIOT", 6); { .name = " 7 SIGBUS", .number = 7 },
signals[8] = ListItem_new(" 7 SIGBUS", 7); { .name = " 8 SIGFPE", .number = 8 },
signals[9] = ListItem_new(" 8 SIGFPE", 8); { .name = " 9 SIGKILL", .number = 9 },
signals[10] = ListItem_new(" 9 SIGKILL", 9); { .name = "10 SIGUSR1", .number = 10 },
signals[11] = ListItem_new("10 SIGUSR1", 10); { .name = "11 SIGSEGV", .number = 11 },
signals[12] = ListItem_new("11 SIGSEGV", 11); { .name = "12 SIGUSR2", .number = 12 },
signals[13] = ListItem_new("12 SIGUSR2", 12); { .name = "13 SIGPIPE", .number = 13 },
signals[14] = ListItem_new("13 SIGPIPE", 13); { .name = "14 SIGALRM", .number = 14 },
signals[15] = ListItem_new("14 SIGALRM", 14); { .name = "15 SIGTERM", .number = 15 },
signals[16] = ListItem_new("15 SIGTERM", 15); { .name = "16 SIGSTKFLT", .number = 16 },
signals[17] = ListItem_new("16 SIGSTKFLT", 16); { .name = "17 SIGCHLD", .number = 17 },
signals[18] = ListItem_new("17 SIGCHLD", 17); { .name = "18 SIGCONT", .number = 18 },
signals[19] = ListItem_new("18 SIGCONT", 18); { .name = "19 SIGSTOP", .number = 19 },
signals[20] = ListItem_new("19 SIGSTOP", 19); { .name = "20 SIGTSTP", .number = 20 },
signals[21] = ListItem_new("20 SIGTSTP", 20); { .name = "21 SIGTTIN", .number = 21 },
signals[22] = ListItem_new("21 SIGTTIN", 21); { .name = "22 SIGTTOU", .number = 22 },
signals[23] = ListItem_new("22 SIGTTOU", 22); { .name = "23 SIGURG", .number = 23 },
signals[24] = ListItem_new("23 SIGURG", 23); { .name = "24 SIGXCPU", .number = 24 },
signals[25] = ListItem_new("24 SIGXCPU", 24); { .name = "25 SIGXFSZ", .number = 25 },
signals[26] = ListItem_new("25 SIGXFSZ", 25); { .name = "26 SIGVTALRM", .number = 26 },
signals[27] = ListItem_new("26 SIGVTALRM", 26); { .name = "27 SIGPROF", .number = 27 },
signals[28] = ListItem_new("27 SIGPROF", 27); { .name = "28 SIGWINCH", .number = 28 },
signals[29] = ListItem_new("28 SIGWINCH", 28); { .name = "29 SIGIO", .number = 29 },
signals[30] = ListItem_new("29 SIGIO", 29); { .name = "29 SIGPOLL", .number = 29 },
signals[31] = ListItem_new("29 SIGPOLL", 29); { .name = "30 SIGPWR", .number = 30 },
signals[32] = ListItem_new("30 SIGPWR", 30); { .name = "31 SIGSYS", .number = 31 },
signals[33] = ListItem_new("31 SIGSYS", 31); };
return signals;
}
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) { SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel)); SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
@ -75,9 +72,8 @@ SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
Panel_init(super, x, y, w, h, LISTITEM_CLASS, true); Panel_init(super, x, y, w, h, LISTITEM_CLASS, true);
((Object*)this)->delete = SignalsPanel_delete; ((Object*)this)->delete = SignalsPanel_delete;
this->signals = Signal_getSignalTable(); for(unsigned int i = 0; i < sizeof(signals)/sizeof(SignalItem); i++)
for(int i = 0; i < SIGNAL_COUNT; i++) Panel_set(super, i, (Object*) ListItem_new(signals[i].name, signals[i].number));
Panel_set(super, i, (Object*) this->signals[i]);
SignalsPanel_reset(this); SignalsPanel_reset(this);
return this; return this;
} }

View File

@ -13,16 +13,16 @@
#include <ctype.h> #include <ctype.h>
typedef struct SignalItem_ {
const char* name;
int number;
} SignalItem;
typedef struct SignalsPanel_ { typedef struct SignalsPanel_ {
Panel super; Panel super;
ListItem** signals;
} SignalsPanel; } SignalsPanel;
#ifndef SIGNAL_COUNT
#define SIGNAL_COUNT 34
#endif
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h); SignalsPanel* SignalsPanel_new(int x, int y, int w, int h);
void SignalsPanel_reset(SignalsPanel* this); void SignalsPanel_reset(SignalsPanel* this);