home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / richmail / richtoatk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-07  |  2.9 KB  |  98 lines

  1. /*
  2. Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3.  
  4. Permission to use, copy, modify, and distribute this material 
  5. for any purpose and without fee is hereby granted, provided 
  6. that the above copyright notice and this permission notice 
  7. appear in all copies, and that the name of Bellcore not be 
  8. used in advertising or publicity pertaining to this 
  9. material without the specific, prior written permission 
  10. of an authorized representative of Bellcore.  BELLCORE 
  11. MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  12. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  13. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  14. */
  15. #include <stdio.h>
  16. #include <ctype.h>
  17. #include "richlex.h"
  18.  
  19. char *translate(t)
  20. char *t;
  21. {
  22.     if (!strcmp(t, "fixed")) return("typewriter");
  23.     if (!strcmp(t, "excerpt")) return("quotation");
  24.     /* Really ought to handle ISO-10646 and ISO-8859-X somehow */
  25.     return(t);
  26. }
  27.  
  28. main() {
  29.     RCHAR c;
  30.     int i, JustDidNewline = 0;
  31.     char tok[MAX_TOKEN_SIZE + 1],*token;
  32.  
  33.     fputs("\\begindata{text, 42}\n\\template{messages}\n", stdout);
  34.     while((c = richtextlex(stdin,tok + 1)) != (RCHAR)EOF) {
  35.     if (c == RICHTEXT_COMMAND || c == RICHTEXT_NEG_COMMAND) {
  36.         if (c == RICHTEXT_NEG_COMMAND) {
  37.         tok[0] = '/';
  38.         token = tok;
  39.         } else
  40.         token = tok + 1;
  41.             if (!strcmp(token, "lt")) {
  42.                 putc('<', stdout);
  43.                 JustDidNewline = 0;
  44.             } else if (!strcmp(token, "nl")) {
  45.                 fputs(JustDidNewline ? "\n" : "\n\n", stdout);
  46.                 JustDidNewline = 1;
  47.             } else if (!strcmp(token, "/paragraph")) {
  48.                 fputs(JustDidNewline ? "\n\n" : "\n\n\n", stdout);
  49.                 JustDidNewline = 1;
  50.             } else if (!strcmp(token, "comment")) {
  51.             int tempc;
  52.                 while (strcmp(token, "/comment")) {
  53.                     while ((tempc = getc(stdin)) != '<') ;
  54.                     for (i=0; (tempc = getc(stdin)) != '>'; ++i) {
  55.                         token[i] = isupper(tempc) ? tolower(tempc) : tempc;
  56.                     }
  57.                     token[i] = '\0';
  58.                 }
  59.             } else if (!ignoretoken(token)) {
  60.                 if (token[0] == '/') {
  61.                     putc('}', stdout);
  62.                 } else {
  63.                     fprintf(stdout, "\\%s{", translate(token));
  64.                     JustDidNewline = 0;
  65.                 }
  66.             }
  67.         } else if (c == '\n') {
  68.             putc(' ', stdout);
  69.             JustDidNewline = 0;
  70.         } else {
  71.             putc((int)c, stdout);
  72.             JustDidNewline = 0;
  73.         }
  74.     }
  75.     fputs("\n \n\\enddata{text, 42}\n", stdout);
  76. }
  77.  
  78. ignoretoken(t)
  79. char *t;
  80. {
  81.     if (*t == '/') ++t;
  82.     if (!strcmp(t, "us-ascii")) return(1);
  83.     if (!strcmp(t, "paragraph")) return(1); /* handled otherwise */
  84.     if (!strcmp(t, "no-op")) return(1);
  85.     return(0);
  86. }
  87.  
  88. controlputc(c)
  89. int c;
  90. {
  91. }
  92.  
  93. controloutput(s, immediate)
  94. char *s;
  95. int immediate;
  96. {
  97. }
  98.