home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libfont / src / wfMisc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.2 KB  |  169 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.  *
  20.  * All function that are of general use in libfont/ are implemented here.
  21.  *
  22.  * dp Suresh <dp@netscape.com>
  23.  */
  24.  
  25.  
  26. // XXX Must make this a class of its own.
  27.  
  28. //
  29. // Rounds an integer to the next higher integer that is divisible by roundto
  30. //
  31. #define WF_ROUND_INT(a, roundto) (((int)((a)/(roundto)) + 1) * (roundto))
  32.  
  33. //
  34. // MergeSizes
  35. //
  36. // Merge size lists together. A size list is an array of size values
  37. // (non-negative) terminated by a negative value.
  38. // It takes a newSizes list and merges this into the oldSizes list allocating
  39. // memory for the oldSizes list in the process.
  40. //
  41. extern void MergeSizes(jdouble * &oldSizes, int &oldLenMax, jdouble *newSizes);
  42.  
  43. //
  44. // CopyString
  45. //
  46. // Make a copy of the input C-String and return a new C++ allocated
  47. // C-String.
  48. //
  49. extern char *CopyString(const char *str);
  50.  
  51. //
  52. // EscapeString
  53. //
  54. // Returns a newly allocated string that Escapes characters from escapeThese
  55. // in the input str.
  56. // For eg.
  57. //    input string    : string-to*be-escaped\n
  58. //    return        : string\-to\*be\-escaped\\n
  59. //
  60. // WARNING: Caller must delete the return string.
  61. //
  62. extern char *EscapeString(const char *str, const char *escapeThese);
  63.  
  64. //
  65. // ScanToken
  66. //  Scans a token delimited by 'stopChars' from 'str' and copies it out
  67. //    into 'buf'
  68. //    By default this compresses multiple spaces in the token to a single space.
  69. //    If 'noSpacesOnOutput' is set, all spaces, leading/trailing/intermediate
  70. //    spaces are stripped.
  71. //
  72. //    Returns a pointer to the character after the token in 'str'
  73. //
  74. extern const char *wf_scanToken(const char *str, char *buf, int len,
  75.                                 char *stopChars, int noSpacesOnOutput);
  76.  
  77. //
  78. // wf_scanVariableAndValue
  79. // Modifies buf such that variable and value point to the the LHS and RHS of
  80. // a buf of the format " variable = value "
  81. // Leading and trailing spaces for both variable and value are trimmed.
  82. //
  83. extern int wf_scanVariableAndValue(char *buf, int buflen,
  84.                                    char *&variable, char *&value);
  85.  
  86.  
  87. /*
  88.  * wf_StringEndsWith
  89.  *
  90.  * returns nonzero if string 's' ends with string 'endstr'
  91.  * else returns zero
  92.  */
  93. extern int wf_stringEndsWith(const char *s, const char *endstr);
  94.  
  95.  
  96. //
  97. // wf_skipSpaces
  98. // Returns a pointer to the first non-space character in 'str'
  99. //
  100. extern const char *wf_skipSpaces(const char *str);
  101.  
  102.  
  103. //
  104. // wf_trimSpaces
  105. // Trims initial and trailing spaces from the input string.
  106. //
  107. char *wf_trimSpaces(char *inputString);
  108.  
  109. //
  110. // Returns
  111. // 0    : if both strings are the same on a case insensitive compare
  112. // -1    : if any of the string were NULL
  113. // 1    : if string 'two' is a case insensitive substring of string 'one'
  114. // 2    : if string 'one' is a case insensitive substring of string 'two'
  115. // 3    : if case insensitive compare failed
  116. //
  117. extern int wf_strcasecmp(const char *one, const char *two);
  118.  
  119. //
  120. // Returns
  121. // 0    : if both strings are the same on a case insensitive compare of atmost
  122. //            n bytes.
  123. // -1    : if any of the string were NULL
  124. extern int wf_strncasecmp(const char *one, const char *two, int n);
  125.  
  126. //
  127. // returns a pointer to the extension part of the input string
  128. extern const char *wf_getExtension(const char *fullname);
  129.  
  130. // =====================================================================
  131. // Webfonts related miscellaneous routines
  132. // =====================================================================
  133.  
  134. // Release an array of fmis. Will call nffmi::release() on each fmi.
  135. // 
  136. // WARNING: WILL NOT RELEASE THE MEMORY FOR THE fmis array.
  137. extern int wf_releaseFmis(struct nffmi **fmis);
  138.  
  139. //
  140. // Adds a string to an existing string. If more memory is required, it extends
  141. // the srcstring (realloc) to fit the new concatenated string.
  142. //
  143. #define WF_STRING_ALLOCATION_STEP 64
  144. extern int wf_addToString(char **str, int *len, int *maxlen, const char *s);
  145.  
  146.  
  147. // ------------------------------------------------------------
  148. //                         FILE operations
  149. // ------------------------------------------------------------
  150.  
  151. // All these return
  152. // 0   : False
  153. // +ve : True
  154. // -1  : Error
  155. extern int wf_isFileDirectory(const char *name);
  156. extern int wf_isFileReadable(const char *filename);
  157.  
  158. //
  159. // expandFileName:
  160. //
  161. // expands the following in the filename
  162. // beginning ~    : HOME
  163. //
  164. // Returns the no: of expansions done. If none was done, returns 0.
  165. // Returns -ve if there was no space to do the expansion.
  166. //
  167. extern int wf_expandFilename(char *filename, int maxlen);
  168.  
  169.