예제 #1
0
void AddRec(void)
{
	COURSE course1;                                          //Declare Variables
	COURSE course2;
	int i = 0;
	char prompt_yn;
	char temp[10];

	if(filename[0])                                          //If database open
	{
		Header();
		printf("\nAdd Record\n");

		EditRec(&course1);                                     //Edit Record and Write record
		WriteRec(&course1);
		ReadRec(&course2);
		DisplayRec(&course2);

		while(array[i].number[0] != '\0')                      //Find opening in array
			i++;
		
		RecCpy(&array[i], &course2);                           //Put record in opening
		
		LinkRec(&array[i]);                                   //Link new record
		printf("\nNew record added sucessfully!");
	}
	else{
		printf("\nError\nNo database is open.\n");                //Error if no database is open
		while(1){						  //Ask the user if they would like to make one
			printf("\nWould you like to create a new database? [y/n] ");
			fgets(temp, 10, stdin);
			if(strlen(temp) > 2) printf("\nERROR: INVALID RESPONSE LENGTH\n");
			else prompt_yn = temp[0];
			if(prompt_yn == 'y'){NewDat(); AddRec();}
			else if(prompt_yn == 'n') break;
			else{
				printf("\nERROR: INVALID RESPONSE\n");
			}
		}
	}

	GetEnter();
	return;
}
Boolean TDataAscii::GetRecs(TDHandle req, void *buf, int bufSize,
                            RecId &startRid, int &numRecs, int &dataSize)
{
  DOASSERT(req, "Invalid request handle");

#if DEBUGLVL >= 3
  printf("TDataAscii::GetRecs: handle %d, buf = 0x%p\n", req->iohandle, buf);
#endif

  DOASSERT(req->iohandle >= 0, "I/O request not initialized properly");

  numRecs = bufSize / _recSize;
  DOASSERT(numRecs > 0, "Not enough record buffer space");

  if (req->nextId > req->endId)
    return false;
  
  int num = req->endId - req->nextId + 1;
  if (num < numRecs)
    numRecs = num;
  
  if (req->iohandle == 0)
    ReadRec(req->nextId, numRecs, buf);
  else
    ReadRecAsync(req, req->nextId, numRecs, buf);
  
  startRid = req->nextId;
  dataSize = numRecs * _recSize;
  req->nextId += numRecs;
  
  _bytesFetched += dataSize;
  
  if (req->nextId > req->endId)
    req->iohandle = -1;

  return true;
}
예제 #3
0
static void ProcFile( char * fname )
/**********************************/
{
    int         ftype;
    char *      name;
    int         status;
    int         namelen;
    char *      bak;

    namelen = strlen( fname ) + 5;
    name = alloca( namelen );
    if( name == NULL ) Suicide();           // null == no stack space left.
    strcpy( name, fname );
    ReplaceExt( name, ".obj", FALSE );
    InFile = QOpen( name, O_RDONLY | O_BINARY, 0 );
    for(;;) {
        CleanRecStuff();
        ftype = ReadRec();
        if( ftype == ENDLIBRARY || ftype == ENDFILE ) {
            break;
        } else if( ftype == LIBRARY ) {
            Warning( "exclude option does not apply to libraries" );
            FreeList( ExcludeList );
            ExcludeList = NULL;
        } else if( ftype != OBJECT ) {
            Error( "file is not a standard OBJECT or LIBRARY file" );
        }
        OutFile = QOpen( TEMP_OBJ_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0 );
        do {
            ProcessRec();
            status = ReadRec();
        } while( status == OK );
        if( status == ENDMODULE ) {
            ProcessRec();           // process the modend rec.
            DoReplace();
        } else {
            Error( "premature end of file encountered" );
        }
        FreeList( ExcludeList );    // do this here so concatenated .obj files
        ExcludeList = NULL;         // only have the first module excluded.
    }
    CloseFiles();
    if( MakeBackup ) {
        bak = alloca( namelen );
        if( bak == NULL ) Suicide();           // null == no stack space left.
        strcpy( bak, name );
        if( ftype == ENDLIBRARY ) {
            ReplaceExt( bak, ".bak", TRUE );
        } else {
            ReplaceExt( bak, ".bob", TRUE );
        }
        CopyFile( name, bak );
    }
    QRemove( name );
    if( ftype == ENDLIBRARY ) {
        rename( TEMP_LIB_NAME, name );
    } else {
        rename( TEMP_OBJ_NAME, name );
    }
    FileCleanup();
}