home *** CD-ROM | disk | FTP | other *** search
- #include <scl1.h>
- #include <scl1keys.h>
- #include <string.h>
- #include <malloc.h>
-
- /* This file shows the use of the LinkedList to create and manage a
- linked list */
-
- main()
- {
- LLData ld;
- char buffer[20];
- int i,Mess;
- unsigned int key=0;
-
- InitVideo();
- LinkedList(LL_INIT,&ld); /* init */
-
- /* add 20 elements ti list */
-
- for(i=0;i < 20;++i)
- {
- sprintf(buffer,"linea #%i",i);
- ld.DataSize=strlen(buffer)+1; /* elements can have different sizes */
- ld.Data=buffer; /* point to our data */
- LinkedList(LL_ADD,&ld);
- }
-
- LinkedList(LL_FIRST,&ld); /* move to first position */
-
- printf("%s size:%i\r\n",ld.Data,ld.DataSize);
-
- Mess=LL_OK;
-
- do
- {
- switch(key) /* translate keystroke to message */
- {
- case UP:
- Mess=LL_PREVIOUS;
- break;
- case DOWN:
- Mess=LL_NEXT;
- break;
- case HOME:
- Mess=LL_FIRST;
- break;
- case END:
- Mess=LL_LAST;
- break;
- case INS:
-
- /* let user insert new element */
-
- memset(buffer,0,sizeof(buffer));
- if(DialogBox(7,"Text:",0x70,10,CC_ANY,buffer)!=-1)
- {
-
- /*
- ld.Data points to new data
- ld.DataSize equals size in bytes */
-
- ld.Data=buffer;
- ld.DataSize=strlen(buffer)+1;
- Mess=LinkedList(LL_INSERT,&ld);
- }
- Mess=0;
- break;
- case DEL:
- Mess=LL_DELETE;
- break;
- case ENTER:
-
- /* let user modify data */
-
- strcpy(buffer,ld.Data);
- if(DialogBox(7,"Text:",0x70,10,CC_ANY,buffer)!=-1)
- {
- ld.Data=buffer;
- ld.DataSize=strlen(buffer)+1;
-
- /* replace previous data */
-
- Mess=LinkedList(LL_REPLACE,&ld);
- Mess=0;
- }
- break;
- case F2:
-
- /* let user modify position */
-
- if(DialogBox(7,"Position:",0x70,10,CC_DIGIT,buffer)!=-1)
- Mess=LinkedList(LL_SET_POSITION,&ld,atoi(buffer));
- break;
- default:
- Mess=0;
- break;
- }
-
- /* send message to LinkedList */
-
- if(Mess)
- {
- Mess=LinkedList(Mess,&ld);
-
- /* display data at current position,
- ld.Data points to our data
- ld.DataSize equals size in byes */
-
- if(Mess!=LL_EMPTY_LIST)
- printf("%s size:%i\r\n",ld.Data,ld.DataSize);
- else
- printf("Empty list\r\n"); /* no data */
- }
- }while((key=GetKey()) != ESC);
- LinkedList(LL_DELETE_ALL,&ld);
- }
-