Esempio n. 1
0
/******************************************************************************
 * Callback to update parameters on the fly
 ******************************************************************************/
static int paramCallback( vlc_object_t *p_this, char const *psz_var,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    filter_t *p_filter = (filter_t *)p_this;
    filter_sys_t *p_sys = (filter_sys_t *) p_data;

    if( !strncmp( psz_var, "delay-time", 10 ) )
    {
        /* if invalid value pretend everything is OK without updating value */
        if( newval.f_float < 0 )
            return VLC_SUCCESS;
        p_sys->f_delayTime = newval.f_float;
        if( !reallocate_buffer( p_filter, p_sys ) )
        {
            p_sys->f_delayTime = oldval.f_float;
            p_sys->i_bufferLength = p_sys->i_channels * ( (int)
                            ( ( p_sys->f_delayTime + p_sys->f_sweepDepth ) * 
                              p_filter->fmt_in.audio.i_rate/1000 ) + 1 );
        }
    }
    else if( !strncmp( psz_var, "sweep-depth", 11 ) )
    {
        if( newval.f_float < 0 || newval.f_float > p_sys->f_delayTime)
            return VLC_SUCCESS;
        p_sys->f_sweepDepth = newval.f_float;
        if( !reallocate_buffer( p_filter, p_sys ) )
        {
            p_sys->f_sweepDepth = oldval.f_float;
            p_sys->i_bufferLength = p_sys->i_channels * ( (int)
                            ( ( p_sys->f_delayTime + p_sys->f_sweepDepth ) * 
                              p_filter->fmt_in.audio.i_rate/1000 ) + 1 );
        }
    }
    else if( !strncmp( psz_var, "sweep-rate", 10 ) )
    {
        if( newval.f_float > p_sys->f_sweepDepth )
            return VLC_SUCCESS;
        p_sys->f_sweepRate = newval.f_float;
        /* Calculate new f_sinMultiplier */
        if( p_sys->f_sweepDepth < small_value() ||
                p_filter->fmt_in.audio.i_rate < small_value() ) {
            p_sys->f_sinMultiplier = 0.0;
        }
        else {
            p_sys->f_sinMultiplier = 11 * p_sys->f_sweepRate /
                ( 7 * p_sys->f_sweepDepth * p_filter->fmt_in.audio.i_rate ) ;
        }
    }
    else if( !strncmp( psz_var, "feedback-gain", 13 ) )
        p_sys->f_feedbackGain = newval.f_float;
    else if( !strncmp( psz_var, "wet-mix", 7 ) )
        p_sys->f_wetLevel = newval.f_float;
    else if( !strncmp( psz_var, "dry-mix", 7 ) )
        p_sys->f_dryLevel = newval.f_float;

    return VLC_SUCCESS;
}
Esempio n. 2
0
    int
main(int ac, char **av)
{
    int i, j;
    int aflag = 0;
    int uflag = 0;
    int fpos;    /* current position in time format buffer */
    int chrcnt;    /* # of chars formatted by current sprintf */
    int bl, wtmp;
    char *ct;
    char *ut_host;
    char *ut_user;
    struct utmpx *bp;
    time_t otime;
    struct stat stb;
    int print = 0;
    char *crmsg = (char *)0;
    long outrec = 0;
    long maxrec = 0x7fffffffL;
    char *wtmpfile = "/var/adm/wtmpx";
    size_t hostf_len;

    (void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)        /* Should be defined by cc -D */
#define    TEXT_DOMAIN "SYS_TEST"        /* Use this only if it weren't. */
#endif
    (void) textdomain(TEXT_DOMAIN);

    (void) time(&buf[0].ut_xtime);
    ac--, av++;
    argc = ac;
    argv = av;
    names = malloc(argc * sizeof (char *));
    if (names == NULL) {
        perror("first");
        exit(2);
    }
    names_num = 0;
    for (i = 0; i < argc; i++) {
        if (argv[i][0] == '-') {

            /* -[0-9]*   sets max # records to print */
            if (isdigit(argv[i][1])) {
                maxrec = atoi(argv[i]+1);
                continue;
            }

            for (j = 1; argv[i][j] != '\0'; ++j) {
                switch (argv[i][j]) {

                    /* -f name sets filename of wtmp file */
                    case 'f':
                        if (argv[i][j+1] != '\0') {
                            wtmpfile = &argv[i][j+1];
                        } else if (i+1 < argc) {
                            wtmpfile = argv[++i];
                        } else {
                            (void) fprintf(stderr,
                                    gettext("first: argument to "
                                        "-f is missing\n"));
                            (void) fprintf(stderr,
                                    gettext(USAGE));
                            exit(1);
                        }
                        goto next_word;

                        /* -n number sets max # records to print */
                    case 'n': {
                              char *arg;

                              if (argv[i][j+1] != '\0') {
                                  arg = &argv[i][j+1];
                              } else if (i+1 < argc) {
                                  arg = argv[++i];
                              } else {
                                  (void) fprintf(stderr,
                                          gettext("first: argument to "
                                              "-n is missing\n"));
                                  (void) fprintf(stderr,
                                          gettext(USAGE));
                                  exit(1);
                              }

                              if (!isdigit(*arg)) {
                                  (void) fprintf(stderr,
                                          gettext("first: argument to "
                                              "-n is not a number\n"));
                                  (void) fprintf(stderr,
                                          gettext(USAGE));
                                  exit(1);
                              }
                              maxrec = atoi(arg);
                              goto next_word;
                          }

                          /* -a displays hostname last on the line */
                    case 'a':
                          aflag++;
                          break;

                          /* -u displays times in UNIX epoch format */
                    case 'u':
                          uflag++;
                          break;

                    default:
                          (void) fprintf(stderr, gettext(USAGE));
                          exit(1);
                }
            }

next_word:
            continue;
        }

        if (strlen(argv[i]) > 2 || strcmp(argv[i], "~") == 0 ||
                getpwnam(argv[i]) != NULL) {
            /* Not a tty number. */
            names[names_num] = argv[i];
            ++names_num;
        } else {
            /* tty number.  Prepend "tty". */
            names[names_num] = strspl("tty", argv[i]);
            ++names_num;
        }
    }

    wtmp = open(wtmpfile, O_RDONLY | O_LARGEFILE);
    if (wtmp < 0) {
        perror(wtmpfile);
        exit(1);
    }
    (void) fstat(wtmp, &stb);
    bl = (stb.st_size + sizeof (buf)-1) / sizeof (buf);
    if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
        (void) signal(SIGINT, onintr);
        (void) signal(SIGQUIT, onintr);
    }
    lines = CHUNK_SIZE;
    ttnames = calloc(lines, sizeof (char *));
    logouts = calloc(lines, sizeof (time_t));
    if (ttnames == NULL || logouts == NULL) {
        (void) fprintf(stderr, gettext("Out of memory \n "));
        exit(2);
    }
    for (bl--; bl >= 0; bl--) {
        (void) lseek(wtmp, (off_t)(bl * sizeof (buf)), 0);
        bp = &buf[read(wtmp, buf, sizeof (buf)) / sizeof (buf[0]) - 1];
        for (; bp >= buf; bp--) {
            if (want(bp, &ut_host, &ut_user)) {
                for (i = 0; i <= lines; i++) {
                    if (i == lines)
                        reallocate_buffer();
                    if (ttnames[i] == NULL) {
                        memory_alloc(i);
                        /*
                         * LMAX+HMAX+NMAX+3 bytes have been
                         * allocated for ttnames[i].
                         * If bp->ut_line is longer than LMAX,
                         * ut_host is longer than HMAX,
                         * and ut_user is longer than NMAX,
                         * truncate it to fit ttnames[i].
                         */
                        (void) strlcpy(ttnames[i], bp->ut_line,
                                LMAX+1);
                        (void) strlcpy(ttnames[i]+LMAX+1,
                                ut_host, HMAX+1);
                        (void) strlcpy(ttnames[i]+LMAX+HMAX+2,
                                ut_user, NMAX+1);
                        record_time(&otime, &print,
                                i, bp);
                        break;
                    } else if (linehostnameq(ttnames[i],
                                bp->ut_line, ut_host, ut_user)) {
                        record_time(&otime,
                                &print, i, bp);
                        break;
                    }
                }
            }
            if (print) {
                if (strncmp(bp->ut_line, "ftp", 3) == 0)
                    bp->ut_line[3] = '\0';
                if (strncmp(bp->ut_line, "uucp", 4) == 0)
                    bp->ut_line[4] = '\0';

                ct = ctime(&bp->ut_xtime);
                (void) printf(gettext("%-*.*s  %-*.*s "),
                        NMAX, NMAX, bp->ut_name,
                        LMAX, LMAX, bp->ut_line);
                hostf_len = strlen(bp->ut_host);
                (void) snprintf(hostf, sizeof (hostf),
                        "%-*.*s", hostf_len, hostf_len,
                        bp->ut_host);
                if(uflag) {
                    fpos = snprintf(timef, sizeof (timef),
                            "%10lu ", bp->ut_xtime);
                } else {
                    fpos = snprintf(timef, sizeof (timef),
                            "%10.10s %13.13s ", /* MJC 8 extra chars */
                            ct, 11 + ct);
                }
                if (!lineq(bp->ut_line, "system boot") &&
                        !lineq(bp->ut_line, "system down")) {
                    if (otime == 0 &&
                            bp->ut_type == USER_PROCESS) {

                        if (fpos < sizeof (timef)) {
                            /* timef still has room */
                            (void) snprintf(timef + fpos, sizeof (timef) - fpos,
                                    gettext("  still logged in"));
                        }

                    } else {
                        time_t delta;
                        if (otime < 0) {
                            otime = -otime;
                            /*
                             * TRANSLATION_NOTE
                             * See other notes on "down"
                             * and "- %5.5s".
                             * "-" means "until".  This
                             * is displayed after the
                             * starting time as in:
                             *     16:20 - down
                             * You probably don't want to
                             * translate this.  Should you
                             * decide to translate this,
                             * translate "- %5.5s" too.
                             */

                            if (fpos < sizeof (timef)) {
                                /* timef still has room */
                                if(uflag) {
                                    chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
                                            gettext("- %-10s"), crmsg);
                                } else {
                                    chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
                                            gettext("- %-24s"), crmsg);
                                }
                                fpos += chrcnt;
                            }

                        } else {

                            if (fpos < sizeof (timef)) {
                                /* timef still has room */
                                if(uflag) {
                                    chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
                                            gettext("- %10lu"), otime);
                                } else {
                                    chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos,
                                            gettext("- %10.10s %13.13s"), ctime(&otime), ctime(&otime) + 11); /* MJC 19 extra chars */
                                }
                                fpos += chrcnt;
                            }

                        }
                        delta = otime - bp->ut_xtime;
                        if (delta < SECDAY) {

                            if (fpos < sizeof (timef)) {
                                /* timef still has room */
                                (void) snprintf(timef + fpos, sizeof (timef) - fpos,
                                        gettext("  (%5.5s)"), asctime(gmtime(&delta)) + 11);
                            }

                        } else {

                            if (fpos < sizeof (timef)) {
                                /* timef still has room */
                                (void) snprintf(timef + fpos, sizeof (timef) - fpos,
                                        gettext(" (%ld+%5.5s)"), delta / SECDAY,
                                        asctime(gmtime(&delta)) + 11);
                            }

                        }
                    }
                }
                if (aflag)
                    (void) printf("%-62.62s %-.*s\n", /* MJC */
                            timef, strlen(hostf), hostf);
                else
                    (void) printf("%-16.16s %-.62s\n", /* MJC */
                            hostf, timef);
                (void) fflush(stdout);
                if (++outrec >= maxrec)
                    exit(0);
            }
            /*
             * when the system is down or crashed.
             */
            if (bp->ut_type == BOOT_TIME) {
                for (i = 0; i < lines; i++)
                    logouts[i] = -bp->ut_xtime;
                bootxtime = -bp->ut_xtime;
                /*
                 * TRANSLATION_NOTE
                 * Translation of this "down " will replace
                 * the %s in "- %s".  "down" is used instead
                 * of the real time session was ended, probably
                 * because the session ended by a sudden crash.
                 */
                crmsg = gettext("down ");
            }
            print = 0;    /* reset the print flag */
        }
    }
    if(uflag) {
        (void) printf(gettext("\nwtmp begins %lu \n"), buf[0].ut_xtime);
    } else {
        ct = ctime(&buf[0].ut_xtime);
        (void) printf(gettext("\nwtmp begins %24.24s \n"), ct);
    }

    /* free() called to prevent lint warning about names */
    free(names);

    return (0);
}