6feb1cc405
Implement percent ('%') filename expansion in the "pipe" widget of the save/pipe dialog. Especially useful for setting Knews*shellfield.buffer in ${XENVIRONMENT}. Count articles for save/pipe command as "1 of N", "2 of N", and so on.
138 lines
2.9 KiB
Text
138 lines
2.9 KiB
Text
$NetBSD: patch-be,v 1.1 2001/08/15 06:09:02 fredb Exp $
|
|
|
|
--- src/expand.c.orig Fri Jan 9 11:16:29 1998
|
|
+++ src/expand.c
|
|
@@ -110,49 +110,46 @@
|
|
return dest;
|
|
}
|
|
|
|
-char *expand_path(char *file_name)
|
|
+char *expand_save_text(char *src)
|
|
{
|
|
- char *path = NULL;
|
|
+ char *dest = NULL;
|
|
long len = 0, pos = 0;
|
|
char ch;
|
|
|
|
- if (file_name[0] == '~' && file_name[1] == '/')
|
|
- file_name += 2;
|
|
-
|
|
- for (ch = *file_name++ ; ch != '\0' ; ch = *file_name++) {
|
|
+ for (ch = *src++ ; ch != '\0' ; ch = *src++) {
|
|
if (pos + 8 > len) {
|
|
len = pos + 256;
|
|
- path = XtRealloc(path, len);
|
|
+ dest = XtRealloc(dest, len);
|
|
}
|
|
|
|
if (ch != '%')
|
|
- path[pos++] = ch;
|
|
+ dest[pos++] = ch;
|
|
else {
|
|
char *p, *c = NULL;
|
|
int cap = False;
|
|
int slash = False;
|
|
int clen = 0;
|
|
|
|
- ch = *file_name++;
|
|
+ ch = *src++;
|
|
switch (ch) {
|
|
case '%':
|
|
- path[pos++] = '%';
|
|
+ dest[pos++] = '%';
|
|
continue; /* don't fall through */
|
|
case 'a':
|
|
case 'A':
|
|
if (global.mode != NewsModeGroup &&
|
|
global.mode != NewsModeThread) {
|
|
fputs("knews: Not in a newsgroup!\n", stderr);
|
|
- XtFree(path);
|
|
+ XtFree(dest);
|
|
return NULL;
|
|
}
|
|
if (!global.curr_art) {
|
|
fputs("knews: No selected article!\n", stderr);
|
|
- XtFree(path);
|
|
+ XtFree(dest);
|
|
return NULL;
|
|
}
|
|
- sprintf(path + pos, "%ld", global.curr_art->no);
|
|
- pos += strlen(path + pos);
|
|
+ sprintf(dest + pos, "%ld", global.curr_art->no);
|
|
+ pos += strlen(dest + pos);
|
|
continue;
|
|
case 'g':
|
|
slash = True;
|
|
@@ -180,7 +177,7 @@
|
|
c = global.nntp_server;
|
|
if (!c) {
|
|
fputs("knews: nntp_server is NULL!\n", stderr);
|
|
- XtFree(path);
|
|
+ XtFree(dest);
|
|
return NULL;
|
|
}
|
|
p = strchr(c, ':');
|
|
@@ -192,7 +189,7 @@
|
|
default:
|
|
fprintf(stderr,
|
|
"knews: %%%c: Unknown format specifier.\n", ch);
|
|
- XtFree(path);
|
|
+ XtFree(dest);
|
|
return NULL;
|
|
}
|
|
|
|
@@ -202,7 +199,7 @@
|
|
clen = strlen(c);
|
|
} else {
|
|
fputs("knews: Not in a newsgroup.\n", stderr);
|
|
- XtFree(path);
|
|
+ XtFree(dest);
|
|
return NULL;
|
|
}
|
|
|
|
@@ -210,7 +207,7 @@
|
|
continue;
|
|
if (pos + clen + 8 > len) {
|
|
len = pos + clen + 256;
|
|
- path = XtRealloc(path, len);
|
|
+ dest = XtRealloc(dest, len);
|
|
}
|
|
|
|
ch = *c++;
|
|
@@ -219,18 +216,32 @@
|
|
if (cap && islower((unsigned char)ch))
|
|
ch = toupper((unsigned char)ch);
|
|
|
|
- path[pos++] = ch;
|
|
+ dest[pos++] = ch;
|
|
while (clen-- > 0) {
|
|
ch = *c++;
|
|
|
|
if (ch == '.' && slash)
|
|
ch ='/';
|
|
- path[pos++] = ch;
|
|
+ dest[pos++] = ch;
|
|
}
|
|
- path[pos] = '\0';
|
|
+ dest[pos] = '\0';
|
|
}
|
|
}
|
|
- path[pos] = '\0';
|
|
+ dest[pos] = '\0';
|
|
+
|
|
+ return dest;
|
|
+}
|
|
+
|
|
+char *expand_path(char *file_name)
|
|
+{
|
|
+ char *path = NULL;
|
|
+
|
|
+ if (file_name[0] == '~' && file_name[1] == '/')
|
|
+ file_name += 2;
|
|
+
|
|
+ path = expand_save_text(file_name);
|
|
+ if (!path)
|
|
+ return NULL;
|
|
|
|
return path;
|
|
}
|