summaryrefslogtreecommitdiffstats
path: root/system_part.c
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-10-01 14:05:00 +0300
committerGalin Simeonov <gts@volconst.com>2021-10-01 14:05:00 +0300
commit6a8bbbf82e21d90ef3609aae5046aef54024b5e0 (patch)
treeb161f1d3b556295807cb5e8388e72bc9441ce25b /system_part.c
parentf66d8e2562ec885c29a578956bf092a1e48cd9da (diff)
downloadvolgit-6a8bbbf82e21d90ef3609aae5046aef54024b5e0.tar.gz
Added tree like output
Diffstat (limited to 'system_part.c')
-rw-r--r--system_part.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/system_part.c b/system_part.c
index 0c162b2..6d5f963 100644
--- a/system_part.c
+++ b/system_part.c
@@ -5,7 +5,7 @@
const char *const default_header="<!DOCTYPE html><html><head><title>GIT</title></head><body>";
const char *const default_footer="</body></html>";
-struct Volgit_Options options
+struct Volgit_State state
=
{
.input_path=NULL,
@@ -52,36 +52,38 @@ void parse_options(int argc,char **argv)
{
i=get_next_option_or_die(i,argc,"expected a file name after --output flag\n");
- options.output_path=argv[i];
- options.output_dir_fd=open(options.output_path,O_RDONLY|O_DIRECTORY);
+ state.output_path=argv[i];
+ state.output_dir_fd=open(state.output_path,O_RDONLY|O_DIRECTORY);
- if(options.output_dir_fd==-1)
+ if(state.output_dir_fd==-1)
{
- mkdir(options.output_path,0775);
- options.output_dir_fd=open(options.output_path,O_RDONLY|O_DIRECTORY);
- if(options.output_dir_fd==-1)
+ mkdir(state.output_path,0775);
+ state.output_dir_fd=open(state.output_path,O_RDONLY|O_DIRECTORY);
+ if(state.output_dir_fd==-1)
die("Could not open output dir\n");
}
}else if_option("--input")
{
i=get_next_option_or_die(i,argc,"expected a file name after --input flag\n");
- options.input_path=argv[i];
+ state.input_path=argv[i];
}else if_option("--header")
{
i=get_next_option_or_die(i,argc,"expected an argument after --header flag\n");
- options.header=read_file(argv[i]);
+ state.header=read_file(argv[i]);
}else if_option("--footer")
{
i=get_next_option_or_die(i,argc,"expected an argument after --footer flag\n");
- options.footer=read_file(argv[i]);
+ state.footer=read_file(argv[i]);
}else if_option("--tree")
{
- options.output_is_tree_like=1;
+ state.output_is_tree_like=1;
}else if_option("--tree-cutoff")
{
i=get_next_option_or_die(i,argc,"expected an argument after --tree-cutoff flag\n");
- if(sscanf(argv[i],"%d",&options.tree_cutoff))
+ if(sscanf(argv[i],"%d",&state.tree_cutoff)!=1)
die("expected a number after the --tree-cutoff flag\n");
+ if(state.tree_cutoff>=MAX_CUTOFF-1)
+ die("cutoff number is too large. Max cutoff is %d\n",MAX_CUTOFF);
}else if_option("-h")
{
die(usage);
@@ -95,9 +97,9 @@ void parse_options(int argc,char **argv)
}
- if(options.input_path==NULL)
+ if(state.input_path==NULL)
die("You need to specify an input path\n");
- if(options.output_path==NULL)
+ if(state.output_path==NULL)
die("You need to specify an output path\n");
#undef if_option
@@ -133,13 +135,13 @@ int create_branch_dir(const char *branch_name)
{
int ret=0;
- ret=openat(options.output_dir_fd,branch_name,O_DIRECTORY|O_RDONLY);
+ ret=openat(state.output_dir_fd,branch_name,O_DIRECTORY|O_RDONLY);
if(ret==-1)
{
- if(mkdirat(options.output_dir_fd,branch_name,0775)==-1)
+ if(mkdirat(state.output_dir_fd,branch_name,0775)==-1)
die("Could not create branch directory for %s\n",branch_name);
- ret=openat(options.output_dir_fd,branch_name,O_DIRECTORY|O_RDONLY);
+ ret=openat(state.output_dir_fd,branch_name,O_DIRECTORY|O_RDONLY);
if(ret==-1)
die("Could not open newly created directory for branch %s\n",branch_name);
}
@@ -170,12 +172,12 @@ FILE* create_file(int branch_dir,const char *filename)
ret=fdopen(fd,"w");
- fprintf(ret,"%s",options.header);
+ fprintf(ret,"%s",state.header);
return ret;
}
void close_file(FILE *file)
{
- fprintf(file,"%s",options.footer);
+ fprintf(file,"%s",state.footer);
fclose(file);
}
int create_dir(int base_dir,const char *dir_name)
@@ -202,10 +204,10 @@ void die(const char *format, ...)
}
void push_html_link_for_blob(FILE *out,const char *filename,const char *oid)
{
- fprintf(out,"<a href=\"%s.html\" class=\"blob_entry\">%s</a>\n",oid,filename);
+ fprintf(out,"<a href=\"%s.html\" class=\"blob_entry\">%s</a>",oid,filename);
}
void push_html_link_for_tree(FILE *out,const char *filename,const char *oid)
{
- fprintf(out,"<b><a href=\"%s/index.html\" class=\"tree_entry\">%s</a></b>\n",oid,filename);
+ fprintf(out,"<b><a href=\"%s/index.html\" class=\"tree_entry\">%s</a></b>",oid,filename);
}
#endif