int main(int argc, char **argv) { print("hello from main\n"); ffork(RFMEM|RFPROC, sayhi, nil); print("rendez got %lu from subproc\n", rendezvous(0x1234, 0)); exits(0); }
int main(int argc, char **argv) { char c, *cp; int j, k, fdtmp; unsigned int len; /* Find the program name */ j = 0; while (argv[0][j] != '\0') j++; len = (unsigned int) j; while (j--) if (argv[0][j] == '/') break; if (argv[0][j] == '/') j++; cp = argv[0] + j; len -= j; /* Sort out the flags */ for (k = 1; k < argc; k++) { if (argv[k][0] == '-') { c = argv[k][1]; switch (c) { case '0': /* pass numbers */ case '1': case '2': case '3': case '4': pnum = c - '0'; break; case 'd': /* used by news */ break; default: (void) write(1, "Usage: ", 7); (void) write(1, cp, len); (void) write(1, " [-#] [in] [out]\n", 17); exit(0); break; } /* Once it's checked, lose it anyway */ for (j = k; j < argc; j++) argv[j] = argv[j + 1]; argc--; k--; } } /* Default i/o settings */ fdin = 0; fdout = 1; fderr = 2; /* Try to open specific files and connect them to stdin/stdout */ if (argc > 1) { if ((fdtmp = open(argv[1], 0)) == -1) die("input open failed"); (void) close(0); if ((fdin = dup(fdtmp)) == -1) die("input dup failed\n"); (void) close(fdtmp); } if (argc > 2) { (void) unlink(argv[2]); if ((fdtmp = creat(argv[2], 0666)) == -1) die("output creat failed"); (void) close(1); if ((fdout = dup(fdtmp)) == -1) die("output dup failed\n"); (void) close(fdtmp); } /* Sort out type of compression */ if (pnum == -1 || pnum == 4) {/* if this is pass 4 */ /* Check header of compressed file */ if (mygetc() != 0x1F || mygetc() != 0x9D) /* check magic number */ die("not a compressed file\n"); iindex = mygetc(); /* get compression style */ } else getpipe(); /* get compression style */ maxbits = iindex & 0x1F; clearflg = ((iindex & 0x80) != 0) ? TRUE : FALSE; if (maxbits < 9 || maxbits > 16) /* check for valid maxbits */ die("can't decompress\n"); if (pnum != -1 && pnum != 0) putpipe(iindex, 0); /* pass style to next copy */ /* Fork off an ancestor if necessary - ffork() increments pnum */ if (pnum == -1) { pnum = 0; if (pnum == 0) ffork(); if (pnum == 1) ffork(); if (pnum == 2) ffork(); if (pnum == 3) ffork(); } /* Preliminary inits. Note: end/maxend/curend are highest, not * highest + 1 */ base = DICTSZ * pnum + 256; locend = base + DICTSZ - 1; maxend = (1 << maxbits) - 1; if (maxend > locend) maxend = locend; while (TRUE) { curend = 255 + (clearflg ? 1 : 0); /* init dictionary */ dcharp = DICTSZ; /* flag for none needed */ curbits = 9; /* init curbits (for copy 0) */ while (TRUE) { /* for each index in input */ if (pnum == 4) {/* get index using getbits() */ if (curbits < maxbits && (1 << curbits) <= curend) { /* Curbits needs to be increased */ /* Due to uglyness in compress, these * indices in the compressed file are * wasted */ while (inmod) getbits(); curbits++; } getbits(); } else getpipe(); /* get next index */ if (iindex == 256 && clearflg) { if (pnum > 0) putpipe(iindex, 0); /* Due to uglyness in compress, these indices * in the compressed file are wasted */ while (inmod) getbits(); break; } tindex = iindex; /* Convert the index part, ignoring spawned chars */ while (tindex >= base) tindex = dindex[tindex - base]; /* Pass on the index */ putpipe(tindex, 0); /* Save the char of the last added entry, if any */ if (dcharp < DICTSZ) dchar[dcharp++] = tindex; if (curend < maxend && ++curend > (base - 1)) dindex[dcharp = (curend - base)] = iindex; /* Do spawned chars. They are naturally produced in * the wrong order. To get them in the right order * without using memory, a series of passes, * progressively less deep, are used */ tbase = base; while ((tindex = iindex) >= tbase) {/* for each char to spawn*/ while ((tindex2 = dindex[tindex - base]) >= tbase) tindex = tindex2; /* scan to desired char */ putpipe(dchar[tindex-base], 1); /* put it to the pipe*/ tbase = tindex + 1; if (tbase == 0) break; /* it's a wrap */ } } } }