From a0b7abf7ff2b3ec098f2aca8dc30aac5ee0fa1ad Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 15 Jun 2016 22:31:47 +0100 Subject: [PATCH] Remove FGAdmin --- CMakeLists.txt | 1 - CMakeModules/ConfigureMsvc3rdParty.cmake | 10 +- utils/CMakeLists.txt | 4 - utils/fgadmin/AUTHORS | 3 - utils/fgadmin/CMakeLists.txt | 47 - utils/fgadmin/README | 35 - utils/fgadmin/src/.gitignore | 1 - utils/fgadmin/src/CMakeLists.txt | 19 - utils/fgadmin/src/config_cmake.h.in | 2 - utils/fgadmin/src/fgadmin.cxx | 142 --- utils/fgadmin/src/fgadmin.fl | 136 -- utils/fgadmin/src/fgadmin.h | 98 -- utils/fgadmin/src/fgadmin_funcs.cxx | 447 ------- utils/fgadmin/src/main.cxx | 91 -- utils/fgadmin/src/untarka.c | 1472 ---------------------- utils/fgadmin/src/untarka.h | 15 - 16 files changed, 2 insertions(+), 2521 deletions(-) delete mode 100644 utils/fgadmin/AUTHORS delete mode 100644 utils/fgadmin/CMakeLists.txt delete mode 100644 utils/fgadmin/README delete mode 100644 utils/fgadmin/src/.gitignore delete mode 100644 utils/fgadmin/src/CMakeLists.txt delete mode 100644 utils/fgadmin/src/config_cmake.h.in delete mode 100644 utils/fgadmin/src/fgadmin.cxx delete mode 100644 utils/fgadmin/src/fgadmin.fl delete mode 100644 utils/fgadmin/src/fgadmin.h delete mode 100644 utils/fgadmin/src/fgadmin_funcs.cxx delete mode 100644 utils/fgadmin/src/main.cxx delete mode 100644 utils/fgadmin/src/untarka.c delete mode 100644 utils/fgadmin/src/untarka.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 26cc596ee..abb820b1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,7 +182,6 @@ option(FG_NIGHTLY "Set to ON to mark this as a nightly build" OFF) option(ENABLE_DEV_WARNINGS "Set to ON to include developer-warnings" OFF) # additional utilities -option(ENABLE_FGADMIN "Set to ON to build the FGADMIN application (default)" ON) option(ENABLE_FGELEV "Set to ON to build the fgelev application (default)" ON) option(WITH_FGPANEL "Set to ON to build the fgpanel application (default)" ON) option(ENABLE_FGVIEWER "Set to ON to build the fgviewer application (default)" ON) diff --git a/CMakeModules/ConfigureMsvc3rdParty.cmake b/CMakeModules/ConfigureMsvc3rdParty.cmake index ebb0b87b1..ecfea56d4 100644 --- a/CMakeModules/ConfigureMsvc3rdParty.cmake +++ b/CMakeModules/ConfigureMsvc3rdParty.cmake @@ -38,16 +38,10 @@ if (MSVC AND MSVC_3RDPARTY_ROOT) set( MSVC_3RDPARTY_DIR 3rdParty ) set( BOOST_LIB lib ) endif (CMAKE_CL_64) - find_path(FLTK_DIR include/FL/Fl.H - ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/fltk - ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/fltk-1.3 - ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR} - ) - list (APPEND CMAKE_PROGRAM_PATH ${FLTK_DIR}/bin) GET_FILENAME_COMPONENT(MSVC_ROOT_PARENT_DIR ${MSVC_3RDPARTY_ROOT} PATH) - set (CMAKE_LIBRARY_PATH ${FLTK_DIR}/lib ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/lib $(BOOST_ROOT)/$(BOOST_LIB) ) - set (CMAKE_INCLUDE_PATH ${FLTK_DIR}/include ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/include) + set (CMAKE_LIBRARY_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/lib $(BOOST_ROOT)/$(BOOST_LIB) ) + set (CMAKE_INCLUDE_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/include) find_path(BOOST_ROOT boost/version.hpp ${MSVC_ROOT_PARENT_DIR} ${MSVC_3RDPARTY_ROOT}/boost diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 2d5b30666..f0dfbed2e 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,7 +1,3 @@ -if(ENABLE_FGADMIN) - add_subdirectory(fgadmin) -endif() - # win32 is just excluded because of not having argument parsing there ... if(RTI_FOUND AND NOT WIN32) add_subdirectory(fgai) diff --git a/utils/fgadmin/AUTHORS b/utils/fgadmin/AUTHORS deleted file mode 100644 index 0b90f1aaa..000000000 --- a/utils/fgadmin/AUTHORS +++ /dev/null @@ -1,3 +0,0 @@ -Curtis Olson -Frederic Bouvier -Erik Hofman diff --git a/utils/fgadmin/CMakeLists.txt b/utils/fgadmin/CMakeLists.txt deleted file mode 100644 index fa59a8ec1..000000000 --- a/utils/fgadmin/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -#Zlib is already required by FG but we check it just in case -if( ZLIB_FOUND ) - include_directories(${ZLIB_INCLUDE_DIR}) - set( HAVE_ZLIB 1) - message(STATUS "Zlib found for fgadmin") -endif( ZLIB_FOUND ) - -find_package(BZip2) -if( BZIP2_FOUND ) - include_directories(${BZIP2_INCLUDE_DIR}) - set( HAVE_BZ2LIB 1) - message(STATUS "BZip2 found for fgadmin") -endif( BZIP2_FOUND ) - -find_package(FLTK) -if( FLTK_FOUND ) - include_directories(${FLTK_INCLUDE_DIR}) - - if ( X11_Xinerama_FOUND ) - message(STATUS "Found X11_Xinerama...") - list(APPEND FLTK_LIBRARIES ${X11_Xinerama_LIB}) - endif() - - if ( X11_Xft_FOUND ) - message(STATUS "Found X11_Xft...") - list(APPEND FLTK_LIBRARIES ${X11_Xft_LIB}) - endif() - - if ( CMAKE_DL_LIBS ) - list(APPEND FLTK_LIBRARIES ${CMAKE_DL_LIBS}) - endif() - - if( EXISTS ${FLTK_FLUID_EXECUTABLE} ) - add_subdirectory(src) - else() - message(STATUS "Fluid executable not found, disabling fgadmin") - endif() - - message(STATUS "Using FLTK_LIBRARIES for fgadmin: ${FLTK_LIBRARIES}") -else() - message(STATUS "FLTK not found, disabling fgadmin") -endif( FLTK_FOUND ) - -configure_file( - "${PROJECT_SOURCE_DIR}/utils/fgadmin/src/config_cmake.h.in" - "${PROJECT_BINARY_DIR}/utils/fgadmin/src/config_fgadmin.h" -) diff --git a/utils/fgadmin/README b/utils/fgadmin/README deleted file mode 100644 index d7fd5cab1..000000000 --- a/utils/fgadmin/README +++ /dev/null @@ -1,35 +0,0 @@ -Welcome to the FlightGear Flight Simulator project. -=================================================== - -The primary web page for this project is: http://www.flightgear.org - -For basic installation instructions see the "INSTALL" file. - -Before you can run FlightGear you will also need to download and -install the "base" package which is a collection of textures, sounds, -sample scenery, and other data files need by the sim. - -For additional install help for specific platforms please browse the -"docs-mini/" subdirectory. - -More complete documentation is available from our web page as a -separate distribution. - -Please take a look at the "Thanks" file for a list of people who have -contributed to this project. If you have contributed something but -don't find your name in this file. Please send a polite reminder to -http://www.flightgear.org/~curt - -For a summary of changes/additions by version see the "NEWS" file. - -This project is GPL'd. For complete details on our licensing please -see the "COPYING" file. - -For information on available mailing lists, mailing list archives, and -other available source code and documenation, please visit our web -site. - -FlightGear is a product of the collaboration of large international -group of volunteers. FlightGear is a work in progress. FlightGear -comes with no warrantee. We hope you enjoy FlightGear and/or find it -of some value! diff --git a/utils/fgadmin/src/.gitignore b/utils/fgadmin/src/.gitignore deleted file mode 100644 index 6e2d97b1f..000000000 --- a/utils/fgadmin/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -fgadmin diff --git a/utils/fgadmin/src/CMakeLists.txt b/utils/fgadmin/src/CMakeLists.txt deleted file mode 100644 index ef98c6c14..000000000 --- a/utils/fgadmin/src/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -fltk_wrap_ui(FGAdminUI fgadmin.fl) -add_library(FGAdminUI ${FGAdminUI_FLTK_UI_SRCS}) - -add_executable(fgadmin WIN32 fgadmin_funcs.cxx main.cxx untarka.c) -add_dependencies(fgadmin FGAdminUI) - -target_link_libraries(fgadmin FGAdminUI - ${SIMGEAR_CORE_LIBRARIES} - ${PLIB_LIBRARIES} - ${FLTK_LIBRARIES} - ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} - ${ZLIB_LIBRARIES} -) - -if( BZIP2_FOUND ) - target_link_libraries(fgadmin ${BZIP2_LIBRARIES}) -endif( BZIP2_FOUND ) - -install(TARGETS fgadmin RUNTIME DESTINATION bin) diff --git a/utils/fgadmin/src/config_cmake.h.in b/utils/fgadmin/src/config_cmake.h.in deleted file mode 100644 index 2409de6d9..000000000 --- a/utils/fgadmin/src/config_cmake.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#cmakedefine HAVE_BZ2LIB -#cmakedefine HAVE_ZLIB diff --git a/utils/fgadmin/src/fgadmin.cxx b/utils/fgadmin/src/fgadmin.cxx deleted file mode 100644 index fc47acf34..000000000 --- a/utils/fgadmin/src/fgadmin.cxx +++ /dev/null @@ -1,142 +0,0 @@ -// generated by Fast Light User Interface Designer (fluid) version 1.0106 - -#include -// using std::cout; -using std::endl; - -#include "fgadmin.h" -#include - -inline void FGAdminUI::cb_main_window_i(Fl_Double_Window*, void*) { - fl_alert("Use the Quit button to exit fgadmin"); -} -void FGAdminUI::cb_main_window(Fl_Double_Window* o, void* v) { - ((FGAdminUI*)(o->user_data()))->cb_main_window_i(o,v); -} - -inline void FGAdminUI::cb_quit_b_i(Fl_Button*, void*) { - quit(); -} -void FGAdminUI::cb_quit_b(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->user_data()))->cb_quit_b_i(o,v); -} - -inline void FGAdminUI::cb_source_b_i(Fl_Button*, void*) { - select_install_source(); -refresh_lists(); -} -void FGAdminUI::cb_source_b(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_source_b_i(o,v); -} - -inline void FGAdminUI::cb_install_b_i(Fl_Button*, void*) { - install_selected(); -} -void FGAdminUI::cb_install_b(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_install_b_i(o,v); -} - -inline void FGAdminUI::cb_source_sel_all_i(Fl_Button*, void*) { - install_box->check_all(); -} -void FGAdminUI::cb_source_sel_all(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_source_sel_all_i(o,v); -} - -inline void FGAdminUI::cb_source_desel_all_i(Fl_Button*, void*) { - install_box->check_none(); -} -void FGAdminUI::cb_source_desel_all(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_source_desel_all_i(o,v); -} - -inline void FGAdminUI::cb_dest_b_i(Fl_Button*, void*) { - select_install_dest(); -refresh_lists(); -} -void FGAdminUI::cb_dest_b(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_dest_b_i(o,v); -} - -inline void FGAdminUI::cb_remove_b_i(Fl_Button*, void*) { - remove_selected(); -} -void FGAdminUI::cb_remove_b(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_remove_b_i(o,v); -} - -inline void FGAdminUI::cb_dest_sel_all_i(Fl_Button*, void*) { - remove_box->check_all(); -} -void FGAdminUI::cb_dest_sel_all(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_dest_sel_all_i(o,v); -} - -inline void FGAdminUI::cb_dest_desel_all_i(Fl_Button*, void*) { - remove_box->check_none(); -} -void FGAdminUI::cb_dest_desel_all(Fl_Button* o, void* v) { - ((FGAdminUI*)(o->parent()->parent()->parent()->user_data()))->cb_dest_desel_all_i(o,v); -} - -FGAdminUI::FGAdminUI() { - { Fl_Double_Window* o = main_window = new Fl_Double_Window(465, 435, "FlightGear Admin Wizard"); - o->callback((Fl_Callback*)cb_main_window, (void*)(this)); - { Fl_Group* o = new Fl_Group(5, 405, 455, 25); - { Fl_Button* o = quit_b = new Fl_Button(375, 405, 85, 25, "Quit"); - o->callback((Fl_Callback*)cb_quit_b); - } - { Fl_Progress* o = progress = new Fl_Progress(5, 405, 365, 25); - o->color(FL_BACKGROUND_COLOR); - o->selection_color((Fl_Color)175); - Fl_Group::current()->resizable(o); - } - o->end(); - } - { Fl_Group* o = new Fl_Group(5, 5, 460, 390); - { Fl_Group* o = new Fl_Group(5, 5, 225, 390); - { Fl_Button* o = source_b = new Fl_Button(5, 5, 225, 25, "Select Scenery Source ..."); - o->callback((Fl_Callback*)cb_source_b); - } - source_text = new Fl_Input(5, 35, 225, 25); - { Fl_Check_Browser* o = install_box = new Fl_Check_Browser(5, 95, 225, 240, "Select Files to Install"); - Fl_Group::current()->resizable(o); - } - { Fl_Button* o = install_b = new Fl_Button(20, 360, 195, 35, "Install Selected Files"); - o->labelfont(1); - o->callback((Fl_Callback*)cb_install_b); - } - { Fl_Button* o = source_sel_all = new Fl_Button(5, 65, 110, 25, "Select all"); - o->callback((Fl_Callback*)cb_source_sel_all); - } - { Fl_Button* o = source_desel_all = new Fl_Button(120, 65, 110, 25, "Deselect all"); - o->callback((Fl_Callback*)cb_source_desel_all); - } - o->end(); - } - { Fl_Group* o = new Fl_Group(230, 5, 230, 390); - { Fl_Button* o = dest_b = new Fl_Button(235, 5, 225, 25, "Select Install Destination ..."); - o->callback((Fl_Callback*)cb_dest_b); - } - dest_text = new Fl_Input(235, 35, 225, 25); - { Fl_Check_Browser* o = remove_box = new Fl_Check_Browser(235, 95, 225, 240, "Select Files to Remove"); - Fl_Group::current()->resizable(o); - } - { Fl_Button* o = remove_b = new Fl_Button(250, 360, 195, 35, "Remove Selected Files"); - o->labelfont(1); - o->callback((Fl_Callback*)cb_remove_b); - } - { Fl_Button* o = dest_sel_all = new Fl_Button(235, 65, 110, 25, "Select all"); - o->callback((Fl_Callback*)cb_dest_sel_all); - } - { Fl_Button* o = dest_desel_all = new Fl_Button(350, 65, 110, 25, "Deselect all"); - o->callback((Fl_Callback*)cb_dest_desel_all); - } - o->end(); - } - o->end(); - Fl_Group::current()->resizable(o); - } - o->end(); - } -} diff --git a/utils/fgadmin/src/fgadmin.fl b/utils/fgadmin/src/fgadmin.fl deleted file mode 100644 index c023ebad9..000000000 --- a/utils/fgadmin/src/fgadmin.fl +++ /dev/null @@ -1,136 +0,0 @@ -# data file for the Fltk User Interface Designer (fluid) -version 1.0106 -header_name {.h} -code_name {.cxx} -decl {\#include } {public -} - -decl {\#include } {public -} - -decl {\#include } {} - -decl {using std::string;} {public -} - -class FGAdminUI {open -} { - decl {\#include } {} - decl {using std::cout;} {} - decl {using std::endl;} {} - Function {FGAdminUI()} {open - } { - Fl_Window main_window { - label {FlightGear Admin Wizard} - callback {fl_alert("Use the Quit button to exit fgadmin");} open - xywh {500 247 465 435} type Double resizable visible - } { - Fl_Group {} {open - xywh {5 405 455 25} - } { - Fl_Button quit_b { - label Quit - callback {quit();} - xywh {375 405 85 25} - } - Fl_Progress progress { - xywh {5 405 365 25} color 49 selection_color 175 resizable - } - } - Fl_Group {} {open - xywh {5 5 460 390} resizable - } { - Fl_Group {} {open - xywh {5 5 225 390} - } { - Fl_Button source_b { - label {Select Scenery Source ...} - callback {select_install_source(); -refresh_lists();} - xywh {5 5 225 25} - } - Fl_Input source_text { - xywh {5 35 225 25} - } - Fl_Check_Browser install_box { - label {Select Files to Install} - xywh {5 95 225 240} resizable - } - Fl_Button install_b { - label {Install Selected Files} - callback {install_selected();} - xywh {20 360 195 35} labelfont 1 - } - Fl_Button source_sel_all { - label {Select all} - callback {install_box->check_all();} - xywh {5 65 110 25} - } - Fl_Button source_desel_all { - label {Deselect all} - callback {install_box->check_none();} - xywh {120 65 110 25} - } - } - Fl_Group {} {open - xywh {230 5 230 390} - } { - Fl_Button dest_b { - label {Select Install Destination ...} - callback {select_install_dest(); -refresh_lists();} - xywh {235 5 225 25} - } - Fl_Input dest_text { - xywh {235 35 225 25} - } - Fl_Check_Browser remove_box { - label {Select Files to Remove} - xywh {235 95 225 240} resizable - } - Fl_Button remove_b { - label {Remove Selected Files} - callback {remove_selected();} - xywh {250 360 195 35} labelfont 1 - } - Fl_Button dest_sel_all { - label {Select all} - callback {remove_box->check_all();} - xywh {235 65 110 25} - } - Fl_Button dest_desel_all { - label {Deselect all} - callback {remove_box->check_none();} selected - xywh {350 65 110 25} - } - } - } - } - } - decl {~FGAdminUI();} {public - } - decl {void init();} {public - } - decl {void show();} {public - } - decl {static void step( void * );} {public - } - decl {static void step( void *, int );} {public - } - decl {void refresh_lists();} {} - decl {void quit();} {} - decl {void select_install_source();} {} - decl {void select_install_dest();} {} - decl {void update_install_box();} {} - decl {void update_remove_box();} {} - decl {void install_selected();} {} - decl {void remove_selected();} {} - decl {void select_all_source();} {} - decl {void deselect_all_source();} {} - decl {void select_all_dest();} {} - decl {void deselect_all_dest();} {} - decl {Fl_Preferences *prefs;} {} - decl {string source;} {} - decl {string dest;} {} - decl {string progress_label;} {} -} diff --git a/utils/fgadmin/src/fgadmin.h b/utils/fgadmin/src/fgadmin.h deleted file mode 100644 index 798eebd2c..000000000 --- a/utils/fgadmin/src/fgadmin.h +++ /dev/null @@ -1,98 +0,0 @@ -// generated by Fast Light User Interface Designer (fluid) version 1.0106 - -#ifndef fgadmin_h -#define fgadmin_h -#include -using std::string; - -#include -#include -#include -#include -#include -#include -#include -#include - -class FGAdminUI { -public: - FGAdminUI(); - Fl_Double_Window *main_window; -private: - inline void cb_main_window_i(Fl_Double_Window*, void*); - static void cb_main_window(Fl_Double_Window*, void*); -public: - Fl_Button *quit_b; -private: - inline void cb_quit_b_i(Fl_Button*, void*); - static void cb_quit_b(Fl_Button*, void*); -public: - Fl_Progress *progress; - Fl_Button *source_b; -private: - inline void cb_source_b_i(Fl_Button*, void*); - static void cb_source_b(Fl_Button*, void*); -public: - Fl_Input *source_text; - Fl_Check_Browser *install_box; - Fl_Button *install_b; -private: - inline void cb_install_b_i(Fl_Button*, void*); - static void cb_install_b(Fl_Button*, void*); -public: - Fl_Button *source_sel_all; -private: - inline void cb_source_sel_all_i(Fl_Button*, void*); - static void cb_source_sel_all(Fl_Button*, void*); -public: - Fl_Button *source_desel_all; -private: - inline void cb_source_desel_all_i(Fl_Button*, void*); - static void cb_source_desel_all(Fl_Button*, void*); -public: - Fl_Button *dest_b; -private: - inline void cb_dest_b_i(Fl_Button*, void*); - static void cb_dest_b(Fl_Button*, void*); -public: - Fl_Input *dest_text; - Fl_Check_Browser *remove_box; - Fl_Button *remove_b; -private: - inline void cb_remove_b_i(Fl_Button*, void*); - static void cb_remove_b(Fl_Button*, void*); -public: - Fl_Button *dest_sel_all; -private: - inline void cb_dest_sel_all_i(Fl_Button*, void*); - static void cb_dest_sel_all(Fl_Button*, void*); -public: - Fl_Button *dest_desel_all; -private: - inline void cb_dest_desel_all_i(Fl_Button*, void*); - static void cb_dest_desel_all(Fl_Button*, void*); -public: - ~FGAdminUI(); - void init(); - void show(); - static void step( void * ); - static void step( void *, int ); -private: - void refresh_lists(); - void quit(); - void select_install_source(); - void select_install_dest(); - void update_install_box(); - void update_remove_box(); - void install_selected(); - void remove_selected(); - void select_all_source(); - void deselect_all_source(); - void select_all_dest(); - void deselect_all_dest(); - Fl_Preferences *prefs; - string source; - string dest; - string progress_label; -}; -#endif diff --git a/utils/fgadmin/src/fgadmin_funcs.cxx b/utils/fgadmin/src/fgadmin_funcs.cxx deleted file mode 100644 index 014e4bc70..000000000 --- a/utils/fgadmin/src/fgadmin_funcs.cxx +++ /dev/null @@ -1,447 +0,0 @@ -// fgadmin_funcs.cxx -- FG Admin UI functions. -// -// Written by Curtis Olson, started February 2004. -// -// Copyright (c) 2004 Curtis L. Olson - http://www.flightgear.org/~curt -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - - -#include -#include -#include -#include - -#ifdef _WIN32 -# include -# include -#define unlink _unlink -#define mkdir _mkdir -#else // !_WIN32 -#include -#endif - -#include - -#include - -#include "fgadmin.h" -#include "untarka.h" - -using std::cout; -using std::endl; -using std::set; -using std::string; - -extern string def_install_source; -extern string def_scenery_dest; - -static const float min_progress = 0.0; -static const float max_progress = 5000.0; - -// FIXME: Ugly hack to detect the situation below -#ifdef FL_Volume_Down -//#if (FL_MAJOR_VERSION > 1)||((FL_MAJOR_VERSION == 1)&&(FL_MINOR_VERSION >= 3)) - // Fltk 1.3 or newer, need to use "fl_filename_free_list" - #define FL_FREE_DIR_ENTRY(e) // do nothing, since "fl_filename_free_list" frees entire list - #define FL_FREE_DIR_LIST(list,count) fl_filename_free_list(&list, count) - #define FL_STAT(file,info) fl_stat( file.str().c_str(), info ) -#else - // Fltk < 1.3, "fl_filename_free_list", "fl_stat" not available - #define FL_FREE_DIR_ENTRY(e) free(e) - #define FL_FREE_DIR_LIST(list,count) free(list) - #define FL_STAT(file,info) stat( file.str().c_str(), info ); -#endif - -/** Strip a single trailing '/' or '\\' */ -static char* stripSlash(char* str) -{ - int l = strlen(str); - if ((l>0)&& - ((str[l-1]=='/')||(str[l-1]=='\\'))) - { - str[l-1] = 0; - } - return str; -} - -// destructor -FGAdminUI::~FGAdminUI() { - delete prefs; -} - - -// initialize additional class elements -void FGAdminUI::init() { - prefs = new Fl_Preferences( Fl_Preferences::USER, - "flightgear.org", - "fgadmin" ); - char buf[FL_PATH_MAX]; - prefs->get( "install-source", buf, def_install_source.c_str(), FL_PATH_MAX ); - source_text->value( buf ); - source = buf; - - prefs->get( "scenery-dest", buf, def_scenery_dest.c_str(), FL_PATH_MAX ); - dest_text->value( buf ); - dest = buf; - - refresh_lists(); - - progress->minimum( min_progress ); - progress->maximum( max_progress ); - - main_window->size_range( 465, 435 ); -} - -// show our UI -void FGAdminUI::show() { - main_window->show(); -} - - -// refresh the check box lists -void FGAdminUI::refresh_lists() { - update_install_box(); - update_remove_box(); -} - - -// scan the source directory and update the install_box contents -// quit -void FGAdminUI::quit() { - main_window->hide(); -} - - -// select the install source -void FGAdminUI::select_install_source() { - char* p = fl_dir_chooser( "Select Scenery Source Directory", - source.c_str(), - 0 ); - if ( p != 0 ) { - source = p; - source_text->value( p ); - prefs->set( "install-source", p ); - prefs->flush(); - } -} - - -// select the install source -void FGAdminUI::select_install_dest() { - char* p = fl_dir_chooser( "Select Scenery Install Directory", - dest.c_str(), - 0 ); - if ( p != 0 ) { - dest = p; - dest_text->value( p ); - prefs->set( "scenery-dest", p ); - prefs->flush(); - } -} - -#if 0 -// Like strcmp, but for strings -static int stringCompare(const void *string1, const void *string2) -{ - const string *s1 = (const string *)string1; - const string *s2 = (const string *)string2; - - // Compare name first, and then index. - return strcmp(s1->c_str(), s2->c_str()); -} -#endif - -void FGAdminUI::update_install_box() { - set file_list; - - install_box->clear(); - - if ( source.length() ) { - struct dirent **list; - int nb = fl_filename_list( source.c_str(), &list ); - for ( int i = 0; i < nb; ++i ) { - // find base name of archive file - char base[FL_PATH_MAX]; - dirent *ent = list[i]; - stripSlash(ent->d_name); - strncpy( base, ent->d_name, FL_PATH_MAX ); - const char *p = fl_filename_ext( base ); - int offset; - string::size_type expected_length = 0; - if ( strcmp( p, ".gz" ) == 0 ) { - offset = p - base; - base[offset] = '\0'; - p = fl_filename_ext( base ); - if ( strcmp( p, ".tar" ) == 0 ) { - offset = p - base; - base[offset] = '\0'; - expected_length = 14; - } - } else if ( strcmp( p, ".tgz" ) == 0 ) { - offset = p - base; - base[offset] = '\0'; - expected_length = 11; - } else if ( strcmp( p, ".zip" ) == 0 ) { - offset = p - base; - base[offset] = '\0'; - expected_length = 11; - } - - if ( strlen(ent->d_name) != expected_length ) { - // simple heuristic to ignore non-scenery files - } else if ( ent->d_name[0] != 'e' && ent->d_name[0] != 'w' ) { - // further sanity checks on name - } else if ( ent->d_name[4] != 'n' && ent->d_name[4] != 's' ) { - // further sanity checks on name - } else { - // add to list if not installed - SGPath install( dest ); - install.append( base ); - if ( ! fl_filename_isdir( install.c_str() ) ) { - // cout << install.str() << " install candidate." << endl; - file_list.insert( ent->d_name ); - } else { - // cout << install.str() << " exists." << endl; - } - } - FL_FREE_DIR_ENTRY(ent); - } - FL_FREE_DIR_LIST(list, nb); - - for ( set::iterator it = file_list.begin(); it != file_list.end(); ++it ) { - install_box->add( it->c_str() ); - } - - install_box->redraw(); - } -} - - -// scan the source directory and update the install_box contents -void FGAdminUI::update_remove_box() { - - remove_box->clear(); - - if ( dest.length() ) { - string path[2]; - path[0] = dest + "/Terrain"; - path[1] = dest + "/Objects"; - if ( !fl_filename_isdir( path[0].c_str() ) ) { - path[0] = dest; - path[1] = ""; - } else if ( !fl_filename_isdir( path[1].c_str() ) ) { - path[1] = ""; - } - - set dir_list; - for ( int i = 0; i < 2; i++ ) { - if ( !path[i].empty() ) { - dirent **list; - int nb = fl_filename_list( path[i].c_str(), &list ); - for ( int i = 0; i < nb; ++i ) { - dirent *ent = list[i]; - stripSlash(ent->d_name); - if ( strlen(ent->d_name) == 7 && - ( ent->d_name[0] == 'e' || ent->d_name[0] == 'w' ) && - ( ent->d_name[4] == 'n' || ent->d_name[4] == 's' ) ) { - dir_list.insert( ent->d_name ); - } - FL_FREE_DIR_ENTRY(ent); - } - FL_FREE_DIR_LIST(list, nb); - } - } - - for ( set::iterator it = dir_list.begin(); it != dir_list.end(); ++it ) { - remove_box->add( it->c_str() ); - } - - remove_box->redraw(); - } -} - - -// install selected files -void FGAdminUI::install_selected() { - char *f; - - install_b->deactivate(); - remove_b->deactivate(); - quit_b->deactivate(); - - // traverse install box and install each item - for ( int i = 0; i <= install_box->nitems(); ++i ) { - if ( install_box->checked( i ) ) { - f = install_box->text( i ); - SGPath file( source ); - file.append( f ); - struct ::stat info; - FL_STAT( file, &info ); - float old_max = progress->maximum(); - progress->maximum( info.st_size ); - progress_label = "Installing "; - progress_label += f; - progress->label( progress_label.c_str() ); - progress->value( min_progress ); - main_window->cursor( FL_CURSOR_WAIT ); - tarextract( (char *)file.c_str(), (char *)dest.c_str(), true, &FGAdminUI::step, this ); - progress->value( min_progress ); - main_window->cursor( FL_CURSOR_DEFAULT ); - progress->label( "" ); - progress->maximum( old_max ); - } - } - quit_b->activate(); - install_b->activate(); - remove_b->activate(); - - refresh_lists(); -} - - -static unsigned long count_dir( const char *dir_name, bool top = true ) { - unsigned long cnt = 0L; - dirent **list; - int nb = fl_filename_list( dir_name, &list ); - if ( nb != 0 ) { - for ( int i = 0; i < nb; ++i ) { - dirent *ent = list[i]; - stripSlash(ent->d_name); - if ( strcmp( ent->d_name, "." ) == 0 ) { - // ignore "." - } else if ( strcmp( ent->d_name, ".." ) == 0 ) { - // ignore ".." - } else if ( fl_filename_isdir( ent->d_name ) ) { - SGPath child( dir_name ); - child.append( ent->d_name ); - cnt += count_dir( child.c_str(), false ); - } else { - cnt += 1; - } - FL_FREE_DIR_ENTRY(ent); - } - FL_FREE_DIR_LIST(list, nb); - } else if ( top ) { - string base = dir_name; - size_t pos = base.rfind('/'); - string file = base.substr( pos ); - base.erase( pos ); - string path = base + "/Terrain" + file; - cnt = count_dir( path.c_str(), false ); - path = base + "/Objects" + file; - cnt += count_dir( path.c_str(), false ); - } - return cnt; -} - -static void remove_dir( const char *dir_name, void (*step)(void*,int), void *data, bool top = true ) { - dirent **list; - int nb = fl_filename_list( dir_name, &list ); - if ( nb > 0 ) { - for ( int i = 0; i < nb; ++i ) { - dirent *ent = list[i]; - SGPath child( dir_name ); - child.append( ent->d_name ); - stripSlash(ent->d_name); - if ( strcmp( ent->d_name, "." ) == 0 ) { - // ignore "." - } else if ( strcmp( ent->d_name, ".." ) == 0 ) { - // ignore ".." - } else if ( child.isDir() ) { - remove_dir( child.c_str(), step, data, false ); - } else { - unlink( child.c_str() ); - if (step) step( data, 1 ); - } - FL_FREE_DIR_ENTRY(ent); - } - FL_FREE_DIR_LIST(list, nb); - rmdir( dir_name ); - } else if ( top ) { - string base = dir_name; - size_t pos = base.rfind('/'); - string file = base.substr( pos ); - base.erase( pos ); - string path = base + "/Terrain" + file; - remove_dir( path.c_str(), step, data, false ); - path = base + "/Objects" + file; - remove_dir( path.c_str(), step, data, false ); - } -} - - -// remove selected files -void FGAdminUI::remove_selected() { - char *f; - - install_b->deactivate(); - remove_b->deactivate(); - quit_b->deactivate(); - // traverse remove box and recursively remove each item - for ( int i = 0; i <= remove_box->nitems(); ++i ) { - if ( remove_box->checked( i ) ) { - f = remove_box->text( i ); - SGPath dir( dest ); - dir.append( f ); - float old_max = progress->maximum(); - progress_label = "Removing "; - progress_label += f; - progress->label( progress_label.c_str() ); - progress->value( min_progress ); - main_window->cursor( FL_CURSOR_WAIT ); - progress->maximum( count_dir( dir.c_str() ) ); - remove_dir( dir.c_str(), &FGAdminUI::step, this ); - progress->value( min_progress ); - main_window->cursor( FL_CURSOR_DEFAULT ); - progress->label( "" ); - progress->maximum( old_max ); - } - } - quit_b->activate(); - install_b->activate(); - remove_b->activate(); - - refresh_lists(); - -} - -void FGAdminUI::step(void *data) -{ - Fl_Progress *p = ((FGAdminUI*)data)->progress; - - // we don't actually know the total work in advanced due to the - // nature of tar archives, and it would be inefficient to prescan - // the files, so just cycle the progress bar until we are done. - float tmp = p->value() + 1; - if ( tmp > max_progress ) { - tmp = 0.0; - } - p->value( tmp ); - - Fl::check(); -} - -void FGAdminUI::step(void *data, int n) -{ - Fl_Progress *p = ((FGAdminUI*)data)->progress; - - float tmp = p->value() + n; - p->value( tmp ); - - Fl::check(); -} diff --git a/utils/fgadmin/src/main.cxx b/utils/fgadmin/src/main.cxx deleted file mode 100644 index 4814fd72c..000000000 --- a/utils/fgadmin/src/main.cxx +++ /dev/null @@ -1,91 +0,0 @@ -// main.cxx -- FlightGear Scenery/Aircraft Admin Tool -// -// Written by Curtis Olson, started February 2004. -// -// Copyright (c) 2004 Curtis L. Olson - http://www.flightgear.org/~curt -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -#include -#include -#include -#include -#include "fgadmin.h" - -std::string def_install_source; -std::string def_scenery_dest; -bool silent = false; - -/** - * --silent - * --install-source= - * --scenery-dest= - */ -static int -parse_args( int, char** argv, int& i ) -{ - if (strcmp( argv[i], "--silent" ) == 0) - { - silent = true; - ++i; - return 1; - } - else if (strncmp( argv[i], "--install-source=", 17 ) == 0) - { - def_install_source.assign( &argv[i][17] ); - ++i; - return 1; - } - else if (strncmp( argv[i], "--scenery-dest=", 15 ) == 0) - { - def_scenery_dest.assign( &argv[i][15] ); - ++i; - return 1; - } - - return 0; -} - -int -main( int argc, char* argv[] ) -{ - int i = 0; - if (Fl::args( argc, argv, i, parse_args ) < argc) - { - Fl::fatal("Options are:\n --silent\n --install-source=\n --scenery-dest=\n%s", Fl::help ); - } - - if ( silent ) - { - Fl_Preferences prefs( Fl_Preferences::USER, "flightgear.org", "fgadmin" ); - char abs_name[ FL_PATH_MAX ]; - - fl_filename_absolute( abs_name, def_install_source.c_str() ); - prefs.set( "install-source", abs_name ); - - fl_filename_absolute( abs_name, def_scenery_dest.c_str() ); - prefs.set( "scenery-dest", abs_name ); - - return 0; - } - - FGAdminUI ui; - ui.init(); - ui.show(); - - return Fl::run(); -} diff --git a/utils/fgadmin/src/untarka.c b/utils/fgadmin/src/untarka.c deleted file mode 100644 index 4e393f398..000000000 --- a/utils/fgadmin/src/untarka.c +++ /dev/null @@ -1,1472 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config_fgadmin.h" -#endif - -#define DUMMY \ - WFLAGS="-ansi -pedantic -W -Wall -Wstrict-prototypes -Wtraditional -Wnested-externs -Winline -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wmissing-prototypes -Wmissing-declarations -Wunused"; \ - set -ex; \ - gcc -s -O2 $WFLAGS -DHAVE_ZLIB -DHAVE_BZ2LIB untarka.c -o untarka -lz -lbz2; \ - exit 0 -/* - * untarka.c -- Display contents and/or extract file from a tar file (possibly - * gzip'd, bzip'd or compress'd) - * by pts@fazekas.hu Wed Jan 29 00:38:31 CET 2003 - * Z compiles fine at Wed Jan 29 14:20:32 CET 2003 - * all run file at Wed Jan 29 15:50:39 CET 2003 - * 0.34 Win32 runs fine at Wed Jan 29 16:02:57 GMT 2003 - * - * Untarka extracts TAR (UNIX Tape ARchive) files without calling any - * external programs. It supports and autodetects multiple compression - * methods (.tar, .tar.Z, .tar.gz, .tar.bz2, .Z, .gz and .bz2). UNIX - * devices, sockets, hard links, symlinks, owners and permissions are - * ignored during extraction. - * - * written by "Pedro A. Aranda Guti\irrez" - * adaptation to Unix by Jean-loup Gailly - * adaptation to bzip2 by José Fonseca - * merged comressors by Szabó Péter at Tue Jan 28 23:40:23 CET 2003 - * compiles on Win32 under MinGW, Linux with gcc. - * - * To get gzip (zlib) support, pass to gcc: -DHAVE_ZLIB -lz - * To get bzip2 (bzlib2) support, pass to gcc: -DHAVE_BZ2LIB -lbz2 - * To get compress (lz) support, relax, since it's the default. - * - * Compile memory-checking with checkergcc -g -ansi -pedantic -W -Wall -Wstrict-prototypes -Wtraditional -Wnested-externs -Winline -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wmissing-prototypes -Wmissing-declarations -Wunused untarka.c -o untarka - */ -/* Imp: symlink() - * Imp: mknod() device, socket - * Imp: hard link() - * Imp: chmod() - * Imp: chown() - * Imp: allow force non-tar gzipped file - * Imp: command line options - * Imp: uncompress ZIP files - * Dat: zlib is able to read uncompressed files, libbz2 isn't - * Dat: magic numbers: - * 257 string ustar\0 POSIX tar archive - * 257 string ustar\040\040\0 GNU tar archive - * 0 string BZh bzip2 compressed data - * 0 string \037\213 gzip compressed data - * 0 string \037\235 compress'd data - * is_tar.c() from file(1) - */ - -#undef DOSISH -#ifdef WIN32 -# include -# define DOSISH 1 -# undef __STRICT_ANSI__ -#endif -#ifdef MSDOS -# define DOSISH 1 -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef DOSISH -# include -# include -#else -# include -#endif - -#if DOSISH -# ifndef F_OK -# define F_OK (0) -# endif -# ifdef _MSC_VER -# define mkdir(dirname,mode) _mkdir(dirname) -# define unlink(fn) _unlink(fn) -# define access(path,mode) _access(path,mode) -# else -# define mkdir(dirname,mode) _mkdir(dirname) -# endif -#else -# include -# include /* mkdir() */ -#endif - -#ifndef OF /* function prototypes */ -# if defined(__STDC__) || defined(__PROTOTYPES__) || defined(__cplusplus) -# define OF(args) args -# else -# define OF(args) args -# endif -#endif - -#include "untarka.h" - -static void error OF((const char *msg)); - -static unsigned long total_read; - -/* #define TAR_GZ 1 */ - -typedef struct Readable { - /*private*/ void *f; - /** @return 0 on success, 1 on failure */ - int (*xOpen4Read)(struct Readable* self, char const* filename); - /** @return 0 on success */ - int (*xClose)(struct Readable* self); - /** @return (unsigned)-1 on error */ - unsigned (*xRead)(struct Readable* self, void* buf, unsigned len); - char const* (*xError)(struct Readable* self, int *errnum_ret); -} Readable; - -enum { FMT_U=1, FMT_Z=2, FMT_GZ=3, FMT_BZ2=4 }; - -/* #define xFILE FILE* */ -static int xU_Open4Read(struct Readable* self, char const* filename) { total_read=0; return NULL==(self->f=fopen(filename,"rb")); } -static int xU_Close(struct Readable* self) { return fclose((FILE*)self->f); } -static unsigned xU_Read(struct Readable* self, void* buf, unsigned len) { - unsigned got=fread(buf,1,len,(FILE*)self->f); - total_read+=got; - return got>0 ? got : ferror((FILE*)self->f) ? 0U-1 : 0; -} -static char const* xU_Error(struct Readable* self, int *errnum_ret) { return (*errnum_ret=ferror((FILE*)self->f))?"I/O error":"OK"; } - -/* #define xFILE struct lz_reader_t* */ -struct lz_reader_t; -static struct lz_reader_t* lz_read_new(FILE* inf); -static int lz_read_init(struct lz_reader_t* reader, FILE* inf); -static int lz_close(struct lz_reader_t* reader); -static unsigned lz_read(struct lz_reader_t* reader, char*buf, unsigned len); - -static int xZ_Open4Read(struct Readable* self, char const* filename) { - FILE *f=fopen(filename,"rb"); - if (NULL==f) return 1; - return NULL==(self->f=lz_read_new(f)); -} -static int xZ_Close(struct Readable* self) { - int ret=lz_close((struct lz_reader_t*)self->f); - free((struct lz_reader_t*)self->f); - return ret; -} -static unsigned xZ_Read(struct Readable* self, void* buf, unsigned len) { - return lz_read((struct lz_reader_t*)self->f, buf, len); -} -static char const* xZ_Error(struct Readable* self, int *errnum_ret) { - (void)self; - *errnum_ret=0; - return "lzw error"; -} - -#ifdef HAVE_ZLIB -#include "zlib.h" -/* #define xFILE gzFile */ -static int xGZ_Open4Read(struct Readable* self, char const* filename) { total_read=0; return NULL==(self->f=gzopen(filename,"rb")); } -static int xGZ_Close(struct Readable* self) { return gzclose((gzFile)self->f); } -static unsigned xGZ_Read(struct Readable* self, void* buf, unsigned len) { unsigned l=gzread((gzFile)self->f,buf,len); total_read=((z_streamp)self->f)->total_in; return l; } -static char const* xGZ_Error(struct Readable* self, int *errnum_ret) { return gzerror((gzFile)self->f, errnum_ret); } -#endif - -#ifdef HAVE_BZ2LIB -#include "bzlib.h" -/* #define xFILE BZFILE* */ -static int xBZ2_Open4Read(struct Readable* self, char const* filename) { return NULL==(self->f=BZ2_bzopen(filename,"rb")); } -static int xBZ2_Close(struct Readable* self) { BZ2_bzclose((BZFILE*)self->f); return 0; } -static unsigned xBZ2_Read(struct Readable* self, void* buf, unsigned len) { return BZ2_bzread((BZFILE*)self->f,buf,len); } -static char const* xBZ2_Error(struct Readable* self, int *errnum_ret) { return BZ2_bzerror((BZFILE*)self->f, errnum_ret); } -#endif - -/* -- is_tar() */ - -/* - * is_tar() -- figure out whether file is a tar archive. - * - * Stolen (by the author!) from the public domain tar program: - * Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu). - * - * @(#)list.c 1.18 9/23/86 Public Domain - gnu - * $Id$ - * - * Comments changed and some code/comments reformatted - * for file command by Ian Darwin. - */ - -/* The magic field is filled with this if uname and gname are valid. */ -#define TMAGIC "ustar " /* 7 chars and a null */ - -/* - * Header block on tape. - * - * I'm going to use traditional DP naming conventions here. - * A "block" is a big chunk of stuff that we do I/O on. - * A "record" is a piece of info that we care about. - * Typically many "record"s fit into a "block". - */ -#define RECORDSIZE 512 -#define NAMSIZ 100 -#define TUNMLEN 32 -#define TGNMLEN 32 - -union tar_record { - char charptr[RECORDSIZE]; - struct header { - char name[NAMSIZ]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char chksum[8]; - char linkflag; - char linkname[NAMSIZ]; - char magic[8]; - char uname[TUNMLEN]; - char gname[TGNMLEN]; - char devmajor[8]; - char devminor[8]; - } header; -}; - -#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') ) - -static int from_oct(int, char *); /* Decode octal number */ - -/* - * Return - * 0 if the checksum is bad (i.e., probably not a tar archive), - * 1 for old UNIX tar file, - * 2 for Unix Std (POSIX) tar file. - */ -static int -is_tar(char *buf, unsigned nbytes) -{ - union tar_record *header = (union tar_record *)buf; - int i; - int sum, recsum; - char *p; - - if (nbytes < sizeof(union tar_record)) - return 0; - - recsum = from_oct(8, header->header.chksum); - - sum = 0; - p = header->charptr; - for (i = sizeof(union tar_record); --i >= 0;) { - /* - * We can't use unsigned char here because of old compilers, - * e.g. V7. - */ - sum += 0xFF & *p++; - } - - /* Adjust checksum to count the "chksum" field as blanks. */ - for (i = sizeof(header->header.chksum); --i >= 0;) - sum -= 0xFF & header->header.chksum[i]; - sum += ' '* sizeof header->header.chksum; - - if (sum != recsum) - return 0; /* Not a tar archive */ - - if (0==strcmp(header->header.magic, TMAGIC)) - return 2; /* Unix Standard tar archive */ - - return 1; /* Old fashioned tar archive */ -} - - -/* - * Quick and dirty octal conversion. - * - * Result is -1 if the field is invalid (all blank, or nonoctal). - */ -static int -from_oct(int digs, char *where) -{ - int value; - - while (*where==' ' || *where=='\f' || *where=='\n' || *where=='\r' || *where=='\t' || *where=='\v') { - where++; - if (--digs <= 0) - return -1; /* All blank field */ - } - value = 0; - while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */ - value = (value << 3) | (*where++ - '0'); - --digs; - } - - if (digs > 0 && *where!='\0' && *where!=' ' && *where!='\f' && *where!='\n' && *where!='\r' && *where!='\t' && *where!='\v') - return -1; /* Ended on non-space/nul */ - - return value; -} - - -/* --- */ - -/** Constructor. - * @return 0 on success, positive for various failure reasons - */ -static int xOpen4Read(struct Readable *self, char const* filename) { - unsigned i; - char buf[RECORDSIZE]; - FILE *f=fopen(filename, "rb"); - if (f==NULL) return 4; - i=sizeof(buf); while (i--!=0) buf[i]='\0'; - if (5>fread(buf, 1, sizeof(buf), f)) return 2; - if (0) { - } else if (buf[0]==0102 && buf[1]==0132 && buf[2]==0150) { -#ifdef HAVE_BZ2LIB - fclose(f); - self->xOpen4Read=xBZ2_Open4Read; - self->xClose=xBZ2_Close; - self->xRead=xBZ2_Read; - self->xError=xBZ2_Error; - if (xBZ2_Open4Read(self, filename)!=0) return 1; -#else - error("bzip2 compression not compiled in"); -#endif - } else if (buf[0]==0037 && (buf[1]&255)==0213 && (buf[2]&255)<=8) { -#ifdef HAVE_ZLIB - fclose(f); - self->xOpen4Read=xGZ_Open4Read; - self->xClose=xGZ_Close; - self->xRead=xGZ_Read; - self->xError=xGZ_Error; - if (xGZ_Open4Read(self, filename)!=0) return 1; -#else - error("gzip compression not compiled in"); -#endif - } else if (buf[0]==0037 && (buf[1]&255)==0235) { - fclose(f); - self->xOpen4Read=xZ_Open4Read; - self->xClose=xZ_Close; - self->xRead=xZ_Read; - self->xError=xZ_Error; - if (xZ_Open4Read(self, filename)!=0) return 1; - } else if ((buf[257]==0165 && buf[258]==0163 && buf[259]==0164 - && buf[260]==0141 && buf[261]==0162 - && (buf[262]==0000 || (buf[262]==0040 && buf[263]==0040 && buf[264]==0)) - ) || is_tar(buf, sizeof(buf)) - ) { - rewind(f); - self->f=f; /* shortcut */ - self->xOpen4Read=xU_Open4Read; - self->xClose=xU_Close; - self->xRead=xU_Read; - self->xError=xU_Error; - } else return 3; - return 0; -} - -/* --- .Z LZ uncompression */ - -/* code derived from - * (N)compress42.c - File compression ala IEEE Computer, Mar 1992. - * Modified by pts@fazekas.hu at Wed Jul 18 17:25:38 CEST 2001. - * - * Authors: - * Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) - * Jim McKie (decvax!mcvax!jim) - * Steve Davies (decvax!vax135!petsd!peora!srd) - * Ken Turkowski (decvax!decwrl!turtlevax!ken) - * James A. Woods (decvax!ihnp4!ames!jaw) - * Joe Orost (decvax!vax135!petsd!joe) - * Dave Mack (csu@alembic.acs.com) - * Peter Jannesen, Network Communication Systems - * (peter@ncs.nl) - * - * Revision 4.2.3 92/03/14 peter@ncs.nl - * Optimise compress and decompress function and a lot of cleanups. - * New fast hash algoritme added (if more than 800Kb available). - */ -#define IBUFSIZ 4096 - -#define NOFUNCDEF -#undef DOS -#undef COMPATIBLE -#undef DONTPTS /* `#define DONTPTS 1' means original uncompress */ -#undef DIRENT -#undef RECURSIVE -#undef SYSDIR -#undef UTIME_H -#undef BYTEORDER -#define BITS 16 /* _must_ be able to handle this many bits, anyway */ -#define FAST -#if 1 /* !! */ -# define ASSERT(x) do { if (!(x)) abort(); } while(0) -#else -# define ASSERT(x) -#endif - -#include -#include /* memcpy(), memset() */ -#include /* abort(), exit() */ - -/* #define fx_write(a,b,c) fwrite((b),1,(c),(a)) */ -#define fx_read(a,b,c) fread( (b),1,(c),(a)) -#define fx_stdin stdin -#define fx_stdout stdout -#define fx_type FILE* - -#ifndef NOFUNCDEF -#define LARGS(a) () /* Relay on include files for libary func defs. */ - extern void *malloc LARGS((int)); - extern void free LARGS((void *)); -#ifndef _IBMR2 - extern int open LARGS((char const *,int,...)); -#endif - extern int close LARGS((int)); - extern int read LARGS((int,void *,int)); - extern int write LARGS((int,void const *,int)); - extern int chmod LARGS((char const *,int)); - extern int unlink LARGS((char const *)); - extern int chown LARGS((char const *,int,int)); - extern int utime LARGS((char const *,struct utimbuf const *)); - extern char *strcpy LARGS((char *,char const *)); - extern char *strcat LARGS((char *,char const *)); - extern int strcmp LARGS((char const *,char const *)); - extern unsigned strlen LARGS((char const *)); - extern void *memset LARGS((void *,char,unsigned int)); - extern void *memcpy LARGS((void *,void const *,unsigned int)); - extern int atoi LARGS((char const *)); - extern void exit LARGS((int)); - extern int isatty LARGS((int)); -#endif - -#ifdef DEF_ERRNO - extern int errno; -#endif - -#undef min -#define min(a,b) ((a>b) ? b : a) - -#define MAGIC_1 (char_type)'\037'/* First byte of compressed file */ -#define MAGIC_2 (char_type)'\235'/* Second byte of compressed file */ -#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */ - /* Masks 0x20 and 0x40 are free. */ - /* I think 0x20 should mean that there is */ - /* a fourth header byte (for expansion). */ -#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */ - /* compression rate is dropping flush tables */ - - /* the next two codes should not be changed lightly, as they must not */ - /* lie within the contiguous general code space. */ -#define FIRST 257 /* first free entry */ -#define CLEAR 256 /* table clear output code */ - -#define INIT_BITS 9 /* initial number of bits/code */ - -#ifndef BYTEORDER -# define BYTEORDER 0000 -#endif - -#ifndef NOALLIGN -# define NOALLIGN 0 -#endif - -/* - * machine variants which require cc -Dmachine: pdp11, z8000, DOS - */ - -#ifdef interdata /* Perkin-Elmer */ -# define SIGNED_COMPARE_SLOW /* signed compare is slower than unsigned */ -#endif - -#ifdef MSDOS /* PC/XT/AT (8088) processor */ -# undef BYTEORDER -# define BYTEORDER 4321 -# undef NOALLIGN -# define NOALLIGN 1 -#endif /* DOS */ - -#ifndef O_BINARY -# define O_BINARY 0 /* System has no binary mode */ -#endif - -typedef long int code_int; - -#ifdef SIGNED_COMPARE_SLOW - typedef unsigned short int count_short; - typedef unsigned long int cmp_code_int; /* Cast to make compare faster */ -#else - typedef long int cmp_code_int; -#endif - -typedef unsigned char char_type; - -#define MAXCODE(n) (1L << (n)) - -#ifndef REGISTERS -# define REGISTERS 20 -#endif -#define REG1 -#define REG2 -#define REG3 -#define REG4 -#define REG5 -#define REG6 -#define REG7 -#define REG8 -#define REG9 -#define REG10 -#define REG11 -#define REG12 -#define REG13 -#define REG14 -#define REG15 -#define REG16 -#if REGISTERS >= 1 -# undef REG1 -# define REG1 register -#endif -#if REGISTERS >= 2 -# undef REG2 -# define REG2 register -#endif -#if REGISTERS >= 3 -# undef REG3 -# define REG3 register -#endif -#if REGISTERS >= 4 -# undef REG4 -# define REG4 register -#endif -#if REGISTERS >= 5 -# undef REG5 -# define REG5 register -#endif -#if REGISTERS >= 6 -# undef REG6 -# define REG6 register -#endif -#if REGISTERS >= 7 -# undef REG7 -# define REG7 register -#endif -#if REGISTERS >= 8 -# undef REG8 -# define REG8 register -#endif -#if REGISTERS >= 9 -# undef REG9 -# define REG9 register -#endif -#if REGISTERS >= 10 -# undef REG10 -# define REG10 register -#endif -#if REGISTERS >= 11 -# undef REG11 -# define REG11 register -#endif -#if REGISTERS >= 12 -# undef REG12 -# define REG12 register -#endif -#if REGISTERS >= 13 -# undef REG13 -# define REG13 register -#endif -#if REGISTERS >= 14 -# undef REG14 -# define REG14 register -#endif -#if REGISTERS >= 15 -# undef REG15 -# define REG15 register -#endif -#if REGISTERS >= 16 -# undef REG16 -# define REG16 register -#endif - -#if BYTEORDER == 4321 && NOALLIGN == 1 -#define input(b,o,c,n,m){ \ - (c) = (*(long *)(&(b)[(o)>>3])>>((o)&0x7))&(m); \ - (o) += (n); \ - } -#else -#define input(b,o,c,n,m){ REG1 char_type *p = &(b)[(o)>>3]; \ - (c) = ((((long)(p[0]))|((long)(p[1])<<8)| \ - ((long)(p[2])<<16))>>((o)&0x7))&(m); \ - (o) += (n); \ - } -#endif - -/* - * 8086 & 80286 Has a problem with array bigger than 64K so fake the array - * For processors with a limited address space and segments. - */ -/* - * To save much memory, we overlay the table used by compress() with those - * used by lz_decompress(). The tab_prefix table is the same size and type - * as the codetab. The tab_suffix table needs 2**BITS characters. We - * get this from the beginning of htab. The output stack uses the rest - * of htab, and contains characters. There is plenty of room for any - * possible stack (stack used to be 8000 characters). - */ -#ifdef MAXSEG_64K - #error removed MAXSEG_64K -#else /* Normal machine */ -# define HSIZE (1<<16) /* (1<<15) is few, (1<<16) seems to be OK, (1<<17) is proven safe OK */ -#if 0 - char_type lz_htab[2*HSIZE]; /* Dat: HSIZE for the codes and HSIZE for de_stack */ - unsigned short lz_codetab[HSIZE]; -#endif -# define tab_prefixof(i) codetab[i] -# define tab_suffixof(i) htab[i] -# define de_stack (htab+(sizeof(htab[0])*(2*HSIZE-1))) -# define clear_tab_prefixof() memset(codetab, 0, 256*sizeof(codetab[0])); -#endif /* MAXSEG_64K */ - -typedef struct lz_reader_t { - /* constants (don't change during decompression) */ - fx_type fdin; - char_type* inbuf; /* [IBUFSIZ+64]; Input buffer */ - char_type* htab; /* [2*HSIZE]; Dat: HSIZE for the codes and HSIZE for de_stack */ - unsigned short* codetab; /* [HSIZE]; */ - int blkmode; - code_int maycode; - - /* variables that have to be saved */ - char_type *stackp; - code_int code; - int finchar; - code_int oldcode; - code_int incode; - int inbits; - int posbits; - int insize; - int bitmask; - code_int freeent; - code_int maxcode; - int n_bits; - int rsize; - int maxbits; -} lz_reader_t; - -static struct lz_reader_t* lz_read_new(FILE *inf) { - lz_reader_t* reader=(lz_reader_t*)malloc(sizeof(lz_reader_t)); - reader->fdin=NULL; - if (reader!=NULL) { - if (lz_read_init(reader, inf)!=0) { - lz_close(reader); - free(reader); reader=NULL; - } - } - return reader; -} -static int lz_close(struct lz_reader_t* reader) { - FILE *fin=reader->fdin; - reader->rsize=-1; - if (reader->inbuf!=NULL) { free(reader->inbuf ); reader->inbuf =NULL; } - if (reader->htab!=NULL) { free(reader->htab ); reader->htab =NULL; } - if (reader->codetab!=NULL) { free(reader->codetab); reader->codetab=NULL; } - if (fin==NULL) return 0; - reader->fdin=NULL; - return fclose(fin); -} -/** @param Zreader uninitialized - * @return 0 on success - */ -static int lz_read_init(struct lz_reader_t* reader, FILE *inf) { - char_type* htab; - unsigned short* codetab; - code_int codex; - reader->fdin=inf; - if (NULL==(reader->inbuf=malloc(IBUFSIZ+67))) return 1; - if (NULL==(htab=reader->htab=malloc(2*HSIZE))) return 1; /* Dat: HSIZE for the codes and HSIZE for de_stack */ - if (NULL==(codetab=reader->codetab=malloc(sizeof(reader->codetab[0])*HSIZE))) return 1; - reader->insize=0; - reader->rsize=0; - while (reader->insize < 3 && (reader->rsize = fx_read(reader->fdin, reader->inbuf+reader->insize, IBUFSIZ)) > 0) - reader->insize += reader->rsize; - - if (reader->insize < 3 - || reader->inbuf[0] != (char_type)'\037' /* First byte of compressed file */ - || reader->inbuf[1] != (char_type)'\235' /* Second byte of compressed file */ - ) return reader->insize >= 0 ? 2 : 3; - - reader->maxbits = reader->inbuf[2] & BIT_MASK; - reader->blkmode = reader->inbuf[2] & BLOCK_MODE; - reader->maycode = MAXCODE(reader->maxbits); - - if (reader->maxbits > BITS) return 4; -#if 0 - fprintf(stderr, - "%s: compressed with %d bits, can only handle %d bits\n", - ("stdin"), maxbits, BITS); - return 4; -#endif - - reader->maxcode = MAXCODE(reader->n_bits = INIT_BITS)-1; - reader->bitmask = (1<n_bits)-1; - reader->oldcode = -1; - reader->finchar = 0; - reader->posbits = 3<<3; - reader->stackp = NULL; - reader->code = -1; - reader->incode = -1; /* fake */ - reader->inbits = 0; /* fake */ - - reader->freeent = ((reader->blkmode) ? FIRST : 256); - - clear_tab_prefixof(); /* As above, initialize the first 256 entries in the table. */ - - for (codex = 255 ; codex >= 0 ; --codex) - tab_suffixof(codex) = (char_type)codex; - return 0; /* success */ -} - -/* - * Decompress stdin to stdout. This routine adapts to the codes in the - * file building the "string" table on-the-fly; requiring no table to - * be stored in the compressed file. The tables used herein are shared - * with those of the compress() routine. See the definitions above. - */ -static unsigned lz_read(struct lz_reader_t* reader, char* outbuf, unsigned obufsize) { -/* static int lz_decompress(fx_type fdin, fx_type fdout) */ - REG2 char_type *stackp; - REG3 code_int code; - REG4 int finchar; - REG5 code_int oldcode; - REG6 code_int incode; - REG7 int inbits; - REG8 int posbits; - REG10 int insize; - REG11 int bitmask; - REG12 code_int freeent; - REG13 code_int maxcode; - REG14 code_int maycode; - REG15 int n_bits; - REG16 int rsize; - int blkmode; - int maxbits; - char_type* inbuf; - char_type* htab; - unsigned short* codetab; - fx_type fdin; - REG9 unsigned outpos=0; /* not restored */ - -#if 0 - fprintf(stderr, ":: call rsize=%d oldcode=%d\n", reader->rsize, (int)reader->oldcode); -#endif - if (reader->rsize<1) return reader->rsize; /* already EOF or error */ - - stackp =reader->stackp; - code =reader->code; - finchar=reader->finchar; - oldcode=reader->oldcode; - incode =reader->incode; - inbits =reader->inbits; - posbits=reader->posbits; - insize =reader->insize; - bitmask=reader->bitmask; - freeent=reader->freeent; - maxcode=reader->maxcode; - maycode=reader->maycode; - n_bits =reader->n_bits; - rsize =reader->rsize; - blkmode=reader->blkmode; - maxbits=reader->maxbits; - htab =reader->htab; - codetab=reader->codetab; - fdin =reader->fdin; - inbuf =reader->inbuf; - if (oldcode!=-1) goto try_fit; /* lz_read() called again */ - - do { - resetbuf: ; - { - REG1 int i; - int e; - int o; - - e = insize-(o = (posbits>>3)); - - for (i = 0 ; i < e ; ++i) - inbuf[i] = inbuf[i+o]; - - insize = e; - posbits = 0; - } - - if ((unsigned)insize < /*sizeof(inbuf)-IBUFSIZ*/ 64) { -#if 0 - fprintf(stderr, ":: try read insize=%d\n", insize); -#endif - if ((rsize = fx_read(fdin, inbuf+insize, IBUFSIZ)) < 0 || ferror(fdin)) return reader->rsize=-1; -#if 0 - fprintf(stderr, ":: got rsize=%d\n", rsize); -#endif - insize += rsize; - inbuf[insize]=inbuf[insize+1]=inbuf[insize+2]=0; - /* ^^^ sentinel, so input() won't produce ``read uninitialized byte(s) in a block.'' */ - } - - inbits = ((rsize > 0) ? (insize - insize%n_bits)<<3 : - (insize<<3)-(n_bits-1)); - - while (inbits > posbits) { - if (freeent > maxcode) { - posbits = ((posbits-1) + ((n_bits<<3) - - (posbits-1+(n_bits<<3))%(n_bits<<3))); - ++n_bits; - if (n_bits == maxbits) - maxcode = maycode; - else - maxcode = MAXCODE(n_bits)-1; - - bitmask = (1<= freeent) { /* Special case for KwKwK string. */ - if (code > freeent) { - posbits -= n_bits; -#if 0 - { - REG1 char_type *p; - p = &inbuf[posbits>>3]; - - fprintf(stderr, "uncompress: insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)\n", insize, posbits, - p[-1],p[0],p[1],p[2],p[3], (posbits&07)); - fprintf(stderr, "uncompress: corrupt input\n"); - abort(); - } -#else - return reader->rsize=-1; -#endif - } - - *--stackp = (char_type)finchar; - code = oldcode; - } - - while ((cmp_code_int)code >= (cmp_code_int)256) { - /* Generate output characters in reverse order */ - *--stackp = tab_suffixof(code); - code = tab_prefixof(code); - } -#if 0 - fprintf(stderr, ":: to stack code=%d\n", (int)code); -#endif - *--stackp = (char_type)(finchar = tab_suffixof(code)); - ASSERT(outpos<=obufsize); - - /* And put them out in forward order */ - { - REG1 int i; - - try_fit: if (outpos+(i = (de_stack-stackp)) >= obufsize) { - /* The entire stack doesn't fit into the outbuf */ - i=obufsize-outpos; - memcpy(outbuf+outpos, stackp, i); - stackp+=i; - /* vvv Dat: blkmode, maycode, inbuf, htab, codetab, fdin need not be saved */ - reader->stackp =stackp; - reader->code =code; - reader->finchar=finchar; - reader->oldcode=oldcode; - reader->incode =incode; - reader->inbits =inbits; - reader->posbits=posbits; - reader->insize =insize; - reader->bitmask=bitmask; - reader->freeent=freeent; - reader->maxcode=maxcode; - reader->maycode=maycode; - reader->n_bits =n_bits; - reader->rsize =rsize; - reader->blkmode=blkmode; - reader->maxbits=maxbits; -#if 0 - fprintf(stderr, ":: return obufsize=%d oldcode=%d\n", obufsize, (int)oldcode); -#endif - return obufsize; - /* Dat: co-routine return back to try_fit, with outpos==0, outbuf=... obufsize=... */ - } else { - memcpy(outbuf+outpos, stackp, i); - outpos += i; - } - } - /* Dat: ignore stackp from now */ - - if ((code = freeent) < maycode) { /* Generate the new entry. */ -#if 0 - fprintf(stderr, ":: new entry code=(%d)\n", (int)code); -#endif - tab_prefixof(code) = (unsigned short)oldcode; - tab_suffixof(code) = (char_type)finchar; - freeent = code+1; - } - oldcode = incode; /* Remember previous code. */ - } - } while (rsize > 0); - reader->rsize=0; - return outpos; -} - -/* --- */ - -/* Values used in typeflag field. */ - -#define REGTYPE '0' /* regular file */ -#define AREGTYPE '\0' /* regular file */ -#define LNKTYPE '1' /* link */ -#define SYMTYPE '2' /* reserved */ -#define CHRTYPE '3' /* character special */ -#define BLKTYPE '4' /* block special */ -#define DIRTYPE '5' /* directory */ -#define FIFOTYPE '6' /* FIFO special */ -#define CONTTYPE '7' /* reserved */ - -#define BLOCKSIZE 512 - -struct tar_header -{ /* byte offset */ - char name[100]; /* 0 */ - char mode[8]; /* 100 */ - char uid[8]; /* 108 */ - char gid[8]; /* 116 */ - char size[12]; /* 124 */ - char mtime[12]; /* 136 */ - char chksum[8]; /* 148 */ - char typeflag; /* 156 */ - char linkname[100]; /* 157 */ - char magic[6]; /* 257 */ - char version[2]; /* 263 */ - char uname[32]; /* 265 */ - char gname[32]; /* 297 */ - char devmajor[8]; /* 329 */ - char devminor[8]; /* 337 */ - char prefix[155]; /* 345 */ - /* 500 */ -}; - -union tar_buffer { - char buffer[BLOCKSIZE]; - struct tar_header header; -}; - -enum { TGZ_EXTRACT = 0, TGZ_LIST }; - -#if 0 -static char *TGZfname OF((const char *)); -void TGZnotfound OF((const char *)); - -int getoct OF((char *, int)); -char *strtime OF((time_t *)); -int ExprMatch OF((char *,char *)); - -int makedir OF((char *)); -int matchname OF((int,int,char **,char *)); - -void error OF((const char *)); -int tar OF((gzFile, int, int, int, char **)); - -void help OF((int)); -int main OF((int, char **)); -#endif - -static char *prog; - -static void error(const char *msg) { - fprintf(stderr, "%s: %s\n", prog, msg); - exit(1); -} - -#ifdef DOSISH -/* This will give a benign warning */ -static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar.bz2", ".tar.Z", ".tar", NULL }; - -/* Return the real name of the TGZ archive */ -/* or NULL if it does not exist. */ -static char *TGZfname OF((const char *fname)) -{ - static char buffer[1024]; - int origlen,i; - - strcpy(buffer,fname); - origlen = strlen(buffer); - - for (i=0; TGZprefix[i]; i++) - { - strcpy(buffer+origlen,TGZprefix[i]); - if (access(buffer,F_OK) == 0) - return buffer; - } - return NULL; -} - -/* error message for the filename */ - -static void TGZnotfound OF((const char *fname)) -{ - int i; - - fprintf(stderr,"%s : couldn't find ",prog); - for (i=0;TGZprefix[i];i++) - fprintf(stderr,(TGZprefix[i+1]) ? "%s%s, " : "or %s%s\n", - fname, - TGZprefix[i]); - exit(1); -} -#endif - - -/* help functions */ - -static int getoct(char *p,int width) -{ - int result = 0; - char c; - - while (width --) - { - c = *p++; - if (c == ' ') - continue; - if (c == 0) - break; - result = result * 8 + (c - '0'); - } - return result; -} - -static char *strtime (time_t *t) -{ - struct tm *local; - static char result[32]; - - local = localtime(t); - sprintf(result,"%2d/%02d/%4d %02d:%02d:%02d", - local->tm_mday, local->tm_mon+1, local->tm_year+1900, - local->tm_hour, local->tm_min, local->tm_sec); - return result; -} - - -/* regular expression matching */ - -#define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) - -static int ExprMatch(char *string,char *expr) -{ - while (1) - { - if (ISSPECIAL(*expr)) - { - if (*expr == '/') - { - if (*string != '\\' && *string != '/') - return 0; - string ++; expr++; - } - else if (*expr == '*') - { - if (*expr ++ == 0) - return 1; - while (*++string != *expr) - if (*string == 0) - return 0; - } - } - else - { - if (*string != *expr) - return 0; - if (*expr++ == 0) - return 1; - string++; - } - } -} - -/* recursive make directory */ -/* abort if you get an ENOENT errno somewhere in the middle */ -/* e.g. ignore error "mkdir on existing directory" */ -/* */ -/* return 1 if OK */ -/* 0 on error */ - -static int makedir (char *newdir) { - /* avoid calling strdup, since it's not ansi C */ - int len = strlen(newdir); - char *p, *buffer = malloc(len+1); - if (buffer==NULL) error("out of memory"); - memcpy(buffer,newdir,len+1); - - if (len <= 0) { - free(buffer); - return 0; - } - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mkdir(buffer, 0775) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mkdir(buffer, 0775) == -1) && (errno == ENOENT)) - { - fprintf(stderr,"%s: couldn't create directory %s\n",prog,buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -static int matchname (int arg,int argc,char **argv,char *fname) -{ - if (arg == argc) /* no arguments given (untgz tgzarchive) */ - return 1; - - while (arg < argc) - if (ExprMatch(fname,argv[arg++])) - return 1; - - return 0; /* ignore this for the moment being */ -} - - -/* Tar file list or extract */ - -static int tar (Readable* rin,int action,int arg,int argc,char **argv, char const* TGZfile, int verbose, void (*step)(void *,int), void *data) { - union tar_buffer buffer; - int is_tar_ok=0; - int len; - int err; - int getheader = 1; - int remaining = 0; - FILE *outfile = NULL; - char fname[BLOCKSIZE]; - time_t tartime = 0; - unsigned long last_read; - -#if 0 - while (0<(len=rin->xRead(rin, &buffer, BLOCKSIZE))) { - fwrite(buffer.buffer, 1, len, stdout); - } - exit(0); -#endif - - last_read = 0; - if (action == TGZ_LIST) - printf(" day time size file\n" - " ---------- -------- --------- -------------------------------------\n"); - while (1) { - len = rin->xRead(rin, &buffer, BLOCKSIZE); - if (len+1 == 0) - error (rin->xError(rin, &err)); - if (step) { step(data,total_read - last_read); last_read = total_read; } - if (!is_tar_ok && !(is_tar_ok=is_tar(buffer.buffer, len))) { - fprintf(stderr, "%s: compressed file not tared: %s\n", prog, TGZfile); - if (action == TGZ_EXTRACT) { - FILE *of; - unsigned len0=strlen(TGZfile), len1=len0; - char *ofn=malloc(len1+5); - if (ofn==NULL) return 1; - memcpy(ofn, TGZfile, len1+1); - while (len1>0 && ofn[len1]!='/' && ofn[len1]!='\\' && ofn[len1]!='.') len1--; - if (ofn[len1]=='.') ofn[len1]='\0'; else strcpy(ofn+len0, ".unc"); - /* ^^^ remove last extension, or add `.unc' */ - fprintf(stderr, "%s: extracting as: %s\n", prog, ofn); - if (NULL==(of=fopen(ofn, "wb"))) error("fopen write error"); - do { - fwrite(buffer.buffer, 1, len, of); - if (ferror(of)) error("write error"); - } while (0<(len=rin->xRead(rin, &buffer, BLOCKSIZE))); /* Imp: larger blocks */ - len=ferror(of); - if (0!=(len|fclose(of))) error("fclose write error"); - free(ofn); - return 0; - } - return 1; - /* !! */ - } - /* - * Always expect complete blocks to process - * the tar information. - */ - if (len != BLOCKSIZE) - error("read: incomplete block read"); - - /* - * If we have to get a tar header - */ - if (getheader == 1) - { - /* - * if we met the end of the tar - * or the end-of-tar block, - * we are done - */ - if ((len == 0) || (buffer.header.name[0]== 0)) break; - - tartime = (time_t)getoct(buffer.header.mtime,12); - strcpy(fname,buffer.header.name); - - switch (buffer.header.typeflag) - { - case DIRTYPE: - if (action == TGZ_LIST) - printf(" %s %s\n",strtime(&tartime),fname); - if (action == TGZ_EXTRACT) - makedir(fname); - break; - case REGTYPE: - case AREGTYPE: - remaining = getoct(buffer.header.size,12); - if (action == TGZ_LIST) - printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); - if (action == TGZ_EXTRACT) - { - if ((remaining) && (matchname(arg,argc,argv,fname))) - { - outfile = fopen(fname,"wb"); - if (outfile == NULL) { - /* try creating directory */ - char *p = strrchr(fname, '/'); - if (p != NULL) { - *p = '\0'; - makedir(fname); - *p = '/'; - outfile = fopen(fname,"wb"); - } - } - if (verbose) - fprintf(stderr, - "%s %s\n", - (outfile) ? "Extracting" : "Couldn't create", - fname); - } - else - outfile = NULL; - } - /* - * could have no contents - */ - getheader = (remaining) ? 0 : 1; - break; - default: - if (action == TGZ_LIST) - printf(" %s <---> %s\n",strtime(&tartime),fname); - break; - } - } - else - { - unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; - - if ((action == TGZ_EXTRACT) && (outfile != NULL)) - { - if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) - { - fprintf(stderr,"%s : error writing %s skipping...\n",prog,fname); - fclose(outfile); - unlink(fname); - } - } - remaining -= bytes; - if (remaining == 0) - { - getheader = 1; - if ((action == TGZ_EXTRACT) && (outfile != NULL)) - { -#ifdef WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal; - SYSTEMTIME st; - struct tm localt; - - fclose(outfile); - - localt = *localtime(&tartime); - - hFile = CreateFile(fname, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - - st.wYear = (WORD)localt.tm_year+1900; - st.wMonth = (WORD)localt.tm_mon; - st.wDayOfWeek = (WORD)localt.tm_wday; - st.wDay = (WORD)localt.tm_mday; - st.wHour = (WORD)localt.tm_hour; - st.wMinute = (WORD)localt.tm_min; - st.wSecond = (WORD)localt.tm_sec; - st.wMilliseconds = 0; - SystemTimeToFileTime(&st,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,NULL,&ftm); - CloseHandle(hFile); - - outfile = NULL; -#else - struct utimbuf settime; - - settime.actime = settime.modtime = tartime; - - fclose(outfile); - outfile = NULL; - utime(fname,&settime); -#endif - } - } - } - } - - if (rin->xClose(rin)) - error("failed gzclose"); - - return 0; -} - - -#ifdef DOSISH -/* =========================================================== */ - -static void help(int exitval) -{ - fprintf(stderr, - "untarka v0.34: super untar + untar.Z" -#ifdef HAVE_ZLIB - " + untar.gz" -#endif -#ifdef HAVE_BZ2LIB - " + untar.bz2" -#endif - "\ncontains code (C) by pts@fazekas.hu since 2003.01.28\n" - "This program is under GPL >=2.0. There is NO WARRANTY. Use at your own risk!\n\n" - "Usage: untarka [-x] tarfile to extract all files\n" - " untarka -x tarfile fname ... to extract selected files\n" - " untarka -l tarfile to list archive contents\n" - " untarka -h to display this help\n"); - exit(exitval); -} - -/* ====================================================================== */ - -extern int _CRT_glob; -int _CRT_glob = 0; /* disable globbing of the arguments */ -#endif -#ifdef COMPILE_MAIN -int main(int argc,char **argv) { - int action = TGZ_EXTRACT; - int arg = 1; - char *TGZfile; - Readable r; - -#if DOSISH - setmode(0, O_BINARY); -#endif - prog = strrchr(argv[0],'\\'); - if (prog == NULL) - { - prog = strrchr(argv[0],'/'); - if (prog == NULL) - { - prog = strrchr(argv[0],':'); - if (prog == NULL) - prog = argv[0]; - else - prog++; - } - else - prog++; - } - else - prog++; - - if (argc == 1) - help(0); - - if (strcmp(argv[arg],"-l") == 0 || strcmp(argv[arg],"-v") == 0) { - action = TGZ_LIST; - if (argc == ++arg) help(0); - } else if (strcmp(argv[arg],"-x") == 0) { - action = TGZ_EXTRACT; - if (argc == ++arg) help(0); - } else if (strcmp(argv[arg],"-h") == 0) help(0); - - if ((TGZfile = TGZfname(argv[arg])) == NULL) - TGZnotfound(argv[arg]); - - ++arg; - if ((action == TGZ_LIST) && (arg != argc)) - help(1); - - /* - * Process the TGZ file - */ - switch (action) { - case TGZ_LIST: - case TGZ_EXTRACT: - switch (xOpen4Read(&r,TGZfile)) { - case 0: break; - case 1: fprintf(stderr, "%s: cannot decode compressed tar file: %s\n", prog, TGZfile); return 1; - case 2: fprintf(stderr, "%s: tar file too short: %s\n", prog, TGZfile); return 1; - case 3: fprintf(stderr, "%s: not a tar file: %s\n", prog, TGZfile); return 1; - case 4: fprintf(stderr, "%s: cannot open tar file: %s\n", prog, TGZfile); return 1; - } - return tar(&r, action, arg, argc, argv, TGZfile, 1, 0, 0); - default: error("Unknown option!"); - } - return 0; -} -#endif - -void -tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void *,int), void *data) -{ - Readable r; - if (xOpen4Read(&r,TGZfile) == 0) - { - int arg = 2, - argc = 2; - char *argv[2]; - chdir( dest ); - argv[0] = "fgadmin"; - argv[1] = TGZfile; - tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step, data); - } -} diff --git a/utils/fgadmin/src/untarka.h b/utils/fgadmin/src/untarka.h deleted file mode 100644 index 24dc8c6a1..000000000 --- a/utils/fgadmin/src/untarka.h +++ /dev/null @@ -1,15 +0,0 @@ -// list the contents of the specified tar file -// bool tarlist( char *tarfile, char *destdir, bool verbose ); - -// extract the specified tar file into the specified destination -// directory -#ifdef __cplusplus -extern "C" { -#endif - -void tarextract( char *tarfile, char *destdir, int verbose, void (*step)(void*,int), void *data ); - -#ifdef __cplusplus -} -#endif -