Example #1
0
void conversion() {
	SqStack S;
	InitStack(S);
	int N;
	printf("input the decimal number:\n");
	scanf_s("%d", &N);
	printf("input the the number system after conversion:\n");
	int d;
	scanf_s("%d", &d);
	while (N) {
		ElemType e;
		e.key = N % d;
		Push(S, e);
		N = N / d;
	}
	PrintStack(S);
	printf("the conversion result is:\n");
	while (!StackEmpty(S)) {
		ElemType e;
		Pop(S, e);
		printf("%d", e.key);
	}
	printf("\n");
	PrintStack(S);
	DestroyStack(S);
}
Example #2
0
int main()
{
    int N, Sn, X;
    Stack S;
    int done = 0;

    scanf("%d", &N);
    S = CreateStack(N);
    while ( !done ) {
        switch( GetOp() ) {
        case push: 
            scanf("%d %d", &Sn, &X);
            if (!Push(X, S, Sn)) printf("Stack %d is Full!\n", Sn);
            break;
        case pop:
            scanf("%d", &Sn);
            X = Top_Pop(S, Sn);
            if ( X==ERROR ) printf("Stack %d is Empty!\n", Sn);
            break;
        case end:
            PrintStack(S, 1);
            PrintStack(S, 2);
            done = 1;
            break;
        }
    }
    return 0;
}
int main()
{
   List L1, L2;
   Stack S1, S2;
   Position current1, current2;
   FILE *fpr, *fpi;
   Position current;
   int isPalindrome;

   L1 = CreateEmptyList();
   fpr = fopen("linkedlist1.dat", "r");
   if(fpr == NULL)
   {
      printf("\nFailed to open file!\n");
   }
   CreateList(fpr, L1);

   L2 = CreateEmptyList();
   fpi = fopen("linkedlist2.dat", "r");
   if(fpi == NULL)
   {
      printf("\nFailed to open file!\n");
      exit(0);
   }
   CreateList(fpi, L2);

   PrintList(L1);
   PrintList(L2);

   S1 = CreateEmptyStack();
   S1 = CreateStackFromList(L1, S1);

   S2 = CreateEmptyStack();
   S2 = CreateStackFromList(L2, S2);
   
   PrintStack(S1);
   PrintStack(S2);

   isPalindrome = CheckIsPalindrome(L1, S1);
   if(isPalindrome == 0)
   {
      printf("\nThat list is a Palindrome!\n");
   }
   else
   {
      printf("\nThat list is not a Palindrome!\n");
   }

   isPalindrome = CheckIsPalindrome(L2, S2);
   if(isPalindrome == 0)
   {
      printf("\nThat list is a Palindrome!\n");
   }
   else
   {
      printf("\nThat list is not a Palindrome!\n");
   }

   return 0;
}
Example #4
0
int main()
{
	Stack s;
	ElemType x;
	cout<<"(1)³õʼ»¯Õ»s"<<endl;
	InitStack(s);
	cout<<"(2)ջΪ"<<(StackEmpty(s)?"¿Õ":"·Ç¿Õ")<<endl;
	cout<<"(3)ÒÀ´ÎÊäÈë×ÖĸÐòÁУ¬ÒÔ¡°#¡±½áÊø£º"<<endl;
	cin>>x;
	while( x!='#')
	{
		Push(s,x);
		cin>>x;
	}
	cout<<"(4)ջΪ"<<(StackEmpty(s)?"¿Õ":"·Ç¿Õ")<<endl;
	cout<<"(5)Õ»³¤¶ÈStackLength(s):"<<StackLength(s)<<endl;
	cout<<"(6a)Õ»¶¥ÔªËØGetTop(s)Ϊ£º";
	cout<<GetTop(s)<<endl;
	cout<<"(6b)Õ»¶¥ÔªËØGetTop1(s,x)Ϊ£º"<<endl;
	GetTop1(s,x);
	cout<<x<<endl;
	cout<<"(7)´ÓÕ»¶¥µ½Õ»µ×ÔªËØPrintStack(s)Ϊ£º"<<endl;
	PrintStack(s);
	cout<<"(8)³öÕ»Pop1(s,x)µÄÔªËØΪ£º"<<endl;
	Pop1(s,x);
	cout<<x<<endl;
	cout<<"(9)³öÕ»ÐòÁÐ:"<<endl;
	while(!StackEmpty(s))
    {
        cout<<Pop(s)<<" ";
    }
    cout<<endl;
    cout<<"(10)ջΪ:"<<(StackEmpty(s)?"¿Õ":"·Ç¿Õ")<<endl;
    cout<<"(11)ÒÀ´Î½øÕ»ÔªËØa,b,c:"<<endl;
    Push(s,'a');
    Push(s,'b');
    Push(s,'c');
    cout<<"(12)´ÓÕ»¶¥µ½Õ»µ×ÔªËØPrintStack(s)Ϊ£º"<<endl;
    PrintStack(s);
    cout<<"(13)Çå¿ÕÕ»ClearStack(s)"<<endl;
    ClearStack(s);
    cout<<"(14)ջΪ"<<(StackEmpty(s)?"¿Õ":"·Ç¿Õ")<<endl;
    cout<<"(15)Ïú»ÙÕ»s:"<<endl;
    DestoryStack(s);
    cout<<"(16)Ïú»ÙÕ»ºóµ÷ÓÃPush(s,e)ºÍPrintStack(s)"<<endl;
    Push(s,'e');
    PrintStack(s);
	return 0;
}
Example #5
0
void lineEdit() {
	SqStack S;
	InitStack(S);
	char ch;
	ch = getchar();
	ElemType e;
	while (ch != EOF) {
		while (ch != EOF && ch != '\n') {
			switch (ch) {
			case '#': 
				Pop(S, e);
				break;
			case '@':
				ClearStack(S);
				break;
			default:
				e.key = ch;
				Push(S, e);
				break;
			}
			ch = getchar();
		}

		PrintStack(S);
		ClearStack(S);
		if (ch != EOF) ch = getchar();
	}
	DestroyStack(S);
}
Example #6
0
int main()
{
	Stack s;
	int n;
	printf("Input n you want to CreateStack\n");
	scanf("%d", &n);
	s = CreateStack(n);
	PrintStack(s);
}
Example #7
0
void PrintStacks()
{
	if(countA != A->m_numElements ||
		countB != B->m_numElements ||
		countC != C->m_numElements)
	{
		int diffA = A->m_numElements - countA;
		int diffB = B->m_numElements - countB;
		int diffC = C->m_numElements - countC;
		if(diffA == 1)
		{
			if(diffB == -1)
				printf("Move Disc %d From B To A",top(A));
			else
				printf("Move Disc %d From C To A",top(A));
		}
		else if(diffB == 1)
		{
			if(diffA == -1)
				printf("Move Disc %d From A To B",top(B));
			else
				printf("Move Disc %d From C To B",top(B));
		}
		else //if (diffC == 1)
		{
			if(diffA == -1)
				printf("Move Disc %d From A To C",top(C));
			else
				printf("Move Disc %d From B To C",top(C));
		}
		countA = A->m_numElements;
		countB = B->m_numElements;
		countC = C->m_numElements;
		printf("\n");
	}

	PrintStack(A);
	printf(" , ");
	PrintStack(B);
	printf(" , ");
	PrintStack(C);
	printf(" , ");
}
Example #8
0
void testBasicStack() {
	SqStack S;
	InitStack(S);
	if (StackEmpty(S)) printf("the Stack S is Empty");
	PrintStack(S);
	printf("add item to the stack.\n");
	CreateStack(S);
	PrintStack(S);
	printf("pop the top of the stack:\n");
	ElemType e;
	Pop(S, e);
	PrintStack(S);
	printf("the element that is popped out: %d\n", e.key);
	ClearStack(S);
	printf("clear the stack:\n");
	PrintStack(S);
	printf("destroy the stack:\n");
	DestroyStack(S);
	PrintStack(S);
}
int main()
{
	int d;
	char pilihan;
	Stack S;

	CreateEmpty(&S);
	printf("%d %d\n",S.TOP,S.T[S.TOP]);
	PrintStack(S);
	while (!IsFull(S))
	{
		scanf("%c %d",&pilihan,&d);
		if (pilihan =='p')
			Pop(&S,d);
		else if (pilihan == 'h') 
			Push(&S,d);
		PrintStack(S); printf("%d\n",S.TOP);
	}	
		
	return 0;
}
int main(int argc, char *argv[])
{
	Stack stack;
	Element item;
	memset(&stack, 0x00, sizeof(Stack));

	item.key = 1;
	printf("Add 1st element into the stack. \n");
	AddStack(&stack, item);
	PrintStack(&stack);

	item.key = 2;
	printf("Add 2nd element into the stack. \n");
	AddStack(&stack, item);
	PrintStack(&stack);

	item.key = 3;
	printf("Add 3rd element into the stack. \n");
	AddStack(&stack, item);
	PrintStack(&stack);

	item.key = 4;
	printf("Add 4th element into the stack. \n");
	AddStack(&stack, item);
	PrintStack(&stack);

	printf("Delete the top element from the stack. \n");
	item = DeleteStack(&stack);
	printf("Delete %d \n", item.key);

	PrintStack(&stack);

	printf("Destroy the stack. \n");
	DestroyStack(&stack);

	
	return 0;
}
Example #11
0
int main() {
	LinkStack S;
	int result;
	pNode node, topNode;

	//0. InitStack
	InitStack(S);
	if (!S) {
		printf("Init Stack failed!\n");
		return -1;
	}
	PrintStack(S);

	//1. Push
	printf("\n");
	PrintStack(S);
	printf("Push Stack\n");
	node = CreateNode(5);
	if (!node) {
		printf("Create Node failed\n");
		return -1;
	}
	Push(S, node);
	PrintStack(S);
	topNode = Top(S);
	PrintNode(topNode);

	//2. Pop
	printf("\n");
	PrintStack(S);
	if (!StackEmpty(S)) {
		printf("Pop Stack\n");
		Pop(S);
	}
	PrintStack(S);

	//3. Clear
	printf("\n");
	PrintStack(S);
	if (!StackEmpty(S)) {
		printf("Clear Stack\n");
		ClearStack(S);
	}
	PrintStack(S);
}
Example #12
0
//先序打印出从根到叶子结点的路径
void PrePrint(BinaryTree *root,StackNode *S)
{
    if(root)
    {
        ElemType e;
        Push(S,root->data);
        if(root->LChild==NULL && root->RChild==NULL)
        {
            Pop(S,&e);
            printf("\n%c:",e);
            PrintStack(S);
        }
        else
        {
            PrePrint(root->LChild,S);
            PrePrint(root->RChild,S);
            Pop(S,&e);
        }
    }
}
Example #13
0
int main() {
	Sqstack S_1, S_2;
	int i = 0, j = 0;
	char str[MAXSIZE];
	while (gets_s(str) != NULL) {
		Initstack(&S_1);
		Initstack(&S_2);
		for (i = 0; str[i] != NULL; i++) {
			switch (str[i]) {
			case'+': {
				Push(&S_2, str[i]);
			}break;
			case'-': {
				Push(&S_2, str[i]);
			}break;
			case'*': {
				Push(&S_2, str[i]);
			}break; 
			case'/': {
				Push(&S_2, str[i]);
			}break;
			case'(': {
				Push(&S_2, str[i]);
			}break;
			case')': {
				Push(&S_2, str[i]);
			}break;
			default: {
				Push(&S_1, str[i]-48);
			}break;
			}
		}
		PrintStack(&S_1);
	}
	
	

	return OK;
}
Example #14
0
int main(int argc, const char *argv[])
{
	LinkStack *testList = NULL;
	elemType e;
	int i;
	srand(time(0));
	printf("list length is %d\n",StackLength(testList));
	if(InitStack(&testList) == ERROR){
		return -1;
	}
	for(i = 0; i < 10 ; i++){
		Push(testList,i);
	}
	printf("list length is %d\n",StackLength(testList));
	PrintStack(testList);
	Pop(testList,&e);
	printf("pop e is %d ,length is %d \n",e,StackLength(testList));
	ClearStack(&testList);
	printf("list length is %d\n",StackLength(testList));

	printf("scanner: is it matching? ");
	scanner("hello(){}") ? printf("true \n"):printf("false \n");
	return 0;
}
Example #15
0
void *initialize_user_process(void *arg)
{
  //  printf("Enters initalize_user_process\n");
  int i;
  char **filename = (char **)arg;
  int argc = 0;
    
  while (filename[argc]!=NULL)
    {
       printf("This is filename[%i]: %s\n", argc, filename[argc]);
      argc++;
    }
  //    printf("This is argc in init: %i\n", argc);
    
  //Step 19: putting in argc
  //k = WordToMachine(argc);
  //memcpy(main_memory+MemorySize-40+12, &k, 4);
    
  //L3 Step 18: start first process, is this init? 
    init=(PCB *)malloc(sizeof(PCB));
    init->registers = (int *)malloc(NumTotalRegs*sizeof(int));
    for (i=0; i < NumTotalRegs; i++)
    {  
      init->registers[i] = 0;
    }
    init->pid = (int *)0;
    //    printf("This is init's pid: %i\n", (int)init->pid);
    //L3 Step 19: 
    init->waiter_sem = make_kt_sem(0);
    init->waiters = new_dllist();
    init->children = make_jrb();

    //Allocate a new PCB
  PCB *temp=(PCB *)malloc(sizeof(PCB));
  temp->registers = (int *)malloc(NumTotalRegs*sizeof(int));
  temp->user_base = 0;
  //printf("Initial user_base: %i\n", temp->user_base);
  //Changed Step 12: temp->user_limit = MemorySize-2048;
  temp->user_limit = MemorySize/8;
  //printf("Initial user_limt: %i\n", temp->user_limit);
  
  //L3 Step 18: 
  temp->parent = init;
  //L3 Step 19: 
  temp->waiter_sem = make_kt_sem(0);
  temp->waiters = new_dllist();
  //L3 Step 21: make rb tree for children 
  temp->children = make_jrb();
  
  //Changed at Step 12: User_Base = temp->user_base;
  User_Base = memory8();
  User_Limit = temp->user_limit;
  //printf("This is User_Base in initialize: %i\n", User_Base);
  //printf("This is User_Limit in initialize: %i\n", User_Limit);

  //set the regs of the
  //printf("Setting all the registers to 0 in initalize_user_process\n");
  for (i=0; i < NumTotalRegs; i++)
    temp->registers[i] = 0;
  
  //printf("Setting pid in init\n");
  temp->pid = (int *)get_new_pid();
  printf("First Pid: %i and its parent's should be 0 init: %i\n", temp->pid, temp->parent->pid );
  /* set up the program counters and the stack register */
  temp->registers[PCReg] = 0;
  temp->registers[NextPCReg] = 4;

  //insert the first process as init's child; WOW you can use this function!
  Jval tempN = new_jval_v((void*)temp); //can only insert Jvals 
  jrb_insert_int(init->children, (int)temp->pid, tempN); //JRB tree, int ikey, Jval val 
  //JRB ptr;
  //  jrb_traverse(ptr, init->children)
  //{
  //printf("This is child pid %i of init %i\n", ptr->key, (int)init->pid);
  //}
  //perform_execve(job, fn, argv)
  // where job is the new PCB, fn is the name of your initial executable (at this point, mine is a.out),
  //and argv is the argv of this initial job.
  //returns-> 0 success, errno if error
  //PrintStack(temp->registers[StackReg], temp->user_base);
  int errno = perform_execve(temp, filename[0],filename);
  // printf("This is perform_execve: %i\n", errno);
    //returns to initialize_user_process(), it either exits because there was an error, or it puts the new job onto the ready queue and calls kt_exit()
  PrintStack(temp->registers[StackReg], temp->user_base);
  if (errno!=0)
  {
      printf("Perform_execve returned unsucessful\n"); 
      kt_exit();
  }
  //printf("Placing jval into queue\n");
  Jval value = new_jval_v((void *)temp);
  //value.v = temp;
  //printf("This is the value being placed into the readyq in the initalize_user_process: %s\n",value.v );
  dll_append(readyq, value);
  // printf("Program %s loaded\n", kos_argv[0]);
  kt_exit();
}
Example #16
0
PdfContentsGraph::PdfContentsGraph( PdfContentsTokenizer & contentsTokenizer )
    : m_graph()
{
    EPdfContentsType t;
    const char * kwText;
    PdfVariant var;
    bool readToken;

    // Keep a count of the number of tokens read so we can report errors
    // more usefully.
    int tokenNumber = 0;

    // Set up the node stack and initialize the root node
    stack<Vertex> parentage;
    parentage.push( add_vertex(m_graph) );
    m_graph[parentage.top()] = MakeNode(KW_RootNode,KW_RootNode);

    // Arguments to be associated with the next keyword found
    vector<PdfVariant> args;

    while ( ( readToken = contentsTokenizer.ReadNext(t, kwText, var) ) )
    {
        ++tokenNumber;
        if (t == ePdfContentsType_Variant)
        {
            // arguments come before operators, but we want to group them up before
            // their operator.
            args.push_back(var);
        }
        else if (t == ePdfContentsType_Keyword)
        {
            const KWInfo & ki ( findKwByName(kwText) );
            if (ki.kt != KT_Closing)
            {
                // We're going to need a new vertex, so make sure we have one ready.
                Vertex v = add_vertex( m_graph );
                // Switch any waiting arguments into the new node's data.
                m_graph[v].first.GetArgs().swap( args );
                assert(!args.size());

                if (ki.kw == KW_Unknown)
                {
                    // No idea what this keyword is. We have to assume it's an ordinary
                    // one, possibly with arguments, and just push it in as a node at the
                    // current level.
                    assert(!m_graph[v].first.IsDefined());
                    m_graph[v].first.SetKw( string(kwText) );
                    add_edge( parentage.top(), v, m_graph );
                    assert( m_graph[v].first.GetKwId() == ki.kw );
                    assert( m_graph[v].first.GetKwString() == kwText );
                }
                else if (ki.kt == KT_Standalone)
                {
                    // Plain operator, shove it in the newly reserved vertex (which might already contain
                    // arguments) and add an edge from the top to it.
                    assert(ki.kw != KW_Undefined && ki.kw != KW_Unknown && ki.kw != KW_RootNode );
                    assert(!m_graph[v].first.IsDefined());
                    m_graph[v].first.SetKw( ki.kw );
                    add_edge( parentage.top(), v, m_graph );
                    assert( m_graph[v].first.GetKwId() == ki.kw );
                    assert( m_graph[v].first.GetKwString() == kwText );
                }
                else if (ki.kt == KT_Opening)
                {
                    PrintStack(m_graph, parentage, "OS: ");
                    assert(ki.kw != KW_Undefined && ki.kw != KW_Unknown && ki.kw != KW_RootNode );
                    assert(!m_graph[v].first.IsDefined());
                    m_graph[v].first.SetKw( ki.kw );
                    // add an edge from the current top to it
                    add_edge( parentage.top(), v, m_graph );
                    // and push it to the top of the parentage stack
                    parentage.push( v );
                    assert( m_graph[v].first.GetKwId() == ki.kw );
                    assert( m_graph[v].first.GetKwString() == kwText );
                    PrintStack(m_graph, parentage, "OF: ");
                }
                else
                {
                    assert(false);
                }
            }
            else if (ki.kt == KT_Closing)
            {
                // This keyword closes a context. The top of the parentage tree should
                // be a node whose KWInstance is the matching opening keyword. We'll check
                // that, then set the second KWInstance appropriately.
                PrintStack(m_graph, parentage, "CS: ");
                assert(ki.kw != KW_Undefined && ki.kw != KW_Unknown && ki.kw != KW_RootNode );
                // Get a reference to the node data for the current parent
                NodeData & n ( m_graph[parentage.top()] );
                PODOFO_RAISE_LOGIC_IF( n.second.IsDefined(), "Closing already closed group" );
                // Ensure that the opening keyword therein is one that this closing keyword is
                // a valid match for
                PdfContentStreamKeyword expectedCloseKw = n.first.GetKwInfo().kwClose;
                // Ensure there aren't any args to the close kw
                assert(!args.size());
                // and handle the close matching
                if ( ki.kw != expectedCloseKw )
                {
                    // Some PDFs, even Adobe ones, place close operators
                    // in the wrong order. We'll do some lookahead to see
                    // if we can fix things up before we hit a non-close
                    // operator.
                    if ( !closeFixup( m_graph, parentage, contentsTokenizer, ki  ) )
                    {
                        string err = formatMismatchError(m_graph, parentage, tokenNumber, ki.kw, expectedCloseKw);
                        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidContentStream, err.c_str() );
                    }
                }
                else
                {
                    n.second.SetKw( ki.kw );
                    // Our associated operator is now on the top of the
                    // parentage stack. Since its scope has ended, it should
                    // also be popped.
                    parentage.pop();
                }
                PrintStack(m_graph, parentage, "CF: ");
            }
            else
            {
                assert(false);
            }
        }
        else
        {
            assert(false);
        }
    }

    PODOFO_RAISE_LOGIC_IF( args.size(), "Stream ended with unconsumed arguments!" );

    PODOFO_RAISE_LOGIC_IF( parentage.size() != 1, "Stream failed to close all levels" );

}
Example #17
0
static SINT32 _NVRAM_RdWr(UINT32 cmd, UINT16 start, UINT16 length, UINT08 *pBuffer)
{
	UINT32	i, j;
	SINT08	rc = I2C_OK;
	UINT16	tLength, tStartOfs, cacheOfs;
	UINT08	*cacheBuf;
	UINT32  tStartIndex, tLastIndex;
	UINT08	*pBuf       = pBuffer;
	UINT16  tLast       = start + length - 1;

#if		(NVM_DEBUG > 0)
	char	*tStr       = (cmd ? "RD" : "WR");
	NVMDRV_PRINT("%snvm(0x%04x,%4d)", tStr, start, length);
#endif	/* (NVM_DEBUG > 0) */

	typedef struct {
		UINT08	i2cid;
		UINT08	addr;
		UINT08	pgsz;
		UINT08	_rsvd;
	} NVM_CFG_T;

	NVM_CFG_T	nvm_cfg[] = {
		//I2C  slave  Page, _rsvd
		// ID,  addr, Size,
		#if	(MODEL_ID == 0)
		{   1,  0xaa,   64, 0 }, /* 32k EEP on I2c Line#1 in Evaluation   Board */
		#elif	(MODEL_ID == 4)
		{   0,  0xa2,   64, 0 }, /* 32k EEP on I2c Line#0 in D2A Chip     Board */ // 0xaa->0xa2
		{   0,  0xa2,  128, 0 }, /* 64k EEP on I2c Line#0 in D2A Chip     Board */
		{   0,  0xa0,  128, 0 }, /* 64k EEP on I2c Line#0 in D2A FPGA     Board */
		#else
		{   0,  0xaa,   64, 0 }, /* 32k EEP on I2c Line#0 in D2A Chip     Board */
		{   0,  0xa2,  128, 0 }, /* 64k EEP on I2c Line#0 in D2A Chip     Board */
		{   0,  0xa0,  128, 0 }, /* 64k EEP on I2c Line#0 in D2A FPGA     Board */
		#endif
		{0xff,  0x00,    0, 0 }  /* DO NOT DELETE : END Marker */
	};
	NVM_CFG_T	*pNvmCfg;

	if (nvmI2cLine == NULL)
	{
		cacheOfs = 0;
		tLength  = 0;

		pNvmCfg = &nvm_cfg[0];

		// while END Marker
		while ( pNvmCfg->i2cid != 0xff )
		{
			I2CMS_ID	testI2c;
			UINT08		testAddr;

			if      ( pNvmCfg->i2cid == 0 ) testI2c = i2cmsId0;
			else if ( pNvmCfg->i2cid == 1 ) testI2c = i2cmsId1;
			else                            testI2c = i2cmsId2;

			testAddr = pNvmCfg->addr;

			if ((rc = i2cmsMasterRead(testI2c, testAddr,(UINT08 *)&cacheOfs, 2, (UINT08 *)&tLength, 2)) == 2)
			{
				nvram_pgsz = pNvmCfg->pgsz;
				nvmI2cAddr = testAddr;
				nvmI2cLine = testI2c;
				dbgprint("NVRAM] found at %2d:0x%02x : PageSize %3d",
						pNvmCfg->i2cid, pNvmCfg->addr, pNvmCfg->pgsz);
				break;
			}

			// repeat next in nvm_cfg[]
			pNvmCfg++;
		}

		if ( nvmI2cLine == NULL )
		{
			dbgprint("Can not access NVRAM, rc = %d", rc);
			return I2C_ERROR;
		}
	}

	tStartIndex = start / nvram_pgsz;
	tLastIndex  = tLast / nvram_pgsz;

	waitSem(lSMidNvm, WAIT_FOREVER);

	for (i = tStartIndex; i <= tLastIndex; i++, pBuf += tLength)
	{
	    /*  Transfer 시작 주소와 크기 설정.								*/
		/*	처음이 아닌 경우, 시작 주소는 Page Size에 동기화한다.		*/
	    /*	Last Block이 0이 아닌 경우 마지막 LOOP에서만 짜투리를 처리	*/
	    tStartOfs  = ( (i == tStartIndex) ? (start  ) : (   i  * nvram_pgsz) );
	    tLength    = ( (i == tLastIndex ) ? (tLast+1) : ((i+1) * nvram_pgsz) ) - tStartOfs;

#if			(NVM_CACHE > 0)
		cacheBuf = &__nvc[i].nc_page[0];
		cacheOfs = (i * nvram_pgsz);
		if (__nvc[i].nc_valid == 0)
		{
			WaitNvmStable(TRUE);
			if (i2cmsMasterRead(nvmI2cLine,nvmI2cAddr,(UINT08 *)&cacheOfs, 2, cacheBuf, nvram_pgsz)!= I2C_ERROR)
			{
#if		(NVM_DEBUG > 1)
				NVMDRV_PRINT("%snvm(0x%04x,%4d) :: page filled", tStr, tStartOfs, tLength);
#endif	/* (NVM_DEBUG > 1) */
				__nvc[i].nc_valid = TRUE;
			}
		}

		if (__nvc[i].nc_valid)
		{
			cacheBuf += (tStartOfs - cacheOfs);
			if (cmd)
			{
#if		(NVM_DEBUG > 1)
				NVMDRV_PRINT("Rdnvm(0x%04x,%4d) :: read cache hit", tStartOfs, tLength);
#endif	/* (NVM_DEBUG > 1) */
				memcpy(pBuf, cacheBuf, tLength);
				continue;
			}
			else
			{
				if (memcmp(cacheBuf, pBuf, tLength) == 0)
				{
					/*
					 *		!!!! CAUTION !!!!
					 * Dangerous Writing Same Data To Nram
					 */
#if		(NVM_DEBUG > 1)
					NVMDRV_PRINT("WRnvm(0x%04x,%4d) :: Write Cache Hit", tStartOfs, tLength);
#endif	/* (NVM_DEBUG > 1) */
#if		(NVM_TRACE > 0)
					PrintStack();
#endif	/* (NVM_TRACE > 0) */
					continue;
				}
				else
				{
					memcpy(cacheBuf, pBuf, tLength);
					__nvc[i].nc_dirty = TRUE;
				}
			}
		}
#endif   /*	(NVM_CACHE > 0) */

	    for (j = 0; j < MAX_NUM_OF_RETRY; j++)
	    {
#if		(NVM_DEBUG > 1)
			NVMDRV_PRINT("%snvm(0x%04x,%4d) :: page request", tStr, tStartOfs, tLength);
#endif	/* (NVM_DEBUG > 1) */

			/*	Wait until nvram device is stable	*/
			WaitNvmStable(cmd);

			/*	Read/Write the block data to EEPROM	*/
			if (cmd != 0)
				rc = i2cmsMasterRead (nvmI2cLine,nvmI2cAddr,(UINT08 *)&tStartOfs, 2, pBuf, tLength);
			else
				rc = i2cmsMasterWrite(nvmI2cLine,nvmI2cAddr,(UINT08 *)&tStartOfs, 2, pBuf, tLength);

			if (rc != I2C_ERROR)
	            break;
	    }

		if (j == MAX_NUM_OF_RETRY)
	    {
			postSem(lSMidNvm);
			return I2C_ERROR;
		}
	}

	postSem(lSMidNvm);

	return I2C_OK;
}