#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libdB/AppendBlank.c $ %D% SwRI" #include #include "dbf.h" /*********************** ** >FILE: AppendBlank.c ***********************/ /**************************************** ** Function: int AppenBlank(int handle) ** ** int handle handle to database structure ** ** Description: ** This subroutine append a blank record to the database. Any character ** fields are initializes to spaces while the numeric fields are set to 0. ** If, before the append, the current record has not been updated it is ** written to the database. If an error occurs, and error number is ** returned to the calling routine. ** ** Return Values: ** ***************** *****************/ dbRet_t AppendBlank(SDDAS_INT handle) { dbfRecord_t *D; FieldRecord_t *fld; SDDAS_INT i, j; dbRet_t rval; if ((D = GetOldDbfHandle(handle)) == NULL) return FAILURE; /* | if the current record needs writing out then do so */ if (D->rStatus == Updated) { if ((rval = PutDbfRecord(handle, D->CurRec)) != SUCCESS) { return rval; } } /* | clear all fields */ for (i=0; iNumFields; i++) { fld = &D->Fields[i]; switch (fld->Typ) { /* | put spaces in for the character type */ case CHARACTER: for (j=0; jLen; j++) { *(fld->Parm + j) = ' '; } break; /* | for the numeric type reset the value to zero */ case NUMERIC: if (fld->Dec == 0) { (void)sprintf(fld->Parm, "%*d", fld->Len, (int)0); } else { (void)sprintf(fld->Parm, "%*.*f", fld->Len, fld->Dec, (float) 0.0); } break; } } /* | indicate this record is NOT deleted */ D->CurRecord[0][0] = ' '; /* | append it to the database and return the status from appending */ return(AppendDbf(handle)); }