#!/usr/sbin/perl #************************************************************************** #* * #* Copyright (c) 1996 Silicon Graphics, Inc. * #* All Rights Reserved * #* * #* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI * #* * #* The copyright notice above does not evidence any actual of intended * #* publication of such source code, and is an unpublished work by Silicon * #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is * #* the property of Silicon Graphics, Inc. Any use, duplication or * #* disclosure not specifically authorized by Silicon Graphics is strictly * #* prohibited. * #* * #* RESTRICTED RIGHTS LEGEND: * #* * #* Use, duplication or disclosure by the Government is subject to * #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in * #* Technical Data and Computer Software clause at DFARS 52.227-7013, * #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR * #* Supplement. Unpublished - rights reserved under the Copyright Laws of * #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. * #* Shoreline Blvd., Mountain View, CA 94039-7311 * #************************************************************************** # DEMO_tables.pl # # Routines for working with the tables 1; # Return true sub Source_Table { local($category, $demos); undef %demos_under; $filename = shift; @list_cat = @_; open(TABLE, "$filename") || &Print_Error("$ERROR_NO_OPEN", "$filename", "$STATUS_SERIOUS"); while () { chop; ($category, $demos) = /(.*)$TABLE_FIRST_DELIM(.*)/; if (("$category" ne "") && ("$demos" ne "") && (grep(/^$category$/, @list_cat))) { $demos_under{$category} = $demos; } } close(TABLE); } sub Update_Tables { # unless ($pid = fork) { # unless (fork) { # &Shutdown_File_Descriptors; # &Parse_List_Demos; # @demo_list = &Generate_Demos_Array; # &Update_Hardware_Table; # &Update_Features_Table; # &Update_Markets_Table; `$CMD_UPDATE_TABLES $CMD_NULLIFY $CMD_BACKGROUND`; # exit 0; # } # exit 0; # } # wait; } sub Update_Hardware_Table { &Print_Error("$ERROR_INFO","Updating Hardware Table","$STATUS_MINOR"); # unless ($pid = fork) { # unless (fork) { # &Shutdown_File_Descriptors; &Parse_Category_Table("$FILE_TABLE_HARDWARE", "HARDWARE", @hardware_categories); &Print_Error("$ERROR_INFO","Finished Updating Hardware Table","$STATUS_MINOR"); # exit 0; # } # exit 0; # } } sub Update_Features_Table { &Print_Error("$ERROR_INFO","Updating Features Table","$STATUS_MINOR"); # unless ($pid = fork) { # unless (fork) { # &Shutdown_File_Descriptors; &Parse_Category_Table("$FILE_TABLE_FEATURES", "FEATURES", @features_categories); &Print_Error("$ERROR_INFO","Finished Updating Features Table","$STATUS_MINOR"); # exit 0; # } # exit 0; # } } sub Update_Markets_Table { &Print_Error("$ERROR_INFO","Updating Industry Table","$STATUS_MINOR"); # unless ($pid = fork) { # unless (fork) { # &Shutdown_File_Descriptors; &Parse_Category_Table("$FILE_TABLE_MARKETS", "MARKETS", @markets_categories); &Print_Error("$ERROR_INFO","Finished Updating Industry Table","$STATUS_MINOR"); # exit 0; # } # exit 0; # } } sub Update_List_Demos { # unless ($pid = fork) { # unless (fork) { # &Shutdown_File_Descriptors; &Parse_List_Demos; # exit 0; # } # exit 0; # } } sub Verify_Custom_Lists { local($list); if (&Is_Custom_List) { &Parse_Name_Space; for $list (&List_Custom_Lists) { open(FILE, ">$PATH_TMP/$name_space{$list}") || &Print_Error("$ERROR_INFO","Can't open temp file for verifying lists: $PATH_TMP/$name_space{$list}. ", "$STATUS_MINOR"); for $demo (&Demos_On_List($list)) { print FILE "$demo\n" if (grep(/^$demo/, @demo_list)); } close(FILE); rename("$PATH_TMP/$name_space{$list}", "$PATH_CUSTOM_DIR/$name_space{$list}"); } } } sub Parse_Category_Table { local($i, $file_name, $demo_name, $demo_tree, $demo_path, $element, $cat, @categories, %link_for); $file_name = shift(@_); $element = shift(@_); @categories = @_; %links_for = ""; open(TABLE, ">$file_name.$EXT_BAK") || &Print_Error("$ERROR_NO_OPEN", "$file_name", "$STATUS_SERIOUS"); for $str (@demo_list) { ($demo_name, $demo_tree) = split(/$TREES_DELIM/, $str); $demo_path = &Tree_Path_From_Name("$demo_tree"); &Parse_Demo_Info("$demo_path/$demo_name/$DEMOSRC_INDEX"); @link_items = split(/\n/, $demo_info{$element}); for $cat (@categories) { if (grep(/^$cat$/i, @link_items)) { $links_for{$cat} .= "$demo_name$TABLE_THIRD_DELIM$demo_tree$TABLE_SECOND_DELIM"; } } } for (@categories) { print TABLE "$_$TABLE_FIRST_DELIM$links_for{$_}\n"; } close(TABLE); rename("$file_name.$EXT_BAK", "$file_name"); } sub Parse_List_Demos { local(@tree_dirs, @legal_demos, $tree_name, $tree_path); &Print_Error("$ERROR_INFO","Updating Demo Lists","$STATUS_MINOR"); for $tree_name (&List_Tree_Names) { $tree_path = &Tree_Path_From_Name("$tree_name"); @tree_dirs = &Generate_List_Demo_Dirs("$tree_path"); @legal_demos = &Generate_Legal_Demos_List("$tree_path", @tree_dirs); &Print_Demo_List_File("$tree_name", @legal_demos); } &Print_All_Demos_List_File; undef @demo_list; @demo_list = &Generate_Demos_Array; &Print_Error("$ERROR_INFO","Finished Updating Demo List","$STATUS_MINOR"); } sub Generate_List_Demo_Dirs { local(@treedirs); # Open up demos directory and grab all directories chdir("$_[0]"); opendir(DIR, "."); @treedirs = grep(-d, readdir(DIR)); @treedirs = grep(!/^\.\.?$/, @treedirs); closedir(DIR); return(&alpha(@treedirs)); } sub Generate_Legal_Demos_List { local(@alldirs, $tree_path, @legal_demos); undef @legal_demos; $tree_path = shift; @alldirs = @_; # For each dir, check for .index, thumbnail.jpg, header.gif, executable for $dir (@alldirs) { if (&Legal_Properties("$tree_path/$dir")) { push(@legal_demos, "$dir"); } else { &Print_Error("$ERROR_ILLEGAL_DEMO", "$dir", "$STATUS_MINOR"); if (!$directorystate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "Directory $dir not writable by user $HTTP_USER.", "$STATUS_MINOR"); } if (!$thumbstate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "$DEMOSRC_THUMBNAIL not found.", "$STATUS_MINOR"); } if (!$demostate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "$DEMOSRC_RUN not found or not executable by user $HTTP_USER.", "$STATUS_MINOR"); } if (!$picstate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "$DEMOSRC_DEMOPIC not found.", "$STATUS_MINOR"); } if (!$headerstate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "$DEMOSRC_HEADER not found or not writable by user $HTTP_USER.", "$STATUS_MINOR"); } if (!$indexstate) { &Print_Error("$ERROR_ILLEGAL_DEMO_REASON", "$DEMOSRC_INDEX not found or not writable by user $HTTP_USER.", "$STATUS_MINOR"); } } } @legal_demos = &alpha(@legal_demos); return(@legal_demos); } sub Get_Files_From_Dir { local(@files, $dir); $dir = $_[0]; opendir(DIR, "$dir"); @files = readdir(DIR); closedir(DIR); return(@files); } sub Legal_Properties { local($dir, @allfiles); $dir = $_[0]; undef $directorystate; undef $indexfound; undef $indexstate; undef $headerfound; undef $headerstate; undef $thumbfound; undef $thumbstate; undef $demofound; undef $demostate; undef $picfound; undef $picstate; @allfiles = &Get_Files_From_Dir("$dir"); chdir("$dir"); # Check for directory permissions stat("$dir"); $directorystate = 1 if -w _; # Check for .index if (grep(/^$DEMOSRC_INDEX$/, @allfiles)) { $indexfound = 1; stat("$dir/$DEMOSRC_INDEX"); $indexstate = 1 if -w _; } # Check for header.jpg if (grep(/^$DEMOSRC_HEADER$/, @allfiles)) { $headerfound = 1; stat("$dir/$DEMOSRC_HEADER"); $headerstate = 1 if -w _; } # Check for thumbnail.gif if (grep(/^$DEMOSRC_THUMBNAIL$/, @allfiles)) { $thumbfound = 1; $thumbstate = 1; } # Check for RUN script if (grep(/^$DEMOSRC_RUN$/, @allfiles)) { $demofound = 1; stat("$dir/$DEMOSRC_RUN"); $demostate = 1 if -x _; } # Check for demo.jpg if (grep(/^$DEMOSRC_DEMOPIC$/, @allfiles)) { $picfound = 1; $picstate = 1; } return( ($directorystate && $demostate && $thumbstate && $headerstate && $indexstate && $picstate) ); } sub Print_All_Demos_List_File { `$CMD_RM $FILE_DEMOLIST $CMD_NULLIFY`; open(LIST_FILE, ">$FILE_DEMOLIST") || &Print_Error("$ERROR_NO_OPEN", "$FILE_DEMOLIST", "$STATUS_SERIOUS"); for $tree_name (&List_Tree_Names) { $tree_file = &Tree_File_From_Name("$tree_name"); open(TREE_FILE, "$PATH_TREES_DIR/$tree_file") || &Print_Error("$ERROR_NO_OPEN", "$tree_file", "$STATUS_SERIOUS"); while () { chop; if ($_) { print LIST_FILE "$_"; print LIST_FILE "$TREES_DELIM"; print LIST_FILE "$tree_name\n"; } } close(TREE_FILE); } close(LIST_FILE); } sub Print_Demo_List_File { local(@legal_demos, $tree_name, $tree_file); $tree_name = shift; @legal_demos = @_; $tree_file = &Tree_File_From_Name("$tree_name"); open(LIST, ">$PATH_TREES_DIR/$tree_file.$EXT_BAK") || &Print_Error("$ERROR_NO_OPEN", "$tree_file.$EXT_BAK", "$STATUS_SERIOUS"); for $demo_name (@legal_demos) { print LIST "$demo_name\n"; } close(LIST); rename("$PATH_TREES_DIR/$tree_file.$EXT_BAK", "$PATH_TREES_DIR/$tree_file") || &Print_Error("$ERROR_NO_OPEN", "$tree_file.$EXT_BAK -> $tree_file", "$STATUS_SERIOUS");; }