Skip to content

Commit

Permalink
Add README for menu and support for compile only
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Portic committed Nov 28, 2015
1 parent a1a1a9c commit d1834fb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 27 deletions.
1 change: 1 addition & 0 deletions menu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ifeq ($(UNAME_R),*ARCH)
else
$(CC) $(CFLAGS) -o $(TARGET) main.o menu.o $(LIBPATH) $(LIBS)
endif
$(RM) *.o

menu.o: menu.c menu.h
$(CC) $(CFLAGS) -c menu.c
Expand Down
13 changes: 13 additions & 0 deletions menu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Meni za automatsko kompajliranje i pokretanje zadataka

Priprema:
Meni samo trazi dorektorijume koji pocinju sa slovom v (malo slovo) i fajlove u njima sa ekstenzijom ".c"

Koriscenje:
1. Otvoriti terminal u direktorijumu menu ili uci u taj direktorijum pomocu cd komande
2. Pokrenuti komanu make koja ce kompajlirati meni za vas sistem
3. Otvoriti meni sa komandom ./menu
4. Izabrati direktorijum, pa zatim fajl i aplikacija ce je kompajlirati i pokrenuti automatski
5. "q" je za nazad ili izlazak, a "c" za samo kompajliranje bez pokretanja (ako je neophodno pokretanje sa argumentima)

--Portic
28 changes: 17 additions & 11 deletions menu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@

#include "menu.h"

#define MAX_PATH 30
#define MAX_FILE 30
#define MAX_COMMAND 70

int main (int argc, char *argv[], char* envp[]) {
char path[MAX_PATH];
char file[MAX_FILE];
char command[MAX_COMMAND];
menu_setup(path);
char remove_command[MAX_FILE];
int compile_only=menu_setup(file);

strcpy(command, "gcc ");
strcat(command, path);
strcat(command, file);
strcat(command, " -o ");
path[strlen(path)-2]=0;
strcat(command, path);
file[strlen(file)-2]=0;
strcat(command, file);
strcat(command, " -lm");

printf("Compiling %s\n", command);
system(command);

printf("Running %s\n", path);
system(path);

printf("\n");

if(compile_only==0) {
printf("Running %s\n", file);
system(file);

strcpy(remove_command, "rm ");
printf("Removing executable\n");
system(strcat(remove_command, file));
}

return 0;
}

34 changes: 21 additions & 13 deletions menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,37 @@

#include "menu.h"

void menu_setup(char path[]) {
int menu_setup(char path[]) {
initscr();
cbreak();
keypad(stdscr, TRUE);
noecho();
curs_set(FALSE);
clear();

menu(path);
int compile_only=menu(path);

endwin();
return compile_only;
}

void menu(char path[]) {
int menu(char path[]) {
char sec[MAX_SECTIONS][MAX_SECTION_STR];
char fil[MAX_FILES][MAX_FILE_STR];
char sec_dir[MAX_FILE_STR];
int n;
int sel=0;
int compile_only=0;

do {
clear();
n=read_sections(sec);
sort_sections_strings(sec, n);

sel=run_sections_menu(sec, n);
if(sel==-1) {
endwin();
return;
return compile_only;
}

clear();
Expand All @@ -41,7 +44,7 @@ void menu(char path[]) {

n=read_files(fil, sec_dir);
sort_files_strings(fil, n);
sel=run_files_menu(fil,n);
sel=run_files_menu(fil,n, &compile_only);
} while(sel==-1);

//char file[MAX_SECTION_STR+MAX_FILE_STR];
Expand All @@ -52,6 +55,7 @@ void menu(char path[]) {
mvprintw(1,1, "Selected file: %s", path);
refresh();
//while(1);
return compile_only;
}

int read_sections(char sec[][MAX_SECTION_STR]) {
Expand Down Expand Up @@ -93,7 +97,7 @@ void draw_sections(char sec[][MAX_SECTION_STR], int n, int selected) {
mvprintw(y++, x, "%s", sec[i]);
attroff(A_STANDOUT);
}

mvprintw(++y, x, "q za izlazak");
refresh();
}

Expand All @@ -102,7 +106,7 @@ int run_sections_menu(char sec[][MAX_SECTION_STR], int max_sel) {

do {
draw_sections(sec, max_sel, sel);
refresh();
//refresh();
int c=getch();

if(c == KEY_UP && sel > 0) {
Expand Down Expand Up @@ -157,26 +161,30 @@ void draw_files(char fil[][MAX_FILE_STR], int n, int selected) {
mvprintw(y++, x, "%s", fil[i]);
attroff(A_STANDOUT);
}

mvprintw(++y, x, "c za kompajliranje fajla, bez pokretanja");
mvprintw(++y, x, "q za nazad");
refresh();
}

int run_files_menu(char fil[][MAX_FILE_STR], int max_sel) {
int run_files_menu(char fil[][MAX_FILE_STR], int max_sel, int *compile_only) {
int sel=0, back=0;

do {
draw_files(fil, max_sel, sel);
refresh();
//refresh();
int c=getch();

if(c == KEY_UP && sel > 0) {
sel--;
} else if(c==KEY_DOWN && sel < max_sel-1) {
} else if(c == KEY_DOWN && sel < max_sel-1) {
sel++;
} else if(c==10) {
} else if(c == 10) {
return sel;
} else if(c=='q') {
} else if(c == 'q') {
back=1;
} else if(c == 'c') {
*compile_only=1;
return sel;
}
} while(back == 0);
return -1;
Expand Down
6 changes: 3 additions & 3 deletions menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define MAX_FILES 30
#define MAX_FILE_STR 20

void menu_setup(char path[]);
void menu(char path[]);
int menu_setup(char path[]);
int menu(char path[]);
int read_sections(char sec[][MAX_SECTION_STR]);
void sort_sections_strings(char sec[][MAX_SECTION_STR], int n);
void draw_sections(char sec[][MAX_SECTION_STR], int n, int sel);
Expand All @@ -16,7 +16,7 @@ int run_sections_menu(char sec[][MAX_SECTION_STR], int n);
int read_files(char sec[][MAX_FILE_STR], char directory[]);
void sort_files_strings(char sec[][MAX_FILE_STR], int n);
void draw_files(char sec[][MAX_FILE_STR], int n, int sel);
int run_files_menu(char sec[][MAX_FILE_STR], int n);
int run_files_menu(char sec[][MAX_FILE_STR], int n, int *compile_only);

#endif

Empty file modified v06/zad05.c
100755 → 100644
Empty file.

0 comments on commit d1834fb

Please sign in to comment.