Beispiel #1
0
int main()
{
    char filename[25];
    int j,ch,c,addr=0X0;
    printf("\n Insert the input file:");
    gets(filename);
    do
    {
     printf("\n Enter your choice:\n 1.Symbol table\n 2.Program length\n 3.Object program\n 4.Rellocate\n 5.Exit");
     fflush(stdin);
     scanf("%d",&ch);
    switch(ch)
    {
      case 1:
              pass1(filename,addr);
              printf("\n The SYMTAB is as follows:\n\n\n\t\t\n");
              printf("\tLABEL\t\tADDRESS\n");
              printf("\t-----\t\t-------\n");
              for(j=0;j<s;j++)
              {
                printf("\t%s\t\t%X\n",symbol[j].symbol_name,symbol[j].symbol_addr);
              }
              printf("\t\t\n");
              break;
      case 2:
              pass1(filename,addr);
              printf("\n The PROGRAM LENGTH is=%X\n",length);
              break;
      case 3:
              pass1(filename,addr);
              pass2();
              break;
      case 4:
              printf("\n Enter the address");
              scanf("%X",&addr);
              pass1(filename,addr);
              printf("\n The SYMTAB is as follows:\n\n\n\t\t\n");
              printf("\tLABEL\t\tADDRESS\n");
              printf("\t-----\t\t-------\n");
              for(j=0;j<s;j++)
              {
                printf("\t%s\t\t%X\n",symbol[j].symbol_name,symbol[j].symbol_addr);
              }
              printf("\t\t\n");
              printf("\n The PROGRAM LENGTH is=%X\n",length);
              pass2();
              break;
      case 5:
              exit(0);
      default:
             printf("\n wrong choice");
    }
    }while(ch!=5);
    return(0);
}
Beispiel #2
0
int main(int argc, const char *argv[])
{
    char buff[64];
    read(0,buff,sizeof(buff));
    pass1(buff);
    return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	int len;

	init();
	options(argc, argv);
	printf("Z80 - Assembler Release %s, %s\n", REL, COPYR);
	pass1();
	pass2();
	if (list_flag) {
		switch (sym_flag) {
		case 0:		/* no symbol table */
			break;
		case 1:		/* unsorted symbol table */
			lst_sym();
			break;
		case 2:		/* symbol table sorted by name */
			len = copy_sym();
			n_sort_sym(len);
			lst_sort_sym(len);
			break;
		case 3:		/* symbol table sorted by address */
			len = copy_sym();
			a_sort_sym(len);
			lst_sort_sym(len);
			break;
		default:
			break;
		}
		fclose(lstfp);
	}
	return(errors);
}
Beispiel #4
0
void PrefWidget::onChangeClicked()
{
  std::string pass1(password1->text().toUTF8());
  std::string pass2(password2->text().toUTF8());
  if (pass1 != pass2)
  {
    errorText->show();
  }
  else
  {
    errorText->hide();

    QSharedPointer<std::vector<QSharedPointer<common::User> > > users =
      common::DbSession::getInstance().getUsers();

    for (int i = 0; i < users->size(); i++)
    {
      QSharedPointer<loader::User> user = users->at(i).
        dynamicCast<loader::User>();

      std::string token = user->getToken();
      if (m_token == token)
      {
        user->setPassword(pass1);
        common::DbSession::getInstance().storeUser(user);
        break;
      }
    }
    password1->setText("");
    password2->setText("");
  }
}
Beispiel #5
0
//Renderfunctions
void LightSolver::render(sf::RenderTarget& target)
{
	fullScreenBuffer.clear(sf::Color(100, 100, 200, 255));
	colorBuffer.clear(sf::Color::Transparent);

	sf::View originalView = fullScreenBuffer.getView();
	const sf::View& view = target.getView();
	fullScreenBuffer.setView(view);
	colorBuffer.setView(view);

	//First pass calculates the lights based on the occluders
	//and writes their colors to the color buffer
	pass1();

	//Restore the original view.
	fullScreenBuffer.setView(originalView);
	colorBuffer.setView(originalView);

	//Second pass merges the color buffer with the fullscreen buffer.
	pass2();

	sf::Sprite sprite = sf::Sprite(getResult());
	sf::Vector2f pos = sf::Vector2f(view.getCenter().x - view.getSize().x / 2.0f, view.getCenter().y - view.getSize().y / 2.0f);
	sprite.setPosition(pos);
	target.draw(sprite, sf::BlendMultiply);

	sprite.setTexture(colorBuffer.getTexture());
	target.draw(sprite, sf::BlendAdd);
}
void main()
{
	FILE *fp,*mnt,*mdt,*ic,*ec;
	struct Instruction in;
	clrscr();
	fp=fopen("./MACRO/COD1.TXT","r");
	mnt=fopen("./MACRO/MNT.TXT","w+");
	mdt=fopen("./MACRO/MDT.TXT","w+");
	ic=fopen("./MACRO/IC.TXT","w+");
	ec=fopen("./MACRO/EC.TXT","w+");
	printf("\n Source Code :\n");
	while(fscanf(fp,"%s%s%s%s",in.lbl,in.mnem,in.op1,in.op2)!=EOF)
	{
		printf("%s %s %s %s\n",in.lbl,in.mnem,in.op1,in.op2);
	}
	getch();
	clrscr();
	pass1(fp,mnt,mdt,ic);
	getch();
	pass2(mnt,mdt,ic,ec);
	fclose(mnt);
	fclose(mdt);
	fclose(ic);
	fclose(fp);
	fclose(ec);
	getch();
}
Beispiel #7
0
int main()
{
    pass1();                  //addressing
    printf("\n\n");
    pass2();                  //obj code
    printf("\n\n");
    t_record();                  //record
    return 0;
}
Beispiel #8
0
void RenderEngine::render(double elapsed)
{
    m_Framebuffer->bind();
    pass1(elapsed);
    m_Framebuffer->unbind();
    pass2(elapsed);

    glfwSwapBuffers();
}
Beispiel #9
0
int cn_set_str(cn_t cn, const char *str){
  int ret;

  ret = pass1(cn, str);
  if(ret != CN_OK){
    return ret;
  }
  return pass2(cn, str);
}
Beispiel #10
0
void assemble(string file) {
  char inFile[100], outFile[100];
  sprintf(inFile, "%s.asm", file);
  sprintf(outFile, "%s.my.hack", file);
  symDump(symTable, symTop);
  pass1(inFile);
  symDump(symTable, symTop);
  pass2(inFile, outFile);
}
Beispiel #11
0
void check(char *file)
{
	int i, j;
	ino_t mino;

	fi = open(file, 0);
	if(fi < 0) {
		fprintf(stderr, "ncheck: cannot open %s\n", file);
		nerror++;
		return;
	}
	nhent = 0;
	printf("%s:\n", file);
	sync();
	bread((daddr_t)1, (char *)&sblock, sizeof(sblock));
	mino = sblock.s_isize * INOPB;
	ino = 0;
	for(i=2;; i+=NI) {
		if(ino >= mino)
			break;
		bread((daddr_t)i, (char *)itab, sizeof(itab));
		for(j=0; j<INOPB*NI; j++) {
			if(ino >= mino)
				break;
			pass1(&itab[j]);
			ino++;
		}
	}
	ilist[nxfile+1] = 0;
	ino = 0;
	for(i=2;; i+=NI) {
		if(ino >= mino)
			break;
		bread((daddr_t)i, (char *)itab, sizeof(itab));
		for(j=0; j<INOPB*NI; j++) {
			if(ino >= mino)
				break;
			pass2(&itab[j]);
			ino++;
		}
	}
	ino = 0;
	for(i=2;; i+=NI) {
		if(ino >= mino)
			break;
		bread((daddr_t)i, (char *)itab, sizeof(itab));
		for(j=0; j<INOPB*NI; j++) {
			if(ino >= mino)
				break;
			pass3(&itab[j]);
			ino++;
		}
	}
}
int main()
{
	char filename[20];
	printf("Enter file to be assembled : ");
	scanf("%s",filename);
	
	printf("Starting pass1.\n");
	pass1(filename);
	printf("Pass1 complete. Intermediate code written to intermediate.txt .\nSymbol table written to symboltable.txt\n\n\n");
	return 0;
}
void ReduceSurfaceTriangulation::operate()
{
  setStretchingFactor(1.0);
  prepare();
  //writeGrid(m_Grid, "take1");
  updateNodeInfo();
  //writeGrid(m_Grid, "take2");
  pass1();
  //pass2();
  createIndices(m_Grid);
  updateNodeInfo();
  computeMeshDensity();
}
Beispiel #14
0
int main()
{     char a[20],b[10],pname[50];
 int d[60],size;
	 FILE *fp1 = fopen("sym.txt", "w");
      FILE *fp2 = fopen("int.txt", "w");
    FILE *f = fopen("input4.txt", "r");
     pass1( a,b,d,pname,fp1,fp2,f,&size);
      fp1 = fopen("sym.txt", "r");
       f = fopen("int.txt", "r");
     fp2 = fopen("object.txt", "w");
     pass2( a,b,d,fp1,fp2,f);
     objprog(pname,d,size);   
	 	
}
Beispiel #15
0
void
parse_cpp(State *s)
{
	int l, alloc;
	char *p, *buf;
	struct {
		char *name;
		void (*func)(State *, char *);
	} *d, dir[] = {
		{ "include",	doinclude },
		{ "define",	dodefine },
		{ "ifndef",	doifndef },
		{ "undef",	doundef },
		{ "ifdef",	doifdef },
		{ "endif",	doendif },
		{ "elif",	doelif },
		{ "else",	doelse },
		{ "if",		doif },
		{ "pragma",	dopragma },
	};
	
	alloc = Memchunk;
	buf = emallocz(alloc, 0);
	while((buf = pass1(s, buf, &alloc)) != nil){
		p = buf;
		while(isspace(*p))
			p++;
		if(*p++ != '#')
			continue;

		while(isspace(*p))
			p++;
		for(d = dir; d < &dir[nelem(dir)]; d++){
			l = strlen(d->name);
			if(strncmp(p, d->name, l) == 0){
				p += l;
				break;
			}
		}
		if(d >= &dir[nelem(dir)])
			continue;

		while(isspace(*p))
			p++;
//print("%s:%d %s %s [%d -> ", s->file, s->line, d->name, p, peek(s));
		d->func(s, p);
//print("%d]\n", peek(s));
	}
	free(buf);
}
Beispiel #16
0
void check(char *file)
{
	int i;
	int j;

	fi = open(file, 0);
	if(fi < 0) {
		printf("cannot open %s\n", file);
		nerror++;
		return;
	}
	headpr = 0;
	printf("%s:\n", file);
	sync();
	bread((daddr_t)1, (char *)&sblock, sizeof(sblock));
	nfiles = sblock.s_isize*INOPB;
	ecount = malloc(nfiles);
	if (ecount==NULL) {
		printf("Not enough core\n");
		exit(04);
	}
	for (i=0; i<nfiles; i++)
		ecount[i] = 0;
	ino = 0;
	for(i=2;; i+=NI) {
		if(ino >= nfiles)
			break;
		bread((daddr_t)i, (char *)itab, sizeof(itab));
		for(j=0; j<INOPB*NI; j++) {
			if(ino >= nfiles)
				break;
			pass1(&itab[j]);
			ino++;
		}
	}
	ino = 0;
	for(i=2;; i+=NI) {
		if(ino >= nfiles)
			break;
		bread((daddr_t)i, (char *)itab, sizeof(itab));
		for(j=0; j<INOPB*NI; j++) {
			if(ino >= nfiles)
				break;
			pass2(&itab[j]);
			ino++;
		}
	}
	free(ecount);
}
Beispiel #17
0
void optFinalize(poffHandle_t poffHandle, poffProgHandle_t poffProgHandle)
{
  /* Build label / line number reference table */

  pass1(poffHandle, poffProgHandle);

  /* Reset for next pass */

  insn_ResetOpCodeRead(poffHandle);
  insn_ResetTmpOpCodeWrite(poffProgHandle);

  /* Now process all of the symbols */

  pass2(poffHandle, poffProgHandle);

  /* We do not use the debug function information so we do not bother
   * to fixup the label references.  Just discard this information.
   */

  poffDiscardDebugFuncInfo(poffHandle);

  /* Reset for next pass */

  insn_ResetOpCodeRead(poffHandle);

  /* Generate relocation information and replace all label references
   * in the code with actual program section data offsets.
   */

  pass3(poffHandle, poffProgHandle);

  /* Reset for next pass */

  insn_ResetOpCodeRead(poffHandle);
  insn_ResetTmpOpCodeWrite(poffProgHandle);

  /* Finally, replace file header entry point with the I-space offset */

  pass4(poffHandle);

  /* Clean up after ourselves */

  poffReleaseLabelReferences();
}
int main(void){
	
	/* do PASS 1 */
	if(!(source_file = fopen("source_code.txt", "r"))){
		printf("SOURCE CODE OPENED ERROR.\n");
		exit(1);
	}
	
	if(!(intermediate_file = fopen("intermediate_file.txt", "w"))){
		printf("INTERMEDIATE FILE CREATED ERROR.\n");
		exit(1);
	}
	
	init_Func();     // Initialization
	
	pass1();
	fclose(source_file);
	fclose(intermediate_file);
	printf("\n\n======================= PASS 1 finished. =======================\n\n\n");
	/* PASS 1 END */
	
	/* do PASS 2 */
	if(!(intermediate_file = fopen("intermediate_file.txt", "r"))){
		printf("INTERMEDIATE FILE OPENED ERROR.\n");
		exit(1);
	}
	
	if(!(object_file = fopen("object_file.txt", "w"))){
		printf("OBJECT FILE CAN NOT BE CREATED.\n");
		exit(1);
	}
	
	pass2();
	
	fclose(intermediate_file);
	fclose(object_file);
	/* PASS 2 END */
	printf("\n\n======================= PASS 2 finished. =======================\n\n\n");
	
	system("PAUSE");
	return 0;
}
void MyWindow::render()
{
    if(!isVisible() || !isExposed())
        return;

    if (!mContext->makeCurrent(this))
        return;

    static bool initialized = false;
    if (!initialized) {
        initialize();
        initialized = true;
    }

    if (mUpdateSize) {
        glViewport(0, 0, size().width(), size().height());
        mUpdateSize = false;
    }

    float deltaT = currentTimeS - tPrev;
    if(tPrev == 0.0f) deltaT = 0.0f;
    tPrev = currentTimeS;
    angle += 0.25f * deltaT;
    if (angle > TwoPI) angle -= TwoPI;

    static float EvolvingVal = 0;
    EvolvingVal += 0.1f;

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindFramebuffer(GL_FRAMEBUFFER, mFBOHandle);
    pass1();

    glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO);
    pass2();

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    pass3();

    mContext->swapBuffers(this);
}
Beispiel #20
0
int main(int argc, char *argv[]) {
	int fsck = 0;
	int opt;
	opterr = 0;
	while ((opt = getopt(argc, argv, "f:p:i:")) != -1) {
		switch (opt) {
			case 'f':
				fsck = 1;
			case 'p':
				theParNum = atoi(optarg);
				break;
			case 'i':
				diskFileName = optarg;
				break;
			default:
				break;
		}
	}
	if (diskFileName == 0) {
		printf("Argument error\n");
		return 0;
	}
//	printf("%d %d %s\n", fsck, pNum, diskFileName);
	
	printPartitionInfo(fsck);
	if (fsck) {
		int i;
//		printf("%d\n", pNum);
		for (i = 1; i <= pNum; ++i)
			if (par[i].type == EXT2_TYPE && (theParNum == 0 || theParNum == i)) {
			init(i, par[i].start);
			pass1();
			pass2();
			pass3();
			pass4();
			cleanup();
		}
	}
//	ext2fsutilTest(par[1].start, par[1].length);
	
	return 0;
}
Beispiel #21
0
Score::FileError importMusicXMLfromBuffer(Score* score, const QString& /*name*/, QIODevice* dev)
      {
      //qDebug("importMusicXMLfromBuffer(score %p, name '%s', dev %p)",
      //       score, qPrintable(name), dev);

      MxmlLogger logger;
      logger.setLoggingLevel(MxmlLogger::Level::MXML_INFO);
      //logger.setLoggingLevel(MxmlLogger::Level::MXML_TRACE); // also include tracing

      // pass 1
      dev->seek(0);
      MusicXMLParserPass1 pass1(score, &logger);
      Score::FileError res = pass1.parse(dev);
      if (res != Score::FileError::FILE_NO_ERROR)
            return res;

      // pass 2
      dev->seek(0);
      MusicXMLParserPass2 pass2(score, pass1, &logger);
      return pass2.parse(dev);
      }
Beispiel #22
0
int main(int argc, char *argv[]) {
  char *filename=argv[1];
  pass1(filename);
  pass2(filename);
}
Beispiel #23
0
int main(int argc, char **argv)
{
    char *buf;
    char *op;

    if(argc != 2){
        fprintf(stderr, "syntax: fsck [devfile][:offset]\n");
        return 1;
    }
    
    op = strchr(argv[1], ':');
    if (op) {
        *op++ = 0;
        offset = atol(op);
    }

    if(fd_open(argv[1])){
        printf("Cannot open file\n");
        return -1;
    }

    buf = daread(1);
    bcopy(buf, (char *) &superblock, sizeof(struct filesys));

    /* Verify the fsize and isize parameters */
    if (superblock.s_mounted == SMOUNTED_WRONGENDIAN) {
        swizzling = 1;
        printf("Checking file system with reversed byte order.\n");
    }

    if (swizzle16(superblock.s_mounted) != SMOUNTED) {
        printf("Device %d has invalid magic number %d. Fix? ", dev, superblock.s_mounted);
        if (!yes())
            exit(-1);
        superblock.s_mounted = swizzle16(SMOUNTED);
        dwrite((blkno_t) 1, (char *) &superblock);
    }
    printf("Device %d has fsize = %d and isize = %d. Continue? ",
            dev, swizzle16(superblock.s_fsize), swizzle16(superblock.s_isize));
    if (!yes())
        exit(-1);

    bitmap = calloc(swizzle16(superblock.s_fsize), sizeof(char));
    linkmap = (int16_t *) calloc(8 * swizzle16(superblock.s_isize), sizeof(int16_t));

    if (!bitmap || !linkmap) {
        fprintf(stderr, "Not enough memory.\n");
        exit(-1);
    }

    printf("Pass 1: Checking inodes...\n");
    pass1();

    printf("Pass 2: Rebuilding free list...\n");
    pass2();

    printf("Pass 3: Checking block allocation...\n");
    pass3();

    printf("Pass 4: Checking directory entries...\n");
    pass4();

    printf("Pass 5: Checking link counts...\n");
    pass5();

    printf("Done.\n");

    exit(0);
}
Beispiel #24
0
int main(int argc,char **argv)
{

	char ofile[255];
	int j,res;

	if(argc==1)
	{
		printf("\nUse:asm85 [option] <filename>");
		printf("\noptions:");
		printf("\n-o <file> - Give the output filename");
		printf("\n-s  Show the machine opcode table");
		printf("\n-i  Enter opcodes into opcode table");
		printf("\nDefault mot file is mot.dat");
		printf("\n");
		return EXIT_SUCCESS;
	}

	if(argc>=2)
	{
		int flag=1;
		j=strcmp(*(argv+1),"-o");
		if(j==0)
		{
			flag=0;
			if(*(argv+2)==NULL)
			{
				printf("\nYou must specify an output file");
				return EXIT_SUCCESS;
			}
			else
				strcpy(ofile,*(argv+2));
			if(*(argv+3)==NULL)
			{
				printf("\nasm85: no input files specified");
				return EXIT_SUCCESS;
			}
			strcpy(filename,*(argv+3));
		}
		j=strcmp(*(argv+1),"-s");
		if(j==0)
		{
			char *file[]={"sdf","mot.dat"};
			flag=0;
			disp(2,&file);
			exit(EXIT_SUCCESS);
		}
		j=strcmp(*(argv+1),"-i");
		if(j==0)
		{
			char *file[]={"df","mot.dat"};
			flag=0;
			input(2,&file);
			exit(EXIT_SUCCESS);
		}

		if(flag)
		{
			strcpy(filename,*(argv+1));
			strcpy(ofile,"c:\\outfile.txt");
		}
	}

	else
	{
		strcpy(filename,*(argv+1));
		strcpy(ofile,"c:\\outfile.txt");
	}


	pass1();

	pass2();

	/*ASSEMBLING DONE, WRITE THE OUPUT FILES */
	res=writeoutfile(ofile);
	if(res==1)
	{
		fprintf(stderr,"\nAn error occur while writing to output file");
		return EXIT_FAILURE;
	}
	else
		printf("\nOutput written to %s",ofile);


	return EXIT_SUCCESS;
}
//function to display the menu
void menu()
{
	int choice,ret;

	printf("\n\n\tAssembler to Our ISA::\n");
	printf("\tThe menu is:\n");
	printf("\t1.Display Assembly Language Code.\n"); // displays the code you have typed.
	printf("\t2.Display Machine Code.\n");  // displays the machine code generated on the console itself.
	printf("\t3.Display Symbol Table.\n"); // displays only the symbol table and no machine code is generated.
	printf("\t4.Generate Machine Code.\n"); // generates all the files symbol table file and machine code file but not displayed on console.
	printf("\t5.ISA Help.\n"); // to display the isa help
	printf("\t6.Exit.\n"); // to exit from file
	printf("\n\nEnter your choice?\n");
	scanf("%d",&choice);
	switch(choice)
	{
		
		case 1:

				printf("\n\tThe Assembly Language Code is:\n");
				displaycode();
				menu();
				break;
		
		case 2:
				ret=pass1();
				if(ret!=0)
				{
					printf("\n%d Errors in code.Please check the program.!\n",ret);
					menu();
				}
				else
				{
					pass2(); // pass2 function generates the machine code.
					displaymachinecode();
					menu();
				}
				break;
		case 3:
			
				ret=pass1();
				if(ret!=0)
				{
					printf("Cannot Display Symbol Table.\n");
					printf("\n%d Errors in code.Please check the program.!\n",ret);
					menu();
				}
				else
				{
					printf("The symbol Table is as follows::\n\n");
					displaysymboltable(); //displays the symbol table
					menu();
				}
				break;

		case 4:

				ret=pass1();
				if(ret!=0)
				{
					printf("\n%d Errors in code.Please check the program.!\n",ret);
					menu();
				}
				else
				{
					pass2(); // pass2 function generates the machine code.
					menu();
				}
				break;

		case 5:
				
				printf("The help is as follows::\n\n");
				help(); // displays the isa help.
				menu();
				break;

		case 6:

				exit(0);
				break;
		
		default:

				printf("Wrong Choice.Enter again..!!");
				menu();
	
	}
}
Beispiel #26
0
int main(int argc,char *argv[])
{
     int er=1,i;
     signed char *s=NULL;
     char *tmpp;

     int mifiles = 5;
     int nifiles = 0;
     int verbose = 0;
     int oldfile = 0;
     int no_link = 0;

     char **ifiles;
     char *ofile;
     char *efile;
     char *lfile;
     char *ifile;
     
     char old_e[MAXLINE];
     char old_l[MAXLINE];
     char old_o[MAXLINE];

     tim1=time(NULL);
     
     ncmos=0;
     n65816=0;
     cmosfl=1;
     w65816=0;	/* default: 6502 only */

     altppchar = '#' ; /* i.e., NO alternate char */

     if((tmpp = strrchr(argv[0],'/'))) {
	tmpp++;
     } else {
	tmpp = argv[0];
     }
     if( (!strcmp(tmpp,"xa65816"))
	|| (!strcmp(tmpp,"XA65816"))
	|| (!strcmp(tmpp,"xa816"))
	|| (!strcmp(tmpp,"XA816"))
	) {
	w65816 = 1;	/* allow 65816 per default */
     }

     /* default output charset for strings in quotes */
     set_charset("ASCII");

     ifiles = malloc(mifiles*sizeof(char*));

     afile = alloc_file();

     if (argc <= 1) {
          usage(w65816, stderr);
          exit(1);
     }

     if (strstr(argv[1], "--help")) {
          usage(w65816, stdout);
	  exit(0);
     }

     if (strstr(argv[1], "--version")) {
          version(programname, progversion, authors, copyright);
	  exit(0);
     }

     ofile="a.o65";
     efile=NULL;
     lfile=NULL;

     if(pp_init()) {
       logout("fatal: pp: no memory!");
       return 1;
     }
     if(b_init()) {
       logout("fatal: b: no memory!");
       return 1;
     }
     if(l_init()) {
       logout("fatal: l: no memory!");
       return 1;
     }

     i=1;
     while(i<argc) {
	if(argv[i][0]=='-') {
	  switch(argv[i][1]) {
	  case 'p':
		/* intentionally not allowing an argument to follow with a
			space to avoid - being seen as the alternate
			preprocessor char! */
		if (argv[i][2] == '\0') {
			fprintf(stderr, "-p requires a character argument\n");
			exit(1);
		}
		if (argv[i][2] == '#')
			fprintf(stderr,
				"using -p# is evidence of stupidity\n");
		altppchar = argv[i][2];
		if (argv[i][3] != '\0')
			fprintf(stderr,
				"warning: extra characters to -p ignored\n");
		break;
	  case 'M':
		masm = 1;	/* MASM compatibility mode */
		break;
	  case 'O':		/* output charset */
		{
		  char *name = NULL;
		  if (argv[i][2] == 0) { 
		    name = argv[++i]; 
		  } else {
		    name = argv[i]+2;
		  }
		  if (set_charset(name) < 0) {
		    fprintf(stderr, "Output charset name '%s' unknown - ignoring! (check case?)\n", name);
		  }
		}
		break;
	  case 'A':		/* make text segment start so that text relocation
				   is not necessary when _file_ starts at adr */
		romable = 2;
		if(argv[i][2]==0) romaddr = atoi(argv[++i]);
		else romaddr = atoi(argv[i]+2);
		break;
	  case 'G':
		noglob = 1;
		break;
	  case 'L':		/* define global label */
		if(argv[i][2]) lg_set(argv[i]+2);
		break;
	  case 'r':
		crossref = 1;
		break;
	  case 'R':
		relmode = 1;
		break;
	  case 'D':
		s = (signed char*)strstr(argv[i]+2,"=");
		if(s) *s = ' ';
		pp_define(argv[i]+2);
		break;
	  case 'c':
		no_link = 1;
		fmode |= FM_OBJ;
		break;
	  case 'v':
		verbose = 1;
		break;
	  case 'C':
		cmosfl = 0;
		break;
          case 'W':
                w65816 = 0;
                break;
          case 'w':
                w65816 = 1;
                break;
	  case 'B':
		showblk = 1;
		break;
	  case 'x':		/* old filename behaviour */
		oldfile = 1;
		fprintf(stderr, "Warning: -x is now deprecated and may disappear in future versions!\n");
		break;
	  case 'I':
		if(argv[i][2]==0) {
		  reg_include(argv[++i]);
		} else {
		  reg_include(argv[i]+2);
		}
		break;
	  case 'o':
		if(argv[i][2]==0) {
		  ofile=argv[++i];
		} else {
		  ofile=argv[i]+2;
		}
		break;
	  case 'l':
		if(argv[i][2]==0) {
		  lfile=argv[++i];
		} else {
		  lfile=argv[i]+2;
		}
		break;
	  case 'e':
		if(argv[i][2]==0) {
		  efile=argv[++i];
		} else {
		  efile=argv[i]+2;
		}
		break;
	  case 'b':			/* set segment base addresses */
		switch(argv[i][2]) {
		case 't':
			if(argv[i][3]==0) tbase = atoi(argv[++i]);
			else tbase = atoi(argv[i]+3);
			break;
		case 'd':
			if(argv[i][3]==0) dbase = atoi(argv[++i]);
			else dbase = atoi(argv[i]+3);
			break;
		case 'b':
			if(argv[i][3]==0) bbase = atoi(argv[++i]);
			else bbase = atoi(argv[i]+3);
			break;
		case 'z':
			if(argv[i][3]==0) zbase = atoi(argv[++i]);
			else zbase = atoi(argv[i]+3);
			break;
		default:
			fprintf(stderr,"unknown segment type '%c' - ignoring!\n",
								argv[i][2]);
			break;
		}
		break;
	  case 0:
		fprintf(stderr, "Single dash '-' on command line - ignoring!\n");
		break;
	  default:
		fprintf(stderr, "Unknown option '%c' - ignoring!\n",argv[i][1]);
		break;
	  }
	} else {		/* no option -> filename */
	  ifiles[nifiles++] = argv[i];
	  if(nifiles>=mifiles) {
	    mifiles += 5;
	    ifiles=realloc(ifiles, mifiles*sizeof(char*));
	    if(!ifiles) {
		fprintf(stderr, "Oops: couldn't alloc enough mem for filelist table..!\n");
		exit(1);
	    }
	  }
	}
	i++;
     }
     if(!nifiles) {
	fprintf(stderr, "No input files given!\n");
	exit(0);
     }

     if(oldfile) {
	strcpy(old_e, ifiles[0]);
	strcpy(old_o, ifiles[0]);
	strcpy(old_l, ifiles[0]);

	if(setfext(old_e,".err")==0) efile = old_e;
	if(setfext(old_o,".obj")==0) ofile = old_o;
	if(setfext(old_l,".lab")==0) lfile = old_l;
     }

     fplab= lfile ? xfopen(lfile,"w") : NULL;
     fperr= efile ? xfopen(efile,"w") : NULL;
     if(!strcmp(ofile,"-")) {
	ofile=NULL;
        fpout = stdout;
     } else {
        fpout= xfopen(ofile,"wb");
     }
     if(!fpout) {
	fprintf(stderr, "Couldn't open output file!\n");
	exit(1);
     }

     if(verbose) fprintf(stderr, "%s\n",copyright);

     if(1 /*!m_init()*/)
     {
       if(1 /*!b_init()*/)
       {
         if(1 /*!l_init()*/)
         {
           /*if(!pp_init())*/
           {
             if(!x_init())
             {
	       if(fperr) fprintf(fperr,"%s\n",copyright);
	       if(verbose) logout(ctime(&tim1));

	       /* Pass 1 */

               pc[SEG_ABS]= 0;		/* abs addressing */
	       seg_start(fmode, tbase, dbase, bbase, zbase, 0, relmode);

	       if(relmode) {
		 r_mode(RMODE_RELOC);
		 segment = SEG_TEXT;
	       } else {
		 r_mode(RMODE_ABS);
	       }

	       nolink = no_link;

               for (i=0; i<nifiles; i++)
               {
		 ifile = ifiles[i];

                 sprintf(out,"xAss65: Pass 1: %s\n",ifile);
                 if(verbose) logout(out);

                 er=pp_open(ifile);
                    puttmp(0);
                    puttmp(T_FILE);
                    puttmp(0);
                    puttmp(0);
                    puttmps((signed char*)&ifile, sizeof(filep->fname));

                 if(!er) {
                   er=pass1();
                   pp_close();
                 } else {
		   sprintf(out, "Couldn't open source file '%s'!\n", ifile);
		   logout(out);
                 }
               }           

	       if((er=b_depth())) {
		 sprintf(out,"Still %d blocks open at end of file!\n",er);
		 logout(out);
	       }

	       if(tbase & (align-1)) {
		   sprintf(out,"Warning: text segment ($%04x) start address doesn't align to %d!\n", tbase, align);
		   logout(out);
	       }
	       if(dbase & (align-1)) {
		   sprintf(out,"Warning: data segment ($%04x) start address doesn't align to %d!\n", dbase, align);
		   logout(out);
	       }
	       if(bbase & (align-1)) {
		   sprintf(out,"Warning: bss segment ($%04x) start address doesn't align to %d!\n", bbase, align);
		   logout(out);
	       }
	       if(zbase & (align-1)) {
		   sprintf(out,"Warning: zero segment ($%04x) start address doesn't align to %d!\n", zbase, align);
		   logout(out);
	       }
               if (n65816>0)
                   fmode |= 0x8000;
	       switch(align) {
		case 1: break;
		case 2: fmode |= 1; break;
		case 4: fmode |= 2; break;
		case 256: fmode |=3; break;
	       }
	       
	       if((!er) && relmode) 
			h_write(fpout, fmode, tlen, dlen, blen, zlen, 0);


               if(!er)
               {
                    if(verbose) logout("xAss65: Pass 2:\n");

		    seg_pass2();

	            if(!relmode) {
	              r_mode(RMODE_ABS);
	            } else {
	              r_mode(RMODE_RELOC);
		      segment = SEG_TEXT;
	            }
                    er=pass2();
               } 

               if(fplab) printllist(fplab);
               tim2=time(NULL);
	       if(verbose) printstat();

	       if((!er) && relmode) seg_end(fpout);	/* write reloc/label info */
			                              
               if(fperr) fclose(fperr);
               if(fplab) fclose(fplab);
               if(fpout) fclose(fpout);

             } else {
               logout("fatal: x: no memory!\n");
             }
             pp_end();
/*           } else {
             logout("fatal: pp: no memory!");*/
           }
         } else {
          logout("fatal: l: no memory!\n");
         }
       } else {
          logout("fatal: b: no memory!\n");
       }
       /*m_exit();*/
     } else { 
          logout("Not enough memory available!\n");
     }

     if(ner || er)
     {
          fprintf(stderr, "Break after %d error%c\n",ner,ner?'s':0);
	  /*unlink();*/
	  if(ofile) {
	    unlink(ofile);
	  }
     }

     free(ifiles);

     return( (er || ner) ? 1 : 0 );
}
bool MultiBootPatcher::Impl::patchZip()
{
    std::unordered_set<std::string> excludeFromPass1;

    for (auto const &item : info->patchInfo()->autoPatchers()) {
        auto args = info->patchInfo()->autoPatcherArgs(item);

        auto *ap = pc->createAutoPatcher(item, info, args);
        if (!ap) {
            error = PatcherError::createPatcherCreationError(
                    ErrorCode::AutoPatcherCreateError, item);
            return false;
        }

        // TODO: AutoPatcher::newFiles() is not supported yet

        std::vector<std::string> existingFiles = ap->existingFiles();
        if (existingFiles.empty()) {
            pc->destroyAutoPatcher(ap);
            continue;
        }

        autoPatchers.push_back(ap);

        // AutoPatcher files should be excluded from the first pass
        for (auto const &file : existingFiles) {
            excludeFromPass1.insert(file);
        }
    }

    // Unlike the old patcher, we'll write directly to the new file
    if (!openOutputArchive()) {
        return false;
    }

    if (cancelled) return false;

    FileUtils::ArchiveStats stats;
    auto result = FileUtils::mzArchiveStats(info->filename(), &stats,
                                            std::vector<std::string>());
    if (!result) {
        error = result;
        return false;
    }

    maxBytes = stats.totalSize;

    if (cancelled) return false;

    // +1 for mbtool_recovery (update-binary)
    // +1 for bb-wrapper.sh
    // +1 for info.prop
    maxFiles = stats.files + 3;
    updateFiles(files, maxFiles);

    if (!openInputArchive()) {
        return false;
    }

    // Create temporary dir for extracted files for autopatchers
    std::string tempDir = FileUtils::createTemporaryDir(pc->tempDirectory());

    if (!pass1(zOutput, tempDir, excludeFromPass1)) {
        boost::filesystem::remove_all(tempDir);
        return false;
    }

    if (cancelled) return false;

    // On the second pass, run the autopatchers on the rest of the files

    if (!pass2(zOutput, tempDir, excludeFromPass1)) {
        boost::filesystem::remove_all(tempDir);
        return false;
    }

    boost::filesystem::remove_all(tempDir);

    if (cancelled) return false;

    updateFiles(++files, maxFiles);
    updateDetails("META-INF/com/google/android/update-binary");

    // Add mbtool_recovery
    result = FileUtils::mzAddFile(
            zOutput, "META-INF/com/google/android/update-binary",
            pc->dataDirectory() + "/binaries/android/"
                    + info->device()->architecture() + "/mbtool_recovery");
    if (!result) {
        error = result;
        return false;
    }

    if (cancelled) return false;

    updateFiles(++files, maxFiles);
    updateDetails("multiboot/bb-wrapper.sh");

    // Add bb-wrapper.sh
    result = FileUtils::mzAddFile(
        zOutput, "multiboot/bb-wrapper.sh",
        pc->dataDirectory() + "/scripts/bb-wrapper.sh");
    if (!result) {
        error = result;
        return false;
    }

    if (cancelled) return false;

    updateFiles(++files, maxFiles);
    updateDetails("multiboot/info.prop");

    const std::string infoProp = createInfoProp();
    result = FileUtils::mzAddFile(
            zOutput, "multiboot/info.prop",
            std::vector<unsigned char>(infoProp.begin(), infoProp.end()));
    if (!result) {
        error = result;
        return false;
    }

    if (cancelled) return false;

    return true;
}
Beispiel #28
0
/******************************************************************************************
 * Function: main
 *
 * Description:
 *	This function reads the config. file for six input parameters,
 *	finds the frequent 1-itemsets, builds the initial FP-tree
 *	using the frequent 1-itemsets and
 *	peforms the FP-growth algorithm of the paper.
 *	It measure both CPU and I/O time for build tree and mining.
 *
 * Functions to be invoked:
 *	input()		-> Read config. file
 *	pass1()		-> Scan DB and find frquent 1-itemsets
 *	buildTree()	-> Build the initial FP-tree
 *	FPgrowth()	-> Start mining
 *
 * Parameters:
 *	Config. file name
 */
void main(int argc, char *argv[])
{
 float  userTime, sysTime;
 struct rusage myTime1, myTime2, myTime3;
 int headerTableSize;

 /* Usage ------------------------------------------*/
 printf("\nFP-tree: Mining large itemsets using user support threshold\n\n");
 if (argc != 2) {
        printf("Usage: %s <config. file>\n\n", argv[0]);
	printf("Content of config. file:\n");
	printf("  Line 1: Upper limit of large itemsets size to be mined\n");
	printf("  Line 2: Support threshold (normalized to [0, 1])\n");
	printf("  Line 3: No. of different items in the DB\n");
	printf("  Line 4: No. of transactions in the DB\n");
	printf("  Line 5: File name of the DB\n");
	printf("  Line 6: Result file name to store the large itemsets\n\n");
        exit(1);
 }

 /* read input parameters --------------------------*/
 printf("input\n");
 input(argv[1]);

 getrusage(RUSAGE_SELF,&myTime1);

 /* pass 1 : Mine the large 1-itemsets -------------*/
 printf("\npass1\n");
 pass1();

 /* Mine the large k-itemsets (k = 2 to realK) -----*/
 if (numLarge[0] > 0) {

	/* create FP-tree --------------------------*/
 	printf("\nbuildTree\n");
 	buildTree();

	getrusage(RUSAGE_SELF,&myTime2);

	/* mining frequent patterns ----------------*/
 	printf("\npassK\n");
	headerTableSize = numLarge[0];
	numLarge[0] = 0;
 	FPgrowth(root, headerTableLink, headerTableSize, NULL, 0);

 	getrusage(RUSAGE_SELF,&myTime3);

 	/* output result of large itemsets ---------*/
 	printf("\nresult\n");
 	displayResult();

 	/* output execution time ---------------------*/
 	printf("Build tree time:\n");
 	userTime =
       		((float) (myTime2.ru_utime.tv_sec  - myTime1.ru_utime.tv_sec)) +
       		((float) (myTime2.ru_utime.tv_usec - myTime1.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime2.ru_stime.tv_sec  - myTime1.ru_stime.tv_sec)) +
       		((float) (myTime2.ru_stime.tv_usec - myTime1.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n\n", sysTime);

 	printf("FP-tree growth time:\n");
 	userTime =
       		((float) (myTime3.ru_utime.tv_sec  - myTime2.ru_utime.tv_sec)) +
       		((float) (myTime3.ru_utime.tv_usec - myTime2.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime3.ru_stime.tv_sec  - myTime2.ru_stime.tv_sec)) +
       		((float) (myTime3.ru_stime.tv_usec - myTime2.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n\n", sysTime);

	printf("Total execution time:\n");
 	userTime =
       		((float) (myTime3.ru_utime.tv_sec  - myTime1.ru_utime.tv_sec)) +
       		((float) (myTime3.ru_utime.tv_usec - myTime1.ru_utime.tv_usec)) * 1e-6;
 	sysTime =
       		((float) (myTime3.ru_stime.tv_sec  - myTime1.ru_stime.tv_sec)) +
       		((float) (myTime3.ru_stime.tv_usec - myTime1.ru_stime.tv_usec)) * 1e-6;

 	printf("User time : %f seconds\n", userTime);
 	printf("System time : %f seconds\n", sysTime);
	printf("Total time: %f seconds\n\n", userTime + sysTime);

 }

 /* free memory ------------------------------------*/
 printf("\ndestroy\n");
 destroy();

 return;
}
Beispiel #29
0
int main(int argc, char **argv) {
  FILE *infile = NULL;
  int w, h;
  // The number of lightfield images in the u and v dimensions.
  int lf_width, lf_height;
  // Defines how many images refer to the same reference image for MCP.
  // lf_blocksize X lf_blocksize images will all use the reference image
  // in the middle of the block of images.
  int lf_blocksize;
  aom_codec_ctx_t codec;
  aom_codec_enc_cfg_t cfg;
  aom_image_t raw;
  aom_image_t raw_shift;
  aom_codec_err_t res;
  aom_fixed_buf_t stats;
  int flags = 0;

  const AvxInterface *encoder = NULL;
  const int fps = 30;
  const int bitrate = 200;  // kbit/s
  const char *const width_arg = argv[1];
  const char *const height_arg = argv[2];
  const char *const infile_arg = argv[3];
  const char *const outfile_arg = argv[4];
  const char *const lf_width_arg = argv[5];
  const char *const lf_height_arg = argv[6];
  const char *lf_blocksize_arg = argv[7];
  exec_name = argv[0];

  if (argc < 8) die("Invalid number of arguments");

  encoder = get_aom_encoder_by_name("av1");
  if (!encoder) die("Unsupported codec.");

  w = (int)strtol(width_arg, NULL, 0);
  h = (int)strtol(height_arg, NULL, 0);
  lf_width = (int)strtol(lf_width_arg, NULL, 0);
  lf_height = (int)strtol(lf_height_arg, NULL, 0);
  lf_blocksize = (int)strtol(lf_blocksize_arg, NULL, 0);
  lf_blocksize = lf_blocksize < lf_width ? lf_blocksize : lf_width;
  lf_blocksize = lf_blocksize < lf_height ? lf_blocksize : lf_height;

  if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
    die("Invalid frame size: %dx%d", w, h);
  if (lf_width <= 0 || lf_height <= 0)
    die("Invalid lf_width and/or lf_height: %dx%d", lf_width, lf_height);
  if (lf_blocksize <= 0) die("Invalid lf_blocksize: %d", lf_blocksize);

  if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, w, h, 32)) {
    die("Failed to allocate image.");
  }
  if (!CONFIG_LOWBITDEPTH) {
    // Need to allocate larger buffer to use hbd internal.
    aom_img_alloc(&raw_shift, AOM_IMG_FMT_I420 | AOM_IMG_FMT_HIGHBITDEPTH, w, h,
                  32);
  }

  printf("Using %s\n", aom_codec_iface_name(encoder->codec_interface()));

  // Configuration
  res = aom_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
  if (res) die_codec(&codec, "Failed to get default codec config.");

  cfg.g_w = w;
  cfg.g_h = h;
  cfg.g_timebase.num = 1;
  cfg.g_timebase.den = fps;
  cfg.rc_target_bitrate = bitrate;
  cfg.g_error_resilient = 0;  // This is required.
  cfg.g_lag_in_frames = 0;    // need to set this since default is 19.
  cfg.kf_mode = AOM_KF_DISABLED;
  cfg.large_scale_tile = 0;  // Only set it to 1 for camera frame encoding.
  cfg.g_bit_depth = AOM_BITS_8;
  flags |= (cfg.g_bit_depth > AOM_BITS_8 || !CONFIG_LOWBITDEPTH)
               ? AOM_CODEC_USE_HIGHBITDEPTH
               : 0;

  if (!(infile = fopen(infile_arg, "rb")))
    die("Failed to open %s for reading", infile_arg);

  // Pass 0
  cfg.g_pass = AOM_RC_FIRST_PASS;
  stats = pass0(&raw, infile, encoder, &cfg, lf_width, lf_height, lf_blocksize,
                flags, &raw_shift);

  // Pass 1
  rewind(infile);
  cfg.g_pass = AOM_RC_LAST_PASS;
  cfg.rc_twopass_stats_in = stats;
  pass1(&raw, infile, outfile_arg, encoder, &cfg, lf_width, lf_height,
        lf_blocksize, flags, &raw_shift);
  free(stats.buf);

  if (!CONFIG_LOWBITDEPTH) aom_img_free(&raw_shift);
  aom_img_free(&raw);
  fclose(infile);

  return EXIT_SUCCESS;
}
Beispiel #30
0
int
main(int argc, char *argv[])
{
    int			c;
    int			sts;
    int			ctx;
    int			i;
    int			lflag = 0;	/* no label by default */
    int			nfile;
    int			n;
    char		*p;
    struct dirent	**namelist;
    __pmContext		*ctxp;
    char		*archpathname;	/* from the command line */
    char		*archdirname;	/* after dirname() */
    char		archname[MAXPATHLEN];	/* full pathname to base of archive name */

    while ((c = pmGetOptions(argc, argv, &opts)) != EOF) {
	switch (c) {
	case 'l':	/* display the archive label */
	    lflag = 1;
	    break;
	case 'v':	/* bump verbosity */
	    vflag++;
	    break;
	}
    }

    if (!opts.errors && opts.optind >= argc) {
	pmprintf("Error: no archive specified\n\n");
	opts.errors++;
    }

    if (opts.errors) {
	pmUsageMessage(&opts);
	exit(EXIT_FAILURE);
    }

    sep = __pmPathSeparator();
    setlinebuf(stderr);

    __pmAddOptArchive(&opts, argv[opts.optind]);
    opts.flags &= ~PM_OPTFLAG_DONE;
    __pmEndOptions(&opts);

    archpathname = argv[opts.optind];
    archbasename = strdup(basename(strdup(archpathname)));
    /*
     * treat foo, foo.index, foo.meta, foo.NNN as all equivalent
     * to "foo"
     */
    p = strrchr(archbasename, '.');
    if (p != NULL) {
	if (strcmp(p, ".index") == 0 || strcmp(p, ".meta") == 0)
	    *p = '\0';
	else {
	    char	*q = p;
	    q++;
	    if (isdigit(*q)) {
		/*
		 * foo.<digit> ... if archpathname does exist, then
		 * safe to strip digits, else leave as is for the
		 * case of, e.g. archive-20150415.041154 which is the
		 * pmmgr basename for an archive with a first volume
		 * named archive-20150415.041154.0
		 */
		if (access(archpathname, F_OK) == 0) {
		    q++;
		    while (*q && isdigit(*q))
			q++;
		    if (*q == '\0')
			*p = '\0';
		}
	    }
	}
    }
    archdirname = dirname(strdup(archpathname));
    if (vflag)
	fprintf(stderr, "Scanning for components of archive \"%s\"\n", archpathname);
    nfile = scandir(archdirname, &namelist, filter, NULL);
    if (nfile < 1) {
	fprintf(stderr, "%s: no PCP archive files match \"%s\"\n", pmProgname, archpathname);
	exit(EXIT_FAILURE);
    }

    /*
     * Pass 0 for data, metadata and index files ... check physical
     * archive record structure, then label record
     */
    sts = STS_OK;
    for (i = 0; i < nfile; i++) {
	char	path[MAXPATHLEN];
	if (strcmp(archdirname, ".") == 0) {
	    /* skip ./ prefix */
	    strncpy(path, namelist[i]->d_name, sizeof(path));
	}
	else {
	    snprintf(path, sizeof(path), "%s%c%s", archdirname, sep, namelist[i]->d_name);
	}
	if (pass0(path) == STS_FATAL)
	    /* unrepairable or unrepaired error */
	    sts = STS_FATAL;
    }
    if (meta_state == STATE_MISSING) {
	fprintf(stderr, "%s%c%s.meta: missing metadata file\n", archdirname, sep, archbasename);
	sts = STS_FATAL;
    }
    if (log_state == STATE_MISSING) {
	fprintf(stderr, "%s%c%s.0 (or similar): missing log file \n", archdirname, sep, archbasename);
	sts = STS_FATAL;
    }

    if (sts == STS_FATAL) {
	if (vflag) fprintf(stderr, "Due to earlier errors, cannot continue ... bye\n");
	exit(EXIT_FAILURE);
    }

    if ((sts = ctx = pmNewContext(PM_CONTEXT_ARCHIVE, archpathname)) < 0) {
	fprintf(stderr, "%s: cannot open archive \"%s\": %s\n", pmProgname, archpathname, pmErrStr(sts));
	fprintf(stderr, "Checking abandoned.\n");
	exit(EXIT_FAILURE);
    }

    if (pmGetContextOptions(ctx, &opts) < 0) {
        pmflush();      /* runtime errors only at this stage */
        exit(EXIT_FAILURE);
    }

    if (lflag)
	dumpLabel();

    /*
     * Note: ctxp->c_lock remains locked throughout ... __pmHandleToPtr()
     *       is only called once, and a single context is used throughout
     *       ... so there is no PM_UNLOCK(ctxp->c_lock) anywhere in the
     *       pmchecklog code.
     *       This works because ctxp->c_lock is a recursive lock and
     *       pmchecklog is single-threaded.
     */
    if ((n = pmWhichContext()) >= 0) {
	if ((ctxp = __pmHandleToPtr(n)) == NULL) {
	    fprintf(stderr, "%s: botch: __pmHandleToPtr(%d) returns NULL!\n", pmProgname, n);
	    exit(EXIT_FAILURE);
	}
    }
    else {
	fprintf(stderr, "%s: botch: %s!\n", pmProgname, pmErrStr(PM_ERR_NOCONTEXT));
	exit(EXIT_FAILURE);
    }

    if (strcmp(archdirname, ".") == 0)
	/* skip ./ prefix */
	strncpy(archname, archbasename, sizeof(archname) - 1);
    else
	snprintf(archname, sizeof(archname), "%s%c%s", archdirname, sep, archbasename);

    sts = pass1(ctxp, archname);

    if (index_state == STATE_BAD) {
	/* prevent subsequent use of bad temporal index */
	ctxp->c_archctl->ac_log->l_numti = 0;
    }

    sts = pass2(ctxp, archname);

    sts = pass3(ctxp, archname, &opts);

    if (vflag) {
	if (result_count > 0)
	    fprintf(stderr, "Processed %d pmResult records\n", result_count);
	if (mark_count > 0)
	    fprintf(stderr, "Processed %d <mark> records\n", mark_count);
    }

    return 0;
}