Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

text_operations.c

Go to the documentation of this file.
00001 /*
00002  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
00003  *      For copying and distribution information, see the file
00004  *      "mit-copyright.h".
00005  *
00006  *      Modified for jwgc by Daniel Henninger.
00007  */
00008 
00009 #include "mit-copyright.h"
00010 
00011 #include "text_operations.h"
00012 #include "char_stack.h"
00013 
00014 string 
00015 lany(text_ptr, str)
00016         string *text_ptr;
00017         string str;
00018 {
00019         string result, whats_left;
00020         char *p = *text_ptr;
00021 
00022         while (*p && *str)
00023                 p++, str++;
00024 
00025         result = string_CreateFromData(*text_ptr, p - *text_ptr);
00026         whats_left = string_Copy(p);
00027         free(*text_ptr);
00028         *text_ptr = whats_left;
00029 
00030         return (result);
00031 }
00032 
00033 string 
00034 lbreak(text_ptr, set)
00035         string *text_ptr;
00036         character_class set;
00037 {
00038         string result, whats_left;
00039         char *p = *text_ptr;
00040 
00041         while (*p && !set[(int) *p])
00042                 p++;
00043 
00044         result = string_CreateFromData(*text_ptr, p - *text_ptr);
00045         whats_left = string_Copy(p);
00046         free(*text_ptr);
00047         *text_ptr = whats_left;
00048 
00049         return (result);
00050 }
00051 
00052 string 
00053 lspan(text_ptr, set)
00054         string *text_ptr;
00055         character_class set;
00056 {
00057         string result, whats_left;
00058         char *p = *text_ptr;
00059 
00060         while (*p && set[(int) *p])
00061                 p++;
00062 
00063         result = string_CreateFromData(*text_ptr, p - *text_ptr);
00064         whats_left = string_Copy(p);
00065         free(*text_ptr);
00066         *text_ptr = whats_left;
00067 
00068         return (result);
00069 }
00070 
00071 string 
00072 rany(text_ptr, str)
00073         string *text_ptr;
00074         string str;
00075 {
00076         string result, whats_left;
00077         string text = *text_ptr;
00078         char *p = text + strlen(text);
00079 
00080         while (text < p && *str)
00081                 p--, str++;
00082 
00083         result = string_Copy(p);
00084         whats_left = string_CreateFromData(text, p - text);
00085         free(text);
00086         *text_ptr = whats_left;
00087 
00088         return (result);
00089 }
00090 
00091 string 
00092 rbreak(text_ptr, set)
00093         string *text_ptr;
00094         character_class set;
00095 {
00096         string result, whats_left;
00097         string text = *text_ptr;
00098         char *p = text + strlen(text);
00099 
00100         while (text < p && !set[(int) p[-1]])
00101                 p--;
00102 
00103         result = string_Copy(p);
00104         whats_left = string_CreateFromData(text, p - text);
00105         free(text);
00106         *text_ptr = whats_left;
00107 
00108         return (result);
00109 }
00110 
00111 string 
00112 rspan(text_ptr, set)
00113         string *text_ptr;
00114         character_class set;
00115 {
00116         string result, whats_left;
00117         string text = *text_ptr;
00118         char *p = text + strlen(text);
00119 
00120         while (text < p && set[(int) p[-1]])
00121                 p--;
00122 
00123         result = string_Copy(p);
00124         whats_left = string_CreateFromData(text, p - text);
00125         free(text);
00126         *text_ptr = whats_left;
00127 
00128         return (result);
00129 }
00130 
00131 string 
00132 paragraph(text_ptr, width)
00133         string *text_ptr;
00134         int width;
00135 {
00136         string result;
00137         char *p, *back, *s, *t;
00138 
00139         result = string_Copy(*text_ptr);
00140 
00141         p = result;
00142         s = result;
00143         t = result;
00144         while (1) {
00145                 if (strlen(p) > width) {
00146                         p = p + width;
00147                         t = p;
00148                         back = p;
00149                         while (*back != ' ' && *back != '\n' &&
00150                                *back != '\t' && back != s) {
00151                                 back--;
00152                         }
00153                         if (back != s && *back != '\n') {
00154                                 *back = '\n';
00155                         }
00156                         else {
00157                                 back = t;
00158                                 while (*back != ' ' && *back != '\n' &&
00159                                         *back != '\t' && *back != '\0') {
00160                                         back++;
00161                                 }
00162                                 if (*back != '\0' && *back != '\n') {
00163                                         *back = '\n';
00164                                 }
00165                                 if (*back == '\0') {
00166                                         break;
00167                                 } 
00168                         }
00169                         p = back + 1;
00170                         if (*p == '\0') {
00171                                 break;
00172                         } 
00173                 }
00174                 else {
00175                         break;
00176                 }
00177         }
00178 
00179         return (result);
00180 }


Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo
Source Perspective by Fisheye