- Timestamp:
- Feb 11, 2009, 12:20:22 PM (16 years ago)
- Branches:
- master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 7980fb2
- Parents:
- 823671c
- git-author:
- Nelson Elhage <nelhage@mit.edu> (02/08/09 16:31:14)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (02/11/09 12:20:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
text.c
rf8d9df1 rf34dd65 6 6 7 7 static const char fileIdent[] = "$Id$"; 8 9 /* start with line aline (where the first line is 1) and print 'lines'10 * lines11 */12 int owl_text_truncate_lines(char *out, char *in, int aline, int lines)13 {14 char *ptr1, *ptr2;15 int i;16 17 strcpy(out, "");18 19 if (aline==0) aline=1; /* really illegal use */20 21 /* find the starting line */22 ptr1=in;23 if (aline!=1) {24 for (i=0; i<aline-1; i++) {25 ptr1=strchr(ptr1, '\n');26 if (!ptr1) return(-1);27 ptr1++;28 }29 }30 /* ptr1 now holds the starting point */31 32 /* copy in the next 'lines' lines */33 if (lines<1) return(-1);34 35 for (i=0; i<lines; i++) {36 ptr2=strchr(ptr1, '\n');37 if (!ptr2) {38 strcat(out, ptr1);39 return(-1);40 }41 strncat(out, ptr1, ptr2-ptr1+1);42 ptr1=ptr2+1;43 }44 return(0);45 }46 47 48 /* the first column is column 0. The message is expected to end in a49 * new line for now */50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)51 {52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;53 int col, cnt, padding;54 55 tmpbuff=owl_malloc(strlen(in)+20);56 57 strcpy(tmpbuff, "");58 last=in+strlen(in)-1;59 ptr_s=in;60 while (ptr_s<last) {61 ptr_e=strchr(ptr_s, '\n');62 if (!ptr_e) {63 /* but this shouldn't happen if we end in a \n */64 break;65 }66 67 if (ptr_e==ptr_s) {68 strcat(tmpbuff, "\n");69 ptr_s++;70 continue;71 }72 73 col = 0;74 cnt = 0;75 padding = 0;76 ptr_c = ptr_s;77 while(col < bcol && ptr_c < ptr_e) {78 gunichar c = g_utf8_get_char(ptr_c);79 if (col + mk_wcwidth(c) > bcol) break;80 col += mk_wcwidth(c);81 ptr_c = g_utf8_next_char(ptr_c);82 if (col >= acol) {83 if (cnt == 0) {84 ptr_s = ptr_c;85 padding = col - acol;86 }87 ++cnt;88 }89 }90 if (cnt) {91 while(padding-- > 0) {92 strcat(tmpbuff, " ");93 }94 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);95 }96 strcat(tmpbuff, "\n");97 ptr_s = ptr_e + 1;98 #if 099 /* we need to check that we won't run over here */100 if ( (ptr_e-ptr_s) < (bcol-acol) ) {101 len=ptr_e-(ptr_s+acol);102 } else {103 len=bcol-acol;104 }105 if ((ptr_s+len)>=last) {106 len-=last-(ptr_s+len);107 }108 109 strncat(tmpbuff, ptr_s+acol, len);110 strcat(tmpbuff, "\n");111 112 ptr_s=ptr_e+1;113 #endif114 }115 strcpy(out, tmpbuff);116 owl_free(tmpbuff);117 }118 119 8 120 9 void owl_text_indent(char *out, char *in, int n)
Note: See TracChangeset
for help on using the changeset viewer.