[x-wrt] r4805 committed - webifmetabin: fix and clean source files

5 views
Skip to first unread message

codesite...@google.com

unread,
Aug 16, 2009, 12:01:30 PM8/16/09
to x-wrt-...@googlegroups.com
Revision: 4805
Author: lubekgc
Date: Sun Aug 16 09:01:13 2009
Log: webifmetabin: fix and clean source files
http://code.google.com/p/x-wrt/source/detail?r=4805

Modified:
/trunk/package/webif/src/bstrip.c
/trunk/package/webif/src/int2human/main.c
/trunk/package/webif/src/webif-page.c
/trunk/package/webif/src/webifmetabin.c
/trunk/package/webif/src/wepkeygen/keygen.c
/trunk/package/webif/src/wepkeygen/md5.c

=======================================
--- /trunk/package/webif/src/bstrip.c Mon Jan 22 11:28:10 2007
+++ /trunk/package/webif/src/bstrip.c Sun Aug 16 09:01:13 2009
@@ -1,4 +1,7 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>

#define BUF_SIZE 1024
#define READ_LEN 14
@@ -11,14 +14,14 @@
{
int r = 0, c = 0;
char *m;
-
+
if (rbuflen > 0)
memcpy(buf, rbuf, rbuflen);
c += rbuflen;

while ((c + read_len < BUF_SIZE) && ((r = read(0, &buf[c], read_len)) >
0)) {
m = NULL;
-
+
if ((m = memchr(&buf[c], '\n', r)) != NULL) {
rbuflen = r - (m - &buf[c] + 1);
if (rbuflen > 0)
@@ -28,10 +31,10 @@
rbuflen = 0;
c += r;
}
-
+
if ((c > 3) && (memcmp(&buf[c - 3], "---", 3) == 0))
read_len = 1;
-
+
if (m != NULL)
return c;
}
@@ -56,13 +59,13 @@
fprintf(stderr, "Syntax: %s (name|data <boundary>)\n", argv[0]);
exit(1);
}
- while (tmp = strchr(argv[1], '\r'))
+ while ((tmp = strchr(argv[1], '\r')))
*tmp = 0;
-
+
len = strlen(argv[1]);

*buf = 0;
- while ((strncmp(buf, argv[1], len) != 0) &&
+ while ((strncmp(buf, argv[1], len) != 0) &&
(strncmp(buf + 2, argv[1], len) != 0)) {
if (r > 0) {
if (r1 > 0)
@@ -76,4 +79,6 @@

if (r1 > 2)
write(1, buf1, r1 - 2);
-}
+
+ return 0;
+}
=======================================
--- /trunk/package/webif/src/int2human/main.c Mon Jan 22 11:28:10 2007
+++ /trunk/package/webif/src/int2human/main.c Sun Aug 16 09:01:13 2009
@@ -1,4 +1,4 @@
-/* stupid stand-alone stub - Jeremy Collake <jer...@bitsum.com> */
+/* stupid stand-alone stub - Jeremy Collake <jer...@bitsum.com> */
/* This code GPL, as if anyone cares. */

#include <stdio.h>
@@ -6,7 +6,7 @@
#include <string.h>
#include "human_readable.h"

-void int2human_usage()
+void int2human_usage()
{
printf("Usage: int2human integer1 integer2 integer3 ...\n\n"
" Where integerX is an integer to convert to human readable form. If
multiple\n"
@@ -25,7 +25,6 @@
#endif
(int argc, char **argv)
{
- int nUseStdin=0;
char *pszInputText;
int nI;
if(argc<2)
@@ -35,7 +34,7 @@
{
int2human_usage();
exit(1);
- }
+ }
}
else
{
@@ -43,7 +42,7 @@
int nReqLen=1; /* require at least null terminator */
for(nI=1; nI<argc;nI++)
{
- if(!strcmp(argv[nI], "--?") || !strcmp(argv[nI], "--help"))
+ if(!strcmp(argv[nI], "--?") || !strcmp(argv[nI], "--help"))
{
int2human_usage();
exit(1);
@@ -53,7 +52,7 @@
pszInputText=(char *)malloc(nReqLen);
pszInputText[0]=0;
for(nI=1; nI<argc;nI++)
- {
+ {
strcat(pszInputText,argv[nI]);
strcat(pszInputText," ");
}
@@ -68,6 +67,6 @@
printf("%s ", make_human_readable_str(strtoul(pS, NULL, 10), 1, 0));
}
free(pszInputText);
- printf("\n");
+ printf("\n");
exit(0);
}
=======================================
--- /trunk/package/webif/src/webif-page.c Tue May 26 05:06:22 2009
+++ /trunk/package/webif/src/webif-page.c Sun Aug 16 09:01:13 2009
@@ -49,7 +49,7 @@
#define LANG_TYPE_MAX 32 /* maximum language name size (for main) */

/* strip_next_token -
- * specialized tokenization - handles quoted strings,
+ * specialized tokenization - handles quoted strings,
* whitespace as delimiter (hard coded, todo: change) */
char *strip_next_token(char *pszSource, char *pszToken, int nTokenLen)
{
@@ -58,9 +58,9 @@
int bInLeadingWhitespace=1;
int nI;
for(nI=0;nI<nTokenLen && pszSource[nI];nI++)
- {
+ {
if(!cClosingQuote) /* if not in quoted string */
- {
+ {
switch(pszSource[nI])
{
/* if opening quote */
@@ -72,22 +72,22 @@
/* if whitespace */
case ' ':
case '\t':
- if(bInLeadingWhitespace)
+ if(bInLeadingWhitespace)
{
continue;
}
/* fall-through */
- case '\n':
+ case '\n':
pszToken[nTokenIndex]=0; /* terminate token */
- return pszSource+nI;
+ return pszSource+nI;
break;
default:
bInLeadingWhitespace=0;
- break;
- }
+ break;
+ }
}
else if(pszSource[nI]==cClosingQuote) /* if in quoted string, and ending
quote */
- {
+ {
pszToken[nTokenIndex]=0; /* terminate token */
nI++; /* advance to the next source char */
break;
@@ -95,24 +95,23 @@
pszToken[nTokenIndex]=pszSource[nI];
nTokenIndex++;
}
- pszToken[nTokenIndex]=0; /* terminate token */
+ pszToken[nTokenIndex]=0; /* terminate token */
return pszSource+nI;
}

-char *extract_lang(char *pszLine, char *pszBuffer, int nBufLen)
-{
- char *pszDelims=" \t";
+char *extract_lang(char *pszLine, char *pszBuffer, int nBufLen)
+{
char szTokenBuffer[MAX_TOKEN_SIZE];
char *pszToken=szTokenBuffer;
int nCount;
- pszLine=strip_next_token(pszLine, szTokenBuffer, MAX_TOKEN_SIZE);
+ pszLine=strip_next_token(pszLine, szTokenBuffer, MAX_TOKEN_SIZE);
for(nCount=0;pszToken[0];)
- {
- switch(nCount)
+ {
+ switch(nCount)
{
case 0:
/* if first argument is 'option' */
- if(!strcasecmp(pszToken, "option"))
+ if(!strcasecmp(pszToken, "option"))
{
nCount++;
}
@@ -124,7 +123,7 @@
break;
case 1:
/* if first non-empty argument is 'lang' */
- if(!strcasecmp(pszToken, "lang"))
+ if(!strcasecmp(pszToken, "lang"))
{
nCount++;
}
@@ -132,22 +131,22 @@
else
{
return NULL;
- }
+ }
break;
case 2:
- if(strlen(pszToken)>nBufLen)
+ if(strlen(pszToken)>nBufLen)
{
/* truncate string if can't fit in buffer */
pszToken[nBufLen-1]=0;
}
strcpy(pszBuffer,pszToken);
- return pszBuffer;
+ return pszBuffer;
}
pszLine=strip_next_token(pszLine, szTokenBuffer, MAX_TOKEN_SIZE);
- }
- return NULL;
-}
-/* lang parsing code block end
+ }
+ return NULL;
+}
+/* lang parsing code block end
**************************************************************** */

/* djb2 hash function */
@@ -158,7 +157,7 @@

while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
-
+
return hash;
}

@@ -167,14 +166,14 @@
char *name, *def, *p, *res = NULL;
lstr *i;
int h;
-
+
def = name = str;
if (((p = strchr(str, '|')) != NULL)
|| ((p = strchr(str, '#')) != NULL)) {
def = p + 1;
*p = 0;
}
-
+
h = hash(name) % HASH_MAX;
i = ltable[h];
while ((res == NULL) && (i != NULL)) {
@@ -182,10 +181,10 @@
res = i->value;
i = i->next;
}
-
+
if (res == NULL)
res = def;
-
+
return res;
}

@@ -198,7 +197,7 @@
s->name = strdup(name);
s->value = strdup(value);
s->next = NULL;
-
+
if (ltable[h] == NULL)
ltable[h] = s;
else {
@@ -233,7 +232,7 @@
l += strlen(TR_END);
}
len++;
-
+
if (len > LINE_BUF)
p = malloc(len);
else
@@ -267,7 +266,7 @@
b++; /* skip leading spaces */
if (!*b)
continue;
-
+
name = b;
if ((b = strstr(name, "=>")) == NULL)
continue; /* separator not found */
@@ -275,17 +274,17 @@
value = b + 2;
if (!*value)
continue;
-
+
*b = 0;
for (b--; isspace(*b); b--)
*b = 0; /* remove trailing spaces */
-
+
while (isspace(*value))
value++; /* skip leading spaces */

for (b = value + strlen(value) - 1; isspace(*b); b--)
*b = 0; /* remove trailing spaces */
-
+
if (!*value)
continue;

@@ -304,9 +303,8 @@
(int argc, char **argv)
{
FILE *f;
- int len, i, done;
+ int i, done;
char line[LINE_BUF], *tmp, *arg;
- glob_t langfiles;
char szLangBuffer[LANG_TYPE_MAX];
char *lang = NULL;
char *proc = "/usr/bin/haserl";
@@ -314,8 +312,7 @@

memset(ltable, 0, HASH_MAX * sizeof(lstr *));
if ((f = fopen("/etc/config/webif", "r")) != NULL) {
- int n, i;
-
+
while (!feof(f) && (lang == NULL)) {
fgets(line, LINE_BUF - 1, f);
lang=extract_lang(line, szLangBuffer, LANG_TYPE_MAX);
@@ -399,11 +396,11 @@
}

f = popen(line, "r");
-
+
while (!feof(f) && (fgets(buf, LINE_BUF - 1, f)) != NULL) {
fprintf(stdout, "%s", translate_line(buf));
fflush(stdout);
}
-
+
return 0;
}
=======================================
--- /trunk/package/webif/src/webifmetabin.c Mon Jan 22 11:28:10 2007
+++ /trunk/package/webif/src/webifmetabin.c Sun Aug 16 09:01:13 2009
@@ -1,4 +1,4 @@
-/* silly stupid meta binary stub
+/* silly stupid meta binary stub
* (c)2006 Jeremy Collake, released under GPL license. */

#include <stdio.h>
@@ -32,7 +32,7 @@
int main(int argc, char **argv)
{
int nI;
- for(nI=0; pszAppletNames[nI]; nI++)
+ for(nI=0; pszAppletNames[nI]; nI++)
{
if(strstr(argv[0], pszAppletNames[nI]))
{
@@ -42,7 +42,7 @@

printf(" ERROR: Must symlink to a supported applet.\n");
printf(" Applets supported are:\n");
- for(nI=0; pszAppletNames[nI]; nI++)
+ for(nI=0; pszAppletNames[nI]; nI++)
{
printf(" %s\n", pszAppletNames[nI]);
}
=======================================
--- /trunk/package/webif/src/wepkeygen/md5.c Wed Jun 11 05:21:28 2008
+++ /trunk/package/webif/src/wepkeygen/md5.c Sun Aug 16 09:01:13 2009
@@ -438,7 +438,7 @@
/* Process last bytes. */
if (buf != ctx->buffer) md5_hash_block(ctx->buffer, ctx);
md5_hash_block(buf, ctx);
-
+
/* Put result from CTX in first 16 bytes following RESBUF. The result is
* always in little endian byte order, so that a byte-wise output yields
* to the wanted ASCII representation of the message digest.

Reply all
Reply to author
Forward
0 new messages