Author: mladen.turk(a)jboss.com
Date: 2007-09-14 04:57:26 -0400 (Fri, 14 Sep 2007)
New Revision: 1030
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/os/linux/module.c
trunk/sight/native/os/linux/netadapter.c
trunk/sight/native/os/linux/network.c
trunk/sight/native/os/linux/tcpstat.c
trunk/sight/native/os/linux/udpstat.c
trunk/sight/native/os/linux/volume.c
trunk/sight/native/os/posix/group.c
trunk/sight/native/os/posix/user.c
trunk/sight/native/share/jnu.c
Log:
Remove union from sight_arr_t
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/include/sight_local.h 2007-09-14 08:57:26 UTC (rev 1030)
@@ -158,6 +158,7 @@
void sight_arr_free(sight_arr_t *);
sight_arr_t *sight_arr_rload(const char *);
sight_arr_t *sight_arr_cload(const char *, const char *);
+sight_arr_t *sight_arr_lload(const char *, int);
#define SIGHT_FREE(x) if ((x)) free((x))
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/include/sight_types.h 2007-09-14 08:57:26 UTC (rev 1030)
@@ -103,10 +103,7 @@
typedef struct sight_arr_t {
jsize siz;
jsize len;
- union {
- char **ca;
- jchar **wa;
- } arr;
+ char **arr;
} sight_arr_t;
typedef struct sight_object_t sight_object_t;
Modified: trunk/sight/native/os/linux/module.c
===================================================================
--- trunk/sight/native/os/linux/module.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/module.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -122,7 +122,7 @@
goto cleanup;
}
for (j = 0; j < amods->siz; j++) {
- if (strchr(amods->arr.ca[j], '/'))
+ if (strchr(amods->arr[j], '/'))
nmods++;
}
@@ -136,7 +136,7 @@
char *bn = NULL;
char *p;
unsigned long long b, o;
- if ((bp = strchr(amods->arr.ca[j], '/'))) {
+ if ((bp = strchr(amods->arr[j], '/'))) {
if ((bn = strrchr(bp, '/')))
bn++;
}
@@ -149,7 +149,7 @@
}
SET_IFIELD_S(0000, m, bn);
SET_IFIELD_S(0001, m, bp);
- b = strtoull(amods->arr.ca[j], &p, 16);
+ b = strtoull(amods->arr[j], &p, 16);
if (p && *p == '-')
o = strtoull(p + 1, NULL, 16) - b;
else
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -214,7 +214,7 @@
memset(&ifi, 0, sizeof(struct ifreq));
strcpy(ifi.ifr_name, name);
-
+
if (!ca->virt) {
if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
id->index = ifi.ifr_ifindex;
@@ -222,7 +222,7 @@
id->index = -1;
if (!ioctl(sd, SIOCGIFFLAGS, (char *)&ifi))
id->flags = ifi.ifr_flags;
- /* Can we have IPV4 without MAC address ? */
+ /* Can we have IPV4 without MAC address ? */
if (!ioctl(sd, SIOCGIFHWADDR, (char *)&ifi))
make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
if (!ioctl(sd, SIOCGIFMTU, (char *)&ifi))
@@ -351,7 +351,7 @@
ce = cache_add(e->ifc, pname);
if (!(id = (net_ifc_data_t *)ce->data)) {
net_ifc_addr_t *ca;
-
+
if (!(id = new_ifc_data(_E, ifr->ifr_name, &ca))) {
free(ifc.ifc_buf);
goto cleanup;
@@ -382,20 +382,20 @@
for (i = 2; i < i4a->siz; i++) {
cache_entry_t *ce;
char *pname;
- if (!(pname = strchr(i4a->arr.ca[i], ':')))
+ if (!(pname = strchr(i4a->arr[i], ':')))
continue;
*pname = '\0';
- ce = cache_add(e->ifc, i4a->arr.ca[i]);
+ ce = cache_add(e->ifc, i4a->arr[i]);
if (!(id = (net_ifc_data_t *)ce->data)) {
net_ifc_addr_t *ca;
- if (!(id = new_ifc_data(_E, i4a->arr.ca[i], &ca))) {
+ if (!(id = new_ifc_data(_E, i4a->arr[i], &ca))) {
sight_arr_free(i4a);
goto cleanup;
}
ce->data = id;
id->type = AF_INET;
- do_ifrec(id, ca, e->sd, i4a->arr.ca[i]);
+ do_ifrec(id, ca, e->sd, i4a->arr[i]);
}
}
sight_arr_free(i4a);
@@ -409,7 +409,7 @@
char ias[64];
char las[128] = "";
struct in6_addr in6;
- al = sscanf(i6a->arr.ca[i],
+ al = sscanf(i6a->arr[i],
"%32s %02x %02x %02x %02x %16s",
ias, &ifidx, &plen, &scope, &dads,
ifi.ifr_name);
if (al != 6)
Modified: trunk/sight/native/os/linux/network.c
===================================================================
--- trunk/sight/native/os/linux/network.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/network.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -106,7 +106,7 @@
}
if ((tdns = sight_arr_rload("/etc/resolv.conf"))) {
for (i = 0; i < tdns->siz; i++) {
- if (strstr(tdns->arr.ca[i], "nameserver")) {
+ if (strstr(tdns->arr[i], "nameserver")) {
len++;
}
}
@@ -118,7 +118,7 @@
goto cleanup;
}
for (i = 0; i < tdns->siz; i++) {
- if ((pd = strstr(tdns->arr.ca[i], "nameserver"))) {
+ if ((pd = strstr(tdns->arr[i], "nameserver"))) {
pd += 10;
addr = sight_new_netaddr_class(_E, _O);
if (!addr || (*_E)->ExceptionCheck(_E)) {
Modified: trunk/sight/native/os/linux/tcpstat.c
===================================================================
--- trunk/sight/native/os/linux/tcpstat.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/tcpstat.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -198,8 +198,8 @@
return;
}
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "TCP: inuse ", 11) == 0) {
- NumCons = atoi(tnet->arr.ca[i] + 11);
+ if (memcmp(tnet->arr[i], "TCP: inuse ", 11) == 0) {
+ NumCons = atoi(tnet->arr[i] + 11);
break;
}
}
@@ -210,8 +210,8 @@
return;
}
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "TCP6: inuse ", 12) == 0) {
- NumCons = atoi(tnet->arr.ca[i] + 12);
+ if (memcmp(tnet->arr[i], "TCP6: inuse ", 12) == 0) {
+ NumCons = atoi(tnet->arr[i] + 12);
break;
}
}
@@ -229,9 +229,9 @@
/* Get the information corresponding to the second entry Tcp: */
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "Tcp:", 4) == 0) {
- if (memcmp(tnet->arr.ca[i], "Tcp: RtoAlgorithm", 17) != 0) {
- sscanf(tnet->arr.ca[i], "Tcp: %d %d %d %d %d %d %d %d %d %d %d %d
%d %d",
+ if (memcmp(tnet->arr[i], "Tcp:", 4) == 0) {
+ if (memcmp(tnet->arr[i], "Tcp: RtoAlgorithm", 17) != 0) {
+ sscanf(tnet->arr[i], "Tcp: %d %d %d %d %d %d %d %d %d %d %d %d %d
%d",
&RtoAlgorithm, &RtoMin, &RtoMax, &MaxConn,
&ActiveOpens,
&PassiveOpens, &AttemptFails, &EstabResets,
&CurrEstab,
&InSegs, &OutSegs, &RetransSegs, &InErrs,
&OutRsts);
@@ -345,7 +345,7 @@
/* TODO: Throw overflow */
return;
}
- num = sscanf(e->tnet->arr.ca[e->idx],
+ num = sscanf(e->tnet->arr[e->idx],
"%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld
%512s",
&d, las, &lp, ras, &rp, &state,
&txq, &rxq, &timer_run, &timelen, &retr,
Modified: trunk/sight/native/os/linux/udpstat.c
===================================================================
--- trunk/sight/native/os/linux/udpstat.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/udpstat.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -115,8 +115,8 @@
return;
}
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "UDP: inuse ", 11) == 0) {
- NumCons = atoi(tnet->arr.ca[i] + 11);
+ if (memcmp(tnet->arr[i], "UDP: inuse ", 11) == 0) {
+ NumCons = atoi(tnet->arr[i] + 11);
break;
}
}
@@ -127,8 +127,8 @@
return;
}
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "UDP6: inuse ", 12) == 0) {
- NumCons = atoi(tnet->arr.ca[i] + 12);
+ if (memcmp(tnet->arr[i], "UDP6: inuse ", 12) == 0) {
+ NumCons = atoi(tnet->arr[i] + 12);
break;
}
}
@@ -146,9 +146,9 @@
/* Get the information corresponding to the second entry Tcp: */
for (i = 0; i < tnet->siz; i++) {
- if (memcmp(tnet->arr.ca[i], "Udp:", 4) == 0) {
- if (memcmp(tnet->arr.ca[i], "Udp: InDatagrams", 16) != 0) {
- sscanf(tnet->arr.ca[i], "Udp: %d %d %d %d %d %d",
+ if (memcmp(tnet->arr[i], "Udp:", 4) == 0) {
+ if (memcmp(tnet->arr[i], "Udp: InDatagrams", 16) != 0) {
+ sscanf(tnet->arr[i], "Udp: %d %d %d %d %d %d",
&InDatagrams, &NoPorts, &InErrors, &OutDatagrams,
&RcvbufErrors, &SndbufErrors);
break;
@@ -252,7 +252,7 @@
/* TODO: Throw overflow */
return;
}
- num = sscanf(e->tnet->arr.ca[e->idx],
+ num = sscanf(e->tnet->arr[e->idx],
"%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld
%512s",
&d, las, &lp, ras, &rp, &state,
&txq, &rxq, &timer_run, &timelen, &retr,
Modified: trunk/sight/native/os/linux/volume.c
===================================================================
--- trunk/sight/native/os/linux/volume.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/linux/volume.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -220,7 +220,7 @@
unsigned long size, used;
int priority;
- if (sscanf(e->swaps->arr.ca[e->swap_idx],
+ if (sscanf(e->swaps->arr[e->swap_idx],
"%250s %30s %lu %lu %d",
path, type, &size, &used, &priority) == 5) {
SET_IFIELD_S(0000, thiz, path);
@@ -231,7 +231,7 @@
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_SWAP);
SET_IFIELD_J(0005, thiz, size - used);
SET_IFIELD_J(0006, thiz, size);
- SET_IFIELD_J(0007, thiz, size - used);
+ SET_IFIELD_J(0007, thiz, size - used);
}
e->swap_idx++;
return;
Modified: trunk/sight/native/os/posix/group.c
===================================================================
--- trunk/sight/native/os/posix/group.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/posix/group.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -157,7 +157,7 @@
goto cleanup;
}
/* 1. GroupName */
- token = sight_strtok_c(tgrp->arr.ca[i], ':', &titer);
+ token = sight_strtok_c(tgrp->arr[i], ':', &titer);
SET_IFIELD_S(0000, u, token);
/* 2. Password */
token = sight_strtok_c(NULL, ':', &titer);
@@ -208,7 +208,7 @@
char *titer;
/* 1. GroupName */
- gname = sight_strtok_c(tgrp->arr.ca[i], ':', &titer);
+ gname = sight_strtok_c(tgrp->arr[i], ':', &titer);
/* 2. Password */
token = sight_strtok_c(NULL, ':', &titer);
/* 3. GID */
Modified: trunk/sight/native/os/posix/user.c
===================================================================
--- trunk/sight/native/os/posix/user.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/os/posix/user.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -171,7 +171,7 @@
goto cleanup;
}
/* 1. UserName */
- token = sight_strtok_c(tusr->arr.ca[i], ':', &titer);
+ token = sight_strtok_c(tusr->arr[i], ':', &titer);
SET_IFIELD_S(0000, u, token);
/* 2. Password */
token = sight_strtok_c(NULL, ':', &titer);
@@ -219,7 +219,7 @@
char *titer;
/* 1. UserName */
- uname = sight_strtok_c(tusr->arr.ca[i], ':', &titer);
+ uname = sight_strtok_c(tusr->arr[i], ':', &titer);
/* 2. Password */
token = sight_strtok_c(NULL, ':', &titer);
/* 3. UID */
@@ -313,7 +313,7 @@
char *titer;
/* 1. UserName */
- uname = sight_strtok_c(tusr->arr.ca[i], ':', &titer);
+ uname = sight_strtok_c(tusr->arr[i], ':', &titer);
if (strcmp(uname, tuc->list[j]->key)) {
continue;
}
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-14 08:30:34 UTC (rev 1029)
+++ trunk/sight/native/share/jnu.c 2007-09-14 08:57:26 UTC (rev 1030)
@@ -766,7 +766,7 @@
return NULL;
a->siz = 0;
a->len = init;
- if (!(a->arr.ca = (char **)malloc(init * sizeof(char *)))) {
+ if (!(a->arr = (char **)malloc(init * sizeof(char *)))) {
int saved = errno;
free(a);
a = NULL;
@@ -780,19 +780,19 @@
if (!str || !*str)
return 0; /* Skip empty and null strings */
if (a->siz < a->len) {
- a->arr.ca[a->siz++] = strdup(str);
+ a->arr[a->siz++] = strdup(str);
}
else {
char **na;
size_t len = a->len << 2;
if (!(na = (char **)malloc(len * sizeof(char *))))
return errno;
- memcpy(na, a->arr.ca, a->siz * sizeof(char *));
- free(a->arr.ca);
+ memcpy(na, a->arr, a->siz * sizeof(char *));
+ free(a->arr);
a->len = len;
- a->arr.ca = na;
- a->arr.ca[a->siz] = strdup(str);
- if (!a->arr.ca[a->siz])
+ a->arr = na;
+ a->arr[a->siz] = strdup(str);
+ if (!a->arr[a->siz])
return errno;
else
a->siz++;
@@ -807,9 +807,9 @@
if (!a)
return;
for (i = 0; i < a->siz; i++) {
- SIGHT_FREE(a->arr.ca[i]);
+ SIGHT_FREE(a->arr[i]);
}
- free(a->arr.ca);
+ free(a->arr);
free(a);
}
@@ -880,6 +880,32 @@
return array;
}
+sight_arr_t *sight_arr_lload(const char *fname, int max_lines)
+{
+ sight_arr_t *array;
+ char buf[8192];
+ FILE *file;
+ int lc = 0;
+ if (!(file = fopen(fname, "r")))
+ return NULL;
+ if (!(array = sight_arr_new(max_lines))) {
+ fclose(file);
+ return NULL;
+ }
+ while (fgets(&buf[0], 8192, file)) {
+ char *pline = sight_trim(&buf[0]);
+ /* Skip empty lines */
+ if (pline) {
+ if (sight_arr_add(array, pline))
+ break;
+ if (++lc >= max_lines)
+ break;
+ }
+ }
+ fclose(file);
+ return array;
+}
+
char *sight_strtok_c(char *str, int sep, char **last)
{
char *sp;