// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/filename-filters.c
// Function: FNFILTER_filter
int FNFILTER_filter( char *fname, int size )
{
    int fnl;
    char tmp[1024];
    char *p;

    if (fname == NULL) return 0;

    fnl = strlen(fname);

    DFN LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: fname[%d chars] = '%s'\n", FL, fnl, fname );

    /** If we're handling a Mac file, prefilter **/
    if (glb.x_mac == 1)
    {
        char *q = fname;

        DFN LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: Filtering x-mac filename '%s'",FL,fname);
        while (*q)
        {
            if (*q == '/') *q = '-'; /** Convert the Mac / separator to a hyphen **/
            q++;
        }
        DFN LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: x-mac filename is now '%s'",FL,fname);
    }


    /* We only look at trimming the quotes off a filename if it has more than 2 chars
        * because obviously we'll need to strip off 2 chars (leading and finishing quote)
        */
    if ( fnl > 2 )
    {

        /* if the MIME_filename starts and ends with "'s */
        if ((fname[0] == '\"') && (fname[fnl-1] == '\"'))
        {
            if (FNFILTER_DNORMAL) LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: Trimming quotes off filename\n", FL );

            /* reduce the file namelength by two*/
            fnl = fnl -2; // 17-11-2002: was =-2, thanks to Vasily Chernikov for spotting the glaring error!

            /* shuffle the MIME_filename chars down */
            memmove(fname,fname+1,fnl);

            /* terminate the string */
            fname[fnl] = '\0';
            if (FNFILTER_DNORMAL) LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: Trimming filename done, fname = '%s'\n", FL, fname );
        } /* if */
    } /* if */

    p = strrchr(fname,'/');
    if (p)
    {
        p++;
        PLD_strncpy( tmp, p, sizeof(tmp) );
        PLD_strncpy( fname, tmp, size);

    } else {

        // Check for Windows/DOS backslash seperator

        p = strrchr( fname, '\\' );
        if ( p )
        {
            if ( *(p+1) != '"' )
            {
                p++;
                PLD_strncpy( tmp, p, sizeof(tmp) );
                PLD_strncpy( fname, tmp, size );
            }
        }
    }

    // Scan for ? symbols - these are often used to make the email client pass paremeters to the filename
    //  Check though to see that the previous character is not a '=' symbol, because if it is, then we
    //  actually have an ISO encoded filename

    p = strchr( fname, '?' );
    if (p != NULL)
    {
        if (p > fname)
        {
            if (*(p-1) != '=')
            {
                *p = '\0';
            } else {
                // leave the ? alone, as it's part of an ISO encoded filename
            }

        } else {
            // First char of the filename is a '?', change this to a hypen.
            *p = '-';
        }
    }

    if (FNFILTER_DNORMAL) LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: Starting paranoia filter\n", FL );

    FNFILTER_paranoid_filter( fname, strlen( fname ) );

    if (FNFILTER_DNORMAL) LOGGER_log("%s:%d:FNFILTER_filter:DEBUG: paranoia filter done. Filename='%s'\n", FL, fname );

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x14505
movl $0x0, -0x4(%rbp)
jmp 0x14821
movq -0x10(%rbp), %rdi
callq 0x2100
movl %eax, -0x18(%rbp)
cmpl $0x1, 0x2187c(%rip)     # 0x35d94
jl 0x1453b
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %r8
leaq 0xb52d(%rip), %rdi      # 0x1fa55
leaq 0xb55b(%rip), %rsi      # 0x1fa8a
movl $0xbe, %edx
movb $0x0, %al
callq 0x117c0
cmpl $0x1, 0x2185e(%rip)     # 0x35da0
jne 0x145de
movq -0x10(%rbp), %rax
movq %rax, -0x430(%rbp)
cmpl $0x1, 0x2183a(%rip)     # 0x35d94
jl 0x1457a
movq -0x10(%rbp), %rcx
leaq 0xb536(%rip), %rdi      # 0x1fa9d
leaq 0xb51c(%rip), %rsi      # 0x1fa8a
movl $0xc5, %edx
movb $0x0, %al
callq 0x117c0
jmp 0x1457c
movq -0x430(%rbp), %rax
cmpb $0x0, (%rax)
je 0x145b5
movq -0x430(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x145a1
movq -0x430(%rbp), %rax
movb $0x2d, (%rax)
movq -0x430(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x430(%rbp)
jmp 0x1457c
cmpl $0x1, 0x217d8(%rip)     # 0x35d94
jl 0x145dc
movq -0x10(%rbp), %rcx
leaq 0xb50f(%rip), %rdi      # 0x1fad8
leaq 0xb4ba(%rip), %rsi      # 0x1fa8a
movl $0xcb, %edx
movb $0x0, %al
callq 0x117c0
jmp 0x145de
cmpl $0x2, -0x18(%rbp)
jle 0x14686
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x14684
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x14684
cmpl $0x1, 0x2177f(%rip)     # 0x35d94
jl 0x14631
leaq 0xb4f2(%rip), %rdi      # 0x1fb10
leaq 0xb465(%rip), %rsi      # 0x1fa8a
movl $0xd8, %edx
movb $0x0, %al
callq 0x117c0
movl -0x18(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
movslq -0x18(%rbp), %rdx
callq 0x2310
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
cmpl $0x1, 0x21732(%rip)     # 0x35d94
jl 0x14682
movq -0x10(%rbp), %rcx
leaq 0xb4dc(%rip), %rdi      # 0x1fb4b
leaq 0xb414(%rip), %rsi      # 0x1fa8a
movl $0xe2, %edx
movb $0x0, %al
callq 0x117c0
jmp 0x14684
jmp 0x14686
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
callq 0x2140
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x146e5
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x428(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10640
movq -0x10(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x10640
jmp 0x14756
movq -0x10(%rbp), %rdi
movl $0x5c, %esi
callq 0x2140
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x14754
movq -0x428(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x22, %eax
je 0x14752
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x428(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10640
movq -0x10(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x10640
jmp 0x14754
jmp 0x14756
movq -0x10(%rbp), %rdi
movl $0x3f, %esi
callq 0x2110
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x147ae
movq -0x428(%rbp), %rax
cmpq -0x10(%rbp), %rax
jbe 0x147a2
movq -0x428(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x3d, %eax
je 0x1479e
movq -0x428(%rbp), %rax
movb $0x0, (%rax)
jmp 0x147a0
jmp 0x147a0
jmp 0x147ac
movq -0x428(%rbp), %rax
movb $0x2d, (%rax)
jmp 0x147ae
cmpl $0x1, 0x215df(%rip)     # 0x35d94
jl 0x147d1
leaq 0xb3d0(%rip), %rdi      # 0x1fb8e
leaq 0xb2c5(%rip), %rsi      # 0x1fa8a
movl $0x113, %edx            # imm = 0x113
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rax
movq %rax, -0x438(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2100
movq -0x438(%rbp), %rdi
movl %eax, %esi
callq 0x142d0
cmpl $0x1, 0x2159a(%rip)     # 0x35d94
jl 0x1481a
movq -0x10(%rbp), %rcx
leaq 0xb3be(%rip), %rdi      # 0x1fbc5
leaq 0xb27c(%rip), %rsi      # 0x1fa8a
movl $0x117, %edx            # imm = 0x117
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopl (%rax)