Changeset 5674
- Timestamp:
- 02/24/10 13:02:56 (3 years ago)
- Location:
- luci2/cbi2
- Files:
-
- 3 added
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
luci2/cbi2/cbi.c
r5673 r5674 12 12 #include <libgen.h> 13 13 14 #include "lucic.h" 14 15 #include "list.h" 15 16 #include "blob.h" … … 589 590 for(i = 0; i < gl.gl_pathc; i++) 590 591 { 591 char buf[256];592 592 char *out = strdup(gl.gl_pathv[i]); 593 593 out[strlen(out) - 1] = 'o'; 594 snprintf(buf, 255, "./lucic %s %s", gl.gl_pathv[i], out);595 buf[255] = '\0';596 594 printf("compiling %s -> %s\n", gl.gl_pathv[i], out); 597 if(! system(buf))595 if(!lucic_main(gl.gl_pathv[i], out)) 598 596 { 599 597 printf("deleting %s\n", gl.gl_pathv[i]); -
luci2/cbi2/luci.c
r5664 r5674 7 7 #include <unistd.h> 8 8 #include <signal.h> 9 #include <libgen.h> 9 10 #include <sys/types.h> 10 11 #include <sys/stat.h> 11 12 #include <sys/mman.h> 12 13 14 #define _GNU_SOURCE 15 #include <getopt.h> 16 13 17 #include "cbi.h" 18 #include "u_sock.h" 19 #include "lucic.h" 14 20 15 21 static int loop = 1; … … 31 37 sigaction(SIGTERM, &s2, NULL); 32 38 } 39 40 int print_help(void) 41 { 42 printf("luci2 - cbi daemon\n"); 43 printf(" -h,-?\t\t- print this help\n"); 44 printf(" -s\t\t- open /tmp/luci2-socket for json testing\n"); 45 printf(" -d\t\t- daemonize\n"); 46 printf(" -v\t\t- use current folder as virtual root\n"); 47 printf(" -b in.luco\t- dump the content of a blob\n"); 48 printf(" -c in.luci\t- compile luci file\n"); 49 printf(" -u in.uvl\t- compile uvl file\n"); 50 printf(" -o out.luco\t- write compiled output to file\n"); 51 return 0; 52 } 53 33 54 int main(int argc, char **argv) 34 55 { 35 struct cbi_ctx *ctx = cbi_load(); 56 int opt; 57 struct cbi_ctx *ctx; 58 int compile = 0; 59 char *c_file = 0; 60 int output = 0; 61 char *o_file = 0; 62 int daemonize = 0; 63 int sock = 0; 64 int blob; 65 char *b_file; 66 int uvl = 0; 67 char *u_file = 0; 68 int vroot = 0; 69 const char *vpath = 0; 70 71 while((opt = getopt(argc, argv, "h?sdvc:o:u:b:")) != -1) 72 { 73 switch(opt) 74 { 75 case '?': 76 case 'h': 77 return print_help(); 78 case 's': 79 sock = 1; 80 break; 81 case 'd': 82 daemonize = 1; 83 break; 84 case 'c': 85 compile = 1; 86 c_file = optarg; 87 break; 88 case 'b': 89 blob = 1; 90 b_file = optarg; 91 break; 92 case 'o': 93 output = 1; 94 o_file = optarg; 95 break; 96 case 'u': 97 uvl = 1; 98 u_file = optarg; 99 break; 100 case 'v': 101 vroot = 1; 102 break; 103 default: 104 printf("unhandled parameter %c\n", opt); 105 break; 106 } 107 } 108 109 if(compile) 110 return lucic_main(c_file, o_file); 111 112 if(blob) 113 // return cbi_dump_blob(b_file); 114 return 0; 115 116 if(uvl) 117 { 118 printf("todo when lua is added\n"); 119 return 1; 120 } 121 122 if(vroot) 123 { 124 vpath = dirname(*argv); 125 printf("using %s as virtual root\n", vpath); 126 } 127 128 if(daemonize) 129 daemon(0,0); 130 131 ctx = cbi_load(); 36 132 37 133 cbi_dump(ctx); 38 134 setup_signals(); 135 if(sock) 136 u_sock_init(); 39 137 while(loop) 40 138 { 41 sleep(1); 139 if(sock) 140 u_sock_poll(); 141 else 142 sleep(1); 42 143 cbi_reindex(ctx); 43 144 } -
luci2/cbi2/lucic.c
r5664 r5674 9 9 10 10 #include "lucip.h" 11 12 void lucip_blob_dump(const char *path, struct blob_buf *bbuf) 13 { 14 if(path) 15 { 16 int fd = open(path, O_CREAT|O_WRONLY, 0644); 17 if (fd < 0) 18 perror("Cannot open output file"); 19 write(fd, bbuf->buf, blob_pad_len(bbuf->buf)); 20 close(fd); 21 } 22 } 11 #include "lucic.h" 23 12 24 13 static bool … … 34 23 }; 35 24 36 void print_usage(void)25 int lucic_main(const char *in, const char *out) 37 26 { 38 printf("lucic <infile> <outfile>\n"); 39 exit(-1); 40 } 41 42 int main(int argc, char **argv) 43 { 44 if(argc != 3) 45 print_usage(); 46 if(!lucip_load(argv[1], &bbuf)) 47 lucip_blob_dump(argv[2], &bbuf); 48 else 49 return printf("error opening %s\n", argv[1]); 27 if(!lucip_load(in, &bbuf)) 28 { 29 printf("Ok!\n"); 30 if(out) 31 lucip_blob_dump(out, &bbuf); 32 else 33 printf("use -o to save luco file\n"); 34 } else { 35 printf("error opening/compiling %s\n", in); 36 return 1; 37 } 50 38 return 0; 51 39 } -
luci2/cbi2/lucip.c
r5672 r5674 196 196 if(*l->last) 197 197 { 198 //struct lucip_tag *t;199 198 if(!l->stackcount) 200 199 return lucip_fail(l, OUTSIDE_TAG); … … 350 349 } 351 350 351 void lucip_blob_dump(const char *path, struct blob_buf *bbuf) 352 { 353 if(path) 354 { 355 int fd = open(path, O_CREAT|O_WRONLY, 0644); 356 if (fd < 0) 357 perror("Cannot open output file"); 358 write(fd, bbuf->buf, blob_pad_len(bbuf->buf)); 359 close(fd); 360 } 361 } -
luci2/cbi2/lucip.h
r5664 r5674 60 60 61 61 int lucip_load(const char *path, struct blob_buf *bbuf); 62 void lucip_blob_dump(const char *path, struct blob_buf *bbuf); 62 63 63 64 #endif -
luci2/cbi2/Makefile
r5673 r5674 4 4 LDFLAGS?= 5 5 LIBS=-llua5.1 6 BINARY=luci c luciuvl uvlc liblmo.a lmo_po2lmo6 BINARY=luci uvl uvlc liblmo.a lmo_po2lmo 7 7 8 8 all: $(BINARY) 9 9 10 lucic: lucic.c lucip.c blob.c 11 $(CC) $(CFLAGS) -o $@ $^ 12 13 luci: luci.c cbi.c validate.c uvl.c blob.c widget.c validator/boolean.c widgets/page.c widgets/form.c widgets/section.c widgets/option.c widgets/field.c widgets/foreach.c widgets/file.c widgets/tsection.c 10 luci: luci.c lucic.c lucip.c cbi.c u_sock.c validate.c uvl.c blob.c widget.c validator/boolean.c widgets/page.c widgets/form.c widgets/section.c widgets/option.c widgets/field.c widgets/foreach.c widgets/file.c widgets/tsection.c 14 11 $(CC) $(CFLAGS) -o $@ $^ 15 12
