Example #1
0
void
gencfile (str fname)
{
  aout << "// -*-c++-*-\n"
       << "/* This file was automatically generated by rpcc. */\n\n"
       << "#include \"" << makehdrname (fname) << "\"\n\n";

#if 0
  for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++)
    if (s->type == rpc_sym::PROGRAM)
      for (const rpc_vers *rv = s->sprogram->vers.base ();
	   rv < s->sprogram->vers.lim (); rv++)
	for (const rpc_proc *rp = rv->procs.base ();
	     rp < rv->procs.lim (); rp++) {
	  needtype.insert (rp->arg);
	  needtype.insert (rp->res);
	}
#endif

  aout << "#ifdef MAINTAINER\n\n";
  for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++)
    dumpprint (s);
  aout << "#endif /* MAINTAINER*/\n";

  for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++)
    dumpsym (s);

  aout << "\n";
}
Example #2
0
void
genheader (str fname)
{
  str guard = makeguard (fname);

  aout << "// -*-c++-*-\n"
       << "/* This file was automatically generated by rpcc. */\n\n"
       << "#ifndef " << guard << "\n"
       << "#define " << guard << " 1\n\n"
       << "#include \"xdrmisc.h\"\n";

  int last = rpc_sym::LITERAL;
  for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++) {
    if (last != s->type
	|| last == rpc_sym::PROGRAM
	|| last == rpc_sym::TYPEDEF
	|| last == rpc_sym::STRUCT
	|| last == rpc_sym::UNION
	|| last == rpc_sym::ENUM)
      aout << "\n";
    last = s->type;
    dumpsym (s);
  }

  aout << "#endif /* !" << guard << " */\n";
}
Example #3
0
void
genpython (str fname)
{
   aout << "# -*-python-*-\n"
        << "# This file was automatically generated by rpcc.\n\n"
        << "class Procedure(object):\n"
        << "\t__slots__ = [ 'pack_arg', 'unpack_arg',"
        << " 'pack_res', 'unpack_res' ]\n\n"
        << "programs = {}\n\n";

   aout << "def pack_ptr(p, o, packf):\n"
        << "\tif o is None:\n"
        << "\t\tp.pack_uint(0)\n"
        << "\telse:\n"
        << "\t\tp.pack_uint(1)\n"
        << "\t\tpackf(o)\n"
        << "def unpack_ptr(u, unpackf):\n"
        << "\tbit = u.unpack_uint()\n"
        << "\tif bit:\n"
        << "\t\treturn unpackf()\n"
        << "\telse:\n"
        << "\t\treturn None\n\n";

   deffns("void", "pass", "None");

   str types[] = {"int", "uint", "hyper", "uhyper",
                  "float", "double", "bool"};
   for (int i = 0; i < 7; i++) {
     deffns(types[i], strbuf() << "p.pack_" << types[i] << "(o)",
            strbuf() << "u.unpack_" << types[i] << "()");
   }
   deffns("u_int32_t", "p.pack_uint(o)", "u.unpack_uint()");
   deffns("int32_t", "p.pack_int(o)", "u.unpack_int()");
   deffns("u_int64_t", "p.pack_uhyper(o)", "u.unpack_uhyper()");
   deffns("int64_t", "p.pack_hyper(o)", "u.unpack_hyper()");

   int last = rpc_sym::LITERAL;
   for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++) {
     if (last != s->type
         || last == rpc_sym::PROGRAM
         || last == rpc_sym::TYPEDEF
         || last == rpc_sym::STRUCT
         || last == rpc_sym::UNION
         || last == rpc_sym::ENUM)
       aout << "\n";
     last = s->type;
     dumpsym (s);
   }
}
Example #4
0
void
genheader (str fname)
{
  str guard = makeguard (fname);

  aout << "// -*-c++-*-\n"
       << "/* This file was automatically generated by XMLRPCC. */\n\n"
       << "#ifndef " << guard << "\n"
       << "#define " << guard << " 1\n\n"
       << "#include \"xdrmisc.h\"\n";

  start_xml_guard ();
  aout << "#include \"okxmlxlate.h\"\n";
  end_xml_guard ();

  int last = rpc_sym::LITERAL;
  for (const rpc_sym *s = symlist.base (); s < symlist.lim (); s++) {
    if (last != s->type
	|| last == rpc_sym::PROGRAM
	|| last == rpc_sym::TYPEDEF
	|| last == rpc_sym::STRUCT
	|| last == rpc_sym::UNION
	|| last == rpc_sym::ENUM)
      aout << "\n";
    last = s->type;
    dumpsym (s);
  }

  start_xml_guard ();
  aout << "extern xml_rpc_file " << stripfname (fname, false)
       << "_rpc_file;\n";
  end_xml_guard ();

  dump_constant_collect_hook (fname);

  aout << "#endif /* !" << guard << " */\n";
}
Example #5
0
int main (int argc, char *argv[])
{
  char *version_string = "Algebraic Preprocessor (Aprepro)";
  int c;
  time_t time_val;
  struct tm *time_structure;
  char *asc_time = NULL;
  char *include_file = NULL;
  
#define NO_ARG 0
#define IS_ARG 1
#define OP_ARG 2

  static struct option long_options[] =
    {
      {"debug",       NO_ARG, 0, 'd'},
      {"statistics",  NO_ARG, 0, 's'},
      {"copyright",   NO_ARG, 0, 'C'},
      {"comment",     IS_ARG, 0, 'c'},
      {"version",     NO_ARG, 0, 'v'},
      {"interactive", NO_ARG, 0, 'i'},
      {"include",     IS_ARG, 0, 'I'},
      {"exit_on",     NO_ARG, 0, 'e'},
      {"help",        NO_ARG, 0, 'h'},
      {"nowarning",   NO_ARG, 0, 'W'},
      {"messages",    NO_ARG, 0, 'M'},
      {"quiet",       NO_ARG, 0, 'q'},
      {"immutable",   NO_ARG, 0, 'X'},
      {"one_based_index", NO_ARG, 0, '1'},
      {NULL,          NO_ARG, NULL, 0}
    };

  int  option_index = 0;
  extern int optind;
  extern char *optarg;

  myname = strrchr (argv[0], '/');
  if (myname == NULL)
    myname = argv[0];
  else
    myname++;

  /* Process command line options */
  initialize_options(&ap_options);
  
  ap_options.end_on_exit = False;
  while ((c = getopt_long (argc, argv, "c:dDsSvViI:eEwWmMhHCqX1",
			   long_options, &option_index)) != EOF)
    {
      switch (c)
	{
	case 'c':
	  NEWSTR(optarg, ap_options.comment);
	  break;

	case 'd':
	case 'D':
	  ap_options.debugging = True;
	  ap_options.info_msg = True;
	  ap_options.warning_msg = True;
	  break;

	case 's':
	case 'S':		/* Print hash statistics */
	  ap_options.statistics = True;
	  break;

	case 'C':		/* Print copyright message */
	  ap_options.copyright = True;
	  break;

	case 'v':
	case 'V':
	  fprintf (stderr, "%s: (%s) %s\n", version_string, qainfo[2], qainfo[1]);
	  break;

	case 'i':
	  ap_options.interactive = True;
	  break;

	case 'I':
	  /*
	   * Check whether optarg specifies a file or a directory
	   * If a file, it is an include file,
	   * If a directory, it is an include_path
	   */
	  if (is_directory(optarg)) {
	    NEWSTR(optarg, ap_options.include_path);
	  } else {
	    NEWSTR(optarg, include_file);
	  }
	  break;
	  
	case 'e':
	case 'E':
	  ap_options.end_on_exit = True;
	  break;

	case 'W':
	  ap_options.warning_msg = False;
	  break;

	case 'q':
	  ap_options.quiet = True;
	  break;

	case 'M':
	  ap_options.info_msg = True;
	  break;

	case 'X':
	  ap_options.immutable = True;
	  break;

	case '1':
	  ap_options.one_based_index = True;
	  break;
	  
	case 'h':
	case 'H':
	  usage();
	  exit(EXIT_SUCCESS);
	  break;
	  
	case '?':
	default:
	  /* getopt will print a message for us */
	  usage ();
	  exit(EXIT_FAILURE);
	  break;
	}
    }

  /* Process remaining options.  If '=' in word, then it is of the form
   * var=value.  Set the value.  If '=' not found, process remaining
   * options as input and output files
   */
  while (optind < argc && strchr(argv[optind], '=') && !strchr(argv[optind], '/')) {
    char *var, *val;
    double value;
    symrec *s;

    var = argv[optind++];
    val = strchr (var, '=');
    if (val == NULL) {
      fprintf(stderr, "ERROR: '%s' is not a valid form for assiging a variable; it will not be defined\n", var);
    } else {
      *val++ = '\0';
      if (!check_valid_var(var)) {
	fprintf(stderr, "ERROR: '%s' is not a valid form for a variable; it will not be defined\n", var);
      } else {
	if (strchr(val, '"') != NULL) { /* Should be a string variable */
	  char *pt = strrchr(val, '"');
	  if (pt != NULL) {
	    val++;
	    *pt = '\0';
	    if (var[0] == '_')
	      s = putsym(var, SVAR, 0);
	    else
	      s = putsym(var, IMMSVAR, 0);
	    NEWSTR(val, s->value.svar);
	  }
	  else {
	    fprintf(stderr, "ERROR: Missing trailing \" in definition of variable '%s'; it will not be defined\n", var);
	  }
	}
	else {
	  int err = sscanf (val, "%lf", &value);
	  if (err <= 0) {
	    fprintf(stderr, "ERROR: Could not parse value in assignment of variable '%s'; it will not be defined\n", var);
	  }
	  else {
	    if (var[0] == '_')
	      s = putsym (var, VAR, 0);
	    else
	      s = putsym (var, IMMVAR, 0);
	    s->value.var = value;
	  }
	}
      }
    }
  }

  if (ap_options.copyright == True)
    copyright_output();
  /* Assume stdin, recopy if and when it is changed */
  yyin = stdin;
  yyout = stdout;

  if (argc > optind) {
    add_input_file(argv[optind]);
  }
  else {
    NEWSTR ("stdin", ap_file_list[nfile].name);
    SET_FILE_LIST (nfile, 0, False, 1);
  }
  if (argc > ++optind) {
    yyout = open_file(argv[optind], "w");
  }
  else {  /* Writing to stdout */
    if (ap_options.interactive)
      setbuf (yyout, (char *) NULL);
  }

  state_immutable = ap_options.immutable;

  
  time_val = time ((time_t*)NULL);
  time_structure = localtime (&time_val);
  asc_time = asctime (time_structure);

  /* NOTE: asc_time includes \n at end of string */
  if (!ap_options.quiet) {
    if (state_immutable) {
      fprintf (yyout, "%s Aprepro (%s) [immutable mode] %s", ap_options.comment, qainfo[2], asc_time);
    } else {
      fprintf (yyout, "%s Aprepro (%s) %s", ap_options.comment, qainfo[2], asc_time);
    }
  }

  if (include_file) {
    nfile++;
    add_input_file(include_file);
    /* Include file specified on command line is processed in immutable
     * state. Reverts back to global immutable state at end of file.
     */
    state_immutable = True;
    echo = False;
  }

  srand((unsigned)time_val);
  
  init_table (ap_options.comment);
  yyparse ();
  if (ap_options.debugging > 0)
    dumpsym (VAR, 0);
  if (ap_options.statistics > 0)
    pstats ();
  add_to_log(myname, 0);
  return (EXIT_SUCCESS);
}				/* NOTREACHED */
Example #6
0
char *
do_dumpvar(void)
{
  dumpsym(VAR, 1);
  return("");
}
Example #7
0
char *
do_dumpfunc(void)
{
  dumpsym(FNCT, 1);
  return("");
}
Example #8
0
char *
do_dumpsym(void)
{
  dumpsym(VAR, 0);
  return("");
}