⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcmdxfer.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*+-------------------------------------------------------------------------	pcmdxfer.c - ecu file transfer related procedure commands	wht@n4hgf.Mt-Park.GA.US  Defined functions:	_adjust_erc_and_iv0(adj_erc)	_make_bottom_label(param,default_flag,sending_flag)	_pcmd_report_send_status()	_smart_sender_common(cmd)	pcmd_rk(param)	pcmd_rs(param)	pcmd_rx(param)	pcmd_ry(param)	pcmd_rz(param)	pcmd_sk(param)	pcmd_ss(param)	pcmd_sx(param)	pcmd_sy(param)	pcmd_sz(param)--------------------------------------------------------------------------*//*+:EDITS:*//*:10-21-1992-19:15-wht@n4hgf-proc file xfer didnt learn about eculibdir *//*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 *//*:09-05-1992-15:35-wht@n4hgf-add -r to sz *//*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA *//*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 *//*:04-23-1991-23:44-wht@n4hgf-big time overhaul - better but flames expected *//*:04-23-1991-05:10-wht@n4hgf-new cmd build mechanism for long file lists *//*:01-17-1991-17:01-wht@n4hgf-skipped files in sz aborted proc *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "ecu.h"#include "ecukey.h"#include "ecuerror.h"#include "esd.h"#include "var.h"#include "proc.h"/* * file transmission command and pathname list ESD initial size * (lengths can grow to ESD_MAXSIZE) */#define CMDESD_INITIAL_SIZE  384 /* executable command initial size */#define PATHESD_INITIAL_SIZE 256 /* pathname list initial size */#define CMDSTR_SIZE          384 /* receive command string size */extern int proctrace;extern int last_child_wait_status;extern char curr_dir[CURR_DIRSIZ];static char bottom_label[80];/*+-------------------------------------------------------------------------	_make_bottom_label(param,default_flag)--------------------------------------------------------------------------*/int_make_bottom_label(param,default_flag,sending_flag)ESD *param;int default_flag;int sending_flag;{register erc;ESD *label = (ESD *)0;	if(default_flag)	{		sprintf(bottom_label,			(sending_flag) ? "-C \"'Connected to %s'\" "			               : "-C 'Connected to %s' ",			(shm->Lrname[0]) ? shm->Lrname : "?");		return(0);	}	if((label = esdalloc(64)) == (ESD *)0)		return(eNoMemory);	if(erc = gstr(param,label,0))	{		esdfree(label);		return(erc);	}	strcpy(bottom_label,(sending_flag) ? "-C \"'" : "-C '");	strcat(bottom_label,label->pb);	strcat(bottom_label,(sending_flag) ? "'\"" : "'");	esdfree(label);	return(0);}	/* end of _make_bottom_label *//*+-------------------------------------------------------------------------	_adjust_erc_and_iv0(adj_erc)--------------------------------------------------------------------------*/int_adjust_erc_and_iv0(adj_erc)int adj_erc;{	if(adj_erc)		return(adj_erc);	iv[0] = (last_child_wait_status & 0xFF)			? 0x100L : (long)((last_child_wait_status >> 8) & 0xFFFF);	if(proctrace)		pprintf("$i00 = %ld (transfer %s)\n",iv[0],			(iv[0] == 0x100L) ? "interrupted" : "program exit status");	return(0);}	/* end of _adjust_erc_and_iv0 *//*+-------------------------------------------------------------------------	_pcmd_report_send_status() - report file transmission resultfor "ecu knowledgeable" protocols onlyreturns proc-type erc--------------------------------------------------------------------------*/int_pcmd_report_send_status(){register ushort ustmp;int erc = eFATAL_ALREADY;int iv0_set = 0;char *signal_name_text();	ustmp = last_child_wait_status;	if((ustmp & 0xFF) == 0)	/* exit() called */	{		ustmp >>= 8;		if(!ustmp)		{			if(proctrace)				pputs("transfer successful\n");			erc = 0;		}		else if(ustmp == 255)			pputs("ecu error: transfer program usage error\n");		else if(ustmp == 254)		{			pputs(			"protocol failure: bad line conditions or remote not ready\n");		}		else if(ustmp == 253)			pputs("no requested files exist\n");		else if(ustmp < 128)		{			if(proctrace)			{				if(ustmp == 127)					pputs("127 or more files skipped\n");				else					pprintf("%u files rejected\n",ustmp);			}			iv[0] = (long)ustmp;			iv0_set = 1;			last_child_wait_status = 0;			erc = 0;		}		else		{			pprintf("transfer aborted by %s\n",signal_name_text(ustmp & 0x7F));			erc = eProcAttn_Interrupt;		}	}	else	{		pprintf("transfer killed by %s\n",signal_name_text(ustmp & 0x7F));		erc = eProcAttn_Interrupt;	}	if(!iv0_set)	{		iv[0] = (last_child_wait_status & 0xFF)			? 0x100L : (long)((last_child_wait_status >> 8) & 0xFFFF);	}	if(proctrace)		pprintf("$i00 = %ld (transfer %s)\n",iv[0],			(iv[0] == 0x100L) ? "interrupted" : "program exit status");	return(erc);}	/* end of _pcmd_report_send_status *//*+-------------------------------------------------------------------------	_smart_sender_common(cmd) - common exec and bottom processingfor "ecu knowledgeable" protocols onlyreturns proc-type erc--------------------------------------------------------------------------*/int_smart_sender_common(cmd)char *cmd;{int erc = 0;	last_child_wait_status = 0;	file_xfer_start();	if(find_shell_chars(cmd))	{	char *expcmd;		if(expand_wildcard_list(cmd,&expcmd))		{			pputs("No files match wildcard list\n");			iv[0] = -1;			return(0);		}		else		{			exec_cmd(expcmd);			erc = _pcmd_report_send_status();			free(expcmd);		}	}	else	{		exec_cmd(cmd);		erc = _pcmd_report_send_status();	}	lreset_ksr();	file_xfer_done_bell();	return(erc);}	/* end of _smart_sender_common *//*+-------------------------------------------------------------------------	pcmd_sx(param)sx [-ak[l]] [<label-str>] <filelist-str>--------------------------------------------------------------------------*/intpcmd_sx(param)ESD *param;{int erc;char switches[8];ESD *pathesd = (ESD *)0;ESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);	get_switches(param,switches,sizeof(switches));	if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))		return(erc);	/*	 * build command at beginning of 'cmdesd' ESD	 */	sprintf(cmdesd->pb,"%s/ecusz -X -. %d ",eculibdir,shm->Liofd);	strcat(cmdesd->pb,bottom_label);#if defined(WHT)	/* for testing */	if(strchr(switches,'p'))		strcat(cmdesd->pb,"-, ");#endif	if(strchr(switches,'a'))		strcat(cmdesd->pb,"-a ");	if(strchr(switches,'k'))		strcat(cmdesd->pb,"-k");	/*	 * update cmdesd esd	 */	cmdesd->cb = strlen(cmdesd->pb);	if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))	{		erc = eNoMemory;		goto FREE_MEM_AND_EXIT;	}	/*	 * get list of pathnames to send	 */	if(erc = gstr(param,pathesd,1))		goto FREE_MEM_AND_EXIT;	/*	 * append filelist to command	 */	if(erc = esdcat(cmdesd,pathesd,1))		goto FREE_MEM_AND_EXIT;	/*	 * perform the operation	 */	erc = _smart_sender_common(cmdesd->pb);FREE_MEM_AND_EXIT:	if(pathesd)		esdfree(pathesd);	if(cmdesd)		esdfree(cmdesd);	return(erc);}	/* end of pcmd_sx *//*+-------------------------------------------------------------------------	pcmd_sy(param)sy [-a[l]] [<label-str>] <filelist-str>--------------------------------------------------------------------------*/intpcmd_sy(param)ESD *param;{int erc;char switches[8];ESD *pathesd = (ESD *)0;ESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);	get_switches(param,switches,sizeof(switches));	if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))		return(erc);	/*	 * build command at beginning of 'cmdesd' ESD	 */	sprintf(cmdesd->pb,"%s/ecusz -Y -. %d ",eculibdir,shm->Liofd);	strcat(cmdesd->pb,bottom_label);	if(strchr(switches,'a'))		strcat(cmdesd->pb,"-a ");	else		strcat(cmdesd->pb,"-b ");	/*	 * update cmdesd esd	 */	cmdesd->cb = strlen(cmdesd->pb);	if(!(pathesd = esdalloc(PATHESD_INITIAL_SIZE)))	{		erc = eNoMemory;		goto FREE_MEM_AND_EXIT;	}	/*	 * get list of pathnames to send	 */	if(erc = gstr(param,pathesd,1))		goto FREE_MEM_AND_EXIT;	/*	 * append filelist to command	 */	if(erc = esdcat(cmdesd,pathesd,1))		goto FREE_MEM_AND_EXIT;	/*	 * perform the operation	 */	erc = _smart_sender_common(cmdesd->pb);FREE_MEM_AND_EXIT:	if(pathesd)		esdfree(pathesd);	if(cmdesd)		esdfree(cmdesd);	return(erc);}	/* end of pcmd_sy *//*+-------------------------------------------------------------------------	pcmd_sz(param)sz [-anf[l]] [<label-str>] <filelist-str>-a ascii, else binary-n send only newer, else all files-f full, else simple pathnames-r resume interrupted xfer-l non-default bottom line label on transfer string$i0 set to:	0: file transfer completely successful	-1 program did not run--------------------------------------------------------------------------*/intpcmd_sz(param)ESD *param;{int erc;char switches[8];ESD *pathesd = (ESD *)0;ESD *cmdesd = esdalloc(CMDESD_INITIAL_SIZE);	if(!cmdesd)		return(eNoMemory);	get_switches(param,switches,sizeof(switches));	if(erc = _make_bottom_label(param,!strchr(switches,'l'),1))		return(erc);	/*	 * build command at beginning of 'cmdesd' ESD	 */	sprintf(cmdesd->pb,"%s/ecusz -Z -. %d ",eculibdir,shm->Liofd);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -