ACC SHELL

Path : /usr/share/YaST2/include/autoinstall/
File Upload :
Current File : //usr/share/YaST2/include/autoinstall/common.ycp

/**
 * File:	include/common.ycp
 * Package:	Auto-installation/Partition
 * Summary:     common helper functions
 * Author:	Sven Schober (sschober@suse.de)
 *
 * $Id: common.ycp 2805 2008-05-27 15:12:42Z sschober $
 */
{
  textdomain "autoinst";

  include "autoinstall/types.ycp";

  import "AutoinstStorage";

  define DialogT currentDialog = $[];
  /* because i don't know how to pass arguments to eval() 
   * i use this global map as a stack
   */
  define map<symbol, any> stack = $[];

  define map currentEvent = $[];
  define symbol replacement_point = `rp;

  /*
   * Global dialogs map. See StorageDialog() for more detailed
   * description of the general architecture.
   */
  define map<string, DialogT > dialogs = $[];

  define void addDialog( string name, DialogT dialog ){
    dialogs = add(dialogs, name, dialog );
  }

  define string symbol2string( symbol s ){
    if( nil == s ){
      return "";
    }
    return substring(tostring(s),1);
  }
  define symbol string2symbol( string s ){
    return symbolof(toterm(s));
  }

  define list<term> toItemList( list<string> sList ){
    return maplist( string s, sList, { return `item(`id(string2symbol(s)), s); });
  }

  define DialogT
    updateCurrentDialog( string dialogType ){
    currentDialog = dialogs[dialogType]:$[];
    return currentDialog;
  }

  define DialogT
    getDialog( string dialogType ){
    return dialogs[dialogType]:$[];
  }

  define void prepareStack(){
    /**
     * TODO: implement.
     */
     y2milestone("prepareStack(): NOT IMPLEMENTED");
  }

  define void
    callDialogFunction( DialogT dialog, symbol function ){
    any functionTerm = dialog[function]:nil;
    if( nil != functionTerm ){
      y2milestone( "calling function: '%1'->'%2'.", dialog[`type]:"Unknown", functionTerm);
      // prepareStack();
      eval( functionTerm );
    }
    else{
      y2milestone( "Function not found: '%1'->'%2'.", dialog[`type]:"Unknown", function);
    }
  }

  /*
   * Called by event handles to indicate the current event has been
   * handled
   */
  define void eventHandled(){
    currentEvent = $[];
  }

  /* extracts type from tree item id strings:
   * "part_2_0" -> "part"
   */
  define string getTypePrefix( string item ){
    if( nil != item && "" != item ){
      return substring( item, 0, findfirstof(item, "_") );
    }
    return item;
  }

  /* strips off type prefixes from tree item id strings:
   * "part_2_0" -> "2_0"
   */
  define string stripTypePrefix( string item ){
    if( nil != item && "" != item ){
      return substring( item, findfirstof(item, "_")+1 );
    }
    return item;
  }

  /* TODO: might be optimized by not using a regex here */
  define string removePrefix( string s, string prefix ){
    string result = "";
    result = regexpsub( s, prefix+"(.*)", "\\1" );
    if( nil == result ){
      return s;
    }
    return result;
  }
  /* seems a bit over eager to supply this, but for consistencies
   * sake...
   */
  define string addPrefix( string s, string prefix ){
    return prefix + s;
  }

}

ACC SHELL 2018