예제 #1
0
int TDBINI::GetMaxSize(PGLOBAL g)
  {
  if (MaxSize < 0)
    MaxSize = Cardinality(g);

  return MaxSize;
  } // end of GetMaxSize
예제 #2
0
static
void BrowWriteUnformattedSet(Tcl_Interp *interp,struct Instance *i)
{
  CONST struct set_t *s;
  unsigned long len,c;
  char value[80];
  s = SetAtomList(i);
  switch(SetKind(s)) {
  case empty_set:
    break;
  case integer_set:
  case string_set:
    len = Cardinality(s);
    for(c=1;c<=len;c++) {
      if (SetKind(s)==integer_set) {
        sprintf(value,"%u", FetchIntMember(s,c));
        Tcl_AppendResult(interp,value," ",(char *)NULL);
      } else {
        Tcl_AppendResult(interp,"'",SCP(FetchStrMember(s,c)),"' ",
                         (char *)NULL);
      }
    }
    return;
  default:
    return;
  }
}
예제 #3
0
void MarkDefaultReductions( void )
/********************************/
{
    a_pro *pro;
    a_state *state;
    a_reduce_action *raction;
    a_reduce_action *default_raction;
    a_shift_action *saction;
    unsigned i;
    unsigned max_tokens;
    unsigned count_tokens;
    unsigned nshifts;
    unsigned nreduces;

    for( i = 0; i < nstate; ++i ) {
        // iterate over all reductions in state
        state = statetab[i];
        nshifts = 0;
        for( saction = state->trans; saction->sym != NULL; ++saction ) {
            ++nshifts;
            if( saction->sym == errsym ) {
                // if there is a shift on the error token then
                // we don't want default reduce actions
                state = NULL;
                break;
            }
        }
        if( state == NULL ) {
            continue;
        }
        default_raction = NULL;
        max_tokens = 0;
        nreduces = 0;
        for( raction = state->redun; (pro = raction->pro) != NULL; ++raction ) {
            ++nreduces;
            count_tokens = Cardinality( raction->follow );
            if( count_tokens >= max_tokens ) {
                max_tokens = count_tokens;
                default_raction = raction;
            }
        }
        if( nshifts == 0 && nreduces == 1 ) {
            OnlyReduce( state );
            ++nstate_1_reduce;
            assert( default_raction != NULL );
        }
        if( default_raction != NULL ) {
            state->default_reduction = default_raction;
        }
    }
}
예제 #4
0
bool MAPFAM::OpenTableFile(PGLOBAL g)
  {
  char    filename[_MAX_PATH];
  int     len;
  MODE    mode = Tdbp->GetMode();
  PFBLOCK fp;
  PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr;

#if defined(_DEBUG)
  // Insert mode is no more handled using file mapping
  assert(mode != MODE_INSERT);
#endif   // _DEBUG

  /*********************************************************************/
  /*  We used the file name relative to recorded datapath.             */
  /*********************************************************************/
  PlugSetPath(filename, To_File, Tdbp->GetPath());

  /*********************************************************************/
  /*  Under Win32 the whole file will be mapped so we can use it as    */
  /*  if it were entirely read into virtual memory.                    */
  /*  Firstly we check whether this file have been already mapped.     */
  /*********************************************************************/
  if (mode == MODE_READ) {
    for (fp = dbuserp->Openlist; fp; fp = fp->Next)
      if (fp->Type == TYPE_FB_MAP && !stricmp(fp->Fname, filename)
                     && fp->Count && fp->Mode == mode)
        break;

    if (trace)
      htrc("Mapping file, fp=%p\n", fp);

  } else
    fp = NULL;

  if (fp) {
    /*******************************************************************/
    /*  File already mapped. Just increment use count and get pointer. */
    /*******************************************************************/
    fp->Count++;
    Memory = fp->Memory;
    len = fp->Length;
  } else {
    /*******************************************************************/
    /*  If required, delete the whole file if no filtering is implied. */
    /*******************************************************************/
    bool   del;
    HANDLE hFile;
    MEMMAP mm;

    del = mode == MODE_DELETE && !Tdbp->GetNext();

    if (del)
      DelRows = Cardinality(g);

    /*******************************************************************/
    /*  Create the mapping file object.                                */
    /*******************************************************************/
    hFile = CreateFileMap(g, filename, &mm, mode, del);

    if (hFile == INVALID_HANDLE_VALUE) {
      DWORD rc = GetLastError();

      if (!(*g->Message))
        sprintf(g->Message, MSG(OPEN_MODE_ERROR),
                "map", (int) rc, filename);

      if (trace)
        htrc("CreateFileMap: %s\n", g->Message);

      return (mode == MODE_READ && rc == ENOENT)
              ? PushWarning(g, Tdbp) : true;
      } // endif hFile

    /*******************************************************************/
    /*  Get the file size (assuming file is smaller than 4 GB)         */
    /*******************************************************************/
    len = mm.lenL;
    Memory = (char *)mm.memory;

    if (!len) {              // Empty or deleted file
      CloseFileHandle(hFile);
      Tdbp->ResetSize();
      return false;
      } // endif len

    if (!Memory) {
      CloseFileHandle(hFile);
      sprintf(g->Message, MSG(MAP_VIEW_ERROR),
                          filename, GetLastError());
      return true;
      } // endif Memory

#if defined(WIN32)
    if (mode != MODE_DELETE) {
#else   // !WIN32
    if (mode == MODE_READ) {
#endif  // !WIN32
      CloseFileHandle(hFile);                    // Not used anymore
      hFile = INVALID_HANDLE_VALUE;              // For Fblock
      } // endif Mode

    /*******************************************************************/
    /*  Link a Fblock. This make possible to reuse already opened maps */
    /*  and also to automatically unmap them in case of error g->jump. */
    /*  Note: block can already exist for previously closed file.      */
    /*******************************************************************/
    fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK));
    fp->Type = TYPE_FB_MAP;
    fp->Fname = (char*)PlugSubAlloc(g, NULL, strlen(filename) + 1);
    strcpy((char*)fp->Fname, filename);
    fp->Next = dbuserp->Openlist;
    dbuserp->Openlist = fp;
    fp->Count = 1;
    fp->Length = len;
    fp->Memory = Memory;
    fp->Mode = mode;
    fp->File = NULL;
    fp->Handle = hFile;                // Used for Delete
  } // endif fp

  To_Fb = fp;                               // Useful when closing

  /*********************************************************************/
  /*  The pseudo "buffer" is here the entire file mapping view.        */
  /*********************************************************************/
  Fpos = Mempos = Memory;
  Top = Memory + len;

  if (trace)
    htrc("fp=%p count=%d MapView=%p len=%d Top=%p\n",
          fp, fp->Count, Memory, len, Top);

  return AllocateBuffer(g);          // Useful for DBF files
  } // end of OpenTableFile

/***********************************************************************/
/*  GetRowID: return the RowID of last read record.                    */
/***********************************************************************/
int MAPFAM::GetRowID(void)
  {
  return Rows;
  } // end of GetRowID

/***********************************************************************/
/*  GetPos: return the position of last read record.                   */
/***********************************************************************/
int MAPFAM::GetPos(void)
  {
  return Fpos - Memory;
  } // end of GetPos

/***********************************************************************/
/*  GetNextPos: return the position of next record.                    */
/***********************************************************************/
int MAPFAM::GetNextPos(void)
  {
  return Mempos - Memory;
  } // end of GetNextPos

/***********************************************************************/
/*  SetPos: Replace the table at the specified position.               */
/***********************************************************************/
bool MAPFAM::SetPos(PGLOBAL g, int pos)
  {
  Fpos = Mempos = Memory + pos;

  if (Mempos >= Top || Mempos < Memory) {
    strcpy(g->Message, MSG(INV_MAP_POS));
    return true;
    } // endif Mempos

  Placed = true;
  return false;
  } // end of SetPos
예제 #5
0
bool DOSFAM::OpenTableFile(PGLOBAL g)
  {
  char    opmode[4], filename[_MAX_PATH];
//int     ftype = Tdbp->GetFtype();
  MODE    mode = Tdbp->Mode;
  PDBUSER dbuserp = PlgGetUser(g);

  // This is required when using Unix files under Windows
  Bin = (Ending == 1);

  switch (mode) {
    case MODE_READ:
      strcpy(opmode, "r");
      break;
    case MODE_DELETE:
      if (!Tdbp->Next) {
        // Store the number of deleted lines
        DelRows = Cardinality(g);

        if (Blocked) {
          // Cardinality must return 0
          Block = 0;
          Last = Nrec;
          } // endif blocked

        // This will erase the entire file
        strcpy(opmode, "w");
        Tdbp->ResetSize();
        break;
        } // endif

      // Selective delete, pass thru
      Bin = true;
    case MODE_UPDATE:
      if ((UseTemp = Tdbp->IsUsingTemp(g))) {
        strcpy(opmode, "r");
        Bin = true;
      } else
        strcpy(opmode, "r+");

      break;
    case MODE_INSERT:
      strcpy(opmode, "a+");
      break;
    default:
      sprintf(g->Message, MSG(BAD_OPEN_MODE), mode);
      return true;
    } // endswitch Mode

  // For blocked I/O or for moving lines, open the table in binary
  strcat(opmode, (Blocked || Bin) ? "b" : "t");

  // Now open the file stream
  PlugSetPath(filename, To_File, Tdbp->GetPath());

  if (!(Stream = PlugOpenFile(g, filename, opmode))) {
    if (trace)
      htrc("%s\n", g->Message);

    return (mode == MODE_READ && errno == ENOENT)
            ? PushWarning(g, Tdbp) : true;
    } // endif Stream

  if (trace)
    htrc("File %s open Stream=%p mode=%s\n", filename, Stream, opmode);

  To_Fb = dbuserp->Openlist;     // Keep track of File block

  /*********************************************************************/
  /*  Allocate the line buffer. For mode Delete a bigger buffer has to */
  /*  be allocated because is it also used to move lines into the file.*/
  /*********************************************************************/
  return AllocateBuffer(g);
  } // end of OpenTableFile
예제 #6
0
static struct gl_list_t *FindArrayChildrenPath(struct gl_list_t *list,
				    CONST struct set_t *sptr,
				    enum find_errors *errval)
{
  struct gl_list_t *result;
  CONST struct Instance *i,*child;
  struct InstanceName rec;
  struct TypeDescription *desc;
  unsigned long c1,len1,c2,len2,pos;
  PAN *p, *p2;
  struct Name *n, *n2;
  symchar *senum;
  long sint;

  switch(SetKind(sptr)){
  case empty_set: return gl_create(0);
  case string_set:
    SetInstanceNameType(rec,StrArrayIndex);
    len2 = Cardinality(sptr);
    len1 = gl_length(list);
    result = gl_create(len1*len2);
    for (c1=1; c1<=len1; c1++){
      p = (PAN *)gl_fetch(list,c1);
      i = p->i;
      if (InstanceKind(i)==ARRAY_ENUM_INST){
	if (NextToExpand(i)!=1){
	  for (c2=1; c2<=len2; c2++){
            senum = FetchStrMember(sptr,c2);
	    SetInstanceNameStrIndex(rec,senum);
	    if ((pos = ChildSearch(i,&rec))==0){
	      DestroyPANList(&result);
	      desc = InstanceTypeDesc(i);
	      if ( GetArrayBaseIsRelation(desc) || GetArrayBaseIsLogRel(desc)){
		*errval = unmade_instance;
	      } else {
		*errval = impossible_instance;
              }
	      return NULL;
	    } else {
              child = InstanceChild(i,pos);
	      if (child!=NULL){
                n = CreateEnumElementName(senum);
                n2 = CopyAppendNameNode(p->n, n);
                DestroyName(n);
                p2 = CreatePAN(child, n2);
		gl_append_ptr(result,(VOIDPTR)p2);
	      } else {
		DestroyPANList(&result);
		*errval = unmade_instance;
		return NULL;
	      }
	    }
	  }
	} else {
	  DestroyPANList(&result);
	  *errval = unmade_instance;
	  return NULL;
	}
      } else {
	DestroyPANList(&result);
	*errval = impossible_instance;
	return NULL;
      }
    }
    return result;
  case integer_set:
    SetInstanceNameType(rec,IntArrayIndex);
    len2 = Cardinality(sptr);
    len1 = gl_length(list);
    result = gl_create(len1*len2);
    for (c1=1; c1<=len1; c1++){
      p = (PAN *)gl_fetch(list,c1);
      i = p->i;
      if (InstanceKind(i)==ARRAY_INT_INST){
	if (NextToExpand(i)!=1){
	  for (c2=1; c2<=len2; c2++){
            sint = FetchIntMember(sptr,c2);
	    SetInstanceNameIntIndex(rec,sint);
	    if ((pos = ChildSearch(i,&rec))==0){
	      DestroyPANList(&result);
	      desc = InstanceTypeDesc(i);
	      if (GetArrayBaseIsRelation(desc) || GetArrayBaseIsLogRel(desc)) {
		*errval = unmade_instance;
	      } else {
		*errval = impossible_instance;
              }
	      return NULL;
	    } else {
	      child = InstanceChild(i,pos);
	      if (child!=NULL){
                n = CreateIntegerElementName(sint);
                n2 = CopyAppendNameNode(p->n, n);
                DestroyName(n);
                p2 = CreatePAN(child, n2);
		gl_append_ptr(result,(VOIDPTR)p2);
	      } else{
		DestroyPANList(&result);
		*errval = unmade_instance;
		return NULL;
	      }
	    }
	  }
	} else {
	  DestroyPANList(&result);
	  *errval = unmade_instance;
	  return NULL;
	}
      } else {
	DestroyPANList(&result);
	*errval = impossible_instance;
	return NULL;
      }
    }
    return result;
  }
  /*NOTREACHED*/
  return NULL;
}
예제 #7
0
bool ZIPFAM::OpenTableFile(PGLOBAL g)
  {
  char    opmode[4], filename[_MAX_PATH];
  MODE    mode = Tdbp->GetMode();

  switch (mode) {
    case MODE_READ:
      strcpy(opmode, "r");
      break;
    case MODE_UPDATE:
      /*****************************************************************/
      /* Updating ZIP files not implemented yet.                       */
      /*****************************************************************/
      strcpy(g->Message, MSG(UPD_ZIP_NOT_IMP));
      return true;
    case MODE_DELETE:
      if (!Tdbp->GetNext()) {
        // Store the number of deleted lines
        DelRows = Cardinality(g);

        // This will erase the entire file
        strcpy(opmode, "w");
//      Block = 0;                // For ZBKFAM
//      Last = Nrec;              // For ZBKFAM
        Tdbp->ResetSize();
      } else {
        sprintf(g->Message, MSG(NO_PART_DEL), "ZIP");
        return true;
      } // endif filter

      break;
    case MODE_INSERT:
      strcpy(opmode, "a+");
      break;
    default:
      sprintf(g->Message, MSG(BAD_OPEN_MODE), mode);
      return true;
    } // endswitch Mode

  /*********************************************************************/
  /*  Open according to logical input/output mode required.            */
  /*  Use specific zlib functions.                                     */
  /*  Treat files as binary.                                           */
  /*********************************************************************/
  strcat(opmode, "b");
  Zfile = gzopen(PlugSetPath(filename, To_File, Tdbp->GetPath()), opmode);

  if (Zfile == NULL) {
    sprintf(g->Message, MSG(GZOPEN_ERROR),
            opmode, (int)errno, filename);
    strcat(strcat(g->Message, ": "), strerror(errno));
    return (mode == MODE_READ && errno == ENOENT)
            ? PushWarning(g, Tdbp) : true;
    } // endif Zfile

  /*********************************************************************/
  /*  Something to be done here. >>>>>>>> NOT DONE <<<<<<<<            */
  /*********************************************************************/
//To_Fb = dbuserp->Openlist;     // Keep track of File block

  /*********************************************************************/
  /*  Allocate the line buffer.                                        */
  /*********************************************************************/
  return AllocateBuffer(g);
  } // end of OpenTableFile