Mercurial > hg > fxanalyse
diff DDS_Fox.c @ 13:e45d6e9544f5
Log file name and line number on error
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 16 Jul 2012 13:04:01 +0200 |
parents | adc9e2a67547 |
children | b47b97cfd050 |
line wrap: on
line diff
--- a/DDS_Fox.c Mon Jul 16 13:00:10 2012 +0200 +++ b/DDS_Fox.c Mon Jul 16 13:04:01 2012 +0200 @@ -1,4 +1,3 @@ -#include <userint.h> #include <tcpsupp.h> #include <ansi_c.h> #include "DDS_Fox.h" @@ -43,6 +42,18 @@ }*/ +#define error(...) _error(__FILE__, __LINE__, __func__, __VA_ARGS__) + +void _error(const char *file, int line, const char *func, const char *frmt, ...) +{ + va_list args; + va_start(args, line); + fprintf(stderr, "ERROR: %s:%d:%s: ", file, line, func); + vfprintf(stderr, frmt, args); + fprintf(stderr, "\n"); + va_end(args); +} + void DDS_Initialize (DDSParameter *Param) { char Request[255]; @@ -294,20 +305,20 @@ char Response[255]; char parsebuf[255]; if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { - printf("Connect failed\n"); + error("Connect failed"); return -1; } if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { - printf("Write failed\n"); + error("Write failed"); return -1; } sprintf(Response," "); if (ClientTCPRead (hConv, Response, 255, 0) < 0) { - printf("Read failed\n"); + error("Read failed"); return -1; } if (strncmp("OK",Response,2)) { - printf("Response failed %s %s\n", Buffer, Response); + error("Response failed %s %s", Buffer, Response); return -1; } return 0; @@ -319,21 +330,21 @@ char parsebuf[255]; char Response[255]; if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { - printf("Connect failed\n"); + error("Connect failed"); return -1; } if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { - printf("Write failed\n"); + error("Write failed"); return -1; } sprintf(Response," "); if (ClientTCPRead (hConv, Response, 255, 0) < 0) { - printf("Read failed\n"); + error("Read failed"); return -1; } if (strncmp(Buffer,Response,strlen(Buffer))) { - printf("Response failed %s %s\n", Buffer, Response); + error("Response failed %s %s", Buffer, Response); return -1; }