Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
stsaz committed Feb 1, 2025
1 parent 4ddac63 commit e0efaff
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 616 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ CFLAGS := -MMD -MP \
-Wall -Wextra -Wno-unused-parameter -Wno-multichar \
-fPIC \
-g
ifeq "$(CPU)" "amd64"
CFLAGS += -march=nehalem
endif
ifeq "$(DEBUG)" "1"
CFLAGS += -O0 -DFF_DEBUG -Werror
else
Expand All @@ -26,6 +23,10 @@ endif
ifeq "$(ASAN)" "1"
CFLAGS += -fsanitize=address
LINKFLAGS += -fsanitize=address
else
ifeq "$(CPU)" "amd64"
CFLAGS += -march=nehalem
endif
endif
CXXFLAGS := -std=c++11 $(CFLAGS)
CFLAGS := -std=c99 $(CFLAGS)
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ Contents:
| [textcount](src/text/textcount.c) | Analyze text files (e.g. print number of lines) |
| [utf8](src/text/utf8.c) | Convert files to UTF-8 |
| **Other:** | |
| [disana](src/text/disana.c) | Analyze disassembler listing |
| [hex](src/ops/hex.c) | Print file contents in hexadecimal format |
| [ico-extract](src/pic/ico-extract.c) | Extract images from .ico |
| [md5](src/ops/md5.c) | Compute MD5 hash |
| [pic](src/pic/pic.c) | Convert images (.bmp/.jpg/.png) |
| **Windows-only:** | |
| [listdisk](src/windows/listdisk.c) | List logical volumes |
| [mount](src/windows/mount.c) | Mount logical volumes |
| [reg](src/windows/reg.c) | Windows Registry utils: search |


Expand Down
2 changes: 0 additions & 2 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ OPERATION:
`pic` Convert images (.bmp/.jpg/.png)

Windows-only:
`listdisk` List logical volumes (Windows)
`mount` Mount logical volumes (Windows)
`reg` Windows Registry utils: search

INPUT:
Expand Down
14 changes: 10 additions & 4 deletions src/fcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#undef stdin
#undef stdout

#define FCOM_VER "1.0-rc17"
#define FCOM_CORE_VER 10017
#define FCOM_VER "1.0-rc18"
#define FCOM_CORE_VER 10018

typedef unsigned char byte;
typedef unsigned char u_char;
Expand Down Expand Up @@ -488,6 +488,7 @@ enum FCOM_SYNC_DIFF {
FCOM_SYNC_DIFF_NO_ATTR = 8,
FCOM_SYNC_DIFF_NO_TIME = 0x10,
FCOM_SYNC_DIFF_TIME_2SEC = 0x20,
FCOM_SYNC_DIFF_MOVE_NO_NAME = 0x40,
};

enum FCOM_SYNC {
Expand Down Expand Up @@ -549,6 +550,11 @@ struct fcom_sync_diff_entry {
void *id;
};

static inline void fcom_sync_diff_entry_destroy(struct fcom_sync_diff_entry *de) {
ffstr_free(&de->lname);
ffstr_free(&de->rname);
}

typedef struct snapshot fcom_sync_snapshot;
typedef struct diff fcom_sync_diff;
typedef struct fcom_sync_if fcom_sync_if;
Expand Down Expand Up @@ -576,8 +582,8 @@ struct fcom_sync_if {

/** Get diff entry.
flags: FCOM_SYNC_SWAP */
const struct fcom_sync_diff_entry* (*info)(fcom_sync_diff *sd, uint i, uint flags);
const struct fcom_sync_diff_entry* (*info_id)(fcom_sync_diff *sd, void *id, uint flags);
int (*info)(fcom_sync_diff *sd, uint i, uint flags, struct fcom_sync_diff_entry *dst);
int (*info_id)(fcom_sync_diff *sd, void *id, uint flags, struct fcom_sync_diff_entry *dst);

/** Update diff entry's status.
Return the resulting status. */
Expand Down
4 changes: 3 additions & 1 deletion src/fs/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ static int args_parse(struct copy *c, fcom_cominfo *cmd)
if (core->com->args_parse(cmd, args, c, FCOM_COM_AP_INOUT))
return -1;

if (!(cmd->chdir.len || cmd->output.len))
if (!(cmd->chdir.len || cmd->output.len)) {
fcom_errlog("please use --output or --chdir to set destination");
return -1;
}

if (cmd->stdout)
c->update = 0;
Expand Down
42 changes: 34 additions & 8 deletions src/fs/gsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static void gsync_signal(fcom_op *op, uint signal);
_(A_SYNC), \
_(A_SYNC_DATE), \
_(A_SWAP), \
_(A_DIFF_NO_DATE), \
_(A_DIFF_MOVE_NO_NAME), \
_(A_INCLUDE_CHANGE), \
_(A_EXCLUDE_CHANGE), \
_(A_RECENTDAYS_CHANGE), \
Expand Down Expand Up @@ -119,6 +121,7 @@ struct gsync {
fcom_sync_snapshot *lsnap, *rsnap;
fcom_sync_diff *diff;
struct fcom_sync_props props;
struct fcom_sync_diff_entry de;

uint show_flags; // enum FCOM_SYNC
xxvec include, exclude; // ffstr[]
Expand All @@ -127,10 +130,10 @@ struct gsync {
xxvec sync_items; // struct sync_el[]
uint sync_item_i;
fcom_task core_task;
uint sync_flags;
uint diff_flags, sync_flags;

ffthread thread;
ffui_menu mfile, mlist, mpopup;
ffui_menuxx mfile, mlist, mpopup;
struct wmain {
ffui_windowxx wnd;
ffui_menu mmenu;
Expand All @@ -145,6 +148,7 @@ struct gsync {

~gsync() {
diff_reset();
fcom_sync_diff_entry_destroy(&this->de);
}

void error(const char *e)
Expand Down Expand Up @@ -219,6 +223,8 @@ struct gsync {
{
gsync *g = (gsync*)param;
g->diff_reset();
ffmem_zero_obj(&g->props.stats);
g->stats_redraw();

ffui_thd_post(scan_status_update, g);
if (!(g->lsnap = g->scan(xxvec(g->wmain.lpath.text()).str()))) {
Expand All @@ -236,8 +242,8 @@ struct gsync {
uint f = FCOM_SYNC_DIFF_LEFT_PATH_STRIP
| FCOM_SYNC_DIFF_RIGHT_PATH_STRIP
| FCOM_SYNC_DIFF_NO_ATTR
// | FCOM_SYNC_DIFF_NO_TIME
| FCOM_SYNC_DIFF_TIME_2SEC;
f |= g->diff_flags;
g->diff = g->sync_if->diff(g->lsnap, g->rsnap, &g->props, f);

g->stats_redraw();
Expand Down Expand Up @@ -292,7 +298,9 @@ struct gsync {
const struct fcom_sync_diff_entry* entry_at(uint i)
{
uint f = (this->show_flags & FCOM_SYNC_SWAP);
return this->sync_if->info(this->diff, i, f);
fcom_sync_diff_entry_destroy(&this->de);
this->sync_if->info(this->diff, i, f, &this->de);
return &this->de;
}

void list_cell_draw(ffui_view_disp *disp)
Expand Down Expand Up @@ -479,6 +487,15 @@ struct gsync {
ffui_post_quitloop();
}

void diff_x(uint id, uint f)
{
if (this->diff_flags & f)
this->diff_flags &= ~f;
else
this->diff_flags |= f;
this->mfile.check(id, !!(this->diff_flags & f));
}

void show_x(ffui_checkboxxx &cb, uint flag)
{
if (cb.checked())
Expand Down Expand Up @@ -540,15 +557,18 @@ struct gsync {
}
}

static void wnd_new__worker(void *param)
void wnd_new()
{
static const char *argv[] = {
"fcom", "gsync", NULL
const char *argv[] = {
"fcom", "gsync", NULL, NULL, NULL
};
const char *exe_name = "fcom";
#ifdef FF_WIN
exe_name = "fcom.exe";
#endif
xxvec lpath = this->wmain.lpath.text(), rpath = this->wmain.rpath.text();
argv[2] = lpath.strz();
argv[3] = rpath.strz();
ffps ps = ffps_exec(xxvec(core->path(exe_name)).strz(), argv, core->env);
fcom_dbglog("spawned PID %u", ffps_id(ps));
ffps_close(ps);
Expand All @@ -566,7 +586,7 @@ struct gsync {

switch (id) {
case A_WND_NEW:
g->core_task_add(wnd_new__worker); break;
g->wnd_new(); break;

case A_SCAN_CMP:
g->core_task_add(scan_and_compare__worker); break;
Expand All @@ -579,6 +599,12 @@ struct gsync {
case A_SWAP:
g->src_dst_swap(); break;

case A_DIFF_NO_DATE:
g->diff_x(id, FCOM_SYNC_DIFF_NO_TIME); break;

case A_DIFF_MOVE_NO_NAME:
g->diff_x(id, FCOM_SYNC_DIFF_MOVE_NO_NAME); break;

case A_INCLUDE_CHANGE:
case A_EXCLUDE_CHANGE:
case A_RECENTDAYS_CHANGE:
Expand Down
12 changes: 10 additions & 2 deletions src/fs/gsync.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ menu mfile {
action A_SCAN_CMP
hotkey "F5"
}
item "Synchronize" {
item "Synchronize Selected" {
action A_SYNC
hotkey "F6"
}
item "Replace Date" {
item "Replace Date for Selected" {
action A_SYNC_DATE
hotkey "Ctrl+D"
}
item "Swap Source and Target" {
action A_SWAP
hotkey "Ctrl+W"
}
check_item "Diff: Ignore Date" {
action A_DIFF_NO_DATE
}
check_item "Diff: Move: Ignore Name" {
action A_DIFF_MOVE_NO_NAME
}
item "E_xit" {
action A_QUIT
hotkey "Ctrl+Q"
Expand All @@ -37,6 +43,7 @@ menu mlist {
menu mpopup {
item "Source: Exec" {
action A_SRC_EXEC
hotkey "Ctrl+X"
}
item "Source: Show Directory" {
action A_SRC_SHOW_DIR
Expand All @@ -46,6 +53,7 @@ menu mpopup {
}
item "Target: Exec" {
action A_DST_EXEC
hotkey "Ctrl+Shift+X"
}
item "Target: Show Directory" {
action A_DST_SHOW_DIR
Expand Down
54 changes: 30 additions & 24 deletions src/fs/sync-cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ struct diff {
const fntree_entry *r = (fntree_entry*)key;
const struct fcom_sync_entry *rd = (struct fcom_sync_entry*)fntree_data(r);

return l->name_len == r->name_len
&& !ffmem_cmp(l->name, r->name, l->name_len)
return ((sd->options & FCOM_SYNC_DIFF_MOVE_NO_NAME)
|| (l->name_len == r->name_len
&& !ffmem_cmp(l->name, r->name, l->name_len)))
&& ld->size == rd->size
&& ((sd->options & FCOM_SYNC_DIFF_NO_ATTR)
|| (ld->unix_attr & FFFILE_UNIX_DIR) == (rd->unix_attr & FFFILE_UNIX_DIR))
Expand All @@ -110,7 +111,11 @@ struct diff {
*(uint64*)key.mtime_msec = fftime_to_msec(&d->mtime);

*(uint64*)key.size = d->size;
ffuint n = 1+8+8 + ffmem_ncopy(key.name, sizeof(key.name), e->name, e->name_len);

uint n = 1+8+8;
if (!(this->options & FCOM_SYNC_DIFF_MOVE_NO_NAME))
n += ffmem_ncopy(key.name, sizeof(key.name), e->name, e->name_len);

return murmurhash3(&key, n, 0x789abcde);
}

Expand Down Expand Up @@ -167,6 +172,7 @@ struct diff {
le = NULL, lb = NULL; break;
}

FF_ASSERT(ents.len < ents.cap);
fntree_cmp_ent *ce = ffvec_pushT(&this->ents, fntree_cmp_ent);
ce->status = 0;
ce->l = le;
Expand Down Expand Up @@ -346,11 +352,9 @@ static uint sync_view(fcom_sync_diff *sd, struct fcom_sync_props *props, uint fl
|| (rd && (rd->unix_attr & FFFILE_UNIX_DIR))))
continue;

if (flags & FCOM_SYNC_SWAP) {
if (rd && fftime_cmp(&rd->mtime, &props->since_time) < 0)
continue;
} else {
if (ld && fftime_cmp(&ld->mtime, &props->since_time) < 0)
if (props->since_time.sec) {
if ((!ld || fftime_cmp(&ld->mtime, &props->since_time) < 0)
&& (!rd || fftime_cmp(&rd->mtime, &props->since_time) < 0))
continue;
}

Expand Down Expand Up @@ -390,34 +394,36 @@ static uint sync_view(fcom_sync_diff *sd, struct fcom_sync_props *props, uint fl
b = __tmp; \
})

static const fcom_sync_diff_entry* sync_info_id(fcom_sync_diff *sd, void *id, uint flags)
static int sync_info_id(fcom_sync_diff *sd, void *id, uint flags, fcom_sync_diff_entry *dst)
{
ffmem_zero_obj(dst);
fntree_cmp_ent *ce = (fntree_cmp_ent*)id;
sd->dif_ent.status = ce->status;
snapshot::full_name(&sd->lname, ce->l, ce->lb);
snapshot::full_name(&sd->rname, ce->r, ce->rb);
sd->dif_ent.lname = sd->lname.str();
sd->dif_ent.rname = sd->rname.str();
sd->dif_ent.left = (ce->l) ? (struct fcom_sync_entry*)fntree_data(ce->l) : NULL;
sd->dif_ent.right = (ce->r) ? (struct fcom_sync_entry*)fntree_data(ce->r) : NULL;
dst->status = ce->status;
ffvec lname = {}, rname = {};
snapshot::full_name(&lname, ce->l, ce->lb);
snapshot::full_name(&rname, ce->r, ce->rb);
dst->lname = *(ffstr*)&lname;
dst->rname = *(ffstr*)&rname;
dst->left = (ce->l) ? (struct fcom_sync_entry*)fntree_data(ce->l) : NULL;
dst->right = (ce->r) ? (struct fcom_sync_entry*)fntree_data(ce->r) : NULL;

if (flags & FCOM_SYNC_SWAP) {
sd->dif_ent.status = status_swap(ce->status);
FF_SWAP2(sd->dif_ent.lname, sd->dif_ent.rname);
FF_SWAP2(sd->dif_ent.left, sd->dif_ent.right);
dst->status = status_swap(ce->status);
FF_SWAP2(dst->lname, dst->rname);
FF_SWAP2(dst->left, dst->right);
}

sd->dif_ent.id = ce;
return &sd->dif_ent;
dst->id = ce;
return 0;
}

static const fcom_sync_diff_entry* sync_info(fcom_sync_diff *sd, uint i, uint flags)
static int sync_info(fcom_sync_diff *sd, uint i, uint flags, fcom_sync_diff_entry *dst)
{
if (i >= sd->filter.len)
return NULL;
return -1;

fntree_cmp_ent *ce = *ffslice_itemT(&sd->filter, i, fntree_cmp_ent*);
return sync_info_id(sd, ce, flags);
return sync_info_id(sd, ce, flags, dst);
}

static uint sync_status(fcom_sync_diff *sd, void *id, uint mask, uint val)
Expand Down
Loading

0 comments on commit e0efaff

Please sign in to comment.