text:
package com.github.mjdev.libaums.fs.fat32;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.util.Log;

import com.github.mjdev.libaums.driver.BlockDeviceDriver;
import com.github.mjdev.libaums.fs.UsbFile;

/**
 * This class represents a directory in the FAT32 file system. It can hold other
 * directories and files.
 *
 * @author mjahnen
 *
 */
public class FatDirectory implements UsbFile {

	private static String TAG = FatDirectory.class.getSimpleName();

	private ClusterChain chain;
	private BlockDeviceDriver blockDevice;
	private FAT fat;
	private Fat32BootSector bootSector;
	/**
	 * Entries read from the device.
	 */
	private List<FatLfnDirectoryEntry> entries;
	/**
	 * Map for checking for existence when for example creating new files or
	 * directories.
	 *

	 * All items are stored in lower case because a FAT32 fs is not case
	 * sensitive.
	 */
	private Map<String, FatLfnDirectoryEntry> lfnMap;
	/**
	 * Map for checking for existence of short names when generating short names
	 * for new files or directories.
	 */
	private Map<ShortName, FatDirectoryEntry> shortNameMap;
	/**
	 * Null if this is the root directory.
	 */
	private FatDirectory parent;
	/**
	 * Null if this is the root directory.
	 */
	private FatLfnDirectoryEntry entry;

	private String volumeLabel;

	/**
	 * Constructs a new FatDirectory with the given information.
	 *
	 * @param blockDevice
	 *            The block device the fs is located.
	 * @param fat
	 *            The FAT of the fs.
	 * @param bootSector
	 *            The boot sector if the fs.
	 * @param parent
	 *            The parent directory of the newly created one.
	 */
	private FatDirectory(BlockDeviceDriver blockDevice, FAT fat, Fat32BootSector bootSector,
			FatDirectory parent) {
		this.blockDevice = blockDevice;
		this.fat = fat;
		this.bootSector = bootSector;
		this.parent = parent;
		entries = new ArrayList<FatLfnDirectoryEntry>();
		lfnMap = new HashMap<String, FatLfnDirectoryEntry>();
		shortNameMap = new HashMap<ShortName, FatDirectoryEntry>();
	}

	/**
	 * This method creates a new directory from a given
	 * {@link FatDirectoryEntry}.
	 *
	 * @param entry
	 *            The entry of the directory.
	 * @param blockDevice
	 *            The block device the fs is located.
	 * @param fat
	 *            The FAT of the fs.
	 * @param bootSector
	 *            The boot sector if the fs.
	 * @param parent
	 *            The parent directory of the newly created one.
	 * @return Newly created directory.
	 */
	/* package */static FatDirectory create(FatLfnDirectoryEntry entry,
			BlockDeviceDriver blockDevice, FAT fat, Fat32BootSector bootSector, FatDirectory parent) {
		FatDirectory result = new FatDirectory(blockDevice, fat, bootSector, parent);
		result.entry = entry;
		return result;
	}

	/**
	 * Reads the root directory from a FAT32 file system.
	 *
	 * @param blockDevice
	 *            The block device the fs is located.
	 * @param fat
	 *            The FAT of the fs.
	 * @param bootSector
	 *            The boot sector if the fs.
	 * @return Newly created root directory.
	 * @throws IOException
	 *             If reading from the device fails.
	 */
	/* package */static FatDirectory readRoot(BlockDeviceDriver blockDevice, FAT fat,
			Fat32BootSector bootSector) throws IOException {
		FatDirectory result = new FatDirectory(blockDevice, fat, bootSector, null);
		result.chain = new ClusterChain(bootSector.getRootDirStartCluster(), blockDevice, fat,
				bootSector);
		result.init();
		return result;
	}

	/**
	 * Initializes the {@link FatDirectory}. Creates the cluster chain if needed
	 * and reads all entries from the cluster chain.
	 *
	 * @throws IOException
	 *             If reading from the device fails.
	 */
	private void init() throws IOException {
		if (chain == null) {
			chain = new ClusterChain(entry.getStartCluster(), blockDevice, fat, bootSector);
		}

		if (entries.size() == 0)
			readEntries();
	}

	/**
	 * Reads all entries from the directory and saves them into {@link #lfnMap},
	 * {@link #entries} and {@link #shortNameMap}.
	 *
	 * @throws IOException
	 *             If reading from the device fails.
	 * @see #write()
	 */
	private void readEntries() throws IOException {
		ByteBuffer buffer = ByteBuffer.allocate((int) chain.getLength());
		chain.read(0, buffer);
		// we have to buffer all long filename entries to parse them later
		ArrayList<FatDirectoryEntry> list = new ArrayList<FatDirectoryEntry>();
		buffer.flip();
		while (buffer.remaining() > 0) {
			FatDirectoryEntry e = FatDirectoryEntry.read(buffer);
			if (e == null) {
				break;
			}

			if (e.isLfnEntry()) {
				list.add(e);
				continue;
			}

			if (e.isVolumeLabel()) {
				if (!isRoot()) {
					Log.w(TAG, "volume label in non root dir!");
				}
				volumeLabel = e.getVolumeLabel();
				Log.d(TAG, "volume label: " + volumeLabel);
				continue;
			}

			// we just skip deleted entries
			if (e.isDeleted()) {
				list.clear();
				continue;
			}

			FatLfnDirectoryEntry lfnEntry = FatLfnDirectoryEntry.read(e, list);
			addEntry(lfnEntry, e);
			list.clear();
		}
	}

	/**
	 * Adds the long file name entry to {@link #lfnMap} and {@link #entries} and
	 * the actual entry to {@link #shortNameMap}.
	 *

	 * This method does not write the changes to the disk. If you want to do so
	 * call {@link #write()} after adding an entry.
	 *
	 * @param lfnEntry
	 *            The long filename entry to add.
	 * @param entry
	 *            The corresponding short name entry.
	 * @see #removeEntry(FatLfnDirectoryEntry)
	 */
	private void addEntry(FatLfnDirectoryEntry lfnEntry, FatDirectoryEntry entry) {
		entries.add(lfnEntry);
		lfnMap.put(lfnEntry.getName().toLowerCase(Locale.getDefault()), lfnEntry);
		shortNameMap.put(entry.getShortName(), entry);
	}

	/**
	 * Removes (if existing) the long file name entry from {@link #lfnMap} and
	 * {@link #entries} and the actual entry from {@link #shortNameMap}.
	 *

	 * This method does not write the changes to the disk. If you want to do so
	 * call {@link #write()} after adding an entry.
	 *
	 * @param lfnEntry
	 *            The long filename entry to remove.
	 * @see #addEntry(FatLfnDirectoryEntry, FatDirectoryEntry)
	 */
	/* package */void removeEntry(FatLfnDirectoryEntry lfnEntry) {
		entries.remove(lfnEntry);
		lfnMap.remove(lfnEntry.getName().toLowerCase(Locale.getDefault()));
		shortNameMap.remove(lfnEntry.getActualEntry().getShortName());
	}

	/**
	 * Renames a long filename entry to the desired new name.
	 *

	 * This method immediately writes the change to the disk, thus no further
	 * call to {@link #write()} is needed.
	 *
	 * @param lfnEntry
	 *            The long filename entry to rename.
	 * @param newName
	 *            The new name.
	 * @throws IOException
	 *             If writing the change to the disk fails.
	 */
	/* package */void renameEntry(FatLfnDirectoryEntry lfnEntry, String newName) throws IOException {
		if (lfnEntry.getName().equals(newName))
			return;

		removeEntry(lfnEntry);
		lfnEntry.setName(newName,
				ShortNameGenerator.generateShortName(newName, shortNameMap.keySet()));
		addEntry(lfnEntry, lfnEntry.getActualEntry());
		write();
	}

	/**
	 * Writes the {@link #entries} to the disk. Any changes made by
	 * {@link #addEntry(FatLfnDirectoryEntry, FatDirectoryEntry)} or
	 * {@link #removeEntry(FatLfnDirectoryEntry)} will then be committed to the
	 * device.
	 *
	 * @throws IOException
	 * @see {@link #write()}
	 */
	/* package */void write() throws IOException {
		init();
		final boolean writeVolumeLabel = isRoot() && volumeLabel != null;
		// first lookup the total entries needed
		int totalEntryCount = 0;
		for (FatLfnDirectoryEntry entry : entries) {
			totalEntryCount += entry.getEntryCount();
		}

		if (writeVolumeLabel)
			totalEntryCount++;

		long totalBytes = totalEntryCount * FatDirectoryEntry.SIZE;
		chain.setLength(totalBytes);

		ByteBuffer buffer = ByteBuffer.allocate((int) chain.getLength());
		buffer.order(ByteOrder.LITTLE_ENDIAN);

		if (writeVolumeLabel)
			FatDirectoryEntry.createVolumeLabel(volumeLabel).serialize(buffer);

		for (FatLfnDirectoryEntry entry : entries) {
			entry.serialize(buffer);
		}

		if (totalBytes % bootSector.getBytesPerCluster() != 0) {
			// add dummy entry filled with zeros to mark end of entries
			buffer.put(new byte[32]);
		}

		buffer.flip();
		chain.write(0, buffer);
	}

	/**
	 *
	 * @return True if this directory is the root directory.
	 */
	private boolean isRoot() {
		return entry == null;
	}

	/**
	 * This method returns the volume label which can be stored in the root
	 * directory of a FAT32 file system.
	 *
	 * @return The volume label.
	 */
	/* package */String getVolumeLabel() {
		return volumeLabel;
	}

	@Override
	public FatFile createFile(String name) throws IOException {
		if (lfnMap.containsKey(name.toLowerCase(Locale.getDefault())))
			throw new IOException("Item already exists!");

		ShortName shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keySet());

		FatLfnDirectoryEntry entry = FatLfnDirectoryEntry.createNew(name, shortName);
		// alloc completely new chain
		long newStartCluster = fat.alloc(new Long[0], 1)[0];
		entry.setStartCluster(newStartCluster);

		Log.d(TAG, "adding entry: " + entry + " with short name: " + shortName);
		addEntry(entry, entry.getActualEntry());
		// write changes immediately to disk
		write();

		return FatFile.create(entry, blockDevice, fat, bootSector, this);
	}

	@Override
	public FatDirectory createDirectory(String name) throws IOException {
		if (lfnMap.containsKey(name.toLowerCase(Locale.getDefault())))
			throw new IOException("Item already exists!");

		ShortName shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keySet());

		FatLfnDirectoryEntry entry = FatLfnDirectoryEntry.createNew(name, shortName);
		entry.setDirectory();
		// alloc completely new chain
		long newStartCluster = fat.alloc(new Long[0], 1)[0];
		entry.setStartCluster(newStartCluster);

		Log.d(TAG, "adding entry: " + entry + " with short name: " + shortName);
		addEntry(entry, entry.getActualEntry());
		// write changes immediately to disk
		write();

		FatDirectory result = FatDirectory.create(entry, blockDevice, fat, bootSector, this);

		// first create the dot entry which points to the dir just created
		FatLfnDirectoryEntry dotEntry = FatLfnDirectoryEntry
				.createNew(null, new ShortName(".", ""));
		dotEntry.setDirectory();
		dotEntry.setStartCluster(newStartCluster);
		FatLfnDirectoryEntry.copyDateTime(entry, dotEntry);
		result.addEntry(dotEntry, dotEntry.getActualEntry());

		// Second the dotdot entry which points to the parent directory (this)
		// if parent is the root dir then set start cluster to zero
		FatLfnDirectoryEntry dotDotEntry = FatLfnDirectoryEntry.createNew(null, new ShortName("..",
				""));
		dotDotEntry.setDirectory();
		dotDotEntry.setStartCluster(isRoot() ? 0 : entry.getStartCluster());
		FatLfnDirectoryEntry.copyDateTime(entry, dotDotEntry);
		result.addEntry(dotDotEntry, dotDotEntry.getActualEntry());

		// write changes immediately to disk
		result.write();

		return result;
	}

	@Override
	public void setLength(long newLength) {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public long getLength() {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public boolean isDirectory() {
		return true;
	}

	@Override
	public String getName() {
		return entry.getName();
	}

	@Override
	public void setName(String newName) throws IOException {
		if (isRoot())
			throw new IllegalStateException("Cannot rename root dir!");
		parent.renameEntry(entry, newName);
	}

	@Override
	public long createdAt() {
		return entry.getActualEntry().getCreatedDateTime();
	}

	@Override
	public long lastModified() {
		return entry.getActualEntry().getLastModifiedDateTime();
	}

	@Override
	public long lastAccessed() {
		return entry.getActualEntry().getLastAccessedDateTime();
	}

	@Override
	public UsbFile getParent() {
		return parent;
	}

	@Override
	public String[] list() throws IOException {
		init();
        List<String> list = new ArrayList<String>(entries.size());
		for (int i = 0; i < entries.size(); i++) {
			String name = entries.get(i).getName();
			if (!name.equals(".") && !name.equals("..")) {
				list.add(name);
			}
		}

        String[] array = new String[list.size()];
        array = list.toArray(array);

        return array;
	}

	@Override
	public UsbFile[] listFiles() throws IOException {
        init();
        List<UsbFile> list = new ArrayList<UsbFile>(entries.size());
        for (int i = 0; i < entries.size(); i++) {
            FatLfnDirectoryEntry entry = entries.get(i);
            String name = entry.getName();
            if (name.equals(".") || name.equals(".."))
                continue;

            if (entry.isDirectory()) {
                list.add(FatDirectory.create(entry, blockDevice, fat, bootSector, this));
            } else {
                list.add(FatFile.create(entry, blockDevice, fat, bootSector, this));
            }
        }

        UsbFile[] array = new UsbFile[list.size()];
        array = list.toArray(array);

        return array;
	}

	@Override
	public void read(long offset, ByteBuffer destination) throws IOException {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public void write(long offset, ByteBuffer source) throws IOException {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public void flush() throws IOException {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public void close() throws IOException {
		throw new UnsupportedOperationException("This is a directory!");
	}

	@Override
	public void moveTo(UsbFile destination) throws IOException {
		if (isRoot())
			throw new IllegalStateException("cannot move root dir!");

		if (!destination.isDirectory())
			throw new IllegalStateException("destination cannot be a file!");
		if (!(destination instanceof FatDirectory))
			throw new IllegalStateException("cannot move between different filesystems!");
		// TODO check if destination is really on the same physical device or
		// partition!

		FatDirectory destinationDir = (FatDirectory) destination;
		if (destinationDir.lfnMap.containsKey(entry.getName().toLowerCase(Locale.getDefault())))
			throw new IOException("item already exists in destination!");

		// now the actual magic happens!
		parent.removeEntry(entry);
		destinationDir.addEntry(entry, entry.getActualEntry());

		parent.write();
		destinationDir.write();
		parent = destinationDir;
	}

	/**
	 * This method moves an long filename entry currently stored in THIS
	 * directory to the destination which also must be a directory.
	 *

	 * Used by {@link FatFile} to move itself to another directory.
	 *
	 * @param entry
	 *            The entry which shall be moved.
	 * @param destination
	 *            The destination directory.
	 * @throws IOException
	 *             If writing fails or the item already exists in the
	 *             destination directory.
	 * @throws IllegalStateException
	 *             If the destination is not a directory or destination is on a
	 *             different file system.
	 */
	/* package */void move(FatLfnDirectoryEntry entry, UsbFile destination) throws IOException {
		if (!destination.isDirectory())
			throw new IllegalStateException("destination cannot be a file!");
		if (!(destination instanceof FatDirectory))
			throw new IllegalStateException("cannot move between different filesystems!");
		// TODO check if destination is really on the same physical device or
		// partition!

		FatDirectory destinationDir = (FatDirectory) destination;
		if (destinationDir.lfnMap.containsKey(entry.getName().toLowerCase(Locale.getDefault())))
			throw new IOException("item already exists in destination!");

		// now the actual magic happens!
		removeEntry(entry);
		destinationDir.addEntry(entry, entry.getActualEntry());

		write();
		destinationDir.write();
	}

	@Override
	public void delete() throws IOException {
		if (isRoot())
			throw new IllegalStateException("Root dir cannot be deleted!");

		init();
		UsbFile[] subElements = listFiles();

		for (UsbFile file : subElements) {
			file.delete();
		}

		parent.removeEntry(entry);
		parent.write();
		chain.setLength(0);
	}
}

redpajama_set_name: RedPajamaGithub


text:
import pygame, math
from SentimentAnalyze import GetData
from GetTweets import GetTweets

# Objects declared for the two other classes
sentimentAnalysis = GetData()
getTweets = GetTweets()

# Initialized
pygame.init()

# Defining colors
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

# Width and Height of the surface
display_width = 800
display_height = 600

half_width = display_width/2
half_height = display_height/2

# Display surface specified
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Twitter Sentiment Analyzer')

gameExit = False

# clock = pygame.time.Clock()
pygame.font.init()

# Function to display text of specified color to user
def message_to_screen(msg, color, location, fontsize):
	font = pygame.font.Font(None, fontsize)
	screen_text = font.render(msg, True, color)
	gameDisplay.blit(screen_text, location )

# Variable declarations
screen = 0
query = ""
returnedresult = ""
user_response = ""
response_printed = 0
tweet_number = 1

# Main Game Loop
while not gameExit:
	# Event Handling Loop
	save_to_file = 0

	# Event handling
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			gameExit = True
		# For screen 0
		if screen == 0:
			if(event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN):
				screen = 1
		# For screen 1
		if screen == 1:
			if event.type == pygame.KEYDOWN:
				if event.unicode.isalpha():
					query += event.unicode
				elif event.key == pygame.K_BACKSPACE:
					query = query[:-1]
				elif event.key == pygame.K_SPACE:
					query += " "
				elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
					if(query!=""):
						screen = 2
						getTweets.getting_query_result(query)
						returnedresult = sentimentAnalysis.run()
		# For screen 2
		if screen == 2:
			if event.type == pygame.KEYDOWN:
				if response_printed == 0:
					if event.key == pygame.K_p:
						user_response = "positive"
						save_to_file = 1
					elif event.key == pygame.K_n:
						user_response = "negative"
						save_to_file = 1
					elif event.key == pygame.K_x:
						user_response = "neutral"
						save_to_file = 1
				elif(response_printed == 1):
					if event.key == pygame.K_y:
						tweet_number += 1
						user_response = ""
						response_printed = 0
					if event.key == pygame.K_e:
						query = ""
						user_response = ""
						response_printed = 0
						screen = 1

	gameDisplay.fill(white)
	if(screen == 0):
		message_to_screen("Twitter Sentiment Analyzer", black, [half_width-250, half_height-80], 50)
		message_to_screen("Press any key to continue...", green, [half_width-250, half_height-20], 30)
	elif(screen == 1):
		message_to_screen("Enter a query search term - ", black, [half_width-250, half_height-80], 50)
		# pygame.draw.circle(gameDisplay, (192,192,192), (half_width,half_heiht + 150), 50)
		message_to_screen(query, black, [half_width-250, half_height], 30)
		if(query!=""):
			message_to_screen("Press enter to submit...", blue, [half_width-250, half_height+50], 30)
			message_to_screen("(Kindly wait a minute for processing)", blue, [half_width-250, half_height+80], 20)
		# TODO - Notify user that system is processing
	elif(screen == 2):
		message_to_screen("Your query:", black, [50, 50], 30)
		message_to_screen(query, black, [50, 80], 25)
		if(returnedresult[0] == "positive"):
			color = green
		elif(returnedresult[0] == "negative"):
			color = red
		elif(returnedresult[0] == "neutral"):
			color = black
		message_to_screen("The sentiment analysis for the query from the last 500 tweets - " + returnedresult[0], color, [50,130],25)
		message_to_screen("For the following tweet, enter positive (P), negative (N) or neutral (X) - ", blue, [50,170],25)

		tweet_question = returnedresult[1]
		tweet_sentiment = returnedresult[2]

		# Dividing the tweet in half for easier display (Max chars in tweet = 140 so it's not a problem)
		t = (tweet_question[tweet_number]).split(' ')
		firstpart, secondpart = t[:len(t)/2], t[len(t)/2:]
		message_to_screen(' '.join(firstpart), black, [50,200],25)
		message_to_screen(' '.join(secondpart), black, [50,225],25)

		if(user_response!=""):
			if(user_response == "positive"):
				color = green
			elif(user_response == "negative"):
				color = red
			else:
				color = black
			message_to_screen("Your response: " + user_response, color, [50,280],25)

			if(tweet_sentiment[tweet_number] == "positive"):
				color = green
			elif(tweet_sentiment[tweet_number] == "negative"):
				color = red
			else:
				color = black
			message_to_screen("System response: " + tweet_sentiment[tweet_number], color, [50,310],25)
			response_printed = 1

		if(response_printed == 1):
			color = red
			if(user_response == tweet_sentiment[tweet_number]):
				color = green
				message_to_print = "Congratulations your answer matched the system response!!"
				if(save_to_file==1):
					sentimentAnalysis.update_train_data(tweet_question[tweet_number], tweet_sentiment[tweet_number])
			else:
				message_to_print = "Sorry, your answer didn't match the system response."
				# If the answers don't match but the overall sentiment matches, we add it to the train data
				if(user_response == returnedresult[0] and save_to_file ==1):
					sentimentAnalysis.update_train_data(tweet_question[tweet_number], user_response)
			message_to_screen(message_to_print, color, [50,360],25)
			message_to_screen("Press (Y) to see another tweet from the same query...", black, [50,420],20)
			message_to_screen("Press (E) to enter a new query...", black, [50,440],20)

	elif(screen == 3):
		message_to_screen("Screen 3 now: I guess this will contain, do you want to play again portion", black, [100, 50], 30)

	# Update is where it gets shown to the user
	pygame.display.update()
pygame.quit()
quit()


text:
=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package Bio::EnsEMBL::EGPipeline::FileDump::GTFDumper;

use strict;
use warnings;
use base ('Bio::EnsEMBL::EGPipeline::FileDump::BaseDumper');

use Bio::EnsEMBL::Utils::IO::GTFSerializer;

use Path::Tiny qw(path);

sub param_defaults {
  my ($self) = @_;

  return {
    %{$self->SUPER::param_defaults},
    'data_type'        => 'basefeatures',
    'file_type'        => 'gtf',
    'logic_name'       => [],
  };
}

sub run {
  my ($self) = @_;
  my $species     = $self->param_required('species');
  my $db_type     = $self->param_required('db_type');
  my $out_file    = $self->param_required('out_file');
  my $logic_names = $self->param_required('logic_name');

  my $reg = 'Bio::EnsEMBL::Registry';

  my $sa = $reg->get_adaptor($species, $db_type, 'Slice');
  my $slices = $sa->fetch_all('toplevel');

  open(my $out_fh, '>', $out_file) or $self->throw("Cannot open file $out_file: $!");
  my $serializer = Bio::EnsEMBL::Utils::IO::GTFSerializer->new($out_fh);
  $serializer->print_main_header($self->get_DBAdaptor($db_type));

  foreach my $slice (@$slices) {
    my @genes;

    if (scalar(@$logic_names) == 0) {
      @genes = @{$slice->get_all_Genes(undef, undef, 1)};
    } else {
      foreach my $logic_name (@$logic_names) {
        push @genes, @{$slice->get_all_Genes($logic_name, undef, 1)};
      }
    }

    foreach my $gene (@genes) {
      $serializer->print_Gene($gene);
    }
  }

  close($out_fh);

  $self->remove_attributes($out_file);
}

sub remove_attributes {
  my ($self, $out_file) = @_;

  my $file = path($out_file);

  my @unwanted_atts = qw(
    \w+_biotype
    \w+_name
    \w+_source
    \w+_version
    exon_id
    protein_id
  );

  my $data = $file->slurp;
  foreach my $att (@unwanted_atts) {
    $data =~ s/\s*$att\s*"[^"]+";//gm;
  }
  $file->spew($data);
}

1;


text:
- Create a 3 minute skit

## Requirements
- 4-6 people per group
- Skit must be at least 3 minutes long
- (Not mandatory)Skit must be based on one of the topics covered in class ([list of clips](https://github.com/crazcalm/oral-english/tree/master/clips))
- (extra credit) Must use at least 10 words and 4 phrases used in previous lessons.
- Each person much speak for at least 30 seconds
- Must write a script

### Script

- Must have the name and student ID of each member in the group
- Format should be similar to the scripts presented in class ([Example](https://github.com/crazcalm/oral-english/blob/master/clips/protect_your_home.md))
- Must have a word bank
- Must have a phrase bank

## Grading

|max points| category|Explanation|
|----------|---------|-----------|
|3|Time met| 1 point for each minute|
|1|individual speaking |Did you speak for at least 30 seconds?|
|2|Words|Did you use at least 2 words from previous lessons? 1 point for each word|
|3|Performance|How well did you know your lines? 1 = Not at all, 2 = mostly, 3 = perfectly|
|3|Script|1 point for the word bank. 1 point for the phrases section. 1 point for the script|

## Final Grade:

- Max points = 10
- Possible Extra credit points = 2


text:
(function() {

    var spotify = angular.module('spotify', []);

    spotify.factory('SpotifyAuth', function($rootScope, $window) {

        var LS_SPOTIFY_AUTH = 'spotify.auth',
            spotifyAuthString = $window.localStorage.getItem(LS_SPOTIFY_AUTH);

        var spotifyAuth = spotifyAuthString ? JSON.parse(spotifyAuthString) : {
            access_token : undefined,
            refresh_token : undefined
        }

        $rootScope.$watch(function() { return spotifyAuth; }, function() {
            console.info('SpotifyAuth::$watch : ', spotifyAuth);
            $window.localStorage.setItem(LS_SPOTIFY_AUTH, JSON.stringify(spotifyAuth));
        }, true);

        return spotifyAuth;
    });

    spotify.factory('SpotifyAuthService', function(SpotifyAuth) {

        return {
            isAuthenticated : function() {},
            authenticate : function(auth) {
                SpotifyAuth.access_token = auth.access_token;
                SpotifyAuth.refresh_token = auth.refresh_token;
            },
            login : function() {
                window.location = "/login";
            },
            logout : function() {
                SpotifyAuth.access_token = undefined;
                SpotifyAuth.refresh_token = undefined;
                this.login();
            },
            refreshToken : function() {}
        }
    });

    spotify.factory('SpotifyService', function($http, SpotifyAuth) {

        var API_BASE_URL = "https://api.spotify.com";

        return {
            browseNewReleases : function() {
                return $http.get(API_BASE_URL + '/v1/browse/new-releases?country=FR', {
                    headers : {
                        'Authorization' : 'Bearer ' + SpotifyAuth.access_token
                    }
                });
            },
            album : function(id) {
                return $http.get(API_BASE_URL + '/v1/albums/' + id);
            }
        }
    })

    .factory('SpotifyHttpLogInterceptor', ['$q', function($q) {
        return {
            'response': function(response) {
                if (response.config.url.indexOf('https://api.spotify.com') == 0) { // On ne log que les appels à l'api
                    console.info(response.config.method + " " + response.config.url + " " + response.status + " : ", response.data);
                }
                return response;
            },
            'responseError': function(rejection) {
                if (rejection.config.url.indexOf('https://api.spotify.com') == 0) { // On ne log que les appels à l'api
                    console.error(rejection.config.method + " " + rejection.config.url + " " + rejection.status + " : ", rejection.data);
                }
                return $q.reject(rejection);
            }
        }
    }])
    .config(['$httpProvider', function($httpProvider) {
        $httpProvider.interceptors.push('SpotifyHttpLogInterceptor');
    }])

}());


text:
#ifndef HAL_NFC_H__
#define HAL_NFC_H__

/** @file
 * @defgroup nfc_t4t_hal NFC Type 4 Tag HAL
 * @{
 * @ingroup nfc_t4t
 * @brief @tagAPI52 Hardware abstraction layer for the NFC Type 4 Tag library.
 *
 * @note Before the NFCT peripheral enters ACTIVATED state, the HFXO must be running.
 * To fulfill this requirement and allow other software modules to also request the HFXO, the NFC Type 4 Tag HAL uses @ref nrf_drv_clock module.
 *
 */

#include <stdint.h>
#include <string.h>
#include <sdk_errors.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @brief Events passed to the upper-layer callback function. */
typedef enum {
    HAL_NFC_EVENT_FIELD_ON,           ///< Field is detected.
    HAL_NFC_EVENT_FIELD_OFF,          ///< Field is lost.
    HAL_NFC_EVENT_DATA_RECEIVED,      ///< Data is received.
    HAL_NFC_EVENT_DATA_TRANSMITTED    ///< Data is transmitted.
} hal_nfc_event_t;

/** @brief Parameter IDs for the set/get function. */
typedef enum {
    HAL_NFC_PARAM_ID_TESTING,         ///< Used for unit tests.
    HAL_NFC_PARAM_FWI,                ///< Frame Wait Time parameter.
    HAL_NFC_PARAM_SELRES,             ///< Parameter for setting the 'Protocol' bits for SEL_RES packet.
    HAL_NFC_PARAM_ID_UNKNOWN
} hal_nfc_param_id_t;

/** @brief Callback from HAL_NFC layer into the upper layer.
  *
  * If event == HAL_NFC_EVENT_DATA_RECEIVED:
  * p_data points to the received packet. The memory belongs to the HAL_NFC layer and
  * is guaranteed to be valid only until the callback returns.
  *
  * If event == HAL_NFC_EVENT_DATA_TRANSMITTED:
  * p_data points to the transmitted packet. The memory belongs to the application.
  *
  * If event == \<Other event\>:
  * p_data definition is event-specific (to be defined).
  *
  * @param[in] p_context    Context for callback execution.
  * @param[in] event        The event that occurred.
  * @param[in] p_data       Received/transmitted data or NULL.
  * @param[in] data_length  Size of the received/transmitted packet.
  */
typedef void (* hal_nfc_callback_t)(void          * p_context,
                                    hal_nfc_event_t event,
                                    const uint8_t * p_data,
                                    size_t          data_length);

/** @brief Function for initializing the NFC layer.
  *
  * This function provides a pointer to a callback function and the callback context
  * to the NFC layer.
  *
  * @param[in] callback     Pointer to the callback function.
  * @param[in] p_context    Context of callback.
  *
  * @retval NRF_SUCCESS If the NFC layer was initialized successfully.  If one
  *                     of the arguments was invalid, an error code is returned.
  */
ret_code_t hal_nfc_setup(hal_nfc_callback_t callback, void * p_context);

/** @brief Function for setting a HAL_NFC parameter.
  *
  * This function allows to set any parameter defined as available by HAL_NFC.
  *
  * @param[in] id           ID of the parameter to set.
  * @param[in] p_data       Pointer to the buffer containing the data to set.
  * @param[in] data_length  Size of the buffer containing the data to set.
  *
  * @retval NRF_SUCCESS If the parameter was set successfully. If one of the arguments
  *                     was invalid (for example, wrong data length), an error code
  *                     is returned.
  */
ret_code_t hal_nfc_parameter_set(hal_nfc_param_id_t id, void * p_data, size_t data_length);

/** @brief Function for querying a HAL_NFC parameter value.
  *
  * The queried value will be placed into the passed data buffer. If the buffer
  * is too small, p_max_data_length will contain the required buffer size.
  *
  * @param[in]      id                ID of the parameter to query.
  * @param[in, out] p_data            Pointer to a buffer receiving the queried data.
  * @param[in, out] p_max_data_length Size of the buffer. It receives the required size if buffer is too small.
  *
  * @retval NRF_SUCCESS If the parameter was received successfully. If one of the arguments
  *                     was invalid (for example, the buffer was too small), an error code
  *                     is returned.
  */
ret_code_t hal_nfc_parameter_get(hal_nfc_param_id_t id, void * p_data, size_t * p_max_data_length);

/** @brief Function for starting the NFC subsystem.
  *
  * After this function completes, NFC readers will be able to detect the chip.
  *
  * @retval NRF_SUCCESS If the NFC subsystem was started successfully. If the NFC
  *                     subsystem could not be started, an error code is returned.
  */
ret_code_t hal_nfc_start(void);

/** @brief Function for sending a packet to the connected NFC reader.
  *
  * The provided data buffer belongs to the caller and is guaranteed to be
  * valid until the HAL_NFC_EVENT_DATA_TRANSMITTED event is received by the
  * callback.
  *
  * @param[in] p_data       The data packet to send.
  * @param[in] data_length  Size of the packet in bytes.
  *
  * @retval NRF_SUCCESS If the packet was sent. Otherwise, an error code is returned.
  */
ret_code_t hal_nfc_send(const uint8_t * p_data, size_t data_length);

/** @brief Function for stopping the NFC subsystem.
  *
  * After this function returns, NFC readers will no longer be able to connect
  * to the chip.
  *
  * @retval NRF_SUCCESS If the NFC subsystem was stopped. Otherwise, an error code
  *                     is returned.
  */
ret_code_t hal_nfc_stop(void);

/** @brief Function for releasing resources.
  *
  * After this call returns, the callback is considered invalid and no more
  * events will be posted to it.
  *
  * @retval NRF_SUCCESS This function always succeeds.
  */
ret_code_t hal_nfc_done(void);

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* HAL_NFC_H__ */


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>net.officefloor.benchmarks</groupId>
		<artifactId>benchmarks</artifactId>
		<version>1.0.0</version>
	</parent>
	<artifactId>woof_benchmark</artifactId>
	<dependencies>
		<dependency>
			<groupId>net.officefloor.web</groupId>
			<artifactId>woof</artifactId>
		</dependency>
		<dependency>
			<groupId>net.officefloor.web</groupId>
			<artifactId>officejson_jackson</artifactId>
		</dependency>
		<dependency>
			<groupId>net.officefloor.persistence</groupId>
			<artifactId>officejpa_hibernate</artifactId>
		</dependency>
		<dependency>
			<groupId>net.officefloor.persistence</groupId>
			<artifactId>officejdbc_postgresql</artifactId>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<transformers>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
									<mainClass>net.officefloor.OfficeFloorMain</mainClass>
								</transformer>
							</transformers>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>


text:
#include "EfiShellLib.h"
#include "Pci22.h"
#include "pci_class.h"
#include "pci.h"
#include "Acpi.h"

extern UINT8      STRING_ARRAY_NAME[];

//
// This is the generated header file which includes whatever needs to be exported (strings + IFR)
//
#include STRING_DEFINES_FILE

#include EFI_PROTOCOL_DEFINITION (PciRootBridgeIo)

EFI_STATUS
PciDump (
  IN EFI_HANDLE                             ImageHandle,
  IN EFI_SYSTEM_TABLE                       *SystemTable
  );

EFI_STATUS
PciFindProtocolInterface (
  IN  EFI_HANDLE                            *HandleBuf,
  IN  UINTN                                 HandleCount,
  IN  UINT16                                Segment,
  IN  UINT16                                Bus,
  OUT EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL       **IoDev
  );

EFI_STATUS
PciGetProtocolAndResource (
  IN  EFI_HANDLE                            Handle,
  OUT EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL       **IoDev,
  OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR     **Descriptors
  );

EFI_STATUS
PciGetNextBusRange (
  IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR  **Descriptors,
  OUT    UINT16                             *MinBus,
  OUT    UINT16                             *MaxBus,
  OUT    BOOLEAN                            *IsEnd
  );

EFI_STATUS
PciExplainData (
  IN PCI_CONFIG_SPACE                       *ConfigSpace,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  );

EFI_STATUS
PciExplainDeviceData (
  IN PCI_DEVICE_HEADER                      *Device,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  );

EFI_STATUS
PciExplainBridgeData (
  IN PCI_BRIDGE_HEADER                      *Bridge,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  );

EFI_STATUS
PciExplainBar (
  IN UINT32                                 *Bar,
  IN UINT16                                 *Command,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,
  IN OUT UINTN                              *Index
  );

EFI_STATUS
PciExplainCardBusData (
  IN PCI_CARDBUS_HEADER                     *CardBus,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  );

EFI_STATUS
PciExplainStatus (
  IN UINT16                                 *Status,
  IN BOOLEAN                                MainStatus,
  IN PCI_HEADER_TYPE                        HeaderType
  );

EFI_STATUS
PciExplainCommand (
  IN UINT16                                 *Command
  );

EFI_STATUS
PciExplainBridgeControl (
  IN UINT16                                 *BridgeControl,
  IN PCI_HEADER_TYPE                        HeaderType
  );

EFI_STATUS
PciExplainCapabilityStruct (
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
  IN UINT64                                   Address,
  IN  UINT8                                   CapPtr
  );

EFI_STATUS
PciExplainPciExpress (
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
  IN  UINT64                                  Address,
  IN  UINT8                                   CapabilityPtr
  );

//
// Global Variables
//
PCI_CONFIG_SPACE  *mConfigSpace;
EFI_HII_HANDLE    HiiHandle;
EFI_GUID          EfiPciGuid = EFI_PCI_GUID;
SHELL_VAR_CHECK_ITEM    PciCheckList[] = {
  {
    L"-s",
    0x01,
    0,
    FlagTypeNeedVar
  },
  {
    L"-i",
    0x02,
    0,
    FlagTypeSingle
  },
  {
    L"-b",
    0x04,
    0,
    FlagTypeSingle
  },
  {
    L"-?",
    0x08,
    0,
    FlagTypeSingle
  },
  {
    NULL,
    0,
    0,
    0
  }
};

EFI_BOOTSHELL_CODE(
  EFI_APPLICATION_ENTRY_POINT(PciDump)
)

EFI_STATUS
PciDump (
  IN EFI_HANDLE                             ImageHandle,
  IN EFI_SYSTEM_TABLE                       *SystemTable
  )
/*++

Routine Description:

  Command entry point. Parses command line arguments and execute it. If
  needed, calls internal function to perform certain operation.

Arguments:

  ImageHandle     The image handle.
  SystemTable     The system table.

Returns:

  EFI_SUCCESS           - The command completed successfully
  EFI_INVALID_PARAMETER - Invalid parameter
  EFI_OUT_OF_RESOURCES  - Out of resources

--*/
{
  UINT16                            Segment;
  UINT16                            Bus;
  UINT16                            Device;
  UINT16                            Func;
  UINT64                            Address;
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *IoDev;
  EFI_STATUS                        Status;
  PCI_COMMON_HEADER                 PciHeader;
  PCI_CONFIG_SPACE                  ConfigSpace;
  UINTN                             ScreenCount;
  UINTN                             TempColumn;
  UINTN                             ScreenSize;
  BOOLEAN                           ExplainData;
  UINTN                             Index;
  UINTN                             SizeOfHeader;
  BOOLEAN                           PrintTitle;
  UINTN                             HandleBufSize;
  EFI_HANDLE                        *HandleBuf;
  UINTN                             HandleCount;
  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
  UINT16                            MinBus;
  UINT16                            MaxBus;
  BOOLEAN                           IsEnd;

  SHELL_VAR_CHECK_CODE              RetCode;
  CHAR16                            *Useful;
  SHELL_ARG_LIST                    *Item;
  SHELL_VAR_CHECK_PACKAGE           ChkPck;

  IoDev = NULL;
  HandleBuf = NULL;
  ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE));
  EFI_SHELL_APP_INIT (ImageHandle, SystemTable);

  //
  // Enable tab key which can pause the output
  //
  EnableOutputTabPause();

  Status = LibInitializeStrings (&HiiHandle, STRING_ARRAY_NAME, &EfiPciGuid);

  if (EFI_ERROR (Status)) {
    return Status;
  }

  if (!EFI_PROPER_VERSION (0, 99)) {
    PrintToken (
      STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT),
      HiiHandle,
      L"pci",
      EFI_VERSION_0_99
      );
    Status = EFI_UNSUPPORTED;
    goto Done;
  }

  RetCode = LibCheckVariables (SI, PciCheckList, &ChkPck, &Useful);
  if (VarCheckOk != RetCode) {
    switch (RetCode) {
    case VarCheckUnknown:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"pci", Useful);
      break;

    case VarCheckDuplicate:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"pci", Useful);
      break;

    case VarCheckLackValue:
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_LACK_ARG), HiiHandle, L"pci", Useful);
      break;

    default:
      break;
    }

    Status = EFI_INVALID_PARAMETER;
    goto Done;
  }
  //
  // Out put help.
  //
  if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) {
    EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
  }

  if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) {
    if (ChkPck.ValueCount > 0 ||
        ChkPck.FlagCount > 2 ||
        (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b"))
        ) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"pci");
      Status = EFI_INVALID_PARAMETER;
    } else {
      PrintToken (STRING_TOKEN (STR_HELPINFO_PCI_VERBOSEHELP), HiiHandle);
      Status = EFI_SUCCESS;
    }

    goto Done;
  }
  //
  // Get all instances of PciRootBridgeIo. Allocate space for 1 EFI_HANDLE and
  // call LibLocateHandle(), if EFI_BUFFER_TOO_SMALL is returned, allocate enough
  // space for handles and call it again.
  //
  HandleBufSize = sizeof (EFI_HANDLE);
  HandleBuf     = (EFI_HANDLE *) AllocatePool (HandleBufSize);
  if (HandleBuf == NULL) {
    PrintToken (STRING_TOKEN (STR_PCI2_OUT_RESOURCES), HiiHandle);
    Status = EFI_OUT_OF_RESOURCES;
    goto Done;
  }

  Status = BS->LocateHandle (
                ByProtocol,
                &gEfiPciRootBridgeIoProtocolGuid,
                NULL,
                &HandleBufSize,
                HandleBuf
                );

  if (Status == EFI_BUFFER_TOO_SMALL) {
    HandleBuf = ReallocatePool (HandleBuf, sizeof (EFI_HANDLE), HandleBufSize);
    if (HandleBuf == NULL) {
      PrintToken (STRING_TOKEN (STR_PCI2_OUT_RESOURCES), HiiHandle);
      Status = EFI_OUT_OF_RESOURCES;
      goto Done;
    }

    Status = BS->LocateHandle (
                  ByProtocol,
                  &gEfiPciRootBridgeIoProtocolGuid,
                  NULL,
                  &HandleBufSize,
                  HandleBuf
                  );
  }

  if (EFI_ERROR (Status)) {
    PrintToken (STRING_TOKEN (STR_PCI2_LOCATE_HANDLE), HiiHandle, Status);
    goto Done;
  }

  HandleCount = HandleBufSize / sizeof (EFI_HANDLE);
  //
  // Argument Count == 1(no other argument): enumerate all pci functions
  //
  if (ChkPck.ValueCount == 0) {
    ST->ConOut->QueryMode (
                  ST->ConOut,
                  ST->ConOut->Mode->Mode,
                  &TempColumn,
                  &ScreenSize
                  );

    ScreenCount = 0;
    ScreenSize -= 4;
    if ((ScreenSize & 1) == 1) {
      ScreenSize -= 1;
    }

    PrintTitle = TRUE;

    //
    // For each handle, which decides a segment and a bus number range,
    // enumerate all devices on it.
    //
    for (Index = 0; Index < HandleCount; Index++) {
      Status = PciGetProtocolAndResource (
                HandleBuf[Index],
                &IoDev,
                &Descriptors
                );
      if (EFI_ERROR (Status)) {
        PrintToken (STRING_TOKEN (STR_PCI2_HANDLE_PROTOCOL), HiiHandle, Status);
        goto Done;
      }
      //
      // No document say it's impossible for a RootBridgeIo protocol handle
      // to have more than one address space descriptors, so find out every
      // bus range and for each of them do device enumeration.
      //
      while (TRUE) {
        Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd);

        if (EFI_ERROR (Status)) {
          PrintToken (STRING_TOKEN (STR_PCI2_BUS), HiiHandle, Status);
          goto Done;
        }

        if (IsEnd) {
          break;
        }

        for (Bus = MinBus; Bus <= MaxBus; Bus++) {
          //
          // For each devices, enumerate all functions it contains
          //
          for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
            //
            // For each function, read its configuration space and print summary
            //
            for (Func = 0; Func <= PCI_MAX_FUNC; Func++) {
              Address = CALC_EFI_PCI_ADDRESS (Bus, Device, Func, 0);
              IoDev->Pci.Read (
                          IoDev,
                          EfiPciWidthUint16,
                          Address,
                          1,
                          &PciHeader.VendorId
                          );

              //
              // If VendorId = 0xffff, there does not exist a device at this
              // location. For each device, if there is any function on it,
              // there must be 1 function at Function 0. So if Func = 0, there
              // will be no more functions in the same device, so we can break
              // loop to deal with the next device.
              //
              if (PciHeader.VendorId == 0xffff && Func == 0) {
                break;
              }

              if (PciHeader.VendorId != 0xffff) {

                if (PrintTitle) {
                  PrintToken (STRING_TOKEN (STR_PCI2_SEG_BUS), HiiHandle);
                  Print (L"   ---  ---  ---  ----\n");
                  PrintTitle = FALSE;
                }

                IoDev->Pci.Read (
                            IoDev,
                            EfiPciWidthUint32,
                            Address,
                            sizeof (PciHeader) / sizeof (UINT32),
                            &PciHeader
                            );

                PrintToken (
                  STRING_TOKEN (STR_PCI2_FOUR_VARS),
                  HiiHandle,
                  IoDev->SegmentNumber,
                  Bus,
                  Device,
                  Func
                  );

                PciPrintClassCode (PciHeader.ClassCode, FALSE);
                PrintToken (
                  STRING_TOKEN (STR_PCI2_VENDOR),
                  HiiHandle,
                  PciHeader.VendorId,
                  PciHeader.DeviceId,
                  PciHeader.ClassCode[0]
                  );

                ScreenCount += 2;
                if (ScreenCount >= ScreenSize && ScreenSize != 0) {
                  //
                  // If ScreenSize == 0 we have the console redirected so don't
                  //  block updates
                  //
                  ScreenCount = 0;
                }
                //
                // If this is not a multi-function device, we can leave the loop
                // to deal with the next device.
                //
                if (Func == 0 && ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) {
                  break;
                }
              }
            }
          }
        }
        //
        // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED,
        // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all
        // devices on all bus, we can leave loop.
        //
        if (Descriptors == NULL) {
          break;
        }
      }
    }

    Status = EFI_SUCCESS;
    goto Done;
  }

  if (ChkPck.ValueCount == 1) {
    PrintToken (STRING_TOKEN (STR_PCI2_TOO_FEW_ARGS), HiiHandle);
    Status = EFI_INVALID_PARAMETER;
    goto Done;
  }
  //
  // Arg count >= 3, dump binary of specified function, interpret if necessary
  //
  if (ChkPck.ValueCount > 3) {
    PrintToken (STRING_TOKEN (STR_PCI2_TOO_MANY_ARGS), HiiHandle);
    Status = EFI_INVALID_PARAMETER;
    goto Done;
  }

  ExplainData                   = FALSE;
  Segment                       = 0;
  Bus                           = 0;
  Device                        = 0;
  Func                          = 0;
  if (LibCheckVarGetFlag (&ChkPck, L"-i") != NULL) {
    ExplainData = TRUE;
  }

  Item = LibCheckVarGetFlag (&ChkPck, L"-s");
  if (NULL != Item) {
    Segment = (UINT16) StrToUIntegerBase (Item->VarStr, 16, &Status);
    if (EFI_ERROR (Status)) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"pci", Item->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    }
  }

  //
  // The first Argument(except "-i") is assumed to be Bus number, second
  // to be Device number, and third to be Func number.
  //
  Item = ChkPck.VarList;
  if (NULL != Item) {
    Bus = (UINT16) StrToUIntegerBase (Item->VarStr, 16, &Status);
    if (EFI_ERROR (Status) || Bus > MAX_BUS_NUMBER) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"pci", Item->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    }

    Item = Item->Next;
  }

  if (NULL != Item) {
    Device = (UINT16) StrToUIntegerBase (Item->VarStr, 16, &Status);
    if (EFI_ERROR (Status) || Device > MAX_DEVICE_NUMBER) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"pci", Item->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    }

    Item = Item->Next;
  }

  if (NULL != Item) {
    Func = (UINT16) StrToUIntegerBase (Item->VarStr, 16, &Status);
    if (EFI_ERROR (Status) || Func > MAX_FUNCTION_NUMBER) {
      PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"pci", Item->VarStr);
      Status = EFI_INVALID_PARAMETER;
      goto Done;
    }
  }

  //
  // Find the protocol interface who's in charge of current segment, and its
  // bus range covers the current bus
  //
  Status = PciFindProtocolInterface (
            HandleBuf,
            HandleCount,
            Segment,
            Bus,
            &IoDev
            );

  if (EFI_ERROR (Status)) {
    PrintToken (
      STRING_TOKEN (STR_PCI2_CANNOT_FIND_PROTOCOL),
      HiiHandle,
      Segment,
      Bus
      );

    goto Done;
  }

  Address = CALC_EFI_PCI_ADDRESS (Bus, Device, Func, 0);
  Status = IoDev->Pci.Read (
                        IoDev,
                        EfiPciWidthUint8,
                        Address,
                        sizeof (ConfigSpace),
                        &ConfigSpace
                        );

  if (EFI_ERROR (Status)) {
    PrintToken (STRING_TOKEN (STR_PCI2_CANNOT_READ_CONFIG), HiiHandle, Status);
    goto Done;
  }

  mConfigSpace = &ConfigSpace;
  PrintToken (
    STRING_TOKEN (STR_PCI2_SEGMENT_BUS),
    HiiHandle,
    Segment,
    Bus,
    Device,
    Func,
    Segment,
    Bus,
    Device,
    Func
    );

  //
  // Dump standard header of configuration space
  //
  SizeOfHeader = sizeof (ConfigSpace.Common) + sizeof (ConfigSpace.NonCommon);

  DumpHex (2, 0, SizeOfHeader, &ConfigSpace);
  Print (L"\n");

  //
  // Dump device dependent Part of configuration space
  //
  DumpHex (
    2,
    SizeOfHeader,
    sizeof (ConfigSpace) - SizeOfHeader,
    ConfigSpace.Data
    );

  //
  // If "-i" appears in command line, interpret data in configuration space
  //
  if (ExplainData) {
    Status = PciExplainData (&ConfigSpace, Address, IoDev);
  }
Done:
  if (HandleBuf != NULL) {
    FreePool (HandleBuf);
  }
  LibCheckVarFreeVarList (&ChkPck);
  LibUnInitializeStrings ();
  return Status;
}

EFI_STATUS
PciFindProtocolInterface (
  IN  EFI_HANDLE                            *HandleBuf,
  IN  UINTN                                 HandleCount,
  IN  UINT16                                Segment,
  IN  UINT16                                Bus,
  OUT EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL       **IoDev
  )
/*++

Routine Description:

  This function finds out the protocol which is in charge of the given
  segment, and its bus range covers the current bus number. It lookes
  each instances of RootBridgeIoProtocol handle, until the one meets the
  criteria is found.

Arguments:

  HandleBuf       Buffer which holds all PCI_ROOT_BRIDIGE_IO_PROTOCOL handles
  HandleCount     Count of all PCI_ROOT_BRIDIGE_IO_PROTOCOL handles
  Segment         Segment number of device we are dealing with
  Bus             Bus number of device we are dealing with
  IoDev           Handle used to access configuration space of PCI device

Returns:

  EFI_SUCCESS           - The command completed successfully
  EFI_INVALID_PARAMETER - Invalid parameter

--*/
{
  UINTN                             Index;
  EFI_STATUS                        Status;
  BOOLEAN                           FoundInterface;
  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
  UINT16                            MinBus;
  UINT16                            MaxBus;
  BOOLEAN                           IsEnd;

  FoundInterface = FALSE;
  //
  // Go through all handles, until the one meets the criteria is found
  //
  for (Index = 0; Index < HandleCount; Index++) {
    Status = PciGetProtocolAndResource (HandleBuf[Index], IoDev, &Descriptors);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    //
    // When Descriptors == NULL, the Configuration() is not implemented,
    // so we only check the Segment number
    //
    if (Descriptors == NULL && Segment == (*IoDev)->SegmentNumber) {
      return EFI_SUCCESS;
    }

    if ((*IoDev)->SegmentNumber != Segment) {
      continue;
    }

    while (TRUE) {
      Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd);
      if (EFI_ERROR (Status)) {
        return Status;
      }

      if (IsEnd) {
        break;
      }

      if (MinBus <= Bus && MaxBus >= Bus) {
        FoundInterface = TRUE;
        break;
      }
    }
  }

  if (FoundInterface) {
    return EFI_SUCCESS;
  } else {
    return EFI_INVALID_PARAMETER;
  }
}

EFI_STATUS
PciGetProtocolAndResource (
  IN  EFI_HANDLE                            Handle,
  OUT EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL       **IoDev,
  OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR     **Descriptors
  )
/*++

Routine Description:

  This function gets the protocol interface from the given handle, and
  obtains its address space descriptors.

Arguments:

  Handle          The PCI_ROOT_BRIDIGE_IO_PROTOCOL handle
  IoDev           Handle used to access configuration space of PCI device
  Descriptors     Points to the address space descriptors

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  EFI_STATUS  Status;

  //
  // Get inferface from protocol
  //
  Status = BS->HandleProtocol (
                Handle,
                &gEfiPciRootBridgeIoProtocolGuid,
                IoDev
                );

  if (EFI_ERROR (Status)) {
    return Status;
  }
  //
  // Call Configuration() to get address space descriptors
  //
  Status = (*IoDev)->Configuration (*IoDev, Descriptors);
  if (Status == EFI_UNSUPPORTED) {
    *Descriptors = NULL;
    return EFI_SUCCESS;

  } else {
    return Status;
  }
}

EFI_STATUS
PciGetNextBusRange (
  IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR  **Descriptors,
  OUT    UINT16                             *MinBus,
  OUT    UINT16                             *MaxBus,
  OUT    BOOLEAN                            *IsEnd
  )
/*++

Routine Description:

  This function get the next bus range of given address space descriptors.
  It also moves the pointer backward a node, to get prepared to be called
  again.

Arguments:

  Descriptors     points to current position of a serial of address space
                  descriptors
  MinBus          The lower range of bus number
  ManBus          The upper range of bus number
  IsEnd           Meet end of the serial of descriptors

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  *IsEnd = FALSE;

  //
  // When *Descriptors is NULL, Configuration() is not implemented, so assume
  // range is 0~PCI_MAX_BUS
  //
  if ((*Descriptors) == NULL) {
    *MinBus = 0;
    *MaxBus = PCI_MAX_BUS;
    return EFI_SUCCESS;
  }
  //
  // *Descriptors points to one or more address space descriptors, which
  // ends with a end tagged descriptor. Examine each of the descriptors,
  // if a bus typed one is found and its bus range covers bus, this handle
  // is the handle we are looking for.
  //
  if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) {
    *IsEnd = TRUE;
  }

  while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) {
    if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) {
      *MinBus = (UINT16) (*Descriptors)->AddrRangeMin;
      *MaxBus = (UINT16) (*Descriptors)->AddrRangeMax;
    }

    (*Descriptors)++;
  }

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainData (
  IN PCI_CONFIG_SPACE                       *ConfigSpace,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  )
/*++

Routine Description:

  Explain the data in PCI configuration space. The part which is common for
  PCI device and bridge is interpreted in this function. It calls other
  functions to interpret data unique for device or bridge.

Arguments:

  ConfigSpace     Data in PCI configuration space
  Address         Address used to access configuration space of this PCI device
  IoDev           Handle used to access configuration space of PCI device

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  PCI_COMMON_HEADER *Common;
  PCI_HEADER_TYPE   HeaderType;
  EFI_STATUS        Status;
  UINT8             CapPtr;

  Common = &(ConfigSpace->Common);

  Print (L"\n");

  //
  // Print Vendor Id and Device Id
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_VENDOR_ID),
    HiiHandle,
    INDEX_OF (&(Common->VendorId)),
    Common->VendorId
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_DEVICE_ID),
    HiiHandle,
    INDEX_OF (&(Common->DeviceId)),
    Common->DeviceId
    );

  //
  // Print register Command
  //
  PciExplainCommand (&(Common->Command));

  //
  // Print register Status
  //
  PciExplainStatus (&(Common->Status), TRUE, PciUndefined);

  //
  // Print register Revision ID
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_REVISION_ID),
    HiiHandle,
    INDEX_OF (&(Common->RevisionId)),
    Common->RevisionId
    );

  //
  // Print register BIST
  //
  PrintToken (STRING_TOKEN (STR_PCI2_BIST), HiiHandle, INDEX_OF (&(Common->BIST)));
  if ((Common->BIST & PCI_BIT_7) != 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_CAPABLE_RETURN), HiiHandle, 0x0f & Common->BIST);

  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_INCAPABLE), HiiHandle);
  }
  //
  // Print register Cache Line Size
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_CACHE_LINE_SIZE),
    HiiHandle,
    INDEX_OF (&(Common->CacheLineSize)),
    Common->CacheLineSize
    );

  //
  // Print register Latency Timer
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_LATENCY_TIMER),
    HiiHandle,
    INDEX_OF (&(Common->PrimaryLatencyTimer)),
    Common->PrimaryLatencyTimer
    );

  //
  // Print register Header Type
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_HEADER_TYPE),
    HiiHandle,
    INDEX_OF (&(Common->HeaderType)),
    Common->HeaderType
    );

  if ((Common->HeaderType & PCI_BIT_7) != 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_MULTI_FUNCTION), HiiHandle);

  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_SINGLE_FUNCTION), HiiHandle);
  }

  HeaderType = (UINT8) (Common->HeaderType & 0x7f);
  switch (HeaderType) {
  case PciDevice:
    PrintToken (STRING_TOKEN (STR_PCI2_PCI_DEVICE), HiiHandle);
    break;

  case PciP2pBridge:
    PrintToken (STRING_TOKEN (STR_PCI2_P2P_BRIDGE), HiiHandle);
    break;

  case PciCardBusBridge:
    PrintToken (STRING_TOKEN (STR_PCI2_CARDBUS_BRIDGE), HiiHandle);
    break;

  default:
    PrintToken (STRING_TOKEN (STR_PCI2_RESERVED), HiiHandle);
    HeaderType = PciUndefined;
  }

  //
  // Print register Class Code
  //
  PrintToken (STRING_TOKEN (STR_PCI2_CLASS), HiiHandle);
  PciPrintClassCode ((UINT8 *) Common->ClassCode, TRUE);
  Print (L"\n");

  //
  // Interpret remaining part of PCI configuration header depending on
  // HeaderType
  //
  CapPtr  = 0;
  Status  = EFI_SUCCESS;
  switch (HeaderType) {
  case PciDevice:
    Status = PciExplainDeviceData (
              &(ConfigSpace->NonCommon.Device),
              Address,
              IoDev
              );
    CapPtr = ConfigSpace->NonCommon.Device.CapabilitiesPtr;
    break;

  case PciP2pBridge:
    Status = PciExplainBridgeData (
              &(ConfigSpace->NonCommon.Bridge),
              Address,
              IoDev
              );
    CapPtr = ConfigSpace->NonCommon.Bridge.CapabilitiesPtr;
    break;

  case PciCardBusBridge:
    Status = PciExplainCardBusData (
              &(ConfigSpace->NonCommon.CardBus),
              Address,
              IoDev
              );
    CapPtr = ConfigSpace->NonCommon.CardBus.CapabilitiesPtr;
    break;
  }
  //
  // If Status bit4 is 1, dump or explain capability structure
  //
  if ((Common->Status) & EFI_PCI_STATUS_CAPABILITY) {
    PciExplainCapabilityStruct (IoDev, Address, CapPtr);
  }

  return Status;
}

EFI_STATUS
PciExplainDeviceData (
  IN PCI_DEVICE_HEADER                      *Device,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  )
/*++

Routine Description:

  Explain the device specific part of data in PCI configuration space.

Arguments:

  Device          Data in PCI configuration space
  Address         Address used to access configuration space of this PCI device
  IoDev           Handle used to access configuration space of PCI device

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  UINTN       Index;
  BOOLEAN     BarExist;
  EFI_STATUS  Status;
  UINTN       BarCount;

  //
  // Print Base Address Registers(Bar). When Bar = 0, this Bar does not
  // exist. If these no Bar for this function, print "none", otherwise
  // list detail information about this Bar.
  //
  PrintToken (STRING_TOKEN (STR_PCI2_BASE_ADDR), HiiHandle, INDEX_OF (Device->Bar));

  BarExist  = FALSE;
  BarCount  = sizeof (Device->Bar) / sizeof (Device->Bar[0]);
  for (Index = 0; Index < BarCount; Index++) {
    if (Device->Bar[Index] == 0) {
      continue;
    }

    if (!BarExist) {
      BarExist = TRUE;
      PrintToken (STRING_TOKEN (STR_PCI2_START_TYPE), HiiHandle);
      Print (L"  --------------------------------------------------------------------------");
    }

    Status = PciExplainBar (
              &(Device->Bar[Index]),
              &(mConfigSpace->Common.Command),
              Address,
              IoDev,
              &Index
              );

    if (EFI_ERROR (Status)) {
      break;
    }
  }

  if (!BarExist) {
    PrintToken (STRING_TOKEN (STR_PCI2_NONE), HiiHandle);

  } else {
    Print (L"\n  --------------------------------------------------------------------------");
  }

  //
  // Print register Expansion ROM Base Address
  //
  if ((Device->ROMBar & PCI_BIT_0) == 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_EXPANSION_ROM_DISABLED), HiiHandle, INDEX_OF (&(Device->ROMBar)));

  } else {
    PrintToken (
      STRING_TOKEN (STR_PCI2_EXPANSION_ROM_BASE),
      HiiHandle,
      INDEX_OF (&(Device->ROMBar)),
      Device->ROMBar
      );
  }
  //
  // Print register Cardbus CIS ptr
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_CARDBUS_CIS),
    HiiHandle,
    INDEX_OF (&(Device->CardBusCISPtr)),
    Device->CardBusCISPtr
    );

  //
  // Print register Sub-vendor ID and subsystem ID
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_SUB_VENDOR_ID),
    HiiHandle,
    INDEX_OF (&(Device->SubVendorId)),
    Device->SubVendorId
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_SUBSYSTEM_ID),
    HiiHandle,
    INDEX_OF (&(Device->SubSystemId)),
    Device->SubSystemId
    );

  //
  // Print register Capabilities Ptr
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_CAPABILITIES_PTR),
    HiiHandle,
    INDEX_OF (&(Device->CapabilitiesPtr)),
    Device->CapabilitiesPtr
    );

  //
  // Print register Interrupt Line and interrupt pin
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_INTERRUPT_LINE),
    HiiHandle,
    INDEX_OF (&(Device->InterruptLine)),
    Device->InterruptLine
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_INTERRUPT_PIN),
    HiiHandle,
    INDEX_OF (&(Device->InterruptPin)),
    Device->InterruptPin
    );

  //
  // Print register Min_Gnt and Max_Lat
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_MIN_GNT),
    HiiHandle,
    INDEX_OF (&(Device->MinGnt)),
    Device->MinGnt
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_MAX_LAT),
    HiiHandle,
    INDEX_OF (&(Device->MaxLat)),
    Device->MaxLat
    );

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainBridgeData (
  IN  PCI_BRIDGE_HEADER                     *Bridge,
  IN  UINT64                                Address,
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL       *IoDev
  )
/*++

Routine Description:

  Explain the bridge specific part of data in PCI configuration space.

Arguments:

  Bridge          Bridge specific data region in PCI configuration space
  Address         Address used to access configuration space of this PCI device
  IoDev           Handle used to access configuration space of PCI device

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  UINTN       Index;
  BOOLEAN     BarExist;
  UINTN       BarCount;
  UINT32      IoAddress32;
  EFI_STATUS  Status;

  //
  // Print Base Address Registers. When Bar = 0, this Bar does not
  // exist. If these no Bar for this function, print "none", otherwise
  // list detail information about this Bar.
  //
  PrintToken (STRING_TOKEN (STR_PCI2_BASE_ADDRESS), HiiHandle, INDEX_OF (&(Bridge->Bar)));

  BarExist  = FALSE;
  BarCount  = sizeof (Bridge->Bar) / sizeof (Bridge->Bar[0]);

  for (Index = 0; Index < BarCount; Index++) {
    if (Bridge->Bar[Index] == 0) {
      continue;
    }

    if (!BarExist) {
      BarExist = TRUE;
      PrintToken (STRING_TOKEN (STR_PCI2_START_TYPE_2), HiiHandle);
      Print (L"  --------------------------------------------------------------------------");
    }

    Status = PciExplainBar (
              &(Bridge->Bar[Index]),
              &(mConfigSpace->Common.Command),
              Address,
              IoDev,
              &Index
              );

    if (EFI_ERROR (Status)) {
      break;
    }
  }

  if (!BarExist) {
    PrintToken (STRING_TOKEN (STR_PCI2_NONE), HiiHandle);
  } else {
    Print (L"\n  --------------------------------------------------------------------------");
  }

  //
  // Expansion register ROM Base Address
  //
  if ((Bridge->ROMBar & PCI_BIT_0) == 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_NO_EXPANSION_ROM), HiiHandle, INDEX_OF (&(Bridge->ROMBar)));

  } else {
    PrintToken (
      STRING_TOKEN (STR_PCI2_EXPANSION_ROM_BASE_2),
      HiiHandle,
      INDEX_OF (&(Bridge->ROMBar)),
      Bridge->ROMBar
      );
  }
  //
  // Print Bus Numbers(Primary, Secondary, and Subordinate
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_BUS_NUMBERS),
    HiiHandle,
    INDEX_OF (&(Bridge->PrimaryBus)),
    INDEX_OF (&(Bridge->SecondaryBus)),
    INDEX_OF (&(Bridge->SubordinateBus))
    );

  Print (L"               ------------------------------------------------------\n");

  PrintToken (STRING_TOKEN (STR_PCI2_BRIDGE), HiiHandle, Bridge->PrimaryBus);
  PrintToken (STRING_TOKEN (STR_PCI2_BRIDGE), HiiHandle, Bridge->SecondaryBus);
  PrintToken (STRING_TOKEN (STR_PCI2_BRIDGE), HiiHandle, Bridge->SubordinateBus);

  //
  // Print register Secondary Latency Timer
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_SECONDARY_TIMER),
    HiiHandle,
    INDEX_OF (&(Bridge->SecondaryLatencyTimer)),
    Bridge->SecondaryLatencyTimer
    );

  //
  // Print register Secondary Status
  //
  PciExplainStatus (&(Bridge->SecondaryStatus), FALSE, PciP2pBridge);

  //
  // Print I/O and memory ranges this bridge forwards. There are 3 resource
  // types: I/O, memory, and pre-fetchable memory. For each resource type,
  // base and limit address are listed.
  //
  PrintToken (STRING_TOKEN (STR_PCI2_RESOURCE_TYPE), HiiHandle);
  Print (L"----------------------------------------------------------------------\n");

  //
  // IO Base & Limit
  //
  IoAddress32 = (Bridge->IoBaseUpper << 16 | Bridge->IoBase << 8);
  IoAddress32 &= 0xfffff000;
  PrintToken (
    STRING_TOKEN (STR_PCI2_TWO_VARS),
    HiiHandle,
    INDEX_OF (&(Bridge->IoBase)),
    IoAddress32
    );

  IoAddress32 = (Bridge->IoLimitUpper << 16 | Bridge->IoLimit << 8);
  IoAddress32 |= 0x00000fff;
  PrintToken (STRING_TOKEN (STR_PCI2_ONE_VAR), HiiHandle, IoAddress32);

  //
  // Memory Base & Limit
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_MEMORY),
    HiiHandle,
    INDEX_OF (&(Bridge->MemoryBase)),
    (Bridge->MemoryBase << 16) & 0xfff00000
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_ONE_VAR),
    HiiHandle,
    (Bridge->MemoryLimit << 16) | 0x000fffff
    );

  //
  // Pre-fetch-able Memory Base & Limit
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_PREFETCHABLE),
    HiiHandle,
    INDEX_OF (&(Bridge->PrefetchableMemBase)),
    Bridge->PrefetchableBaseUpper,
    (Bridge->PrefetchableMemBase << 16) & 0xfff00000
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_TWO_VARS_2),
    HiiHandle,
    Bridge->PrefetchableLimitUpper,
    (Bridge->PrefetchableMemLimit << 16) | 0x000fffff
    );

  //
  // Print register Capabilities Pointer
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_CAPABILITIES_PTR_2),
    HiiHandle,
    INDEX_OF (&(Bridge->CapabilitiesPtr)),
    Bridge->CapabilitiesPtr
    );

  //
  // Print register Bridge Control
  //
  PciExplainBridgeControl (&(Bridge->BridgeControl), PciP2pBridge);

  //
  // Print register Interrupt Line & PIN
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_INTERRUPT_LINE_2),
    HiiHandle,
    INDEX_OF (&(Bridge->InterruptLine)),
    Bridge->InterruptLine
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_INTERRUPT_PIN),
    HiiHandle,
    INDEX_OF (&(Bridge->InterruptPin)),
    Bridge->InterruptPin
    );

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainBar (
  IN UINT32                                 *Bar,
  IN UINT16                                 *Command,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,
  IN OUT UINTN                              *Index
  )
/*++

Routine Description:

  Explain the Base Address Register(Bar) in PCI configuration space.

Arguments:

  Bar             Points to the Base Address Register intended to interpret
  Command         Points to the register Command
  Address         Address used to access configuration space of this PCI device
  IoDev           Handle used to access configuration space of PCI device
  Index           The Index

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  UINT16  OldCommand;
  UINT16  NewCommand;
  UINT64  Bar64;
  UINT32  OldBar32;
  UINT32  NewBar32;
  UINT64  OldBar64;
  UINT64  NewBar64;
  BOOLEAN IsMem;
  BOOLEAN IsBar32;
  UINT64  RegAddress;

  IsBar32   = TRUE;
  Bar64     = 0;
  NewBar32  = 0;
  NewBar64  = 0;

  //
  // According the bar type, list detail about this bar, for example: 32 or
  // 64 bits; pre-fetchable or not.
  //
  if ((*Bar & PCI_BIT_0) == 0) {
    //
    // This bar is of memory type
    //
    IsMem = TRUE;

    if ((*Bar & PCI_BIT_1) == 0 && (*Bar & PCI_BIT_2) == 0) {
      PrintToken (STRING_TOKEN (STR_PCI2_BAR), HiiHandle, *Bar & 0xfffffff0);
      PrintToken (STRING_TOKEN (STR_PCI2_MEM), HiiHandle);
      PrintToken (STRING_TOKEN (STR_PCI2_32_BITS), HiiHandle);

    } else if ((*Bar & PCI_BIT_1) == 0 && (*Bar & PCI_BIT_2) != 0) {
      Bar64 = 0x0;
      CopyMem (&Bar64, Bar, sizeof (UINT32));
      PrintToken (STRING_TOKEN (STR_PCI2_ONE_VAR_2), HiiHandle, RShiftU64 ((Bar64 & 0xfffffffffffffff0), 32));
      PrintToken (STRING_TOKEN (STR_PCI2_ONE_VAR_3), HiiHandle, Bar64 & 0xfffffffffffffff0);
      PrintToken (STRING_TOKEN (STR_PCI2_MEM), HiiHandle);
      PrintToken (STRING_TOKEN (STR_PCI2_64_BITS), HiiHandle);
      IsBar32 = FALSE;
      *Index += 1;

    } else {
      //
      // Reserved
      //
      PrintToken (STRING_TOKEN (STR_PCI2_BAR), HiiHandle, *Bar & 0xfffffff0);
      PrintToken (STRING_TOKEN (STR_PCI2_MEM_2), HiiHandle);
    }

    if ((*Bar & PCI_BIT_3) == 0) {
      PrintToken (STRING_TOKEN (STR_PCI2_NO), HiiHandle);

    } else {
      PrintToken (STRING_TOKEN (STR_PCI2_YES), HiiHandle);
    }

  } else {
    //
    // This bar is of io type
    //
    IsMem = FALSE;
    PrintToken (STRING_TOKEN (STR_PCI2_ONE_VAR_4), HiiHandle, *Bar & 0xfffffffc);
    Print (L"I/O                               ");
  }

  //
  // Get BAR length(or the amount of resource this bar demands for). To get
  // Bar length, first we should temporarily disable I/O and memory access
  // of this function(by set bits in the register Command), then write all
  // "1"s to this bar. The bar value read back is the amount of resource
  // this bar demands for.
  //
  //
  // Disable io & mem access
  //
  OldCommand  = *Command;
  NewCommand  = (UINT16) (OldCommand & 0xfffc);
  RegAddress  = Address | INDEX_OF (Command);
  IoDev->Pci.Write (IoDev, EfiPciWidthUint16, RegAddress, 1, &NewCommand);

  RegAddress = Address | INDEX_OF (Bar);

  //
  // Read after write the BAR to get the size
  //
  if (IsBar32) {
    OldBar32  = *Bar;
    NewBar32  = 0xffffffff;

    IoDev->Pci.Write (IoDev, EfiPciWidthUint32, RegAddress, 1, &NewBar32);
    IoDev->Pci.Read (IoDev, EfiPciWidthUint32, RegAddress, 1, &NewBar32);
    IoDev->Pci.Write (IoDev, EfiPciWidthUint32, RegAddress, 1, &OldBar32);

    if (IsMem) {
      NewBar32  = NewBar32 & 0xfffffff0;
      NewBar32  = (~NewBar32) + 1;

    } else {
      NewBar32  = NewBar32 & 0xfffffffc;
      NewBar32  = (~NewBar32) + 1;
      NewBar32  = NewBar32 & 0x0000ffff;
    }
  } else {

    OldBar64 = 0x0;
    CopyMem (&OldBar64, Bar, sizeof (UINT32));
    NewBar64 = 0xffffffffffffffff;

    IoDev->Pci.Write (IoDev, EfiPciWidthUint32, RegAddress, 2, &NewBar64);
    IoDev->Pci.Read (IoDev, EfiPciWidthUint32, RegAddress, 2, &NewBar64);
    IoDev->Pci.Write (IoDev, EfiPciWidthUint32, RegAddress, 2, &OldBar64);

    if (IsMem) {
      NewBar64  = NewBar64 & 0xfffffffffffffff0;
      NewBar64  = (~NewBar64) + 1;

    } else {
      NewBar64  = NewBar64 & 0xfffffffffffffffc;
      NewBar64  = (~NewBar64) + 1;
      NewBar64  = NewBar64 & 0x000000000000ffff;
    }
  }
  //
  // Enable io & mem access
  //
  RegAddress = Address | INDEX_OF (Command);
  IoDev->Pci.Write (IoDev, EfiPciWidthUint16, RegAddress, 1, &OldCommand);

  if (IsMem) {
    if (IsBar32) {
      PrintToken (STRING_TOKEN (STR_PCI2_NEWBAR_32), HiiHandle, NewBar32);
      PrintToken (STRING_TOKEN (STR_PCI2_NEWBAR_32_2), HiiHandle, NewBar32 + (*Bar & 0xfffffff0) - 1);

    } else {
      PrintToken (STRING_TOKEN (STR_PCI2_RSHIFT), HiiHandle, RShiftU64 (NewBar64, 32));
      PrintToken (STRING_TOKEN (STR_PCI2_RSHIFT), HiiHandle, (UINT32) NewBar64);
      Print (L"  ");
      PrintToken (
        STRING_TOKEN (STR_PCI2_RSHIFT),
        HiiHandle,
        RShiftU64 ((NewBar64 + (Bar64 & 0xfffffffffffffff0) - 1), 32)
        );
      PrintToken (STRING_TOKEN (STR_PCI2_RSHIFT), HiiHandle, (UINT32) (NewBar64 + (Bar64 & 0xfffffffffffffff0) - 1));

    }
  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_NEWBAR_32_3), HiiHandle, NewBar32);
    PrintToken (STRING_TOKEN (STR_PCI2_NEWBAR_32_4), HiiHandle, NewBar32 + (*Bar & 0xfffffffc) - 1);
  }

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainCardBusData (
  IN PCI_CARDBUS_HEADER                     *CardBus,
  IN UINT64                                 Address,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
  )
/*++

Routine Description:

  Explain the cardbus specific part of data in PCI configuration space.

Arguments:

  CardBus         CardBus specific region of PCI configuration space
  Address         Address used to access configuration space of this PCI device
  IoDev           Handle used to access configuration space of PCI device

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  BOOLEAN           Io32Bit;
  PCI_CARDBUS_DATA  *CardBusData;

  PrintToken (
    STRING_TOKEN (STR_PCI2_CARDBUS_SOCKET),
    HiiHandle,
    INDEX_OF (&(CardBus->CardBusSocketReg)),
    CardBus->CardBusSocketReg
    );

  //
  // Print Secondary Status
  //
  PciExplainStatus (&(CardBus->SecondaryStatus), FALSE, PciCardBusBridge);

  //
  // Print Bus Numbers(Primary bus number, CardBus bus number, and
  // Subordinate bus number
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_BUS_NUMBERS_2),
    HiiHandle,
    INDEX_OF (&(CardBus->PciBusNumber)),
    INDEX_OF (&(CardBus->CardBusBusNumber)),
    INDEX_OF (&(CardBus->SubordinateBusNumber))
    );

  Print (L"               ------------------------------------------------------\n");

  PrintToken (STRING_TOKEN (STR_PCI2_CARDBUS), HiiHandle, CardBus->PciBusNumber);
  PrintToken (STRING_TOKEN (STR_PCI2_CARDBUS_2), HiiHandle, CardBus->CardBusBusNumber);
  PrintToken (STRING_TOKEN (STR_PCI2_CARDBUS_3), HiiHandle, CardBus->SubordinateBusNumber);

  //
  // Print CardBus Latency Timer
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_CARDBUS_LATENCY),
    HiiHandle,
    INDEX_OF (&(CardBus->CardBusLatencyTimer)),
    CardBus->CardBusLatencyTimer
    );

  //
  // Print Memory/Io ranges this cardbus bridge forwards
  //
  PrintToken (STRING_TOKEN (STR_PCI2_RESOURCE_TYPE_2), HiiHandle);
  Print (L"----------------------------------------------------------------------\n");

  PrintToken (
    STRING_TOKEN (STR_PCI2_MEM_3),
    HiiHandle,
    INDEX_OF (&(CardBus->MemoryBase0)),
    CardBus->BridgeControl & PCI_BIT_8 ? L"    Prefetchable" : L"Non-Prefetchable",
    CardBus->MemoryBase0 & 0xfffff000,
    CardBus->MemoryLimit0 | 0x00000fff
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_MEM_3),
    HiiHandle,
    INDEX_OF (&(CardBus->MemoryBase1)),
    CardBus->BridgeControl & PCI_BIT_9 ? L"    Prefetchable" : L"Non-Prefetchable",
    CardBus->MemoryBase1 & 0xfffff000,
    CardBus->MemoryLimit1 | 0x00000fff
    );

  Io32Bit = (BOOLEAN) (CardBus->IoBase0 & PCI_BIT_0);
  PrintToken (
    STRING_TOKEN (STR_PCI2_IO_2),
    HiiHandle,
    INDEX_OF (&(CardBus->IoBase0)),
    Io32Bit ? L"          32 bit" : L"          16 bit",
    CardBus->IoBase0 & (Io32Bit ? 0xfffffffc : 0x0000fffc),
    CardBus->IoLimit0 & (Io32Bit ? 0xffffffff : 0x0000ffff) | 0x00000003
    );

  Io32Bit = (BOOLEAN) (CardBus->IoBase1 & PCI_BIT_0);
  PrintToken (
    STRING_TOKEN (STR_PCI2_IO_2),
    HiiHandle,
    INDEX_OF (&(CardBus->IoBase1)),
    Io32Bit ? L"          32 bit" : L"          16 bit",
    CardBus->IoBase1 & (Io32Bit ? 0xfffffffc : 0x0000fffc),
    CardBus->IoLimit1 & (Io32Bit ? 0xffffffff : 0x0000ffff) | 0x00000003
    );

  //
  // Print register Interrupt Line & PIN
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_INTERRUPT_LINE_3),
    HiiHandle,
    INDEX_OF (&(CardBus->InterruptLine)),
    CardBus->InterruptLine,
    INDEX_OF (&(CardBus->InterruptPin)),
    CardBus->InterruptPin
    );

  //
  // Print register Bridge Control
  //
  PciExplainBridgeControl (&(CardBus->BridgeControl), PciCardBusBridge);

  //
  // Print some registers in data region of PCI configuration space for cardbus
  // bridge. Fields include: Sub VendorId, Subsystem ID, and Legacy Mode Base
  // Address.
  //
  CardBusData = (PCI_CARDBUS_DATA *) ((UINT8 *) CardBus + sizeof (PCI_CARDBUS_HEADER));

  PrintToken (
    STRING_TOKEN (STR_PCI2_SUB_VENDOR_ID_2),
    HiiHandle,
    INDEX_OF (&(CardBusData->SubVendorId)),
    CardBusData->SubVendorId,
    INDEX_OF (&(CardBusData->SubSystemId)),
    CardBusData->SubSystemId
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_OPTIONAL),
    HiiHandle,
    INDEX_OF (&(CardBusData->LegacyBase)),
    CardBusData->LegacyBase
    );

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainStatus (
  IN UINT16                                 *Status,
  IN BOOLEAN                                MainStatus,
  IN PCI_HEADER_TYPE                        HeaderType
  )
/*++

Routine Description:

  Explain each meaningful bit of register Status. The definition of Status is
  slightly different depending on the PCI header type.

Arguments:

  Status          Points to the content of register Status
  MainStatus      Indicates if this register is main status(not secondary
                  status)
  HeaderType      Header type of this PCI device

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  if (MainStatus) {
    PrintToken (STRING_TOKEN (STR_PCI2_STATUS), HiiHandle, INDEX_OF (Status), *Status);

  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_SECONDARY_STATUS), HiiHandle, INDEX_OF (Status), *Status);
  }

  PrintToken (STRING_TOKEN (STR_PCI2_NEW_CAPABILITIES), HiiHandle, (*Status & PCI_BIT_4) != 0);

  //
  // Bit 5 is meaningless for CardBus Bridge
  //
  if (HeaderType == PciCardBusBridge) {
    PrintToken (STRING_TOKEN (STR_PCI2_66_CAPABLE), HiiHandle, (*Status & PCI_BIT_5) != 0);

  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_66_CAPABLE_2), HiiHandle, (*Status & PCI_BIT_5) != 0);
  }

  PrintToken (STRING_TOKEN (STR_PCI2_FAST_BACK), HiiHandle, (*Status & PCI_BIT_7) != 0);

  PrintToken (STRING_TOKEN (STR_PCI2_MASTER_DATA), HiiHandle, (*Status & PCI_BIT_8) != 0);
  //
  // Bit 9 and bit 10 together decides the DEVSEL timing
  //
  PrintToken (STRING_TOKEN (STR_PCI2_DEVSEL_TIMING), HiiHandle);
  if ((*Status & PCI_BIT_9) == 0 && (*Status & PCI_BIT_10) == 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_FAST), HiiHandle);

  } else if ((*Status & PCI_BIT_9) != 0 && (*Status & PCI_BIT_10) == 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_MEDIUM), HiiHandle);

  } else if ((*Status & PCI_BIT_9) == 0 && (*Status & PCI_BIT_10) != 0) {
    PrintToken (STRING_TOKEN (STR_PCI2_SLOW), HiiHandle);

  } else {
    PrintToken (STRING_TOKEN (STR_PCI2_RESERVED_2), HiiHandle);
  }

  PrintToken (
    STRING_TOKEN (STR_PCI2_SIGNALED_TARGET),
    HiiHandle,
    (*Status & PCI_BIT_11) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_RECEIVED_TARGET),
    HiiHandle,
    (*Status & PCI_BIT_12) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_RECEIVED_MASTER),
    HiiHandle,
    (*Status & PCI_BIT_13) != 0
    );

  if (MainStatus) {
    PrintToken (
      STRING_TOKEN (STR_PCI2_SIGNALED_ERROR),
      HiiHandle,
      (*Status & PCI_BIT_14) != 0
      );

  } else {
    PrintToken (
      STRING_TOKEN (STR_PCI2_RECEIVED_ERROR),
      HiiHandle,
      (*Status & PCI_BIT_14) != 0
      );
  }

  PrintToken (
    STRING_TOKEN (STR_PCI2_DETECTED_ERROR),
    HiiHandle,
    (*Status & PCI_BIT_15) != 0
    );

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainCommand (
  IN UINT16                                 *Command
  )
/*++

Routine Description:

  Explain each meaningful bit of register Command.

Arguments:

  Command         Points to the content of register Command

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  //
  // Print the binary value of register Command
  //
  PrintToken (STRING_TOKEN (STR_PCI2_COMMAND), HiiHandle, INDEX_OF (Command), *Command);

  //
  // Explain register Command bit by bit
  //
  PrintToken (
    STRING_TOKEN (STR_PCI2_SPACE_ACCESS_DENIED),
    HiiHandle,
    (*Command & PCI_BIT_0) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_MEMORY_SPACE),
    HiiHandle,
    (*Command & PCI_BIT_1) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_BEHAVE_BUS_MASTER),
    HiiHandle,
    (*Command & PCI_BIT_2) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_MONITOR_SPECIAL_CYCLE),
    HiiHandle,
    (*Command & PCI_BIT_3) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_MEM_WRITE_INVALIDATE),
    HiiHandle,
    (*Command & PCI_BIT_4) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_PALETTE_SNOOPING),
    HiiHandle,
    (*Command & PCI_BIT_5) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_ASSERT_PERR),
    HiiHandle,
    (*Command & PCI_BIT_6) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_DO_ADDR_STEPPING),
    HiiHandle,
    (*Command & PCI_BIT_7) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_SERR_DRIVER),
    HiiHandle,
    (*Command & PCI_BIT_8) != 0
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_FAST_BACK_2),
    HiiHandle,
    (*Command & PCI_BIT_9) != 0
    );

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainBridgeControl (
  IN UINT16                                 *BridgeControl,
  IN PCI_HEADER_TYPE                        HeaderType
  )
/*++

Routine Description:

  Explain each meaningful bit of register Bridge Control.

Arguments:

  BridgeControl   Points to the content of register Bridge Control
  HeaderType      The headertype

Returns:

  EFI_SUCCESS     The command completed successfully

--*/
{
  PrintToken (
    STRING_TOKEN (STR_PCI2_BRIDGE_CONTROL),
    HiiHandle,
    INDEX_OF (BridgeControl),
    *BridgeControl
    );

  PrintToken (
    STRING_TOKEN (STR_PCI2_PARITY_ERROR),
    HiiHandle,
    (*BridgeControl & PCI_BIT_0) != 0
    );
  PrintToken (
    STRING_TOKEN (STR_PCI2_SERR_ENABLE),
    HiiHandle,
    (*BridgeControl & PCI_BIT_1) != 0
    );
  PrintToken (
    STRING_TOKEN (STR_PCI2_ISA_ENABLE),
    HiiHandle,
    (*BridgeControl & PCI_BIT_2) != 0
    );
  PrintToken (
    STRING_TOKEN (STR_PCI2_VGA_ENABLE),
    HiiHandle,
    (*BridgeControl & PCI_BIT_3) != 0
    );
  PrintToken (
    STRING_TOKEN (STR_PCI2_MASTER_ABORT),
    HiiHandle,
    (*BridgeControl & PCI_BIT_5) != 0
    );

  //
  // Register Bridge Control has some slight differences between P2P bridge
  // and Cardbus bridge from bit 6 to bit 11.
  //
  if (HeaderType == PciP2pBridge) {
    PrintToken (
      STRING_TOKEN (STR_PCI2_SECONDARY_BUS_RESET),
      HiiHandle,
      (*BridgeControl & PCI_BIT_6) != 0
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_FAST_ENABLE),
      HiiHandle,
      (*BridgeControl & PCI_BIT_7) != 0
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_PRIMARY_DISCARD_TIMER),
      HiiHandle,
      (*BridgeControl & PCI_BIT_8) ? L"2^10" : L"2^15"
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_SECONDARY_DISCARD_TIMER),
      HiiHandle,
      (*BridgeControl & PCI_BIT_9) ? L"2^10" : L"2^15"
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_DISCARD_TIMER_STATUS),
      HiiHandle,
      (*BridgeControl & PCI_BIT_10) != 0
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_DISCARD_TIMER_SERR),
      HiiHandle,
      (*BridgeControl & PCI_BIT_11) != 0
      );

  } else {
    PrintToken (
      STRING_TOKEN (STR_PCI2_CARDBUS_RESET),
      HiiHandle,
      (*BridgeControl & PCI_BIT_6) != 0
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_IREQ_ENABLE),
      HiiHandle,
      (*BridgeControl & PCI_BIT_7) != 0
      );
    PrintToken (
      STRING_TOKEN (STR_PCI2_WRITE_POSTING_ENABLE),
      HiiHandle,
      (*BridgeControl & PCI_BIT_10) != 0
      );
  }

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainCapabilityStruct (
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
  IN UINT64                                   Address,
  IN  UINT8                                   CapPtr
  )
{
  UINT8   CapabilityPtr;
  UINT16  CapabilityEntry;
  UINT8   CapabilityID;
  UINT64  RegAddress;

  CapabilityPtr = CapPtr;

  //
  // Go through the Capability list
  //
  while (CapabilityPtr > 0x3F) {
    //
    // Mask it to DWORD alignment per PCI spec
    //
    CapabilityPtr &= 0xFC;

    RegAddress = Address + CapabilityPtr;
    IoDev->Pci.Read (IoDev, EfiPciWidthUint16, RegAddress, 1, &CapabilityEntry);

    CapabilityID = (UINT8) CapabilityEntry;

    //
    // Explain PciExpress data
    //
    if (EFI_PCI_CAPABILITY_ID_PCIEXP == CapabilityID) {
      PciExplainPciExpress (IoDev, Address, CapabilityPtr);
      return EFI_SUCCESS;
    }
    //
    // Explain other capabilities here
    //
    CapabilityPtr = (UINT8) (CapabilityEntry >> 8);
  }

  return EFI_SUCCESS;
}

EFI_STATUS
PciExplainPciExpress (
  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
  IN  UINT64                                  Address,
  IN  UINT8                                   CapabilityPtr
  )
{

  PCIE_CAP_STURCTURE  PciExpressCap;
  EFI_STATUS          Status;
  UINT64              RegAddress;
  UINT8               Bus;
  UINT8               Dev;
  UINT8               Func;
  UINT8               *ExRegBuffer;
  UINTN               ExtendRegSize;
  UINT64              Pciex_Address;

  RegAddress = Address + CapabilityPtr;
  IoDev->Pci.Read (
              IoDev,
              EfiPciWidthUint32,
              RegAddress,
              sizeof (PciExpressCap) / sizeof (UINT32),
              &PciExpressCap
              );

  Print (L"\nPci Express device capability structure:\n");
  //
  // Print PciExpress Capability ID, should be 0x10 per PCI sepc.
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_CAPABILITY_CAPID),
    HiiHandle,
    0x00,
    PciExpressCap.PcieCapId
    );

  //
  // Print Next capability pointer in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_NEXTCAP_PTR),
    HiiHandle,
    0x01,
    PciExpressCap.NextCapPtr
    );

  //
  // Print Capabilities register in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_CAP_REGISTER),
    HiiHandle,
    0x02,
    PciExpressCap.PcieCapReg
    );

  //
  // Print Device capabilities in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_DEVICE_CAP),
    HiiHandle,
    0x04,
    PciExpressCap.PcieDeviceCap
    );

  //
  // Print DeviceStatus in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_DEVICE_CONTROL),
    HiiHandle,
    0x08,
    PciExpressCap.DeviceControl
    );

  //
  // Print DeviceStatus in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_DEVICE_STATUS),
    HiiHandle,
    0x0A,
    PciExpressCap.DeviceStatus
    );

  //
  // Print Link Capabilities in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_LINK_CAPABILITIES),
    HiiHandle,
    0x0C,
    PciExpressCap.LinkCap
    );

  //
  // Print LinkControl in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_LINK_CONTROL),
    HiiHandle,
    0x10,
    PciExpressCap.LinkControl
    );

  //
  // Print LinkStatus in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_LINK_STATUS),
    HiiHandle,
    0x12,
    PciExpressCap.LinkStatus
    );

  //
  // Print RootCap in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_SLOT_CAPABILITIES),
    HiiHandle,
    0x14,
    PciExpressCap.SlotCap
    );

  //
  // Print SlotControl in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_SLOT_CONTROL),
    HiiHandle,
    0x18,
    PciExpressCap.SlotControl
    );

  //
  // Print SlotStatus in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_SLOT_STATUS),
    HiiHandle,
    0x1A,
    PciExpressCap.SlotStatus
    );

  //
  // Print RootControl in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_ROOT_CONTROL),
    HiiHandle,
    0x1C,
    PciExpressCap.RootControl
    );

  //
  // Print RsvdP in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_RSVDP),
    HiiHandle,
    0x1E,
    PciExpressCap.RsvdP
    );

  //
  // Print RootStatus in PciExpress Capability structure
  //
  PrintToken (
    STRING_TOKEN (STR_PCIEX_ROOT_STATUS),
    HiiHandle,
    0x20,
    PciExpressCap.RootStatus
    );

  Bus           = (UINT8) (RShiftU64 (Address, 24));
  Dev           = (UINT8) (RShiftU64 (Address, 16));
  Func          = (UINT8) (RShiftU64 (Address, 8));

  Pciex_Address = CALC_EFI_PCIEX_ADDRESS (Bus, Dev, Func, 0x100);

  ExtendRegSize = 0x1000 - 0x100;

  ExRegBuffer   = (UINT8 *) AllocatePool (ExtendRegSize);

  //
  // PciRootBridgeIo protocol should support pci express extend space IO
  // (Begins at offset 0x100)
  //
  Status = IoDev->Pci.Read (
                        IoDev,
                        EfiPciWidthUint32,
                        Pciex_Address,
                        (ExtendRegSize) / sizeof (UINT32),
                        (VOID *) (ExRegBuffer)
                        );
  if (EFI_ERROR (Status)) {
    FreePool ((VOID *) ExRegBuffer);
    return EFI_UNSUPPORTED;
  }
  //
  // Start outputing PciEx extend space( 0xFF-0xFFF)
  //
  Print (L"\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\n\n");

  DumpHex (
    2,
    0x100,
    ExtendRegSize,
    (VOID *) (ExRegBuffer)
    );

  FreePool ((VOID *) ExRegBuffer);
  return EFI_SUCCESS;
}

EFI_STATUS
InitializePciGetLineHelp (
  OUT CHAR16              **Str
  )
/*++

Routine Description:

  Get this command's line help

Arguments:

  Str - The line help

Returns:

  EFI_SUCCESS   - Success

--*/
{
  return LibCmdGetStringByToken (
          STRING_ARRAY_NAME,
          &EfiPciGuid,
          STRING_TOKEN (STR_HELPINFO_PCI_LINEHELP),
          Str
          );
}


text:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.appservice.generated;

import com.azure.core.util.Context;

/** Samples for AppServiceEnvironments ListWorkerPools. */
public final class AppServiceEnvironmentsListWorkerPoolsSamples {
    /*
     * x-ms-original-file: specification/web/resource-manager/Microsoft.Web/stable/2022-03-01/examples/AppServiceEnvironments_ListWorkerPools.json
     */
    /**
     * Sample code: Get all worker pools of an App Service Environment.
     *
     * @param azure The entry point for accessing resource management APIs in Azure.
     */
    public static void getAllWorkerPoolsOfAnAppServiceEnvironment(
        com.azure.resourcemanager.AzureResourceManager azure) {
        azure
            .webApps()
            .manager()
            .serviceClient()
            .getAppServiceEnvironments()
            .listWorkerPools("test-rg", "test-ase", Context.NONE);
    }
}


text:
class Github < Cask
  version :latest
  sha256 :no_check

  url 'https://central.github.com/mac/latest'
  homepage 'http://mac.github.com'
  license :oss

  app 'GitHub.app'
  binary 'GitHub.app/Contents/MacOS/github_cli', :target => 'github'
  postflight do
    system '/usr/bin/defaults', 'write', 'com.github.GitHub', 'moveToApplicationsFolderAlertSuppress', '-bool', 'true'
  end

  zap :delete => [
                  '~/Library/Application Support/GitHub for Mac',
                  '~/Library/Application Support/ShipIt_stderr.log',
                  '~/Library/Application Support/ShipIt_stdout.log',
                  '~/Library/Application Support/com.github.GitHub',
                  '~/Library/Application Support/com.github.GitHub.ShipIt',
                  '~/Library/Caches/GitHub for Mac',
                  '~/Library/Caches/com.github.GitHub',
                  '~/Library/Containers/com.github.GitHub.Conduit',
                 ]
end


text:
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/spf13/viper"
	"github.com/stayradiated/rango/rangolib"
)

func main() {

	// setup config file
	viper.SetConfigName("config")
	viper.ReadInConfig()

	// set config defaults
	viper.SetDefault("ContentDir", "content")
	viper.SetDefault("AdminDir", "admin")
	viper.SetDefault("AssetsDir", "static/assets")

	// make sure content dir exists
	contentDir := viper.GetString("ContentDir")
	_, err := os.Stat(contentDir)
	if err != nil && os.IsNotExist(err) {
		os.Mkdir(contentDir, 0755)
	}

	// make sure assets dir exists
	assetsDir := viper.GetString("AssetsDir")
	_, err = os.Stat(assetsDir)
	if err != nil && os.IsNotExist(err) {
		os.Mkdir(assetsDir, 0755)
	}

	// create router
	router := NewRouter(&RouterConfig{
		Handlers: &Handlers{
			Config:     rangolib.NewConfig("config.toml"),
			Dir:        rangolib.NewDir(),
			Page:       rangolib.NewPage(),
			ContentDir: contentDir,
			AssetsDir:  assetsDir,
		},
		AdminDir: viper.GetString("AdminDir"),
	})

	// start http server
	fmt.Println("Starting server on :8080")
	log.Fatal(http.ListenAndServe(":8080", router))
}