Example #1
0
void ArgInit(int argc, char *argv[]) {
	int n,m;
	int argn=18;
	char *args[] = { "bs", "bc", "b", "u", "q", "s",
			 "da", "de", "dr", "ds", "d",
			 "vx", "v2", "v1", "v0", "v", "h", "?" };

	execargn=1;

	if(argc>=2)
	{
	    for(n=1; n<argc; n++)
	    {
		if(*argv[n]=='-' || *argv[n]=='/')
		{
		    for(m=0; m<argn; m++)
		    {
				if(stricmp(argv[n]+1, args[m])==0) switch(m)
				{

					case 0:	execargn++;	// -BS
						bindtype=1;
						goto l0;

					case 1:	execargn++;	// -BC
						bindtype=2;
						goto l0;

					case 2:	execargn++;	// -B
						bindtype=0;
						goto l0;

					case 3:	execargn++;	// -U
						bind=FALSE;
						goto l0;

					case 4:	execargn++;	// -Q
						quiet=TRUE;
						silent=FALSE;
						goto l0;

					case 5:	execargn++;	// -S
						quiet=TRUE;
						silent=TRUE;
						goto l0;

					case 6:	execargn++;	// -DA
						advanced=FALSE;
						goto l0;

					case 7:	execargn++;	// -DE
						encode=FALSE;
						goto l0;

					case 8:	execargn++;	// -DR
						strip=FALSE;
						goto l0;

					case 9:	execargn++;	// -DS
						smart=FALSE;
						goto l0;

					case 10:	execargn++;	// -D
						smart=FALSE;
						strip=FALSE;
						encode=FALSE;
						advanced=FALSE;
						goto l0;

					case 11:			// -VX & -V2
					case 12:	execargn++;
						verbose=TRUE;
						verbxtra=TRUE;
						goto l0;

				   case 13:    	execargn++;	// -V1
						verbose=TRUE;
						verbxtra=TRUE;
						nocount=TRUE;
						goto l0;

				   case 14:    	execargn++;	// -V0
						verbose=TRUE;
						nocount=TRUE;
						goto l0;

					case 15:	execargn++;	// -V
						verbose=TRUE;
						goto l0;

					case 16:
					case 17:	ShowCopyright();
						goto l1;

				}
		    }
		    ShowCopyright();
		    err_arg(argv[n]);
		}
l0:		argn=18;
	    }
	}
	ShowCopyright();

	if(argc<2 || execargn>=argc)
	{
l1:	  Print("SC/32A fatal: syntax is SC [commands] [options] <execname.xxx>\n\n");
	  Print("Commands:\n");
	  Print("---------\n");
	  Print("/B                 Bind DOS/32A to produced LC Executable\n");
	  Print("/BS                Bind STUB/32A to produced LC Executable\n");
	  Print("/BC                Bind STUB/32C to produced LC Executable\n");
	  Print("/U                 Produce Unbound Linear Compressed Executable\n\n");
	  Print("Options:\n");
	  Print("--------\n");
	  Print("/D                 Turn off all optimization features\n");
	  Print("/DA                Disable Advanced preprocessing of Executable\n");
	  Print("/DE                Disable Encoding of LC Executable (no compression)\n");
	  Print("/DR                Disable Removing of post-zero areas from Executable\n");
	  Print("/DS                Disable Smart Encoding when compressing Executable\n");
	  Print("/V[0|1|2]          Verbose mode (displays additional information)\n");
	  Print("/Q                 Quiet mode (partially disables console output)\n");
	  Print("/S                 Silent mode (totally disables console output)\n");
	  Print("/H or /?           This help\n");
	  exit(0);

	}
}
Example #2
0
int main(int argc, char* argv[]) {
	try {
    TCLAP::CmdLine cmd("Command description message", ' ', "0.2");
    
    TCLAP::SwitchArg lex_switch("l", "lex", "Process up to the Lexer phase");
    TCLAP::SwitchArg parse_switch("p", "parse", 
                                  "Process up to the Parser phase");
    TCLAP::SwitchArg sem_switch("s", "sem", 
                                "Process up to the Semantic Analyser phase");
    TCLAP::SwitchArg tup_switch("t", "tup", 
                                "Process up to the Tuple phase");
    TCLAP::SwitchArg compile_switch("c", "compile", 
                                    "Process all phases and compile (default)",
                                    true);
    TCLAP::SwitchArg quiet_switch("q", "quiet", 
                                  "Only display error messages (default)", true);
    TCLAP::SwitchArg verbose_switch("v", "verbose", 
                                    "Display all Trace messages");
    TCLAP::ValueArg< std::string > out_arg("o", "out", 
                                           "Output file (default -out=STDOUT)", 
                                           false, "out", "string");
    TCLAP::ValueArg< std::string > err_arg("e", "err", 
                                           "Error file (default -err=STDOUT)", 
                                           false, "err", "string");
    TCLAP::UnlabeledMultiArg<std::string> input_args("input", "Input files", true, "string");
    
    std::vector<TCLAP::Arg*> args;
    args.push_back(&lex_switch);
    args.push_back(&parse_switch);
    args.push_back(&sem_switch);
    args.push_back(&tup_switch);
    args.push_back(&compile_switch);
    cmd.xorAdd(args);
    cmd.add(quiet_switch);
    cmd.add(verbose_switch);
    cmd.add(out_arg);
    cmd.add(err_arg);
    cmd.add(input_args);

    cmd.parse(argc, argv);

    std::vector< std::string > inputFiles = input_args.getValue();
    if (inputFiles.size() == 0) {
      fprintf(stderr, "No input files. Please specify 1 or more .cs13 files using -I <file>\n");
      return -1;
    }

    Administrator *admin;
    std::string err = err_arg.getValue();
    if (err.compare("err") != 0) {  
      // Have to create the error file to be able to write to it
      std::ofstream filestream(err_arg.getValue());
      if (!filestream) {
        fprintf(stderr, "Error creating %s\n", err_arg.getValue().c_str());
        return -1;
      }
      filestream.clear();
      filestream.close();
      admin = new Administrator(inputFiles, err_arg.getValue());
    } else {
      admin = new Administrator(inputFiles);
    }
    std::string out = out_arg.getValue();
    if (out.compare("out") != 0) {
      admin->set_output_file(out_arg.getValue());
    }

    if (verbose_switch.isSet()) {
      admin->ShowTrace(true);
    }
    
    if (lex_switch.isSet()) {
      admin->LexerPhase();
    } else if (parse_switch.isSet()) {
      admin->ParserPhase();
    } else if (sem_switch.getValue()) {
		  admin->SemanticAnalysisPhase();
    } else if (tup_switch.isSet()) {
      admin->TupleGenerationPhase();
    } else {
      admin->Compile();
    }    
	} catch(TCLAP::ArgException &e) {
    fprintf(stderr, "error: %s for arg %s\n", e.error().c_str(), e.argId().c_str());
	}

  return 0;
}