From: Thomas Walker Lynch Date: Fri, 29 Mar 2019 22:54:43 +0000 (+0100) Subject: tranche-make looks to be working X-Git-Url: https://git.reasoningtechnology.com/style/static/git-favicon.png?a=commitdiff_plain;h=2d1e2aca15ecbe2871ea2fdf7dc65a4514fdda7e;p=subu tranche-make looks to be working --- diff --git a/module/da/src/da.lib.c b/module/da/src/da.lib.c index 7fa384a..f09412d 100644 --- a/module/da/src/da.lib.c +++ b/module/da/src/da.lib.c @@ -33,7 +33,7 @@ bool da_emptyq(Da *dap){ } size_t da_length(Da *dap){ - return dap->end - dap->base; + return (dap->end - dap->base)/dap->element_size; } diff --git a/module/da/src/da.lib.h b/module/da/src/da.lib.h index 189ee50..3188011 100644 --- a/module/da/src/da.lib.h +++ b/module/da/src/da.lib.h @@ -26,6 +26,7 @@ bool da_boundq(Da *dap); void da_push(Da *dap, void *element); bool da_pop(Da *dap, void *element); void da_cat(Da *dap_base, Da *dap_cat); +void da_push_string(Da *dap0, char *string); char *da_index(Da *dap, size_t i); void da_map(Da *dap, void f(void *, void *), void *closure); void da_free_elements(Da *dap); diff --git a/module/share/include/da.h b/module/share/include/da.h index 189ee50..3188011 100644 --- a/module/share/include/da.h +++ b/module/share/include/da.h @@ -26,6 +26,7 @@ bool da_boundq(Da *dap); void da_push(Da *dap, void *element); bool da_pop(Da *dap, void *element); void da_cat(Da *dap_base, Da *dap_cat); +void da_push_string(Da *dap0, char *string); char *da_index(Da *dap, size_t i); void da_map(Da *dap, void f(void *, void *), void *closure); void da_free_elements(Da *dap); diff --git a/module/share/lib/libda.a b/module/share/lib/libda.a index 49ece65..6809926 100644 Binary files a/module/share/lib/libda.a and b/module/share/lib/libda.a differ diff --git a/module/tranche/src/tranche-make.cli.c b/module/tranche/src/tranche-make.cli.c index 5286e3c..6fe480b 100644 --- a/module/tranche/src/tranche-make.cli.c +++ b/module/tranche/src/tranche-make.cli.c @@ -1,7 +1,11 @@ /* +.. don't think I need sdir, just pass src_file_path through as the source, +need to add -tdir option to the tranche call, an mod tranche to take it. +sname then becomes also becomes a path to src. + usage: - argv[0] [] [-sname ] [-sdir ] [-tdir ] [-mfile ] + argv[0] [] [-sname ] [-sdir ] [-tdir ] [-mfile ] gets the names of all the targets from the source file, then appends to the mfile a couple of lines of the form: @@ -13,27 +17,33 @@ Our makefile is typically run in the directory above where the sources are located. options - the trc file to be read + the trc file to be read -sdir prepend to in the makefile deps line that is printed -tdir prepend to each " -mfile where to send the output, defaults to stdout -sname replaces sourcename as the name to write as the source - useful for pipes -If is not provided stdin is used. +If is not provided stdin is used. If -mfile is not provided, stdout is used. -If -sdir is not provided, the directory part of the is used. If the +If -sdir is not provided, the directory part of the is used. If the user does not want this behavior, give a value of "." for -sdir. +.. should modify this to allow multiple source files on the command line .. + */ +#include +#include +#include #include #include +#include #include #include "tranche.lib.h" int main(int argc, char **argv, char **envp){ - char *source_file_path = 0; + char *src_file_path = 0; char *sname = 0; char *sdir = 0; char *tdir = 0; @@ -43,7 +53,6 @@ int main(int argc, char **argv, char **envp){ Da args; // we will queue the non option args here Da *argsp = &args; da_alloc(argsp, sizeof(char *)); - int args_cnt = 0; int err_cnt = 0; char **pt = argv; @@ -55,54 +64,57 @@ int main(int argc, char **argv, char **envp){ if(!*option){ fprintf(stderr, "Currently there is no lone '-' option.\n"); err_cnt++; - continue; + goto endif; } pt++; if(!*pt || **pt == '-'){ fprintf(stderr, "Missing value for option %s.\n", option); err_cnt++; - if(!*pt) break; - continue; + if(!*pt) break; // then nothing more to parse + goto endif; } value = *pt; if( !strcmp(option, "mfile") ){ mfile_path = value; - continue; + goto endif; } if( !strcmp(option, "sdir") ){ sdir = value; - continue; + goto endif; } if( !strcmp(option, "tdir") ){ tdir = value; - continue; + goto endif; } if( !strcmp(option, "sname") ){ sname = value; - continue; + goto endif; } fprintf(stderr, "Unrecognized option %s.", option); err_cnt++; - continue; + goto endif; } + // else clause da_push(argsp, pt); - arg_cnt++; - pt++; + endif: + pt++; } - if(!da_emptyq(argsp)) src_file_path = da_index(args, 0); + int args_cnt = da_length(argsp); + if(args_cnt > 1) src_file_path = *(char **)da_index(argsp, 1); // arg contracts - if(da_length(argsp) > 1){ - fprintf(stderr, "too many args/n"); + if(da_length(argsp) > 2){ + fprintf(stderr, "too many args\n"); err_cnt++; } - if(!src_file_name && !sname){ - fprintf(stderr, "must specify at least one eof a source_file_path or an sname/n"); + if(!src_file_path && !sname){ + fprintf(stderr, "must specify at least one eof a src_file_path or an sname\n"); err_cnt++; } if(err_cnt > 0){ - fprintf(stderr, "usage: %s [] [-sname ] [-sdir ] [-tdir ] [-mfile ]\n", argv[0]); + fprintf(stderr, "usage: %s [] [-sname ] [-sdir ] [-tdir ] [-mfile ]\n", argv[0]); return TRANCHE_ERR_ARG_PARSE; } + da_free(argsp); // this only frees the array itself, not the things it points to }// end of argument parse @@ -114,19 +126,19 @@ int main(int argc, char **argv, char **envp){ else src_file = fopen(src_file_path, "r"); - if(mfile_path == "") - mfile_fd = STDOUT_FILENO; + if(mfile_path) + mfile_fd = open(mfile_path, O_WRONLY | O_APPEND | O_CREAT, 0666); else - mfile_fd = open(file_name, O_WRONLY | O_APPEND | O_CREAT, 0666); + mfile_fd = STDOUT_FILENO; int err = 0; if(!src_file){ fprintf(stderr,"could not open tranche source file %s\n", src_file_path); - err+= ERR_SRC_OPEN; + err+= TRANCHE_ERR_SRC_OPEN; } if(mfile_fd == -1){ fprintf(stderr, "Could not open the dep file %s\n", mfile_path); - err+= ERR_DST_OPEN; + err+= TRANCHE_ERR_DST_OPEN; } if(err) return err; } @@ -141,14 +153,13 @@ int main(int argc, char **argv, char **envp){ tranche_make(src_file, sname, mfile_fd, sdir, tdir); { // deallocate resources instead of just existing, so as to catch any errors - da_free(argsp); int err_cnt = 0; if(src_file != stdin) - if( !fclose(src_file) ){perror(); err_cnt++;} + if( fclose(src_file) ){perror(NULL); err_cnt++;} if(mfile_fd != STDOUT_FILENO) - if( close(mfile_fd) == -1 ){perror(); err_cnt++;} + if( close(mfile_fd) == -1 ){perror(NULL); err_cnt++;} if( err_cnt ) - return TRANCHE_ERR_CLOSE; + return TRANCHE_ERR_FCLOSE; else return 0; } diff --git a/module/tranche/src/tranche.cli.c b/module/tranche/src/tranche.cli.c index 97fe653..1e6ee60 100644 --- a/module/tranche/src/tranche.cli.c +++ b/module/tranche/src/tranche.cli.c @@ -28,7 +28,7 @@ the same file as one already open in the containing tranche .. int main(int argc, char **argv, char **envp){ if(argc != 2){ fprintf(stderr, "usage: %s \n",argv[0]); - return TRANCHE_ERR_ARGC; + return TRANCHE_ERR_ARG_PARSE; } FILE *file = fopen(argv[1], "r"); if(!file){ diff --git a/module/tranche/src/tranche.lib.c b/module/tranche/src/tranche.lib.c index 455c6d7..b27aaa6 100644 --- a/module/tranche/src/tranche.lib.c +++ b/module/tranche/src/tranche.lib.c @@ -190,7 +190,7 @@ int tranche_target(FILE *src, Da *target_arrp){ // Inserts a zero to chop off the filename similar to the old basename. // Returns a pointer to the first character after the inserted zero, i.e. to the filename. char *path_chop(char *path){ - file = path + strlen(path); + char *file = path + strlen(path); if(file == path) return file; file--; if(file == path){ @@ -216,10 +216,10 @@ char *path_chop(char *path){ void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *sdir, char *tdir){ // target list - Da tarr; - Da *tarrp; // target array pointer - da_alloc(tarrp, sizeof(char *)); - tranche_target(src_file, tarrp); + Da ta; + Da *tap=&ta; // target array pointer + da_alloc(tap, sizeof(char *)); + tranche_target(src_file, tap); char sp = ' '; char colon = ':'; @@ -229,41 +229,39 @@ void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *sdir, char char terminator = 0; // output the dependency line ---------------------------------------- - Da dlarr; - Da *dlarrp; // dependency line array pointer - da_alloc(dlarrp, sizeof(char)); - char *pt = tarrp->base; // char * because it points to a byte in the array - while( pt < tarrp->end ){ + Da dla; + Da *dlap=&dla; // dependency line array pointer + da_alloc(dlap, sizeof(char)); + char *pt = tap->base; // char * because it points to a byte in the array + while( pt < tap->end ){ if(tdir){ - da_push_string(dlarrp, tdir); - da_push(dlarrp, &slash); + da_push_string(dlap, tdir); + da_push(dlap, &slash); } - da_push_string(dlarrp, *(char **)pt); - da_push(dlarrp, &sp); - pt += dap->element_size; + da_push_string(dlap, *(char **)pt); + da_push(dlap, &sp); + pt += tap->element_size; } - da_push(dlarrp, &colon); - da_push(dlarrp, &sp); + da_push(dlap, &colon); + da_push(dlap, &sp); if(sdir){ - da_push_string(dlarrp, sdir); - da_push(dlarrp, &slash); + da_push_string(dlap, sdir); + da_push(dlap, &slash); } - da_push_string(dlarrp, src_name); - da_push(dlarrp, &newline); - da_push(dlarrp, &terminator); - write(mfile_fd, dlarrp->base, dlarrp->end - dlarrp->base); - da_free_elements(tarrp); - da_free(tarrp); + da_push_string(dlap, src_name); + da_push(dlap, &newline); + write(mfile_fd, dlap->base, dlap->end - dlap->base); + da_free_elements(tap); + da_free(tap); // output acction line ---------------------------------------- - da_rewind(dlarrp); // reuse the line buffer - da_push(dlarrp, &tab); - da_push_string(dlarrp, "tranche $<"); - da_push(dlarrp, &newline); - da_push(dlarrp, &newline); - da_push(dlarrp, &terminator); - write(mfile_fd, dlarrp->base, dlarrp->end - dlarrp->base); - da_free(dlarrp); + da_rewind(dlap); // reuse the line buffer + da_push(dlap, &tab); + da_push_string(dlap, "tranche $<"); + da_push(dlap, &newline); + da_push(dlap, &newline); + write(mfile_fd, dlap->base, dlap->end - dlap->base); + da_free(dlap); return; } diff --git a/module/tranche/test/try/test2stdout.dat b/module/tranche/test/try/test2stdout.dat new file mode 100644 index 0000000..139597f --- /dev/null +++ b/module/tranche/test/try/test2stdout.dat @@ -0,0 +1,2 @@ + + diff --git a/module/tranche/test/try/tranche-make b/module/tranche/test/try/tranche-make new file mode 120000 index 0000000..b3adcec --- /dev/null +++ b/module/tranche/test/try/tranche-make @@ -0,0 +1 @@ +../../exec/tranche-make \ No newline at end of file diff --git a/tool/bin/tranche b/tool/bin/tranche index eb63c28..b105ce0 100755 Binary files a/tool/bin/tranche and b/tool/bin/tranche differ diff --git a/tool/bin/tranche-make b/tool/bin/tranche-make new file mode 100755 index 0000000..3330f46 Binary files /dev/null and b/tool/bin/tranche-make differ diff --git a/tool/bin/tranche-target b/tool/bin/tranche-target new file mode 100755 index 0000000..e9fd5ff Binary files /dev/null and b/tool/bin/tranche-target differ