Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <string.h>
  5. #include "texbuffer.h"
  6.  
  7. typedef struct textbuffer *TB;
  8. typedef struct node *link;
  9.  
  10. struct textbuffer{
  11. link start;
  12. link end;
  13. int numberoflines;
  14. };
  15.  
  16. struct lineImp{
  17. char *text[];
  18. link next;
  19. link prev;
  20. };
  21.  
  22. /* Allocate a new textbuffer whose contents is initialised with the text given
  23. * in the array.
  24. */
  25. link newNode(char text[]){
  26. struct lineImp * newLine = malloc(sizeof(text[]));
  27. newLine->next = NULL;
  28. newLine->prev = NULL;
  29. return newLine;
  30. }
  31. TB newTB (char text[]){
  32. link curr;
  33. int i = 0;//array counter
  34. TB *newBuffer = malloc(sizeof(struct textbuffer));
  35. assert(newBuffer !=NULL);
  36. newBuffer->start = newLine;
  37. newBuffer->end = newLine;
  38.  
  39. char *token;
  40. char *previousToken;
  41. /* get the first token */
  42. previosToken = strtok(text[], '\n');
  43. int lineLength = 0;
  44. /* walk through other tokens */
  45. while( token != NULL )
  46. {
  47. struct lineImp * newLine = malloc(sizeof((token-previousToken)+1));
  48. if(newBuffer->start != NULL){
  49. newBuffer->start = newLine
  50. newLine->next = NULL;
  51. newline->prev = newBuffer->start;
  52. } else{
  53. while(curr->next !=NULL){
  54. curr = curr->next;
  55. }
  56. curr->next = newLine;
  57. newLine->next = NULL;
  58. }
  59. previousToken = token;
  60. token = strtok(NULL, s);
  61. }
  62. /* while(text[i] != '\0'){
  63. temp = text[i];
  64. if(text[i] == '\n'){
  65. newNode(text[i]-temp + 1);
  66. }
  67. i++;
  68. }
  69. */
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement