#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *name;
char *desc;

void parseOneDB();

int main(int argc, const char* argv[]) {
	if(argc < 2) { // not enough arguments
		return 1;
	}
	
	// get " name "
	name = (char *)malloc(sizeof(char) * (strlen(argv[1])+2));
	name[0] = ' '; // start with space
	strcat(name, argv[1]); // add name
	strcat(name, " "); // end with space
	
	// get " desc "
	int chars=3; // starting desc length (spaces + terminating null)
	int i;
	for(i=2; i<argc; ++i) { // for each argument
		if(i!=2) { // not first arg
			++chars; // add space length (1)
		}
		chars+=strlen(argv[i]); // add length
	}
	
	desc = (char *)malloc(sizeof(char) * chars); // allocate memory for description
	
	desc[0] = ' '; // start with space
	chars=1; // used 1 char
	
	for(i=2; i<argc; ++i) { // for each argument
		if(i!=2) { // not first arg
			desc[chars]=' '; // add space
			++chars;
		}
		strcat(desc, argv[i]); // add chars
		chars+=strlen(argv[i]);
	}
	strcat(desc, " "); // add last space
	
	parseOneDB(); // parse
	return 0;
}

void parseOneDB() {
	int i;
	//lower case name
	for(i=0;i<strlen(name);++i) {
		if (name[i] >= 'A' && name[i] <= 'Z') {
			name[i] = name[i] + ('a'-'A');
		}
	}
	//lower case desc
	for(i=0;i<strlen(desc);++i) {
		if (desc[i] >= 'A' && desc[i] <= 'Z') {
			desc[i] = desc[i] + ('a'-'A');
		}
	}
	
	//names of packages in each category
	char PKG_CAT_Desktop[]=" blackbox compiz desk_icon_theme_browndust desk_icon_theme_darkfire desk_icon_theme_original e16 fbpanel fluxbox fvwm gfontsel glipper gtk-chtheme gtk_theme_citrus_cut gtk_theme_fishing_the_sky gtk_theme_fishpie gtk_theme_gradient_brown gtk_theme_gradient_grey gtk_theme_m8darker gtk_theme_phacile_blue gtk_theme_polished_blue gtk_theme_stardust_zigbert gxset icewm jwm2 jwmconfig2 lxpanel metacity minixcal obconf openbox pupx rox_filer rox_filer twm wallpaper windowmaker xclipboard xclock xkbconfigmanager xlock_gui xlockmore ";
	char PKG_CAT_System[]=" absvolume absvolume_puppy absvolume_puppy asapm asapm blinky freememapplet freememapplet freememapplet_xlib gparted gparted gtklp hardinfo hpijs lxtask memtest memtester pprocess pschedule sysprof_DEV usbview xload ";
	char PKG_CAT_Setup[]=" net_setup net_setup_retro petget wakepup2 ";
	char PKG_CAT_Utility[]=" alltray clamav cutecom floppy gadmin-rsync gexec glade2bas_DEV hiawatha isomaster lxrad lxrad_DEV lzma minicom most pbackup picocom pmirror rxvt rxvt rxvt-unicode snotes urxvt-unicode xarchive xarchiver xfdiff-cut xfprot xterm ";
	char PKG_CAT_Filesystem[]=" gdmap gfnrename gwhere mc nautilus pdrive pfind prename uxplor worker xfe zfind ";
	char PKG_CAT_Graphic[]=" autoq3d autotrace blender dia dia-gnomeless eog flphoto fotoxx gcolor2 gimageview gimp gimp-help gphoto2 gpicview gqview grabc gview inkscape inkscape inkscapelite inkview mtpaint scale2x varicad xfig xpaint xv ";
	char PKG_CAT_Document[]=" abiword abiword-dictionary-en abiword-plugins adobereader aiksaurus amaya bluefish chmsee cssed e3 emacs epdfview geany gedit ghex gv jed joe jove leafpad leafpad link-grammar lyx medit mp nano pdfedit scite scribus xman xpdf zedit ";
	char PKG_CAT_Calculate[]=" acct calcoo cgtkcalc expensetracker galculator gmeasures gnumeric grisbi homebank moneymanagerx ycalc xcalc ";
	char PKG_CAT_Personal[]=" datakiosk didiwiki dlume evolution fpm2 notecase osmo pplog pstopwatch ptimer ";
	char PKG_CAT_Network[]=" autoconnect bind file_sharing-curlftpfs-mpscan fwbuilder gfilemanager gnome-ppp gpptp john linux_firewall monkey mtr nmap pnethood pppoeconf_pup pure_ftpd pwireless rp_pppoe_cli superscan wifi-radar wireshark wvdial ";
	char PKG_CAT_Internet[]=" alpine axel ayttm bareftp bitchx dillo ekiga elinks elm epic4 fetchmail filezilla firefox flashplayer flock gajim gcurl getmail gftp gtkmoz gurlchecker jags lftp ihu licq links lynx mailx mcabber mldonkey mozilla-firefox mozilla-thunderbird msmtp mutt ncftp netsurf nn pan pctorrent pidgin pidgin_perl psip puppy-podcast-grabber pwget seamonkey seamonkey seamonkey_addons sendmail skipstone ssh_gui sylpheed urlgfe wengophone xchat ";
	char PKG_CAT_Multimedia[]=" amarok amp asunder audacious audacity aumix cdw cinelerra dkop gecko-mediaplayer grafburn gtkam gxine madplay mhwaveedit mpg321 mplayer mplayer_codecs_basic mplayer_codecs_full mplayer-fonts mplayerplug-in pburn pburn_theme_pburn_original pcdripper pdvdrsab pmetatagger pmusic pmusic_THEME_pmusic_original pupdvdtool ripoff sgmixer simpleburn timidity++ workbone xfmedia xfreecd xine-ui xsane zmixer ";
	char PKG_CAT_Fun[]=" frozen-bubble gnuchess gtans lincity picpuz rubix supertux tile vitetris wesnoth wormux xinvaders xsoldier ";
	char PKG_CAT_Develop[]=" anjuta boo clisp cmake cvs gambas lua mercurial mono nant ocaml nasm poedit ruby subversion svn vala valgrind ";
	char PKG_CAT_BuildingBlock[]=" 915resolution a2ps a52dec acl alsa-lib alsa-utils atk audiofile aufs autocutsel autologin bash bbc_provided bc bcrypt bdb bin boehm-gc bogofilter bridge-utils busybox buttondialog bzip2 cairo cairomm cddetect cdp cdparanoia cdrdao cdrkit cdrtools chmlib coreutils cpio ctorrent cups cups cups_pdf curl ddcprobe device_mapper dhcp dhcpcd dhcp_client dialog dialog dictd_client dietlibc diffstat diffutils disktype dmidecode docbook-xml dosfstools dotpuphandler dpkg-deb dvdauthor dvd+rwtools e2fsprogs ed edid eject elspci enchant exiv2 expat faac faad2 ffmpeg file findutils flac foomatic-filters freetype fribidi fuse gail gawk gcc gdbm getdir gettext ghostscript ghostscript gifsicle gins glib glibc glibc_i18n_en glibc_locales glibmm gnome_menus goffice goffice7 grep grub gtk+ gtk+ gtkdialog gtkdialog2 gtkdialog3 gtklist04mu gtklogfileviewer gtkmm guess_fs gutenprint gutenprint gxmessage gzip hdparm hicolor-icon-theme hotplug2stdout hsfmodem id3lib ifplugd ifplugd_old inotail inotify-tools installwatch iptables jasper kbd lame lcms less libao libart libcap libcddb libcdio libdaemon libdvdcss libdvdnav libdvdplay libdvdread libexif libexif-gtk libexo libexo_lib libgd libgif libglade libgnomecanvas libgnomecanvasmm libgnomecups libgnomecups libgnomeprint libgnomeprint libgnomeprintui libgphoto2 libgsf libid3tag libidl libjpeg libmad libmng libogg libpng librsvg libsigc++ libsndfile libstdc++ libtiff libtool libungif libusb libvorbis libxfce4util libxfcegui4 libxml libxml_python libxscrnsaver libxslt libxslt_python linux-header metamail mimencode mirdir mktemp modem_stats module-init-tools module_init_tools mp3info mut2 ncompress ncurses ndiswrapper nenscript netpbm net-tools normalize ntfs-3g ntfsprogs openssh_client openssl pango parted pciutils pcmcia-cs pcmciautils pcre perl perl-compress-zlib perl-digest-sha1 perl-extutils-depends perl-extutils-pkgconfig perl-html-parser perl-uri perl-xml-parser perl-xml-simple pfilesearch pixman poppler popt ppp pptp procinfo procps programchooser psmisc pup_dock puppybasic puppyinputdetect puppyserialdetect qt4 readline reiserfsprogs replaceit rman rsync samba samba_client sane-backends sdparm sed setserial setvol sgml-base since sqlite squashfs_tools squashfs-tools startup-notification sysfsutils syslinux sysvinit tar time truncate udev udev_cut unclutter unionfs_utils unzip util-linux vamps vcdimager vorbis-tools waitmax wavplay wget wireless-tools wpa_supplicant wpa_supplicant wpa_supplicant wv x264 xclip xcut xdg_puppy xdialog xine-lib xine-plugin xmessage xorg_base xorg_really_base xorg_xfbdev xorg_xorg_base xorg_xorg_dri xorg_xorg_full_dri xorg_xorg_servers xorg_xvesa xvidcore yaf_splash zenity zip zlib ";
	char PKG_CAT_Help[]=" linux-faqs linux-howtos man-pages ";
	
	if(strstr(PKG_CAT_Desktop, name)) {printf("Desktop");return;}
	if(strstr(PKG_CAT_System, name)) {printf("System");return;}
	if(strstr(PKG_CAT_Setup, name)) {printf("Setup");return;}
	if(strstr(PKG_CAT_Utility, name)) {printf("Utility");return;}
	if(strstr(PKG_CAT_Filesystem, name)) {printf("Filesystem");return;}
	if(strstr(PKG_CAT_Graphic, name)) {printf("Graphic");return;}
	if(strstr(PKG_CAT_Document, name)) {printf("Document");return;}
	if(strstr(PKG_CAT_Calculate, name)) {printf("Calculate");return;}
	if(strstr(PKG_CAT_Personal, name)) {printf("Personal");return;}
	if(strstr(PKG_CAT_Network, name)) {printf("Network");return;}
	if(strstr(PKG_CAT_Internet, name)) {printf("Internet");return;}
	if(strstr(PKG_CAT_Multimedia, name)) {printf("Multimedia");return;}
	if(strstr(PKG_CAT_Fun, name)) {printf("Fun");return;}
	if(strstr(PKG_CAT_Develop, name)) {printf("Develop");return;}
	if(strstr(PKG_CAT_BuildingBlock, name)) {printf("BuildingBlock");return;}
	if(strstr(PKG_CAT_Help, name)) {printf("Help");return;}
	
	if(strstr(name, " lib")) {printf("BuildingBlock");return;} //check if library
	
	//words in description
	if(strstr(desc, " library ")) {printf("BuildingBlock");return;}
	if(strstr(desc, " howto ")) {printf("Help");return;}
	if(strstr(desc, " documentation ")) {printf("Help");return;}
	if(strstr(desc, " faq ")) {printf("Help");return;}
	if(strstr(desc, " doc ")) {printf("Help");return;}
	if(strstr(desc, " docs ")) {printf("Help");return;}
	if(strstr(desc, " help ")) {printf("Help");return;}
	if(strstr(desc, " develop ")) {printf("Develop");return;}
	if(strstr(desc, " development ")) {printf("Develop");return;}
	if(strstr(desc, " programming ")) {printf("Develop");return;}
	if(strstr(desc, " language ")) {printf("Develop");return;}
	if(strstr(desc, " lua ")) {printf("Develop");return;}
	if(strstr(desc, " vala ")) {printf("Develop");return;}
	if(strstr(desc, "lisp ")) {printf("Develop");return;}
	if(strstr(desc, " mono ")) {printf("Develop");return;}
	if(strstr(desc, " assembler ")) {printf("Develop");return;}
	if(strstr(desc, " bash ")) {printf("Develop");return;}
	if(strstr(desc, " paint ")) {printf("Graphic");return;}
	if(strstr(desc, " painting ")) {printf("Graphic");return;}
	if(strstr(desc, " image edit")) {printf("Graphic");return;}
	if(strstr(desc, " bitmap edit")) {printf("Graphic");return;}
	if(strstr(desc, " vector edit")) {printf("Graphic");return;}
	if(strstr(desc, " photo")) {printf("Graphic");return;}
	if(strstr(desc, " graphic")) {printf("Graphic");return;}
	if(strstr(desc, " font edit")) {printf("Graphic");return;}
	if(strstr(desc, " image view")) {printf("Graphic");return;}
	if(strstr(desc, " thumbnail")) {printf("Graphic");return;}
	if(strstr(desc, " game ")) {printf("Fun");return;}
	if(strstr(desc, " games ")) {printf("Fun");return;}
	if(strstr(desc, " boardgame ")) {printf("Fun");return;}
	if(strstr(desc, " fun ")) {printf("Fun");return;}
	if(strstr(desc, " multimedia ")) {printf("Multimedia");return;}
	if(strstr(desc, " scanner ")) {printf("Multimedia");return;}
	if(strstr(desc, " audio play")) {printf("Multimedia");return;}
	if(strstr(desc, " sound play")) {printf("Multimedia");return;}
	if(strstr(desc, " audio edit")) {printf("Multimedia");return;}
	if(strstr(desc, " sound edit")) {printf("Multimedia");return;}
	if(strstr(desc, " video play")) {printf("Multimedia");return;}
	if(strstr(desc, " video edit")) {printf("Multimedia");return;}
	if(strstr(desc, " video view")) {printf("Multimedia");return;}
	if(strstr(desc, " media player ")) {printf("Multimedia");return;}
	if(strstr(desc, " song ")) {printf("Multimedia");return;}
	if(strstr(desc, " ripper ")) {printf("Multimedia");return;}
	if(strstr(desc, " recorder ")) {printf("Multimedia");return;}
	if(strstr(desc, " burner ")) {printf("Multimedia");return;}
	if(strstr(desc, " mixer ")) {printf("Multimedia");return;}
	if(strstr(desc, " internet ")) {printf("Internet");return;}
	if(strstr(desc, " download")) {printf("Internet");return;}
	if(strstr(desc, " chat ")) {printf("Internet");return;}
	if(strstr(desc, " irc ")) {printf("Internet");return;}
	if(strstr(desc, "icq ")) {printf("Internet");return;}
	if(strstr(desc, " yahoo ")) {printf("Internet");return;}
	if(strstr(desc, "msn ")) {printf("Internet");return;}
	if(strstr(desc, " instant messag")) {printf("Internet");return;}
	if(strstr(desc, " im client ")) {printf("Internet");return;}
	if(strstr(desc, " ftp ")) {printf("Internet");return;}
	if(strstr(desc, " sftp ")) {printf("Internet");return;}
	if(strstr(desc, " ssh ")) {printf("Internet");return;}
	if(strstr(desc, " secure shell ")) {printf("Internet");return;}
	if(strstr(desc, " torrent ")) {printf("Internet");return;}
	if(strstr(desc, " podcast ")) {printf("Internet");return;}
	if(strstr(desc, " mail ")) {printf("Internet");return;}
	if(strstr(desc, " email ")) {printf("Internet");return;}
	if(strstr(desc, " news ")) {printf("Internet");return;}
	if(strstr(desc, " browser ")) {printf("Internet");return;}
	if(strstr(desc, " web ")) {printf("Internet");return;}
	if(strstr(desc, " telnet ")) {printf("Internet");return;}
	if(strstr(desc, " network ")) {printf("Network");return;}
	if(strstr(desc, " modem ")) {printf("Network");return;}
	if(strstr(desc, " dialup ")) {printf("Network");return;}
	if(strstr(desc, " firewall ")) {printf("Network");return;}
	if(strstr(desc, " file sharing ")) {printf("Network");return;}
	if(strstr(desc, " samba ")) {printf("Network");return;}
	if(strstr(desc, " server ")) {printf("Network");return;}
	if(strstr(desc, " port scanner ")) {printf("Network");return;}
	if(strstr(desc, " wireless ")) {printf("Network");return;}
	if(strstr(desc, " bluetooth ")) {printf("Network");return;}
	if(strstr(desc, " irda ")) {printf("Network");return;}
	if(strstr(desc, " lan ")) {printf("Network");return;}
	if(strstr(desc, " wan ")) {printf("Network");return;}
	if(strstr(desc, " vpn ")) {printf("Network");return;}
	if(strstr(desc, " personal ")) {printf("Personal");return;}
	if(strstr(desc, " wiki ")) {printf("Personal");return;}
	if(strstr(desc, " password ")) {printf("Personal");return;}
	if(strstr(desc, " wikki ")) {printf("Personal");return;}
	if(strstr(desc, " wik")) {printf("Personal");return;}
	if(strstr(desc, " notes ")) {printf("Personal");return;}
	if(strstr(desc, " blog ")) {printf("Personal");return;}
	if(strstr(desc, " address")) {printf("Personal");return;}
	if(strstr(desc, " database ")) {printf("Personal");return;}
	if(strstr(desc, " calculate ")) {printf("Calculate");return;}
	if(strstr(desc, " calculator ")) {printf("Calculate");return;}
	if(strstr(desc, " spreadsheet ")) {printf("Calculate");return;}
	if(strstr(desc, " financ")) {printf("Calculate");return;}
	if(strstr(desc, " measure")) {printf("Calculate");return;}
	if(strstr(desc, " accounting ")) {printf("Calculate");return;}
	if(strstr(desc, " bookkeeping ")) {printf("Calculate");return;}
	if(strstr(desc, " document ")) {printf("Document");return;}
	if(strstr(desc, " wordprocessor ")) {printf("Document");return;}
	if(strstr(desc, " text editor ")) {printf("Document");return;}
	if(strstr(desc, " hex editor ")) {printf("Document");return;}
	if(strstr(desc, " html editor ")) {printf("Document");return;}
	if(strstr(desc, "pdf editor ")) {printf("Document");return;}
	if(strstr(desc, "pdf viewer ")) {printf("Document");return;}
	if(strstr(desc, " dictionary ")) {printf("Document");return;}
	if(strstr(desc, " wysiwyg ")) {printf("Document");return;}
	if(strstr(desc, " open office")) {printf("Document");return;}
	if(strstr(desc, " openoffice ")) {printf("Document");return;}
	if(strstr(desc, " postscript viewer ")) {printf("Document");return;}
	if(strstr(desc, " presentation ")) {printf("Document");return;}
	if(strstr(desc, " desktop publishing ")) {printf("Document");return;}
	if(strstr(desc, " word processor")) {printf("Document");return;}
	if(strstr(desc, " filesystem ")) {printf("Filesystem");return;}
	if(strstr(desc, " disk ")) {printf("Filesystem");return;}
	if(strstr(desc, " batch ")) {printf("Filesystem");return;}
	if(strstr(desc, " catalog")) {printf("Filesystem");return;}
	if(strstr(desc, " file manager ")) {printf("Filesystem");return;}
	if(strstr(desc, " renamer ")) {printf("Filesystem");return;}
	if(strstr(desc, " file ")) {printf("Filesystem");return;}
	if(strstr(desc, " drive")) {printf("Filesystem");return;}
	if(strstr(desc, " disk")) {printf("Filesystem");return;}
	if(strstr(desc, " disc ")) {printf("Filesystem");return;}
	if(strstr(desc, " window ")) {printf("Desktop");return;}
	if(strstr(desc, " screen ")) {printf("Desktop");return;}
	if(strstr(desc, " icon")) {printf("Desktop");return;}
	if(strstr(desc, " desktop ")) {printf("Desktop");return;}
	if(strstr(desc, " utility ")) {printf("Utility");return;}
	if(strstr(desc, " archive")) {printf("Utility");return;}
	if(strstr(desc, " remote ")) {printf("Utility");return;}
	if(strstr(desc, " backup ")) {printf("Utility");return;}
	if(strstr(desc, " partition ")) {printf("Utility");return;}
	if(strstr(desc, " terminal ")) {printf("Utility");return;}
	if(strstr(desc, " storage ")) {printf("Utility");return;}
	if(strstr(desc, " console ")) {printf("Utility");return;}
	if(strstr(desc, " system ")) {printf("System");return;}
	if(strstr(desc, " print ")) {printf("System");return;}
	if(strstr(desc, " printing ")) {printf("System");return;}
	if(strstr(desc, " process ")) {printf("System");return;}
	if(strstr(desc, " hardware ")) {printf("System");return;}
	if(strstr(desc, " monitor")) {printf("System");return;}
	
	printf("BuildingBlock"); // default
}

