Skip to content

Commit

Permalink
Merge pull request #79 from roberthawdon/develop
Browse files Browse the repository at this point in the history
Develop to Master (0.6.2)
  • Loading branch information
roberthawdon authored Mar 2, 2019
2 parents f2ab8f5 + b015e6e commit 902fa04
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 146 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ To install DF-SHOW via Homebrew, run the following in your terminal:

.. code-block:: bash
brew install roberthawdon/homebrew-dfshow/dfshow
brew tap roberthawdon/dfshow
brew install dfshow
Building from Git
-----------------
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([dfshow], [0.6.1], [https://github.com/roberthawdon/dfshow/issues])
AC_INIT([dfshow], [0.6.2], [https://github.com/roberthawdon/dfshow/issues])
AC_GNU_SOURCE
AM_INIT_AUTOMAKE([subdir-objects])
AC_PROG_CC
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.6.1-alpha'
release = '0.6.2-alpha'


# -- General configuration ---------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ To install DF-SHOW via Homebrew, run the following in your terminal:

.. code-block:: bash
brew install roberthawdon/homebrew-dfshow/dfshow
brew tap roberthawdon/dfshow
brew install dfshow
Building from Source
--------------------
Expand Down
31 changes: 24 additions & 7 deletions src/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <libconfig.h>
#include <dirent.h>
#include <errno.h>
#include "common.h"
#include "colors.h"

Expand All @@ -41,6 +42,8 @@ colorPairs colors[256];

char fgbgLabel[11];

char errmessage[256];

extern int colormode;
extern int c;
extern int * pc;
Expand Down Expand Up @@ -220,7 +223,7 @@ void refreshColors(){
void saveTheme(){
config_t cfg;
config_setting_t *root, *setting, *group, *array;
int e, i;
int e, f, i;
char filename[1024];
char * rewrite;
move(0,0);
Expand Down Expand Up @@ -249,7 +252,8 @@ void saveTheme(){
setting = config_setting_add(array, NULL, CONFIG_TYPE_INT);
config_setting_set_int(setting, colors[i].bold);
}
if (check_dir(dirFromPath(filename))){
saveTheme:
if (access(dirFromPath(filename), W_OK) == 0){
if (check_file(filename)){
curs_set(FALSE);
printMenu(0,0, "File exists. Replace? (!Yes/!No)");
Expand All @@ -274,11 +278,24 @@ void saveTheme(){
setenv("DFS_THEME", objectFromPath(filename), 1);
}
} else {
curs_set(FALSE);
mk_dir(dirFromPath(filename));
config_write_file(&cfg, filename);
// topLineMessage("Error: Unable to write file");
curs_set(TRUE);
if (errno == ENOENT){
// curs_set(FALSE);
// mk_dir(dirFromPath(filename));
// config_write_file(&cfg, filename);
// // topLineMessage("Error: Unable to write file");
// curs_set(TRUE);
f = createParentsInput(dirFromPath(filename));
if (f == 1){
createParentDirs(filename);
goto saveTheme;
} else {
sprintf(errmessage, "Error: %s", strerror(errno));
topLineMessage(errmessage);
}
} else {
sprintf(errmessage, "Error: %s", strerror(errno));
topLineMessage(errmessage);
}
}
config_destroy(&cfg);
}
Expand Down
101 changes: 101 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,107 @@ int getch10th (void) {
return ch;
}

int splitPath(pathDirs **dirStruct, char *path){
int e, i, j, c;
pathDirs *tmp;

tmp = malloc(sizeof(pathDirs));
if (tmp){
*dirStruct = tmp;
}

e = -1;
j = 0;
c = strlen(path);

for(i = 0; i < c; i++){
if (path[i] == '/'){
if (e > -1){
(*dirStruct)[e].directories[j] = '\0';
if(!strcmp((*dirStruct)[e].directories, "..")){
// assmue .. and remove the element before
(*dirStruct)[e] = (*dirStruct)[e - 1];
(*dirStruct)[e - 1] = (*dirStruct)[e - 2];
e--;
(*dirStruct) = realloc((*dirStruct), sizeof(pathDirs) * (2 + e));
} else if (!strcmp((*dirStruct)[e].directories, ".")){
// strip single .
strcpy((*dirStruct)[e].directories, "\0");
} else {
// If element created is NOT ..
e++;
(*dirStruct) = realloc((*dirStruct), sizeof(pathDirs) * (2 + e));
}
} else {
e++;
(*dirStruct) = realloc((*dirStruct), sizeof(pathDirs) * (2 + e));
}
j=0;
} else {
(*dirStruct)[e].directories[j] = path[i];
j++;
}
}
(*dirStruct)[e].directories[j] = '\0';
if (!strcmp((*dirStruct)[e].directories, ".")){
strcpy((*dirStruct)[e].directories, "");
e--;
}

return(e);
}

int createParentsInput(char *path)
{
int result = 0;
int messageLen;
wchar_t *message = malloc(sizeof(wchar_t) * 1);

messageLen = (strlen(path) + 64);

message = realloc(message, sizeof(wchar_t) * (messageLen + 1));

swprintf(message, messageLen, L"Directory [<%s>] does not exist. Create it? !Yes/!No (enter = no)", path);
wPrintMenu(0,0, message);
while(1)
{
*pc = getch10th();
if (*pc == 'y'){
result = 1;
break;
} else if ((*pc == 'n') || (*pc == 10)){
result = 0;
break;
} else if (*pc == 27){
result = -1;
break;
}
}
free(message);
return(result);
}

void createParentDirs(char *path){
pathDirs *targetPath;
char *tempPath = malloc(sizeof(char) + 1);
int e, i = 0;

e = splitPath(&targetPath, path);

strcpy(tempPath, "");
for (i = 0; i < e; i++){
tempPath = realloc(tempPath, sizeof(char) * (strlen(tempPath) + strlen(targetPath[i].directories) + 2));
sprintf(tempPath, "%s/%s", tempPath, targetPath[i].directories);
if (!check_dir(tempPath)){
mk_dir(tempPath);
}
}

free(targetPath);
free(tempPath);
return;
}

int cmp_menu_ref(const void *lhs, const void *rhs)
{

Expand Down
7 changes: 7 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ typedef struct {
int displayLabelSize;
} menuDef;

typedef struct {
char directories[256];
} pathDirs;

int getch10th (void);
int cmp_menu_ref(const void *lhs, const void *rhs);
int splitPath(pathDirs **dirStruct, char *path);
int createParentsInput(char *path);
void createParentDirs(char *path);
void addMenuItem(menuDef **dfMenu, int *pos, char* refLabel, wchar_t* displayLabel, int hotKey);
void updateMenuItem(menuDef **dfMenu, int *menuSize, char* refLabel, wchar_t* displayLabel);
wchar_t * genMenuDisplayLabel(wchar_t* preMenu, menuDef* dfMenu, int size, wchar_t* postMenu, int comma);
Expand Down
93 changes: 6 additions & 87 deletions src/showfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,101 +154,20 @@ int checkRunningEnv(){

char *getRelativePath(char *file, char *target)
{
typedef struct {
char directories[256];
} path;

char *result = malloc(sizeof(char) + 1);
int i, j, e, c, resultLen, targetUp, fileUp;
path *fileStruct, *targetStruct;
int currentFileIndex, currentTargetIndex, fileLen, targetLen, commonPath = 0;
pathDirs *fileStruct, *targetStruct;
int fileLen, targetLen, commonPath = 0;

targetUp = fileUp = 0;

fileStruct = malloc(sizeof(path));
targetStruct = malloc(sizeof(path));

// Store sections of file in structure
e = -1;
j = 0;
c = strlen(file);

for(i = 0; i < c; i++){
if (file[i] == '/'){
if (e > -1){
fileStruct[e].directories[j] = '\0';
if(!strcmp(fileStruct[e].directories, "..")){
// assmue .. and remove the element before
fileStruct[e] = fileStruct[e - 1];
fileStruct[e - 1] = fileStruct[e - 2];
e--;
fileStruct = realloc(fileStruct, sizeof(path) * (2 + e));
} else if (!strcmp(fileStruct[e].directories, ".")){
// strip single .
strcpy(fileStruct[e].directories, "\0");
} else {
// If element created is NOT ..
e++;
fileStruct = realloc(fileStruct, sizeof(path) * (2 + e));
}
} else {
e++;
fileStruct = realloc(fileStruct, sizeof(path) * (2 + e));
}
j=0;
} else {
fileStruct[e].directories[j] = file[i];
j++;
}
}
fileStruct[e].directories[j] = '\0';
if (!strcmp(fileStruct[e].directories, ".")){
strcpy(fileStruct[e].directories, "");
e--;
}
e = splitPath(&fileStruct, file);
fileLen = e + 1;
currentFileIndex = e;

// Store sections of target in structure
e = -1;
j = 0;
c = strlen(target);

for(i = 0; i < c; i++){
if (target[i] == '/'){
if (e > -1){
targetStruct[e].directories[j] = '\0';
if(!strcmp(targetStruct[e].directories, "..")){
// assmue .. and remove the element before
targetStruct[e] = targetStruct[e - 1];
targetStruct[e - 1] = targetStruct[e - 2];
e--;
targetStruct = realloc(targetStruct, sizeof(path) * (2 + e));
} else if (!strcmp(targetStruct[e].directories, ".")){
// strip single .
strcpy(targetStruct[e].directories, "\0");
} else {
// If element created is NOT ..
e++;
targetStruct = realloc(targetStruct, sizeof(path) * (2 + e));
}
} else {
e++;
targetStruct = realloc(targetStruct, sizeof(path) * (2 + e));
}
j=0;
} else {
targetStruct[e].directories[j] = target[i];
j++;
}
}
targetStruct[e].directories[j] = '\0';
if (!strcmp(targetStruct[e].directories, ".")){
strcpy(targetStruct[e].directories, "");
e--;
}
e = splitPath(&targetStruct, target);
targetLen = e + 1;
currentTargetIndex = e;

// Find the smallest of our structures
if (fileLen > targetLen){
Expand Down Expand Up @@ -303,9 +222,9 @@ char *getRelativePath(char *file, char *target)
}
} else {
// Assume we're in the same directory at this point
j = strlen(fileStruct[currentFileIndex].directories);
j = strlen(fileStruct[fileLen - 1].directories);
result = realloc(result, sizeof(char) * (j + 1));
sprintf(result, "%s", fileStruct[currentFileIndex].directories);
sprintf(result, "%s", fileStruct[fileLen - 1].directories);
}

// result[resultLen - 1] = '\0'; // This seems to cause no end of grief on FreeBSD and I can't even remember why it's here.
Expand Down
Loading

0 comments on commit 902fa04

Please sign in to comment.