diff options
author | Mike Blumenkrantz <zmike@osg.samsung.com> | 2016-02-22 12:16:16 -0500 |
---|---|---|
committer | Mike Blumenkrantz <zmike@osg.samsung.com> | 2016-02-22 18:29:01 -0500 |
commit | 3af1a8af1e76701d2204a8b3307cd80abce47efc (patch) | |
tree | ce512b1ac6e86afb66ebb15eb3a45b731ac423ed /src/lib/embryo/embryo_str.c | |
parent | a0ad57bb16545c2aa5b1a153c97e0ca1b675e6b9 (diff) |
embryo: reformat the whole thing
so many tabs
Diffstat (limited to 'src/lib/embryo/embryo_str.c')
-rw-r--r-- | src/lib/embryo/embryo_str.c | 208 |
1 files changed, 110 insertions, 98 deletions
diff --git a/src/lib/embryo/embryo_str.c b/src/lib/embryo/embryo_str.c index 649bd49f8f..de39437058 100644 --- a/src/lib/embryo/embryo_str.c +++ b/src/lib/embryo/embryo_str.c | |||
@@ -23,20 +23,20 @@ | |||
23 | #include "Embryo.h" | 23 | #include "Embryo.h" |
24 | #include "embryo_private.h" | 24 | #include "embryo_private.h" |
25 | 25 | ||
26 | #define STRGET(ep, str, par) { \ | 26 | #define STRGET(ep, str, par) { \ |
27 | Embryo_Cell *___cptr; \ | 27 | Embryo_Cell *___cptr; \ |
28 | str = NULL; \ | 28 | str = NULL; \ |
29 | if ((___cptr = embryo_data_address_get(ep, par))) { \ | 29 | if ((___cptr = embryo_data_address_get(ep, par))) { \ |
30 | int ___l; \ | 30 | int ___l; \ |
31 | ___l = embryo_data_string_length_get(ep, ___cptr); \ | 31 | ___l = embryo_data_string_length_get(ep, ___cptr); \ |
32 | (str) = alloca(___l + 1); \ | 32 | (str) = alloca(___l + 1); \ |
33 | if (str) embryo_data_string_get(ep, ___cptr, str); \ | 33 | if (str) embryo_data_string_get(ep, ___cptr, str); \ |
34 | } } | 34 | } } |
35 | #define STRSET(ep, par, str) { \ | 35 | #define STRSET(ep, par, str) { \ |
36 | Embryo_Cell *___cptr; \ | 36 | Embryo_Cell *___cptr; \ |
37 | if ((___cptr = embryo_data_address_get(ep, par))) { \ | 37 | if ((___cptr = embryo_data_address_get(ep, par))) { \ |
38 | embryo_data_string_set(ep, str, ___cptr); \ | 38 | embryo_data_string_set(ep, str, ___cptr); \ |
39 | } } | 39 | } } |
40 | 40 | ||
41 | /* exported string api */ | 41 | /* exported string api */ |
42 | 42 | ||
@@ -249,8 +249,8 @@ _embryo_str_strcut(Embryo_Program *ep, Embryo_Cell *params) | |||
249 | if (params[4] >= l1) params[4] = l1; | 249 | if (params[4] >= l1) params[4] = l1; |
250 | if (params[4] == params[3]) | 250 | if (params[4] == params[3]) |
251 | { | 251 | { |
252 | STRSET(ep, params[1], ""); | 252 | STRSET(ep, params[1], ""); |
253 | return 0; | 253 | return 0; |
254 | } | 254 | } |
255 | s2 = alloca(params[4] - params[3] + 1); | 255 | s2 = alloca(params[4] - params[3] + 1); |
256 | strncpy(s2, s1 + params[3], params[4] - params[3]); | 256 | strncpy(s2, s1 + params[3], params[4] - params[3]); |
@@ -270,8 +270,9 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb | |||
270 | { | 270 | { |
271 | if ((!inesc) && (!insub)) | 271 | if ((!inesc) && (!insub)) |
272 | { | 272 | { |
273 | if (s1[i] == '\\') inesc = 1; | 273 | if (s1[i] == '\\') inesc = 1; |
274 | else if (s1[i] == '%') insub = 1; | 274 | else if (s1[i] == '%') |
275 | insub = 1; | ||
275 | if ((!inesc) && (!insub)) | 276 | if ((!inesc) && (!insub)) |
276 | { | 277 | { |
277 | s2[o] = s1[i]; | 278 | s2[o] = s1[i]; |
@@ -287,17 +288,19 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb | |||
287 | switch (s1[i]) | 288 | switch (s1[i]) |
288 | { | 289 | { |
289 | case 't': | 290 | case 't': |
290 | s2[o] = '\t'; | 291 | s2[o] = '\t'; |
291 | o++; | 292 | o++; |
292 | break; | 293 | break; |
294 | |||
293 | case 'n': | 295 | case 'n': |
294 | s2[o] = '\n'; | 296 | s2[o] = '\n'; |
295 | o++; | 297 | o++; |
296 | break; | 298 | break; |
299 | |||
297 | default: | 300 | default: |
298 | s2[o] = s1[i]; | 301 | s2[o] = s1[i]; |
299 | o++; | 302 | o++; |
300 | break; | 303 | break; |
301 | } | 304 | } |
302 | inesc = 0; | 305 | inesc = 0; |
303 | } | 306 | } |
@@ -307,49 +310,76 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb | |||
307 | switch (s1[i]) | 310 | switch (s1[i]) |
308 | { | 311 | { |
309 | case '%': | 312 | case '%': |
310 | s2[o] = '%'; | 313 | s2[o] = '%'; |
311 | o++; | 314 | o++; |
312 | break; | 315 | break; |
316 | |||
313 | case 'c': | 317 | case 'c': |
314 | cptr = embryo_data_address_get(ep, params[p]); | 318 | cptr = embryo_data_address_get(ep, params[p]); |
315 | if (cptr) s2[o] = (char)(*cptr); | 319 | if (cptr) s2[o] = (char)(*cptr); |
316 | p++; | 320 | p++; |
317 | o++; | 321 | o++; |
318 | break; | 322 | break; |
323 | |||
319 | case 'i': | 324 | case 'i': |
320 | case 'd': | 325 | case 'd': |
321 | case 'x': | 326 | case 'x': |
322 | case 'X': | 327 | case 'X': |
328 | { | ||
329 | char fmt[10] = ""; | ||
330 | char tmp[256] = ""; | ||
331 | int l; | ||
332 | |||
333 | if (s1[i] == 'i') strcpy(fmt, "%i"); | ||
334 | else if (s1[i] == 'd') | ||
335 | strcpy(fmt, "%d"); | ||
336 | else if (s1[i] == 'x') | ||
337 | strcpy(fmt, "%x"); | ||
338 | else if (s1[i] == 'X') | ||
339 | strcpy(fmt, "%08x"); | ||
340 | cptr = embryo_data_address_get(ep, params[p]); | ||
341 | if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); | ||
342 | l = strlen(tmp); | ||
343 | if ((o + l) > max_len) | ||
323 | { | 344 | { |
324 | char fmt[10] = ""; | 345 | l = max_len - o; |
325 | char tmp[256] = ""; | 346 | if (l < 0) l = 0; |
326 | int l; | 347 | tmp[l] = 0; |
327 | |||
328 | if (s1[i] == 'i') strcpy(fmt, "%i"); | ||
329 | else if (s1[i] == 'd') strcpy(fmt, "%d"); | ||
330 | else if (s1[i] == 'x') strcpy(fmt, "%x"); | ||
331 | else if (s1[i] == 'X') strcpy(fmt, "%08x"); | ||
332 | cptr = embryo_data_address_get(ep, params[p]); | ||
333 | if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); | ||
334 | l = strlen(tmp); | ||
335 | if ((o + l) > max_len) | ||
336 | { | ||
337 | l = max_len - o; | ||
338 | if (l < 0) l = 0; | ||
339 | tmp[l] = 0; | ||
340 | } | ||
341 | strcpy(s2 + o, tmp); | ||
342 | o += l; | ||
343 | p++; | ||
344 | } | 348 | } |
345 | break; | 349 | strcpy(s2 + o, tmp); |
350 | o += l; | ||
351 | p++; | ||
352 | } | ||
353 | break; | ||
354 | |||
346 | case 'f': | 355 | case 'f': |
356 | { | ||
357 | char tmp[256] = ""; | ||
358 | int l; | ||
359 | |||
360 | cptr = embryo_data_address_get(ep, params[p]); | ||
361 | if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); | ||
362 | l = strlen(tmp); | ||
363 | if ((o + l) > max_len) | ||
347 | { | 364 | { |
348 | char tmp[256] = ""; | 365 | l = max_len - o; |
349 | int l; | 366 | if (l < 0) l = 0; |
367 | tmp[l] = 0; | ||
368 | } | ||
369 | strcpy(s2 + o, tmp); | ||
370 | o += l; | ||
371 | p++; | ||
372 | } | ||
373 | break; | ||
374 | |||
375 | case 's': | ||
376 | { | ||
377 | char *tmp; | ||
378 | int l; | ||
350 | 379 | ||
351 | cptr = embryo_data_address_get(ep, params[p]); | 380 | STRGET(ep, tmp, params[p]); |
352 | if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); | 381 | if (tmp) |
382 | { | ||
353 | l = strlen(tmp); | 383 | l = strlen(tmp); |
354 | if ((o + l) > max_len) | 384 | if ((o + l) > max_len) |
355 | { | 385 | { |
@@ -359,32 +389,13 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb | |||
359 | } | 389 | } |
360 | strcpy(s2 + o, tmp); | 390 | strcpy(s2 + o, tmp); |
361 | o += l; | 391 | o += l; |
362 | p++; | ||
363 | } | 392 | } |
364 | break; | 393 | p++; |
365 | case 's': | 394 | } |
366 | { | 395 | break; |
367 | char *tmp; | ||
368 | int l; | ||
369 | 396 | ||
370 | STRGET(ep, tmp, params[p]); | ||
371 | if (tmp) | ||
372 | { | ||
373 | l = strlen(tmp); | ||
374 | if ((o + l) > max_len) | ||
375 | { | ||
376 | l = max_len - o; | ||
377 | if (l < 0) l = 0; | ||
378 | tmp[l] = 0; | ||
379 | } | ||
380 | strcpy(s2 + o, tmp); | ||
381 | o += l; | ||
382 | } | ||
383 | p++; | ||
384 | } | ||
385 | break; | ||
386 | default: | 397 | default: |
387 | break; | 398 | break; |
388 | } | 399 | } |
389 | insub = 0; | 400 | insub = 0; |
390 | } | 401 | } |
@@ -503,21 +514,22 @@ _embryo_str_strrchr(Embryo_Program *ep, Embryo_Cell *params) | |||
503 | void | 514 | void |
504 | _embryo_str_init(Embryo_Program *ep) | 515 | _embryo_str_init(Embryo_Program *ep) |
505 | { | 516 | { |
506 | embryo_program_native_call_add(ep, "atoi", _embryo_str_atoi); | 517 | embryo_program_native_call_add(ep, "atoi", _embryo_str_atoi); |
507 | embryo_program_native_call_add(ep, "fnmatch", _embryo_str_fnmatch); | 518 | embryo_program_native_call_add(ep, "fnmatch", _embryo_str_fnmatch); |
508 | embryo_program_native_call_add(ep, "strcmp", _embryo_str_strcmp); | 519 | embryo_program_native_call_add(ep, "strcmp", _embryo_str_strcmp); |
509 | embryo_program_native_call_add(ep, "strncmp", _embryo_str_strncmp); | 520 | embryo_program_native_call_add(ep, "strncmp", _embryo_str_strncmp); |
510 | embryo_program_native_call_add(ep, "strcpy", _embryo_str_strcpy); | 521 | embryo_program_native_call_add(ep, "strcpy", _embryo_str_strcpy); |
511 | embryo_program_native_call_add(ep, "strncpy", _embryo_str_strncpy); | 522 | embryo_program_native_call_add(ep, "strncpy", _embryo_str_strncpy); |
512 | embryo_program_native_call_add(ep, "strlen", _embryo_str_strlen); | 523 | embryo_program_native_call_add(ep, "strlen", _embryo_str_strlen); |
513 | embryo_program_native_call_add(ep, "strcat", _embryo_str_strcat); | 524 | embryo_program_native_call_add(ep, "strcat", _embryo_str_strcat); |
514 | embryo_program_native_call_add(ep, "strncat", _embryo_str_strncat); | 525 | embryo_program_native_call_add(ep, "strncat", _embryo_str_strncat); |
515 | embryo_program_native_call_add(ep, "strprep", _embryo_str_strprep); | 526 | embryo_program_native_call_add(ep, "strprep", _embryo_str_strprep); |
516 | embryo_program_native_call_add(ep, "strnprep", _embryo_str_strnprep); | 527 | embryo_program_native_call_add(ep, "strnprep", _embryo_str_strnprep); |
517 | embryo_program_native_call_add(ep, "strcut", _embryo_str_strcut); | 528 | embryo_program_native_call_add(ep, "strcut", _embryo_str_strcut); |
518 | embryo_program_native_call_add(ep, "snprintf", _embryo_str_snprintf); | 529 | embryo_program_native_call_add(ep, "snprintf", _embryo_str_snprintf); |
519 | embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); | 530 | embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); |
520 | embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); | 531 | embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); |
521 | embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); | 532 | embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); |
522 | embryo_program_native_call_add(ep, "printf", _embryo_str_printf); | 533 | embryo_program_native_call_add(ep, "printf", _embryo_str_printf); |
523 | } | 534 | } |
535 | |||