Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

SRC/sock_scn.c

Go to the documentation of this file.
00001 00005 #include <stdio.h> 00006 #include <stdarg.h> 00007 #include <string.h> 00008 00009 #include "copyrigh.h" 00010 #include "wattcp.h" 00011 #include "misc.h" 00012 #include "pctcp.h" 00013 00014 #if defined(__WATCOMC__) && (__WATCOMC__ >= 1250) /* OW 1.5+ */ 00015 #define OPENWATCOM_15 00016 #endif 00017 00018 /* 00019 * MSC/DMC/DJGPP 2.01 doesn't have vsscanf(). 00020 * On Windows there's nothing to be done yet :-( 00021 */ 00022 #if defined(WIN32) && !defined(__MINGW32__) && !defined(OPENWATCOM_15) 00023 static int vsscanf (const char *buf, const char *fmt, va_list arglist) 00024 { 00025 ARGSUSED (buf); 00026 ARGSUSED (fmt); 00027 ARGSUSED (arglist); 00028 return (0); 00029 } 00030 #elif defined(__DJGPP__) && (DJGPP_MINOR < 2) 00031 static int vsscanf (const char *buf, const char *fmt, va_list arglist) 00032 { 00033 FILE *fil = stdin; 00034 fil->_ptr = (char*) buf; 00035 return _doscan (fil, fmt, arglist); 00036 } 00037 #elif defined(_MSC_VER) || defined(__DMC__) 00038 static int vsscanf (const char *buf, const char *fmt, va_list arglist) 00039 { 00040 extern _input (FILE*, const char*, va_list); 00041 FILE *fil = stdin; 00042 fil->_ptr = (char*) buf; 00043 return _input (fil, fmt, arglist); 00044 } 00045 #endif 00046 00047 /* 00048 * sock_scanf - Read a line and return number of fields matched. 00049 * 00050 * BIG WARNING: Don't use this for packetised protocols like 00051 * SSH. Only suitable for ASCII orientented protocols 00052 * like POP3/SMTP/NNTP etc. 00053 * 00054 * NOTE: Don't use {\r\n} in 'fmt' (it's stripped in sock_gets). 00055 */ 00056 int MS_CDECL sock_scanf (sock_type *s, const char *fmt, ...) 00057 { 00058 char buf [tcp_MaxBufSize]; 00059 int fields = 0; 00060 int status, len; 00061 00062 while ((status = sock_dataready(s)) == 0) 00063 { 00064 if (status == -1) 00065 return (-1); 00066 00067 len = sock_gets (s, (BYTE*)buf, sizeof(buf)); 00068 if (len > 0) 00069 { 00070 va_list args; 00071 va_start (args, fmt); 00072 fields = vsscanf (buf, fmt, args); 00073 va_end (args); 00074 break; 00075 } 00076 } 00077 return (fields); 00078 } 00079

Generated on Wed Aug 4 08:55:53 2010 for Watt-32 tcp/ip by doxygen 1.3.8