separate file for 'config' options

This commit is contained in:
SANO Masatoshi 2014-10-01 06:43:54 +09:00
parent 5f88b57471
commit 14df127d93
4 changed files with 37 additions and 32 deletions

View file

@ -5,4 +5,5 @@ ros_SOURCES = lsp.c opt.c download.c util.c archive.c html.c\
cmds/run/cmd.c \
cmds/pull/cmd.c cmds/pull/sbcl.c cmds/pull/sbcl-bin.c \
cmds/list/cmd.c \
cmds/help/cmd.c
cmds/help/cmd.c \
cmds/config/cmd.c

32
src/cmds/config/cmd.c Normal file
View file

@ -0,0 +1,32 @@
#include <stdio.h>
#include "util.h"
#include "opt.h"
int cmd_config(int argc, const char **argv)
{
char* home=homedir();
char* path=cat(home,"config",NULL);
int ret;
struct opts* opt=global_opt;
struct opts** opts=&opt;
if(argc==1) {
printf("oneshot:\n");
print_opts(local_opt);
printf("local:\n");
print_opts(opt);
ret= 1;
}else {
// TBD parse options
if(argc==2) {
unset_opt(opts, argv[1]);
save_opts(path,opt);
ret= 2;
}else if(argc>2) {
set_opt(opts, argv[1],(char*)argv[2],0);
save_opts(path,opt);
ret= 3;
}
}
s(home),s(path);
return ret;
}

View file

@ -16,7 +16,7 @@ extern int cmd_list(int argc,char **argv,struct sub_command* cmd);
extern int cmd_download(int argc,char **argv,struct sub_command* cmd);
extern int cmd_tar(int argc,char **argv,struct sub_command* cmd);
extern int cmd_version(int argc,char **argv,struct sub_command* cmd);
extern int cmd_opt(int argc,char **argv,struct sub_command* cmd);
extern int cmd_config(int argc,char **argv,struct sub_command* cmd);
extern int cmd_help(int argc,char **argv,struct sub_command* cmd);
extern void register_cmd_run(void);
@ -142,6 +142,7 @@ int main (int argc,char **argv) {
top_options=add_command(top_options,"no-quicklisp","+Q",cmd_notyet,1,0,"do not use quicklisp",NULL);
top_options=add_command(top_options,"verbose","-v",cmd_notyet,1,0,"be quite noisy while building",NULL);
top_options=add_command(top_options,"quiet","-q",cmd_notyet,1,0,"be quite quiet while building (default)",NULL);
top_options=add_command(top_options,"version",NULL,cmd_version,0,1,NULL,NULL);
top_options=nreverse(top_options);
/*commands*/
@ -149,7 +150,7 @@ int main (int argc,char **argv) {
register_cmd_pull();
top_commands=add_command(top_commands,"execute" ,"!",cmd_notyet,1,1,"Run the specified software without generating a script",NULL);
top_commands=add_command(top_commands,"output" ,NULL,cmd_notyet,1,1,"Generate an executable script or binary from the software specification",NULL);
top_commands=add_command(top_commands,"config" ,NULL,cmd_opt,1,1,"Get and set options",NULL);
top_commands=add_command(top_commands,"config" ,NULL,cmd_config,1,1,"Get and set options",NULL);
/* {"list",NULL,cmd_list,1,1}, */
/* {"set",NULL,cmd_notyet,0,1}, */
top_commands=add_command(top_commands,"version" ,NULL,cmd_version,1,1,"Show the "PACKAGE" version information",NULL);

View file

@ -211,32 +211,3 @@ LVal add_command(LVal cmd,const char* name,const char* short_name,sub_command_fn
cmd=cons(p,cmd);
return cmd;
}
int cmd_opt(int argc, const char **argv)
{
char* home=homedir();
char* path=cat(home,"config",NULL);
int ret;
struct opts* opt=global_opt;
struct opts** opts=&opt;
if(argc==1) {
printf("oneshot:\n");
print_opts(local_opt);
printf("local:\n");
print_opts(opt);
ret= 1;
}else {
// TBD parse options
if(argc==2) {
unset_opt(opts, argv[1]);
save_opts(path,opt);
ret= 2;
}else if(argc>2) {
set_opt(opts, argv[1],(char*)argv[2],0);
save_opts(path,opt);
ret= 3;
}
}
s(home),s(path);
return ret;
}