* Expand a string, substituting any "%" with the current filename,
* and any "#" with the previous filename and an initial "!" with
extern char *current_file
, *previous_file
;
* Make one pass to see how big a buffer we
* need to allocate for the expanded string.
for (fr
= s
; *fr
!= '\0'; fr
++)
if (s
== fr
&& t
== (char *) 0) {
error("no previous command");
n
+= (s
== fr
) ? strlen(t
) : 1;
n
+= (current_file
!= (char *) 0) ?
strlen(current_file
) : 1;
n
+= (previous_file
!= (char *) 0) ?
strlen(previous_file
) : 1;
if ((e
= (char *) calloc(n
+1, sizeof(char))) == (char *) 0) {
error("cannot allocate memory");
* Now copy the string, expanding any "%" or "#".
for (fr
= s
; *fr
!= '\0'; fr
++)
if (current_file
== (char *) 0)
strcpy(to
, current_file
);
if (previous_file
== (char *) 0)
strcpy(to
, previous_file
);