985 |
|
} |
986 |
|
return(NULL); |
987 |
|
} |
988 |
< |
if (viewfp == NULL) { /* open file */ |
988 |
> |
if (viewfp == NULL) { /* open file */ |
989 |
|
if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { |
990 |
|
perror(vval(VIEWFILE)); |
991 |
|
quit(1); |
992 |
|
} |
993 |
< |
} else if (n < viewnum) { /* rewind file */ |
993 |
> |
} else if (n > 0 && n < viewnum) { /* rewind file */ |
994 |
|
if (viewnum == 1 && feof(viewfp)) |
995 |
|
return(&curview); /* just one view */ |
996 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
1000 |
|
copystruct(&curview, &stdview); |
1001 |
|
viewnum = 0; |
1002 |
|
} |
1003 |
+ |
if (n < 0) { /* get next view */ |
1004 |
+ |
register int c = getc(viewfp); |
1005 |
+ |
if (c == EOF) |
1006 |
+ |
return((VIEW *)NULL); /* that's it */ |
1007 |
+ |
ungetc(c, viewfp); |
1008 |
+ |
n = viewnum + 1; |
1009 |
+ |
} |
1010 |
|
while (n > viewnum) { /* scan to desired view */ |
1011 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
1012 |
|
return(viewnum==1 ? &curview : (VIEW *)NULL); |
1020 |
|
int |
1021 |
|
countviews() /* count views in view file */ |
1022 |
|
{ |
1023 |
< |
register int n = 0; |
1023 |
> |
int n; |
1024 |
|
|
1025 |
< |
while (getview(n+1) != NULL) |
1025 |
> |
if (getview(n=1) == NULL) |
1026 |
> |
return(0); |
1027 |
> |
while (getview(-1) != NULL) |
1028 |
|
n++; |
1029 |
|
return(n); |
1030 |
|
} |