aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbrdel.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /pkg/tbtables/tbrdel.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/tbtables/tbrdel.x')
-rw-r--r--pkg/tbtables/tbrdel.x77
1 files changed, 77 insertions, 0 deletions
diff --git a/pkg/tbtables/tbrdel.x b/pkg/tbtables/tbrdel.x
new file mode 100644
index 00000000..23796f15
--- /dev/null
+++ b/pkg/tbtables/tbrdel.x
@@ -0,0 +1,77 @@
+include <tbset.h>
+include "tbtables.h"
+include "tblerr.h"
+
+# tbrdel -- delete rows
+# This routine deletes a range of rows.
+# NOTE: The number of rows TB_NROWS(tp) will be modified by this routine
+# if the range of rows to be deleted is within the table. The physical
+# disk space occupied by these rows will not be deallocated; the file
+# will still be just as large as before.
+#
+# Phil Hodge, 23-Mar-1988 Subroutine created.
+# Phil Hodge, 3-Apr-1995 Set TB_MODIFIED to true.
+# Phil Hodge, 6-Mar-1998 Modify to allow a row selector, if the rows
+# to be deleted are at the end of the table.
+
+procedure tbrdel (tp, firstrow, lastrow)
+
+pointer tp # i: pointer to table descriptor
+int firstrow # i: first row to be deleted
+int lastrow # i: last row to be deleted
+#--
+int row1 # actual first row to be deleted
+int nrows # number of rows written to table
+int ndel # number of rows to be deleted
+int rst_rownum()
+errchk tbxnll, tbynll, tbznll, tbfchp, tbrsft
+
+begin
+ if (firstrow < 1 || lastrow < 1)
+ call error (1, "tbrdel: Row number less than one is invalid.")
+
+ if (firstrow > lastrow)
+ return
+
+ nrows = TB_NROWS(tp)
+
+ if (TB_ROW_SELECT(tp) == YES) {
+
+ if (lastrow < TB_NSEL_ROWS(tp))
+ call error (1,
+ "Can't delete rows in the middle of a table that uses a row selector.")
+
+ if (firstrow > TB_NSEL_ROWS(tp))
+ return # nothing to do
+
+ row1 = rst_rownum (TB_ROWSET(tp), firstrow)
+ # and row2 = nrows
+
+ if (nrows - row1 > TB_NSEL_ROWS(tp) - firstrow)
+ call error (1,
+ "tbrdel: Range of rows to delete includes non-selected rows.")
+
+ ndel = nrows - row1 + 1
+
+ if (TB_TYPE(tp) == TBL_TYPE_S_ROW)
+ call tbxnll (tp, max (1, nrows-ndel+1), nrows)
+ else if (TB_TYPE(tp) == TBL_TYPE_S_COL)
+ call tbynll (tp, max (1, nrows-ndel+1), nrows)
+ else if (TB_TYPE(tp) == TBL_TYPE_TEXT)
+ call tbznll (tp, max (1, nrows-ndel+1), nrows)
+ else if (TB_TYPE(tp) == TBL_TYPE_FITS)
+ call tbfchp (tp, ndel)
+ else
+ call error (ER_TBCORRUPTED, "tbrdel: invalid table type")
+
+ TB_NROWS(tp) = max (0, nrows - ndel)
+
+ } else {
+
+ ndel = min (nrows, lastrow) - firstrow + 1
+ # Shift the rows.
+ call tbrsft (tp, firstrow, -ndel)
+ }
+
+ TB_MODIFIED(tp) = true
+end