+ char *cmd, *t = NULL;
+ int r, len;
+ const char *ext;
+
+ /* Open the output file. */
+ switch (output_mode) {
+ case output_c: ext = ".c"; break;
+ case output_h: ext = ".h"; break;
+ default: error ("internal error in do_rpcgen / output_mode");
+ }
+
+ if (out && strcmp (out, "-") == 0) {
+ output_filename = NULL;
+ unlink_output_filename = 0;
+ yyout = stdout;
+ }
+ else if (out) {
+ output_filename = out;
+ unlink_output_filename = 1;
+ yyout = fopen (output_filename, "w");
+ if (yyout == NULL)
+ perrorf ("%s", output_filename);
+ }
+ else {
+ len = strlen (filename);
+ t = malloc (len + 3);
+ if (t == NULL)
+ perrorf ("malloc");
+ strcpy (t, filename);
+ if (len >= 2 && strcmp (t + len - 2, ".x") == 0)
+ strcpy (t + len - 2, ext);
+ else
+ strcat (t, ext);
+ output_filename = t;
+ unlink_output_filename = 1;
+ yyout = fopen (output_filename, "w");
+ if (yyout == NULL)
+ perrorf ("%s", output_filename);
+ }