aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flx/Makefile2
-rw-r--r--flx/fct1.c13
-rw-r--r--flx/flx.h3
-rw-r--r--flx/input_file.c7
-rw-r--r--flx/main.c1
-rw-r--r--flx/output_file.c8
-rw-r--r--flx/utils.c58
-rw-r--r--flx/utils.h9
-rw-r--r--flx/utils.h.orig187
9 files changed, 275 insertions, 13 deletions
diff --git a/flx/Makefile b/flx/Makefile
index d78b873..23e1491 100644
--- a/flx/Makefile
+++ b/flx/Makefile
@@ -26,7 +26,7 @@
NAME=flx
-VERSION=0.6.9
+VERSION=0.7.0
SRC=main.c arg.c utils.c md5.c flx.c fct1.c check.c sign.c \
input.c input_fs.c input_file.c \
output.c output_file.c
diff --git a/flx/fct1.c b/flx/fct1.c
index 6402f50..622add7 100644
--- a/flx/fct1.c
+++ b/flx/fct1.c
@@ -362,22 +362,27 @@ char *build_line(char *path, char *filename, t_file_desc *info) {
else
s += sprintf(blk+s, "%10ld ", st->st_mtime);
- s += sprintf(blk+s, "%s", backslashed_str(path, " \\\n()\t"));
+ s += sprintf(blk+s, "%s", escape_str(path));
if (S_ISLNK(st->st_mode) && info->link)
- s += sprintf(blk+s, " %s", backslashed_str(info->link, " \\\n()\t"));
+ s += sprintf(blk+s, " %s", escape_str(info->link));
}
else {
if (IS(Options, GOPT_HUMAN_READABLE))
s += sprintf(blk+s, "? 0000(-) % 5d % 5d % 10d -------------------------------- %10d(-) %s",0 , 0, 0, 0,
- backslashed_str(path, " \\\n()\t"));
+ escape_str(path));
else
s += sprintf(blk+s, "? 0000 % 5d % 5d % 10d -------------------------------- %10d %s",0 , 0, 0, 0,
- backslashed_str(path, " \\\n()\t"));
+ escape_str(path));
}
return (blk);
}
+/* return formatted info into a static string */
+char *show_filename(char *path, char *filename, t_file_desc *info) {
+ return (path);
+}
+
/* view files with recursive method */
void dump_tree_(t_ft *tree, int force) {
diff --git a/flx/flx.h b/flx/flx.h
index 68e351f..6c71355 100644
--- a/flx/flx.h
+++ b/flx/flx.h
@@ -8,7 +8,7 @@
#include "utils.h"
#include "md5.h"
-#define COPYRIGHT "Copyright 2002, Benoit DOLEZ <bdolez@ant-computing.com>"
+#define COPYRIGHT "Copyright 2002-2004, Benoit DOLEZ <bdolez@ant-computing.com>"
#define DUMPBASENAME "formilux-sig.dat"
@@ -219,6 +219,7 @@ extern char *checksum_md5_from_data(char *data, int len) ;
extern char *end_field(char *line) ;
extern int mkdir_with_parent(char *pathname, mode_t mode) ;
extern char *build_line(char *path, char *filename, t_file_desc *info) ;
+extern char *show_filename(char *path, char *filename, t_file_desc *info) ;
extern void dump_tree(t_ft *tree) ;
extern int dump_diff_tree(t_dtree *tree);
extern int files_are_the_same(t_file_desc *f1, t_file_desc *f2, int Diff, char *path) ;
diff --git a/flx/input_file.c b/flx/input_file.c
index 5a4b0c5..ec50c02 100644
--- a/flx/input_file.c
+++ b/flx/input_file.c
@@ -4,6 +4,7 @@
#include <sys/types.h>
#include <stdlib.h>
#include <dirent.h>
+#include <ctype.h>
#include "input_file.h"
#include "utils.h"
@@ -42,6 +43,10 @@ char **get_field1(char *line) {
*pline++ = *(line+1);
line += 2 ;
}
+ else if (*line == '%' && isxdigit(*(line+1)) && isxdigit(*(line+2))) {
+ *pline++ = HEX2DEC(line[1])*16+HEX2DEC(line[2]);
+ line += 3;
+ }
else {
*pline++ = *line++ ;
}
@@ -116,7 +121,7 @@ t_file_desc *fill_from_signfs_line(char **tab, char **rpath, t_file_desc **desc)
if (p1[0] != '-') {
for (i = 0 ; p1[i] ; i++)
temp[i] = (unsigned char)
- (HEXTODEC(p1[i * 2]) * 16 + HEXTODEC(p1[i * 2 + 1]));
+ (HEX2DEC(p1[i * 2]) * 16 + HEX2DEC(p1[i * 2 + 1]));
(*desc)->md5 = MALLOC(i);
memcpy((*desc)->md5, temp, i);
}
diff --git a/flx/main.c b/flx/main.c
index 7d82047..98d6153 100644
--- a/flx/main.c
+++ b/flx/main.c
@@ -33,6 +33,7 @@ char *Progname = NULL;
#define FLX_SIGN 1
#define FLX_CHECK 2
+#define FLX_LS 3
t_param FLX_poptions[] = {
diff --git a/flx/output_file.c b/flx/output_file.c
index cbfed4e..e50a717 100644
--- a/flx/output_file.c
+++ b/flx/output_file.c
@@ -12,6 +12,7 @@
#define OPT_SORTED 0x01
#define OPT_WRITE 0x02
+#define OPT_LS 0x04
/* affiche le contenu d'un répertoire à partir de l'emplacement spécifié en
* reprenant son nom
@@ -145,6 +146,9 @@ int output_file_write_(t_file_status *desc, t_ft *tree,
}
int output_file_write(t_file_status *desc, t_ft *tree, int number) {
+ if ((desc->options & OPT_LS) == OPT_LS)
+ return (output_file_write_(desc, tree, number, show_filename));
+ else
return (output_file_write_(desc, tree, number, build_line));
}
@@ -190,6 +194,8 @@ t_file_status *output_file_open(char *pathname, char *opts) {
options = (sign > 0 ? (options|OPT_SORTED) : (options&~OPT_SORTED));
else if (!strcmp(popts, "level") && pvalue) /* recurse level */
new->recursion = atoi(pvalue);
+ else if (!strcmp(popts, "ls")) /* just list flag */
+ options = options|OPT_LS;
else {
error("unknown option : %s", popts);
FREE(new);
@@ -198,6 +204,8 @@ t_file_status *output_file_open(char *pathname, char *opts) {
popts = t;
}
+ new->options = options;
+
filename = ppath;
if (ppath && (ppath = backslashed_strmchr(ppath, DELIM_LIST))) {
status = *ppath++;
diff --git a/flx/utils.c b/flx/utils.c
index 96a52ae..79af51c 100644
--- a/flx/utils.c
+++ b/flx/utils.c
@@ -5,9 +5,12 @@
#include <sys/types.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <ctype.h>
#include "utils.h"
+static char bigbuffer[BUFFLEN];
+
POOL_INIT(p2void);
// fonction to return write in 'ls -l' format
@@ -118,17 +121,62 @@ char *backslashed_strmchr(char *s, char *mc) {
/* return the string with characters 'toback' backslashed */
char *backslashed_str(char *s, char *toback) {
- static char buff[BUFFLEN];
- char *pbuff = buff;
+ char *pbuff = bigbuffer;
+ int len = 0;
- while (*s) {
+ while (*s && len < (BUFFLEN-1)) {
if (strchr(toback, *s)) {
*pbuff++ = '\\';
}
*pbuff++ = *s++;
}
- *pbuff = 0;
- return (buff);
+ bigbuffer[len] = 0;
+ return (bigbuffer);
+}
+
+/* escape unprintable char with its hexadecimal value (url encode form) */
+char *escape_str(char *s) {
+ char *pbuff = bigbuffer;
+ int len = 0;
+
+ while (*s && len < (BUFFLEN-4)) {
+ if (flx_is_graph(*s)) {
+ *pbuff++ = *s++;
+ len++;
+ }
+ else {
+ *pbuff++ = '%';
+ *pbuff++ = DEC2HEX(*s/16);
+ *pbuff++ = DEC2HEX(*s%16);
+ s++;
+ len += 3;
+ }
+ }
+ bigbuffer[len] = 0;
+ return (bigbuffer);
+}
+
+/* unescape string from %xx string form */
+char *unescape_str(char *s) {
+ char *pbuff = bigbuffer;
+ int len = 0;
+
+ while (*s && len < (BUFFLEN-1)) {
+ if (*s == '\\') {
+ s++;
+ *pbuff++ = *s++;
+ }
+ else if (*s == '%' && isxdigit(*(s+1)) && isxdigit(*(s+2))) {
+ *pbuff++ = HEX2DEC(s[1])*16+HEX2DEC(s[2]);
+ s += 3;
+ }
+ else {
+ *pbuff++ = *s++;
+ }
+ len++;
+ }
+ bigbuffer[len] = 0;
+ return (bigbuffer);
}
void *push_str_sorted(void *ptr, char *str) {
diff --git a/flx/utils.h b/flx/utils.h
index 17c1991..984fc7a 100644
--- a/flx/utils.h
+++ b/flx/utils.h
@@ -58,7 +58,12 @@ typedef unsigned char u_char;
#define PFERROR(str...) PFERROR2(str, 0)
#define PFERROR2(str, p...) pferror("%s:%d: " str, __FILE__, __LINE__, ##p)
-#define HEXTODEC(a) (('0'<=(a) && (a)<='9')?(a)-'0':(a)-'a'+10)
+
+#define DEC2HEX(c) ({unsigned char __c=(c);(__c<10)?(__c+'0'):(__c-10+'a'); })
+#define HEX2DEC(c) ({unsigned char __c=(c);('0'<=__c&&__c<='9')?(__c-'0'):\
+ ('A'<=__c&&__c<='F')?(__c-'A'+10):\
+ (__c-'a'+10); })
+#define flx_is_graph(x) ({int __c = (x); __c > 0x20 && __c < 0x7f && __c != '%' && __c != '\\' && __c != '$'; })
#ifdef MEM_OPTIM
@@ -183,5 +188,7 @@ char *backslashed_strchr(char *s, char c);
char *backslashed_strmchr(char *s, char *mc);
char *backslashed_str(char *, char *toback);
void *push_str_sorted(void *ptr, char *str);
+char *escape_str(char *s);
+char *unescape_str(char *s);
#endif /* __UTILS_H__ */
diff --git a/flx/utils.h.orig b/flx/utils.h.orig
new file mode 100644
index 0000000..17c1991
--- /dev/null
+++ b/flx/utils.h.orig
@@ -0,0 +1,187 @@
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <malloc.h>
+#include <string.h>
+#include <stdio.h>
+
+#define BUFFER_LENGTH 8192
+#define FILENAME_LENGTH 4096
+
+#define MALLOC(size) ({ \
+ void *__var; \
+ if (!(__var = malloc(size))) { \
+ PFERROR("malloc(%d)", size); \
+ exit(2); \
+ } \
+ __var; \
+})
+
+#define CALLOC(nb, size) ({ \
+ void *__var; \
+ if (!(__var = calloc(nb, size))) { \
+ PFERROR("calloc(%d, %d)", nb, size); \
+ exit(2); \
+ } \
+ __var; \
+})
+
+#define FREE(ptr) free(ptr)
+
+#define STRDUP(str) ({ \
+ char *__var; \
+ if (!(__var = strdup(str))) { \
+ PFERROR("strdup(%s)", str); \
+ exit(2); \
+ } \
+ __var; \
+})
+
+#define GET_UMASK() ({mode_t __mask = umask(0); umask(__mask); __mask; })
+
+
+#define IS(v, f) (((v) & (f)) == (f))
+#define SET(v, f) ((v) |= (f))
+#define UNSET(v, f) ((v) &= ~(f))
+
+
+#ifndef __USE_BSD
+typedef unsigned int u_int;
+typedef unsigned char u_char;
+#endif
+
+
+#define BUFFLEN BUFFER_LENGTH
+
+#define PFERROR(str...) PFERROR2(str, 0)
+#define PFERROR2(str, p...) pferror("%s:%d: " str, __FILE__, __LINE__, ##p)
+#define HEXTODEC(a) (('0'<=(a) && (a)<='9')?(a)-'0':(a)-'a'+10)
+
+
+#ifdef MEM_OPTIM
+/*
+ * Returns a pointer to type <type> taken from the
+ * pool <pool_type> or dynamically allocated. In the
+ * first case, <pool_type> is updated to point to the
+ * next element in the list.
+ */
+#define POOL_ALLOC(type) ({ \
+ void *p; \
+ if ((p = pool_##type) == NULL) \
+ p = malloc(sizeof(type)); \
+ else { \
+ pool_##type = *(void **)pool_##type; \
+ } \
+ p; \
+})
+
+/*
+ * Puts a memory area back to the corresponding pool.
+ * Items are chained directly through a pointer that
+ * is written in the beginning of the memory area, so
+ * there's no need for any carrier cell. This implies
+ * that each memory area is at least as big as one
+ * pointer.
+ */
+#define POOL_FREE(type, ptr) ({ \
+ *(void **)ptr = (void *)pool_##type; \
+ pool_##type = (void *)ptr; \
+})
+#define POOL_INIT(type) type *pool_##type = NULL
+#define POOL_INIT_PROTO(type) extern type *pool_##type
+
+#else
+#define POOL_ALLOC(type) (calloc(1,sizeof(type)));
+#define POOL_FREE(type, ptr) (free(ptr));
+#define POOL_INIT
+#endif /* MEM_OPTIM */
+
+
+typedef void *p2void[2];
+
+/* initialise memory pool for list managing */
+
+#define PUSH_STR_SORTED(ptr, str) (ptr = push_str_sorted(ptr, str))
+
+/* unusable!!!
+ * #define SIMPLE_LIST_FOREACH(list, data, current, next) \
+ * for(current = list; \
+ * (next = SIMPLE_LIST_NEXT(current), data = SIMPLE_LIST_PTR(current), current); \
+ * current = next)
+ */
+
+#define SIMPLE_LIST_FLUSH(list) ( { \
+ while (list) SIMPLE_LIST_POP(list); \
+})
+
+#define SIMPLE_LIST_NEXT_PTR(list) (SIMPLE_LIST_PTR(SIMPLE_LIST_NEXT(list)))
+#define SIMPLE_LIST_NEXT(list) (*(((void**)(list))))
+#define SIMPLE_LIST_PTR(list) (*(((void**)(list)) + 1))
+#define SIMPLE_LIST_INIT() POOL_INIT(p2void)
+
+#define SIMPLE_LIST_PUSH(list, elem) ( { \
+ void **__new; \
+ __new = POOL_ALLOC(p2void); \
+ __new[0] = (void*)(list); \
+ __new[1] = (void*)(elem); \
+ (list) = (void *)__new; \
+})
+
+#define SIMPLE_LIST_FILE(list, elem) ( { \
+ void **__next = list; \
+ if (!list) { \
+ __next = POOL_ALLOC(p2void); \
+ (list) = (void*)__next; \
+ } else { \
+ while (SIMPLE_LIST_NEXT(__next)) __next = SIMPLE_LIST_NEXT(__next); \
+ SIMPLE_LIST_NEXT(__next) = POOL_ALLOC(p2void); \
+ __next = SIMPLE_LIST_NEXT(__next); \
+ } \
+ __next[0] = NULL; \
+ __next[1] = (void*)(elem); \
+} )
+
+
+#define SIMPLE_LIST_DEFILE(list) SIMPLE_LIST_POP(list)
+#define SIMPLE_LIST_POP(list) ( { \
+ void **__old = (void **)list, *__elem = NULL; \
+ if (list) { \
+ list = __old[0]; \
+ __elem = __old[1]; \
+ POOL_FREE(p2void, __old); \
+ } \
+ __elem ; \
+})
+
+
+#define LIST_CHAIN(pprev, pnew, pnext) ({ \
+ (pnew)->prev = pprev; \
+ (pnew)->next = pnext; \
+ (pnew)->prev->next = pnew; \
+ (pnew)->next->prev = pnew; \
+})
+
+#define LIST_UNCHAIN(pold) ({ \
+ (pold)->prev->next = (pold)->next; \
+ (pold)->next->prev = (pold)->prev; \
+})
+
+
+POOL_INIT_PROTO(p2void);
+
+char *right(mode_t mode);
+char *dirname(char *);
+char *basename(char *);
+int error(char *,...);
+void warning(char *,...);
+int fatal_error(char *,...);
+int pferror(char *,...);
+char *backslashed_strchr(char *s, char c);
+char *backslashed_strmchr(char *s, char *mc);
+char *backslashed_str(char *, char *toback);
+void *push_str_sorted(void *ptr, char *str);
+
+#endif /* __UTILS_H__ */