plan9port/src/libndb/ndbreorder.c

54 lines
964 B
C
Raw Normal View History

2005-02-11 19:41:16 +00:00
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ndb.h>
/*
* reorder the tuple to put x's line first in the entry and x fitst in its line
*/
Ndbtuple*
ndbreorder(Ndbtuple *t, Ndbtuple *x)
{
Ndbtuple *nt;
Ndbtuple *last, *prev;
/* if x is first, we're done */
if(x == t)
return t;
/* find end of x's line */
for(last = x; last->line == last->entry; last = last->line)
;
/* rotate to make this line first */
if(last->line != t){
/* detach this line and everything after it from the entry */
for(nt = t; nt->entry != last->line; nt = nt->entry)
;
nt->entry = nil;
2005-02-11 19:41:16 +00:00
/* switch */
for(nt = last; nt->entry != nil; nt = nt->entry)
;
nt->entry = t;
}
/* rotate line to make x first */
if(x != last->line){
/* find entry before x */
fix clang 3.4 warnings and ignore uninteresting ones fixed warnings: src/cmd/fossil/disk.c:37:14: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator] src/cmd/fossil/disk.c:38:14: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator] src/cmd/fossil/disk.c:39:14: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator] src/cmd/fossil/disk.c:40:13: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator] src/cmd/fossil/disk.c:41:14: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator] src/libndb/ndbreorder.c:41:55: warning: for loop has empty body [-Wempty-body] ignored warnings: src/cmd/acid/dbg.y:393:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/bc.y:1327:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/bc.y:1327:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/grep/grep.y:420:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/grep/grep.y:420:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/hoc/hoc.y:692:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/hoc/hoc.y:692:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/lex/parser.y:886:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/rc/syn.y:303:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/cmd/units.y:1003:9: warning: array index -1 is before the beginning of the array [-Warray-bounds] src/libregexp/regcomp.c:19:16: warning: variable 'reprog' is not needed and will not be emitted [-Wunneeded-internal-declaration] LGTM=rsc R=rsc https://codereview.appspot.com/158250043
2014-10-21 14:22:12 +02:00
for(prev = last; prev->line != x; prev = prev->line)
2005-02-11 19:41:16 +00:00
;
/* detach line */
nt = last->entry;
last->entry = last->line;
/* reattach */
prev->entry = nt;
}
return x;
}