os161-1.99
 All Data Structures
palin.c
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 /*
00031 
00032         Test suite.
00033 
00034         This program takes the palindrome below and checks if it's
00035         a palindrome or not. It will hopefully exhibit an interesting
00036         page fault pattern.
00037 
00038         The palindrome was taken from 
00039 
00040         http://www.cs.brown.edu/people/nfp/palindrome.html
00041 
00042         This is not large enough to really stress the VM system, but
00043         might be useful for testing in the early stages of the VM
00044         assignment.
00045 */
00046 
00047 /*
00048 A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop,
00049 a pint, a catalpa, a gas, an oil, a bird, a yell, a vat, a caw, a pax,
00050 a wag, a tax, a nay, a ram, a cap, a yam, a gay, a tsar, a wall, a
00051 car, a luger, a ward, a bin, a woman, a vassal, a wolf, a tuna, a nit,
00052 a pall, a fret, a watt, a bay, a daub, a tan, a cab, a datum, a gall, 
00053 a hat, a fag, a zap, a say, a jaw, a lay, a wet, a gallop, a tug, a
00054 trot, a trap, a tram, a torr, a caper, a top, a tonk, a toll, a ball, 
00055 a fair, a sax, a minim, a tenor, a bass, a passer, a capital, a rut, 
00056 an amen, a ted, a cabal, a tang, a sun, an ass, a maw, a sag, a jam, 
00057 a dam, a sub, a salt, an axon, a sail, an ad, a wadi, a radian, a
00058 room, a rood, a rip, a tad, a pariah, a revel, a reel, a reed, a pool,
00059 a plug, a pin, a peek, a parabola, a dog, a pat, a cud, a nu, a fan, 
00060 a pal, a rum, a nod, an eta, a lag, an eel, a batik, a mug, a mot, a
00061 nap, a maxim, a mood, a leek, a grub, a gob, a gel, a drab, a citadel,
00062 a total, a cedar, a tap, a gag, a rat, a manor, a bar, a gal, a cola, 
00063 a pap, a yaw, a tab, a raj, a gab, a nag, a pagan, a bag, a jar, a
00064 bat, a way, a papa, a local, a gar, a baron, a mat, a rag, a gap, a
00065 tar, a decal, a tot, a led, a tic, a bard, a leg, a bog, a burg, a
00066 keel, a doom, a mix, a map, an atom, a gum, a kit, a baleen, a gala, 
00067 a ten, a don, a mural, a pan, a faun, a ducat, a pagoda, a lob, a rap,
00068 a keep, a nip, a gulp, a loop, a deer, a leer, a lever, a hair, a pad,
00069 a tapir, a door, a moor, an aid, a raid, a wad, an alias, an ox, an
00070 atlas, a bus, a madam, a jag, a saw, a mass, an anus, a gnat, a lab, 
00071 a cadet, an em, a natural, a tip, a caress, a pass, a baronet, a
00072 minimax, a sari, a fall, a ballot, a knot, a pot, a rep, a carrot, 
00073 a mart, a part, a tort, a gut, a poll, a gateway, a law, a jay, a sap,
00074 a zag, a fat, a hall, a gamut, a dab, a can, a tabu, a day, a batt, 
00075 a waterfall, a patina, a nut, a flow, a lass, a van, a mow, a nib, 
00076 a draw, a regular, a call, a war, a stay, a gam, a yap, a cam, a ray, 
00077 an ax, a tag, a wax, a paw, a cat, a valley, a drib, a lion, a saga, 
00078 a plat, a catnip, a pooh, a rail, a calamus, a dairyman, a bater, 
00079 a canal - Panama! 
00080 */
00081 
00082 /* The palindrome below is a quadruple concatenation of the above */
00083 
00084 #include <stdio.h>
00085 #include <string.h>
00086 
00087 char palindrome[8000] = 
00088 "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
00089 "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
00090 "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
00091 "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
00092 "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
00093 "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
00094 "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
00095 "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
00096 "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
00097 "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
00098 "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
00099 "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
00100 "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
00101 "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
00102 "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
00103 "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
00104 "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
00105 "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
00106 "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
00107 "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
00108 "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
00109 "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
00110 "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
00111 "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
00112 "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
00113 "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
00114 "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
00115 "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
00116 "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
00117 "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
00118 "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
00119 "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
00120 "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
00121 "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
00122 "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
00123 "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
00124 "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
00125 "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
00126 "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
00127 "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
00128 "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
00129 "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
00130 "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
00131 "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
00132 "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
00133 "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
00134 "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
00135 "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
00136 "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
00137 "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
00138 "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
00139 "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
00140 "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
00141 "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
00142 "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
00143 "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
00144 "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
00145 "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
00146 "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
00147 "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
00148 "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
00149 "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
00150 "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
00151 "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
00152 "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
00153 "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
00154 "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
00155 "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
00156 "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
00157 "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
00158 "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
00159 "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
00160 "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
00161 "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
00162 "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
00163 "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
00164 "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
00165 "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
00166 "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
00167 "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
00168 "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
00169 "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
00170 "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
00171 "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama";
00172 
00173 int
00174 main()
00175 {
00176         char *start, *end;
00177         
00178         printf("Welcome to the palindrome tester!\n");
00179         printf("I will take a large palindrome and test it.\n");
00180         printf("Here it is:\n");
00181         printf("%s\n", palindrome);
00182 
00183         printf("Testing...");
00184         /* skip to end */
00185         end = palindrome+strlen(palindrome);
00186         end--;
00187 
00188         for (start = palindrome; start <= end; start++, end--) {
00189                 putchar('.');
00190                 if (*start != *end) {
00191                         printf("NOT a palindrome\n");
00192                         return 0;
00193                 }
00194         }
00195         
00196         printf("IS a palindrome\n");
00197         return 0;
00198 }
 All Data Structures