You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
5.3 KiB
142 lines
5.3 KiB
#include "ubl-settings-repo-back.h"
|
|
|
|
|
|
dict_simple *yon_dict_new(){
|
|
dict_simple *dict = (dict_simple*)malloc(sizeof(dict_simple));
|
|
dict->first=dict;
|
|
dict->next=NULL;
|
|
dict->data=NULL;
|
|
return dict;
|
|
}
|
|
|
|
dict_simple *yon_dict_append(dict_simple *dictionary_to_append){
|
|
dict_simple *dict = (dict_simple*)malloc(sizeof(dict_simple));
|
|
dictionary_to_append->next=dict;
|
|
dict->first=dictionary_to_append->first;
|
|
dict->next=NULL;
|
|
dict->data=NULL;
|
|
return dict;
|
|
}
|
|
|
|
repo_operation *yon_operation_new(){
|
|
repo_operation *operation = (repo_operation*)malloc(sizeof(repo_operation));
|
|
operation->package_add=NULL;
|
|
operation->package_remove=NULL;
|
|
operation->rename=NULL;
|
|
operation->target=NULL;
|
|
operation->create=0;
|
|
return operation;
|
|
}
|
|
|
|
char *yon_string_append(char *source, char *append){
|
|
int size = (strlen(source)+strlen(append)+2);
|
|
char *n_source = (char*)malloc(sizeof(char)*size);
|
|
memset(n_source,0,size);
|
|
memcpy(n_source,source,strlen(source));
|
|
memcpy(n_source+strlen(source)," ",1);
|
|
memcpy(n_source+strlen(source)+1,append,strlen(append));
|
|
return n_source;
|
|
}
|
|
|
|
char *yon_string_copy(char *string){
|
|
if (string){
|
|
char *str = malloc(sizeof(char)*strlen(string)+1);
|
|
memset(str,0,strlen(string)+1);
|
|
memcpy(str,string,strlen(string));
|
|
return str;
|
|
} else return NULL;
|
|
}
|
|
|
|
char *yon_string_find_last(char *source, char *find){
|
|
|
|
for (char *found = strstr(source,find);found;found=strstr(found,find)){
|
|
if (found);
|
|
}
|
|
}
|
|
|
|
int yon_repo_proceed(int argc, char *argv[]){
|
|
int option_index=0;
|
|
int show_help=0;
|
|
{
|
|
struct option long_options[] = {
|
|
{"repo-new", 1, 0, 1},
|
|
{"package-add", 1, 0, 2},
|
|
{"package-remove", 1, 0, 3},
|
|
{"repo-rename", 1, 0, 4},
|
|
{"origin", 1, 0, 'o'},
|
|
{ NULL, 0, NULL, 0 }
|
|
};
|
|
dict_simple *dict = yon_dict_new();
|
|
repo_operation *operation = yon_operation_new();
|
|
dict->data=(void*)operation;
|
|
#define curpack(dict) ((repo_operation*)dict->data)
|
|
for (int i=0;i<argc;i++){
|
|
int argument=getopt_long(argc,argv,"o",long_options,&option_index);
|
|
switch(argument){
|
|
case 2: curpack(dict)->package_add = yon_string_append(curpack(dict)->package_add,yon_string_copy(optarg));
|
|
break;
|
|
case 3: curpack(dict)->package_remove = yon_string_append(curpack(dict)->package_add,yon_string_copy(optarg));
|
|
break;
|
|
case 4: curpack(dict)->rename=yon_string_copy(optarg);
|
|
case 1:
|
|
if (!((repo_operation*)dict->data)->target) ((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
|
else {
|
|
dict = yon_dict_append(dict);
|
|
operation = yon_operation_new();
|
|
dict->data=(void*)operation;
|
|
((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
|
}
|
|
((repo_operation*)dict->data)->create=1;
|
|
break;
|
|
case 'o':
|
|
if (!((repo_operation*)dict->data)->target) ((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
|
else {
|
|
dict = yon_dict_append(dict);
|
|
operation = yon_operation_new();
|
|
dict->data=(void*)operation;
|
|
((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
|
}
|
|
break;
|
|
case '?': printf("%s: %c\n",UNKNOWN_ARGUMENT_LABEL,argument);
|
|
break;
|
|
}
|
|
}
|
|
for (dict_simple *dct=dict->first;dct;dct=dct->next){
|
|
if (curpack(dct)->target){
|
|
if (curpack(dct)->create){
|
|
GKeyFile *file = g_key_file_new();
|
|
g_key_file_load_from_file(file,"/etc/pacman.conf",G_KEY_FILE_KEEP_COMMENTS,NULL);
|
|
g_key_file_set_string(file,curpack(dct)->target,"Server",curpack(dct)->target);
|
|
char *command = yon_string_append("repo-add ",curpack(dct)->target);
|
|
if (curpack(dct)->package_add){
|
|
command = yon_string_append(command," ");
|
|
command = yon_string_append(command,curpack(dct)->package_add);
|
|
}
|
|
system(command);
|
|
|
|
} else if (curpack(dct)->package_remove){
|
|
char *command = yon_string_append("repo-remove ",curpack(dct)->target);
|
|
command = yon_string_append(command," ");
|
|
command = yon_string_append(command,curpack(dct)->package_remove);
|
|
system(command);
|
|
}
|
|
if (curpack(dct)->package_add){
|
|
char *command = yon_string_append("repo-add ",curpack(dct)->target);
|
|
command = yon_string_append(command," ");
|
|
command = yon_string_append(command,curpack(dct)->package_add);
|
|
}
|
|
system(command);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[]){
|
|
char *local=setlocale(LC_ALL, "");
|
|
textdomain (LocaleName);
|
|
yon_repo_proceed(argc, argv);
|
|
|
|
}
|