コード例 #1
0
/* ========================================================================= */
int ZEXPORT deflateReset (z_streamp strm)
{
    deflate_state *s;
    
    if (strm == Z_NULL || strm->state == Z_NULL ||
        strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;

    strm->total_in = strm->total_out = 0;
    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
    strm->data_type = Z_UNKNOWN;

    s = (deflate_state *)strm->state;
    s->pending = 0;
    s->pending_out = s->pending_buf;

    if (s->noheader < 0) {
        s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
    }
    s->status = s->noheader ? BUSY_STATE : INIT_STATE;
    strm->adler = 1;
    s->last_flush = Z_NO_FLUSH;

    _tr_init(s);
    lm_init(s);

    return Z_OK;
}
コード例 #2
0
/* ========================================================================= */
int zlib_deflateReset(
	z_streamp strm
)
{
    deflate_state *s;
    
    if (strm == NULL || strm->state == NULL)
        return Z_STREAM_ERROR;

    strm->total_in = strm->total_out = 0;
    strm->msg = NULL;
    strm->data_type = Z_UNKNOWN;

    s = (deflate_state *)strm->state;
    s->pending = 0;
    s->pending_out = s->pending_buf;

    if (s->noheader < 0) {
        s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
    }
    s->status = s->noheader ? BUSY_STATE : INIT_STATE;
    strm->adler = 1;
    s->last_flush = Z_NO_FLUSH;

    zlib_tr_init(s);
    lm_init(s);

    return Z_OK;
}
コード例 #3
0
ファイル: vbe.c プロジェクト: ziglef/DefenseOfTheFuture
int vbe_get_mode_info(unsigned short mode, vbe_mode_info_t *vmi_p) {
  
  struct reg86u reg86;
  mmap_t memory;
  
  lm_init();
  
  lm_alloc(VBE_MODE_INFO_SIZE, &memory);
  
  reg86.u.w.ax = 0x4F01;
  reg86.u.w.cx =  1 << 14 | mode;
  reg86.u.w.es = PB2BASE(memory.phys);
  reg86.u.w.di = PB2OFF(memory.phys);
  reg86.u.b.intno = 0x10;
  
  if(sys_int86(&reg86) != OK){
	  printf("vbe_get_mode_info: sys_int86() failed \n");
	  return 1;
  }
  
  memcpy(vmi_p, memory.virtual, VBE_MODE_INFO_SIZE);
  
  lm_free(&memory);
  
  return 0;
}
コード例 #4
0
ファイル: test5.c プロジェクト: bernardobelchior1/feup-lcom
int test_controller() {
	if (lm_init() == NULL) {
			printf("\tvg_get_controller_info(): lm_init() failed \n");
			return 1;
		}

	return vbe_get_controller_info();
}
コード例 #5
0
ファイル: video_gr.c プロジェクト: Digas29/LCOM-FROGGER
int controler_info(){
	mmap_t map_info;

	char * virtualBase = (char *) lm_init();
	if(virtualBase == NULL) return 1;

	VESA_INFO *info = (VESA_INFO *)lm_alloc(sizeof(VESA_INFO), &map_info);


	info->VESASignature[0] = 'V';
	info->VESASignature[1] = 'B';
	info->VESASignature[2] = 'E';
	info->VESASignature[3] = '2';


	vbe_get_controler_info(map_info.phys);
	char* ptr;
	ptr = REALPTR(info->VideoModePtr) + virtualBase;

	unsigned short *videoModesPtr = (unsigned short *)ptr;
	printf("Capabilites: \n");
	if(info->Capabilities[0] & BIT(0)){
		printf("DAC width is switchable to 8 bits per primary color\n");
	}
	else{
		printf("DAC is fixed width, with 6 bits per primary color\n");
	}
	if(info->Capabilities[0] & BIT(1)){
		printf("Controller is not VGA compatible\n");
	}
	else{
		printf("Controller is VGA compatible\n");
	}
	if(info->Capabilities[0] & BIT(2)){
		printf("When programming large blocks of information to the RAMDAC, use the blank bit in Function 09h.\n");
	}
	else{
		printf("Normal RAMDAC operation\n");
	}
	printf("\n Modes: \n");
	while(*videoModesPtr != END){
		printf("0x%X \t", *videoModesPtr);
		videoModesPtr++;
	}
	printf("\n\n VRAM SIZE: %d blocks of 64 KB\n", info->TotalMemory);
	lm_free(&map_info);
	return 0;
}
コード例 #6
0
int main(int argc, char **argv) {
  const char *usage = "Usage: fastsubs [-n <n> | -p <p>] model.lm[.gz] < input.txt";
  g_message_init();
  char buf[BUF];
  Token s[SMAX+1];
  char *w[SMAX+1];

  int opt;
  guint opt_n = NMAX;
  gdouble opt_p = PMAX;
  while ((opt = getopt(argc, argv, "p:n:")) != -1) {
    switch(opt) {
    case 'n':
      opt_n = atoi(optarg);
      break;
    case 'p':
      opt_p = atof(optarg);
      break;
    default:
      g_error("%s", usage);
    }
  }
  if (optind >= argc)
    g_error("%s", usage);
  g_message("Get substitutes until count=%d OR probability=%g", opt_n, opt_p);
  g_message("Loading model file %s", argv[optind]);
  LM lm = lm_init(argv[optind]);
  Hpair *subs = minialloc(lm->nvocab * sizeof(Hpair));
  g_message("ngram order = %d\n==> Enter sentences:\n", lm->order);
  int fs_ncall = 0;
  int fs_nsubs = 0;
  while(fgets(buf, BUF, stdin)) {
    int n = sentence_from_string(s, buf, SMAX, w);
    for (int i = 2; i <= n; i++) {
      int nsubs = fastsubs(subs, s, i, lm, opt_p, opt_n);
      fs_ncall++; fs_nsubs += nsubs;
      fputs(w[i], stdout);
      for (int j = 0; j < nsubs; j++) {
	printf("\t%s %.8f", token_to_string(subs[j].token), subs[j].logp);
      }
      printf("\n");
    }
  }
  minialloc_free_all();
  g_message("calls=%d subs/call=%g pops/call=%g", 
	    fs_ncall, (double)fs_nsubs/fs_ncall, (double)fs_niter/fs_ncall);
}
コード例 #7
0
ファイル: langmon.c プロジェクト: Magister/bjcups-2.50
int main(int ac, char **arv)
{
	int error;

#ifdef DEBUG
	/* logfile=/var/log/log.txt */
	create_log();
	fprintf(log_path, "ac = %d\n", ac);
	fflush(log_path);
#endif

	/* setup signal handlers */
	init_signals();

	/* printer DEVICE ID and command line option check */
	if((error = get_printer_devid()) < 0 || check_arg(ac,arv) < 0){

		/*
		   Not Canon printer
			or
		   "--gui" option not found
		*/
#ifdef DEBUG
		write_log("Now normal printing ......\n");
#endif
		print_normal();
		exit(0);
	}

	/* create semapho and other setup */
	if((error = lm_init(PRNT_PATH))){
		exit(0);
	}

	/* monitor_process/print_process/status_process start */
	lm_main_fork();

	/* delete semapho */
	remove_sem(sem_id);
	/* free memory (status monitor argv string) */
	free_arg();

#ifdef DEBUG
	write_log("LM end \n");
#endif
	exit(0);
}
コード例 #8
0
ファイル: vbe.c プロジェクト: vascofg/lcom
int vbe_get_mode_info(unsigned short mode, vbe_mode_info_t *vmi_p) {
  
	struct reg86u registers;
	mmap_t address;

	lm_init();
	lm_alloc(VBE_MODE_INFO_BLOCK_SIZE, &address);
	registers.u.b.ah = 0x4F;
	registers.u.b.al = 0x01;
	registers.u.w.es = PB2BASE(address.phys);
	registers.u.w.di = PB2OFF(address.phys);
	registers.u.b.intno = 0x10;
	registers.u.w.cx = 1 << 14 | mode;
	sys_int86(&registers);
	vbe_unpack_mode_info(address.virtual, vmi_p);
	lm_free(&address);
	return 1;
}
コード例 #9
0
ファイル: ZipSS.cpp プロジェクト: geoffsmith82/delphizip
int ZipOp::ZipStreamStream(void)
{
    fwindow_size = 0L;

    if (fGEncrypt)
    {
        fkey = fGPassword;

        if (!fkey || !*(fkey))
        {
            // use global
            if (GetUserPW() != DZ_ERR_GOOD)
                return -1;  // error

            fkey = fuser_key;
        }
    }

    fZipInfile = new ZStream(this, _T("0:<INSTREAM>"), fSS->fSSInput);

    AutoStream inz(&fZipInfile);
    fimax = fSS->Size;
    fcrc = crc32(0L, NULL, 0);
    fisize = 0;
    CB->SetArg1(1);
    CB->UserCB(zacCount);

    // Pass total filesize.
    CB->SetFileSize(fimax);
    CB->UserCB(zacSize);
    ulg f_crc = 0;
    __int64 fsz = 0;
    bool haveCRC = false;

    if (fkey)
    {
        if (!fNoPrecalc)
        {
            if (Verbose < 0)
                Notify(ITRACE,  _T("about to call Precalculate CRC"));

            // +++++ get CRC before we start
			CB->UserXItem(fimax, 13, _T("*PreCalculate"));
            __int64 pos1 = 0;

            if (!fZipInfile->IsFile)
                pos1 = fZipInfile->SetPosition(0, FILE_CURRENT); // get start posn

			f_crc = crc32(0L, NULL, 0);
            unsigned long byts;

            while (true)
            {
                unsigned ToRead = sizeof(fwindow);

                if (fimax > 0 && (fsz + ToRead) > fimax)
                {
                    ToRead = (unsigned)(fimax - fsz);

                    if (!ToRead)
                        break;
                }

                if (!fZipInfile->Read(fwindow, ToRead, &byts) || !byts)
                    break;

				fsz += byts;
				f_crc = crc32(f_crc, (const uch*)fwindow, (int)byts);
				CB->UserXProgress(byts, 13);

                if (Abort_Flag)
					Fatal(DZ_ERM_ABORT, 0);
            }

            fSS->CRC = f_crc;

            haveCRC = true;
            // reposition

            if (fZipInfile->SetPosition(pos1, FILE_BEGIN) != pos1)
            {
                if (Verbose)
					Notify(IVERBOSE, _T("Could not reposition %s [%s]"),
						fZipInfile->fname.c_str(), SysMsg().c_str());

				return  DZError(DZ_ERM_ERROR_SEEK);
			}

            if (fimax > fsz)
                fimax = fsz;
        }

        // ----- get CRC before we start
        // Since we do not yet know the crc here, we pretend that the crc is the
        //   modification time:
//    if (!haveCRC)
//      fSS->CRC = z->tim << 16;
        if (Verbose < 0)
            Notify(ITRACE,  _T("using supplied CRC %lu"), fSS->CRC);
    }

    // connect to output
    fZipOutfile = new ZStream(this, _T("0:<OUTSTREAM>"), fSS->fSSOutput);

    AutoStream outz(&fZipOutfile);

    CB->UserItem(fimax, _T("<INSTREAM>"));

	if (fkey)
		crypthead(fkey, fSS->CRC);  // write

    // Write stored or deflated file to zip file
    fSS->Method &= 0xFF;

    if (fSS->Method != DEFLATE)
        fSS->Method = 0;

    if (flevel < 1)
        fSS->Method = 0;

	int mthd = (int)fSS->Method;

    if (mthd == DEFLATE)
    {
        if (Verbose < 0)
            Notify(ITRACE,  _T("about to call Deflate"));

        bi_init();
        ush att = BINARY;
        ush flg = FLAG_ENCRYPT_BIT;

        // will be changed in deflate()
        ct_init(&att, &mthd);
        lm_init(flevel, &flg);

        // PERFORM THE DEFLATE
        fSS->Size = deflate();

        if (Abort_Flag)
			Fatal(DZ_ERM_ABORT, 0);
    }
    else
    {
        int k;

        if (Verbose)
            Notify(IVERBOSE, _T("Storing %s "), fZipInfile->fname.c_str());

        while ((k = read_buf(fwindow, sizeof(fwindow))) > 0
                && k != EOF)
        {
            if (Abort_Flag)
				Fatal(DZ_ERM_ABORT, 0);

			if (!zfwrite(fwindow,  (extent)k))
				return DZ_ERM_TEMP_FAILED;
        }

    }
    /*  Finished Item */
    CB->UserItem(-1, _T("<INSTREAM>")); // mark end of item
    CB->UserCB(zacEndOfBatch); // done with stream compression

    if (haveCRC)
    {
        if (f_crc != fcrc)
            Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File CRC changed while zipping: %s"),
                   fZipInfile->fname.c_str());

        if (fisize != fsz)
            Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File size changed while zipping: %s"),
                   fZipInfile->fname.c_str());
    }

    fSS->Size = fisize;

    fSS->CRC = fcrc;
    fSS->Method = (DWORD)mthd | (fkey ? 0xff00 : 0);
    return DZ_ERR_GOOD;
}
コード例 #10
0
void *vg_init(unsigned short mode) {
	vbe_mode_info_t info;
	struct reg86u reg86;
	int r;
	struct mem_range mr;

	reg86.u.b.intno = BIOS_VIDEO_INT; /* BIOS video services */
	reg86.u.w.ax = SET_VBE_MODE; /* Set Video Mode function */
	reg86.u.w.bx = SET_LINEAR_MODE | mode; /* Mode */

	if (sys_int86(&reg86) != OK) { // Sets video mode
		printf("\tvg_init(): sys_int86() failed \n");
		return NULL;
	}

	switch (reg86.u.w.ax) {
	case VBE_FUNC_CALL_FAILED:
		printf("\tvg_init(): sys_int86() function call failed.\n");
		return NULL;
		break;
	case VBE_FUNC_NOT_SUPPORTED:
		printf("\tvg_init(): sys_int86() function not supported.\n");
		return NULL;
		break;
	case VBE_FUNC_INVALID_CUR_MODE:
		printf(
				"\tvg_init(): sys_int86() function invalid in current video mode.\n");
		return NULL;
		break;
	}

	if (lm_init() == NULL) {
		printf("\tvg_init(): lm_init() failed \n");
		return NULL;
	}

	if (vbe_get_mode_info(mode, &info) != OK) { // Gets info
		printf("\tvg_init(): vbe_get_mode_info() failed \n");
		return NULL;
	}

	h_res = info.XResolution;
	v_res = info.YResolution; //Sets global variables
	bits_per_pixel = info.BitsPerPixel;

	//Allow memory mapping

	mr.mr_base = (phys_bytes)(info.PhysBasePtr);
	mr.mr_limit = mr.mr_base
			+ info.XResolution * info.YResolution * info.BitsPerPixel / 8;

	if (OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)))
		panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r);

	// Map memory

	video_mem = vm_map_phys(SELF, (void *) mr.mr_base,
			info.XResolution * info.YResolution * info.BitsPerPixel / 8);

	double_buffer = malloc(h_res * v_res * sizeof(char));

	/*if(video_mem == MAP_FAILED)
	 panic("video_txt couldn't map video memory");*/

	return video_mem;
}