📄 linelist.c
字号:
list->sortKey = sortKey;
list->sortOrder = sortOrder;
} else if ((sortKey == 't') && (sortOrder == 'd')) {
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
ReverseTimeCmp);
list->sortKey = sortKey;
list->sortOrder = sortOrder;
} else if ((sortKey == 's') && (sortOrder == 'a')) {
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
SizeCmp);
list->sortKey = sortKey;
list->sortOrder = sortOrder;
} else if ((sortKey == 's') && (sortOrder == 'd')) {
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
ReverseSizeCmp);
list->sortKey = sortKey;
list->sortOrder = sortOrder;
} else if (sortKey == 'b') {
/* This is different from the rest. */
list->sortKey = sortKey;
list->sortOrder = sortOrder;
qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
BreadthFirstCmp);
}
} /* SortFileInfoList */
void
VectorizeFileInfoList(FileInfoListPtr list)
{
FileInfoVec fiv;
FileInfoPtr fip;
int i;
fiv = (FileInfoVec) calloc((size_t) (list->nFileInfos + 1), sizeof(FileInfoPtr));
if (fiv != (FileInfoVec) 0) {
for (i = 0, fip = list->first; fip != NULL; fip = fip->next, i++)
fiv[i] = fip;
list->vec = fiv;
}
} /* VectorizeFileInfoList */
void
UnvectorizeFileInfoList(FileInfoListPtr list)
{
FileInfoVec fiv;
FileInfoPtr fip;
int i, n;
fiv = list->vec;
if (fiv != (FileInfoVec) 0) {
list->first = fiv[0];
n = list->nFileInfos;
if (n > 0) {
list->last = fiv[n - 1];
fip = fiv[0];
fip->prev = NULL;
fip->next = fiv[1];
for (i = 1; i < n; i++) {
fip = fiv[i];
fip->prev = fiv[i - 1];
fip->next = fiv[i + 1];
}
}
free(fiv);
list->vec = (FileInfoVec) 0;
}
} /* UnvectorizeFileInfoList */
void
InitFileInfo(FileInfoPtr fip)
{
(void) memset(fip, 0, sizeof(FileInfo));
fip->type = '-';
fip->size = kSizeUnknown;
fip->mdtm = kModTimeUnknown;
} /* InitFileInfoList */
FileInfoPtr
RemoveFileInfo(FileInfoListPtr list, FileInfoPtr killMe)
{
FileInfoPtr nextFileInfo, prevFileInfo;
nextFileInfo = killMe->next;
prevFileInfo = killMe->prev;
if (killMe->lname != NULL) {
killMe->lname[0] = '\0'; /* Make it useless just in case. */
free(killMe->lname);
}
if (killMe->relname != NULL) {
killMe->relname[0] = '\0';
free(killMe->relname);
}
if (killMe->rname != NULL) {
killMe->rname[0] = '\0';
free(killMe->rname);
}
if (killMe->rlinkto != NULL) {
killMe->rlinkto[0] = '\0';
free(killMe->rlinkto);
}
if (killMe->plug != NULL) {
killMe->plug[0] = '\0';
free(killMe->plug);
}
if (list->first == killMe)
list->first = nextFileInfo;
if (list->last == killMe)
list->last = prevFileInfo;
if (nextFileInfo != NULL)
nextFileInfo->prev = prevFileInfo;
if (prevFileInfo != NULL)
prevFileInfo->next = nextFileInfo;
free(killMe);
list->nFileInfos--;
return (nextFileInfo);
} /* RemoveFileInfo */
/* Adds a string to the FileInfoList specified. */
FileInfoPtr
AddFileInfo(FileInfoListPtr list, FileInfoPtr src)
{
FileInfoPtr lp;
lp = (FileInfoPtr) malloc(sizeof(FileInfo));
if (lp != NULL) {
(void) memcpy(lp, src, sizeof(FileInfo));
lp->next = NULL;
if (list->first == NULL) {
list->first = list->last = lp;
lp->prev = NULL;
list->nFileInfos = 1;
} else {
lp->prev = list->last;
list->last->next = lp;
list->last = lp;
list->nFileInfos++;
}
}
return lp;
} /* AddFileInfo */
int
ConcatFileInfoList(FileInfoListPtr dst, FileInfoListPtr src)
{
FileInfoPtr lp, lp2;
FileInfo newfi;
for (lp = src->first; lp != NULL; lp = lp2) {
lp2 = lp->next;
newfi = *lp;
newfi.relname = StrDup(lp->relname);
newfi.lname = StrDup(lp->lname);
newfi.rname = StrDup(lp->rname);
newfi.rlinkto = StrDup(lp->rlinkto);
newfi.plug = StrDup(lp->plug);
if (AddFileInfo(dst, &newfi) == NULL)
return (-1);
}
return (0);
} /* ConcatFileInfoList */
int
ComputeRNames(FileInfoListPtr dst, const char *dstdir, int pflag, int nochop)
{
FileInfoPtr lp, lp2;
char *buf;
char *cp;
if (dstdir == NULL)
dstdir = ".";
for (lp = dst->first; lp != NULL; lp = lp2) {
lp2 = lp->next;
buf = NULL;
if (nochop != 0) {
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
if (Dynscat(&buf, dstdir, "/", lp->relname, 0) == NULL)
goto memerr;
if (pflag != 0) {
/* Init lname to parent dir name of remote dir */
cp = strrchr(dstdir, '/');
if (cp == NULL)
cp = strrchr(dstdir, '\\');
if (cp != NULL) {
if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
goto memerr;
TVFSPathToLocalPath(lp->lname);
}
}
} else {
if (Dynscat(&buf, lp->relname, 0) == NULL)
goto memerr;
}
} else {
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
cp = strrchr(lp->relname, '/');
if (cp == NULL)
cp = strrchr(lp->relname, '\\');
if (cp != NULL) {
cp++;
} else {
cp = lp->relname;
}
if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
goto memerr;
if (pflag != 0) {
/* Init lname to parent dir name of remote dir */
cp = strrchr(dstdir, '/');
if (cp == NULL)
cp = strrchr(dstdir, '\\');
if (cp != NULL) {
if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
goto memerr;
TVFSPathToLocalPath(lp->lname);
}
}
} else {
cp = strrchr(lp->relname, '/');
if (cp == NULL)
cp = strrchr(lp->relname, '\\');
if (cp != NULL) {
cp++;
} else {
cp = lp->relname;
}
if (Dynscat(&buf, cp, 0) == NULL)
goto memerr;
}
}
lp->rname = buf;
if (lp->rname == NULL) {
memerr:
return (-1);
}
LocalPathToTVFSPath(lp->rname);
}
return (0);
} /* ComputeRNames */
int
ComputeLNames(FileInfoListPtr dst, const char *srcdir, const char *dstdir, int nochop)
{
FileInfoPtr lp, lp2;
char *buf;
char *cp;
if (srcdir != NULL) {
cp = strrchr(srcdir, '/');
if (cp == NULL)
cp = strrchr(srcdir, '\\');
if (cp != NULL)
srcdir = cp + 1;
}
if (dstdir == NULL)
dstdir = ".";
for (lp = dst->first; lp != NULL; lp = lp2) {
lp2 = lp->next;
buf = NULL;
if (nochop != 0) {
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
if (Dynscat(&buf, dstdir, "/", 0) == NULL)
goto memerr;
}
if (lp->lname != NULL) {
if (Dynscat(&buf, lp->lname, "/", 0) == NULL)
goto memerr;
} else if (srcdir != NULL) {
if (Dynscat(&buf, srcdir, "/", 0) == NULL)
goto memerr;
}
if (Dynscat(&buf, lp->relname, 0) == NULL)
goto memerr;
} else {
if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
cp = strrchr(lp->relname, '/');
if (cp == NULL)
cp = strrchr(lp->relname, '\\');
if (cp == NULL) {
cp = lp->relname;
} else {
cp++;
}
if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
goto memerr;
} else {
cp = strrchr(lp->relname, '/');
if (cp == NULL)
cp = strrchr(lp->relname, '\\');
if (cp == NULL) {
cp = lp->relname;
} else {
cp++;
}
if (Dynscat(&buf, cp, 0) == NULL)
goto memerr;
}
}
if (buf == NULL) {
memerr:
return (-1);
}
if (lp->lname != NULL) {
free(lp->lname);
lp->lname = NULL;
}
lp->lname = buf;
TVFSPathToLocalPath(lp->lname);
}
return (0);
} /* ComputeLNames */
int
ConcatFileToFileInfoList(FileInfoListPtr dst, char *rfile)
{
FileInfo newfi;
InitFileInfo(&newfi); /* Use defaults. */
newfi.relname = StrDup(rfile);
newfi.rname = NULL;
newfi.lname = NULL;
if (AddFileInfo(dst, &newfi) == NULL)
return (-1);
return (0);
} /* ConcatFileToFileInfoList */
int
LineListToFileInfoList(LineListPtr src, FileInfoListPtr dst)
{
LinePtr lp, lp2;
InitFileInfoList(dst);
for (lp = src->first; lp != NULL; lp = lp2) {
lp2 = lp->next;
if (ConcatFileToFileInfoList(dst, lp->line) < 0)
return (-1);
}
return (0);
} /* LineListToFileList */
int
LineToFileInfoList(LinePtr lp, FileInfoListPtr dst)
{
InitFileInfoList(dst);
if (ConcatFileToFileInfoList(dst, lp->line) < 0)
return (-1);
return (0);
} /* LineToFileInfoList */
/* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -