The patch itself

Walery Studennikov despair at sama.ru
Sat Jul 28 23:13:50 UTC 2001


Sorry, forgot to include the patch itself
-------------- next part --------------
1350c1350
< void ftplink_cmd (void)
---
> static void ftplink_plain_cmd (void)
1354a1355,1492
> 
> static unsigned char get_hot_key( int n )
> {
>     return (n <= 9) ? '0' + n : 'a' + n - 10;
> }
> 
> struct ftplink_desc {
>     char *link;
>     char *title;
> };
> 
> void ftplink_cmd (void)
> {
>     FILE *f;
>     char buf[256], *cd_path, *title1;
>     int n_links, i, titlelen, maxlen = 0;
>     Listbox* listbox;
>     struct ftplink_desc *ftplinks = NULL;
> 
>     /* Open file with ftp links from the user home directory */
>     char *filename = concat_dir_and_file( home_dir, MC_FTPLINKS );
> 
>     if ( !( f = fopen( filename, "r" ) ) ) {
> 	sprintf( buf, _("Failed to open: %s"), filename );
> 	message( 1, _(" Error "), buf );
> 
> 	ftplink_plain_cmd();
> 	goto theend;
>     }
> 
>     /* How many links is there? */
>     for ( n_links=0; fgets( buf, sizeof buf, f ); )
> 	if ( buf[0] != '\n' && buf[0] != '\0' && buf [0] != '#' )
> 	    ++n_links;
>     rewind( f );
> 
>     if ( n_links <= 0 ) {
> 	sprintf( buf, _("There is no valid links in %s"), filename );
> 	message( 1, _(" Error "), buf );
> 
> 	ftplink_plain_cmd();
> 	goto theend_2;
>     }
> 
> 
> 
>     ftplinks = calloc( n_links + 1, sizeof(struct ftplink_desc) );
> 
>     /* Copy links to ftplinks */
>     for( n_links = 0; fgets( buf, sizeof buf, f ); ) {
> 	char *p = buf;
> 	int buflen = strlen( buf );
> 
> 	if ( *p == '\n' || *p == '\0' || *p == '#' )
> 	    continue;
> 
> 	if ( buflen > 0 && buf[ buflen - 1 ] == '\n' )
> 	    buf[ buflen - 1 ] = '\0';
> 
> 	while ( *p != '\t' && *p != ' ' && *p != '\0' )
> 	    ++p;
> 
> 	if ( *p == '\0' ) {
> 	    p = buf;
> 	    goto skip_title;
> 	}
> 
> 	*p++ = 0;
> 
> 	while ( *p == '\t' || *p == ' ' )
> 	    ++p;
> 	if ( *p == '\0' )
> 	    p = buf;
> 
> skip_title:
> 	/* buf - ftp link itself */
> 	/* p   - link description */
> 	ftplinks[n_links].link = strdup( buf );
> 	ftplinks[n_links].title = strdup( p );
> 
> 	titlelen = strlen( p );
> 	maxlen = (titlelen > maxlen) ? titlelen : maxlen;
> 
> 	++n_links;
>     }
> 
>     /* Create listbox and fill it with ftp links */
>     title1 = _("-  >> Old-style ftp dialog <<");
>     titlelen = strlen( title1 );
>     maxlen = (titlelen > maxlen) ? titlelen : maxlen;
> 
>     listbox = create_listbox_window(
> 	maxlen + 6, n_links + 1,
> 	_(" Choose ftp link "), "[Ftp Links]");
> 
>     LISTBOX_APPEND_TEXT( listbox, '-', title1, NULL );
> 
> 
>     for (i = 0; i < n_links; i++) {
> 	char buffer[255];
> 	sprintf( buffer, "%c  %s", get_hot_key(i), ftplinks[i].title );
> 	LISTBOX_APPEND_TEXT( listbox, get_hot_key(i), buffer,
> 			     ftplinks[i].link );
>     }
> 
> 
>     listbox_select_by_number( listbox->list, 0 );
>     i = run_listbox( listbox );
> 
>     if (i <= 0) {
> 	ftplink_plain_cmd();
> 	goto theend_3;
>     }
> 
>     --i;
>     cd_path = g_strconcat ("/#ftp:", ftplinks[i].link, NULL);
>     
>     if (do_panel_cd (MENU_PANEL, cd_path, 0))
> 	directory_history_add (MENU_PANEL, (MENU_PANEL)->cwd);
>     else
> 	message (1, MSG_ERROR, _(" Could not chdir to %s "), cd_path);
> 
>     g_free (cd_path);
> 
> theend_3:
>     for (i = 0; i < n_links; i++) {
> 	free( ftplinks[i].link );
> 	free( ftplinks[i].title );
>     }
>     free( ftplinks );
> 
> theend_2:
>     fclose( f );
> 
> theend:
>     g_free (filename);
> }
> 
-------------- next part --------------
--- user.orig.h	Thu Jul 26 17:18:38 2001
+++ user.h	Thu Jul 26 17:19:50 2001
@@ -23,6 +23,7 @@
 #   define MC_GLOBAL_MENU       "mc.mnu"
 #   define MC_HOME_MENU         "mc.mnu"
 #   define MC_HINT              "mc.hnt"
+#   define MC_FTPLINKS          "mc.ftp"
 #else
 #   define CEDIT_GLOBAL_MENU    "cedit.menu"
 #   define CEDIT_LOCAL_MENU     ".cedit.menu"
@@ -31,6 +32,7 @@
 #   define MC_LOCAL_MENU        ".mc.menu"
 #   define MC_HOME_MENU         ".mc/menu"
 #   define MC_HINT              "mc.hint"
+#   define MC_FTPLINKS          ".mc/ftplinks"
 #endif
 
 #endif


More information about the mc-devel mailing list