--------------------------------------------------------------------------- | Facility : libnform | Function : static int Insert_String( | FORM * form, | int row, | char *txt, | int len ) | | Descript
| 2011 | | on the beginning of the row, all other characters are |
| 2012 | | moved to the right. After the text a pad character will |
| 2013 | | be inserted to separate the text from the rest. If |
| 2014 | | necessary the insertion moves characters on the next |
| 2015 | | line to make place for the requested insertion string. |
| 2016 | | |
| 2017 | | Return Values : E_OK - success |
| 2018 | | E_REQUEST_DENIED - |
| 2019 | | E_SYSTEM_ERROR - system error |
| 2020 | +--------------------------------------------------------------------------*/ |
| 2021 | static int Insert_String(FORM *form, int row, char *txt, int len) |
| 2022 | { |
| 2023 | FIELD *field = form->current; |
| 2024 | char *bp = Address_Of_Row_In_Buffer(field,row); |
| 2025 | int datalen = (int)(After_End_Of_Data(bp,field->dcols) - bp); |
| 2026 | int freelen = field->dcols - datalen; |
| 2027 | int requiredlen = len+1; |
| 2028 | char *split; |
| 2029 | int result = E_REQUEST_DENIED; |
| 2030 | char *Space; |
| 2031 | |
| 2032 | Space = (char*)malloc(2*sizeof(char)); |
| 2033 | strcpy(Space, " "); |
| 2034 | |
| 2035 | if (freelen >= requiredlen) |
| 2036 | { |
| 2037 | wmove(form->w,row,0); |
| 2038 | winsnstr(form->w,txt,len); |
| 2039 | wmove(form->w,row,len); |
| 2040 | winsnstr(form->w,Space,1); |
| 2041 | free(Space); |
| 2042 | return E_OK; |
| 2043 | } |
| 2044 | else |
| 2045 | { /* we have to move characters on the next line. If we are on the |
| 2046 | last line this may work, if the field is growable */ |
| 2047 | if ((row == (field->drows - 1)) && Growable(field)) |
| 2048 | { |
| 2049 | if (!Field_Grown(field,1)) |
| 2050 | { |
| 2051 | free(Space); |
| 2052 | return(E_SYSTEM_ERROR); |
| 2053 | } |
| 2054 | /* !!!Side-Effect : might be changed due to growth!!! */ |
| 2055 | bp = Address_Of_Row_In_Buffer(field,row); |
| 2056 | } |
| 2057 | |
| 2058 | if (row < (field->drows - 1)) |
| 2059 | { |
| 2060 | split = After_Last_Whitespace_Character(bp, |
| 2061 | (int)(Get_Start_Of_Data(bp + field->dcols - requiredlen , |
| 2062 | requiredlen) - bp)); |
| 2063 | /* split points now to the first character of the portion of the |
| 2064 | line that must be moved to the next line */ |
| 2065 | datalen = (int)(split-bp); /* + freelen has to stay on this line */ |
| 2066 | freelen = field->dcols - (datalen + freelen); /* for the next line */ |
| 2067 | |
| 2068 | if ((result=Insert_String(form,row+1,split,freelen))==E_OK) |
| 2069 | { |
| 2070 | wmove(form->w,row,datalen); |
no test coverage detected
searching dependent graphs…