Fix coding style of util/lar/*.[ch] by running:

indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs *.[ch]

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@142 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Stefan Reinauer 2007-02-27 13:00:22 +00:00
commit 86d6551987
7 changed files with 160 additions and 170 deletions

View file

@ -43,49 +43,48 @@ int create_lar(int argc, char *argv[])
u32 *walk;
u32 csum;
int pathlen, entrylen, filelen;
struct lar_header *header;
struct lar_header *header;
struct stat statbuf;
archivename=argv[2];
if (argc<=3) {
archivename = argv[2];
if (argc <= 3) {
printf("No files for archive %s\n", archivename);
exit(1);
}
printf("Opening %s\n", archivename);
archive=fopen(archivename, "w");
if(!archive) {
// error
archive = fopen(archivename, "w");
if (!archive) {
// error
exit(1);
}
for (i=3; i<argc; i++) {
for (i = 3; i < argc; i++) {
printf(" Adding %s to archive\n", argv[i]);
ret=stat(argv[i], &statbuf);
if(ret) {
ret = stat(argv[i], &statbuf);
if (ret) {
printf(" no such file %s\n", argv[i]);
exit(1);
}
filelen=statbuf.st_size;
filelen = statbuf.st_size;
tempmem=malloc(sizeof(struct lar_header)+MAX_PATHLEN+filelen+16);
if(!tempmem) {
printf ("no memory\n");
tempmem = malloc(sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16);
if (!tempmem) {
printf("no memory\n");
return (1);
}
memset(tempmem, 0, sizeof(struct lar_header)+MAX_PATHLEN+filelen+16);
memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16);
header=(struct lar_header *)tempmem;
pathname=tempmem+sizeof(struct lar_header);
pathlen=sprintf(pathname, argv[i])+1;
pathlen = (pathlen+15)&0xfffffff0; // align it to 16 bytes
header = (struct lar_header *)tempmem;
pathname = tempmem + sizeof(struct lar_header);
pathlen = sprintf(pathname, argv[i]) + 1;
pathlen = (pathlen + 15) & 0xfffffff0; // align it to 16 bytes
/* read file into memory */
filebuf=pathname+pathlen;
source=fopen(argv[i], "r");
if(!source) {
filebuf = pathname + pathlen;
source = fopen(argv[i], "r");
if (!source) {
printf(" no such file %s\n", argv[i]);
exit(1);
}
@ -94,20 +93,20 @@ int create_lar(int argc, char *argv[])
/* create correct header */
memcpy(header, MAGIC, 8);
header->len=htonl(statbuf.st_size);
header->offset=htonl(sizeof(struct lar_header)+pathlen);
header->len = htonl(statbuf.st_size);
header->offset = htonl(sizeof(struct lar_header) + pathlen);
/* calculate checksum */
csum=0;
for (walk=(u32 *)tempmem;
walk<(u32 *)(tempmem+ statbuf.st_size+sizeof(struct lar_header)+pathlen);
walk++) {
csum+=ntohl(*walk);
csum = 0;
for (walk = (u32 *) tempmem;
walk < (u32 *) (tempmem + statbuf.st_size +
sizeof(struct lar_header) + pathlen); walk++) {
csum += ntohl(*walk);
}
header->checksum=htonl(csum);
header->checksum = htonl(csum);
/* write out entry to archive */
entrylen=(filelen+pathlen+sizeof(struct lar_header)+15) & 0xfffffff0;
entrylen = (filelen + pathlen + sizeof(struct lar_header) + 15) & 0xfffffff0;
fwrite(tempmem, entrylen, 1, archive);
@ -120,5 +119,3 @@ int create_lar(int argc, char *argv[])
return 0;
}

View file

@ -40,76 +40,75 @@ struct mem_file {
int find_file(struct mem_file *archive, char *filename, struct mem_file *result)
{
char * walk, *fullname;
struct lar_header * header;
for (walk = archive->start; walk < archive->start +
archive->len; walk+=16) {
char *walk, *fullname;
struct lar_header *header;
if(strcmp(walk, MAGIC)!=0)
for (walk = archive->start; walk < archive->start +
archive->len; walk += 16) {
if (strcmp(walk, MAGIC) != 0)
continue;
header=(struct lar_header *)walk;
fullname=walk+sizeof(struct lar_header);
header = (struct lar_header *)walk;
fullname = walk + sizeof(struct lar_header);
// FIXME: check checksum
if(strcmp(fullname, filename)!=0) {
result->start=walk + ntohl(header->offset);
result->len=ntohl(header->len);
if (strcmp(fullname, filename) != 0) {
result->start = walk + ntohl(header->offset);
result->len = ntohl(header->len);
return 0;
}
// skip file
walk += ( ntohl(header->offset) + ntohl(header->len)
+ 15 ) & 0xfffffff0;
walk += (ntohl(header->offset) + ntohl(header->len)
+ 15) & 0xfffffff0;
}
return 1;
}
int main(int argc, char *argv[])
{
int fd, ret;
struct stat statbuf;
struct mem_file archive, result;
if (argc!=2) {
if (argc != 2) {
printf("Usage: example archive.lar\n");
exit(0);
}
if (stat(argv[1], &statbuf)!=0) {
printf("Error opening %s: %s\n",
argv[1], strerror(errno));
if (stat(argv[1], &statbuf) != 0) {
printf("Error opening %s: %s\n", argv[1], strerror(errno));
exit(1);
}
printf("Opening %s\n", argv[1]);
fd=open(argv[1], O_RDONLY);
if (fd==-1) {
printf("Error while opening %s: %s\n",
argv[1], strerror(errno));
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
printf("Error while opening %s: %s\n",
argv[1], strerror(errno));
exit(1);
}
archive.len=statbuf.st_size;
archive.len = statbuf.st_size;
archive.start=mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, fd, 0);
archive.start = mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, fd, 0);
/* OS stuff ends here */
/* ------------------------------------------------- */
// find first compressor
ret=find_file(&archive, "compression/", &result);
if(!ret) printf("file found.\n");
else printf("file not found.\n");
ret=find_file(&archive, "normal/initram", &result);
if(!ret) printf("file found.\n");
else printf("file not found.\n");
ret = find_file(&archive, "compression/", &result);
if (!ret)
printf("file found.\n");
else
printf("file not found.\n");
ret = find_file(&archive, "normal/initram", &result);
if (!ret)
printf("file found.\n");
else
printf("file not found.\n");
/* ------------------------------------------------- */
/* OS stuff starts again here */
@ -118,5 +117,3 @@ int main(int argc, char *argv[])
return 0;
}

View file

@ -35,84 +35,82 @@
int extract_lar(int argc, char *argv[])
{
int archivefile;
char * archivename;
char * inmap;
char * walk;
char *archivename;
char *inmap;
char *walk;
char *fullname, *pathname, *pos;
struct lar_header * header;
struct lar_header *header;
struct stat statbuf;
int archivelen;
int do_extract;
int i;
archivename=argv[2];
archivename = argv[2];
if (stat(archivename, &statbuf)!=0) {
printf("Error opening %s: %s\n",
archivename, strerror(errno));
if (stat(archivename, &statbuf) != 0) {
printf("Error opening %s: %s\n", archivename, strerror(errno));
exit(1);
}
printf("Opening %s\n", archivename);
archivefile=open(archivename, O_RDONLY);
if (archivefile==-1) {
printf("Error while opening %s: %s\n",
archivename, strerror(errno));
archivefile = open(archivename, O_RDONLY);
if (archivefile == -1) {
printf("Error while opening %s: %s\n",
archivename, strerror(errno));
exit(1);
}
archivelen=statbuf.st_size;
archivelen = statbuf.st_size;
inmap=mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, archivefile, 0);
inmap = mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, archivefile, 0);
for (walk=inmap; walk<inmap+statbuf.st_size; walk+=16) {
FILE * file_to_extract;
for (walk = inmap; walk < inmap + statbuf.st_size; walk += 16) {
FILE *file_to_extract;
if(strcmp(walk, MAGIC)!=0)
if (strcmp(walk, MAGIC) != 0)
continue;
header=(struct lar_header *)walk;
fullname=walk+sizeof(struct lar_header);
header = (struct lar_header *)walk;
fullname = walk + sizeof(struct lar_header);
// FIXME: check checksum
do_extract=1;
if(argc>3) {
do_extract=0;
for (i=3; i<argc; i++) {
if(strcmp(fullname, argv[i])==0) {
do_extract=1;
do_extract = 1;
if (argc > 3) {
do_extract = 0;
for (i = 3; i < argc; i++) {
if (strcmp(fullname, argv[i]) == 0) {
do_extract = 1;
break;
}
}
}
// dont extract this one, skip it.
if(!do_extract)
if (!do_extract)
continue;
printf(" Extracting file %s\n", walk+sizeof(struct lar_header));
printf(" Extracting file %s\n",
walk + sizeof(struct lar_header));
// Create the directory if it does not exist.
pathname=strdup(fullname);
pos=strrchr(pathname, '/');
if(pos) {
pos[1]=0;
pathname = strdup(fullname);
pos = strrchr(pathname, '/');
if (pos) {
pos[1] = 0;
//printf("pathname %s\n",pathname);
mkdirp(pathname);
}
free(pathname);
file_to_extract=fopen(fullname, "w");
if(!file_to_extract) {
file_to_extract = fopen(fullname, "w");
if (!file_to_extract) {
printf("error creating file.\n");
exit(1);
}
//printf("starting offs=%d, len=%d\n", ntohl(header->offset),
// ntohl(header->len));
fwrite(walk+ntohl(header->offset), ntohl(header->len),
1, file_to_extract);
// ntohl(header->len));
fwrite(walk + ntohl(header->offset), ntohl(header->len),
1, file_to_extract);
fclose(file_to_extract);
}
munmap(inmap, statbuf.st_size);
@ -121,5 +119,3 @@ int extract_lar(int argc, char *argv[])
return 0;
}

View file

@ -36,17 +36,17 @@
int main(int argc, char *argv[])
{
if (argc<2) {
if (argc < 2) {
printf("Usage: lar [cxl] archive.lar <files>\n");
exit(0);
}
if (strcmp(argv[1], "x")==0)
if (strcmp(argv[1], "x") == 0)
extract_lar(argc, argv);
else if (strcmp(argv[1], "c")==0)
create_lar(argc,argv);
else if (strcmp(argv[1], "l")==0)
list_lar(argc,argv);
else if (strcmp(argv[1], "c") == 0)
create_lar(argc, argv);
else if (strcmp(argv[1], "l") == 0)
list_lar(argc, argv);
else {
printf("mode must be c or x\n");
exit(1);

View file

@ -33,5 +33,3 @@ struct lar_header {
u32 checksum;
u32 offset;
};

View file

@ -30,27 +30,29 @@ int mkdirp(char *dirpath)
#define MAX_PATH 1024
char *pos, *currpath, *path;
char cwd[MAX_PATH];
int ret=0;
int ret = 0;
path = strdup(dirpath);
currpath = path;
if(!getcwd(cwd, MAX_PATH)) {
if (!getcwd(cwd, MAX_PATH)) {
free(path);
printf("error getting cwd\n");
return -1;
}
do {
pos=index(currpath,'/');
if (pos)*pos=0;
pos = index(currpath, '/');
if (pos)
*pos = 0;
//printf("cp=%s\n",currpath);
mkdir(currpath,0755);
ret=chdir(currpath);
if(pos) currpath=pos+1;
} while (pos && !ret && strlen(currpath)) ;
mkdir(currpath, 0755);
ret = chdir(currpath);
if (pos)
currpath = pos + 1;
} while (pos && !ret && strlen(currpath));
chdir(cwd);
free(path);
@ -59,14 +61,19 @@ int mkdirp(char *dirpath)
}
#if 0
int main(void) {
int main(void)
{
int ret;
ret=mkdirp("a/b/c/d/");
if (ret) printf("error! mkdir\n\n");
else printf("jippie! mkdir\n\n");
ret=mkdirp("a/b/c/d");
if (ret) printf("error! mkdir\n");
else printf("jippie! mkdir\n");
ret = mkdirp("a/b/c/d/");
if (ret)
printf("error! mkdir\n\n");
else
printf("jippie! mkdir\n\n");
ret = mkdirp("a/b/c/d");
if (ret)
printf("error! mkdir\n");
else
printf("jippie! mkdir\n");
return 0;
}

View file

@ -35,63 +35,60 @@
int list_lar(int argc, char *argv[])
{
int archivefile;
char * archivename;
char * inmap;
char * walk;
char *archivename;
char *inmap;
char *walk;
char *fullname;
struct lar_header * header;
struct lar_header *header;
struct stat statbuf;
int archivelen;
int do_extract;
int i;
archivename=argv[2];
archivename = argv[2];
if (stat(archivename, &statbuf)!=0) {
printf("Error opening %s: %s\n",
archivename, strerror(errno));
if (stat(archivename, &statbuf) != 0) {
printf("Error opening %s: %s\n", archivename, strerror(errno));
exit(1);
}
printf("Opening %s\n", archivename);
archivefile=open(archivename, O_RDONLY);
if (archivefile==-1) {
printf("Error while opening %s: %s\n",
archivename, strerror(errno));
archivefile = open(archivename, O_RDONLY);
if (archivefile == -1) {
printf("Error while opening %s: %s\n",
archivename, strerror(errno));
exit(1);
}
archivelen=statbuf.st_size;
archivelen = statbuf.st_size;
inmap=mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, archivefile, 0);
inmap = mmap(NULL, statbuf.st_size, PROT_READ,
MAP_SHARED, archivefile, 0);
for (walk=inmap; walk<inmap+statbuf.st_size; walk+=16) {
if(strcmp(walk, MAGIC)!=0)
for (walk = inmap; walk < inmap + statbuf.st_size; walk += 16) {
if (strcmp(walk, MAGIC) != 0)
continue;
header=(struct lar_header *)walk;
fullname=walk+sizeof(struct lar_header);
do_extract=1;
if(argc>3) {
do_extract=0;
for (i=3; i<argc; i++) {
if(strcmp(fullname, argv[i])==0) {
do_extract=1;
header = (struct lar_header *)walk;
fullname = walk + sizeof(struct lar_header);
do_extract = 1;
if (argc > 3) {
do_extract = 0;
for (i = 3; i < argc; i++) {
if (strcmp(fullname, argv[i]) == 0) {
do_extract = 1;
break;
}
}
}
// dont extract this one, skip it.
if(!do_extract)
if (!do_extract)
continue;
printf(" %s ", walk+sizeof(struct lar_header));
printf(" %s ", walk + sizeof(struct lar_header));
printf("(%d bytes @0x%x)\n", ntohl(header->len),
(walk-inmap)+ntohl(header->offset));
(walk - inmap) + ntohl(header->offset));
}
munmap(inmap, statbuf.st_size);
close(archivefile);
@ -99,5 +96,3 @@ int list_lar(int argc, char *argv[])
return 0;
}