--------------------------------------------------------------------------- | Facility : libnform | Function : int set_field_buffer(FIELD *field, | int buffer, char *value) | | Description : Set the given buffer of the field to the given value. | Buffer 0 stores the displayed content of the field. |
| 3776 | Field-Buffer manipulation routines. |
| 3777 | The effects of setting a buffer is tightly coupled to the core of the form |
| 3778 | driver logic. This is especially true in the case of growable fields. |
| 3779 | So I don't separate this into an own module. |
| 3780 | --------------------------------------------------------------------------*/ |
| 3781 | |
| 3782 | /*--------------------------------------------------------------------------- |
| 3783 | | Facility : libnform |
| 3784 | | Function : int set_field_buffer(FIELD *field, |
| 3785 | | int buffer, char *value) |
| 3786 | | |
| 3787 | | Description : Set the given buffer of the field to the given value. |
| 3788 | | Buffer 0 stores the displayed content of the field. |
| 3789 | | For dynamic fields this may grow the fieldbuffers if |
| 3790 | | the length of the value exceeds the current buffer |
| 3791 | | length. For buffer 0 only printable values are allowed. |
| 3792 | | For static fields, the value needs not to be zero ter- |
| 3793 | | minated. It is copied up to the length of the buffer. |
| 3794 | | |
| 3795 | | Return Values : E_OK - success |
| 3796 | | E_BAD_ARGUMENT - invalid argument |
| 3797 | | E_SYSTEM_ERROR - system error |
| 3798 | +--------------------------------------------------------------------------*/ |
| 3799 | int set_field_buffer(FIELD * field, int buffer, const char * value) |
| 3800 | { |
| 3801 | char *s, *p; |
| 3802 | int res = E_OK; |
| 3803 | unsigned int len; |
| 3804 | |
| 3805 | if ( !field || !value || ((buffer < 0)||(buffer > field->nbuf)) ) |
| 3806 | RETURN(E_BAD_ARGUMENT); |
| 3807 | |
| 3808 | len = Buffer_Length(field); |
| 3809 | |
| 3810 | if (buffer==0) |
| 3811 | { |
| 3812 | const char *v; |
| 3813 | unsigned int i = 0; |
| 3814 | |
| 3815 | for(v=value; *v && (i<len); v++,i++) |
| 3816 | { |
| 3817 | if (!isprint((unsigned char)*v)) |
| 3818 | RETURN(E_BAD_ARGUMENT); |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | if (Growable(field)) |
| 3823 | { |
| 3824 | /* for a growable field we must assume zero terminated strings, because |
| 3825 | somehow we have to detect the length of what should be copied. |
| 3826 | */ |
| 3827 | unsigned int vlen = strlen(value); |
| 3828 | if (vlen > len) |
| 3829 | { |
| 3830 | if (!Field_Grown(field, |
| 3831 | (int)(1 + (vlen-len)/((field->rows+field->nrow)*field->cols)))) |
| 3832 | RETURN(E_SYSTEM_ERROR); |
| 3833 | |
| 3834 | /* in this case we also have to check, whether or not the remaining |
| 3835 | characters in value are also printable for buffer 0. */ |
no test coverage detected
searching dependent graphs…