Пример #1
0
int
main(int argc, char *argv[])
{
	u_char *cp, *oldpath, *path;
	int ch, code, count, diffcount, oldcount;
	u_int i, j;
	FILE *fp;

	while ((ch = getopt(argc, argv, "")) != -1)
		switch(ch) {
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 1)
		usage();

	if ((fp = fopen(argv[0], "r")) == NULL)
		err(1, "%s", argv[0]);

	/* First copy bigram array to stdout. */
	(void)fgets(bigrams, BGBUFSIZE + 1, fp);

	if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE)
		err(1, "stdout");
	(void)fclose(fp);

#ifdef LOOKUP
	/* init lookup table */
	for (i = 0; i < UCHAR_MAX + 1; i++)
	    	for (j = 0; j < UCHAR_MAX + 1; j++) 
			big[i][j] = (bg_t)-1;

	for (cp = bigrams, i = 0; *cp != '\0'; i += 2, cp += 2)
	        big[(u_char)*cp][(u_char)*(cp + 1)] = (bg_t)i;

#endif /* LOOKUP */

	oldpath = buf1;
	path = buf2;
	oldcount = 0;

	while (fgets(path, sizeof(buf2), stdin) != NULL) {

		/* skip empty lines */
		if (*path == '\n')
			continue;

		/* remove newline */
		for (cp = path; *cp != '\0'; cp++) {
#ifndef LOCATE_CHAR30
			/* old locate implementations core'd for char 30 */
			if (*cp == SWITCH)
				*cp = '?';
			else
#endif /* !LOCATE_CHAR30 */

			/* chop newline */
			if (*cp == '\n')
				*cp = '\0';
		}

		/* Skip longest common prefix. */
		for (cp = path; *cp == *oldpath; cp++, oldpath++)
			if (*cp == '\0')
				break;

		count = cp - path;
		diffcount = count - oldcount + OFFSET;
		oldcount = count;
		if (diffcount < 0 || diffcount > 2 * OFFSET) {
			if (putchar(SWITCH) == EOF ||
			    putw(diffcount, stdout) == EOF)
				err(1, "stdout");
		} else
			if (putchar(diffcount) == EOF)
				err(1, "stdout");

		while (*cp != '\0') {
			/* print *two* characters */

			if ((code = BGINDEX(cp)) != (bg_t)-1) {
				/*
				 * print *one* as bigram
				 * Found, so mark byte with 
				 *  parity bit. 
				 */
				if (putchar((code / 2) | PARITY) == EOF)
					err(1, "stdout");
				cp += 2;
			}

			else {
				for (i = 0; i < 2; i++) {
					if (*cp == '\0')
						break;

					/* print umlauts in file names */
					if (*cp < ASCII_MIN || 
					    *cp > ASCII_MAX) {
						if (putchar(UMLAUT) == EOF ||
						    putchar(*cp++) == EOF)
							err(1, "stdout");
					} 

					else {
						/* normal character */
						if(putchar(*cp++) == EOF)
							err(1, "stdout");
					}
				}

			}
		}

		if (path == buf1) {		/* swap pointers */
			path = buf2;
			oldpath = buf1;
		} else {
			path = buf1;
			oldpath = buf2;
		}
	}
	/* Non-zero status if there were errors */
	if (fflush(stdout) != 0 || ferror(stdout))
		exit(1);
	exit(0);
}
Пример #2
0
boolean
save(char *filename, lispobj init_function, int sse2_mode)
{
    FILE *file;

#if defined WANT_CGC
    volatile lispobj *func_ptr = &init_function;
    char sbuf[128];

    strcpy(sbuf, filename);
    filename = sbuf;
    /* Get rid of remnant stuff. This is a MUST so that
     * the memory manager can get started correctly when
     * we restart after this save. Purify is going to
     * maybe move the args so we need to consider them volatile,
     * especially if the gcc optimizer is working!!
     */
    purify(NIL, NIL);

    init_function = *func_ptr;
    /* Set dynamic space pointer to base value so we don't write out
     * MBs of just cleared heap.
     */
    if (SymbolValue(X86_CGC_ACTIVE_P) != NIL)
	SetSymbolValue(ALLOCATION_POINTER, DYNAMIC_0_SPACE_START);
#endif
    /* Open the file: */
    remove(filename);
    file = fopen(filename, "w");
    if (file == NULL) {
	perror(filename);
	return TRUE;
    }
    printf("[Undoing binding stack... ");
    fflush(stdout);
    unbind_to_here((lispobj *) BINDING_STACK_START);
    SetSymbolValue(CURRENT_CATCH_BLOCK, 0);
    SetSymbolValue(CURRENT_UNWIND_PROTECT_BLOCK, 0);
    SetSymbolValue(EVAL_STACK_TOP, 0);
    printf("done]\n");
#if defined WANT_CGC && defined X86_CGC_ACTIVE_P
    SetSymbolValue(X86_CGC_ACTIVE_P, T);
#endif
    printf("[Saving current lisp image into %s:\n", filename);

    putw(CORE_MAGIC, file);

    putw(CORE_VERSION, file);
#if defined(i386) && defined(FEATURE_SSE2)
    putw(4, file);
#else
    putw(3, file);
#endif
    putw(version, file);

#if defined(i386) && defined(FEATURE_SSE2)
    if (sse2_mode) {
        putw(SSE2, file);
    } else {
        putw(X87, file);
    }
#endif
    
    putw(CORE_NDIRECTORY, file);
    putw((5 * 3) + 2, file);

    output_space(file, READ_ONLY_SPACE_ID, read_only_space,
		 (lispobj *) SymbolValue(READ_ONLY_SPACE_FREE_POINTER));
    output_space(file, STATIC_SPACE_ID, static_space,
		 (lispobj *) SymbolValue(STATIC_SPACE_FREE_POINTER));
#ifdef GENCGC
    /* Flush the current_region updating the tables. */
#ifdef DEBUG_BAD_HEAP
    fprintf(stderr, "before ALLOC_POINTER = %p\n", (lispobj *) SymbolValue(ALLOCATION_POINTER));
    dump_region(&boxed_region);
#endif
    gc_alloc_update_page_tables(0, &boxed_region);
    gc_alloc_update_page_tables(1, &unboxed_region);
#ifdef DEBUG_BAD_HEAP
    fprintf(stderr, "boxed_region after update\n");
    dump_region(&boxed_region);

    print_ptr((lispobj*) 0x2805a184);
#endif
    
#ifdef DEBUG_BAD_HEAP
    /*
     * For some reason x86 has a heap corruption problem.  I (rtoy)
     * have not been able to figure out how that occurs, but what is
     * happening is that when a core is loaded, there is some static
     * object pointing to an object that is on a free page.  In normal
     * usage, at startup there should be 4 objects in static space
     * pointing to a free page, because these are newly allocated
     * objects created by the C runtime.  However, there is an
     * additional object.
     *
     * I do not know what this object should be or how it got there,
     * but it will often cause CMUCL to fail to save a new core file.
     *
     * Disabling this call to update_dynamic_space_free_pointer is a
     * work around.  What is happening is that u_d_s_f_p is resetting
     * ALLOCATION_POINTER, but that weird object is in the current
     * region, but after resetting the pointer, that object isn't
     * saved to the core file.  By not resetting the pointer, the
     * object (or at least enough of it) gets saved in the core file
     * that we don't have problems when reloading.
     *
     * Note that on sparc and ppc, u_d_s_f_p doesn't actually do
     * anything because the call to reset ALLOCATION_POINTER is a nop
     * on sparc and ppc.  And sparc and ppc dont' have the heap
     * corruption issue.  That's not conclusive evidence, though.
     *
     * This needs more work and investigation.
     */
    update_dynamic_space_free_pointer();
#endif

#ifdef DEBUG_BAD_HEAP    
    fprintf(stderr, "after ALLOC_POINTER = %p\n", (lispobj *) SymbolValue(ALLOCATION_POINTER));
#endif    
#endif

#ifdef reg_ALLOC
    output_space(file, DYNAMIC_SPACE_ID, current_dynamic_space,
		 current_dynamic_space_free_pointer);
#else
    output_space(file, DYNAMIC_SPACE_ID, current_dynamic_space,
		 (lispobj *) SymbolValue(ALLOCATION_POINTER));
#endif

    putw(CORE_INITIAL_FUNCTION, file);
    putw(3, file);
    putw(init_function, file);

    putw(CORE_END, file);
    fclose(file);

    printf("done.]\n");

    exit(0);
}
Пример #3
0
int SpriteCache::saveToFile(const char *filnam, int lastElement, bool compressOutput)
{
  FILE *output = fopen(filnam, "wb");
  if (output == NULL)
    return -1;

  if (compressOutput) {
    // re-open the file so that it can be seeked
    fclose(output);
    output = fopen(filnam, "r+b");
    if (output == NULL)
      return -1;
  }

  int spriteFileIDCheck = (int)time(NULL);

  // version 6
  putshort(6, output);

  fwrite(spriteFileSig, strlen(spriteFileSig), 1, output);

  fputc(compressOutput ? 1 : 0, output);
  putw(spriteFileIDCheck, output);

  int i, lastslot = 0;
  if (elements < lastElement)
    lastElement = elements;

  for (i = 1; i < lastElement; i++) {
    // slot empty
    if ((images[i] != NULL) || ((offsets[i] != 0) && (offsets[i] != sprite0InitialOffset)))
      lastslot = i;
  }

  putshort(lastslot, output);

  // allocate buffers to store the indexing info
  int numsprits = lastslot + 1;
  short *spritewidths = (short*)malloc(numsprits * sizeof(short));
  short *spriteheights = (short*)malloc(numsprits * sizeof(short));
  long *spriteoffs = (long*)malloc(numsprits * sizeof(long));

  const int memBufferSize = 100000;
  char *memBuffer = (char*)malloc(memBufferSize);

  for (i = 0; i <= lastslot; i++) {

    spriteoffs[i] = ftell(output);

    // if compressing uncompressed sprites, load the sprite into memory
    if ((images[i] == NULL) && (this->spritesAreCompressed != compressOutput))
      (*this)[i];

    if (images[i] != NULL) {
      // image in memory -- write it out
      pre_save_sprite(i);
      int bpss = bitmap_color_depth(images[i]) / 8;
      spritewidths[i] = images[i]->w;
      spriteheights[i] = images[i]->h;
      putshort(bpss, output);
      putshort(spritewidths[i], output);
      putshort(spriteheights[i], output);

      if (compressOutput) {
        long lenloc = ftell(output);
        // write some space for the length data
        putw(0, output);

        compressSprite(images[i], output);

        long fileSizeSoFar = ftell(output);
        // write the length of the compressed data
        fseek(output, lenloc, SEEK_SET);
        putw((fileSizeSoFar - lenloc) - 4, output);
        fseek(output, 0, SEEK_END);
      }
      else
        fwrite(&images[i]->line[0][0], spritewidths[i] * bpss, spriteheights[i], output);

      continue;
    }

    if ((offsets[i] == 0) || ((offsets[i] == sprite0InitialOffset) && (i > 0))) {
      // sprite doesn't exist
      putshort(0, output);
      spritewidths[i] = 0;
      spriteheights[i] = 0;
      spriteoffs[i] = 0;
      continue;
    }

    // not in memory -- seek to it in the source file
    seekToSprite(i);
    lastLoad = i;

    short colDepth = getshort(ff);
    putshort(colDepth, output);

    if (colDepth == 0) {
      continue;
    }

    if (this->spritesAreCompressed != compressOutput) {
      // shouldn't be able to get here
      free(memBuffer);
      fclose(output);
      return -2;
    }

    // and copy the data across
    int width = getshort(ff);
    int height = getshort(ff);

    spritewidths[i] = width;
    spriteheights[i] = height;

    putshort(width, output);
    putshort(height, output);

    int sizeToCopy;
    if (this->spritesAreCompressed) {
      sizeToCopy = getw(ff);
      putw(sizeToCopy, output);
    }
    else {
      sizeToCopy = width * height * (int)colDepth;
    }

    while (sizeToCopy > memBufferSize) {
      fread(memBuffer, memBufferSize, 1, ff);
      fwrite(memBuffer, memBufferSize, 1, output);
      sizeToCopy -= memBufferSize;
    }

    fread(memBuffer, sizeToCopy, 1, ff);
    fwrite(memBuffer, sizeToCopy, 1, output);
  }

  free(memBuffer);

  fclose(output);

  // write the sprite index file
  FILE *ooo = fopen(spindexfilename, "wb");
  // write "SPRINDEX" id
  fwrite(&spindexid[0], strlen(spindexid), 1, ooo);
  // write version (1)
  putw(2, ooo);
  putw(spriteFileIDCheck, ooo);
  // write last sprite number and num sprites, to verify that
  // it matches the spr file
  putw(lastslot, ooo);
  putw(numsprits, ooo);
  fwrite(&spritewidths[0], sizeof(short), numsprits, ooo);
  fwrite(&spriteheights[0], sizeof(short), numsprits, ooo);
  fwrite(&spriteoffs[0], sizeof(long), numsprits, ooo);
  fclose(ooo);

  free(spritewidths);
  free(spriteheights);
  free(spriteoffs);

  return 0;
}
Пример #4
0
int wuWriteFontDat( wJAf_t *wfont, char *filename, int pt_size )
{
	FILE *fp;
	char magic[4];
	magic[0] = 0;
	magic[1] = 0;
	magic[2] = 0;
	magic[3] = 0;
	float height, ascend, descend;
	int winning_baseline;
	int winning_height;
	int i;
	int def = 0;
	fp = fopen(filename, "wb");
	fseek( fp, 0, SEEK_SET );
	i = 0;
	while( i < 256 )
	{
/*void putf( float number, FILE *file );
void puts( int number, FILE *file );*/
		puts( wfont->glyph[i].phWidth, fp );
		puts( wfont->glyph[i].phHeight, fp );
		puts( wfont->glyph[i].hAdv, fp );
		puts( wfont->glyph[i].hOfs, fp );
		putw( wfont->glyph[i].baseline, fp );
		putf( wfont->glyph[i].st1[0], fp );
		putf( wfont->glyph[i].st1[1], fp );
		putf( wfont->glyph[i].st2[0], fp );
		putf( wfont->glyph[i].st2[1], fp );
		//printf( "char %1c (%d) %d %d %d %d %d | %2.2f %2.2f %2.2f %2.2f\n", i, i, wfont->glyph[i].phWidth, wfont->glyph[i].phHeight, wfont->glyph[i].hAdv, wfont->glyph[i].hOfs, wfont->glyph[i].baseline, wfont->glyph[i].st1[0], wfont->glyph[i].st1[1], wfont->glyph[i].st2[0], wfont->glyph[i].st2[1] );
		i++;
	}
	
	/*
	puts( wfont->mPointSize, fp );
	puts( wfont->mHeight, fp );
	puts( wfont->mAscender, fp );
	puts( wfont->mDescender, fp );
	*/
	/*
	puts( 16, fp );
	puts( 18, fp );
	puts( 16, fp );
	puts( 12, fp );
	*/
	float size_scale = (float)(pt_size) / (float)(wfont->mHeight);
	height = (float)(pt_size);
	//ascend = ((float)(wfont->mAscender) / (float)(wfont->mHeight)) * pt_size;
	//descend = ((float)(wfont->mDescender) / (float)(wfont->mHeight)) * pt_size;
	ascend = ((float)(wfont->mAscender) * size_scale);
	descend = ((float)(wfont->mDescender) * size_scale);
	descend -= size_scale * 12.0;
	int iascend, idescend;
	iascend = (int)(ascend);
	idescend = (int)(descend);
	//ascend = ((float)(wfont->mAscender)) * size_scale;
	//descend = ((float)(wfont->mDescender)) * size_scale;
	
	printf( "Font Junk: pt_size %d, height %d, Ascender %2.2f (%d), Descender %2.2f (%d)\n", pt_size, wfont->mHeight, ascend, iascend, descend, idescend );

	puts( iascend, fp );
	puts( pt_size, fp );
	puts( iascend, fp );
	puts( idescend, fp );
	//puts( 0, fp );
	//puts( 0, fp );
	puts( 0, fp );
	puts( 0, fp );
	fclose( fp );
}
Пример #5
0
static int my_putw(int w, FILE *fp)
{
    return putw(w, _get_actual_fp(fp));
}
Пример #6
0
/* *** SCRIPT SYMBOL: [File] FileWrite *** */
static void FileWrite(FILE*haa, const char *towrite) {
  check_valid_file_handle(haa,"FileWrite");
  putw(strlen(towrite)+1,haa);
  fwrite(towrite,strlen(towrite)+1,1,haa);
  }
Пример #7
0
/* *** SCRIPT SYMBOL: [File] FileWriteInt *** */
static void FileWriteInt(FILE*haa,int into) {
  check_valid_file_handle(haa,"FileWriteInt");
  fputc('I',haa);
  putw(into,haa);
  }
Пример #8
0
void main(void)
{
	FILE *fs,*fd,*fi;
	char str[150],str1[150],str2[150],str3[10],str4[10],*error,hmfname[13];
	unsigned cnt,cnt1;
	int i,j,k,comp,intno,destno=0,ctxcont=0;

	printf("\n INT-list to HelpMake converter\n"
				" (c) 1994-95 by Giorgio Caimi\n\n"
            "Checking archives...");
  	if ((fopen("PORTS.LST","rb")==NULL)||
       (fopen("CMOS.LST","rb")==NULL)||
       (fopen("FARCALL.LST","rb")==NULL)||
		 (fopen("MEMORY.LST","rb")==NULL)||
		 (fopen("GLOSSARY.LST","rb")==NULL)||
		 (fopen("CATEGORY.KEY","rb")==NULL)) {
      fcloseall();
		printf("NEED 'PORTS.LST','MEMORY.LST','CMOS.LST',\n"
				 "                         "
				 "'GLOSSARY.LST','CATEGORY.KEY' AND 'FARCALL.LST'\n");
		putchar(7);
      exit(1);
   }
   fcloseall();

	if (fopen("INTERRUP.LST","rb")==NULL) {
   	fcloseall();
		printf("RUN 'COMBINE.BAT' FIRST\n");
		putchar(7);
      exit(2);
	}
	fcloseall();

	printf("OK\nWriting banner...");

   sprintf(hmfname,"INTLST%02X.HM",++destno);
	fd=fopen(hmfname,"wt");
	fputs(intlist,fd);

   printf("OK\nAdding 'FARCALL.LST'...");
	fs=fopen("FARCALL.LST","rt");
	fputs(fcall,fd); /* put context */
	fputs(menuglo1,fd); /* put menu */
   fputs(line,fd);
	while (fgets(str,95,fs)) fputs(checkslash(str),fd);
	fclose(fs);

  	printf("OK\nAdding 'MEMORY.LST'...");
   fs=fopen("MEMORY.LST","rt");
   fputs(mem,fd); /* put context */
	fputs(menuglo1,fd); /* put menu */
   fputs(line,fd);
	while (fgets(str,95,fs)) fputs(checkslash(str),fd);
	fclose(fs);

	printf("OK\nAdding 'CMOS.LST'...");
	fs=fopen("CMOS.LST","rt");
	fputs(cmos,fd); /* put context */
	fputs(menuglo1,fd); /* put menu */
   fputs(line,fd);
	while (fgets(str,95,fs)) fputs(checkslash(str),fd);
	fclose(fs);

	printf("OK\nAdding 'GLOSSARY.LST'...");
	fs=fopen("GLOSSARY.LST","rt");
	fputs(gloss,fd); /* put context */
	fputs(menuglo,fd); /* put menu */
   fputs(line,fd);
	while (fgets(str,95,fs)) fputs(checkslash(str),fd);
	fclose(fs);

   printf("OK\nConverting 'PORTS.LST'...");
	fs=fopen("PORTS.LST","rt");
	fi=fopen("PORTS.IDX","wt");
	cnt=0;str2[0]='\0';
   do {
   	while (strncmp(str2,"--------",8)) fgets(str2,95,fs);
      comp=strncmp(str2,"--------!---CONTACT",19);
      if (comp)
			if (str2[10]=='P') { /* found topic */
         	fgets(str2,95,fs);

			   strcpy(str,str2);
            str2[0]='\0';  /* topic formatting */
            i=j=0;
            if (!strncmp(str,"PORT",4)) i=5; /* some have "PORT", some not */
            while (str[i]&&(str[i]!=' ')&&(str[i]!='\t')) {
               str2[j]=str[i];
               ++i;++j;
            } /* reach end of port(s) number(s) */
            for (;j<10;j++) str2[j]=' '; /* align to column 10 */
            str2[j++]='-';
            while ((str[i]=='-')||(str[i]==' ')||(str[i]=='\t')) ++i; /* skip useless chars */
            str2[j++]=' ';
            for (;str[i];i++) { /* copy remaining chars */
               str2[j]=str[i];
               if (str2[j]=='\t') str2[j]=' ';
               ++j;
            }
            str2[j]='\0';
            checkslash(str2);

            fputs(str2,fi);   /* add entry to index */
			   fgets(str,95,fs);
			   while (!strcmp(str,"\n")) fgets(str,95,fs); /* search text */
			   if (strncmp(str,"--------",8)) {  /* Is there any description? */
				   sprintf(str1,"%04u\n",cnt++);
				   strncpy(port_a+11,str1,4);
               fputs(port_a,fd);fputs(port_b,fd);/* put context */
				   fputs(menu,fd);fputs(line,fd); /* put menu */
				   fputs("\\b",fd); /* bold on */
				   str2[strlen(str2)-1]='\0';fputs(str2,fd);
				   fputs("\\p\n\n",fd); /* bold off */
				   do
						fputs(checkslash(str),fd);
					while (fgets(str,95,fs),strncmp(str,"--------",8));
				   fputs(str1,fi);
				   ++ctxcont;
			   } else fputs("\n",fi);
            strcpy(str2,str);
	      } else fgets(str2,95,fs);
	} while (comp);
	fclose(fi);fclose(fs);

	printf("OK\nIndexing 'PORTS.LST'...");
	fs=fopen("PORTS.IDX","rt");
   fputs(port,fd);fputs(port_b,fd);
	fputs(menubas,fd);fputs(line,fd);
	while (fgets(str,95,fs)) {
		fgets(str1,95,fs);
		if ((k=strcmp(str1,"\n"))!=0) fputs("\\u\\a",fd);
      str[strlen(str)-1]='\0';  /* del newline */
		fputs(str,fd);
      if (k) {
			fputs("\\v",fd);
			strncpy(port_a+11,str1,4);
			strcpy(str1,port_a+9);
			str1[strlen(str1)-1]='\0';
			fputs(str1,fd);
			fputs("\\v\\u",fd);
			++ctxcont;
      }
      putc('\n',fd);
	}
   fclose(fs);
   unlink("PORTS.IDX");

	printf("OK\nConverting 'CATEGORY.KEY'...");
	fs=fopen("CATEGORY.KEY","rt");
	fputs(keys,fd); /* put context */
	fputs(menuglo,fd); /* put menu */
   fputs(line,fd);
	while (*fgets(str,95,fs)!='-') ;
   while (fgets(str,95,fs)) {
      error=str;
      while ((*error=='\t')||(*error==' ')) ++error;
      fputs(checkslash(error),fd);
   }
	fclose(fs);

	printf("OK\nConverting 'INTERRUP.LST'...");
	fs=fopen("INTERRUP.LST","rt");
	fi=fopen("INTERRUP.IDX","wt");
	cnt=cnt1=str[0]=0;intno=-1;
	do {
		do {
			strcpy(str2,str);
      	while (strncmp(str2,"--------",8))
				fgets(str2,95,fs);
			comp=strncmp(str2,"--------!---Admin",17);
			if ((comp)&&(str2[8]=='!')) fgets(str,95,fs);
		} while ((comp)&&(str2[8]=='!'));
		if (comp) {
 			intlst_d[15]=str2[8]; /* category (main) */
			i=10;j=33;
			for (;str2[i];i++) {  /* key */
				intlst_d[j]=str2[i];
				if (intlst_d[j]!='-') ++j;
			}
			intlst_d[j]='\0';
			str[0]=str2[10];str[1]=str2[11]; /* int no. */
			str[2]='\0';
			k=(int)strtol(str,&error,16);
			if ((k!=intno)||(cnt1==500)) {
            if (intno>=0) fputs("\n\n",fi);
            fputs(str,fi);  /* put int no. */
				putc('\n',fi);
				intno=k;cnt1=0;
			} else ++cnt1;
			fgets(str2,95,fs);
			intlst_d[16]=str2[7]; /* category (flag) */
			if (str2[7]=='-') i=9; else i=11;
			strcpy(str,str2+i); /* description */
			checkslash(str);
			sprintf(str1,"%04u\n",cnt++);
         fputs(str,fi);fputs(str1,fi);
			strncpy(intlst_b+11,str1,5);
			fputs(intlst_b,fd);fputs(intlst_c,fd);/* put context */
			fputs(menu,fd);fputs(line,fd); /* put menu */
			fputs("\\b",fd); /* bold on */
			str[strlen(str)-1]='\0';fputs(str,fd);
			fputs("\\p\n",fd); /* bold off */
			fputs(intlst_d,fd);
			putc('\n',fd);
			while (fgets(str2,95,fs),strncmp(str2,"--------",8))
				fputs(checkslash(str2),fd);
			strcpy(str,str2);
			++ctxcont;
			if (ctxcont==600) {
				ctxcont=0;
            sprintf(hmfname,"INTLST%02X.HM",++destno);
				freopen(hmfname,"wt",fd);
			}
		}
	} while (comp);
   fputs("\n\n",fi);
	fclose(fi);fclose(fs);

	printf("OK\nIndexing 'INTERRUP.LST'...");
	fs=fopen("INTERRUP.IDX","rt");
	fi=fopen("INTERRUP.CNT","wb");
	fputs(intlst,fd);fputs(intlst_c,fd); /* put context */
   fputs(menubas,fd);fputs(line,fd); /* put menu */
   fputs(klink,fd); /* put searching keys link */
   cnt=0;
   while (fgets(str,95,fs)) {
		str3[0]=str1[0]=cnt1=0;
		do {
			strcpy(str4,str3);
         fgets(str1,95,fs);
			fgets(str3,9,fs);
			++cnt1;
		} while (*str1!='\n');
		fputs("  \\u\\aINT ",fd);
 		str[strlen(str)-1]='\0';  /* del newline */
		fputs(str,fd);
		fputs("\\v",fd);
		if (cnt1==2) { /* put text */
			strncpy(intlst_b+11,str4,5);
			strcpy(str1,intlst_b+9);
		} else { /* put index */
			sprintf(str4,"%04u",cnt++);
			strncpy(intlst_a+11,str4,4);
			strcpy(str1,intlst_a+9);
		}
      str1[strlen(str1)-1]='\0';
		fputs(str1,fd);
		putw(cnt1-1,fi);
		fputs("\\v\\u\n",fd);
	}
	fclose(fs);fclose(fi);

   fs=fopen("INTERRUP.IDX","rt");
	fi=fopen("INTERRUP.CNT","rb");
	cnt=0;
	while ((k=getw(fi))!=EOF) {
		fgets(str,95,fs);
		if (k>1) {
			sprintf(str3,"%04u",cnt++);
			strncpy(intlst_a+11,str3,4);
 			fputs(intlst_a,fd);fputs(intlst_c,fd); /* put context */
			fputs(menu,fd);fputs(line,fd); /* put menu */
		}
		for (i=0;i<k;i++) {
			fgets(str,95,fs);
         fgets(str3,9,fs);
			if (k>1) {
				fputs("\\u\\a",fd);
				str[strlen(str)-1]='\0';  /* del newline */
				fputs(str,fd);
				fputs("\\v",fd);
				strncpy(intlst_b+11,str3,5);
				strcpy(str1,intlst_b+9);
				str1[strlen(str1)-1]='\0';  /* del newline */
				fputs(str1,fd);
            fputs("\\v\\u\n",fd);
			}
		}
      fgets(str3,9,fs);
		fgets(str3,9,fs);
	}

	fclose(fs);fclose(fi);
	unlink("INTERRUP.IDX");unlink("INTERRUP.CNT");

   fclose(fd);

	printf("OK\n\nDONE.\n");
	putchar(7);
}
Пример #9
0
answer()
{
	register PLAYER		*pp;
	register int		newsock;
	register FILE		*tmpfd;
# ifdef MONITOR
	static FLAG		monitor;
# endif MONITOR
	static char		name[NAMELEN];
	static int		socklen;
	static u_long		machine;
	static u_long		uid;
	static SOCKET		sockstruct;
# ifdef OLDIPC
	extern SOCKET		Daemon;
# endif OLDIPC

# ifdef INTERNET
	socklen = sizeof sockstruct;
# else
	socklen = sizeof sockstruct - 1;
# endif INTERNET
	errno = 0;
# ifndef OLDIPC
	if ((newsock = accept(Socket, &sockstruct, &socklen)) < 0)
# else OLDIPC
	if (accept(Socket, &sockstruct) < 0)
# endif OLDIPC
	{
		if (errno == EINTR)
			return;
		perror("accept");
		cleanup(1);
	}
# ifdef OLDIPC
	newsock = Socket;
	Socket = socket(SOCK_STREAM, 0, (struct sockaddr *) &Daemon,
		SO_ACCEPTCONN);
	if (Socket < 0) {
		perror("new accept socket");
		cleanup(1);
	}
	Sock_mask = (1 << Socket);
	Fds_mask |= Sock_mask;
	if (Socket >= Num_fds)
		Num_fds = Socket + 1;
# endif OLDIPC

	tmpfd = fdopen(newsock, "w");

# ifdef INTERNET
	machine = ntohl(((struct sockaddr_in *) &sockstruct)->sin_addr.s_addr);
# else INTERNET
	if (machine == 0)
		machine = gethostid();
# endif INTERNET
	(void) putw(getpid(), tmpfd);
	(void) read(newsock, (char *) &uid, sizeof uid);
	uid = ntohl(uid);
	(void) read(newsock, name, NAMELEN);
	(void) read(newsock, Ttyname, NAMELEN);
# ifdef MONITOR
	(void) read(newsock, (char *) &monitor, sizeof monitor);
# endif MONITOR

	if (reached_limit(machine)) {
		socklen = 0;
		(void) write(newsock, (char *) &socklen, sizeof socklen);
		(void) close(newsock);
# ifdef OLDIPC
		Fds_mask &= ~(1 << newsock);
# endif OLDIPC
		return;
	}

# ifdef MONITOR
	if (monitor)
		if (End_monitor < &Monitor[MAXMON])
			pp = End_monitor++;
		else {
			socklen = 0;
			(void) write(newsock, (char *) &socklen,
				sizeof socklen);
			(void) close(newsock);
			return;
		}
	else
# endif MONITOR
		if (End_player < &Player[MAXPL])
			pp = End_player++;
		else {
			socklen = 0;
			(void) write(newsock, (char *) &socklen,
				sizeof socklen);
			(void) close(newsock);
			return;
		}

	pp->p_ident = get_ident(machine, uid, name);
	pp->p_output = tmpfd;
	pp->p_death[0] = '\0';
	pp->p_fd = newsock;
	pp->p_mask = (1 << pp->p_fd);
# ifndef OLDIPC
	Fds_mask |= pp->p_mask;
	if (pp->p_fd >= Num_fds)
		Num_fds = pp->p_fd + 1;
# endif OLDIPC

	pp->p_y = 0;
	pp->p_x = 0;

# ifdef MONITOR
	if (monitor)
		stmonitor(pp);
	else
# endif MONITOR
		stplayer(pp);
}
Пример #10
0
int
main(int argc, char *argv[])
{
	char	buffer[BUFSIZ];
	wchar_t	wbuffer[BUFSIZ];
	char	*buf;
	wchar_t	*wbuf;
	FILE	*f;
	off_t	off;
	fpos_t	pos;
	size_t	size;
	int	fd, r;
	char	c;
	wchar_t	wc;

	if ((fd = dup(1)) == -1)
		err(2, "dup");
	if ((dup_stdout = fdopen(fd, "w")) == NULL)
		err(2, "fdopen");
	if ((fd = mkstemp(filename)) == -1)
		err(2, "mkstemp");
	if (write(fd, "0123456789\n\n", 12) != 12 || close(fd))
		err(2, "write + close");

	/* status */
	TEST_UNCHANGED(fwide(f, 0));
	TEST_NARROW(fwide(f, -1));
	TEST_WIDE(fwide(f, 1));
	TEST_UNCHANGED(feof(f));
	TEST_UNCHANGED(ferror(f));
	TEST_UNCHANGED(fileno(f));
	TEST_UNCHANGED(clearerr(f));

	/* flush and purge */
	TEST_UNCHANGED(fflush(f));
	TEST_UNCHANGED(fpurge(f));

	/* positioning */
	TEST_UNCHANGED(fgetpos(f, &pos));
	TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos));
	TEST_UNCHANGED(ftell(f));
	TEST_UNCHANGED(ftello(f));
	TEST_UNCHANGED(fseek(f, 1, SEEK_CUR));
	TEST_UNCHANGED(fseek(f, 1, SEEK_SET));
	TEST_UNCHANGED(fseek(f, 1, SEEK_END));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_SET));
	TEST_UNCHANGED(fseeko(f, 1, SEEK_END));
	TEST_UNCHANGED(rewind(f));

	/* buffering */
	TEST_UNCHANGED(setbuf(f, NULL));
	TEST_UNCHANGED(setbuf(f, buffer));
	TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ));
	TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0));
	TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0));
	TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0));
	TEST_UNCHANGED(setbuffer(f, NULL, 0));
	TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ));
	TEST_UNCHANGED(setlinebuf(f));

	/* locking */
	TEST_UNCHANGED(flockfile(f);funlockfile(f));
	TEST_UNCHANGED(ftrylockfile(f);funlockfile(f));

	/* input */
	TEST_NARROW(getc(f));
	TEST_NARROW(getc_unlocked(f));
	TEST_NARROW(fgetc(f));
	TEST_NARROW(c = fgetc(f); ungetc(c, f));
	TEST_NARROW(fgets(buffer, BUFSIZ, f));
	TEST_NARROW(fscanf(f, "%s\n", buffer));
	TEST_NARROW(fgetln(f, &size));

	/* output */
	TEST_NARROW(putc('c', f));
	TEST_NARROW(putc_unlocked('c', f));
	TEST_NARROW(fputc('c', f));
	TEST_NARROW(fputs("foo", f));
	TEST_NARROW(fprintf(f, "%s\n", "foo"));

	/* input from stdin */
	TEST_NARROW_STD(stdin, getchar());
	TEST_NARROW_STD(stdin, getchar_unlocked());
	TEST_NARROW_STD(stdin, fgets(buffer, BUFSIZ, stdin));
	TEST_NARROW_STD(stdin, scanf("%s\n", buffer));

	/* output to stdout */
	TEST_NARROW_STD(stdout, putchar('c'));
	TEST_NARROW_STD(stdout, putchar_unlocked('c'));
	TEST_NARROW_STD(stdout, puts("foo"));
	TEST_NARROW_STD(stdout, printf("foo"));

	/* word-size ops */
	/*
	 * fread and fwrite are specified as being implemented in
	 * terms of fgetc() and fputc() and therefore must set the
	 * stream orientation to narrow.
	 */
	TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f));
	TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f));

	/*
	 * getw() and putw() aren't specified anywhere but logically
	 * should behave the same as fread/fwrite.  Not all OSes agree:
	 * Solaris 10 has them not changing the orientation.
	 */
	TEST_NARROW(getw(f));
	TEST_NARROW(putw(1234, f));


	/* WIDE CHAR TIME! */

	/* input */
	TEST_WIDE(getwc(f));
	TEST_WIDE(fgetwc(f));
	TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f));
	TEST_WIDE(fgetws(wbuffer, BUFSIZ, f));
	TEST_WIDE(fwscanf(f, L"%s\n", wbuffer));

	/* output */
	TEST_WIDE(putwc(L'c', f));
	TEST_WIDE(fputwc(L'c', f));
	TEST_WIDE(fputws(L"foo", f));
	TEST_WIDE(fwprintf(f, L"%s\n", L"foo"));

	/* input from stdin */
	TEST_WIDE_STD(stdin, getwchar());
	TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer));

	/* output to stdout */
	TEST_WIDE_STD(stdout, putwchar(L'c'));
	TEST_WIDE_STD(stdout, wprintf(L"foo"));


	/* memory streams */
	f = open_memstream(&buf, &size);
	if (!((r = fwide(f, 0)) < 0))
		fail(__LINE__, r, "<", "open_memstream()");
	fclose(f);
	f = open_wmemstream(&wbuf, &size);
	if (!((r = fwide(f, 0)) > 0))
		fail(__LINE__, r, ">", "open_wmemstream()");
	fclose(f);


	/* random stuff? */
	TEST_UNCHANGED_STD(stderr, perror("foo"));

	remove(filename);
	if (failures)
		exit(1);
	exit(0);
}
Пример #11
0
bool String::writeToFile(FILE *file)
{
    putw(_length,file);
    return writeFile(file);
}
Пример #12
0
void main()
{
char a;
float x=10,y,x1,y1,n=1.0;
int m=3;
int max=0,k;
int count=1,score=0;
char l[33],r[33];
FILE *f;
char *o="Lives ";
char *q="Score";
int gd=DETECT,gm,b;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(GREEN);
while(!kbhit())
{
setcolor(BLUE);
settextstyle(7,HORIZ_DIR,6);
outtextxy(120,180,"CATCH THE EGG");
setcolor(WHITE);
settextstyle(7,HORIZ_DIR,1);
outtextxy(180,250,"PRESS ANY KEY TO START");
settextstyle(8,HORIZ_DIR,1);
outtextxy(440,390,"C Project By");
outtextxy(440,410,"Abhinav");
outtextxy(440,430,"Nikhil");
outtextxy(440,450,"Nitish");
settextstyle(1,HORIZ_DIR,1);
setcolor(WHITE);
outtextxy(30,395,"Press Z to move left");
outtextxy(30,415,"Press M to move right");
outtextxy(30,435,"Press Q to QUIT");
delay(150);
setcolor(BLACK);
settextstyle(7,HORIZ_DIR,1);
outtextxy(180,250,"PRESS ANY KEY TO START");
delay(150);
}
cleardevice();
setbkcolor(BLACK);
y=440.0;
while(a!='q'&& m!=-1)
{
sprintf(l,"%s %d",o,m);
sprintf(r,"%s %d",q,score);
x1=rand() % 400 + 10;
y1=10;
cleardevice();
while(y1<440 && a!='q')
{
setcolor(WHITE);
settextstyle(9,HORIZ_DIR,1);
outtextxy(450,20,l);
outtextxy(450,50,r);
setcolor(RED);
setfillstyle(1,YELLOW);
rectangle(x,y,x+20,y+15);
floodfill(x+1,y+1,RED);
b=getpixel(x+50,y+50);
setcolor(WHITE);
setfillstyle(1,WHITE);
ellipse(x1,y1,0,360,4,15);
floodfill(x1,y1,WHITE);
setfillstyle(SOLID_FILL,b);
setcolor(b);
if(kbhit())
{
a=getch();
if(a=='q')break;
rectangle(x,y,x+20,y+15);
floodfill(x+1,y+1,b);
if(a=='m')
if(x<getmaxx())
x+=15.0;
else
x=0;
if(a=='z')
if(x>0)
x-=15.0;
else
x=getmaxx();
}
setcolor(BLACK);
setfillstyle(1,BLACK);
ellipse(x1,y1,0,360,4,15);
delay(5);
floodfill(x1,y1,BLACK);
if(y1-440>-5)
{
if(x1-x<30 && x1-x>-10)
{
setcolor(YELLOW);
setfillstyle(1,YELLOW);
ellipse(x1,y1,0,360,4,15);
floodfill(x1,y1,YELLOW);
setcolor(BLACK);
setfillstyle(1,BLACK);
ellipse(x1,y1,0,360,4,15);
delay(200);
floodfill(x1,y1,BLACK);
score+=3;
break;
}
else
m--;
break;
}
y1=y1+n;
}
if(count%4==0)
{
n+=0.2;
}
count++;
}
if(m==-1)
{
cleardevice();
setcolor(RED);
settextstyle(6,HORIZ_DIR,6);
outtextxy(220,200,"GAME OVER");
f=fopen("high.txt","a+");
putw(score,f);
rewind(f);
while(k!=EOF)
{
k=getw(f);
if(k>max)
max=k;
}
fclose(f);
settextstyle(6,HORIZ_DIR,1);
setcolor(WHITE);
sprintf(r,"  Your Score %d",score);
outtextxy(250,290,r);
sprintf(r,"  High Score %d",max);
outtextxy(250,330,r);
delay(2000);
}
closegraph();
}
Пример #13
0
void runSuccess() {
    FILE* file = VALID_FILE;
    if (file != NULL) {
        putw(anyint(), file);
    }
}
Пример #14
0
void runFailure() {
    putw(anyint(), NULL);
}