setupinf.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,908 行 · 第 1/5 页

C
1,908
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  Read and parse setup.inf file, create dialogs if necessary.
*               Also initialize other variables.
*
****************************************************************************/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <ctype.h>
#if !defined( __UNIX__ )
    #include <direct.h>
#else
    #include <sys/stat.h>
#endif

#if defined( __WINDOWS__ ) || defined( __NT__ )
    #include "windows.h"
#endif

#include "gui.h"
#include "guistr.h"
#include "guidlg.h"
#include "dlgbutn.h"
#include "guiutil.h"
#include "setup.h"
#include "setupinf.h"
#include "genvbl.h"
#include "gendlg.h"
#include "genctrl.h"
#include "dlggen.h"
#include "utils.h"
#include "setupio.h"
#if !defined( __UNIX__ )
    #include "bdiff.h"
#endif

extern char             *TrimQuote(char*);
extern int              SkipDialogs;
extern int              VisibilityCondition;
extern char             *VariablesFile;
extern void             ReadVariablesFile( char * );

#define RoundUp( v, r ) (((v)+(r)-1) & ~(unsigned long)((r)-1))

#define BUF_SIZE        8192

#include "dynarray.h"

static struct setup_info {
    long                stamp;
    char                *pm_group_file_name;
    char                *pm_group_name;
    char                *pm_group_icon;
    array_info          disks;
    array_info          dirs;
    array_info          files;
    array_info          pm_files;
    array_info          profile;
    array_info          autoexec;
    array_info          config;
    array_info          environment;
    array_info          target;
    array_info          label;
    array_info          upgrade;
#ifdef PATCH
    array_info          patch_files;
#endif
    array_info          spawn;
    array_info          delete;
    array_info          fileconds;
    array_info          dlls_to_count;
    array_info          force_DLL_install;
    array_info          all_pm_groups;
} SetupInfo;

#ifdef PATCH
typedef enum {
    PATCH_COPY_FILE,
    PATCH_DELETE_FILE,
    PATCH_FILE,
    PATCH_MAKE_DIR
} PATCHCOMMANDTYPE;

typedef enum {
    REG_EXE             = 0
} FILETYPE;

struct patch_info {
    PATCHCOMMANDTYPE    command;
    char                *destdir;
    char                *destfile;
    char                *srcfile;
    char                *exetype;
    char                *condition;
} *PatchInfo = NULL;

extern int              ExeType( char *name, char *type );
extern int              PerformDecode( char*, char*, unsigned_32 );
extern unsigned_32      ReadInternal( char* );

#endif

static struct disk_info {
    char                *desc;
} *DiskInfo = NULL;


static struct dir_info {
    char                *desc;
    int                 target;
    int                 parent;
    int                 num_files;
    int                 num_existing;
    unsigned            used            : 1;
} *DirInfo = NULL;


static struct target_info {
    char                *name;
    long                space_needed;
    long                max_tmp_file;
    int                 num_files;
    int                 supplimental;
    bool                needs_update;
    char                *temp_disk;
} *TargetInfo = NULL;

static struct label_info {
    char                *dir;
    char                *label;
} *LabelInfo = NULL;

static struct upgrade_info {
    char                *name;
} *UpgradeInfo = NULL;


typedef struct a_file_info {
    char                *name;
    vhandle             dst_var;
    unsigned long       disk_size;
    unsigned long       disk_date;
    unsigned long       size;
    unsigned long       date;
    unsigned            in_old_dir : 1;
    unsigned            in_new_dir : 1;
    unsigned            read_only : 1;
    unsigned            is_nlm : 1;
} a_file_info;

typedef enum {
    OP_AND,
    OP_OR,
    OP_NOT,
    OP_EXIST,
    OP_VAR,
    OP_FALSE,
    OP_TRUE
} tree_op;

typedef struct tree_node {
    union {
        struct tree_node*left;
        vhandle         v;
    } u;
    struct tree_node    *right;
    tree_op             op;
} tree_node;

typedef struct file_cond_info {
    tree_node *cond;
    unsigned    one_uptodate    : 1;
    unsigned    dont_touch      : 1;
} file_cond_info;

file_cond_info *FileCondInfo = NULL;

static struct file_info {
    char                *filename;
    int                 dir_index, old_dir_index, disk_index;
    unsigned            num_files;
    a_file_info         *files;
    union {
        file_cond_info  *p;
        int             i;
    } condition;
    char                file_type;
    unsigned            add : 1;
    unsigned            remove : 1;
    unsigned            supplimental : 1;
    unsigned            core_component : 1;
} *FileInfo = NULL;

static struct pm_info {
    char                *filename;
    char                *parameters;
    char                *desc;
    char                *icoioname;
    int                 icon_pos;
    char                *condition;
} *PMInfo = NULL;

static struct profile_info {
    char                *hive_name;
    char                *app_name;
    char                *key_name;
    char                *value;
    char                *file_name;
    char                *condition;
} *ProfileInfo = NULL;

static struct spawn_info {
    char                *condition;
    char                *command;
    when_time           when;
} *SpawnInfo = NULL;

typedef enum {
    DELETE_DIALOG,
    DELETE_FILE,
    DELETE_DIR,
} delete_type;

static struct delete_info {
    char                *name;
    delete_type         type;
} *DeleteInfo = NULL;

static struct config_info {
    char                *var;
    char                *value;
    char                *condition;
} *ConfigInfo = NULL, *EnvironmentInfo = NULL, *AutoExecInfo = NULL;

static struct dlls_to_check {
    int                 index;
    char *              full_path;
} *DLLsToCheck = NULL;

static struct force_DLL_install {
    char        *name;
} *ForceDLLInstall = NULL;

static struct all_pm_groups {
    char        *group;
    char        *group_file_name;
} *AllPMGroups = NULL;

typedef enum {
    RS_UNDEFINED,
    RS_APPLICATION,
    RS_DISKS,
    RS_DIRS,
    RS_FILES,
    RS_PMINFO,
    RS_PROFILE,
    RS_AUTOEXEC,
    RS_CONFIG,
    RS_ENVIRONMENT,
    RS_TERMINATE,
    RS_DIALOG,
    RS_TARGET,
    RS_LABEL,
    RS_UPGRADE,
    RS_ERRORMESSAGE,
    RS_SETUPERRORMESSAGE,
    RS_STATUSLINEMESSAGE,
    RS_MISCMESSAGE,
    RS_LICENSEMESSAGE,
    RS_PATCH,
    RS_AUTOSET,
    RS_SPAWN,
    RS_RESTRICTIONS,
    RS_DELETEFILES,
    RS_FORCEDLLINSTALL
} read_state;

static read_state       State;
static size_t           NoLineCount;
static size_t           *LineCountPointer = &NoLineCount;
static bool             NeedGetDiskSizes = FALSE;
static bool             NeedInitAutoSetValues = TRUE;
static char             *ReadBuf;
static size_t           ReadBufSize;
static char             *RawReadBuf;
static char             *RawBufPos;
extern gui_coord        GUIScale;
static int              MaxWidthChars;
static int              CharWidth;

#define MAX_WINDOW_WIDTH 90

#define MAGICVARS( x, y ) \
x( FullInstall, y ) \
x( FullCDInstall, y ) \
x( UnInstall, y ) \
x( MinimalInstall, y ) \
x( SelectiveInstall, y ) \
x( PreviousInstall, y )

#define NONMAGICVARS( x, y ) \
x( IsDos, y ) \
x( IsOS2, y ) \
x( IsOS2DosBox, y ) \
x( IsWin, y ) \
x( IsWin32, y ) \
x( IsWin32s, y ) \
x( IsWin95, y ) \
x( IsWinNT, y ) \
x( HelpFiles, y ) \

#define defvar( x, y ) vhandle x;
MAGICVARS( defvar, 0 )
NONMAGICVARS( defvar, 0 )

#define orvar( x, y ) x == y ||
#define IsMagicVar( v ) MAGICVARS( orvar, v ) FALSE

/**********************************************************************/
/*                   EXPRESSION EVALUTORS                             */
/**********************************************************************/
static tree_node *TreeNode( tree_op op, void *left, void *right )
/********************************************************/
{
    tree_node   *tree;

    tree = GUIMemAlloc( sizeof( tree_node ) );
    tree->op = op;
    tree->u.left = left;
    tree->right = right;
    return( tree );
}

static vhandle GetTokenHandle( char *p );
static tree_node *BuildExprTree( char *str )
/***********************************/
{
    char                *token;
    int                 stack_top;
    tree_node           *stack[ 16 ];
    char                *str2;
    char                *p;
    tree_node           *tree;

    if( str == NULL || str[ 0 ] == '\0' || str[ 0 ] == '.' ) {
        return( TreeNode( OP_TRUE, NULL, NULL ) );
    }
    GUIStrDup( str, &str2 );
    stack_top = -1;
    token = strtok( str2, " " ); // copy string so we can use STRTOK
    while( token != NULL ) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?