home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / texchk / part1 / ctools.h < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  10.6 KB  |  355 lines

  1. /* -*- Mode: C; Package: (CTOOLS C) -*- */
  2.  
  3. #ifndef Bool
  4. #define Bool int
  5. #endif
  6.  
  7. #ifndef T
  8. #define T 1
  9. #endif
  10.  
  11. #ifndef F
  12. #define F 0
  13. #endif
  14.  
  15. #ifndef MAXINT
  16. #define MAXINT 2147483647
  17. #define MAXINTSTR "2147483647"
  18. #endif
  19.  
  20. #ifndef MAXPATHLEN
  21. #define MAXPATHLEN 80
  22. #endif
  23.  
  24. extern char *emalloc();
  25.  
  26.   /* int space; */
  27.   /* space must be greater than 0 */
  28.   /* Causes executution to halt with a 'Fatal error' message if memory */
  29.   /* cannot be allocated, otherwise returns pointer to malloc-ed space */
  30.  
  31. extern char *anewstr();
  32.  
  33.   /* char *astring; */
  34.   /* emalloc's space and copies astring into that space.  Returns pointer */
  35.   /* to new string. */
  36.  
  37.  
  38. extern int copy();
  39.  
  40.   /* char *dest, *src; int n; */
  41.   /* copies exactly n bytes. */
  42.   /* return value undefined.  Use only as procedure. */
  43.  
  44. extern int fill();
  45.  
  46.   /* char *addr, ch; int n; */
  47.   /* copies ch into n consecutive bytes. */
  48.   /* return value undefined.  Use only as procedure. */
  49.  
  50. extern int to_upper_if_lower();
  51.  
  52.   /* char ch;  Returns possibly upper-cased value. */
  53.  
  54. extern int to_lower_if_upper();
  55.  
  56.   /* char ch;  Returns possibly lower-cased value. */
  57.  
  58. extern int buffconcat();
  59.  
  60.   /* char *buffer, *s1, *s2; */
  61.   /* s1 and s2 must be null terminated.  Buffer must be at least */
  62.   /* strlen(s1) + strlen(s2) + 1 characters long.  Buffer is null */
  63.   /* terminated upon completion. */
  64.  
  65.   /* return value undefined.  Use only as procedure. */
  66.  
  67. extern int nbuffconcat();
  68.  
  69.   /* char *buffer; int n; char *s1,*s2,*s3,*s4,*s5,*s6; */
  70.   /* all the strings must be null terminated.  Buffer must be big enough */
  71.   /* to hold the null terminated result.  0 < n < 7 . 
  72.   /* returns -1 if n is out of range, otherwise 0 */
  73.  
  74. extern int slcompare();
  75.  
  76.   /* char *s1; int l1; char *s2; int l2 */
  77.   /* does not stop if it encounters a null character. */
  78.   /* returns 0 if equal, -1 if not equal */
  79.  
  80. extern int slge_compare();
  81.  
  82.   /* char *s1; int l1; char *s2; int l2 */
  83.   /* does not stop if it encounters a null character. */
  84.   /* returns 0 if equal, -1 if s1 < s2, 1 if s1 > s2 */
  85.  
  86. extern int nocase_compare();
  87.  
  88.   /* char *s1; int l1; char *s2; int l2 */
  89.   /* does not stop if it encounters a null character. */
  90.   /* returns 0 if equal, -1 if s1 < s2, 1 if s1 > s2  case independently. */
  91.  
  92. extern char * strfind();
  93.  
  94.   /* char *s1; char *s2; int fast; */
  95.   /* finds s2 as a substring of s1.  s1 and s2 are null terminated. */
  96.   /* returns 0 if not found, otherwise pointer into s1 to first matching */
  97.   /* character. */
  98.  
  99.   /* WARNING:  will access off the end of s1 in the interest of efficiency */
  100.   /* if 'fast' is non-zero. */
  101.  
  102. extern char * strncfind();
  103.  
  104.   /* char *s1; char *s2; int fast; */
  105.   /* finds s2 as a substring of s1 case independently.  s1 and s2 are */
  106.   /* null terminated. */
  107.   /* returns 0 if not found, otherwise pointer into s1 to first matching */
  108.   /* character. */
  109.  
  110.   /* WARNING:  will access off the end of s1 in the interest of efficiency */
  111.   /* if 'fast' is non-zero. */
  112.  
  113. extern char * strsearch();
  114.  
  115.   /* char *s1; int l1; char *s2; int l2 */
  116.   /* finds s2 as a substring of s1.  Does not stop if it encounters a null. */
  117.   /* returns pointer into s1, otherwise (char *) 0 if search fails */
  118.   /* case dependent */
  119.  
  120. extern char * strncsearch();
  121.  
  122.   /* char *s1; int l1; char *s2; int l2 */
  123.   /* finds s2 as a substring of s1. */
  124.   /* returns pointer into s1, otherwise (char *) 0 if search fails */
  125.   /* case independent */
  126.  
  127. extern int remove_excess_blanks();
  128.  
  129.   /* char *newstring, *oldstring; */
  130.   /* newstring must be long enough to hold the result, which may be as */
  131.   /* long as oldstring.  oldstring must be null terminated. */
  132.   /* an excess blank is any blank before the first non-blank character, */
  133.   /* any blank after the last non-blank character, and any blank immediately */
  134.   /* following a blank. */
  135.   /* returns length of newstring */
  136.  
  137. extern int yes_or_no_check();
  138.  
  139.   /* char *astring; */
  140.   /* returns 1 for yes, 0 for no, -1 for neither. */
  141.   /* astring must be one of "YES", "Y", "NO", "N" in any capitalization. */
  142.  
  143.  
  144. /* These routines return T if every char satisfies a certain condition. */
  145. /* These returns all returns T if given a null string. */
  146.  
  147. extern Bool all_digits();
  148. extern Bool all_whitespace();
  149. extern Bool all_uppercase();
  150. extern Bool all_lowercase();
  151. extern Bool all_alphabetic();
  152. extern Bool all_alphanumeric();
  153. extern Bool all_ascii();
  154.  
  155.  
  156. extern int str_to_pos_int();
  157.  
  158.   /* char *astring; int low,high; */
  159.   /* low must be >= 0. */
  160.   /* returns -1 if *astring is not composed of digits. */
  161.   /* returns -2 if the integer is out of range. */
  162.   /* despite its name, 0 can be returned as a legitimate value. */
  163.   /* treats all digit strings as decimal. */
  164.  
  165.  
  166. extern int sreverse();
  167.  
  168.   /* char *buffer; char *astring; */
  169.   /* puts the characters of astring in reverse order into buffer. */
  170.   /* buffer must be at least as long as astring + 1. */
  171.   /* buffer is null terminated when done. */
  172.   /* No return value.  Use only as procedure. */
  173.  
  174. extern char *ip_sreverse();
  175.  
  176.   /* char *astring; */
  177.   /* Returns astring with its characters reversed. */
  178.   /* reversal is done in place. */
  179.  
  180.  
  181.  
  182. #define PATH_MAXPATHLEN 256
  183.  
  184. char *temp_path();
  185.  
  186. /*
  187.   char *dir; char *filename;
  188.  
  189.   Returns a pointer to a character string containing the string
  190.   <dir>/<filename>.  The pointer points to a buffer which will may get
  191.   overwritten if any functions in this package are subsequently called.
  192.   0 is returned if the pathname would exceed PATH_MAXPATHLEN-1 chars.
  193. */
  194.  
  195.  
  196. char *perm_path();
  197.  
  198. /*
  199.   char *dir; char *filename;
  200.  
  201.   Same as temp_path, except the pathname string is malloc'ed and is thus
  202.   permanent unless specifically freed by the user.  Further, no limit
  203.   on the size of the path is made.
  204. */
  205.  
  206.  
  207. char *make_path();
  208.  
  209. /*
  210.   char *dir; char *filename; char *extension; Bool perm;
  211.  
  212.   Creates <dir>/<filename><extension> .  The string returned is permanent
  213.   or not depending on 'perm'.  If perm is not true, 0 will be returned if
  214.   the resulting path exceeds PATH_MAXPATHLEN-1 chars.
  215. */
  216.  
  217.  
  218. char *make_path_numeric_extension();
  219.  
  220. /*
  221.   char *dir; char *filename; int extension; Bool perm;
  222.  
  223.   Same as make_path except that extension is first converted into a
  224.   string using sprintf.
  225. */
  226.  
  227.  
  228. char *just_filename();
  229.  
  230. /*  
  231.   char *path; Bool new; Bool perm;
  232.  
  233.   Given a path of the form /<x>/<y>/<z> returns <z>.  If new is not set
  234.   then a pointer into the original input string is returned.  If new is
  235.   set a copy is returned, either permanent or not depending on perm.
  236. */
  237.  
  238.  
  239. #define ANSWER_NO 0
  240. #define ANSWER_YES 1
  241. #define ANSWER_HELP 2
  242. #define ANSWER_QUIT 3
  243. #define ANSWER_EOF 4
  244.  
  245. #define AT_EOF -1
  246. #define TOO_MANY_CHARS -2
  247. #define IOERROR -3
  248. #define TOO_MANY_LINES -4
  249. #define LINE_TOO_LONG -5
  250.  
  251. extern read_yes_or_no ();
  252.  
  253.   /* FILE *iport, *oport; char *prompt; char *helpstring; char *quitstring; */
  254.  
  255.   /* prints prompt, then reads from iport until is gets 'Y', 'N', 'YES' or */
  256.   /* 'NO' (case independently).  If helpstring and/or quitstring are not */
  257.   /* "" or (char *) 0 then if the user types in one of those ANSWER_HELP */
  258.   /* or ANSWER_QUIT are returned, otherwise ANSWER_NO or ANSWER_YES are */
  259.   /* eventually returned. */
  260.  
  261.  
  262. extern int getline ();
  263.  
  264.   /* FILE *iport; char *buffer; int buflen; */
  265.  
  266.   /* reads a line into buffer.  Does not put the '\n' into buffer. */
  267.   /* Returns AT_EOF if at end of file when called.  If it encounters */
  268.   /* end of file after reading at least one character, the eof is treated */
  269.   /* as if it were a newline.   Returns TOO_MANY_CHARS if more than */
  270.   /* buflen - 1 characters are read before encountering a newline. */        
  271.   /* In this case exactly buflen - 1 characters are read. */
  272.   /* The last character read is always follwed by a '\0'. */
  273.   /* if successful getline returns the number of characters read exclusive */
  274.   /* of a terminating newline or eof. */
  275.  
  276.  
  277. extern int getlines();
  278.  
  279.   /* FILE *fp; int n; char ***ptr_lines; char *linebuf; int maxlinelen; */
  280.   /* See documentation for getfile below */
  281.   /* If called, 'n' must have a value 0. */
  282.  
  283. extern int getfile();
  284.  
  285.   /* char *filename; char ***ptr_lines; char *linebuf; int maxlinelen; */
  286.  
  287.   /* read in a file as an array of character strings */
  288.   /* 'maxlinelen+1' is the maximum length a line of the file is allowed */
  289.   /* to be.  'linebuf' must be at least 'maxlinelen+1' characters long. */
  290.   /* Returns the number of lines in the file (and therefore the number */
  291.   /* of entries in *ptr_lines) if successful.  Returns IOERROR if it */
  292.   /* could not open the file to read from. Returns TOO_MANY_CHARS if */
  293.   /* it encounters a line longer than 'maxlinelen' characters.  
  294.  
  295.   /* Space for each line is malloc'ed as it is read in and the text for */
  296.   /* the jth line is stored in (*ptr_lines)[j] */
  297.  
  298.   /* Only works for fairly small files as it recurses its way through the */
  299.   /* file and does a lot of malloc-ing.  Use read_file_into_buffer or */
  300.   /* ngetfile for large files. */
  301.  
  302. extern int ngetlines();
  303.  
  304.  /* FILE *fp; int n; char ***ptr_lines; char *linebuf; int maxlinelen; */
  305.  /* Same as getlines, except at most 'n' lines will be read.  Returns */
  306.  /* TOO_MANY_LINES if more than 'n' lines are present. */
  307.  
  308. extern int ngetfile();
  309.  
  310.  /* int n; char *filename; char ***ptr_lines; char *linebuf; int maxlinelen; */
  311.  /* See ngetlines above. */
  312.  
  313. extern int read_file_into_buffer();
  314.  
  315.   /* char *filename; 
  316.      char ***ptr_lines;
  317.      int maxlines;
  318.      char *buffer;
  319.      int buflen;
  320.      char *linebuffer;
  321.      int linebuflen;
  322.   */
  323.  
  324.   /* *ptr_lines should be an array of character string pointers maxlines */
  325.   /* big.  buffer should be an array of characters buflen long.  The routine */
  326.   /* reads lines using getline and stores them into buffer, terminating each */
  327.   /* with a null.  A pointer to the nth line read is stored in *ptr_lines[n] */
  328.   /* Returns IOERROR if it cannot open the file for reading, TOO_MANY_LINES */
  329.   /* if more than maxlines were read in, TOO_MANY_CHARS if buffer is */
  330.   /* filled before end of file is reached, and LINE_TOO_LONG is any line is */
  331.   /* longer than linebuflen.  Returns number of lines read in if successful. */
  332.  
  333. extern char *efopen();  
  334.  
  335.   /* char *filename; char *mode */
  336.  
  337.   /* Actually returns a (FILE *), so one must cast the return value to this */
  338.   /* type.  It doesn't return a (FILE *) explicitly because then to include */
  339.   /* this file one would have to include <stdio.h> explicitly before it. */
  340.   /* The routine simply calls fopen with the same arguments, but prints a */
  341.   /* reasonable error message and calls exit if the call to fopen fails. */
  342.  
  343.  
  344. Bool check_string();
  345.  
  346.   /* char *str; long minlen; long maxlen; */
  347.  
  348.   /* Returns T if str is not 0 and has a length between minlen and maxlen */
  349.   /* inclusived, otherwise returns F. */
  350.  
  351.  
  352. #ifndef check_int
  353. #define check_int(i,minval,maxval) ((i) >= (minval) && (i) <= (maxval))
  354. #endif
  355.