Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
mbcs.c File Reference
#include <plgetopt.h>
#include <nspr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

static void TraverseDirectory (unsigned char *dir)
PRIntn main (PRIntn argc, char *argv[])

Variables

PRLogModuleInfolm
PRLogModuleLevel msgLevel = PR_LOG_NONE
PRIntn debug = 0
PRUint32 failed_already = 0
char * dirName = NULL

Function Documentation

PRIntn main ( PRIntn  argc,
char *  argv[] 
)

Definition at line 145 of file mbcs.c.

{
    { /* get command line options */
        /*
        ** Get command line options
        */
        PLOptStatus os;
        PLOptState *opt = PL_CreateOptState(argc, argv, "dv");

           while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
        {
                  if (PL_OPT_BAD == os) continue;
            switch (opt->option)
            {
            case 'd':  /* debug */
                debug = 1;
                         msgLevel = PR_LOG_ERROR;
                break;
            case 'v':  /* verbose mode */
                         msgLevel = PR_LOG_DEBUG;
                break;
             default:
                dirName = strdup(opt->value); 
                break; 
            }
        }
           PL_DestroyOptState(opt);
    } /* end get command line options */

    lm = PR_NewLogModule("Test");       /* Initialize logging */

    
    if ( dirName == NULL )  {
        printf("you gotta specify a directory as an operand!\n");
        exit(1);
    }

    TraverseDirectory( dirName );

    if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
    return( (failed_already == PR_TRUE )? 1 : 0 );
}  /* main() */

Here is the call graph for this function:

static void TraverseDirectory ( unsigned char *  dir) [static]

Definition at line 89 of file mbcs.c.

{
    PRDir *cwd;
    PRDirEntry *dirEntry;
    PRFileInfo info;
    PRStatus rc;
    PRInt32 err;
    PRFileDesc *fd;
    char    nextDir[256];
    char    file[256];

    printf("Directory: %s\n", dir );
    cwd = PR_OpenDir( dir );
    if ( NULL == cwd )  {
        printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n", 
            dir, PR_GetError(), PR_GetOSError());
        exit(1);
    }
    while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN )))  {
        sprintf( file, "%s/%s", dir, dirEntry->name );
        rc = PR_GetFileInfo( file, &info );
        if ( PR_FAILURE == rc ) {
            printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n", 
                dirEntry->name, PR_GetError(), PR_GetOSError());
            exit(1);
        }
        if ( PR_FILE_FILE == info.type )  {
            printf("File: %s \tsize: %ld\n", dirEntry->name, info.size );
            fd = PR_Open( file, PR_RDONLY, 0 );
            if ( NULL == fd )  {
                printf("PR_Open() failed. Error: %ld, OSError: %ld\n", 
                    PR_GetError(), PR_GetOSError());
            }
            rc = PR_Close( fd );
            if ( PR_FAILURE == rc )  {
                printf("PR_Close() failed. Error: %ld, OSError: %ld\n", 
                    PR_GetError(), PR_GetOSError());
            }
        } else if ( PR_FILE_DIRECTORY == info.type ) {
            sprintf( nextDir, "%s/%s", dir, dirEntry->name );
            TraverseDirectory(nextDir);
        } else {
            printf("type is not interesting for file: %s\n", dirEntry->name );
            /* keep going */
        }
    }
    /* assume end-of-file, actually could be error */

    rc = PR_CloseDir( cwd );
    if ( PR_FAILURE == rc ) {
        printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n", 
            dir, PR_GetError(), PR_GetOSError());
    }

} /* end TraverseDirectory() */

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PRIntn debug = 0

Definition at line 80 of file mbcs.c.

char* dirName = NULL

Definition at line 84 of file mbcs.c.

Definition at line 81 of file mbcs.c.

Definition at line 78 of file mbcs.c.

Definition at line 79 of file mbcs.c.