#!/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_custom.pl # # Routines for dealing with custom lists 1; # Return true sub Is_Custom_List { return(&Number_Custom_Lists); } sub Number_Custom_Lists { local($count); &Parse_Name_Space; $count = 0; for (keys %name_space) { ++$count; } return($count); } sub List_Custom_List_Files { &Parse_Name_Space; return( values(%name_space) ); } sub Get_Default_List { open(FILE, "$FILE_DEFAULT_LIST") || &Print_Error("$ERROR_INFO","Can't open default list file for read.","$STATUS_MINOR"); $line = ; chop if (grep(/\n/, $line)); local($output) = "$line"; close(FILE); chomp($output); return($output); } sub Set_Default_List { local($list_name) = shift; open(FILE, ">$FILE_DEFAULT_LIST") || &Print_Error("$ERROR_INFO","Can't open default list file for write.","$STATUS_MINOR"); print FILE "$list_name"; close(FILE); } sub Generate_Maint_Custom_Page { &Parse_Name_Space; if ($in{$CGI_CUSTOM_ADD_SWITCH}) { if ($in{$CGI_CUSTOM_INCLUDE_SWITCH}) { &Generate_Add_Results_Page; } elsif ($in{$CGI_CHECKFORNONE_SWITCH}) { &Generate_Add_Picker_Page(1); } else { &Generate_Add_Picker_Page; } } elsif ($in{$CGI_CUSTOM_EDIT_SWITCH}) { if ($in{$CGI_CUSTOM_INCLUDE_SWITCH}) { &Generate_Edit_Results_Page; } elsif ($in{$CGI_CHECKFORNONE_SWITCH}) { &Generate_Edit_Picker_Page(1); } else { &Generate_Edit_Picker_Page; } } elsif ($in{$CGI_CUSTOM_DELETE_SWITCH}) { &Generate_Delete_List_Page; } elsif ($in{$CGI_CUSTOM_OLD_NAME_SWITCH}) { &Generate_Change_Name_Page; } elsif ($in{$CGI_CUSTOM_VIEW_SWITCH}) { &Pop_List_Demos($in{$CGI_CUSTOM_VIEW_SWITCH}); } else { &Print_Main_Custom_Page; } } sub Generate_Change_Name_Page { $in{$CGI_CUSTOM_NEW_NAME_SWITCH} = &Make_HTTP_Safe("$in{$CGI_CUSTOM_NEW_NAME_SWITCH}"); &Print_Maint_Top("List Name Changed", "$IMGSRC_HEADER_CUSTOM"); &Change_Name($in{$CGI_CUSTOM_OLD_NAME_SWITCH}, $in{$CGI_CUSTOM_NEW_NAME_SWITCH}) if ("$in{$CGI_CUSTOM_OLD_NAME_SWITCH}" ne "$in{$CGI_CUSTOM_NEW_NAME_SWITCH}"); &Print_Name_Change_Success; } sub Change_Name { $name_space{$_[1]} = $name_space{$_[0]}; delete $name_space{$_[0]}; &Print_Name_Space; } sub Print_Name_Change_Success { &Print_Error("$ERROR_INFO","Custom Demo List \"$in{$CGI_CUSTOM_OLD_NAME_SWITCH}\" Changed To \"$in{$CGI_CUSTOM_NEW_NAME_SWITCH}\"","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "The list $in{$CGI_CUSTOM_OLD_NAME_SWITCH} changed its name to $in{$CGI_CUSTOM_NEW_NAME_SWITCH}."; print "

\n"; print "Use this utility to make further modifications to your custom list portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Custom_Forms; } sub Generate_Delete_List_Page { if (&Number_Custom_Lists == 1) { &Print_Maint_Top("Deleted Custom Demo List: $in{$CGI_CUSTOM_DELETE_SWITCH}", "$IMGSRC_HEADER_CUSTOM", $PASSWD_NO_OVERRIDE, $CUSTOM_UPDATE_TOC); } else { &Print_Maint_Top("Deleted Custom Demo List: $in{$CGI_CUSTOM_DELETE_SWITCH}", "$IMGSRC_HEADER_CUSTOM"); } &Delete_List($in{$CGI_CUSTOM_DELETE_SWITCH}); &Print_Delete_Success_Page; } sub Delete_List { &Remove_List_File($_[0]); delete $name_space{$_[0]}; &Print_Name_Space; } sub Remove_List_File { `$CMD_RM $PATH_CUSTOM_DIR/$name_space{$_[0]} $CMD_NULLIFY`; } sub Print_Delete_Success_Page { &Print_Error("$ERROR_INFO","Custom Demo List \"$in{$CGI_CUSTOM_DELETE_SWITCH}\" Deleted","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "The custom list was successfully deleted."; print "

\n"; print "Use this utility to make further modifications to your custom list portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Custom_Forms; } sub Pop_List_Demos { &Parse_Name_Space; &Print_HTTP_Header("$in{$CGI_CUSTOM_VIEW_SWITCH}"); print "\n"; print "
$in{$CGI_CUSTOM_VIEW_SWITCH}
\n"; print "

\n"; print "

\n"; &Print_HTTP_Footer; } sub Generate_Add_Results_Page { if (&Number_Custom_Lists == 0) { &Print_Maint_Top("Added New Custom Demo List: $in{$CGI_CUSTOM_ADD_SWITCH}", "$IMGSRC_HEADER_CUSTOM", $PASSWD_NO_OVERRIDE, $CUSTOM_UPDATE_TOC); } else { &Print_Maint_Top("Added New Custom Demo List: $in{$CGI_CUSTOM_ADD_SWITCH}", "$IMGSRC_HEADER_CUSTOM"); } &Add_List($in{$CGI_CUSTOM_ADD_SWITCH}); &Print_Error("$ERROR_INFO","Custom Demo List \"$in{$CGI_CUSTOM_ADD_SWITCH}\" Created","$STATUS_MINOR"); &Print_Success_Page; } sub Generate_Edit_Results_Page { &Print_Maint_Top("Edited Custom Demo List: $in{$CGI_CUSTOM_EDIT_SWITCH}", "$IMGSRC_HEADER_CUSTOM"); &Print_Error("$ERROR_INFO","Custom Demo List \"$in{$CGI_CUSTOM_EDIT_SWITCH}\" Edited","$STATUS_MINOR"); &Edit_List($in{$CGI_CUSTOM_EDIT_SWITCH}); &Print_Success_Page; } sub Print_Success_Page { print "INFORMATION

\n"; print "

\n"; print "The custom demo list was successfully generated."; print "

\n"; print "Use this utility to make further modifications to your custom list portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Custom_Forms; } sub Add_List { local($file_name, $demo); $file_name = &Generate_File_Name; open(NAMESPACE, ">>$FILE_NAMESPACE"); print NAMESPACE "$_[0]"; print NAMESPACE "$CUSTOM_DELIM"; print NAMESPACE "$file_name\n"; close(NAMESPACE); &Write_List_File($file_name); &Parse_Name_Space; } sub Edit_List { local($file_name, $demo); $file_name = $name_space{$_[0]}; &Write_List_File($file_name); } sub Write_List_File { @demos_on_list = split(/\n/, $in{$CGI_CUSTOM_INCLUDE_SWITCH}); open(LISTFILE, ">$PATH_CUSTOM_DIR/$_[0]"); for $demo (@demos_on_list) { print LISTFILE "$demo\n"; } close(LISTFILE); } sub Generate_File_Name { ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); return("$year.$mon.$mday.$hour.$min.$sec.$EXT_LIST") } sub Generate_Add_Picker_Page { &Print_Maint_Top("Add Custom Demo List: $in{$CGI_CUSTOM_ADD_SWITCH}", "$IMGSRC_HEADER_CUSTOM"); if ($_[0]) { print "ERROR: You did not pick any demos for this list. Please\n"; print "select at least one demo, or cancel.

"; } &Generate_Picker_Page_Bottom($CGI_CUSTOM_ADD_SWITCH); } sub Generate_Edit_Picker_Page { &Print_Maint_Top("Edit Custom Demo List: $in{$CGI_CUSTOM_EDIT_SWITCH}", "$IMGSRC_HEADER_CUSTOM"); if ($_[0]) { print "ERROR: You did not pick any demos for this list. Please\n"; print "select at least one demo, or cancel and delete the list.

"; } else { @demos_on_list = &Demos_On_List("$in{$CGI_CUSTOM_EDIT_SWITCH}"); } &Generate_Picker_Page_Bottom($CGI_CUSTOM_EDIT_SWITCH); } sub Demos_On_List { local($file_name, @demos); $file_name = $name_space{$_[0]}; open(LISTFILE, "$PATH_CUSTOM_DIR/$file_name") || &Print_Error("$ERROR_NO_OPEN", "$file_name", "$STATUS_SERIOUS"); while() { chop; $line = $_; if (grep(/$TREES_DELIM/, $line)) { push(@demos, $line); } else { # Support old style custom lists $name = &Tree_Name_From_Path("$TREE_DEFAULT_PATH", 1); if ("$name" ne "") { push(@demos, "$line$TREES_DELIM$name"); } } } return(@demos); } sub Generate_Picker_Page_Bottom { &Print_Picker_List($_[0]); &Print_Look_At_Help; &Print_Maint_Bottom; &Print_HTTP_Footer; } sub Print_Picker_List { local($firstCol); print "INSTRUCTIONS

\n"; print "Please select the demos you wish to include on the custom list.\n"; print "To select a demo, check the box next to the demo icon, then click\n"; print "on the Make List buttons.\n"; print "
\n"; print "

\n"; print "

\n


\n"; print "

\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; $firstCol = 1; for $demo ( @demo_list ) { ($demo_name, $tree_name) = split($TREES_DELIM, $demo); print "\n" if ($firstCol); print "\n"; print "\n" if (!$firstCol); $firstCol = (!$firstCol); } print "
\n"; print "\n"; &Print_Demo_Bullet("$demo_name", "$tree_name"); print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } sub Print_Main_Custom_Page { local(@lists, $list); &Print_Maint_Top("Custom Demo Lists", "$IMGSRC_HEADER_CUSTOM"); print "INFORMATION

\n"; print "

\n"; print "Add, view, edit, or delete custom demo lists."; print "

\n


\n"; &Print_Main_Custom_Forms; } sub Print_Main_Custom_Forms { @lists = &List_Custom_Lists; &Print_Add_List_Form; print "


\n"; if (@lists) { print "PICK \n"; print "DEMO\n"; print "LIST

\n"; print "\n"; } foreach $list ( &alpha(@lists)) { &Print_List_Bullet($list); } print "
\n

\n" if (@lists); &Print_Look_At_Help; &Print_Maint_Bottom; &Print_HTTP_Footer; } sub Print_Add_List_Form { print "ADD \n"; print "LIST

\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n\n\n\n
\n"; print ""; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; } sub Print_List_Bullet { local($safe_custom_name); undef $safe_custom_name; $safe_custom_name = &HTTP_Syntax("$_[0]"); print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "

\n"; } sub List_Custom_Lists { local(@lists); for (keys %name_space) { push(@lists, $_); } return( &alpha(@lists)); } sub Print_Name_Space { local($key); open(NAMESPACE, ">$FILE_NAMESPACE"); for $key (keys %name_space) { if (defined $name_space{$key}) { print NAMESPACE "$key"; print NAMESPACE "$CUSTOM_DELIM"; print NAMESPACE "$name_space{$key}\n"; } } close(NAMESPACE); &Parse_Name_Space; } sub Custom_File_Exists { local($file_name) = shift; chdir("$PATH_CUSTOM_DIR"); return( (-r "$PATH_CUSTOM_DIR/$file_name") ) } sub Parse_Name_Space { local($isError) = 0; undef(%name_space); if(open(NAMESPACE, "$FILE_NAMESPACE")) { while() { chop if (grep(\n, $_)); ($key, $val) = split(/$CUSTOM_DELIM/, $_) if ($_); $name_space{$key} = $val if ($_); } } # Test to make sure the file associated in the namespace still exists for $list (keys(%name_space)) { if (! &Custom_File_Exists("$name_space{$list}") ) { &Print_Error("$ERROR_INFO","Removing custom list \"$list\". File is missing.","$STATUS_MINOR"); delete $name_space{$list}; # delete this part of the namespace $isError = 1; } } # If there are changes, reprint the NameSpace &Print_Name_Space if ($isError); }