[svn-commits] file: trunk r1459 - in /trunk: ./ wct4xxp/fw2h.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Sep 9 12:31:45 MST 2006


Author: file
Date: Sat Sep  9 14:31:45 2006
New Revision: 1459

URL: http://svn.digium.com/view/zaptel?rev=3D1459&view=3Drev
Log:
Merged revisions 1458 via svnmerge from =

https://origsvn.digium.com/svn/zaptel/branches/1.2

........
r1458 | file | 2006-09-09 15:29:31 -0400 (Sat, 09 Sep 2006) | 2 lines

Update firmware header generation tool to support paths being supplied with=
 the filename (reported internally by Spiceland)

........

Modified:
    trunk/   (props changed)
    trunk/wct4xxp/fw2h.c

Propchange: trunk/
---------------------------------------------------------------------------=
---
Binary property 'branch-1.2-merged' - no diff available.

Modified: trunk/wct4xxp/fw2h.c
URL: http://svn.digium.com/view/zaptel/trunk/wct4xxp/fw2h.c?rev=3D1459&r1=
=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/wct4xxp/fw2h.c (original)
+++ trunk/wct4xxp/fw2h.c Sat Sep  9 14:31:45 2006
@@ -4,31 +4,46 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+
 int main(int argc, char *argv[])
 {
-	char *c;
-	int fd;
-	FILE *f;
-	int res;
-	int x;
+	char *c =3D NULL, *fw_hdr_name =3D NULL;
+	int fd, res, x;
+	FILE *f =3D NULL;
 	unsigned char buf[1024];
+
+	/* Make sure we have the right amount of arguments */
 	if (argc !=3D 3) {
-		fprintf(stderr, "Usage: fw2h <infile> <outfile>");
+		fprintf(stderr, "Usage: fw2h <infile> <outfile>\n");
 		exit(1);
 	}
-	fd =3D open(argv[1], O_RDONLY);
-	if (fd < 0) {
+
+	/* Make sure we can open the firmware in file */
+	if ((fd =3D open(argv[1], O_RDONLY)) < 0) {
 		fprintf(stderr, "Unable to open '%s': %s\n", argv[1], strerror(errno));
 		exit(1);
 	}
-	f =3D fopen(argv[2], "w+");
-	if (!f) {
+
+	/* Make sure we can write out the firmware header file */
+	if (!(f =3D fopen(argv[2], "w+"))) {
 		fprintf(stderr, "Unable to open '%s' for writing: %s\n", argv[2], strerr=
or(errno));
 		exit(1);
 	}
+
+	/* Strip file extension */
 	c =3D strrchr(argv[2], '.');
-	if (c) *c =3D '\0';
-	fprintf(f, "static unsigned char %s[] =3D {\t", argv[2]);
+	if (c)
+		*c =3D '\0';
+
+	/* Now determine the firmware header name */
+	c =3D strrchr(argv[2], '/');
+	if (c)
+		fw_hdr_name =3D ++c;
+	else
+		fw_hdr_name =3D argv[2];
+
+	/* Write out the firmware as a header file */
+	fprintf(f, "static unsigned char %s[] =3D {\t", fw_hdr_name);
 	while ((res =3D read(fd, buf, sizeof(buf))) > 0) {
 		for (x =3D 0; x < res; x++) {
 			if (!(x % 16))
@@ -37,10 +52,12 @@
 		}
 	}
 	fprintf(f, "\n};\n");
+
 	if (res < 0) {
 		fprintf(stderr, "Error reading file: %s\n", strerror(errno));
 		exit(1);
 	}
+
 	fclose(f);
 	close(fd);
 	exit(0);



More information about the svn-commits mailing list