|
| |||||||||||||
#include "mit-copyright.h"#include "char_stack.h"#include "string_dictionary.h"#include "formatter.h"#include "text_operations.h"Go to the source code of this file.
Defines | |
| #define | const |
Functions | |
| int | env_length () |
| string | verbatim (string str, int bracketsonly) |
| string | protect (string str) |
| void | free_desc (desctype *desc) |
| desctype * | disp_get_cmds (char *str, int *pstr, int *pnl) |
|
|
Definition at line 17 of file formatter.c. |
|
||||||||||||||||
|
Definition at line 434 of file formatter.c. References char_stack, char_stack_create, char_stack_empty, char_stack_pop, char_stack_push, char_stack_top, _desctype::code, desctype, env_length(), _desctype::len, _desctype::next, and _desctype::str. 00437 {
00438 desctype *desc, *here;
00439 int len;
00440 char_stack terminators = char_stack_create();
00441 char terminator;
00442 int nstr = 0, nnl = 0;
00443 char *curstr;
00444
00445 desc = (desctype *) malloc(sizeof(desctype));
00446 here = desc;
00447 curstr = str;
00448 terminator = '\0';
00449
00450 while (*curstr) {
00451 if (*curstr == '\n') {
00452 here->code = DT_NL;
00453 curstr++;
00454 nnl++;
00455 }
00456 else if (*curstr == terminator) { /* if this is the end of
00457 * an env */
00458 here->code = DT_END;
00459 terminator = char_stack_top(terminators);
00460 char_stack_pop(terminators);
00461 curstr++;
00462 }
00463 else if ((len = text_length(curstr, terminator))) { /* if there is a text
00464 * block here */
00465 here->code = DT_STR;
00466 here->str = curstr;
00467 here->len = len;
00468 curstr += len;
00469 nstr++;
00470 }
00471 else if (*curstr == '@') { /* if this is the beginning
00472 * of an env */
00473 len = env_length(curstr + 1);
00474 here->code = DT_ENV;
00475 here->str = curstr + 1;
00476 here->len = len;
00477 char_stack_push(terminators, terminator);
00478 terminator = otherside(*(curstr + 1 + len));
00479 curstr += (len + 2); /* jump over @, env name, and
00480 * opener */
00481 }
00482
00483 here->next = (desctype *) malloc(sizeof(desctype));
00484 here = here->next;
00485 }
00486
00487 while (!char_stack_empty(terminators)) {
00488 here->code = DT_END;
00489 terminator = char_stack_top(terminators);
00490 char_stack_pop(terminators);
00491 here->next = (desctype *) malloc(sizeof(desctype));
00492 here = here->next;
00493 }
00494 here->code = DT_EOF;
00495 *pstr = nstr;
00496 *pnl = nnl;
00497
00498 return (desc);
00499 }
|
|
|
Referenced by disp_get_cmds(), and protect(). |
|
|
Definition at line 363 of file formatter.c. References desctype, and _desctype::next. 00365 {
00366 desctype *next_desc;
00367
00368 while (desc->code != DT_EOF) {
00369 next_desc = desc->next;
00370 free(desc);
00371 desc = next_desc;
00372 }
00373 free(desc);
00374 }
|
|
|
Definition at line 283 of file formatter.c. References char_stack, char_stack_create, char_stack_empty, char_stack_pop, char_stack_push, char_stack_top, env_length(), string, string_Concat2, string_Copy, string_CreateFromData, and verbatim(). 00285 {
00286 string temp, temp2, temp3;
00287 int len, templen;
00288 char_stack chs;
00289 char tos;
00290
00291 temp = string_Copy("");
00292 templen = 1;
00293 chs = char_stack_create();
00294
00295 while (*str) {
00296 tos = (char_stack_empty(chs) ? 0 : char_stack_top(chs));
00297
00298 if (*str == tos) {
00299 /* if the character is the next terminator */
00300
00301 temp = (char *) realloc(temp, ++templen);
00302 temp[templen - 2] = *str++;
00303 char_stack_pop(chs);
00304 temp[templen - 1] = '\0';
00305 }
00306 else if ((len = pure_text_length(str, tos))) {
00307 if (tos) {
00308 /*
00309 * if the block is text in an environment,
00310 * just copy it
00311 */
00312
00313 temp2 = string_CreateFromData(str, len);
00314 str += len;
00315 temp = string_Concat2(temp, temp2);
00316 templen += len;
00317 free(temp2);
00318 }
00319 else {
00320 /*
00321 * if the block is top level text, verbatim
00322 * brackets only (not @'s) and add text to
00323 * temp
00324 */
00325
00326 temp2 = string_CreateFromData(str, len);
00327 str += len;
00328 temp3 = verbatim(temp2, 1);
00329 temp = string_Concat2(temp, temp3);
00330 templen += strlen(temp3);
00331 free(temp3);
00332 }
00333 }
00334 else {
00335 /*
00336 * if the block is an environment, copy it, push
00337 * delimiter
00338 */
00339
00340 len = env_length(str + 1);
00341 char_stack_push(chs, otherside(str[len + 1]));
00342 len += 2;
00343 temp2 = string_CreateFromData(str, len);
00344 str += len;
00345 temp = string_Concat2(temp, temp2);
00346 templen += len;
00347 free(temp2);
00348 }
00349 }
00350 /* all blocks have been copied. */
00351
00352 while (!char_stack_empty(chs)) {
00353 temp = (char *) realloc(temp, ++templen);
00354 temp[templen - 2] = char_stack_top(chs);
00355 char_stack_pop(chs);
00356 }
00357 temp[templen - 1] = '\0';
00358
00359 return (temp);
00360 }
|
|
||||||||||||
|
Definition at line 201 of file formatter.c. References lany(), lbreak(), string_Concat2, and string_Copy. 00204 {
00205 char *temp, *temp2;
00206 int bracketnum, len;
00207
00208 if (strlen(str) == pure_text_length(str, 0)) {
00209 /* No environments, so consider the fast-and-easy methods */
00210
00211 if (not_contains(str, allbracket_set)) {
00212 temp = string_Copy(str);
00213 free(str);
00214 return (temp);
00215 }
00216
00217 if (not_contains(str, abracket_set)) {
00218 temp = (char *) malloc((len = strlen(str)) + 4);
00219 temp[0] = '@';
00220 temp[1] = '<';
00221 (void) memcpy(temp + 2, str, len);
00222 temp[len + 2] = '>';
00223 temp[len + 3] = '\0';
00224 free(str);
00225 return (temp);
00226 }
00227 if (not_contains(str, sbracket_set)) {
00228 temp = (char *) malloc((len = strlen(str)) + 4);
00229 temp[0] = '@';
00230 temp[1] = '[';
00231 (void) memcpy(temp + 2, str, len);
00232 temp[len + 2] = ']';
00233 temp[len + 3] = '\0';
00234 free(str);
00235 return (temp);
00236 }
00237 if (not_contains(str, cbracket_set)) {
00238 temp = (char *) malloc((len = strlen(str)) + 4);
00239 temp[0] = '@';
00240 temp[1] = '{';
00241 (void) memcpy(temp + 2, str, len);
00242 temp[len + 2] = '}';
00243 temp[len + 3] = '\0';
00244 free(str);
00245 return (temp);
00246 }
00247 if (not_contains(str, paren_set)) {
00248 temp = (char *) malloc((len = strlen(str)) + 4);
00249 temp[0] = '@';
00250 temp[1] = '(';
00251 (void) memcpy(temp + 2, str, len);
00252 temp[len + 2] = ')';
00253 temp[len + 3] = '\0';
00254 free(str);
00255 return (temp);
00256 }
00257 }
00258
00259 temp = lbreak(&str, bracketsonly ? allbracket_set : allmaskable_set);
00260 while (*str) {
00261 bracketnum = (int) (strchr(brackets, str[0]) - brackets);
00262 temp = string_Concat2(temp, openbracket[bracketnum]);
00263 temp = string_Concat2(temp, temp2 = lany(&str, " "));
00264 free(temp2);
00265 temp = string_Concat2(temp, closebracket[bracketnum]);
00266 temp = string_Concat2(temp, temp2 = lbreak(&str, bracketsonly ?
00267 allbracket_set : allmaskable_set));
00268 free(temp2);
00269 }
00270 free(str); /* str is "" at this point, anyway */
00271
00272 return (temp);
00273 }
|
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |