short DB_Query(mvar *var, u_char *buf, int dir) // get next key { short s; // for returns int i; // a handy int s = Copy2local(var); // get local copy if (s < 0) { return s; // exit on error } systab->vol[volnum-1]->stats.dbqry++; // update stats if (dir < 0) // if it's backward { s = Get_data(-1); // get the previous if ((s < 0) && (s != -ERRM7)) // check for errors { if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } return s; // and return the error } if ((level == 0) && (s == -ERRM7)) // if no such global { buf[0] = '\0'; // null terminate ret if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } return 0; // and return } Index--; // backup the Index if (Index < 10) // can't happen? { panic("DB_Query: Problem with negative direction"); } chunk = (cstring *) &iidx[idx[Index]]; // point at the chunk record = (cstring *) &chunk->buf[chunk->buf[1]+4]; // point at the dbc if ((!chunk->buf[0]) && (!chunk->buf[1]) && // if first node ((partab.jobtab->last_block_flags & GL_TOP_DEFINED) == 0)) { buf[0] = '\0'; // null terminate ret if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } return 0; // and return } } // end backwards else // it's forward { s = Get_data(0); // try to find that if ((s < 0) && (s != -ERRM7)) // check for errors { if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } return s; // and return the error } if ((level == 0) && (s == -ERRM7)) // if no such global { buf[0] = '\0'; // null terminate ret if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } return 0; // and return } if ((s < 0) && (!db_var.slen)) { Index++; } if ((Index > blk[level]->mem->last_idx) || (s >= 0)) // want next one { s = Locate_next(); // point at next if (s < 0) // not found or error { if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } buf[0] = '\0'; // null terminate ret if (s == -ERRM7) // undefined? { s = 0; // yes - clear it } return s; // done } } } for (i = 10; i <= Index; i++) // scan to current { chunk = (cstring *) &iidx[idx[i]]; // point at the chunk bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1], chunk->buf[1]); // update the key keybuf[0] = chunk->buf[0] + chunk->buf[1]; // and the size } if (curr_lock) // if locked { SemOp( SEM_GLOBAL, -curr_lock); // release global lock } db_var.uci = var->uci; // copy db_var.volset = var->volset; // original & new db_var.name.var_qu = var->name.var_qu; // data db_var.slen = keybuf[0]; // to bcopy(&keybuf[1], &db_var.key[0], keybuf[0]); // db_var return UTIL_String_Mvar(&db_var, buf, 9999); // convert and return }
short Dname2(u_char *ret_buffer, mvar *var, int sub) { if (sub < 0) return -(ERRM39); // Invalid $NAME argument return UTIL_String_Mvar(var, ret_buffer, sub); // do it elsewhere }