00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <errno.h>
00023 #include <assert.h>
00024 #include <locale.h>
00025
00026 #ifdef WIN32
00027 #include <windows.h>
00028 #endif
00029
00030 #define _LIBRASCH_BUILD
00031 #include <ra.h>
00032 #include <ra_priv.h>
00033 #include <pl_general.h>
00034
00040 LIBRAAPI value_handle
00041 ra_value_malloc()
00042 {
00043 struct ra_value *v;
00044
00045 v = malloc(sizeof(struct ra_value));
00046 memset(v, 0, sizeof(struct ra_value));
00047
00048 v->handle_id = RA_HANDLE_VALUE;
00049
00050 return (value_handle)v;
00051 }
00052
00053
00060 LIBRAAPI void
00061 ra_value_free(value_handle vh)
00062 {
00063 struct ra_value *v = (struct ra_value *)vh;
00064
00065 if (!v || !valid_value_handle(vh, __LINE__))
00066 return;
00067
00068 free_mem(v);
00069 free(v);
00070 }
00071
00072
00080 int
00081 valid_value_handle(value_handle vh, int line_num)
00082 {
00083 int ok = 1;
00084 struct ra_value *v = (struct ra_value *)vh;
00085 if (!v)
00086 return ok;
00087
00088 if (v->handle_id != RA_HANDLE_VALUE)
00089 ok = 0;
00090
00091 if (!ok)
00092 {
00093 fprintf(stderr, "called from line %d\n", line_num);
00094 assert(0);
00095 }
00096
00097 return ok;
00098 }
00099
00100
00107 LIBRAAPI void
00108 ra_value_reset(value_handle vh)
00109 {
00110 struct ra_value *v = (struct ra_value *)vh;
00111 if (!v || !valid_value_handle(vh, __LINE__))
00112 return;
00113
00114 free_mem(v);
00115 }
00116
00117
00125 LIBRAAPI long
00126 ra_value_get_type(value_handle vh)
00127 {
00128 struct ra_value *v = (struct ra_value *)vh;
00129 if (!v || !valid_value_handle(vh, __LINE__))
00130 return RA_VALUE_TYPE_NONE;
00131
00132 return v->utype;
00133 }
00134
00135
00142 LIBRAAPI int
00143 ra_value_is_ok(value_handle vh)
00144 {
00145 struct ra_value *v = (struct ra_value *)vh;
00146 if (!v || !valid_value_handle(vh, __LINE__))
00147 return 0;
00148
00149 return v->value_is_valid;
00150 }
00151
00152
00160 LIBRAAPI long
00161 ra_value_get_num_elem(value_handle vh)
00162 {
00163 struct ra_value *v = (struct ra_value *)vh;
00164 if (!v || !valid_value_handle(vh, __LINE__))
00165 return 0;
00166
00167 return v->num_values;
00168 }
00169
00170
00178 LIBRAAPI long
00179 ra_value_get_info(value_handle vh)
00180 {
00181 struct ra_value *v = (struct ra_value *)vh;
00182 if (!v || !valid_value_handle(vh, __LINE__))
00183 return RA_INFO_NONE;
00184
00185 return v->id;
00186 }
00187
00188
00196 LIBRAAPI const char *
00197 ra_value_get_name(value_handle vh)
00198 {
00199 struct ra_value *v = (struct ra_value *)vh;
00200 if (!v || !valid_value_handle(vh, __LINE__))
00201 return NULL;
00202
00203 utf8_to_local(v->name, v->name_locale, RA_VALUE_NAME_MAX);
00204
00205 return v->name_locale;
00206 }
00207
00208
00216 LIBRAAPI const char *
00217 ra_value_get_desc(value_handle vh)
00218 {
00219 struct ra_value *v = (struct ra_value *)vh;
00220 if (!v || !valid_value_handle(vh, __LINE__))
00221 return NULL;
00222
00223 utf8_to_local(v->desc, v->desc_locale, RA_VALUE_DESC_MAX);
00224
00225 return v->desc_locale;
00226 }
00227
00228
00238 LIBRAAPI int
00239 ra_value_set_number(value_handle vh, long number)
00240 {
00241 struct ra_value *v = (struct ra_value *)vh;
00242 if (!v || !valid_value_handle(vh, __LINE__))
00243 return -1;
00244
00245 v->number = number;
00246
00247 return 0;
00248 }
00249
00250
00257 LIBRAAPI long
00258 ra_value_get_number(value_handle vh)
00259 {
00260 struct ra_value *v = (struct ra_value *)vh;
00261
00262 if (!v || !valid_value_handle(vh, __LINE__))
00263 return 0;
00264
00265 return v->number;
00266 }
00267
00268
00279 int
00280 set_meta_info(value_handle vh, const char *name, const char *desc, int id)
00281 {
00282 struct ra_value *v = (struct ra_value *)vh;
00283 if (!v || !valid_value_handle(vh, __LINE__))
00284 return -1;
00285
00286 if (name && (name[0] != '\0'))
00287 {
00288 strncpy(v->name, gettext(name), RA_VALUE_NAME_MAX-1);
00289 v->name[RA_VALUE_NAME_MAX-1] = '\0';
00290 }
00291 else
00292 v->name[0] = '\0';
00293
00294 if (desc && (desc[0] != '\0'))
00295 {
00296 strncpy(v->desc, gettext(desc), RA_VALUE_DESC_MAX-1);
00297 v->desc[RA_VALUE_DESC_MAX-1] = '\0';
00298 }
00299 else
00300 v->desc[0] = '\0';
00301
00302 v->id = id;
00303
00304 return 0;
00305 }
00306
00307
00315 LIBRAAPI void
00316 ra_value_set_short(value_handle vh, const short value)
00317 {
00318 struct ra_value *v = (struct ra_value *)vh;
00319
00320 if (!v || !valid_value_handle(vh, __LINE__))
00321 return;
00322
00323 free_mem(v);
00324 v->value.s = value;
00325 v->utype = RA_VALUE_TYPE_SHORT;
00326 v->value_is_valid = 1;
00327 }
00328
00329
00337 LIBRAAPI void
00338 ra_value_set_long(value_handle vh, const long value)
00339 {
00340 struct ra_value *v = (struct ra_value *)vh;
00341
00342 if (!v || !valid_value_handle(vh, __LINE__))
00343 return;
00344
00345 free_mem(v);
00346 v->value.l = value;
00347 v->utype = RA_VALUE_TYPE_LONG;
00348 v->value_is_valid = 1;
00349 }
00350
00351
00359 LIBRAAPI void
00360 ra_value_set_double(value_handle vh, const double value)
00361 {
00362 struct ra_value *v = (struct ra_value *)vh;
00363
00364 if (!v || !valid_value_handle(vh, __LINE__))
00365 return;
00366
00367 free_mem(v);
00368 v->value.d = value;
00369 v->utype = RA_VALUE_TYPE_DOUBLE;
00370 v->value_is_valid = 1;
00371 }
00372
00373
00381 LIBRAAPI void
00382 ra_value_set_string(value_handle vh, const char *string)
00383 {
00384 struct ra_value *v = (struct ra_value *)vh;
00385 char *conv = NULL;
00386 size_t len;
00387
00388 if (!string || !v || !valid_value_handle(vh, __LINE__))
00389 return;
00390
00391 free_mem(v);
00392
00393 v->value_locale.c = ra_alloc_mem(strlen(string) + 1);
00394 memset(v->value_locale.c, '\0', strlen(string)+1);
00395 if (v->value_locale.c != NULL)
00396 strncpy(v->value_locale.c, string, strlen(string));
00397
00398
00399 if (strlen(string) > 0)
00400 {
00401 len = strlen(string) * 2;
00402 conv = calloc(len, 1);
00403 local_to_utf8(string, conv, len);
00404 len = strlen(conv);
00405 v->value.c = ra_alloc_mem(len + 1);
00406 memset(v->value.c, '\0', len+1);
00407 if (v->value.c != NULL)
00408 strncpy(v->value.c, conv, len);
00409 free(conv);
00410 }
00411 else
00412 {
00413 v->value.c = ra_alloc_mem(1);
00414 v->value.c[0] = '\0';
00415 }
00416
00417 v->utype = RA_VALUE_TYPE_CHAR;
00418 v->value_is_valid = 1;
00419 }
00420
00421
00429 LIBRAAPI void
00430 ra_value_set_string_utf8(value_handle vh, const char *string)
00431 {
00432 struct ra_value *v = (struct ra_value *)vh;
00433 char *conv = NULL;
00434 size_t len;
00435
00436 if (!string || !v || !valid_value_handle(vh, __LINE__))
00437 return;
00438
00439 free_mem(v);
00440
00441 v->value.c = ra_alloc_mem(strlen(string) + 1);
00442 memset(v->value.c, '\0', strlen(string)+1);
00443 if (v->value.c != NULL)
00444 strcpy(v->value.c, string);
00445
00446
00447 if (strlen(string) > 0)
00448 {
00449 len = strlen(string) * 2;
00450 conv = calloc(len, 1);
00451 utf8_to_local(string, conv, len);
00452 len = strlen(conv);
00453 v->value_locale.c = ra_alloc_mem(len + 1);
00454 memset(v->value_locale.c, '\0', len+1);
00455 if (v->value_locale.c != NULL)
00456 strcpy(v->value_locale.c, conv);
00457 free(conv);
00458 }
00459 else
00460 {
00461 v->value_locale.c = ra_alloc_mem(1);
00462 v->value_locale.c[0] = '\0';
00463 }
00464
00465 v->utype = RA_VALUE_TYPE_CHAR;
00466 v->value_is_valid = 1;
00467 }
00468
00469
00477 LIBRAAPI void
00478 ra_value_set_voidp(value_handle vh, const void *value)
00479 {
00480 struct ra_value *v = (struct ra_value *)vh;
00481
00482 if (!v || !valid_value_handle(vh, __LINE__))
00483 return;
00484
00485 free_mem(v);
00486 v->value.vp = (void *)value;
00487 v->utype = RA_VALUE_TYPE_VOIDP;
00488 v->value_is_valid = 1;
00489 }
00490
00491
00500 LIBRAAPI void
00501 ra_value_set_short_array(value_handle vh, const short *array, long num)
00502 {
00503 struct ra_value *v = (struct ra_value *)vh;
00504 long size;
00505
00506 if (!v || !array || !valid_value_handle(vh, __LINE__))
00507 return;
00508
00509 free_mem(v);
00510
00511 size = sizeof(short) * num;
00512 v->value.sp = ra_alloc_mem(size);
00513 if (v->value.sp)
00514 {
00515 memcpy(v->value.sp, array, size);
00516 v->utype = RA_VALUE_TYPE_SHORT_ARRAY;
00517 v->num_values = num;
00518 }
00519 v->value_is_valid = 1;
00520 }
00521
00522
00531 LIBRAAPI void
00532 ra_value_set_long_array(value_handle vh, const long *array, long num)
00533 {
00534 struct ra_value *v = (struct ra_value *)vh;
00535 long size;
00536
00537 if (!v || !array || !valid_value_handle(vh, __LINE__))
00538 return;
00539
00540 free_mem(v);
00541
00542 size = sizeof(long) * num;
00543 v->value.lp = ra_alloc_mem(size);
00544 if (v->value.lp)
00545 {
00546 memcpy(v->value.lp, array, size);
00547 v->utype = RA_VALUE_TYPE_LONG_ARRAY;
00548 v->num_values = num;
00549 }
00550 v->value_is_valid = 1;
00551 }
00552
00553
00562 LIBRAAPI void
00563 ra_value_set_double_array(value_handle vh, const double *array, long num)
00564 {
00565 struct ra_value *v = (struct ra_value *)vh;
00566 long size;
00567
00568 if (!v || !array || !valid_value_handle(vh, __LINE__))
00569 return;
00570
00571 free_mem(v);
00572
00573 size = sizeof(double) * num;
00574 v->value.dp = ra_alloc_mem(size);
00575 if (v->value.dp)
00576 {
00577 memcpy(v->value.dp, array, size);
00578 v->utype = RA_VALUE_TYPE_DOUBLE_ARRAY;
00579 v->num_values = num;
00580 }
00581 v->value_is_valid = 1;
00582 }
00583
00584
00593 LIBRAAPI void
00594 ra_value_set_string_array(value_handle vh, const char **array, long num)
00595 {
00596 struct ra_value *v = (struct ra_value *)vh;
00597 long size;
00598
00599 if (!v || !array || !valid_value_handle(vh, __LINE__))
00600 return;
00601
00602 free_mem(v);
00603
00604 size = sizeof(char *) * num;
00605 v->value_locale.cp = ra_alloc_mem(size);
00606 if (v->value_locale.cp)
00607 {
00608 long l;
00609 for (l = 0; l < num; l++)
00610 {
00611 v->value_locale.cp[l] = ra_alloc_mem(strlen(array[l]) + 1);
00612 memset(v->value_locale.cp[l], '\0', strlen(array[l])+1);
00613 if (v->value_locale.cp[l])
00614 memcpy(v->value_locale.cp[l], array[l], strlen(array[l]) + 1);
00615 }
00616 }
00617
00618
00619 v->value.cp = ra_alloc_mem(size);
00620 if (v->value.cp)
00621 {
00622 long l;
00623 size_t len;
00624 char *conv = NULL;
00625
00626 for (l = 0; l < num; l++)
00627 {
00628 if (strlen(array[l]) > 0)
00629 {
00630 len = strlen(array[l]) * 2;
00631 conv = calloc(len, 1);
00632 local_to_utf8(array[l], conv, len);
00633 len = strlen(conv);
00634 v->value.cp[l] = ra_alloc_mem(len + 1);
00635 memset(v->value.cp[l], '\0', len+1);
00636 if (v->value.cp[l])
00637 memcpy(v->value.cp[l], conv, len + 1);
00638 free(conv);
00639 }
00640 else
00641 {
00642 v->value.cp[l] = ra_alloc_mem(1);
00643 v->value.cp[l][0] = '\0';
00644 }
00645 }
00646 }
00647
00648 v->utype = RA_VALUE_TYPE_CHAR_ARRAY;
00649 v->num_values = num;
00650 v->value_is_valid = 1;
00651 }
00652
00653
00663 LIBRAAPI void
00664 ra_value_set_string_array_utf8(value_handle vh, const char **array, long num)
00665 {
00666 struct ra_value *v = (struct ra_value *)vh;
00667 long size;
00668
00669 if (!v || !array || !valid_value_handle(vh, __LINE__))
00670 return;
00671
00672 free_mem(v);
00673
00674 size = sizeof(char *) * num;
00675 v->value.cp = ra_alloc_mem(size);
00676 if (v->value.cp)
00677 {
00678 long l;
00679 for (l = 0; l < num; l++)
00680 {
00681 v->value.cp[l] = ra_alloc_mem(strlen(array[l]) + 1);
00682 memset(v->value.cp[l], '\0', strlen(array[l])+1);
00683 if (v->value.cp[l])
00684 memcpy(v->value.cp[l], array[l], strlen(array[l]) + 1);
00685 }
00686 }
00687
00688
00689 v->value_locale.cp = ra_alloc_mem(size);
00690 if (v->value_locale.cp)
00691 {
00692 long l;
00693 size_t len;
00694 char *conv = NULL;
00695
00696 for (l = 0; l < num; l++)
00697 {
00698 if (strlen(array[l]) > 0)
00699 {
00700 len = strlen(array[l]) * 2;
00701 conv = calloc(len, 1);
00702 utf8_to_local(array[l], conv, len);
00703 len = strlen(conv);
00704 v->value_locale.cp[l] = ra_alloc_mem(len + 1);
00705 memset(v->value_locale.cp[l], '\0', len+1);
00706 if (v->value_locale.cp[l])
00707 memcpy(v->value_locale.cp[l], conv, len + 1);
00708 free(conv);
00709 }
00710 else
00711 {
00712 v->value_locale.cp[l] = ra_alloc_mem(1);
00713 v->value_locale.cp[l][0] = '\0';
00714 }
00715 }
00716 }
00717
00718 v->utype = RA_VALUE_TYPE_CHAR_ARRAY;
00719 v->num_values = num;
00720 v->value_is_valid = 1;
00721 }
00722
00723
00732 LIBRAAPI void
00733 ra_value_set_voidp_array(value_handle vh, const void **array, long num)
00734 {
00735 struct ra_value *v = (struct ra_value *)vh;
00736 long size;
00737
00738 if (!v || !array || !valid_value_handle(vh, __LINE__))
00739 return;
00740
00741 free_mem(v);
00742
00743 size = sizeof(void *) * num;
00744 v->value.vpp = ra_alloc_mem(size);
00745 if (v->value.vpp)
00746 {
00747 memcpy(v->value.vpp, array, size);
00748 v->utype = RA_VALUE_TYPE_VOIDP_ARRAY;
00749 v->num_values = num;
00750 }
00751 v->value_is_valid = 1;
00752 }
00753
00754
00763 LIBRAAPI void
00764 ra_value_set_vh_array(value_handle vh, const value_handle *array, long num)
00765 {
00766 struct ra_value *v = (struct ra_value *)vh;
00767 long l;
00768
00769 if (!v || !array || !valid_value_handle(vh, __LINE__))
00770 return;
00771
00772 free_mem(v);
00773
00774 v->value.vhp = ra_alloc_mem(sizeof(value_handle) * num);
00775 if (v->value.vhp)
00776 {
00777 for (l = 0; l < num; l++)
00778 {
00779 v->value.vhp[l] = ra_value_malloc();
00780 ra_value_copy(v->value.vhp[l], array[l]);
00781 }
00782 v->utype = RA_VALUE_TYPE_VH_ARRAY;
00783 v->num_values = num;
00784 }
00785 v->value_is_valid = 1;
00786 }
00787
00788
00795 LIBRAAPI short
00796 ra_value_get_short(value_handle vh)
00797 {
00798 short ret = 0;
00799 struct ra_value *v = (struct ra_value *)vh;
00800
00801 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00802 return ret;
00803
00804 switch (v->utype)
00805 {
00806 case RA_VALUE_TYPE_SHORT:
00807 ret = v->value.s;
00808 break;
00809 case RA_VALUE_TYPE_LONG:
00810 ret = (short)(v->value.l);
00811 break;
00812 case RA_VALUE_TYPE_DOUBLE:
00813 ret = (short)(v->value.d);
00814 break;
00815 }
00816
00817 return ret;
00818 }
00819
00820
00827 LIBRAAPI long
00828 ra_value_get_long(value_handle vh)
00829 {
00830 long ret = 0;
00831 struct ra_value *v = (struct ra_value *)vh;
00832
00833 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00834 return ret;
00835
00836 switch (v->utype)
00837 {
00838 case RA_VALUE_TYPE_SHORT:
00839 ret = (long)(v->value.s);
00840 break;
00841 case RA_VALUE_TYPE_LONG:
00842 ret = v->value.l;
00843 break;
00844 case RA_VALUE_TYPE_DOUBLE:
00845 ret = (long)(v->value.d);
00846 break;
00847 }
00848
00849 return ret;
00850 }
00851
00852
00859 LIBRAAPI double
00860 ra_value_get_double(value_handle vh)
00861 {
00862 double ret = 0.0;
00863 struct ra_value *v = (struct ra_value *)vh;
00864
00865 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00866 return ret;
00867
00868 switch (v->utype)
00869 {
00870 case RA_VALUE_TYPE_SHORT:
00871 ret = (double)(v->value.s);
00872 break;
00873 case RA_VALUE_TYPE_LONG:
00874 ret = (double)(v->value.l);
00875 break;
00876 case RA_VALUE_TYPE_DOUBLE:
00877 ret = v->value.d;
00878 break;
00879 }
00880
00881 return ret;
00882 }
00883
00884
00893 LIBRAAPI const char *
00894 ra_value_get_string(value_handle vh)
00895 {
00896 const char *ret = NULL;
00897 struct ra_value *v = (struct ra_value *)vh;
00898
00899 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00900 return ret;
00901
00902 switch (v->utype)
00903 {
00904 case RA_VALUE_TYPE_CHAR:
00905 ret = v->value_locale.c;
00906 break;
00907 }
00908
00909 return ret;
00910 }
00911
00912
00921 LIBRAAPI const char *
00922 ra_value_get_string_utf8(value_handle vh)
00923 {
00924 const char *ret = NULL;
00925 struct ra_value *v = (struct ra_value *)vh;
00926
00927 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00928 return ret;
00929
00930 switch (v->utype)
00931 {
00932 case RA_VALUE_TYPE_CHAR:
00933 ret = v->value.c;
00934 break;
00935 }
00936
00937 return ret;
00938 }
00939
00940
00947 LIBRAAPI const void *
00948 ra_value_get_voidp(value_handle vh)
00949 {
00950 void *ret = NULL;
00951 struct ra_value *v = (struct ra_value *)vh;
00952
00953 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00954 return ret;
00955
00956 switch (v->utype)
00957 {
00958 case RA_VALUE_TYPE_VOIDP:
00959 ret = v->value.vp;
00960 break;
00961 }
00962
00963 return ret;
00964 }
00965
00966
00976 LIBRAAPI const short *
00977 ra_value_get_short_array(value_handle vh)
00978 {
00979 const short *ret = NULL;
00980 struct ra_value *v = (struct ra_value *)vh;
00981
00982 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
00983 return ret;
00984
00985 switch (v->utype)
00986 {
00987 case RA_VALUE_TYPE_SHORT_ARRAY:
00988 ret = v->value.sp;
00989 break;
00990 }
00991
00992 return ret;
00993 }
00994
00995
01005 LIBRAAPI const long *
01006 ra_value_get_long_array(value_handle vh)
01007 {
01008 const long *ret = NULL;
01009 struct ra_value *v = (struct ra_value *)vh;
01010
01011 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01012 return ret;
01013
01014 switch (v->utype)
01015 {
01016 case RA_VALUE_TYPE_LONG_ARRAY:
01017 ret = v->value.lp;
01018 break;
01019 }
01020
01021 return ret;
01022 }
01023
01024
01034 LIBRAAPI const double *
01035 ra_value_get_double_array(value_handle vh)
01036 {
01037 const double *ret = NULL;
01038 struct ra_value *v = (struct ra_value *)vh;
01039
01040 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01041 return ret;
01042
01043 switch (v->utype)
01044 {
01045 case RA_VALUE_TYPE_DOUBLE_ARRAY:
01046 ret = v->value.dp;
01047 break;
01048 }
01049
01050 return ret;
01051 }
01052
01053
01063 LIBRAAPI const char **
01064 ra_value_get_string_array(value_handle vh)
01065 {
01066 const char **ret = NULL;
01067 struct ra_value *v = (struct ra_value *)vh;
01068
01069 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01070 return ret;
01071
01072 switch (v->utype)
01073 {
01074 case RA_VALUE_TYPE_CHAR_ARRAY:
01075 ret = (const char **)(v->value_locale.cp);
01076 break;
01077 }
01078
01079 return ret;
01080 }
01081
01082
01092 LIBRAAPI const char **
01093 ra_value_get_string_array_utf8(value_handle vh)
01094 {
01095 const char **ret = NULL;
01096 struct ra_value *v = (struct ra_value *)vh;
01097
01098 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01099 return ret;
01100
01101 switch (v->utype)
01102 {
01103 case RA_VALUE_TYPE_CHAR_ARRAY:
01104 ret = (const char **)(v->value.cp);
01105 break;
01106 }
01107
01108 return ret;
01109 }
01110
01111
01121 LIBRAAPI const void **
01122 ra_value_get_voidp_array(value_handle vh)
01123 {
01124 const void **ret = NULL;
01125 struct ra_value *v = (struct ra_value *)vh;
01126
01127 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01128 return ret;
01129
01130 switch (v->utype)
01131 {
01132 case RA_VALUE_TYPE_VOIDP_ARRAY:
01133 ret = (const void **)(v->value.vpp);
01134 break;
01135 }
01136
01137 return ret;
01138 }
01139
01140
01150 LIBRAAPI const value_handle *
01151 ra_value_get_vh_array(value_handle vh)
01152 {
01153 const value_handle *ret = NULL;
01154 struct ra_value *v = (struct ra_value *)vh;
01155
01156 if (!v || !(v->value_is_valid) || !valid_value_handle(vh, __LINE__))
01157 return ret;
01158
01159 switch (v->utype)
01160 {
01161 case RA_VALUE_TYPE_VH_ARRAY:
01162 ret = v->value.vhp;
01163 break;
01164 }
01165
01166 return ret;
01167 }
01168
01169
01178 LIBRAAPI int
01179 ra_value_copy(value_handle dest, value_handle src)
01180 {
01181 struct ra_value *d = (struct ra_value *)dest;
01182 struct ra_value *s = (struct ra_value *)src;
01183 int ret = 0;
01184
01185 if (!d || !s || !valid_value_handle(d, __LINE__) || !valid_value_handle(s, __LINE__))
01186 return -1;
01187
01188 free_mem(d);
01189
01190 strncpy(d->name, s->name, RA_VALUE_NAME_MAX);
01191 strncpy(d->desc, s->desc, RA_VALUE_DESC_MAX);
01192 d->id = s->id;
01193 d->can_be_changed = 1;
01194
01195 if (!s->value_is_valid)
01196 return -1;
01197
01198 switch (s->utype)
01199 {
01200 case RA_VALUE_TYPE_SHORT:
01201 ra_value_set_short(dest, s->value.s);
01202 break;
01203 case RA_VALUE_TYPE_LONG:
01204 ra_value_set_long(dest, s->value.l);
01205 break;
01206 case RA_VALUE_TYPE_DOUBLE:
01207 ra_value_set_double(dest, s->value.d);
01208 break;
01209 case RA_VALUE_TYPE_CHAR:
01210 ra_value_set_string(dest, s->value.c);
01211 break;
01212 case RA_VALUE_TYPE_VOIDP:
01213 ra_value_set_voidp(dest, s->value.vp);
01214 break;
01215 case RA_VALUE_TYPE_SHORT_ARRAY:
01216 ra_value_set_short_array(dest, s->value.sp, s->num_values);
01217 break;
01218 case RA_VALUE_TYPE_LONG_ARRAY:
01219 ra_value_set_long_array(dest, s->value.lp, s->num_values);
01220 break;
01221 case RA_VALUE_TYPE_DOUBLE_ARRAY:
01222 ra_value_set_double_array(dest, s->value.dp, s->num_values);
01223 break;
01224 case RA_VALUE_TYPE_CHAR_ARRAY:
01225 ra_value_set_string_array(dest, (const char **)(s->value.cp), s->num_values);
01226 break;
01227 case RA_VALUE_TYPE_VOIDP_ARRAY:
01228 ra_value_set_voidp_array(dest, (const void **)(s->value.vpp), s->num_values);
01229 break;
01230 case RA_VALUE_TYPE_VH_ARRAY:
01231 ra_value_set_vh_array(dest, s->value.vhp, s->num_values);
01232 break;
01233 default:
01234 ret = -1;
01235 break;
01236 }
01237
01238 return ret;
01239 }
01240
01241
01254 LIBRAAPI int
01255 ra_value_get_single_elem(value_handle dest, value_handle src, long elem_num)
01256 {
01257 struct ra_value *d = (struct ra_value *)dest;
01258 struct ra_value *s = (struct ra_value *)src;
01259 int ret = 0;
01260
01261 if (!d || !s || !valid_value_handle(d, __LINE__) || !valid_value_handle(s, __LINE__) || (elem_num < 0))
01262 return -1;
01263
01264 if (elem_num >= s->num_values)
01265 return -1;
01266
01267 if (!s->value_is_valid)
01268 return -1;
01269
01270 free_mem(d);
01271
01272 strncpy(d->name, s->name, RA_VALUE_NAME_MAX);
01273 strncpy(d->desc, s->desc, RA_VALUE_DESC_MAX);
01274 d->id = s->id;
01275 d->can_be_changed = 1;
01276
01277 switch (s->utype)
01278 {
01279 case RA_VALUE_TYPE_SHORT:
01280 ra_value_set_short(dest, s->value.s);
01281 break;
01282 case RA_VALUE_TYPE_LONG:
01283 ra_value_set_long(dest, s->value.l);
01284 break;
01285 case RA_VALUE_TYPE_DOUBLE:
01286 ra_value_set_double(dest, s->value.d);
01287 break;
01288 case RA_VALUE_TYPE_CHAR:
01289 ra_value_set_string(dest, s->value.c);
01290 break;
01291 case RA_VALUE_TYPE_VOIDP:
01292 ra_value_set_voidp(dest, s->value.vp);
01293 break;
01294 case RA_VALUE_TYPE_SHORT_ARRAY:
01295 ra_value_set_short(dest, s->value.sp[elem_num]);
01296 break;
01297 case RA_VALUE_TYPE_LONG_ARRAY:
01298 ra_value_set_long(dest, s->value.lp[elem_num]);
01299 break;
01300 case RA_VALUE_TYPE_DOUBLE_ARRAY:
01301 ra_value_set_double(dest, s->value.dp[elem_num]);
01302 break;
01303 case RA_VALUE_TYPE_CHAR_ARRAY:
01304 ra_value_set_string(dest, s->value.cp[elem_num]);
01305 break;
01306 case RA_VALUE_TYPE_VOIDP_ARRAY:
01307 ra_value_set_voidp(dest, s->value.vpp[elem_num]);
01308 break;
01309 case RA_VALUE_TYPE_VH_ARRAY:
01310 ret = ra_value_copy(dest, s->value.vhp[elem_num]);
01311 break;
01312 default:
01313 ret = -1;
01314 break;
01315 }
01316
01317 return ret;
01318 }
01319
01320
01327 void
01328 free_mem(struct ra_value *v)
01329 {
01330 v->value_is_valid = 0;
01331 v->num_values = 0;
01332 switch (v->utype)
01333 {
01334 case RA_VALUE_TYPE_CHAR:
01335 if (v->value.c)
01336 ra_free_mem(v->value.c);
01337 v->value.c = NULL;
01338 if (v->value_locale.c)
01339 ra_free_mem(v->value_locale.c);
01340 v->value_locale.c = NULL;
01341 break;
01342 case RA_VALUE_TYPE_SHORT_ARRAY:
01343 if (v->value.sp)
01344 ra_free_mem(v->value.sp);
01345 v->value.sp = NULL;
01346 break;
01347 case RA_VALUE_TYPE_LONG_ARRAY:
01348 if (v->value.lp)
01349 ra_free_mem(v->value.lp);
01350 v->value.lp = NULL;
01351 break;
01352 case RA_VALUE_TYPE_DOUBLE_ARRAY:
01353 if (v->value.dp)
01354 ra_free_mem(v->value.dp);
01355 v->value.dp = NULL;
01356 break;
01357 case RA_VALUE_TYPE_CHAR_ARRAY:
01358 if (v->value.cp)
01359 {
01360 long l;
01361 for (l = 0; l < v->num_values; l++)
01362 {
01363 if (v->value.cp[l])
01364 ra_free_mem(v->value.cp[l]);
01365 }
01366 ra_free_mem(v->value.cp);
01367 }
01368 v->value.cp = NULL;
01369 if (v->value_locale.cp)
01370 {
01371 long l;
01372 for (l = 0; l < v->num_values; l++)
01373 {
01374 if (v->value_locale.cp[l])
01375 ra_free_mem(v->value_locale.cp[l]);
01376 }
01377 ra_free_mem(v->value_locale.cp);
01378 }
01379 v->value_locale.cp = NULL;
01380 break;
01381 case RA_VALUE_TYPE_VOIDP_ARRAY:
01382 if (v->value.vpp)
01383 ra_free_mem(v->value.vpp);
01384 v->value.vpp = NULL;
01385 break;
01386 case RA_VALUE_TYPE_VH_ARRAY:
01387 if (v->value.vhp)
01388 {
01389 long l;
01390 for (l = 0; l < v->num_values; l++)
01391 ra_value_free(v->value.vhp[l]);
01392 ra_free_mem(v->value.vhp);
01393 }
01394 v->value.vhp = NULL;
01395 break;
01396 }
01397
01398 v->utype = RA_VALUE_TYPE_NONE;
01399 }
01400
01401