setupinf.c

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

C
1,908
字号
#endif
            }
            if( val == NULL && line[1] != '\0' ) {
                val = getenv( &line[1] );
            }
        } else {
            val = line;
        }
    }
    if( val == NULL || val[0] == '\0' ) val = VarGetStrVal( var_handle );
    SetVariableByHandle( var_handle, val );
    if( VariablesFile != NULL ) {
        ReadVariablesFile( VarGetName( var_handle ) );
    }
    line = next; next = NextToken( line, '"' );
    line = next; next = NextToken( line, '"' );
    ReplaceVars( buff, line );
    line = next; next = NextToken( line, ',' );
    line = next; next = NextToken( line, ',' );
    if( line == NULL || *line == '\0' || EvalCondition( line ) ) {
        dlg->curr_dialog->pVariables[dlg->num_variables] = var_handle;
        dlg->num_variables += 1;
        line = next; next = NextToken( line, ',' );
        if( line != NULL ) {
            // condition for visibility (dynamic)
            GUIStrDup( line,
                       &dlg->curr_dialog->pVisibilityConds[ dlg->curr_dialog->num_controls ] );
        }
        set_dlg_edit( dlg->curr_dialog->controls, dlg->array.num-1,
                      buff, VarGetId( var_handle ), C0, dlg->row_num, C0 + W - 1 );
        if( buff[0] != '\0' ) {
            BumpArray( &dlg->array );
            if( line != NULL ) {
                // condition for visibility (dynamic)
                GUIStrDup( line,
                           &dlg->curr_dialog->pVisibilityConds[ dlg->curr_dialog->num_controls + 1] );
            }
            MakeDummyVar( dummy_var );
            // dummy_var allows control to have an id - used by dynamic visibility feature
            var_handle = AddVariable( dummy_var );
            set_dlg_dynamstring( dlg->curr_dialog->controls, dlg->array.num-1, buff, var_handle,
                      C0, dlg->row_num, C0 + strlen( buff ) );
        }
        dlg->max_width = max( dlg->max_width, 2*strlen( buff ) );
    } else {
        rc = FALSE;
    }
    GUIMemFree( vbl_name );
    return( rc );
}

static void CompileCondition( char *str, char **to );

static void GrabConfigInfo( char *line, array_info *info )
/********************************************************/
{
   int          num;
   char         *next;
   struct       config_info *array;

    num = info->num;
    if( !BumpArray( info ) )
        return;
    array = *(info->array);
    next = NextToken( line, '=' );
    GUIStrDup( line, &array[num].var );
    line = next; next = NextToken( line, ',' );
    GUIStrDup( line, &array[num].value );
    CompileCondition( next, &array[num].condition );
}

static bool ProcLine( char *line, pass_type pass )
/************************************************/
{
    char                *next;
    int                 num;
    int                 tmp;
    char                *p;

    // Remove leading and trailing white-space.
    line = StripEndBlanks( line );

    // Check for comment
    if( *line == '#' ) {
        return( TRUE );
    }

    // Check if the state has changed.
    if( *line == '[' ) {
        LineCountPointer = &NoLineCount;
        if( stricmp( line, "[End]" ) == 0 ) {
            State = RS_TERMINATE;
        } else if( stricmp( line, "[Application]" ) == 0 ) {
            State = RS_APPLICATION;
        } else if( stricmp( line, "[Disks]" ) == 0 ) {
            State = RS_DISKS;
            LineCountPointer = &SetupInfo.disks.alloc;
        } else if( stricmp( line, "[Dirs]" ) == 0 ) {
            State = RS_DIRS;
            LineCountPointer = &SetupInfo.dirs.alloc;
        } else if( stricmp( line, "[Files]" ) == 0 ) {
            State = RS_FILES;
            LineCountPointer = &SetupInfo.files.alloc;
        } else if( stricmp( line, "[PM Info]" ) == 0 ) {
            State = RS_PMINFO;
            LineCountPointer = &SetupInfo.pm_files.alloc;
        } else if( stricmp( line, "[Profile]" ) == 0 ) {
            State = RS_PROFILE;
            LineCountPointer = &SetupInfo.profile.alloc;
        } else if( stricmp( line, "[Autoexec]" ) == 0 ) {
            State = RS_AUTOEXEC;
            LineCountPointer = &SetupInfo.autoexec.alloc;
        } else if( stricmp( line, "[Config]" ) == 0 ) {
            State = RS_CONFIG;
            LineCountPointer = &SetupInfo.config.alloc;
        } else if( stricmp( line, "[Environment]" ) == 0 ) {
            State = RS_ENVIRONMENT;
            LineCountPointer = &SetupInfo.environment.alloc;
        } else if( stricmp( line, "[Dialog]" ) == 0 ) {
            State = RS_DIALOG;
        } else if( stricmp( line, "[Targets]" ) == 0 ) {
            State = RS_TARGET;
            LineCountPointer = &SetupInfo.target.alloc;
        } else if( stricmp( line, "[Labels]" ) == 0 ) {
            State = RS_LABEL;
            LineCountPointer = &SetupInfo.label.alloc;
        } else if( stricmp( line, "[Upgrade]" ) == 0 ) {
            State = RS_UPGRADE;
            LineCountPointer = &SetupInfo.upgrade.alloc;
        } else if( stricmp( line, "[ErrorMessage]" ) == 0 ) {
            State = RS_ERRORMESSAGE;
        } else if( stricmp( line, "[SetupErrorMessage]" ) == 0 ) {
            State = RS_SETUPERRORMESSAGE;
        } else if( stricmp( line, "[StatuslineMessage]" ) == 0 ) {
            State = RS_STATUSLINEMESSAGE;
        } else if( stricmp( line, "[MiscMessage]" ) == 0 ) {
            State = RS_MISCMESSAGE;
        } else if( stricmp( line, "[LicenseMessage]" ) == 0 ) {
            State = RS_LICENSEMESSAGE;
#ifdef PATCH
        } else if( stricmp( line, "[Patch]" ) == 0 ) {
            State = RS_PATCH;
            LineCountPointer = &SetupInfo.patch_files.alloc;
#endif
        } else if( stricmp( line, "[Restrictions]" ) == 0 ) {
            State = RS_RESTRICTIONS;
        } else if( stricmp( line, "[DeleteFiles]" ) == 0 ) {
            State = RS_DELETEFILES;
            LineCountPointer = &SetupInfo.delete.alloc;
        } else if( stricmp( line, "[AutoSet]" ) == 0 ) {
            State = RS_AUTOSET;
        } else if( stricmp( line, "[Spawn]" ) == 0 ) {
            State = RS_SPAWN;
        } else if( stricmp( line, "[ForceDLLInstall]" ) == 0 ) {
            State = RS_FORCEDLLINSTALL;
            LineCountPointer = &SetupInfo.force_DLL_install.alloc;
        } else {
            State = RS_UNDEFINED;   // Unrecognized section in SETUP.INF file.
        }
        return( TRUE );
    }

    // line is part of the current state.
    if( *line == ';' || *line == '\0' )
        return( TRUE );
    if( pass == PRESCAN_FILE ) {
        ++*LineCountPointer;
        return( TRUE );
    }

    switch( State ) {
    case RS_DIALOG:
        {
        static DIALOG_INFO  dialog_info;
        bool            added;

        next = NextToken( line, '=' );
        if( stricmp( line, "name" ) == 0 ) {
            // new dialog
            memset( &dialog_info, 0, sizeof( DIALOG_INFO ) );
            dialog_info.curr_dialog = AddNewDialog( next );
            InitArray( &dialog_info.curr_dialog->controls, sizeof( gui_control_info ), &dialog_info.array );
            dialog_info.wrap_width = MaxWidthChars;
        } else if( stricmp( line, "condition" ) == 0 ) {
            CompileCondition( next, &dialog_info.curr_dialog->condition );
        } else if( stricmp( line, "title" ) == 0 ) {
            GUIStrDup( next, &dialog_info.curr_dialog->title );
        } else if( stricmp( line, "any_check" ) == 0 ) {
            dialog_info.curr_dialog->any_check = AddVariable( next );
        } else if( stricmp( line, "width" ) == 0 ) {
            int         wrap_width;
            wrap_width = atoi( next );
            if( wrap_width > 0  &&  wrap_width <= MaxWidthChars ) {
                dialog_info.wrap_width = wrap_width;
            }
        } else if( stricmp( line, "vis_condition" ) == 0 ) {
            line = next; next = NextToken( line, ',' );
            if( next == NULL || EvalCondition( next ) ) {
                GUIStrDup( line,
                           &dialog_info.curr_dialog->pVisibilityConds[ dialog_info.curr_dialog->num_controls - 1 ] );
            }
        } else {
            // add another control to current dialog
            if( !BumpArray( &dialog_info.array ) ) {
                SetupError( "IDS_NOMEMORY" );
                exit( 1 );
            }
            if( stricmp( line, "static_text" ) == 0 ) {
                dialog_info.col_num = C0;
                added = dialog_static( next, &dialog_info );
            } else if( stricmp( line, "dynamic_text" ) == 0 ) {
                added = dialog_dynamic( next, &dialog_info );
            } else if( stricmp( line, "other_button" ) == 0 ) {
                added = dialog_other_button( next, &dialog_info );
            } else if( stricmp( line, "edit_button" ) == 0 ) {
                added = dialog_edit_button( next, &dialog_info );
            } else if( stricmp( line, "push_button" ) == 0 ) {
                added = dialog_pushbutton( next, &dialog_info );
                if( added ) {
                    dialog_info.row_num -= 1;
                }
            } else if( stricmp( line, "radio_button" ) == 0 ) {
                added = dialog_radiobutton( next, &dialog_info );
            } else if( stricmp(line, "check_box") == 0 ) {
                dialog_info.col_num = C0;
                added = dialog_checkbox( next, &dialog_info );
            } else if( stricmp(line, "detail_check") == 0 ) {
                dialog_info.col_num = C0;
                added = dialog_detail_check( next, &dialog_info );
            } else if( stricmp(line, "check_box_continue") == 0 ) {
                dialog_info.row_num -= 1;
                added = dialog_checkbox( next, &dialog_info );
            } else if( stricmp(line, "edit_control") == 0 ) {
                added = dialog_editcontrol( next, &dialog_info );
            } else if( stricmp(line, "text_window") == 0 ) {
                added = dialog_textwindow( next, &dialog_info );
            }
            if( added ) {
                dialog_info.row_num += 1;
                // in case this was the last control, set some values
                dialog_info.curr_dialog->pVariables[dialog_info.num_variables] = NO_VAR;
                dialog_info.curr_dialog->pConditions[dialog_info.num_variables] = NULL;
                dialog_info.curr_dialog->num_controls = dialog_info.array.num;
                dialog_info.curr_dialog->num_push_buttons = dialog_info.num_push_buttons;
                dialog_info.curr_dialog->rows = dialog_info.row_num  + HEIGHT_BORDER;
                if( dialog_info.num_push_buttons != 0 ) {
                    dialog_info.curr_dialog->rows += 1;
                }
                dialog_info.curr_dialog->cols = dialog_info.max_width + WIDTH_BORDER;
            } else {
                dialog_info.array.num--;
            }
        }
        }
        break;
    case RS_APPLICATION:
        next = NextToken( line, '=' );
        if( stricmp( line, "DefPMGroup" ) == 0 ) {
            line = next; next = NextToken( line, ',' );
            GUIStrDup( line, &SetupInfo.pm_group_file_name );
            line = next; next = NextToken( line, ',' );
            GUIStrDup( line, &SetupInfo.pm_group_name );
            num = SetupInfo.all_pm_groups.num;
            if( !BumpArray( &SetupInfo.all_pm_groups ) )
                return( FALSE );
            GUIStrDup( line, &AllPMGroups[ num ].group );
            GUIStrDup( SetupInfo.pm_group_file_name, &AllPMGroups[ num ].group_file_name );
            if( next == NULL ) {
                SetupInfo.pm_group_icon = NULL;
            } else {
                GUIStrDup( next, &SetupInfo.pm_group_icon );
            }
        } else {
            if( line[0] == '$' ) {
                // global variables start with '$'
                if( GetVariableByName( line ) == NO_VAR ) {
                    // if variable already is set, do not change it
                    SetVariableByName( line, next );
                }
            } else {
                SetVariableByName( line, next );
            }
        }
        break;

    case RS_DISKS:
        num = SetupInfo.disks.num;
        if( !BumpArray( &SetupInfo.disks ) )
            return( FALSE );
        GUIStrDup( line, &DiskInfo[num].desc );
        break;

    case RS_DIRS:
        num = SetupInfo.dirs.num;
        if( !BumpArray( &SetupInfo.dirs ) )
            return( FALSE );
        next = NextToken( line, ',' );
        GUIStrDup( line, &DirInfo[num].desc );
        line = next; next = NextToken( line, ',' );
        DirInfo[num].target = atoi( line ) - 1;
        DirInfo[num].parent = atoi( next );
        if( DirInfo[num].parent != -1 ) {
            DirInfo[num].parent--;
        }
        break;

    case RS_FILES:
        num = SetupInfo.files.num;
        if( !BumpArray( &SetupInfo.files ) )
            return( FALSE );
        next = NextToken( line, ',' );
        GUIStrDup( line, &FileInfo[num].filename );
        line = next; next = NextToken( line, ',' );
        /*
            Multiple files in archive. First number is number of files,
            followed by a list of file sizes in 512 byte blocks.
        */
        #define get36( x ) strtol( x, NULL, 36 )
        tmp = get36( line );
        if( tmp == 0 ) {
            FileInfo[ num ].files = NULL;
        } else {
            FileInfo[ num ].files = GUIMemAlloc( tmp * sizeof( a_file_info ) );
            if( FileInfo[ num ].files == NULL )
                return( NULL );
        }
        FileInfo[num].supplimental = FALSE;
        FileInfo[num].core_component = FALSE;
        FileInfo[ num ].num_files = tmp;
        while( --tmp >= 0 ) {
            a_file_info *file = &FileInfo[num].files[tmp];

            line = next; next = NextToken( line, ',' );
            p = NextToken( line, '!' );
            GUIStrDup( line, &file->name );
            {
                char    fext[_MAX_EXT];
                _splitpath( file->name, NULL, NULL, NULL, fext );
                file->is_nlm = stricmp( fext, ".nlm" ) == 0;
            }
            line = p; p = NextToken( line, '!' );
            file->size = get36( line ) * 512UL;
            if( p != NULL && p[0] != '\0' && p[0] != '!' ) {
                file->date = get36( p );
            } else {
                file->date = SetupInfo.stamp;
            }
            line = p; p = NextToken( line, '!' );
            if( p != NULL && p[0] != '\0' && p[0] != '!' ) {
                file->dst_var = AddVariable( p );
            } else {
                file->dst_var = NO_VAR;
            }
            line = p; p = NextToken( line, '!' );
            if( p != NULL ) {
                if( *p == 's' ) {
                    FileInfo[ num ].supplimental = TRUE;
                } else if( *p == 'k' ) {
                    FileInfo[ num ].core_component = TRUE;
                }
            }
        }
        line = next; next = NextToken( line, ',' );
        FileInfo[ num ].dir_index = get36( line ) - 1;
        line = next; next = NextToken( line, ',' );
        FileInfo[ num ].old_dir_index = get36( line );
        if( FileInfo[ num ].old_dir_index != -1 ) {
            FileInfo[ num ].old_dir_index--;
        }
        line = next; next = NextToken( line, ',' );
        FileInfo[ num ].disk_index = get36( line ) - 1;
        line = next; next = NextToken( line, ',' );
        FileInfo[ num ].file_type = tolower( *line );
        line = next; next = NextToken( line, ',' );
        FileInfo[num].condition.i = NewFileCond( line );
        break;

#ifdef PATCH
    case RS_PATCH:
        num = SetupInfo.pa

⌨️ 快捷键说明

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