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

📄 dial.c

📁 minicom 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			  d3 = dialents;			  while (d3 != (struct dialent*)NULL) {			  	if (!strcmp(d3->name, d->name))			  		d3->flags &= ~FL_TAG;			  	d3 = d3->next;			  }							}				/*  er 27-Apr-99 */			return(retst);		}		for(f = 0; f < 3; f++) {			if (f == 0) t = P_MNOCON1;			if (f == 1) t = P_MNOCON2;			if (f == 2) t = P_MNOCON3;			if (f == 3) t = P_MNOCON4;			if ((*t) && (!strncmp(modbuf, t, strlen(t)))) {				if (retries < maxretries) {					x = dialfailed(t, rdelay);					if (x < 0) {						keyboard(KSTOP, 0);						wclose(dialwin, 1);						return(retst);					}				}				if (maxretries == 1) reason = t;				goto MainLoop;			}		}	    }	    /* Do timer routines here. */	    time(&now);	    if (last != now) {		dialtime -= (now - last);		if (dialtime < 0) dialtime = 0;		wlocate(dialwin, 11, 4);		wprintf(dialwin, "%-3d  ", dialtime);		if (dialtime <= 0) {			mputs(P_MDIALCAN, 0);			reason = _("Timeout");			retst = -1;			if (retries < maxretries) {				x = dialfailed(reason, rdelay);				if (x < 0) {					keyboard(KSTOP, 0);					wclose(dialwin, 1);					return(retst);				}			}		}	    }	    last = now;	}  } /* End of main while cq MainLoop */	  dialfailed(reason, -1);  keyboard(KSTOP, 0);  wclose(dialwin, 1);  return(retst);}/* * Create an empty entry. */static struct dialent *mkstdent(){  struct dialent *d;    d = (struct dialent *)malloc(sizeof (struct dialent));    if (d == (struct dialent *)0) return(d);  d->name[0] = 0;  d->number[0] = 0;  d->script[0] = 0;  d->username[0] = 0;  d->password[0] = 0;  d->term = 1;  d->dialtype = 0;  d->flags = FL_DEL;  strcpy(d->baud, "Curr");  strcpy(d->bits, "8");  strcpy(d->parity, "N");  d->lastdate[0] = 0;	/* jl 22.06.97 */  d->lasttime[0] = 0;  d->count = 0;  d->convfile[0] = 0;	/* jl 21.09.97 */  strcpy(d->stopb, "1");  d->next = (struct dialent *)0;  return(d);}/* Read version 4 of the dialing directory. */void v4_read(fp, d, dv)struct dialent *d;FILE *fp;struct dver *dv;	/* jl 21.09.97 */{  (void) fread((char *)d, dv->size, (size_t)1, fp);  if (dv->size < sizeof(struct dialent)) {    if (dv->size < offsetof(struct dialent, count) + sizeof(struct dialent *)){      d->count = 0;      d->lasttime[0] = 0;      d->lastdate[0] = 0;    }    if (dv->size < offsetof(struct dialent, stopb) + sizeof(struct dialent *))      d->convfile[0]=0;    strcpy(d->stopb, "1");  }}/* Read version 3 of the dialing directory. */void v3_read(fp, d)struct dialent *d;FILE *fp;{  struct v3_dialent v3;   /* jl 22.06.97 */  (void) fread((char *)&v3, sizeof(v3), (size_t)1, fp);  memcpy(d, &v3, offsetof(struct v3_dialent, next));    d->lastdate[0]=0;  d->lasttime[0]=0;  d->count=0;  d->convfile[0]=0;  strcpy(d->stopb, "1");}/* Read version 2 of the dialing directory. */void v2_read(fp, d)struct dialent *d;FILE *fp;{  struct v3_dialent v3;   /* jl 22.06.97 */  (void) fread((char *)&v3, sizeof(v3), (size_t)1, fp);  memcpy(d, &v3, offsetof(struct v3_dialent, next));  if (d->flags & FL_ANSI) d->flags |= FL_WRAP;  d->lastdate[0]=0;  d->lasttime[0]=0;  d->count=0;  d->convfile[0]=0;  strcpy(d->stopb, "1");}/* Read version 1 of the dialing directory. */void v1_read(fp, d)FILE *fp;struct dialent *d;{  struct v1_dialent v1;  fread((char *)&v1, sizeof(v1), (size_t)1, fp);  memcpy(d->username, v1.username, sizeof(v1) - offsetof(struct v1_dialent, username));  strncpy(d->name, v1.name, sizeof(d->name));  strncpy(d->number, v1.number, sizeof(d->number));  strncpy(d->script, v1.script, sizeof(d->script));  d->lastdate[0]=0;  d->lasttime[0]=0;  d->count=0;  d->convfile[0]=0;  strcpy(d->stopb, "1");}/* Read version 0 of the dialing directory. */void v0_read(fp, d)FILE *fp;struct dialent *d;{  v1_read(fp, d);  d->dialtype = 0;  d->flags = 0;}/* * Read in the dialing directory from $HOME/.dialdir */int readdialdir(){  long size;  FILE *fp;  char dfile[256];  char copycmd[512];  static int didread = 0;  int f;  struct dialent *d = NULL, *prev = (struct dialent *)0;  struct dver dial_ver;  WIN *w;  if (didread) return(0);  didread = 1;  nrents = 1;  tagged = (char *)malloc(1);  tagged[0] = 0;  /* Make the manual dial entry. */  d_man = mkstdent();  strcpy(d_man->name, _("Manually entered number"));  /* Construct path */  snprintf(dfile, sizeof(dfile), "%s/.dialdir", homedir);  /* Try to open ~/.dialdir */  if ((fp = sfopen(dfile, "r")) == (FILE *)NULL) {	if (errno == EPERM) {		werror(_("Cannot open ~/.dialdir: permission denied"));		dialents = mkstdent();		dendd = 1;		return(0);	}  	dialents = mkstdent();  	return(0);  }  /* Get size of the file */  fseek(fp, 0L, SEEK_END);  size = ftell(fp);  if (size == 0) {  	dialents = mkstdent();  	fclose(fp);  	return(0);  }  /* Get version of the dialing directory */  fseek(fp, 0L, SEEK_SET);  fread(&dial_ver, sizeof(dial_ver), 1, fp);  if (dial_ver.magic != DIALMAGIC) {	/* First version without version info. */	dial_ver.version = 0;	fseek(fp, 0L, SEEK_SET);  } else	size -= sizeof(dial_ver);  /* See if the size of the file is allright. */  switch(dial_ver.version) {	case 0:	case 1:		dial_ver.size = sizeof(struct v1_dialent);		break;	case 2:	case 3:		dial_ver.size = sizeof(struct v3_dialent);		break;	case 4:	  /* dial_ver.size = sizeof(struct dialent); */	  /* Removed the forced setting to add flexibility.	   * Now you don't need to change the version number	   * if you just add fields to the end of the dialent structure	   * before the *next pointer and don't change existing fields.	   * Just update the initialization in the functions	   * v4_read and mkstdent (and whatever you added the field for)	   * jl 21.09.97	   */	  	if (dial_ver.size < 200 ||		    dial_ver.size > sizeof(struct dialent)) {		  werror(_("Phonelist garbled (unknown version?)"));		  dendd = 1;		  dialents = mkstdent();		  return(-1);		}		break;	default:  		werror(_("Unknown dialing directory version"));		dendd = 1;  		dialents = mkstdent();  		return(-1);  }  if (size % dial_ver.size != 0) {  	werror(_("Phonelist garbled (?)"));  	fclose(fp);	dendd = 1;  	dialents = mkstdent();  	return(-1);  }  /* Read in the dialing entries */  nrents = size / dial_ver.size;  if (nrents == 0) {	dialents = mkstdent();	nrents = 1;	fclose(fp);	return(0);  }  for(f = 1; f <= nrents; f++) {  	if ((d = (struct dialent *)malloc(sizeof (struct dialent))) ==  		(struct dialent *)0) {  			if(f == 1)				dialents = mkstdent();			else				prev->next = (struct dialent *)0;  			werror(_("Out of memory while reading dialing directory"));			fclose(fp);  			return(-1);  	}	switch(dial_ver.version) {		case 0:			v0_read(fp, d);			break;		case 1:			v1_read(fp, d);			break;		case 2:			v2_read(fp, d);			break;		case 3:			v3_read(fp, d);			break;		case 4:			v4_read(fp, d, &dial_ver);			break;	}	/* MINIX terminal type is obsolete */	if (d->term == 2) d->term = 1;  	if (prev != (struct dialent *)0)  		prev->next = d;  	else  		dialents = d;  	prev = d;  }  d->next = (struct dialent *)0;  fclose(fp);  if (dial_ver.size < sizeof(struct dialent)) {    if (snprintf(copycmd,sizeof(copycmd),	     "cp %s %s.%hd",dfile,dfile,dial_ver.size) > 0) {      if (P_LOGFNAME[0] != 0)	do_log("%s", copycmd);      if (system(copycmd) == 0) {	snprintf(copycmd,sizeof(copycmd),		 _("Old dialdir copied as %s.%hd"),dfile,dial_ver.size);	w=mc_tell("%s", copycmd);	if (w) {	  sleep(2);	  wclose(w,1);	}	writedialdir();      }    }  }  return(0);}/* * Write the new $HOME/.dialdir */static void writedialdir(){  struct dialent *d;  char dfile[256];  FILE *fp;  struct dver dial_ver;  char oldfl;  int omask;  /* Make no sense if access denied */  if (dendd) return;  snprintf(dfile, sizeof(dfile), "%s/.dialdir", homedir);  omask = umask(077);  if ((fp = sfopen(dfile, "w")) == (FILE *)0) {	(void)umask(omask);  	werror(_("Can't write to ~/.dialdir"));	dendd = 1;  	return;  }  (void)umask(omask);  d = dialents;  /* Set up version info. */  dial_ver.magic = DIALMAGIC;  dial_ver.version = 4;  dial_ver.size = sizeof(struct dialent);  dial_ver.res1 = 0;	/* We don't use these res? fields, but let's */  dial_ver.res2 = 0;	/* initialize them to a known init value for */  dial_ver.res3 = 0;	/* whoever needs them later / jl 22.09.97    */  dial_ver.res4 = 0;  fwrite(&dial_ver, sizeof(dial_ver), (size_t)1, fp);  /* Write dialing directory */  while(d) {	oldfl = d->flags;	d->flags &= FL_SAVE;  	if (fwrite(d, sizeof(struct dialent), (size_t)1, fp) != 1) {  		werror(_("Error writing ~/.dialdir!"));  		fclose(fp);  		return;  	}	d->flags = oldfl;  	d = d->next;  }  fclose(fp);}/* * Get entry "no" in list. */static struct dialent *getno(no)int no;{  struct dialent *d;    d = dialents;    if (no >= nrents) return((struct dialent *)NULL);  while(no--) d = d->next;  return(d);}/* Note: Minix does not exist anymore. */static char *te[] = { "VT102", "MINIX", "ANSI " };/* * Edit an entry. */static void dedit(d)struct dialent *d;{  WIN *w;  int c;  char* name = _(" A -  Name                :"),      * number = _(" B -  Number              :"),      * dial_string = _(" C -  Dial string #       :"),      * local_echo = _(" D -  Local echo          :"),      * script = _(" E -  Script              :"),      * username = _(" F -  Username            :"),      * password = _(" G -  Password            :"),      * terminal_emulation = _(" H -  Terminal Emulation  :"),      * backspace_key_sends = _(" I -  Backspace key sends :"),      * linewrap = _(" J -  Linewrap            :"),      * line_settings = _(" K -  Line Settings       :"),      * conversion_table = _(" L -  Conversion table    :"),      * question = _("Change which setting?");    w = wopen(5, 4, 75, 19, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);  wprintf(w, "%s %s\n", name, d->name);  wprintf(w, "%s %s\n", number, d->number);  wprintf(w, "%s %d\n", dial_string, d->dialtype + 1);  wprintf(w, "%s %s\n", local_echo, _(yesno(d->flags & FL_ECHO)));  wprintf(w, "%s %s\n", script, d->script);  wprintf(w, "%s %s\n", username, d->username);  wprintf(w, "%s %s\n", password, d->password);  wprintf(w, "%s %s\n", terminal_emulation, te[d->term - 1]);  wprintf(w, "%s %s\n", backspace_key_sends,	d->flags & FL_DEL ? _("Delete") : _("Backspace"));  wprintf(w, "%s %s\n", linewrap,	d->flags & FL_WRAP ? _("On") : _("Off"));  wprintf(w, "%s %s %s%s%s\n", line_settings,  	d->baud, d->bits, d->parity, d->stopb);  wprintf(w, "%s %s\n", conversion_table, d->convfile);  wprintf(w, _("      Last dialed         : %s %s\n"),d->lastdate,d->lasttime);  wprintf(w, _("      Times on            : %d"),d->count);  wlocate(w, 4, 15);  wputs(w, question);  wredraw(w, 1);  while(1) {      wlocate(w, strlen (question) + 5, 15);      c = wxgetch();      if (c >= 'a') c -= 32;      switch(c) {        case '\033':        case '\r':  	case '\n':  		wclose(w, 1);  		return;  	case 'A':  		wlocate(w, strlen (name) + 1, 0);  		(void) wgets(w, d->name, 31, 32);  		break;  	case 'B':  		wlocate(w, strlen (number) + 1, 1);  		(void) wgets(w, d->number, 31, 32);  		break;	case 'C':		d->dialtype = (d->dialtype + 1) % 3;		wlocate(w, strlen (dial_string) + 1, 2);		wprintf(w, "%d", d->dialtype + 1);		wflush();		break;	case 'D':		d->flags ^= FL_ECHO;		wlocate(w, strlen (local_echo) + 1, 3);		wprintf(w, "%s", _(yesno(d->flags & FL_ECHO)));		wflush();		break;  	case 'E':  		wlocate(w, strlen (script) + 1, 4);  		(void) wgets(w, d->script, 31, 32);	  		break;  	case 'F':  		wlocate(w, strlen (username) + 1, 5);  		(void) wgets(w, d->username, 31, 32);  		break;  	case 'G':  		wlocate(w, strlen (password) + 1, 6);  		(void) wgets(w, d->password, 31, 32);  		break;	  	case 'H':  		d->term = (d->term % 3) + 1;		/* MINIX == 2 is obsolete. */		if (d->term == 2) d->term = 3;  		wlocate(w, strlen (terminal_emulation) + 1, 7);  		wputs(w, te[d->term - 1]);			/* Also set backspace key. */		if (d->term == ANSI) {			d->flags &= ~FL_DEL;			d->flags |= FL_WRAP;		} else {			d->flags &= ~FL_WRAP;			d->flags |= FL_DEL;		}		wlocate(w, strlen (backspace_key_sends) + 1, 8);		wputs(w, d->flags & FL_DEL ? _("Delete   ") : _("Backspace"));		wlocate(w, strlen (linewrap) + 1, 9);		wputs(w, d->flags & FL_WRAP ? _("On ") : _("Off"));  		break;	case 'I':		d->flags ^= FL_DEL;		wlocate(w, strlen (backspace_key_sends) + 1, 8);		wputs(w, d->flags & FL_DEL ? _("Delete   ") : _("Backspace"));		break;	case 'J':		d->flags ^= FL_WRAP;		wlocate(w, strlen (linewrap) + 1, 9);		wputs(w, d->flags & FL_WRAP ? _("On ") : _("Off"));		break;  	case 'K':  		get_bbp(d->baud, d->bits, d->parity, d->stopb, 1);  		wlocate(w, strlen (line_settings) + 1, 10);  		wprintf(w, "%s %s%s%s  ",			d->baud, d->bits, d->parity, d->stopb);  		break; 	case 'L':	/* jl 21.09.97 */		wlocate(w, strlen (conversion_table) + 1, 11);		(void) wgets(w, d->convfile, 15, 16);		break;  	default:  		break;      }  }}static WIN *dsub;static char *what =          N_("  Dial    Find    Add     Edit   Remove   moVe   Manual ");/*          12345678901234567890123456789012345678901234567890123456		     1         2         3         4         5       */static int dprev;#define DIALOPTS 7   /* Number of commands in vertical dial menu *//* * Highlight a choice in the horizontal menu. */static void dhili(position_dialing_directory, k)int position_dialing_directory, k;{  /* acme@conectiva.com.br 28/02/1998      hack to make i18n strings work with _this_ hack ;> :     the i18n string must have a options with the same size (padded 

⌨️ 快捷键说明

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