Re: New function in Left and right menu



Sorry!

Of course i forgot to attach the patch!

Anyway, some help:

The new function reads the datas from the ~/.mc/connections file.
The Syntax:

=Account name
prefix(/#ftp, /#sh ...)server
user name
password

=Account name2
.
.
.

Bye
Laszlo Suto

diff -urdN mc-2004-01-22-08/src/cmd.c mc-2004-01-22-08-connections/src/cmd.c
--- mc-2004-01-22-08/src/cmd.c	2003-11-27 18:52:56.000000000 +0100
+++ mc-2004-01-22-08-connections/src/cmd.c	2004-01-25 13:49:00.000000000 +0100
@@ -1177,6 +1177,139 @@
 	     "[FTP File System]", "/#ftp:", 1);
 }
 
+
+void connections_cmd (void)
+{
+    enum{
+	STATE_START,
+	STATE_READ,
+	STATE_END,
+	STATE_COMMENT
+    };
+
+    char *confile;
+    char *data;
+    Listbox *listbox;
+    struct CAccount *conn=NULL;
+    GList *current=NULL;
+    GList *cur=NULL;		//just for free the memory indeed
+    short int state=STATE_START;
+    short int read_num=0;
+    char *buffer=NULL;
+    int length=0;
+    char *cd_path=NULL;
+    int to_home;
+    char *prefix=g_new(char,20),*p=NULL;
+    char *machine=NULL;
+    
+    
+    confile=concat_dir_and_file(home_dir,MC_CONNECTIONS);
+    if( (data=load_file(confile)) == NULL ) {
+	message(1, MSG_ERROR,_("Cannot open file:%s \n %s"),confile,unix_error_string(errno));
+	g_free(confile);
+	return;
+    }
+    
+    listbox=create_listbox_window (60,10,_("Connections..."),"[Connections]");
+    
+    while(state!=STATE_END) {			//parse the Connections file
+
+	switch (state){
+	    case STATE_START:	switch(*data) {
+				    case '=':
+					state=STATE_READ;
+					conn=g_new(CAccount,1);
+					buffer=conn->accname;
+					break;
+				    case '#':state=STATE_COMMENT;break;
+				    case '\0':state=STATE_END;break;
+				}
+				break;
+				
+	    case STATE_READ:  if(*data!=' ' || *data!='\t')
+				if((*data=='\n' && read_num==3) || \
+	                              (*data=='\0' && read_num==3)) {
+					*buffer='\0';
+					state= (*data=='\n') ? STATE_START : STATE_END;
+					current=g_list_append(current,conn);
+
+					length=0;
+					read_num=0;
+				    } 
+				else if(*data=='\n'){
+					    *buffer='\0';
+					    switch(read_num){
+						case 0:buffer=(char *) conn->server;break;
+						case 1:buffer=(char *) conn->name;break;
+						case 2:buffer=(char *) conn->pass;break;
+					    }
+					    length=0;
+					    read_num++;    
+				    }
+				else	if(length++<254) *buffer++=*data;
+				break;
+				
+	    case STATE_COMMENT:	if(*data=='\n') state=STATE_START;
+				if(*data=='\0') state=STATE_END;
+				break;
+				
+	}
+	if(state!=STATE_END) data++;
+    
+    }
+    
+    cur=current;
+    while(current){
+	listbox_add_item (listbox->list,0,0,((CAccount *)(current->data))->accname,current);
+	current=g_list_next(current);
+    }
+	    
+    run_dlg (listbox->dlg);
+    
+    if(listbox->dlg->ret_value==B_CANCEL) current = NULL;
+         else	{ 
+		    current=listbox->list->current->data;
+		    conn=(CAccount *) current->data;
+	  }
+ 
+    destroy_dlg(listbox->dlg);
+    g_free (listbox);
+    g_free (confile);    
+    
+    if (!SELECTED_IS_PANEL)
+	return;
+
+    to_home = 0;	/* FIXME: how to solve going to home nicely? /~/ is 
+			   ugly as hell and leads to problems in vfs layer */
+
+    machine=conn->server;
+    p=prefix;
+    
+    while( *machine!=':' && *machine!='\0') {
+	    *prefix++=*machine;
+	     machine++;
+	 }
+    *prefix++=':';*prefix='\0';
+    machine++;
+    
+    if(*machine=='\0') {
+			g_list_free (cur);
+			return;    
+	}		
+	
+    cd_path = g_strconcat (p,conn->name,":\0",conn->pass,"@\0",machine, to_home ? "/~/" : NULL, NULL);
+    
+    if (do_panel_cd (MENU_PANEL, cd_path, 0))
+	directory_history_add (MENU_PANEL, (MENU_PANEL)->cwd);
+    else
+	message (1, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
+	
+    g_free (cd_path);
+    g_list_free (cur);
+    return;
+}
+
+
 void fishlink_cmd (void)
 {
     nice_cd (_(" Shell link to machine "), _(machine_str),
diff -urdN mc-2004-01-22-08/src/cmd.h mc-2004-01-22-08-connections/src/cmd.h
--- mc-2004-01-22-08/src/cmd.h	2003-10-24 22:10:01.000000000 +0200
+++ mc-2004-01-22-08-connections/src/cmd.h	2004-01-25 13:46:56.000000000 +0100
@@ -3,6 +3,7 @@
 
 void netlink_cmd (void);
 void ftplink_cmd (void);
+void connections_cmd (void);
 void fishlink_cmd (void);
 void smblink_cmd (void);
 void undelete_cmd (void);
@@ -57,4 +58,16 @@
 void quick_view_cmd (void);
 void toggle_listing_cmd (void);
 
+
+typedef struct CAccount
+{
+  char accname[255];
+  char server[255];
+  char name[255];
+  char pass[255];
+} CAccount;
+
+#define MC_CONNECTIONS		".mc/connections"
+
+
 #endif /* __CMD_H */
diff -urdN mc-2004-01-22-08/src/main.c mc-2004-01-22-08-connections/src/main.c
--- mc-2004-01-22-08/src/main.c	2003-11-14 21:43:12.000000000 +0100
+++ mc-2004-01-22-08-connections/src/main.c	2004-01-25 10:55:32.000000000 +0100
@@ -803,6 +803,7 @@
     {' ', N_("&Network link..."), 'N', netlink_cmd},
 #endif
     {' ', N_("FT&P link..."), 'P', ftplink_cmd},
+    {' ', N_("&Connections..."), 'C', connections_cmd},    
     {' ', N_("S&hell link..."), 'H', fishlink_cmd},
 #ifdef WITH_SMBFS
     {' ', N_("SM&B link..."), 'B', smblink_cmd},
@@ -827,6 +828,7 @@
     {' ', N_("&Network link..."), 'N', netlink_cmd},
 #endif
     {' ', N_("FT&P link..."), 'P', ftplink_cmd},
+    {' ', N_("&Connections..."), 'C', connections_cmd},
     {' ', N_("S&hell link..."), 'H', fishlink_cmd},
 #ifdef WITH_SMBFS
     {' ', N_("SM&B link..."), 'B', smblink_cmd},



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]