temp = (char *)calloc(1, (strlen(lynx_temp_space) + 60)); if (temp == NULL) outofmem(__FILE__, "change_sug_filename");
PUBLIC void change_sug_filename ARGS1(	char *,		fname){    char *temp, *cp, *cp1, *end;#ifdef VMS    char *dot;    int j, k;#endif /* VMS */    /*     *	Establish the current end of fname.     */    end = fname + strlen(fname);    /*     *	Unescape fname.     */    HTUnEscape(fname);    /*     *	Rename any temporary files.     */    temp = (char *)calloc(1, (strlen(lynx_temp_space) + 60));    if (temp == NULL)	outofmem(__FILE__, "change_sug_filename");    cp = wwwName(lynx_temp_space);    if (LYIsHtmlSep(*cp)) {	sprintf(temp, "file://localhost%s%d", cp, (int)getpid());    } else {	sprintf(temp, "file://localhost/%s%d", cp, (int)getpid());    }    if (!strncmp(fname, temp, strlen(temp))) {	cp = strrchr(fname, '.');	if (strlen(cp) > (strlen(temp) - 4))	    cp = NULL;	strcpy(temp, (cp ? cp : ""));	strcpy(fname, "temp");	strcat(fname, temp);    }    FREE(temp);    if (fname[strlen(fname) - 1] == '/')    /*     *  Hmm... we have a directory name.     *  It is annoying to see a scheme+host+path name as a suggested one,     *  let's remove the last_slash and go ahead like we have a file name. - LP     */    fname[strlen(fname) - 1] = '\0';    /*     *	Remove everything up the the last_slash if there is one.     */    if ((cp = strrchr(fname,'/')) != NULL && strlen(cp) > 1) {	cp1 = fname;	/*	 *  Go past the slash.	 */	cp++;	for (; *cp != '\0'; cp++, cp1++) {	    *cp1 = *cp;	}	*cp1 = '\0';    }    /*     *	Trim off date-size suffix, if present.     */    if ((*(end - 1) == ']') && ((cp = strrchr(fname, '[')) != NULL) &&	(cp > fname) && *(--cp) == ' ') {	while (*cp == ' ') {	    *(cp--) = '\0';	}    }    /*     *	Trim off VMS device and/or directory specs, if present.     */    if ((cp = strchr(fname,'[')) != NULL &&	(cp1 = strrchr(cp,']')) != NULL && strlen(cp1) > 1) {	cp1++;	for (cp=fname; *cp1 != '\0'; cp1++) {	    *(cp++) = *cp1;	}	*cp = '\0';    }#ifdef VMS    /*     *	Replace illegal or problem characters.     */    dot = fname + strlen(fname);    for (cp = fname; cp < dot; cp++) {	/*	 *  Replace with underscores.	 */	if (*cp == ' ' || *cp == '/' || *cp == ':' ||	    *cp == '[' || *cp == ']' || *cp == '&') {	    *cp = '_';	/*	 *  Replace with dashes.	 */	} else if (*cp == '!' || *cp == '?' || *cp == '\'' ||		   *cp == ',' || *cp == ':' || *cp == '\"' ||		   *cp == '+' || *cp == '@' || *cp == '\\' ||		   *cp == '(' || *cp == ')' || *cp == '=' ||		   *cp == '<' || *cp == '>' || *cp == '#' ||		   *cp == '%' || *cp == '*' || *cp == '`' ||		   *cp == '~' || *cp == '^' || *cp == '|' ||		   *cp <  ' ' || ((unsigned char)*cp) > 126) {	    *cp = '-';	}    }    /*     *	Collapse any serial underscores.     */    cp = fname + 1;    j = 0;    while (cp < dot) {	if (fname[j] == '_' && *cp == '_') {	    cp++;	} else {	    fname[++j] = *cp++;	}    }    fname[++j] = '\0';    /*     *	Collapse any serial dashes.     */    dot = fname + (strlen(fname));    cp = fname + 1;    j = 0;    while (cp < dot) {	if (fname[j] == '-' && *cp == '-') {	    cp++;	}  else {	    fname[++j] = *cp++;	}    }    fname[++j] = '\0';    /*     *	Trim any trailing or leading     *	underscores or dashes.     */    cp = fname + (strlen(fname)) - 1;    while (*cp == '_' || *cp == '-') {	*cp-- = '\0';    }    if (fname[0] == '_' || fname[0] == '-') {	dot = fname + (strlen(fname));	cp = fname;	while ((*cp == '_' || *cp == '-') && cp < dot) {	    cp++;	}	j = 0;	while (cp < dot) {	    fname[j++] = *cp++;	}	fname[j] = '\0';    }    /*     *	Replace all but the last period with _'s, or second     *	to last if last is followed by a terminal Z or z,     *	or GZ or gz,     *	e.g., convert foo.tar.Z to     *		      foo.tar_Z     *	  or, convert foo.tar.gz to     *		      foo.tar-gz     */    j = strlen(fname) - 1;    if ((dot = strrchr(fname, '.')) != NULL) {	if (TOUPPER(fname[j]) == 'Z') {	    if ((fname[j-1] == '.') &&		(((cp = strchr(fname, '.')) != NULL) && cp < dot)) {		*dot = '_';		dot = strrchr(fname, '.');	    } else if (((TOUPPER(fname[j-1]) == 'G') &&			fname[j-2] == '.') &&		       (((cp = strchr(fname, '.')) != NULL) && cp < dot)) {		*dot = '-';		dot = strrchr(fname, '.');	    }	}	cp = fname;	while ((cp = strchr(cp, '.')) != NULL && cp < dot) {	    *cp = '_';	}	/*	 *  But if the root is > 39 characters, move	 *  the period appropriately to the left.	 */	while (dot - fname > 39) {	    *dot = '\0';	    if ((cp = strrchr(fname, '_')) != NULL) {		*cp  = '.';		*dot = '_';	    } else if ((cp = strrchr(fname, '-')) != NULL) {		*cp  = '.';		*dot = '_';	    } else if (*(dot + 1) == '\0') {		j = strlen(fname);		while (j > 39) {		    fname[j] = fname[j-1];		    j--;		}		fname[j] = '.';	    } else {		*dot = '.';		j = 39;		k = 0;		while (dot[k] != '\0') {		    fname[j++] = dot[k++];		}		fname[j] = '\0';	    }	    dot = strrchr(fname, '.');	}	/*	 *  Make sure the extension is < 40 characters.	 */	if ((fname + strlen(fname) - dot) > 39) {	    *(dot + 40) = '\0';	}	/*	 *  Trim trailing dashes or underscores.	 */	j = (strlen(fname) - 1);	while (fname[j] == '_' || fname[j] == '-') {	    fname[j--] = '\0';	}    } else {	/*	 *  No period, so put one on the end, or after	 *  the 39th character, trimming trailing dashes	 *  or underscores.	 */	if (strlen(fname) > 39) {	    fname[39] = '\0';	}	j = (strlen(fname) - 1);	while ((fname[j] == '_') || (fname[j] == '-')) {	    j--;	}	fname[++j] = '.';	fname[++j] = '\0';    }#else /* Not VMS (UNIX): */    /*     *	Replace problem characters.     */    for (cp = fname; *cp != '\0'; cp++) {	switch (*cp) {	    case '\'':	    case '\"':	    case '/':	    case ' ':		*cp = '-';	}    }#endif /* VMS (UNIX) */    /*     *	Make sure the rest of the original string in nulled.     */    cp = fname + strlen(fname);    while (cp < end) {	*cp++ = '\0';    }    return;}