|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T b
Length: 7188 (0x1c14) Types: TextFile Names: »bprintf.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Abermud/bprintf.c«
/* ** This module and key.c together handle al the I/O of the system */ #include "kernel.h" #ifdef RCSID static char RCS[] = "$Header: bprintf.c,v 1.1 89/03/13 09:35:42 rsalz Exp $"; #endif /* RCSID */ #define SYSBUFSIZE 4096 makebfr() { if ((sysbuf = NEW(char, SYSBUFSIZE)) == NULL) crapup("Out Of Memory"); sysbuf[0] = 0; } /* VARARGS1 */ bprintf(format, arg1, arg2, arg3, arg4) char *format, *arg1, *arg2, *arg3, *arg4; { char x[1024]; sprintf(x, format, arg1, arg2, arg3, arg4); if (strlen(x) > sizeof x - 1) { mudlog("Bprintf Short Buffer overflow"); crapup("Internal Error in BPRINTF"); } /* Now we have a string of chars expanded */ quprnt(x); } dcprnt(str, file) char *str; FILE *file; { register int ct; for (ct = 0; str[ct]; ) { if (str[ct] != '\001') { kiputc(str[ct++], file); continue; } ct++; switch (str[ct++]) { case 'f': ct = pfile(str, ct, file); continue; case 'd': ct = pndeaf(str, ct, file); continue; case 's': ct = pcansee(str, ct, file); continue; case 'p': ct = prname(str, ct, file); continue; case 'c': ct = pndark(str, ct, file); continue; case 'P': ct = ppndeaf(str, ct, file); continue; case 'D': ct = ppnblind(str, ct, file); continue; case 'l': ct = pnotkb(str, ct, file); continue; default: str[0] = '\0'; loseme(); crapup("Internal control sequence error\n"); } } pr_qcr = 0; } int pfile(str, ct, file) char *str; int ct; FILE *file; { FILE *a; char x[128]; ct = tocontinue(str, ct, x, 128); if (debug_mode) fprintf(file, "[FILE %s]\n", str); kiputs("", file); if ((a = fopen(x, "r")) == NULL) fprintf(stderr, "[Cannot find file ->%s]\n", x); else { while (fgets(x, sizeof x, a)) fprintf(file, "%s", x); fclose(a); } return ct; } int pndeaf(str, ct, file) char *str; FILE *file; { char x[256]; ct = tocontinue(str, ct, x, 256); if (!ail_deaf) kiputs(x, file); return ct; } pcansee(str, ct, file) char *str; FILE *file; { char x[25]; char z[257]; int a; ct = tocontinue(str, ct, x, 23); a = fpbns(x); if (!seeplayer(a)) { ct = tocontinue(str, ct, z, 256); return ct; } ct = tocontinue(str, ct, z, 256); kiputs(z, file); return ct; } prname(str, ct, file) char *str; FILE *file; { char x[24]; ct = tocontinue(str, ct, x, 24); kiputs(seeplayer(fpbns(x)) ? x : "Someone", file); return ct; } int pndark(str, ct, file) char *str; FILE *file; { char x[257]; ct = tocontinue(str, ct, x, sizeof x - 1); if ((!isdark()) && (ail_blind == 0)) kiputs(x, file); return ct; } int tocontinue(str, ct, x, mx) char *str; int ct; char *x; int mx; { int s; for (s = 0; str[ct] != '\001'; s++) x[s] = str[ct++]; x[s] = 0; if (s >= mx) { mudlog("IO_TOcontinue overrun"); strcpy(str, ""); crapup("Buffer OverRun in IO_TOcontinue"); } return ct + 1; } int seeplayer(x) int x; { if (x == -1 || x == mynum) return 1; if (pvis(x > 0) && plev(mynum) < pvis(x)) return 0; if (ail_blind) return 0; if (ploc(mynum) == ploc(x) && isdark()) return 0; setname(x); return 1; } int ppndeaf(str, ct, file) char *str; int ct; FILE *file; { char x[24]; ct = tocontinue(str, ct, x, 24); if (!ail_deaf) kiputs(seeplayer(fpbns(x)) ? x : "Someone", file); return ct; } int ppnblind(str, ct, file) char *str; FILE *file; { char x[24]; ct = tocontinue(str, ct, x, 24); if (!ail_blind) kiputs(seeplayer(fpbns(x)) ? x : "Someone", file); return ct; } logcom() { if (userid == GUESTID) { bprintf("\nNot allowed from this ID\n"); return; } if (log_fl) { fprintf(log_fl, "\nEnd of log....\n\n"); fclose(log_fl); log_fl = NULL; bprintf("End of log\n"); return; } bprintf("Commencing Logging Of Session\n"); setreuid(-1, userid); if ((log_fl = fopen("mud_log", "a")) == NULL) log_fl = fopen("mud_log", "w"); setreuid(-1, sys_uid); if (log_fl == NULL) { bprintf("Cannot open log file mud_log\n"); return; } bprintf("The log will be written to the file 'mud_log'\n"); } pbfr() { FILE *fln; block_alarm(); closeworld(); pr_due = 0; if (log_fl) { iskb = 0; dcprnt(sysbuf, log_fl); } if (snoopd != -1 && (fln = opensnoop(pname(snoopd), "a")) != NULL) { iskb = 0; dcprnt(sysbuf, fln); closelock(fln); } iskb = 1; dcprnt(sysbuf, stdout); sysbuf[0] = 0; /* clear buffer */ if (snoopt != -1) viewsnoop(); unblock_alarm(); } quprnt(x) char *x; { if (strlen(x) + strlen(sysbuf) > SYSBUFSIZE - 1) { strcpy(sysbuf, ""); loseme(); mudlog("Buffer overflow on user %s", pname(mynum)); crapup("PANIC - Buffer overflow"); } strcat(sysbuf, x); } int pnotkb(str, ct, file) char *str; FILE *file; { char x[128]; ct = tocontinue(str, ct, x, 127); if (!iskb) kiputs(x, file); return ct; } FILE * opensnoop(user, per) char *per; char *user; { char z[256]; sprintf(z, "%s%s", SNOOPFILE, user); return openlock(z, per); } snoopcom() { FILE *fx; int x; if (plev(mynum) < 10) { bprintf("Ho hum, the weather is nice isn't it\n"); return; } if (snoopt != -1) { bprintf("Stopped snooping on %s\n", sntn); snoopt = -1; sendsys(sntn, pname(mynum), -400, 0, ""); } if (pl1 == -1 && ob1 == -1) return; if ((x = pl1) == -1) { bprintf("Who is that ?\n"); return; } if ((plev(mynum) < 10000 && plev(x) >= 10) || ptstflg(x, 6)) { bprintf("Your magical vision is obscured\n"); snoopt = -1; return; } strcpy(sntn, pname(x)); snoopt = x; bprintf("Started to snoop on %s\n", pname(x)); sendsys(sntn, pname(mynum), -401, 0, ""); fx = opensnoop(pname(mynum), "w"); fprintf(fx, " "); closelock(fx); } viewsnoop() { int x; char z[128]; FILE *fx; if (snoopt == -1 || (fx = opensnoop(pname(mynum), "r+")) == NULL) return; while (!feof(fx) && fgets(z, sizeof z, fx)) if (z[0]) { printf("|%s", z); pr_due = 1; } ftruncate(fileno(fx), 0); closelock(fx); x = snoopt; snoopt = -1; /* pbfr(); */ snoopt = x; } chksnp() { if (snoopt != -1) sendsys(sntn, pname(mynum), -400, 0, ""); } /* Assign Him her etc according to who it is */ setname(x) int x; { char *p; p = pname(x); if (x > 15 && x != fpbns("riatha") && x != fpbns("shazareth") && EQ(p, "owin") && EQ(p, "glowin") && EQ(p, "dio") && EQ(p, "bomber") && EQ(p, "smythe") && EQ(p, "seamas")) { strcpy(wd_it, p); return; } if (psex(x)) strcpy(wd_her, p); else strcpy(wd_him, p); strcpy(wd_them, p); } kiputc(c, file) char c; FILE *file; { if (pr_qcr) putchar('\n'); pr_qcr = 0; fprintf(file, "%c", c); pr_due = 1; } kiputs(s, file) char *s; FILE *file; { if (pr_qcr) putchar('\n'); pr_qcr = 0; fprintf(file, "%s", s); pr_due = 1; }