Xv6 with picoc & Linkage editor
v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
|
00001 #include "types.h" 00002 #include "stat.h" 00003 #include "user.h" 00004 00005 char buf[512]; 00006 00007 void 00008 wc(int fd, char *name) 00009 { 00010 int i, n; 00011 int l, w, c, inword; 00012 00013 l = w = c = 0; 00014 inword = 0; 00015 while((n = read(fd, buf, sizeof(buf))) > 0){ 00016 for(i=0; i<n; i++){ 00017 c++; 00018 if(buf[i] == '\n') 00019 l++; 00020 if(strchr(" \r\t\n\v", buf[i])) 00021 inword = 0; 00022 else if(!inword){ 00023 w++; 00024 inword = 1; 00025 } 00026 } 00027 } 00028 if(n < 0){ 00029 printf( "wc: read error\n"); 00030 exit(1); 00031 } 00032 printf( "%d %d %d %s\n", l, w, c, name); 00033 } 00034 00035 int 00036 main(int argc, char *argv[]) 00037 { 00038 int fd, i; 00039 00040 if(argc <= 1){ 00041 wc(0, ""); 00042 exit(1); 00043 } 00044 00045 for(i = 1; i < argc; i++){ 00046 if((fd = open(argv[i], 0)) < 0){ 00047 printf( "cat: cannot open %s\n", argv[i]); 00048 exit(1); 00049 } 00050 wc(fd, argv[i]); 00051 close(fd); 00052 } 00053 exit(1); 00054 }