#include <stdio.h>\r
#include <string.h>\r
#include "header.h"\r
-\r
-#if USE_READLINE\r
-# include "readline.h"\r
-#endif\r
+#include <readline.h>\r
\r
#define _stdin 0\r
#define _stdout 1\r
#define _stderr 2\r
\r
// ==== PROTOTYPES ====\r
-char *ReadCommandLine(int *Length);\r
-void Parse_Args(char *str, char **dest);\r
+ int Parse_Args(const char *str, char **dest);\r
void CallCommand(char **Args);\r
void Command_Logout(int argc, char **argv);\r
void Command_Clear(int argc, char **argv);\r
int length = 0;\r
int i;\r
int iArgCount = 0;\r
- #if !USE_READLINE\r
- int bCached = 1;\r
- #else\r
tReadline *readline_state = Readline_Init(1);\r
- #endif\r
\r
gasEnvironment = envp;\r
\r
for(;;)\r
{\r
// Free last command & arguments\r
- if(saArgs[0]) free(saArgs);\r
- #if !USE_READLINE\r
- if(!bCached) free(sCommandStr);\r
- bCached = 0;\r
- #endif\r
+ if(saArgs[0]) free(saArgs[0]);\r
\r
printf("%s$ ", gsCurrentDirectory);\r
\r
// Read Command line\r
- #if USE_READLINE\r
sCommandStr = Readline( readline_state );\r
printf("\n");\r
length = strlen(sCommandStr);\r
- #else\r
- sCommandStr = ReadCommandLine( &length );\r
- \r
- if(!sCommandStr) {\r
- printf("PANIC: Out of heap space\n");\r
- return -1;\r
- }\r
- \r
- // Check if the command should be cached\r
- if(gasCommandHistory == NULL || strcmp(sCommandStr, gasCommandHistory[giLastCommand]) != 0)\r
- {\r
- if(giLastCommand >= giCommandSpace) {\r
- giCommandSpace += 12;\r
- gasCommandHistory = realloc(gasCommandHistory, giCommandSpace*sizeof(char*));\r
- }\r
- giLastCommand ++;\r
- gasCommandHistory[ giLastCommand ] = sCommandStr;\r
- bCached = 1;\r
- }\r
- #endif\r
\r
// Parse Command Line into arguments\r
- Parse_Args(sCommandStr, saArgs);\r
- \r
- // Count Arguments\r
- iArgCount = 0;\r
- while(saArgs[iArgCount]) iArgCount++;\r
+ iArgCount = Parse_Args(sCommandStr, saArgs);\r
\r
// Silently Ignore all empty commands\r
if(saArgs[1][0] == '\0') continue;\r
// Shall we?\r
CallCommand( &saArgs[1] );\r
\r
- #if USE_READLINE\r
free( sCommandStr );\r
- #endif\r
}\r
}\r
\r
-#if !USE_READLINE\r
/**\r
- * \fn char *ReadCommandLine(int *Length)\r
- * \brief Read from the command line\r
- */\r
-char *ReadCommandLine(int *Length)\r
-{\r
- char *ret;\r
- int len, pos, space = 1023;\r
- char ch;\r
- #if 0\r
- int scrollbackPos = giLastCommand;\r
- #endif\r
- \r
- // Preset Variables\r
- ret = malloc( space+1 );\r
- if(!ret) return NULL;\r
- len = 0; pos = 0;\r
- \r
- // Read In Command Line\r
- do {\r
- ch = getchar(); // Read Character from stdin (read is a blocking call)\r
- if(ch == '\n') break;\r
- \r
- switch(ch)\r
- {\r
- // Control characters\r
- case '\x1B':\r
- ch = getchar(); // Read control character\r
- switch(ch)\r
- {\r
- //case 'D': if(pos) pos--; break;\r
- //case 'C': if(pos<len) pos++; break;\r
- case '[':\r
- ch = getchar(); // Read control character\r
- switch(ch)\r
- {\r
- #if 0\r
- case 'A': // Up\r
- {\r
- int oldLen = len;\r
- if( scrollbackPos > 0 ) break;\r
- \r
- free(ret);\r
- ret = strdup( gasCommandHistory[--scrollbackPos] );\r
- \r
- len = strlen(ret);\r
- while(pos--) printf("\x1B[D");\r
- write(_stdout, len, ret); pos = len;\r
- while(pos++ < oldLen) write(_stdout, 1, " ");\r
- }\r
- break;\r
- case 'B': // Down\r
- {\r
- int oldLen = len;\r
- if( scrollbackPos < giLastCommand-1 ) break;\r
- \r
- free(ret);\r
- ret = strdup( gasCommandHistory[++scrollbackPos] );\r
- \r
- len = strlen(ret);\r
- while(pos--) write(_stdout, 3, "\x1B[D");\r
- write(_stdout, len, ret); pos = len;\r
- while(pos++ < oldLen) write(_stdout, 1, " ");\r
- }\r
- break;\r
- #endif\r
- case 'D': // Left\r
- if(pos == 0) break;\r
- pos --;\r
- printf("\x1B[D");\r
- break;\r
- case 'C': // Right\r
- if(pos == len) break;\r
- pos++;\r
- printf("\x1B[C");\r
- break;\r
- }\r
- }\r
- break;\r
- \r
- // Backspace\r
- case '\b':\r
- if(len <= 0) break; // Protect against underflows\r
- putchar(ch);\r
- if(pos == len) { // Simple case of end of string\r
- len --;\r
- pos--;\r
- }\r
- else {\r
- printf("%.*s ", len-pos, &ret[pos]); // Move Text\r
- printf("\x1B[%iD", len-pos+1);\r
- // Alter Buffer\r
- memmove(&ret[pos-1], &ret[pos], len-pos);\r
- pos --;\r
- len --;\r
- }\r
- break;\r
- \r
- // Tab\r
- case '\t':\r
- //TODO: Implement Tab-Completion\r
- //Currently just ignore tabs\r
- break;\r
- \r
- default: \r
- // Expand Buffer\r
- if(len+1 > space) {\r
- space += 256;\r
- ret = realloc(ret, space+1);\r
- if(!ret) return NULL;\r
- }\r
- \r
- // Editing inside the buffer\r
- if(pos != len) {\r
- putchar(ch); // Print new character\r
- printf("%.*s", len-pos, &ret[pos]); // Move Text\r
- printf("\x1B[%iD", len-pos);\r
- memmove( &ret[pos+1], &ret[pos], len-pos );\r
- }\r
- else {\r
- putchar(ch);\r
- }\r
- ret[pos++] = ch;\r
- len ++;\r
- break;\r
- }\r
- } while(ch != '\n');\r
- \r
- // Cap String\r
- ret[len] = '\0';\r
- printf("\n");\r
- \r
- // Return length\r
- if(Length) *Length = len;\r
- \r
- return ret;\r
-}\r
-#endif\r
-\r
-/**\r
- * \fn void Parse_Args(char *str, char **dest)\r
+ * \fn int Parse_Args(const char *str, char **dest)\r
* \brief Parse a string into an argument array\r
*/\r
-void Parse_Args(char *str, char **dest)\r
+int Parse_Args(const char *str, char **dest)\r
{\r
int i = 1;\r
char *buf = malloc( strlen(str) + 1 );\r
if(buf == NULL) {\r
dest[0] = NULL;\r
printf("Parse_Args: Out of heap space!\n");\r
- return ;\r
+ return 0;\r
}\r
\r
strcpy(buf, str);\r
if(*buf == '\0') break;\r
}\r
dest[i] = NULL;\r
- if(i == 1) {\r
- free(buf);\r
- dest[0] = NULL;\r
- }\r
+ \r
+ return i;\r
}\r
\r
/**\r
// Human readable sizes
case 'h': gbViewHumanReadable = 1; continue;
default:
- fprintf(stderr, "%s: Unknown option '%c'\n", *str);
+ fprintf(stderr, "%s: Unknown option '%c'\n", argv[0], *str);
ShowUsage(argv[0]);
exit(EXIT_FAILURE);
}
printf("%s %4i %4i ", permStr, owner, group);
if(gbViewHumanReadable && type != FTYPE_DIR) {
if(size < 2048) { // < 2 KiB
- printf("%4i B ", size);
+ printf("%4lli B ", size);
}
else if(size < 2048*1024) { // < 2 MiB
- printf("%4i KiB ", size>>10);
+ printf("%4lli KiB ", size>>10);
}
else if(size < (uint64_t)2048*1024*1024) { // < 2 GiB
- printf("%4i MiB ", size>>20);
+ printf("%4lli MiB ", size>>20);
}
else if(size < (uint64_t)2048*1024*1024*1024) { // < 2 TiB
- printf("%4i GiB ", size>>30);
+ printf("%4lli GiB ", size>>30);
}
else { // Greater than 2 TiB (if your files are larger than this, you are Doing It Wrong [TM])
- printf("%4i TiB ", size>>40);
+ printf("%4lli TiB ", size>>40);
}
} else {
- printf("%8i ", size);
+ printf("%8lli ", size);
}
}
fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1))
fcn_obj2src = $(subst $(OBJECT_DIR),$(SOURCE_DIR),$(patsubst %$(OBJECT_SUFFIX).o,%,$1))
-fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval OBJ-$(DIR):=$(OBJ-$(DIR)) $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1)
+fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1) $(eval OBJ-$1:=$2)
# Start of Voodoo code
_REL_POS := $(dir $(lastword $(MAKEFILE_LIST)))
$(eval _dir=$(_DIR-$@))
@echo [AR] ru $@
@$(RM) $@
- @$(AR) ru $@ $(OBJ-$(_dir))
+ @$(AR) ru $@ $(OBJ-$@)
# Dynamic Library (.so)
%.so:
$(eval _dir=$(_DIR-$@))
@echo [LD] -shared -o $@
- @$(LD) $(LDFLAGS) -shared -soname $(basename $@) -o $@ $(filter %.o,$^) $(LDFLAGS-$(_dir))
+ @$(LD) $(LDFLAGS) -shared -soname $(notdir $@) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
# Executable (.bin)
%.bin:
$(eval _dir=$(_DIR-$@))
@echo [LD] -o $@
- @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir))
+ @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
@$(CP) $@ $(@:%.bin=%)
$(OUTPUTDIR)%:
$(eval _dir=$(_DIR-$@))
@echo [LD] -o $@
- @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir))
+ @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
-include $(ALL_OBJ:%=%.dep)