Changeset 398
- Timestamp:
- 09/04/09 14:00:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/src/simples.c
r397 r398 14 14 char *remote_txt() 15 15 { 16 if (is_server) 17 return ("client"); 18 else 19 return ("remote server"); 16 return (is_server ? "client" : "remote server"); 20 17 } 21 18 … … 34 31 for (p1 = txt + l - 1; (*p1 == ' ') || (*p1 == '\t') || (*p1 == '\n') || (*p1 == '\r'); *p1-- = '\0'); 35 32 36 return (txt);33 return txt; 37 34 } 38 35 … … 65 62 if ((c >= 'a') && (c <= 'f')) 66 63 return (c - 'a' + 10); 67 return (-1); 64 65 return -1; 68 66 } 69 67 … … 77 75 buf[i] = rc; 78 76 } 79 return (n); 77 78 return n; 80 79 } 81 80 … … 97 96 n++; 98 97 } 99 return (rc); 98 99 return rc; 100 100 } 101 101 … … 104 104 int rc; 105 105 106 if (strlen(trim(asc)) != 2) 107 rc = (-1); 108 else if ((rc = (gethexval(asc[0]) << 4) | gethexval(asc[1])) & 0x100) 109 rc = (-1); 110 return (rc); 106 if (strlen(trim(asc)) != 2) { 107 rc = -1; 108 } else if ((rc = (gethexval(asc[0]) << 4) | gethexval(asc[1])) & 0x100) { 109 rc = -1; 110 } 111 112 return rc; 111 113 } 112 114 … … 115 117 long rc; 116 118 117 if (strlen(trim(asc)) != 4) 118 rc = (-1);119 else {119 if (strlen(trim(asc)) != 4) { 120 rc = -1; 121 } else { 120 122 rc = gethexval(asc[0]) << 12 | gethexval(asc[1]) << 8 | gethexval(asc[2]) << 4 | gethexval(asc[3]); 121 if (rc & 0x10000) 122 rc = (-1); 123 } 124 return (rc); 123 if (rc & 0x10000) { 124 rc = -1; 125 } 126 } 127 128 return rc; 125 129 } 126 130 … … 131 135 for (i = rc = 0; i < 32; i += 2) { 132 136 if ((n1 = gethexval(asc[i])) < 0) 133 rc = (-1);137 rc = -1; 134 138 if ((n2 = gethexval(asc[i + 1])) < 0) 135 rc = (-1);139 rc = -1; 136 140 bin[i >> 1] = (n1 << 4) + (n2 & 0xff); 137 141 } 138 return (rc); 142 143 return rc; 139 144 } 140 145 … … 145 150 for (i = rc = 0; i < 28; i += 2) { 146 151 if ((n1 = gethexval(asc[i])) < 0) 147 rc = (-1);152 rc = -1; 148 153 if ((n2 = gethexval(asc[i + 1])) < 0) 149 rc = (-1);154 rc = -1; 150 155 bin[i >> 1] = (n1 << 4) + (n2 & 0xff); 151 156 } 152 return (rc); 157 158 return rc; 153 159 } 154 160 … … 158 164 static char buf[33]; 159 165 160 if (!asc) 166 if (!asc) { 161 167 asc = buf; 162 for (i = 0; i < 16; i++) 168 } 169 for (i = 0; i < 16; i++) { 163 170 sprintf(asc + (i << 1), "%02X", bin[i]); 171 } 164 172 165 173 return asc; … … 245 253 for (i = 0; i < n; k += b[i++]) 246 254 k <<= 8; 255 247 256 return k; 248 257 } … … 268 277 break; 269 278 } 279 270 280 return b; 271 281 } … … 276 286 ulong rc; 277 287 278 for (rc = i = 0, n = strlen(trim(asc)) - 1; i < (abs(bytes) << 1); n--, i++) 288 for (rc = i = 0, n = strlen(trim(asc)) - 1; i < (abs(bytes) << 1); n--, i++) { 279 289 if (n >= 0) { 280 290 int rcl; … … 285 295 } 286 296 rc |= (rcl << (i << 2)); 287 } else if (bytes < 0) 297 } else if (bytes < 0) { 288 298 rc |= (0xf << (i << 2)); 299 } 300 } 289 301 errno = 0; 302 290 303 return rc; 291 304 } … … 326 339 pfds.revents = 0; 327 340 if (poll(&pfds, 1, 0) != 1) 328 return (0);341 return 0; 329 342 else 330 343 return (((pfds.revents) & POLLIN) == POLLIN); … … 333 346 int file_exists (const char *filepath) { 334 347 FILE *file = fopen(filepath, "r"); 348 335 349 if (file != NULL) { 336 350 fclose(file); 337 351 return 1; 338 352 } 353 339 354 return 0; 340 355 }
Note:
See TracChangeset
for help on using the changeset viewer.