Mercurial > mplayer.hg
comparison stream/freesdp/parser.c @ 21504:06fe68e8049a
Simplify NEXT_LINE macro and put most of it in a separate function.
author | reimar |
---|---|
date | Wed, 06 Dec 2006 12:25:52 +0000 |
parents | f9a95c04844a |
children | b9fa8b0ddab9 |
comparison
equal
deleted
inserted
replaced
21503:f9a95c04844a | 21504:06fe68e8049a |
---|---|
34 **/ | 34 **/ |
35 | 35 |
36 #include "parserpriv.h" | 36 #include "parserpriv.h" |
37 | 37 |
38 /** | 38 /** |
39 * \brief find the start of the next line | |
40 * \param c pointer to current position in string | |
41 * \return pointer to start of next line or NULL if illegal (i.e. | |
42 * a '\r' is not followed by a '\n' | |
43 */ | |
44 static const char *next_line(const char *c) { | |
45 c += strcspn(c, "\n\r"); | |
46 if (*c == 0) return c; | |
47 if (*c == '\r') c++; | |
48 if (*c == '\n') | |
49 return c + 1; | |
50 return NULL; | |
51 } | |
52 | |
53 /** | |
39 * Moves the <code>c<code> pointer up to the beginning of the next | 54 * Moves the <code>c<code> pointer up to the beginning of the next |
40 * line. | 55 * line. |
41 * | 56 * |
42 * @param c char pointer to pointer | 57 * @param c char pointer to pointer |
43 * @retval FSDPE_ILLEGAL_CHARACTER, when an illegal '\r' character | 58 * @retval FSDPE_ILLEGAL_CHARACTER, when an illegal '\r' character |
44 * (not followed by a '\n') is found, returns | 59 * (not followed by a '\n') is found, returns |
45 */ | 60 */ |
46 #define NEXT_LINE(c) \ | 61 #define NEXT_LINE(c) do { if (!(c = next_line(c))) return FSDPE_ILLEGAL_CHARACTER; } while (0); |
47 { \ | |
48 while ((*(c) != '\0') && (*(c) != '\r') && (*(c) != '\n')) { \ | |
49 (c)++; \ | |
50 } \ | |
51 if (*(c) == '\n') { \ | |
52 (c)++; \ | |
53 } else if (*(c) == '\r') { \ | |
54 (c)++; \ | |
55 if (*(c) == '\n') { \ | |
56 (c)++; \ | |
57 } else { \ | |
58 return FSDPE_ILLEGAL_CHARACTER; \ | |
59 } \ | |
60 } \ | |
61 } | |
62 | 62 |
63 fsdp_error_t | 63 fsdp_error_t |
64 fsdp_parse (const char *text_description, fsdp_description_t * dsc) | 64 fsdp_parse (const char *text_description, fsdp_description_t * dsc) |
65 { | 65 { |
66 fsdp_error_t result; | 66 fsdp_error_t result; |