home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / z39.c < prev    next >
Text File  |  1994-01-23  |  11KB  |  192 lines

  1. /*@z39.c:String Handler:AsciiToFull(), StringEqual(), etc.@*******************/
  2. /*                                                                           */
  3. /*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  4. /*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  5. /*                                                                           */
  6. /*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  7. /*  Basser Department of Computer Science                                    */
  8. /*  The University of Sydney 2006                                            */
  9. /*  AUSTRALIA                                                                */
  10. /*                                                                           */
  11. /*  This program is free software; you can redistribute it and/or modify     */
  12. /*  it under the terms of the GNU General Public License as published by     */
  13. /*  the Free Software Foundation; either version 1, or (at your option)      */
  14. /*  any later version.                                                       */
  15. /*                                                                           */
  16. /*  This program is distributed in the hope that it will be useful,          */
  17. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  18. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  19. /*  GNU General Public License for more details.                             */
  20. /*                                                                           */
  21. /*  You should have received a copy of the GNU General Public License        */
  22. /*  along with this program; if not, write to the Free Software              */
  23. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  24. /*                                                                           */
  25. /*  FILE:         z39.c                                                      */
  26. /*  MODULE:       String Handler                                             */
  27. /*  EXTERNS:      AsciiToFull(), StringEqual(), StringLessEqual(),           */
  28. /*                StringCat(), StringCopy(), StringLength(),                 */
  29. /*                StringFOpen(), StringFPuts(), StringFGets(),               */
  30. /*                StringUnlink(), StringLink(), StringBeginsWith(),          */
  31. /*                StringContains(), StringInt(), StringFiveInt(),            */
  32. /*                StringQuotedWord()                                         */
  33. /*                                                                           */
  34. /*****************************************************************************/
  35. #include "externs"
  36.  
  37.  
  38. /*****************************************************************************/
  39. /*                                                                           */
  40. /*          AsciiToFull(str)          Returns ASCII string as FULL_CHARs.    */
  41. /*  BOOLEAN StringEqual(a, b)         TRUE if strings a and b are equal      */
  42. /*  BOOLEAN StringLessEqual(a, b)     TRUE if string a <= string b           */
  43. /*          StringCat(a, b)           Catenate string b onto end of a        */
  44. /*          StringCopy(a, b)          Overwrite string a with string b       */
  45. /*          StringLength(a)           Length of string a                     */
  46. /*          StringFOpen(str, mode)    Equivalent to fopen(str, mode)         */
  47. /*          StringFPuts(str, fp)      Equivalent to fputs(str, fp)           */
  48. /*          StringFGets(str, n, fp)   Equivalent to fgets(str, n, fp)        */
  49. /*          StringUnlink(a)           Equivalent to unlink(a)                */
  50. /*          StringLink(a, b)          Equivalent to link(a, b)               */
  51. /*                                                                           */
  52. /*  These procedures are defined as macros in file externs.                  */
  53. /*                                                                           */
  54. /*****************************************************************************/
  55.  
  56.  
  57. /*@::StringBeginsWith(), StringContains(), StringInt(), StringFiveInt()@******/
  58. /*                                                                           */
  59. /*  BOOLEAN StringBeginsWith(str, pattern)                                   */
  60. /*                                                                           */
  61. /*  Check whether str begins with pattern.                                   */
  62. /*                                                                           */
  63. /*****************************************************************************/
  64.  
  65. BOOLEAN StringBeginsWith(str, pattern)
  66. FULL_CHAR *str, *pattern;
  67. { FULL_CHAR *sp, *pp;
  68.   sp = str;  pp = pattern;
  69.   while( *sp != '\0' && *pp != '\0' )
  70.   { if( *sp++ != *pp++ )  return FALSE;
  71.   }
  72.   return (*pp == '\0');
  73. } /* end StringBeginsWith */
  74.  
  75.  
  76. /*****************************************************************************/
  77. /*                                                                           */
  78. /*  BOOLEAN StringContains(str, pattern)                                     */
  79. /*                                                                           */
  80. /*  Check whether str contains pattern.                                      */
  81. /*                                                                           */
  82. /*****************************************************************************/
  83.  
  84. BOOLEAN StringContains(str, pattern)
  85. FULL_CHAR *str, *pattern;
  86. { FULL_CHAR *sp;
  87.   for( sp = str;  *sp != '\0';  sp++ )
  88.   { if( StringBeginsWith(sp, pattern) )  return TRUE;
  89.   }
  90.   return FALSE;
  91. } /* end StringContains */
  92.  
  93.  
  94. /*****************************************************************************/
  95. /*                                                                           */
  96. /*  FULL_CHAR *StringInt(i)                                                  */
  97. /*  FULL_CHAR *StringFiveInt(i)                                              */
  98. /*                                                                           */
  99. /*  Returns a string version of integer i.                                   */
  100. /*                                                                           */
  101. /*****************************************************************************/
  102.  
  103. FULL_CHAR *StringInt(i)
  104. int i;
  105. { static FULL_CHAR buff[20];
  106.   sprintf( (char *) buff, "%d", i);
  107.   return buff;
  108. } /* end StringInt */
  109.  
  110. FULL_CHAR *StringFiveInt(i)
  111. int i;
  112. { static FULL_CHAR buff[20];
  113.   sprintf( (char *) buff, "%.5d", i);
  114.   return buff;
  115. } /* end StringInt */
  116.  
  117.  
  118. /*@::StringQuotedWord()@******************************************************/
  119. /*                                                                           */
  120. /*  static char *quoted_string[]                                             */
  121. /*                                                                           */
  122. /*  quoted_string[ch] is a string containing the representation of the       */
  123. /*  8-bit character ch within a quoted string in a Lout source file.         */
  124. /*                                                                           */
  125. /*****************************************************************************/
  126.  
  127. static char *quoted_string[] = {
  128.     "\\000", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
  129.     "\\010", "\\011", "\\012", "\\013", "\\014", "\\015", "\\016", "\\017",
  130.     "\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
  131.     "\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
  132.     " ",     "!",     "\\\"",  "#",     "$",     "%",     "&",     "'",
  133.     "(",     ")",     "*",     "+",     ",",     "-",     ".",     "/",
  134.     "0",     "1",     "2",     "3",     "4",     "5",     "6",     "7",
  135.     "8",     "9",     ":",     ";",     "<",     "=",     ">",     "?",
  136.  
  137.     "@",     "A",     "B",     "C",     "D",     "E",     "F",     "G",
  138.     "H",     "I",     "J",     "K",     "L",     "M",     "N",     "O",
  139.     "P",     "Q",     "R",     "S",     "T",     "U",     "V",     "W",
  140.     "X",     "Y",     "Z",     "[",     "\\\\",  "]",     "^",     "_",
  141.     "`",     "a",     "b",     "c",     "d",     "e",     "f",     "g",
  142.     "h",     "i",     "j",     "k",     "l",     "m",     "n",     "o",
  143.     "p",     "q",     "r",     "s",     "t",     "u",     "v",     "w",
  144.     "x",     "y",     "z",     "{",     "|",     "}",     "~",     "\\177",
  145.  
  146.     "\\200", "\\201", "\\202", "\\203", "\\204", "\\205", "\\206", "\\207",
  147.     "\\210", "\\211", "\\212", "\\213", "\\214", "\\215", "\\216", "\\217",
  148.     "\\220", "\\221", "\\222", "\\223", "\\224", "\\225", "\\226", "\\227",
  149.     "\\230", "\\231", "\\232", "\\233", "\\234", "\\235", "\\236", "\\237",
  150.     "\\240", "\\241", "\\242", "\\243", "\\244", "\\245", "\\246", "\\247",
  151.     "\\250", "\\251", "\\252", "\\253", "\\254", "\\255", "\\256", "\\257",
  152.     "\\260", "\\261", "\\262", "\\263", "\\264", "\\265", "\\266", "\\267",
  153.     "\\270", "\\271", "\\272", "\\273", "\\274", "\\275", "\\276", "\\277",
  154.  
  155.     "\\300", "\\301", "\\302", "\\303", "\\304", "\\305", "\\306", "\\307",
  156.     "\\310", "\\311", "\\312", "\\313", "\\314", "\\315", "\\316", "\\317",
  157.     "\\320", "\\321", "\\322", "\\323", "\\324", "\\325", "\\326", "\\327",
  158.     "\\330", "\\331", "\\332", "\\333", "\\334", "\\335", "\\336", "\\337",
  159.     "\\340", "\\341", "\\342", "\\343", "\\344", "\\345", "\\346", "\\347",
  160.     "\\350", "\\351", "\\352", "\\353", "\\354", "\\355", "\\356", "\\357",
  161.     "\\360", "\\361", "\\362", "\\363", "\\364", "\\365", "\\366", "\\367",
  162.     "\\370", "\\371", "\\372", "\\373", "\\374", "\\375", "\\376", "\\377",
  163. };
  164.  
  165.  
  166. /*****************************************************************************/
  167. /*                                                                           */
  168. /*  FULL_CHAR *StringQuotedWord(x)                                           */
  169. /*                                                                           */
  170. /*  Returns the string in QWORD x in the form it would need to take if it    */
  171. /*  was a quoted word in a Lout source file.  Note that the result is        */
  172. /*  returned in a static variable so it needs to be copied before a          */
  173. /*  subsequent call to StringQuotedWord is made.                             */
  174. /*                                                                           */
  175. /*****************************************************************************/
  176.  
  177. FULL_CHAR *StringQuotedWord(x)
  178. OBJECT x;
  179. { FULL_CHAR *p, *q, *r;
  180.   static FULL_CHAR buff[MAX_LINE];
  181.   assert( type(x) == QWORD, "StringQuotedWord: type(x) != QWORD!" );
  182.   q = buff;
  183.   *q++ = CH_QUOTE;
  184.   for( p = string(x);  *p != '\0';  p++ )
  185.   { 
  186.     for( r = (FULL_CHAR *) quoted_string[*p];  *r != '\0';  *q++ = *r++ );
  187.   }
  188.   *q++ = CH_QUOTE;
  189.   *q++ = '\0';
  190.   return buff;
  191. } /* StringQuotedWord */
  192.