コード例 #1
0
/*
 * read the file into a list of lines.
 *
 * we use the buffered read functions to read a block at a time, and
 * return us a pointer to a line within the block. The line we are
 * pointed to is not null terminated. from this we do a line_new: this
 * will make a copy of the text (since we want to re-use the buffer), and
 * will null-terminate its copy.
 *
 * we also give each line a number, starting at one.
 */
void
file_readlines(FILEDATA fd)
{
    LPSTR textp;
    LPWSTR pwzText;
    int cwch;
    HANDLE fh;
    FILEBUFFER fbuf;
    int linelen;
    int linenr = 1;
    HCURSOR hcurs;

    hcurs = SetCursor(LoadCursor(NULL, IDC_WAIT));

    /* open the file */
    fh = dir_openfile(fd->diritem);

    if (fh == INVALID_HANDLE_VALUE) {
        TRACE_ERROR(LoadRcString(IDS_ERR_OPENING_FILE), FALSE);
        SetCursor(hcurs);
        return;
    }
    /* initialise the file buffering */
    fbuf = readfile_new(fh, &fd->fUnicode);

    if (fbuf)
    {
        /* make an empty list for the files */
        fd->lines = List_Create();

        while ( (textp = readfile_next(fbuf, &linelen, &pwzText, &cwch)) != NULL) {
            if (linelen>0) { /* readfile failure gives linelen==-1 */
                line_new(textp, linelen, pwzText, cwch, linenr++, fd->lines);
            } else {
                line_new("!! <unreadable> !!", 20, NULL, 0, linenr++,fd->lines);
                break;
            }


        }

        /* close filehandle and free buffer */
        readfile_delete(fbuf);
    }

    dir_closefile(fd->diritem, fh);

    SetCursor(hcurs);
}
コード例 #2
0
ファイル: browse.c プロジェクト: mingpen/OpenNT
BOOL
BrowseForDirectory( char *szCurrDir )

/*++

Routine Description:

    Presents a common file open dialog that contains only the directory
    tree.  The use can select a directory for use as a storage location
    for the DRWTSN32 log file.

Arguments:

    szCurrDir  - current directory

Return Value:

    TRUE       - got a good directory (user pressed the OK button)
    FALSE      - got nothing (user pressed the CANCEL button)

    the szCurrDir is also changed to have the selected directory.

--*/

{
    OPENFILENAME   of;
    char           ftitle     [MAX_PATH];
    char           title      [MAX_PATH];
    char           fname      [MAX_PATH];
    char           szDrive    [_MAX_DRIVE];
    char           szDir      [_MAX_DIR];

    ftitle[0] = 0;
    strcpy( fname, "*.*" );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = NULL;
    of.hInstance = GetModuleHandle( NULL );
    of.lpstrFilter = NULL;
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter = 0;
    of.nFilterIndex = 0;
    of.lpstrFile = fname;
    of.nMaxFile = MAX_PATH;
    of.lpstrFileTitle = ftitle;
    of.nMaxFileTitle = MAX_PATH;
    of.lpstrInitialDir = szCurrDir;
    strcpy( title, LoadRcString( IDS_LOGBROWSE_TITLE ) );
    of.lpstrTitle = title;
    of.Flags = OFN_NONETWORKBUTTON |
               OFN_ENABLEHOOK      |
               OFN_NOCHANGEDIR     |
               OFN_SHOWHELP        |
               OFN_ENABLETEMPLATE;
    of.nFileOffset = 0;
    of.nFileExtension = 0;
    of.lpstrDefExt = NULL;
    of.lCustData = 0;
    of.lpfnHook = BrowseHookProc;
    of.lpTemplateName = MAKEINTRESOURCE(DIRBROWSEDIALOG);
    if (GetSaveFileName( &of )) {
        _splitpath( fname, szDrive, szDir, NULL, NULL );
        strcpy( szCurrDir, szDrive );
        strcat( szCurrDir, szDir );
        szCurrDir[strlen(szCurrDir)-1] = '\0';
        return TRUE;
    }
    return FALSE;
}
コード例 #3
0
ファイル: browse.c プロジェクト: mingpen/OpenNT
BOOL
GetDumpFileName( char *szDumpName )

/*++

Routine Description:

    Presents a common file open dialog for the purpose of selecting a
    wave file to be played when an application error occurs.

Arguments:

    szWaveName - name of the selected wave file

Return Value:

    TRUE       - got a good wave file name (user pressed the OK button)
    FALSE      - got nothing (user pressed the CANCEL button)

    the szWaveName is changed to have the selected wave file name.

--*/

{
    OPENFILENAME   of;
    char           ftitle[MAX_PATH];
    char           title[MAX_PATH];
    char           fname[MAX_PATH];
    char           filter[1024];
    char           szDrive    [_MAX_DRIVE];
    char           szDir      [_MAX_DIR];

    ftitle[0] = 0;
    strcpy( fname, "*.dmp" );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = NULL;
    of.hInstance = GetModuleHandle( NULL );
    strcpy( filter, LoadRcString( IDS_DUMP_FILTER ) );
    strcpy( &filter[strlen(filter)+1], "*.dmp" );
    filter[strlen(filter)+1] = '\0';
    of.lpstrFilter = filter;
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter = 0;
    of.nFilterIndex = 0;
    of.lpstrFile = fname;
    of.nMaxFile = MAX_PATH;
    of.lpstrFileTitle = ftitle;
    of.nMaxFileTitle = MAX_PATH;
    of.lpstrInitialDir = szLastDumpFile;
    strcpy( title, LoadRcString( IDS_DUMPBROWSE_TITLE ) );
    of.lpstrTitle = title;
    of.Flags = OFN_NONETWORKBUTTON |
               OFN_ENABLEHOOK      |
               OFN_ENABLETEMPLATE  |
               OFN_SHOWHELP        |
               OFN_NOCHANGEDIR;
    of.nFileOffset = 0;
    of.nFileExtension = 0;
    of.lpstrDefExt = "dmp";
    of.lCustData = 0;
    of.lpfnHook = DumpHookProc;
    of.lpTemplateName = MAKEINTRESOURCE(DUMPFILEOPENDIALOG);
    if (GetOpenFileName( &of )) {
        strcpy( szDumpName, fname );
        _splitpath( fname, szDrive, szDir, NULL, NULL );
        strcpy( szLastDumpFile, szDrive );
        strcat( szLastDumpFile, szDir );
        return TRUE;
    }
    return FALSE;
}