Exemplo n.º 1
0
bool Save(uchar  *pbBase, uint  wSize)
{
  while (wSize > 0)
  {
    uint wFree = wLEAF_BYTES - wByteOut;        // размер свободной части буфера

    if (wSize > wFree)                          // блок данных больше размера свободной части буфера
    {                                           // заполняем всё свободное место
      memcpy(mpbPageOut + wByteOut, pbBase, wFree);                                

      if (SafePageWrite(wPageOut) == false) return false; // записываем буфер

      OpenOut(wPageOut + 1);                    // подготавливаемся к записи следующей страницы

      pbBase += wFree;                          // переходим на следующую позицию источника данных
      wSize  -= wFree;                          // уменьшаем размер блока данных
    }
    else
    {                                           // заносим все данные в буфер
      memcpy(mpbPageOut + wByteOut, pbBase, wSize);                                  
      wByteOut += wSize;                        // увеличиваем счётчик заполнения буфера

      return true;
    }
  }

  return true;
}  
Exemplo n.º 2
0
bool SaveBuff(uint wPage, void *pbBuff, uint wSize)
{
  OpenOut(wPage);

  if (Save(pbBuff, wSize) == false)
    return false;

  return CloseOut();
}
Exemplo n.º 3
0
Boolean FileReader::Open(const char* Fname_, int Mode_)
{
  if (SharedBuffer())
  {
    if ((Mode_ & ios::out) || (Mode_ & ios::app))
      return OpenOut(Fname_, Mode_);
    else if (Mode_ & ios::in)
      return OpenIn(Fname_, Mode_);
  }
  else
  {
    Boolean OpenOK_ = TRUE;

    if ((Mode_ & ios::out) || (Mode_ & ios::app))
      OpenOK_ = OpenOut(Fname_, Mode_);

    if (Mode_ & ios::in)
      OpenOK_ = OpenOK_ && OpenIn(Fname_, Mode_);

    return OpenOK_;
  }

  return FALSE;
}
Exemplo n.º 4
0
main(int   argc,
     char  **argv)
{
    extern int	    optind;	/* for use of getopt() */
    extern char	    *optarg;	/* for use of getopt() */
    int		    ch;		/* command-line option letter */

    int		    outarch = NATIVE;

    char	    **field_names = NULL;
    int		    num_fields = 0;
    int		    alloc_fields = 0;

    int		    rflag = NO;	/* -r option specified? */
    char	    *rrange;	/* arguments of -r option */
    long	    start_rec;	/* starting record number */
    long	    end_rec;	/* ending record number */
    long	    num_recs;	/* number of records to read
				   (0 means all up to end of file) */
    long	    num_read;	/* number of records actually read */

    int		    Aflag = NO;	/* annotate Ascii output? */
    Annot	    *annotate = NULL;
    int		    annwidth = 70;

    char	    *iname;	/* input file name */
    FILE	    *ifile;	/* input stream */
    struct header   *ihd;	/* input file header */
    struct fea_data *irec;	/* input record */

    char	    *oname;	/* output file name */
    FILE	    *ofile;	/* output stream */
    FieldList	    list;	/* output field list */
    int		    outord = TYPE_ORDER;
    FieldSpec	    **ofields;	/* output fields in field or type order */

    double	    rec_freq;
    double	    start_time_offset;
    char	    *fdata;
    double	    *edata;
    int		    type;
    int		    len, i;
    long	    dim[1];
    FieldSpec	    *field;

    FieldList	    source;	/* field list of source file */

    while ((ch = getopt(argc, argv, "a:f:r:x:A:F")) != EOF)
	switch (ch)
	{
	case 'a':
	    outarch = ((!strcmp(optarg, "EDR1")) ? EDR1
		       : (!strcmp(optarg, "EDR2")) ? EDR2
		       : (!strcmp(optarg, "NATIVE")) ? NATIVE
		       : (!strcmp(optarg, "ASCII")) ? ASCII
		       : UNKNOWN);
	    break;
	case 'f':
	    if (num_fields >= alloc_fields)
	    {
		size_t	size;

		alloc_fields = num_fields + 1 + num_fields/2;
		size = (alloc_fields + 1) * sizeof(char *);
		field_names = (char **)
		    ((field_names == NULL)
		     ? malloc(size)
		     : realloc(field_names, size));
	    }
	    field_names[num_fields++] = optarg;
	    field_names[num_fields] = NULL;
	    break;
	case 'r':
	    rflag = YES;
	    rrange = optarg;
	    break;
	case 'x':
	    debug_level = atoi(optarg);
	    break;
	case 'A':
	    Aflag = YES;
	    annwidth = atoi(optarg);
	    break;
	case 'F':
	    outord = FIELD_ORDER;
	    break;
	default:
	    SYNTAX;
	    break;
	}

    if (argc - optind > 2)
    {
	fprintf(stderr,
		"%s: too many file names specified.\n", ProgName);
	SYNTAX;
    }
    if (argc - optind < 2)
    {
	fprintf(stderr,
		"%s: too few file names specified.\n", ProgName);
	SYNTAX;
    }

    iname = eopen(ProgName,
		  argv[optind++], "r", FT_FEA, NONE, &ihd, &ifile);

    oname = argv[optind++];

    start_rec = 1;
    end_rec = LONG_MAX;
    num_recs = 0;

    if (rflag)
    {
	lrange_switch(rrange, &start_rec, &end_rec, 0);
	if (end_rec != LONG_MAX)
	    num_recs = end_rec - start_rec + 1;
    }

    REQUIRE(start_rec >= 1, "can't start before beginning of file");
    REQUIRE(end_rec >= start_rec, "empty range of records specified");

    if (debug_level)
	fprintf(stderr,
		"start_rec: %ld.  end_rec: %ld.  num_recs: %ld.\n",
		start_rec, end_rec, num_recs);

    DebugMsgLevel = debug_level;
    DebugMsgFunc = DebugPrint;

    irec = allo_fea_rec(ihd);

    REQUIRE(irec != NULL, "can't allocate memory for input record");

    list = fea_to_FieldList(ihd, irec, field_names, FALSE);

    REQUIRE(list != NULL,
	    "failure converting input header to field list");

    switch (outord)
    {
    case TYPE_ORDER:
	if (debug_level)
	    fprintf(stderr, "making type-ordered field array.\n");
	ofields = TypeOrder(list);
	break;
    case FIELD_ORDER:
	if (debug_level)
	    fprintf(stderr, "making field-ordered field array.\n");
	ofields = FieldOrder(list);
	break;
    default:
	REQUIRE(0, "output order neither TYPE_ORDER nor FIELD_ORDER");
	break;
    }

    if (debug_level)
	fprintf(stderr, "setting field ordering.\n");

    REQUIRE(SetFieldOrdering(&list, outord),
	    "can't set field ordering of output");

    rec_freq = get_genhd_val("record_freq", ihd, 1.0);

    type = genhd_type("record_freq", &len, ihd);

    if (type != HD_UNDEF)
    {
	field = AddGlobalField(&list, "recordFreq", 0, NULL, EDOUBLE, NULL);
	*(double *) field->data = rec_freq;
    }

    type = genhd_type("start_time", &len, ihd);

    if (type != HD_UNDEF && rec_freq != 0)
    {
	start_time_offset = (start_rec - 1) / rec_freq;

	fdata = (char *) get_genhd("start_time", ihd);
	edata = (double *) type_convert((long) len, fdata, type,
					(char *) NULL, DOUBLE,
					(void (*)()) NULL);

	if (start_time_offset != 0)
	{
	    for (i = 0; i < len; i++)
		edata[i] += start_time_offset;
	}

	dim[0] = len;
	AddGlobalField(&list, "startTime", 1, dim, EDOUBLE, edata);
    }

    source = fea_to_FieldList(ihd, NULL, NULL, TRUE);
    (void) AddSource(&list, 0, iname, source);

    (void) AddCommandLine(&list, GetCommandLine(argc, argv));

    if (debug_level)
	fprintf(stderr, "annwidth %d.\n", annwidth);

    if (Aflag)
    {
	annotate = (Annot *) malloc(sizeof(Annot));
	annotate->position = 0;
	annotate->indent = 0;
	annotate->width = annwidth;
	annotate->recnum = 0;
    }

    if (debug_level)
	fprintf(stderr, "writing Esignal header.\n");

    REQUIRE(OpenOut(oname, list, outarch, &ofile, annotate),
	    "write header failed");
    if (ofile == stdout)
	oname = "<stdout>";

    num_read = start_rec - 1;

    if (debug_level)
	fprintf(stderr, "skipping %ld records.\n", num_read);

/*    skiprec(ifile, num_read, size_rec(ihd)); */
    fea_skiprec(ifile, num_read, ihd);

    while (num_read++ < end_rec && get_fea_rec(irec, ihd, ifile) != EOF)
    {
	if (debug_level > 2)
	    fprintf(stderr, "Record number %ld read.\n", num_read);

	WriteRecord(ofields, outarch, ofile, annotate);
    }

    if (--num_read < end_rec && num_recs != 0)
	fprintf(stderr, "fea2esig: only %ld records read.\n",
		num_read - (start_rec - 1));

    exit(0);
    /*NOTREACHED*/
}
Exemplo n.º 5
0
void	OpenDiagFile( LPTSTR lpf, HANDLE * lpHF, BOOL bApd )
{
   OpenOut( lpf, lpHF, bApd );
}
Exemplo n.º 6
0
static void CloseRecord(uint  wPage, uint  i)
{
  OpenOut(wPage + i / bRECORD_BLOCK);
  RecordToBuff((uchar *) &mpbPageOut + (i % bRECORD_BLOCK)*SIZEOF_RECORD);
}