From 86d655198719e4f180a710b5b5af9033bd677b73 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Tue, 27 Feb 2007 13:00:22 +0000 Subject: [PATCH] Fix coding style of util/lar/*.[ch] by running: indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs *.[ch] Signed-off-by: Uwe Hermann Acked-by: Uwe Hermann Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@142 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- util/lar/create.c | 63 +++++++++++++++++------------------- util/lar/example.c | 71 ++++++++++++++++++++-------------------- util/lar/extract.c | 80 ++++++++++++++++++++++------------------------ util/lar/lar.c | 12 +++---- util/lar/lar.h | 2 -- util/lar/lib.c | 39 ++++++++++++---------- util/lar/list.c | 61 ++++++++++++++++------------------- 7 files changed, 159 insertions(+), 169 deletions(-) diff --git a/util/lar/create.c b/util/lar/create.c index cab36126eb..b8958cc046 100644 --- a/util/lar/create.c +++ b/util/lar/create.c @@ -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; ilen=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; } - - diff --git a/util/lar/example.c b/util/lar/example.c index 5b1df34e91..d4b6d25f35 100644 --- a/util/lar/example.c +++ b/util/lar/example.c @@ -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; } - - diff --git a/util/lar/extract.c b/util/lar/extract.c index 0ad37067d7..fc59d11e4c 100644 --- a/util/lar/extract.c +++ b/util/lar/extract.c @@ -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; walk3) { - do_extract=0; - for (i=3; i 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; } - - diff --git a/util/lar/lar.c b/util/lar/lar.c index 58a9a829ea..ba926fcfde 100644 --- a/util/lar/lar.c +++ b/util/lar/lar.c @@ -36,17 +36,17 @@ int main(int argc, char *argv[]) { - if (argc<2) { + if (argc < 2) { printf("Usage: lar [cxl] archive.lar \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); diff --git a/util/lar/lar.h b/util/lar/lar.h index 3fdf5ae2ac..cafdd4aac8 100644 --- a/util/lar/lar.h +++ b/util/lar/lar.h @@ -33,5 +33,3 @@ struct lar_header { u32 checksum; u32 offset; }; - - diff --git a/util/lar/lib.c b/util/lar/lib.c index 6b4baa7a58..ba6b53d7e6 100644 --- a/util/lar/lib.c +++ b/util/lar/lib.c @@ -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; } diff --git a/util/lar/list.c b/util/lar/list.c index 5ea091bad2..3e0794538d 100644 --- a/util/lar/list.c +++ b/util/lar/list.c @@ -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; walk3) { - do_extract=0; - for (i=3; i 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; } - -