putpkt (buf) char *buf;
putpkt (char *buf)
putpkt (buf)     char *buf;{  int i;  unsigned char csum = 0;  char buf2[PBUFSIZ];  int cnt = strlen (buf);  int ch;  int tcount = 0;  char *p;  /* Copy the packet into buffer BUF2, encapsulating it     and giving it a checksum.  */  if (cnt > (int) sizeof (buf2) - 5)		/* Prosanity check */    abort();  p = buf2;  *p++ = '$';  for (i = 0; i < cnt; i++)    {      csum += buf[i];      *p++ = buf[i];    }  *p++ = '#';  *p++ = tohex ((csum >> 4) & 0xf);  *p++ = tohex (csum & 0xf);  /* Send it over and over until we get a positive ack.  */  while (1)    {      int started_error_output = 0;      if (remote_debug)	{	  *p = '\0';	  printf_unfiltered ("Sending packet: %s...", buf2);	  gdb_flush(gdb_stdout);	}      if (SERIAL_WRITE (remote_desc, buf2, p - buf2))	perror_with_name ("putpkt: write failed");      /* read until either a timeout occurs (-2) or '+' is read */      while (1)	{	  ch = readchar (remote_timeout); 	  if (remote_debug)	    {	      switch (ch)		{		case '+':		case SERIAL_TIMEOUT:		case '$':		  if (started_error_output)		    {		      putchar_unfiltered ('\n');		      started_error_output = 0;		    }		}	    }	  switch (ch)	    {	    case '+':	      if (remote_debug)		printf_unfiltered("Ack\n");	      return 1;	    case SERIAL_TIMEOUT:	      tcount ++;	      if (tcount > 3)		return 0;	      break;		/* Retransmit buffer */	    case '$':	      {		char junkbuf[PBUFSIZ];	      /* It's probably an old response, and we're out of sync.  Just		 gobble up the packet and ignore it.  */		getpkt (junkbuf, 0);		continue;		/* Now, go look for + */	      }	    default:	      if (remote_debug)		{		  if (!started_error_output)		    {		      started_error_output = 1;		      printf_unfiltered ("putpkt: Junk: ");		    }		  putchar_unfiltered (ch & 0177);		}	      continue;	    }	  break;		/* Here to retransmit */	}#if 0      /* This is wrong.  If doing a long backtrace, the user should be	 able to get out next time we call QUIT, without anything as violent	 as interrupt_query.  If we want to provide a way out of here	 without getting to the next QUIT, it should be based on hitting	 ^C twice as in remote_wait.  */      if (quit_flag)	{	  quit_flag = 0;	  interrupt_query ();	}#endif    }}