本文整理匯總了C++中Binit函數的典型用法代碼示例。如果您正苦於以下問題:C++ Binit函數的具體用法?C++ Binit怎麽用?C++ Binit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Binit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: tcmd
void
tcmd(char *arname, int count, char **files)
{
int fd;
Armember *bp;
char name[ARNAMESIZE+1];
fd = openar(arname, OREAD, 0);
Binit(&bar, fd, OREAD);
Bseek(&bar,seek(fd,0,1), 1);
while(bp = getdir(&bar)) {
if(count == 0 || match(count, files)) {
if(vflag)
longt(bp);
trim(file, name, ARNAMESIZE);
Bprint(&bout, "%s\n", name);
}
skip(&bar, bp->size);
free(bp);
}
close(fd);
}
示例2: pcmd
void
pcmd(char *arname, int count, char **files)
{
int fd;
Armember *bp;
fd = openar(arname, OREAD, 0);
Binit(&bar, fd, OREAD);
Bseek(&bar,seek(fd,0,1), 1);
while(bp = getdir(&bar)) {
if(count == 0 || match(count, files)) {
if(vflag)
print("\n<%s>\n\n", file);
arcopy(&bar, 0, bp);
if (write(1, bp->member, bp->size) < 0)
wrerr();
} else
skip(&bar, bp->size);
free(bp);
}
close(fd);
}
示例3: threadmain
void
threadmain(int argc, char *argv[])
{
int i;
Index *ix;
u32int bcmem;
bcmem = 0;
ARGBEGIN{
case 'B':
bcmem = unittoull(ARGF());
break;
default:
usage();
break;
}ARGEND
if(argc < 1)
usage();
fmtinstall('H', encodefmt);
if(initventi(argv[0], &conf) < 0)
sysfatal("can't init venti: %r");
if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
initdcache(bcmem);
ix = mainindex;
Binit(&bout, 1, OWRITE);
for(i=0; i<ix->nsects; i++)
if(shoulddump(ix->sects[i]->name, argc-1, argv+1))
dumpisect(ix->sects[i]);
Bterm(&bout);
threadexitsall(0);
}
示例4: pushinput
static void
pushinput(char *name, int fd, uchar *str)
{
Input *in;
int depth;
depth = 0;
for(in=input; in; in=in->next)
if(depth++ >= 10) /* prevent deep C stack in plumber and bad include structure */
parseerror("include stack too deep; max 10");
in = emalloc(sizeof(Input));
in->file = estrdup(name);
in->next = input;
input = in;
if(str)
in->s = str;
else{
in->fd = emalloc(sizeof(Biobuf));
if(Binit(in->fd, fd, OREAD) < 0)
parseerror("can't initialize Bio for rules file: %r");
}
}
示例5: main
void
main(int argc, char *argv[])
{
Fils fstr[NFILES];
int nfdone = 0;
Binit(&bout, 1, OWRITE);
Files = fstr;
for(argc = findopt(argc, argv); argc > 0; --argc, ++argv)
if(Multi == 'm') {
if(Nfiles >= NFILES - 1)
die("too many files");
if(mustopen(*argv, &Files[Nfiles++]) == 0)
nfdone++; /* suppress printing */
} else {
if(pr(*argv))
Bterm(Files->f_f);
nfdone++;
}
if(!nfdone) /* no files named, use stdin */
pr(nulls); /* on GCOS, use current file, if any */
errprint(); /* print accumulated error reports */
exits(error? "error": 0);
}
示例6: rdgeom
static void
rdgeom(SDunit *unit)
{
char *line;
char *flds[5];
Biobuf bb;
Biobuf *bp;
static char geom[] = "geometry ";
bp = &bb;
seek(unit->ctl, 0, 0);
Binit(bp, unit->ctl, OREAD);
while((line = Brdline(bp, '\n')) != nil){
line[Blinelen(bp) - 1] = '\0';
if (strncmp(line, geom, sizeof geom - 1) == 0)
break;
}
if (line != nil && tokenize(line, flds, nelem(flds)) >= 3) {
unit->sectors = atoll(flds[1]);
unit->secsize = atoll(flds[2]);
}
Bterm(bp);
seek(unit->ctl, 0, 0);
}
示例7: opensd
static Disk*
opensd(Disk *disk)
{
Biobuf b;
char *p, *f[10];
int nf;
Binit(&b, disk->ctlfd, OREAD);
while(p = Brdline(&b, '\n')) {
p[Blinelen(&b)-1] = '\0';
nf = tokenize(p, f, nelem(f));
if(nf >= 3 && strcmp(f[0], "geometry") == 0) {
disk->secsize = strtoll(f[2], 0, 0);
if(nf >= 6) {
disk->c = strtol(f[3], 0, 0);
disk->h = strtol(f[4], 0, 0);
disk->s = strtol(f[5], 0, 0);
}
}
if(nf >= 4 && strcmp(f[0], "part") == 0 && strcmp(f[1], disk->part) == 0) {
disk->offset = strtoll(f[2], 0, 0);
disk->secs = strtoll(f[3], 0, 0) - disk->offset;
}
}
disk->size = disk->secs * disk->secsize;
if(disk->size <= 0) {
strcpy(disk->part, "");
disk->type = Tfile;
return openfile(disk);
}
findgeometry(disk);
return mkwidth(disk);
}
示例8: main
void
main(int argc, char **argv)
{
int i, ok, rcvrs;
char *addr, *rv, *trv, *host, *domain;
char **errs;
char hellodomain[256];
String *from, *fromm, *sender;
alarmscale = 60*1000; /* minutes */
quotefmtinstall();
fmtinstall('[', encodefmt);
errs = malloc(argc*sizeof(char*));
reply = s_new();
host = 0;
ARGBEGIN{
case 'a':
tryauth = 1;
if(trysecure == 0)
trysecure = 1;
break;
case 'A': /* autistic: won't talk to us until we talk (Verizon) */
autistic = 1;
break;
case 'b':
if (bustedmx >= Maxbustedmx)
sysfatal("more than %d busted mxs given", Maxbustedmx);
bustedmxs[bustedmx++] = EARGF(usage());
break;
case 'd':
debug = 1;
break;
case 'f':
filter = 1;
break;
case 'g':
gdomain = EARGF(usage());
break;
case 'h':
host = EARGF(usage());
break;
case 'i':
insecure = 1;
break;
case 'p':
alarmscale = 10*1000; /* tens of seconds */
ping = 1;
break;
case 's':
if(trysecure == 0)
trysecure = 1;
break;
case 't':
trysecure = 2;
break;
case 'u':
user = EARGF(usage());
break;
default:
usage();
break;
}ARGEND;
Binit(&berr, 2, OWRITE);
Binit(&bfile, 0, OREAD);
/*
* get domain and add to host name
*/
if(*argv && **argv=='.') {
domain = *argv;
argv++; argc--;
} else
domain = domainname_read();
if(host == 0)
host = sysname_read();
strcpy(hostdomain, domainify(host, domain));
strcpy(hellodomain, domainify(sysname_read(), domain));
/*
* get destination address
*/
if(*argv == 0)
usage();
addr = *argv++; argc--;
farend = addr;
/*
* get sender's machine.
* get sender in internet style. domainify if necessary.
*/
if(*argv == 0)
usage();
sender = unescapespecial(s_copy(*argv++));
argc--;
fromm = s_clone(sender);
rv = strrchr(s_to_c(fromm), '!');
if(rv)
*rv = 0;
else
//.........這裏部分代碼省略.........
示例9: main
void
main(int argc, char *argv[])
{
int fd;
long i, j, k, n;
Dir *d;
char *name;
ulong *data;
ulong tbase, sum;
long delta;
Symbol s;
Biobuf outbuf;
Fhdr f;
struct COUNTER *cp;
char filebuf[128], *file;
if(argc != 2 && argc != 3)
error(0, "usage: tprof pid [binary]");
/*
* Read symbol table
*/
if(argc == 2){
file = filebuf;
snprint(filebuf, sizeof filebuf, "/proc/%s/text", argv[1]);
}else
file = argv[2];
fd = open(file, OREAD);
if(fd < 0)
error(1, file);
if (!crackhdr(fd, &f))
error(1, "read text header");
if (f.type == FNONE)
error(0, "text file not an a.out");
machbytype(f.type);
if (syminit(fd, &f) < 0)
error(1, "syminit");
close(fd);
/*
* Read timing data
*/
file = smprint("/proc/%s/profile", argv[1]);
fd = open(file, OREAD);
if(fd < 0)
error(1, file);
free(file);
d = dirfstat(fd);
if(d == nil)
error(1, "stat");
n = d->length/sizeof(data[0]);
if(n < 2)
error(0, "data file too short");
data = malloc(d->length);
if(data == 0)
error(1, "malloc");
if(read(fd, data, d->length) < 0)
error(1, "text read");
close(fd);
for(i=0; i<n; i++)
data[i] = machdata->swal(data[i]);
delta = data[0]-data[1];
print("total: %ld\n", data[0]);
if(data[0] == 0)
exits(0);
if (!textsym(&s, 0))
error(0, "no text symbols");
tbase = s.value & ~(mach->pgsize-1); /* align down to page */
print("TEXT %.8lux\n", tbase);
/*
* Accumulate counts for each function
*/
cp = 0;
k = 0;
for (i = 0, j = (s.value-tbase)/PCRES+2; j < n; i++) {
name = s.name; /* save name */
if (!textsym(&s, i)) /* get next symbol */
break;
sum = 0;
while (j < n && j*PCRES < s.value-tbase)
sum += data[j++];
if (sum) {
cp = realloc(cp, (k+1)*sizeof(struct COUNTER));
if (cp == 0)
error(1, "realloc");
cp[k].name = name;
cp[k].time = sum;
k++;
}
}
if (!k)
error(0, "no counts");
cp[k].time = 0; /* "etext" can take no time */
/*
* Sort by time and print
*/
qsort(cp, k, sizeof(struct COUNTER), compar);
Binit(&outbuf, 1, OWRITE);
//.........這裏部分代碼省略.........
示例10: arcmd
/*
* perform the 'r' and 'u' commands
*/
void
arcmd(char *arname, int count, char **files)
{
int fd;
int i;
Arfile *ap;
Armember *bp;
Dir *d;
Biobuf *bfile;
fd = openar(arname, ORDWR, 1);
if (fd >= 0) {
Binit(&bar, fd, OREAD);
Bseek(&bar,seek(fd,0,1), 1);
}
astart = newtempfile(artemp);
ap = astart;
aend = 0;
for(i = 0; fd >= 0; i++) {
bp = getdir(&bar);
if (!bp)
break;
if (bamatch(file, poname)) { /* check for pivot */
aend = newtempfile(tailtemp);
ap = aend;
}
/* pitch symdef file */
if (i == 0 && strcmp(file, symdef) == 0) {
skip(&bar, bp->size);
continue;
}
if (count && !match(count, files)) {
scanobj(&bar, ap, bp->size);
arcopy(&bar, ap, bp);
continue;
}
bfile = Bopen(file, OREAD);
if (!bfile) {
if (count != 0)
fprint(2, "ar: cannot open %s\n", file);
scanobj(&bar, ap, bp->size);
arcopy(&bar, ap, bp);
continue;
}
d = dirfstat(Bfildes(bfile));
if (d == nil)
fprint(2, "ar: cannot stat %s: %r\n", file);
if (uflag && (d == nil || d->mtime <= bp->date)) {
scanobj(&bar, ap, bp->size);
arcopy(&bar, ap, bp);
Bterm(bfile);
free(d);
continue;
}
mesg('r', file);
skip(&bar, bp->size);
scanobj(bfile, ap, d->length);
free(d);
armove(bfile, ap, bp);
Bterm(bfile);
}
if(fd >= 0)
close(fd);
/* copy in remaining files named on command line */
for (i = 0; i < count; i++) {
file = files[i];
if(file == 0)
continue;
files[i] = 0;
bfile = Bopen(file, OREAD);
if (!bfile)
fprint(2, "ar: %s cannot open\n", file);
else {
mesg('a', file);
d = dirfstat(Bfildes(bfile));
if (d == nil)
fprint(2, "ar: can't stat %s: %r\n", file);
else {
scanobj(bfile, astart, d->length);
armove(bfile, astart, newmember());
free(d);
}
Bterm(bfile);
}
}
if(fd < 0 && !cflag)
install(arname, astart, 0, aend, 1); /* issue 'creating' msg */
else
install(arname, astart, 0, aend, 0);
}
示例11: main
void
main(int argc, char *argv[])
{
int i, fd, n, aflag, vflag;
char body[Bodysize+2], *raw, *ret;
Biobuf *bp;
sprint(patfile, "%s/patterns", UPASLIB);
aflag = -1;
vflag = 0;
ARGBEGIN {
case 'a':
aflag = 1;
break;
case 'v':
vflag = 1;
break;
case 'd':
debug++;
break;
case 'p':
strcpy(patfile,ARGF());
break;
} ARGEND
bp = Bopen(patfile, OREAD);
if(bp){
parsepats(bp);
Bterm(bp);
}
if(argc >= 1){
fd = open(*argv, OREAD);
if(fd < 0){
fprint(2, "can't open %s\n", *argv);
exits("open");
}
Binit(&bin, fd, OREAD);
} else
Binit(&bin, 0, OREAD);
*body = 0;
*header = 0;
ret = 0;
for(;;){
raw = canon(&bin, header+1, body+1, &n);
if(raw == 0)
break;
if(aflag == 0)
continue;
if(aflag < 0)
aflag = 0;
if(vflag){
if(header[1]) {
fprint(2, "\t**** Header ****\n\n");
write(2, header+1, strlen(header+1));
fprint(2, "\n");
}
fprint(2, "\t**** Body ****\n\n");
if(body[1])
write(2, body+1, strlen(body+1));
fprint(2, "\n");
}
for(i = 0; patterns[i].action; i++){
if(matchaction(&patterns[i], header+1))
ret = patterns[i].action;
if(i == HoldHeader)
continue;
if(matchaction(&patterns[i], body+1))
ret = patterns[i].action;
}
}
exits(ret);
}
示例12: main
void
main(int argc, char **argv)
{
int i;
ARGBEGIN {
# ifdef DEBUG
case 'd': debug++; break;
case 'y': yydebug = TRUE; break;
# endif
case 't': case 'T':
Binit(&fout, 1, OWRITE);
errorf= 2;
foutopen = 1;
break;
case 'v': case 'V':
report = 1;
break;
case 'n': case 'N':
report = 0;
break;
case '9':
nine = 1;
break;
default:
warning("Unknown option %c", ARGC());
} ARGEND
sargc = argc;
sargv = argv;
if (argc > 0){
yyfile = argv[fptr++];
fin = Bopen(yyfile, OREAD);
if(fin == 0)
error ("%s - can't open file: %r", yyfile);
sargc--;
sargv++;
}
else {
yyfile = "/fd/0";
fin = myalloc(sizeof(Biobuf), 1);
if(fin == 0)
exits("core");
Binit(fin, 0, OREAD);
}
if(Bgetc(fin) == Beof) /* no input */
exits(0);
Bseek(fin, 0, 0);
gch();
/* may be gotten: def, subs, sname, stchar, ccl, dchar */
get1core();
/* may be gotten: name, left, right, nullstr, parent, ptr */
strcpy((char*)sp, "INITIAL");
sname[0] = sp;
sp += strlen("INITIAL") + 1;
sname[1] = 0;
if(yyparse()) exits("error"); /* error return code */
/* may be disposed of: def, subs, dchar */
free1core();
/* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */
get2core();
ptail();
mkmatch();
# ifdef DEBUG
if(debug) pccl();
# endif
sect = ENDSECTION;
if(tptr>0)cfoll(tptr-1);
# ifdef DEBUG
if(debug)pfoll();
# endif
cgoto();
# ifdef DEBUG
if(debug){
print("Print %d states:\n",stnum+1);
for(i=0;i<=stnum;i++)stprt(i);
}
# endif
/* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, stchar, sname */
/* may be gotten: verify, advance, stoff */
free2core();
get3core();
layout();
/* may be disposed of: verify, advance, stoff, nexts, nchar,
gotof, atable, ccpackflg, sfall */
# ifdef DEBUG
free3core();
# endif
fother = Bopen(cname,OREAD);
if(fother == 0)
error("Lex driver missing, file %s: %r",cname);
while ( (i=Bgetc(fother)) != Beof)
Bputc(&fout, i);
Bterm(fother);
Bterm(&fout);
if(
# ifdef DEBUG
debug ||
# endif
report == 1)statistics();
//.........這裏部分代碼省略.........
示例13: tune_in
void
tune_in(int fd, long *x, struct convert *out)
{
Biobuf b;
Rune rbuf[N];
Rune *r, *er, tr;
int c, i;
USED(x);
r = rbuf;
er = rbuf+N-3;
Binit(&b, fd, OREAD);
while((c = Bgetrune(&b)) != Beof){
ninput += b.runesize;
if(r >= er){
OUT(out, rbuf, r-rbuf);
r = rbuf;
}
if(c>=0xe210/**/ && c <= 0xe38c/**/ && (i = c%16) < nelem(t2)){
if(c >= 0xe380/**/){
*r++ = 0x0b95/*க*/;
*r++ = 0x0bcd/*்*/;
*r++ = 0x0bb7/*ஷ*/;
}else
*r++ = findbytune(t3, nelem(t3), c-i+1);
if(i != 1)
*r++ = t2[i];
}else if((tr = findbytune(t1, nelem(t1), c)) != Runeerror)
*r++ = tr;
else switch(c){
case 0xe3d0/**/:
*r++ = 0x0ba3/*ண*/; *r++ = 0x0bbe/*ா*/;
break;
case 0xe3d1/**/:
*r++ = 0x0bb1/*ற*/; *r++ = 0x0bbe/*ா*/;
break;
case 0xe3d2/**/:
*r++ = 0x0ba9/*ன*/; *r++ = 0x0bbe/*ா*/;
break;
case 0xe3d4/**/:
*r++ = 0x0ba3/*ண*/; *r++ = 0x0bc8/*ை*/;
break;
case 0xe3d5/**/:
*r++ = 0x0bb2/*ல*/; *r++ = 0x0bc8/*ை*/;
break;
case 0xe3d6/**/:
*r++ = 0x0bb3/*ள*/; *r++ = 0x0bc8/*ை*/;
break;
case 0xe3d7/**/:
*r++ = 0x0ba9/*ன*/; *r++ = 0x0bc8/*ை*/;
break;
case 0xe38d/**/:
*r++ = 0x0bb6/*ஶ*/; *r++ = 0x0bcd/*்*/; *r++ = 0x0bb0/*ர*/; *r++ = 0x0bc0/*ீ*/;
break;
default:
if(c >= 0xe200 && c <= 0xe3ff){
if(squawk)
EPR "%s: rune 0x%x not in output cs\n", argv0, c);
nerrors++;
if(clean)
break;
c = BADMAP;
}
*r++ = c;
break;
}
}
if(r > rbuf)
OUT(out, rbuf, r-rbuf);
OUT(out, rbuf, 0);
}
示例14: createcd
/*
* It's not strictly conforming; instead it's enough to
* get us up and running; presumably the real CD writing
* will take care of being conforming.
*
* Things not conforming include:
* - no path table
* - root directories are of length zero
*/
Cdimg*
createcd(char *file, Cdinfo info)
{
int fd, xfd;
Cdimg *cd;
if(access(file, AEXIST) == 0){
werrstr("file already exists");
return nil;
}
if((fd = create(file, ORDWR, 0666)) < 0)
return nil;
cd = emalloc(sizeof *cd);
cd->file = atom(file);
Binit(&cd->brd, fd, OREAD);
if((xfd = open(file, ORDWR)) < 0)
sysfatal("can't open file again: %r");
Binit(&cd->bwr, xfd, OWRITE);
Crepeat(cd, 0, 16*Blocksize);
Cputisopvd(cd, info);
if(info.flags & CDbootable){
cd->bootimage = info.bootimage;
cd->flags |= CDbootable;
Cputbootvol(cd);
}
if(readisodesc(cd, &cd->iso) < 0)
assert(0);
if(info.flags & CDplan9)
cd->flags |= CDplan9;
else if(info.flags & CDrockridge)
cd->flags |= CDrockridge;
if(info.flags & CDjoliet) {
Cputjolietsvd(cd, info);
if(readjolietdesc(cd, &cd->joliet) < 0)
assert(0);
cd->flags |= CDjoliet;
}
Cputendvd(cd);
if(info.flags & CDdump){
cd->nulldump = Cputdumpblock(cd);
cd->flags |= CDdump;
}
if(cd->flags & CDbootable){
Cputbootcat(cd);
Cupdatebootvol(cd);
}
if(info.flags & CDconform)
cd->flags |= CDconform;
cd->flags |= CDnew;
cd->nextblock = Cwoffset(cd) / Blocksize;
assert(cd->nextblock != 0);
return cd;
}
示例15: main
void
main(int argc, char *argv[])
{
int c;
char *p, *name, *val;
Binit(&bso, 1, OWRITE);
listinit();
nerrors = 0;
outfile = "5.out";
HEADTYPE = -1;
INITTEXT = -1;
INITDAT = -1;
INITRND = -1;
INITENTRY = 0;
nuxiinit();
p = getenv("GOARM");
if(p != nil && strcmp(p, "5") == 0)
debug['F'] = 1;
ARGBEGIN {
default:
c = ARGC();
if(c == 'l')
usage();
if(c >= 0 && c < sizeof(debug))
debug[c]++;
break;
case 'o':
outfile = EARGF(usage());
break;
case 'E':
INITENTRY = EARGF(usage());
break;
case 'I':
debug['I'] = 1; // denote cmdline interpreter override
interpreter = EARGF(usage());
break;
case 'L':
Lflag(EARGF(usage()));
break;
case 'T':
INITTEXT = atolwhex(EARGF(usage()));
break;
case 'D':
INITDAT = atolwhex(EARGF(usage()));
break;
case 'R':
INITRND = atolwhex(EARGF(usage()));
break;
case 'r':
rpath = EARGF(usage());
break;
case 'H':
HEADTYPE = headtype(EARGF(usage()));
/* do something about setting INITTEXT */
break;
case 'V':
print("%cl version %s\n", thechar, getgoversion());
errorexit();
case 'X':
name = EARGF(usage());
val = EARGF(usage());
addstrdata(name, val);
break;
} ARGEND
USED(argc);
if(argc != 1)
usage();
libinit();
if(HEADTYPE == -1)
HEADTYPE = Hlinux;
switch(HEADTYPE) {
default:
diag("unknown -H option");
errorexit();
case Hnoheader: /* no header */
HEADR = 0L;
if(INITTEXT == -1)
INITTEXT = 0;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4;
break;
case Hrisc: /* aif for risc os */
HEADR = 128L;
if(INITTEXT == -1)
INITTEXT = 0x10005000 + HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4;
break;
case Hplan9x32: /* plan 9 */
//.........這裏部分代碼省略.........