"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

exo-test.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "misc.h"
#include "options.h"
#include "libexo.h"

Include dependency graph for exo-test.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define SYM1   1
 

#define SYM2   2
 


Function Documentation

void main int    argc,
char **    argv
 

Definition at line 97 of file exo-test.c.

References exo_term_t::as_token, ec_array, ec_blob, ec_char, ec_float, ec_integer, ec_list, ec_string, ec_token, EXO_ARR, exo_chain(), exo_deepcopy(), EXO_FMT_MAJOR, EXO_FMT_MINOR, exo_intern_as(), exo_new(), exo_print(), exo_read(), FALSE, fatal(), help_me, load_file, make_defs, exo_term_t::next, opt_new(), opt_print_options(), opt_process_options(), opt_reg_flag(), opt_reg_string(), print_db, save_file, TRUE, and usage().

00098 {
00099   /* build the command line options database */
00100   odb = opt_new(/* no orphan fn */NULL);
00101   opt_reg_flag(odb, "-h", "print help message",
00102                &help_me, /* default */FALSE, /* !print */FALSE, NULL);
00103   opt_reg_flag(odb, "-defs", "make internal defs",
00104                &make_defs, /* default */FALSE, /* print */TRUE, NULL);
00105   opt_reg_string(odb, "-load", "load an EXO file",
00106                  &load_file, /* default */NULL,
00107                  /* print */TRUE, /* format */NULL);
00108   opt_reg_string(odb, "-save", "save an EXO file",
00109                  &save_file, /* default */NULL,
00110                  /* print */TRUE, /* format */NULL);
00111   opt_reg_flag(odb, "-print", "print the EXO DB to stdout",
00112                &print_db, /* default */FALSE,
00113                /* print */TRUE, /* format */NULL);
00114 
00115   /* process the command line options */
00116   opt_process_options(odb, argc, argv);
00117 
00118   if (help_me)
00119     {
00120       /* print help message and exit */
00121       usage(stderr, argc, argv);
00122       exit(1);
00123     }
00124 
00125   /* print options used */
00126   opt_print_options(odb, stderr, /* short */TRUE, /* notes */TRUE);
00127 
00128   if (load_file)
00129     {
00130       ZFILE *exo_stream;
00131       struct exo_term_t *exo;
00132 
00133       exo_stream = myzfopen(load_file, "r");
00134       if (!exo_stream)
00135         fatal("could not open EXO file `%s'", load_file);
00136 
00137       while ((exo = exo_read(exo_stream->fd)) != NULL)
00138         exo_db = exo_chain(exo_db, exo);
00139 
00140       myzfclose(exo_stream);
00141     }
00142 
00143   if (make_defs)
00144     {
00145       struct exo_term_t *list, *array, *a, *b, *c, *d, *e, *f, *g, *h, *i;
00146       char *data = "This is a test to see if blobs really work...";
00147       char *data1 = "This is a test to see if blobs really work..."
00148         "This is a test to see if blobs really work..."
00149           "This is a test to see if blobs really work..."
00150             "This is a test to see if blobs really work..."
00151               "This is a test to see if blobs really work..."
00152                 "This is a test to see if blobs really work..."
00153                   "This is a test to see if blobs really work..."
00154                     "This is a test to see if blobs really work...";
00155       unsigned char data2[16] =
00156         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
00157 
00158       exo_db =
00159         exo_chain(exo_db, exo_new(ec_string, "** basic types tests **"));
00160       exo_db = exo_chain(exo_db, a = exo_new(ec_integer, (exo_integer_t)42));
00161       exo_db = exo_chain(b = exo_new(ec_float, (exo_float_t)42.0), exo_db);
00162       exo_db = exo_chain(exo_db, c = exo_new(ec_char, (int)'x'));
00163       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\n'));
00164       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\b'));
00165       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\x02'));
00166       exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\xab'));
00167       exo_db = exo_chain(exo_db, exo_new(ec_string, "this is a test..."));
00168       exo_db =
00169         exo_chain(exo_db, d = exo_new(ec_string, "this is\na test...\n"));
00170       exo_db = exo_chain(exo_db, exo_new(ec_string, "a test... <<\\\b>>\n"));
00171 
00172       exo_db = exo_chain(exo_db, exo_new(ec_string, "** deep copy tests **"));
00173       exo_db = exo_chain(exo_db, exo_deepcopy(d));
00174       exo_db = exo_chain(exo_db, exo_deepcopy(c));
00175       exo_db = exo_chain(exo_db, exo_deepcopy(b));
00176       exo_db = exo_chain(exo_db, exo_deepcopy(a));
00177 
00178       exo_db = exo_chain(exo_db, exo_new(ec_string, "** list tests **"));
00179       exo_db =
00180         exo_chain(exo_db, exo_new(ec_list,
00181                                   exo_deepcopy(d), exo_deepcopy(c),
00182                                   exo_deepcopy(b), exo_deepcopy(a), NULL));
00183       exo_db = exo_chain(exo_db, exo_new(ec_list, NULL));
00184       exo_db =
00185         exo_chain(exo_db, exo_new(ec_list,
00186                                   exo_new(ec_list, NULL),
00187                                   exo_new(ec_list, NULL),
00188                                   exo_new(ec_list, exo_deepcopy(a), NULL),
00189                                   NULL));
00190       list = exo_deepcopy(a);
00191       list = exo_chain(list, exo_deepcopy(b));
00192       list = exo_chain(list, exo_deepcopy(a));
00193       list = exo_chain(list, exo_deepcopy(b));
00194       list = exo_chain(exo_deepcopy(c), list);
00195       exo_db = exo_chain(exo_db, e = exo_new(ec_list, list, NULL));
00196       exo_db = exo_chain(exo_db, exo_new(ec_list,
00197                                          exo_deepcopy(e),
00198                                          exo_new(ec_list, NULL),
00199                                          exo_deepcopy(e),
00200                                          exo_deepcopy(a), NULL));
00201 
00202       exo_db = exo_chain(exo_db, exo_new(ec_string, "** array tests **"));
00203       exo_db = exo_chain(exo_db, exo_new(ec_array, 16, NULL));
00204       f = array = exo_new(ec_array, 16, NULL);
00205       EXO_ARR(array, 2) = exo_deepcopy(e);
00206       EXO_ARR(array, 3) = exo_deepcopy(a);
00207       EXO_ARR(array, 4) = exo_deepcopy(c);
00208       EXO_ARR(array, 6) = exo_deepcopy(EXO_ARR(array, 2));
00209       EXO_ARR(array, 7) = exo_deepcopy(EXO_ARR(array, 1));
00210       exo_db = exo_chain(exo_db, array);
00211       exo_db =
00212         exo_chain(exo_db, exo_new(ec_array, 4,
00213                                   exo_deepcopy(a),
00214                                   exo_deepcopy(e),
00215                                   exo_deepcopy(c),
00216                                   exo_deepcopy(f),
00217                                   NULL));
00218 
00219       exo_db = exo_chain(exo_db, exo_new(ec_string, "** token tests **"));
00220 #define SYM1            1
00221 #define SYM2            2
00222       exo_intern_as("sym1", SYM1);
00223       exo_intern_as("sym2", SYM2);
00224       g = exo_new(ec_token, "sym1"),
00225       exo_db = exo_chain(exo_db,
00226                          exo_new(ec_list,
00227                                  g,
00228                                  exo_new(ec_integer,
00229                                          (exo_integer_t)
00230                                          g->as_token.ent->token),
00231                                  NULL));
00232       h = exo_new(ec_token, "sym2"),
00233       exo_db = exo_chain(exo_db,
00234                          exo_new(ec_list,
00235                                  h,
00236                                  exo_new(ec_integer,
00237                                          (exo_integer_t)
00238                                          h->as_token.ent->token),
00239                                  NULL));
00240       i = exo_new(ec_token, "sym3"),
00241       exo_db = exo_chain(exo_db,
00242                          exo_new(ec_list,
00243                                  i,
00244                                  exo_new(ec_integer,
00245                                          (exo_integer_t)
00246                                          i->as_token.ent->token),
00247                                  NULL));
00248 
00249       /* das blobs */
00250       exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data), data));
00251       exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data1), data1));
00252       exo_db = exo_chain(exo_db, exo_new(ec_blob, sizeof(data2), data2));
00253     }
00254 
00255   if (print_db)
00256     {
00257       struct exo_term_t *exo;
00258 
00259       /* emit header comment */
00260       fprintf(stdout, "\n/* EXO DB */\n\n");
00261       fprintf(stdout,
00262               "/* EXO save file, file format version %d.%d */\n\n",
00263               EXO_FMT_MAJOR, EXO_FMT_MINOR);
00264 
00265       /* emit all defs */
00266       for (exo=exo_db; exo != NULL; exo=exo->next)
00267         {
00268           exo_print(exo, stdout);
00269           fprintf(stdout, "\n\n");
00270         }
00271     }
00272 
00273   if (save_file)
00274     {
00275       ZFILE *exo_stream;
00276       struct exo_term_t *exo;
00277 
00278       exo_stream = myzfopen(save_file, "w");
00279       if (!exo_stream)
00280         fatal("could not open EXO file `%s'", save_file);
00281 
00282       /* emit header comment */
00283       fprintf(exo_stream->fd,
00284               "/* EXO save file, file format version %d.%d */\n\n",
00285               EXO_FMT_MAJOR, EXO_FMT_MINOR);
00286 
00287       /* emit all defs */
00288       for (exo=exo_db; exo != NULL; exo=exo->next)
00289         {
00290           exo_print(exo, exo_stream->fd);
00291           fprintf(exo_stream->fd, "\n\n");
00292         }
00293       myzfclose(exo_stream);
00294     }
00295 }

void usage FILE *    stream,
int    argc,
char **    argv
[static]
 

Definition at line 90 of file exo-test.c.

References opt_print_help().

00091 {
00092   fprintf(stream, "Usage: %s {-options}\n", argv[0]);
00093   opt_print_help(odb, stream);
00094 }


Variable Documentation

struct exo_term_t* exo_db = NULL [static]
 

Definition at line 87 of file exo-test.c.

int help_me [static]
 

Definition at line 72 of file exo-test.c.

Referenced by main().

char* load_file [static]
 

Definition at line 78 of file exo-test.c.

Referenced by main().

int make_defs [static]
 

Definition at line 75 of file exo-test.c.

Referenced by main().

struct opt_odb_t* odb [static]
 

Definition at line 69 of file exo-test.c.

int print_db [static]
 

Definition at line 84 of file exo-test.c.

Referenced by main().

char* save_file [static]
 

Definition at line 81 of file exo-test.c.

Referenced by main().



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214