From 242be95344b62ee1f64c205d8046b9e96b5241e6 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 17 Jul 2017 00:24:08 +0200 Subject: New main --- h.c | 250 ------------------------------------------------------- main.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.h | 31 +++++++ 3 files changed, 325 insertions(+), 250 deletions(-) delete mode 100755 h.c create mode 100755 main.c diff --git a/h.c b/h.c deleted file mode 100755 index bf7f9e4..0000000 --- a/h.c +++ /dev/null @@ -1,250 +0,0 @@ - - -#include "main.h" -#include "regex.h" -#include "readline.h" - -#include -#include -#include -#include -#include - -#include "item.h" -#include "wind.h" - - -#ifdef DEBUG - -#include - -#endif - -const int color[] = { - COLOR_BLACK, COLOR_RED, - COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, - COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE}; - - - - - -#define MAX_PATH 1024 - - - -extern char* msg_win_str; - -static bool visual_mode = false; -WINDOW *cmd_win; -WINDOW *sep_win; -char status[10]; - - -void fail_exit(const char *msg) { - if (visual_mode) - endwin(); - fprintf(stderr, "%s\n", msg); - exit(EXIT_FAILURE); -} - - - - -void edit_rl(menuC* menu,void func(TagLib_Tag *, const char*), int c) { - status[1]=c; - printStatus(); - refresh(); - curs_set(2); - move(LINES-1, 0); - readline_n(); - clear(); - curs_set(0); - itemC* it = menu->list+menu->hl; - if( msg_win_str) { - int selected = 0; - for(int i = 0 ; i < menu->nbElem ; i++) - if( menu->list[i].selected ) - selected = 1; - if( ! selected && ! it->opt ) { - mvprintc(20, 20, "H$1e$2l$3l$4o", 10); - func(it->info.tag, msg_win_str); - taglib_file_save(it->info.file); - }else{ - for(int i = 0 ; i < menu->nbElem ; i++) - if( menu->list[i].selected && !menu->list[i].opt ) { - func(menu->list[i].info.tag, msg_win_str); - taglib_file_save(menu->list[i].info.file); - } - } - } -} - -int main(int argc, char* argv[]){ - itemC* menuL = NULL; - int size = 0; - int c; - int comp = 0; - - setlocale(LC_ALL, ""); - initscr(); - if (has_colors()) { - CHECK(start_color); - } - CHECK(cbreak); - CHECK(noecho); - CHECK(nonl); - CHECK(intrflush, NULL, FALSE); - visual_mode = true; - taglib_set_strings_unicode(1); - curs_set(0); - - cmd_win = newwin(1, COLS, LINES - 20, 0); - sep_win = newwin(1, COLS, LINES - 2, 0); - - init_pair( 12, COLOR_WHITE, COLOR_BLUE); - CHECK(wbkgd, sep_win, COLOR_PAIR(12)); - CHECK(wrefresh, sep_win); - init_readline(); - - for(int i = 0 ; i < 9 ; i++) { - init_pair( i+1, i, COLOR_BLACK); - } - - if( !argv[1] ) { - listdir(0, &menuL, &size); - } else { - chdir(argv[1]); - listdir(0,&menuL, &size); - puts(argv[1]); - } - qsort(menuL, size, sizeof *menuL, sort_i); - - menuC menu = (menuC) { menuL, size, 0, 0, 0, NULL, NULL, 1, 1, COLS/2-1, LINES-2}; - - - - printmenu(&menu); - printTagInfoHeader(); - move(1,COLS/2); - vline( ACS_VLINE, LINES-2) ; - - - while( c = getch() ) { - if (c == KEY_RESIZE) { - resizeMain(&menu); - continue; - } - switch( comp ) { - case 0: - switch (c) { - case KEY_SF: - case 'j': - if( menu.hl < menu.nbElem-1 ) - menu.hl++; - printTagInfo(&menu); - break; - case KEY_SR: - case 'k': - if( menu.hl > 0) - menu.hl--; - printTagInfo(&menu); - break; - case KEY_SLEFT: - break; - case KEY_SRIGHT: - break; - case 'e': - if( !status[0] ) { - status[0] = 'e'; - comp = 'e'; - }else{ - status[0] = 0; - } - break; - case ' ': - menu.list[menu.hl].selected = !menu.list[menu.hl].selected; - break; - case 's': - prepare("xs"); - regexSelection(&menu,msg_win_str); - resizeMain(&menu); - break; - case 'x': - prepare("x"); - regexXtract(&menu.list[menu.hl], msg_win_str); - resizeMain(&menu); - break; - case 'q': - goto end; - case '\r': - if( menu.list[menu.hl].opt ) { - int n = strlen(menu.list[menu.hl].cstr+1); - char* s = menu.list[menu.hl].cstr+1; - s[n-1] = 0; - chdir(s); - s[n-1] = ']'; - cleanmenu(&menu); - - freelitem(menuL, size); - listdir(0,&menuL, &size); - qsort(menuL, size, sizeof *menuL, sort_i); - menu.list = menuL; - menu.nbElem = size; - menu.hl = 0; - } - default:; -// fprintf(stderr, "[%c]", c); - } - break; - case 'e': - echo(); - move(LINES-1,1); - switch(c) { - case 't': - edit_rl(&menu,taglib_tag_set_title,'t'); - break; - case 'a': - edit_rl(&menu,taglib_tag_set_artist,'a'); - break; - case 'b': - edit_rl(&menu,taglib_tag_set_album,'b'); - break; - case 'y': - break; - case 'n': - break; - case 'g': - edit_rl(&menu,taglib_tag_set_genre,'g'); - break; - case 'c': - edit_rl(&menu,taglib_tag_set_comment,'c'); - break; - default: - ; - } - comp = 0; - status[0] = status[1] = 0; - - printmenu(&menu); - printTagInfoHeader(); - printTagInfo(&menu); - break; - } - printStatus(); - printmenu(&menu); - move(1,COLS/2); - vline( ACS_VLINE, LINES-2) ; - refresh(); - } - - refresh(); - getch(); -end: - endwin(); - - return 0; -} - - - diff --git a/main.c b/main.c new file mode 100755 index 0000000..14e45d3 --- /dev/null +++ b/main.c @@ -0,0 +1,294 @@ + + +#include "main.h" +#include "regex.h" +#include "readline.h" + +#include +#include +#include +#include +#include + +#include "item.h" +#include "wind.h" + + +#ifdef DEBUG + +#include + +#endif + +const int color[] = { + COLOR_BLACK, COLOR_RED, + COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, + COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE}; + + + + + +#define MAX_PATH 1024 + + + +extern char* msg_win_str; + +static bool visual_mode = false; +WINDOW *cmd_win; +WINDOW *sep_win; +char status[10]; + + +void fail_exit(const char *msg) { + if (visual_mode) + endwin(); + fprintf(stderr, "%s\n", msg); + exit(EXIT_FAILURE); +} + + +void edit_rl(menuC* menu,void func(TagLib_Tag *, const char*), int c); + +void edit_rl(menuC* menu,void func(TagLib_Tag *, const char*), int c) { + status[1]=c; + printStatus(); + refresh(); + curs_set(2); + move(LINES-1, 0); + readline_n(); + clear(); + curs_set(0); + itemC* it = menu->list+menu->hl; + if( msg_win_str) { + int selected = 0; + for(int i = 0 ; i < menu->nbElem ; i++) + if( menu->list[i].selected ) + selected = 1; + if( ! selected && ! it->opt ) { + mvprintc(20, 20, "H$1e$2l$3l$4o", 10); + func(it->info.tag, msg_win_str); + taglib_file_save(it->info.file); + }else{ + for(int i = 0 ; i < menu->nbElem ; i++) + if( menu->list[i].selected && !menu->list[i].opt ) { + func(menu->list[i].info.tag, msg_win_str); + taglib_file_save(menu->list[i].info.file); + } + } + } +} + +int main(int argc, char* argv[]){ + + while (1) { + int c; + int optIndex = 0; + static struct option optlv[] = { + {"help", no_argument, 0, 'h' }, + {"version", no_argument, 0, 'v' }, + {"dir", required_argument, 0, 'd' }, + {NULL, 0, 0, 0 } + }; + + + c = getopt_long(argc, argv, "hvd:", optlv, &optIndex); + if (c == -1) + break; + + switch (c) { + case 'v': + if( !strcmp(optlv[optIndex].name, "version") ) { + puts( VERSION_METAG ); + } + break; + + case 'h': + puts( HELP_STRING_METAG ); + return EXIT_SUCCESS; + + break; + case 'c': + if( optarg ) { + + } else { + fprintf(stderr, "Veuillez indiquer un directory\n"); + } + break; + case '?': + default: + return EXIT_FAILURE; + } + } + + + + + itemC* menuL = NULL; + int size = 0; + int c; + int comp = 0; + + setlocale(LC_ALL, ""); + initscr(); + if (has_colors()) { + CHECK(start_color); + } + CHECK(cbreak); + CHECK(noecho); + CHECK(nonl); + CHECK(intrflush, NULL, FALSE); + visual_mode = true; + taglib_set_strings_unicode(1); + curs_set(0); + + cmd_win = newwin(1, COLS, LINES - 20, 0); + sep_win = newwin(1, COLS, LINES - 2, 0); + + init_pair( 12, COLOR_WHITE, COLOR_BLUE); + CHECK(wbkgd, sep_win, COLOR_PAIR(12)); + CHECK(wrefresh, sep_win); + init_readline(); + + for(int i = 0 ; i < 9 ; i++) { + init_pair( i+1, i, COLOR_BLACK); + } + + if( !argv[1] ) { + listdir(0, &menuL, &size); + } else { + chdir(argv[1]); + listdir(0,&menuL, &size); + puts(argv[1]); + } + qsort(menuL, size, sizeof *menuL, sort_i); + + menuC menu = (menuC) { menuL, size, 0, 0, 0, NULL, NULL, 1, 1, COLS/2-1, LINES-2}; + + + + printmenu(&menu); + printTagInfoHeader(); + move(1,COLS/2); + vline( ACS_VLINE, LINES-2) ; + + + while( c = getch() ) { + if (c == KEY_RESIZE) { + resizeMain(&menu); + continue; + } + switch( comp ) { + case 0: + switch (c) { + case KEY_SF: + case 'j': + if( menu.hl < menu.nbElem-1 ) + menu.hl++; + printTagInfo(&menu); + break; + case KEY_SR: + case 'k': + if( menu.hl > 0) + menu.hl--; + printTagInfo(&menu); + break; + case KEY_SLEFT: + break; + case KEY_SRIGHT: + break; + case 'e': + if( !status[0] ) { + status[0] = 'e'; + comp = 'e'; + }else{ + status[0] = 0; + } + break; + case ' ': + menu.list[menu.hl].selected = !menu.list[menu.hl].selected; + break; + case 's': + prepare("xs"); + regexSelection(&menu,msg_win_str); + resizeMain(&menu); + break; + case 'x': + prepare("x"); + regexXtract(&menu.list[menu.hl], msg_win_str); + resizeMain(&menu); + break; + case 'q': + goto end; + case '\r': + if( menu.list[menu.hl].opt ) { + int n = strlen(menu.list[menu.hl].cstr+1); + char* s = menu.list[menu.hl].cstr+1; + s[n-1] = 0; + chdir(s); + s[n-1] = ']'; + cleanmenu(&menu); + + freelitem(menuL, size); + listdir(0,&menuL, &size); + qsort(menuL, size, sizeof *menuL, sort_i); + menu.list = menuL; + menu.nbElem = size; + menu.hl = 0; + } + default:; +// fprintf(stderr, "[%c]", c); + } + break; + case 'e': + echo(); + move(LINES-1,1); + switch(c) { + case 't': + edit_rl(&menu,taglib_tag_set_title,'t'); + break; + case 'a': + edit_rl(&menu,taglib_tag_set_artist,'a'); + break; + case 'b': + edit_rl(&menu,taglib_tag_set_album,'b'); + break; + case 'y': + break; + case 'n': + break; + case 'g': + edit_rl(&menu,taglib_tag_set_genre,'g'); + break; + case 'c': + edit_rl(&menu,taglib_tag_set_comment,'c'); + break; + default: + ; + } + comp = 0; + status[0] = status[1] = 0; + + printmenu(&menu); + printTagInfoHeader(); + printTagInfo(&menu); + break; + } + printStatus(); + printmenu(&menu); + move(1,COLS/2); + vline( ACS_VLINE, LINES-2) ; + refresh(); + } + + refresh(); + getch(); +end: + endwin(); + + return 0; +} + + + diff --git a/main.h b/main.h index 9f272ec..7131a12 100644 --- a/main.h +++ b/main.h @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -74,6 +75,36 @@ void fail_exit(const char *msg); _a > _b ? _a : _b; }) +#define VERSION_METAG "Alpha" +#define HELP_STRING_METAG "Utilisation : metag [OPTION]...\n" \ + "Editeur de tag mp3" \ + "Options :\n" \ + "\t\t--help -h Affiche l'aide simple\n" \ + "\t\t--version -v Affiche la version\n" \ + "\t\t--dir -d Change le répertoire de travail\n"\ + "\n" \ + "Basic control :\n" \ + " 'e%' - edit % where % can be :\n" \ + " t for title | a for artist | b for album | g for genre" \ + " y for year | y for comment | n for track number" \ + "" \ + " 'q' to exit" \ + "" \ + " 's' select by regex" \ + "" \ + " 'x' extract information from the title by regex" \ + "" \ + " ' ' toggle selection of the current item" \ + "" \ + " 'k' selection up" \ + " 'j' selection down" \ + "" + + + + + + #endif -- cgit v1.2.3