📄 vfile.c
字号:
VFILE *vfile;unsigned char c;{ vseek(vfile, vtell(vfile)); return vputc(vfile, c);}short vgetw(vfile)VFILE *vfile;{ short w; if (vtell(vfile) + 2 > vsize(vfile)) return -1; w = vgetc(vfile); w += ((short) vgetc(vfile) << 8); return w;}short vputw(vfile, w)VFILE *vfile;short w;{ vputc(vfile, w); vputc(vfile, w >> 8); return w;}long vgetl(vfile)VFILE *vfile;{ long w; if (vtell(vfile) + 4 > vsize(vfile)) return -1; w = vgetc(vfile); w += ((long) vgetc(vfile) << 8); w += ((long) vgetc(vfile) << 16); w += ((long) vgetc(vfile) << 24); return w;}long vputl(vfile, w)VFILE *vfile;long w;{ vputc(vfile, w); vputc(vfile, w >> 8); vputc(vfile, w >> 16); vputc(vfile, w >> 24); return w;}int _rc(vfile, addr)VFILE *vfile;long addr;{ if (vfile->vpage1) vunlock(vfile->vpage1); vfile->vpage1 = vlock(vfile, vfile->addr = (addr & ~(long) (PGSIZE - 1))); return rc(vfile, addr);}int _wc(vfile, addr, c)VFILE *vfile;long addr;unsigned char c;{ if (addr + 1 > vsize(vfile)) my_valloc(vfile, addr + 1 - vsize(vfile)); if (vfile->vpage1) vunlock(vfile->vpage1); vfile->vpage1 = vlock(vfile, vfile->addr = (addr & ~(long) (PGSIZE - 1))); return wc(vfile, addr, c);}short rw(vfile, addr)VFILE *vfile;long addr;{ short c; if (addr + 2 > vsize(vfile)) return -1; c = rc(vfile, addr); c += ((short) rc(vfile, addr + 1) << 8); return c;}short ww(vfile, addr, c)VFILE *vfile;long addr;short c;{ if (addr + 2 > vsize(vfile)) my_valloc(vfile, addr + 2 - vsize(vfile)); wc(vfile, addr, c); wc(vfile, addr + 1, c >> 8); return c;}long rl(vfile, addr)VFILE *vfile;long addr;{ long c; if (addr + 4 > vsize(vfile)) return -1; c = rc(vfile, addr); c += ((long) rc(vfile, addr + 1) << 8); c += ((long) rc(vfile, addr + 2) << 16); c += ((long) rc(vfile, addr + 3) << 24); return c;}long wl(vfile, addr, c)VFILE *vfile;long addr;long c;{ if (addr + 4 > vsize(vfile)) my_valloc(vfile, addr + 4 - vsize(vfile)); wc(vfile, addr, c); wc(vfile, addr + 1, c >> 8); wc(vfile, addr + 2, c >> 16); wc(vfile, addr + 3, c >> 24); return c;}void vread(v, blk, size)VFILE *v;unsigned char *blk;int size;{ long addr = vtell(v); unsigned char *src; int x; while (size) { src = vlock(v, addr); x = PGSIZE - (addr & (PGSIZE - 1)); if (x >= size) { vseek(v, addr + size); mcpy(blk, src, size); vunlock(src); return; } size -= x; addr += x; mcpy(blk, src, x); blk += x; vunlock(src); } vseek(v, addr);}void vwrite(v, blk, size)VFILE *v;unsigned char *blk;int size;{ long addr = vtell(v); unsigned char *src; int x; if (addr + size > vsize(v)) my_valloc(v, addr + size - vsize(v)); while (size) { src = vlock(v, addr); x = PGSIZE - (addr & (PGSIZE - 1)); if (x >= size) { vseek(v, addr + size); mcpy(src, blk, size); vchanged(src); vunlock(src); return; } size -= x; addr += x; mcpy(src, blk, x); blk += x; vchanged(src); vunlock(src); } vseek(v, addr);}/* Write zstring to vfile */void vputs(v, s)VFILE *v;unsigned char *s;{ while (*s) { vputc(v, *s); ++s; }}/* Read a line from a file. Remove '\n' if there was any */unsigned char *vgets(v, s)VFILE *v;unsigned char *s;{ unsigned char *b, *a, *x, *y; int cnt; /* Return with NULL if at end of file */ if (vtell(v) == vsize(v)) { vsrm(s); return NULL; } /* Create string if it doesn't exist */ if (!s) s = vsmk(80); /* Zero string length */ sLen(s) = 0; loop: /* Set b to end of string, a to page pointer, and cnt to min which ever * (string or page) has the least space left */ b = s + sLen(s); a = v->bufp; cnt = Imin(sSIZ(s) - sLen(s), v->left - v->lv); /* Copy until \n is found or until page or buffer out of space */ if (cnt >= 16) do { if ((b[0] = a[0]) == '\n') { a += 1; b += 1; goto ovr; } if ((b[1] = a[1]) == '\n') { a += 2; b += 2; cnt -= 1; goto ovr; } if ((b[2] = a[2]) == '\n') { a += 3; b += 3; cnt -= 2; goto ovr; } if ((b[3] = a[3]) == '\n') { a += 4; b += 4; cnt -= 3; goto ovr; } if ((b[4] = a[4]) == '\n') { a += 5; b += 5; cnt -= 4; goto ovr; } if ((b[5] = a[5]) == '\n') { a += 6; b += 6; cnt -= 5; goto ovr; } if ((b[6] = a[6]) == '\n') { a += 7; b += 7; cnt -= 6; goto ovr; } if ((b[7] = a[7]) == '\n') { a += 8; b += 8; cnt -= 7; goto ovr; } if ((b[8] = a[8]) == '\n') { a += 9; b += 9; cnt -= 8; goto ovr; } if ((b[9] = a[9]) == '\n') { a += 10; b += 10; cnt -= 9; goto ovr; } if ((b[10] = a[10]) == '\n') { a += 11; b += 11; cnt -= 10; goto ovr; } if ((b[11] = a[11]) == '\n') { a += 12; b += 12; cnt -= 11; goto ovr; } if ((b[12] = a[12]) == '\n') { a += 13; b += 13; cnt -= 12; goto ovr; } if ((b[13] = a[13]) == '\n') { a += 14; b += 14; cnt -= 13; goto ovr; } if ((b[14] = a[14]) == '\n') { a += 15; b += 15; cnt -= 14; goto ovr; } if ((b[15] = a[15]) == '\n') { a += 16; b += 16; cnt -= 15; goto ovr; } } while (a += 16, b += 16, (cnt -= 16) >= 16);/* x = a; y = b; a += cnt - 15; b += cnt - 15; switch(cnt) { case 15: if((b[0]=a[0])=='\n') { a+=1; b+=1; goto zif; } case 14: if((b[1]=a[1])=='\n') { a+=2; b+=2; goto zif; } case 13: if((b[2]=a[2])=='\n') { a+=3; b+=3; goto zif; } case 12: if((b[3]=a[3])=='\n') { a+=4; b+=4; goto zif; } case 11: if((b[4]=a[4])=='\n') { a+=5; b+=5; goto zif; } case 10: if((b[5]=a[5])=='\n') { a+=6; b+=6; goto zif; } case 9: if((b[6]=a[6])=='\n') { a+=7; b+=7; goto zif; } case 8: if((b[7]=a[7])=='\n') { a+=8; b+=8; goto zif; } case 7: if((b[8]=a[8])=='\n') { a+=9; b+=9; goto zif; } case 6: if((b[9]=a[9])=='\n') { a+=10; b+=10; goto zif; } case 5: if((b[10]=a[10])=='\n'){ a+=11; b+=11; goto zif; } case 4: if((b[11]=a[11])=='\n'){ a+=12; b+=12; goto zif; } case 3: if((b[12]=a[12])=='\n'){ a+=13; b+=13; goto zif; } case 2: if((b[13]=a[13])=='\n'){ a+=14; b+=14; goto zif; } case 1: if((b[14]=a[14])=='\n'){ a+=15; b+=15; goto zif; } } a = x + cnt; b = y + cnt; cnt=0; goto ovr;zif: cnt -= a - x - 1;*/ if (cnt) do { if ((*b++ = *a++) == '\n') break; } while (--cnt); ovr: /* Update string and page data */ sLen(s) = b - s; v->left -= a - v->bufp; v->bufp = a; if (!cnt) if (vtell(v) == vsize(v)) b[0] = 0; else { if (sLen(s) == sSiz(s)) s = vsensure(s, sLen(s) + (sLen(s) >> 1) + 16); if (!v->left) vseek(v, vtell(v)); goto loop; } else b[-1] = 0; return s;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -