示例#1
0
文件: filelist.c 项目: djrtl/ncmpc-dj
struct filelist *
filelist_new_recv(struct mpd_connection *connection)
{
	struct filelist *filelist = filelist_new();
	filelist_recv(filelist, connection);
	return filelist;
}
示例#2
0
FILELIST * filelist_push_front( FILELIST * list, OBJECT * path )
{
    FILEITEM * item;
    file_info_t * file;

    /* Lazy initialization
     */
    if ( filelist_empty( list ) )
    {
        list = filelist_new( path );
        return list;
    }


    item = (FILEITEM *)BJAM_MALLOC( sizeof( FILEITEM ) );
    memset( item, 0, sizeof( *item ) );
    item->value = (file_info_t *)BJAM_MALLOC( sizeof( file_info_t ) );

    file = item->value;
    memset( file, 0, sizeof( *file ) );

    file->name = path;
    file->files = L0;

    if ( list->head )
    {
        item->next = list->head;
    }
    else
    {
        list->tail = item;
    }
    list->head = item;
    list->size++;

    return list;
}
示例#3
0
/* Outputs a sorted list of files/directories matching the mask,
 * to idx.
 */
static void filedb_ls(FILE *fdb, int idx, char *mask, int showall)
{
    int ok = 0, cnt = 0, is = 0;
    char s1[81], *p = NULL;
    struct flag_record user = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
    filedb_entry *fdbe = NULL;
    filelist_t *flist = NULL;

    flist = filelist_new();
    filedb_readtop(fdb, NULL);
    fdbe = filedb_getfile(fdb, ftell(fdb), GET_FULL);
    while (fdbe) {
        ok = 1;
        if (fdbe->stat & FILE_UNUSED)
            ok = 0;
        if (ok && (fdbe->stat & FILE_DIR) && fdbe->flags_req) {
            /* Check permissions */
            struct flag_record req = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };

            break_down_flags(fdbe->flags_req, &req, NULL);
            get_user_flagrec(dcc[idx].user, &user, dcc[idx].u.file->chat->con_chan);
            if (!flagrec_ok(&req, &user)) {
                ok = 0;
            }
        }
        if (ok)
            is = 1;
        if (ok && !wild_match_file(mask, fdbe->filename))
            ok = 0;
        if (ok && (fdbe->stat & FILE_HIDDEN) && !(showall))
            ok = 0;
        if (ok) {
            /* Display it! */
            if (cnt == 0) {
                dprintf(idx, FILES_LSHEAD1);
                dprintf(idx, FILES_LSHEAD2);
            }
            filelist_add(flist, fdbe->filename);
            if (fdbe->stat & FILE_DIR) {
                char *s2 = NULL, *s3 = NULL;

                /* Too long? */
                if (strlen(fdbe->filename) > 45) {
                    /* Display the filename on its own line. */
                    s2 = nmalloc(strlen(fdbe->filename) + 3);
                    sprintf(s2, "%s/\n", fdbe->filename);
                    filelist_addout(flist, s2);
                    my_free(s2);
                } else {
                    s2 = nmalloc(strlen(fdbe->filename) + 2);
                    sprintf(s2, "%s/", fdbe->filename);
                }
                /* Note: You have to keep the sprintf and the nmalloc statements
                 *       in sync, i.e. always check that you allocate enough
                 *       memory.
                 */
                if ((fdbe->flags_req) && (user.global &(USER_MASTER | USER_JANITOR))) {
                    s3 = nmalloc(42 + strlen(s2 ? s2 : "") + 6 +
                                 strlen(FILES_REQUIRES) + strlen(fdbe->flags_req) + 1 +
                                 strlen(fdbe->chan ? fdbe->chan : "") + 1);
                    sprintf(s3, "%-30s <DIR%s>  (%s %s%s%s)\n", s2,
                            fdbe->stat & FILE_SHARE ?
                            " SHARE" : "", FILES_REQUIRES, fdbe->flags_req,
                            fdbe->chan ? " " : "", fdbe->chan ? fdbe->chan : "");
                } else {
                    s3 = nmalloc(38 + strlen(s2 ? s2 : ""));
                    sprintf(s3, "%-30s <DIR>\n", s2 ? s2 : "");
                }
                if (s2)
                    my_free(s2);
                filelist_addout(flist, s3);
                my_free(s3);
            } else {
                char s2[41], t[50], *s3 = NULL, *s4;

                s2[0] = 0;
                if (showall) {
                    if (fdbe->stat & FILE_SHARE)
                        strcat(s2, " (shr)");
                    if (fdbe->stat & FILE_HIDDEN)
                        strcat(s2, " (hid)");
                }
                egg_strftime(t, 10, "%d%b%Y", localtime(&fdbe->uploaded));
                if (fdbe->size < 1024)
                    sprintf(s1, "%5d", fdbe->size);
                else
                    sprintf(s1, "%4dk", (int) (fdbe->size / 1024));
                if (fdbe->sharelink)
                    strcpy(s1, "     ");
                /* Too long? */
                if (strlen(fdbe->filename) > 30) {
                    s3 = nmalloc(strlen(fdbe->filename) + 2);
                    sprintf(s3, "%s\n", fdbe->filename);
                    filelist_addout(flist, s3);
                    my_free(s3);
                    /* Causes filename to be displayed on its own line */
                } else
                    malloc_strcpy(s3, fdbe->filename);
                s4 = nmalloc(69 + strlen(s3 ? s3 : "") + strlen(s1) +
                             strlen(fdbe->uploader) + strlen(t) + strlen(s2));
                sprintf(s4, "%-30s %s  %-9s (%s)  %6d%s\n", s3 ? s3 : "", s1,
                        fdbe->uploader, t, fdbe->gots, s2);
                if (s3)
                    my_free(s3);
                filelist_addout(flist, s4);
                my_free(s4);
                if (fdbe->sharelink) {
                    s4 = nmalloc(9 + strlen(fdbe->sharelink));
                    sprintf(s4, "   --> %s\n", fdbe->sharelink);
                    filelist_addout(flist, s4);
                    my_free(s4);
                }
            }
            if (fdbe->desc) {
                p = strchr(fdbe->desc, '\n');
                while (p != NULL) {
                    *p = 0;
                    if ((fdbe->desc)[0]) {
                        char *sd;

                        sd = nmalloc(strlen(fdbe->desc) + 5);
                        sprintf(sd, "   %s\n", fdbe->desc);
                        filelist_addout(flist, sd);
                        my_free(sd);
                    }
                    strcpy(fdbe->desc, p + 1);
                    p = strchr(fdbe->desc, '\n');
                }
                if ((fdbe->desc)[0]) {
                    char *sd;

                    sd = nmalloc(strlen(fdbe->desc) + 5);
                    sprintf(sd, "   %s\n", fdbe->desc);
                    filelist_addout(flist, sd);
                    my_free(sd);
                }
            }
            cnt++;
        }
        free_fdbe(&fdbe);
        fdbe = filedb_getfile(fdb, ftell(fdb), GET_FULL);
    }
    if (is == 0)
        dprintf(idx, FILES_NOFILES);
    else if (cnt == 0)
        dprintf(idx, FILES_NOMATCH);
    else {
        filelist_sort(flist);
        filelist_idxshow(flist, idx);
        dprintf(idx, "--- %d file%s.\n", cnt, cnt != 1 ? "s" : "");
    }
    filelist_free(flist);
}
示例#4
0
int main(int argc, char **argv) /*@globals errno,stderr,stdout@*/
{
    ex_t exitcode = EX_OK;

    fBogotune = true;		/* for rob_compute_spamicity() */

    dbgout = stderr;

    progtype = build_progtype(progname, DB_TYPE);

    ham_files  = filelist_new("ham");
    spam_files = filelist_new("spam");

    /* process args and read mailboxes */
    process_arglist(argc, argv);

    /* directories from command line and config file are already handled */
    if (ds_flag == DS_DSK) {

	bfpath *bfp;

	if (ds_path == NULL)
	    ds_path = get_directory(PR_ENV_BOGO);
	if (ds_path == NULL)
	    ds_path = get_directory(PR_ENV_HOME);

	if (ds_path == NULL) {
	    fprintf(stderr, "Cannot derive bogofilter directory from environment, aborting.\n");
	    exit(EX_ERROR);
	}

	set_bogohome(ds_path);
	bfp = bfpath_create(ds_path);

	if (!bfpath_check_mode(bfp, BFP_MUST_EXIST)) {
	    fprintf(stderr, "Can't open wordlist '%s'\n", bfp->filepath);
	    exit(EX_ERROR);
	}

	if (bfp->exists && bfp->isdir) {
	    bfpath_free(bfp);
	    ds_path = mxcat(ds_path, DIRSEP_S, WORDLIST, NULL);	
	    bfp = bfpath_create(ds_path);
	    if (!bfpath_check_mode(bfp, BFP_MUST_EXIST)) {
		fprintf(stderr, "Can't open wordlist '%s'\n", bfp->filepath);
		exit(EX_ERROR);
	    }
	}

	env = ds_init(bfp);
	
	init_wordlist("word", ds_path, 0, WL_REGULAR);
    }

    bogotune_init();

    if (ds_flag == DS_DSK)
	load_wordlist(load_hook, train);

    /* if encoding not yet set, assume old style */
    if (encoding == E_UNKNOWN)
	encoding = E_RAW;

    if (bogolex_file != NULL)
	bogolex();
    else
	bogotune();

    bogotune_free();

    if (ds_flag == DS_DSK)
	ds_cleanup(env);

    exit(exitcode);
}