static void termcrt(int status, int fast) { //struct process *proc = gettib()->proc; struct crtbase *crtbase = NULL;//(struct crtbase *) proc->crtbase; // Check for vfork() exit if (crtbase->fork_exit) crtbase->fork_exit(status); // Call termination handlers when last instance exits //if (atomic_decrement(&__instcount) == 0) { // Execute atexit handlers if (!fast) run_atexit_handlers(); #if !defined(__GNUC__) && !defined(__TINYC__) // Execute C pre-terminators initterm(__xp_a, __xp_z); // Execute C terminators initterm(__xt_a, __xt_z); #endif } // Clean runtime library term_crtbase(crtbase); }
static int initcrt() { int rc; //if (atomic_increment(&__instcount) == 1) { #if !defined(__GNUC__) && !defined(__TINYC__) // Execute C initializers rc = inittermi(__xi_a, __xi_z); if (rc != 0) return rc; // Execute C++ initializers initterm(__xc_a, __xc_z); #endif } return 0; }
int main(int argc, char **argv) { FILE * volatile f; char *s; volatile int left; volatile off_t initline; volatile int prnames = 0; volatile int initopt = 0; volatile int srchopt = 0; int clearit = 0; int ch; char initbuf[80]; if (pledge("stdio rpath tty", NULL) == -1) { perror("pledge"); exit(1); } setlocale(LC_ALL, ""); /* all signals just use a stub handler and interrupt syscalls */ sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = onsignal; nfiles = argc; fnames = argv; initterm(); nscroll = Lpp/2 - 1; if (nscroll <= 0) nscroll = 1; if ((s = getenv("MORE")) != NULL && *s != '\0') argscan(s); while (--nfiles > 0) { if ((ch = (*++fnames)[0]) == '-') argscan(*fnames + 1); else if (ch == '+') { s = *fnames; if (*++s == '/') { srchopt++; (void)strlcpy(initbuf, ++s, sizeof(initbuf)); } else { initopt++; for (initline = 0; *s != '\0'; s++) { if (isdigit((unsigned char)*s)) initline = initline * 10 + *s - '0'; } --initline; } } else break; } /* * Allow clreol only if Home and eraseln and EodClr strings are * defined, and in that case, make sure we are in noscroll mode. */ if (clreol) { if (Home == NULL || *Home == '\0' || eraseln == NULL || *eraseln == '\0' || EodClr == NULL || *EodClr == '\0') clreol = 0; else noscroll = 1; } if (dlines == 0) dlines = Lpp - 1; left = dlines; if (nfiles > 1) prnames++; if (!no_intty && nfiles == 0) usage(); else f = stdin; if (!no_tty) { struct sigaction osa; (void)sigaction(SIGQUIT, &sa, NULL); (void)sigaction(SIGINT, &sa, NULL); (void)sigaction(SIGWINCH, &sa, NULL); if (sigaction(SIGTSTP, &osa, NULL) == 0 && osa.sa_handler == SIG_DFL) { (void)sigaction(SIGTSTP, &sa, NULL); (void)sigaction(SIGTTIN, &sa, NULL); (void)sigaction(SIGTTOU, &sa, NULL); catch_susp++; } set_tty(); } if (no_intty) { if (no_tty) copy_file(stdin); else { if ((ch = Getc(f)) == '\f') doclear(); else { Ungetc(ch, f); if (noscroll && ch != EOF) { if (clreol) home(); else doclear(); } } if (srchopt) { if (search(initbuf, stdin, 1) == 0 && noscroll) left--; } else if (initopt) skiplns(initline, stdin); screen(stdin, left); } no_intty = 0; dup2(STDERR_FILENO, STDIN_FILENO); /* stderr is a tty */ prnames++; firstf = 0; } while (fnum < nfiles) { if ((f = checkf(fnames[fnum], &clearit)) != NULL) { context.line = context.chrctr = 0; Currline = 0; restart: if (firstf) { firstf = 0; if (srchopt) { if (search(initbuf, f, 1) < 0) goto restart; if (noscroll) left--; } else if (initopt) skiplns(initline, f); } else if (fnum < nfiles && !no_tty) left = command(fnames[fnum], f); if (left != 0) { if ((noscroll || clearit) && (file_size != LONG_MAX)) { if (clreol) home(); else doclear(); } if (prnames) { if (bad_so) erasep(0); if (clreol) cleareol(); fputs("::::::::::::::", stdout); if (promptlen > 14) erasep(14); putchar('\n'); if (clreol) cleareol(); printf("%s\n", fnames[fnum]); if (clreol) cleareol(); fputs("::::::::::::::\n", stdout); if (left > Lpp - 4) left = Lpp - 4; } if (no_tty) copy_file(f); else { within++; screen(f, left); within = 0; } } fflush(stdout); fclose(f); screen_start.line = screen_start.chrctr = 0L; context.line = context.chrctr = 0L; } fnum++; firstf = 0; } reset_tty(); exit(0); }
int main(int argc, char **argv) { int i, std_argc; char *term = getenv("TERM"); char *cap, std_input = FALSE; int setuperr; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); progname = argv[0]; while ((i = getopt(argc, argv, "ST:")) != EOF) { switch (i) { case 'T': fildes = -1; (void) putenv("LINES="); (void) putenv("COLUMNS="); term = optarg; break; case 'S': std_input = TRUE; break; case '?': /* FALLTHROUGH */ usage: /* FALLTHROUGH */ default: (void) fprintf(stderr, gettext( "usage:\t%s [-T [term]] capname [parm argument...]\n"), progname); (void) fprintf(stderr, gettext("OR:\t%s -S <<\n"), progname); exit(2); } } if (!term || !*term) { (void) fprintf(stderr, gettext("%s: No value for $TERM and no -T specified\n"), progname); exit(2); } (void) setupterm(term, fildes, &setuperr); switch (setuperr) { case -2: (void) fprintf(stderr, gettext("%s: unreadable terminal descriptor \"%s\"\n"), progname, term); exit(3); break; case -1: (void) fprintf(stderr, gettext("%s: no terminfo database\n"), progname); exit(3); break; case 0: (void) fprintf(stderr, gettext("%s: unknown terminal \"%s\"\n"), progname, term); exit(3); } reset_shell_mode(); /* command line arguments */ if (!std_input) { if (argc == optind) goto usage; cap = argv[optind++]; if (strcmp(cap, "init") == 0) initterm(); else if (strcmp(cap, "reset") == 0) reset_term(); else if (strcmp(cap, "longname") == 0) (void) printf("%s\n", longname()); else exit(outputcap(cap, argc, argv)); return (0); } else { /* standard input argumets */ char buff[128]; char **v; /* allocate storage for the 'faked' argv[] array */ v = (char **)malloc(10 * sizeof (char *)); for (i = 0; i < 10; i++) v[i] = (char *)malloc(32 * sizeof (char)); while (gets(buff) != NULL) { /* read standard input line; skip over empty lines */ if ((std_argc = sscanf(buff, "%s %s %s %s %s %s %s %s %s %s", v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9])) < 1) { continue; } cap = v[0]; optind = 1; if (strcmp(cap, "init") == 0) { initterm(); } else if (strcmp(cap, "reset") == 0) { reset_term(); } else if (strcmp(cap, "longname") == 0) { (void) printf("%s\n", longname()); } else { (void) outputcap(cap, std_argc, v); } (void) fflush(stdout); } return (0); } }
int main(int argc, char **argv) { FILE *f; char *s; char *p; int ch; int left; int prnames = 0; int initopt = 0; int srchopt = 0; int clearit = 0; int initline = 0; char initbuf[INIT_BUF]; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); nfiles = argc; fnames = argv; setlocale(LC_ALL, ""); initterm (); /* Auto set no scroll on when binary is called page */ if (!(strcmp(program_invocation_short_name, "page"))) noscroll++; prepare_line_buffer(); nscroll = Lpp/2 - 1; if (nscroll <= 0) nscroll = 1; if ((s = getenv("MORE")) != NULL) argscan(s); while (--nfiles > 0) { if ((ch = (*++fnames)[0]) == '-') { argscan(*fnames+1); } else if (ch == '+') { s = *fnames; if (*++s == '/') { srchopt++; for (++s, p = initbuf; p < initbuf + (INIT_BUF - 1) && *s != '\0';) *p++ = *s++; *p = '\0'; } else { initopt++; for (initline = 0; *s != '\0'; s++) if (isdigit (*s)) initline = initline*10 + *s -'0'; --initline; } } else break; } /* allow clreol only if Home and eraseln and EodClr strings are * defined, and in that case, make sure we are in noscroll mode */ if (clreol) { if((Home == NULL) || (*Home == '\0') || (eraseln == NULL) || (*eraseln == '\0') || (EodClr == NULL) || (*EodClr == '\0') ) clreol = 0; else noscroll = 1; } if (dlines == 0) dlines = Lpp - 1; /* was: Lpp - (noscroll ? 1 : 2) */ left = dlines; if (nfiles > 1) prnames++; if (!no_intty && nfiles == 0) usage(stderr); else f = stdin; if (!no_tty) { signal(SIGQUIT, onquit); signal(SIGINT, end_it); #ifdef SIGWINCH signal(SIGWINCH, chgwinsz); #endif /* SIGWINCH */ if (signal (SIGTSTP, SIG_IGN) == SIG_DFL) { signal(SIGTSTP, onsusp); catch_susp++; } stty (fileno(stderr), &otty); } if (no_intty) { if (no_tty) copy_file (stdin); else { if ((ch = Getc (f)) == '\f') doclear(); else { Ungetc (ch, f); if (noscroll && (ch != EOF)) { if (clreol) home (); else doclear (); } } if (srchopt) { search (initbuf, stdin, 1); if (noscroll) left--; } else if (initopt) skiplns (initline, stdin); screen (stdin, left); } no_intty = 0; prnames++; firstf = 0; } while (fnum < nfiles) { if ((f = checkf (fnames[fnum], &clearit)) != NULL) { context.line = context.chrctr = 0; Currline = 0; if (firstf) sigsetjmp (restore, 1); if (firstf) { firstf = 0; if (srchopt) { search (initbuf, f, 1); if (noscroll) left--; } else if (initopt) skiplns (initline, f); } else if (fnum < nfiles && !no_tty) { sigsetjmp (restore, 1); left = command (fnames[fnum], f); } if (left != 0) { if ((noscroll || clearit) && (file_size != LONG_MAX)) { if (clreol) home (); else doclear (); } if (prnames) { if (bad_so) erasep (0); if (clreol) cleareol (); putsout("::::::::::::::"); if (promptlen > 14) erasep (14); putchar('\n'); if(clreol) cleareol(); puts(fnames[fnum]); if(clreol) cleareol(); puts("::::::::::::::"); if (left > Lpp - 4) left = Lpp - 4; } if (no_tty) copy_file (f); else { within++; screen(f, left); within = 0; } } sigsetjmp (restore, 1); fflush(stdout); fclose(f); screen_start.line = screen_start.chrctr = 0L; context.line = context.chrctr = 0L; } fnum++; firstf = 0; } reset_tty (); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int datafd; /* FIXME: the facility should be configurable */ openlog("daydream", LOG_PID, LOG_LOCAL2); if (!(origdir = getenv("DAYDREAM"))) { syslog(LOG_ERR, "environment variable DAYDREAM not set"); fputs("Environment variable DAYDREAM is not set.\n", stderr); exit(1); } if (chdir(origdir) == -1) { syslog(LOG_ERR, "cannot chdir to home directory"); fputs("Cannot chdir to BBS home directory.\n", stderr); exit(1); } umask(007); datafd = open("data/daydream.dat", O_RDONLY); if (datafd == -1) { syslog(LOG_WARNING, "cannot open \"daydream.dat\": %s", strerror(errno)); fprintf(stderr, "cannot open \"daydream.dat\": %s\n", strerror(errno)); exit(1); } if (read(datafd, &maincfg, sizeof(struct DayDream_MainConfig)) != sizeof(struct DayDream_MainConfig)) { syslog(LOG_WARNING, "bad \"daydream.dat\": %s", strerror(errno)); fprintf(stderr, "bad \"daydream.dat\": %s\n", strerror(errno)); exit(1); } close(datafd); if (create_directory(DDTMP, maincfg.CFG_BBSUID, maincfg.CFG_BBSGID, 0770) == -1) { syslog(LOG_ERR, "cannot create temporary directory: %m"); fputs("Cannot create temporary directory.\n", stderr); exit(1); } initstringspace(); srand(time(NULL)); serhandle = 0; protocol = 0; onlinestat = 0; userinput = 1; lrp = lsp = oldlrp = oldlsp = 0; lrpdatname[0] = 0; ffilestagged = filestagged = bytestagged = fbytestagged = 0; *reason = 0; memset(&clog, 0, sizeof(struct callerslog)); if (!getcmdline(argc, argv)) return 0; read_conference_data(); readdatafile((void **) &nodes, "data/multinode.dat", 0); readdatafile((void **) &presets, "data/access.dat", 0); readdatafile((void **) &secs, "data/security.dat", 0); readdatafile((void **) &displays, "data/display.dat", 0); readdatafile((void **) &exts, "data/externalcommands.dat", 0); readdatafile((void **) &arcs, "data/archivers.dat", 255); readdatafile((void **) &protocols, "data/protocols.dat", 0); display = 0; /* Check if we know which TTY we're using.. */ olms = NewList(); if (ul_user != -1) { cmdlineupload(); return 0; } initterm(); /* Initialize carrier loss handler */ if (mkdir(currnode->MULTI_TEMPORARY, 0770) == -1 && errno != EEXIST) { syslog(LOG_ERR, "cannot create temporary directory %s (%d)", currnode->MULTI_TEMPORARY, errno); fprintf(stderr, "cannot create temporary directory %s (%d)\r\n", currnode->MULTI_TEMPORARY, errno); return 0; } signal(SIGHUP, carrieroff); if (!fnode) { signal(SIGTERM, carrieroff); signal(SIGINT, carrieroff); } if (fnode) { int ir = 0; while (waitforcall(ir++) != -1) { visitbbs(0); if (forcebps) break; } tcflush(serhandle, TCIOFLUSH); } else visitbbs(0); fini_keyboard(); return 0; }