Advertisement
shiftdot515

cnotes.h

Jun 14th, 2018
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 33.15 KB | None | 0 0
  1. #if NOTFORINCLUSION
  2. #include <stdio.h>
  3.  
  4. /*
  5.  * streams stdin, stdout, stderr are open at program start
  6.  */
  7.  
  8. FILE * fopen(const char *filename, const char * mode);
  9.  
  10. /* opens filename returning file pointer or NULL
  11.  * mode = "r"  open text file for reading
  12.  *      = "w"  create text file for writing, overwrite existing
  13.  *      = "a"  append
  14.  *      = "r+" open text for reading and writing ( update )
  15.  *      = "w+" create text for update, overwrite existing
  16.  *      = "a+" open text for update, writing at end.
  17.  *
  18.  *      = "rb"
  19.  *      = "r+b" etc, indicates a binary file.  
  20.  *
  21.  * Update mode reading and writing the same file, but fflush or seek must be
  22.  * called in between.  Filenames are limited to FILENAME_MAX character.
  23.  * Only FOPEN_MAX files may be opened at once.
  24.  */
  25.  
  26. FILE * freopen(const char * filename, const char * mode, FILE * stream);
  27.  
  28. /* reassociates a stream  */
  29.  
  30. int fflush(FILE *stream);
  31.  
  32. /* Causes unwritten data to be written , returns EOF for a write error, or zero
  33.  * fflush(NULL) flushes all output streams.
  34.  */
  35.  
  36. int fclose( FILE * stream );
  37. /* flushes output and discards waiting,
  38.  * It returns EOF if any errors occurred,  and zero otherwise.
  39.  */
  40.  
  41. int remove( const char * filename);
  42.  
  43. /* returns non-zero if the attempt fails. */
  44.  
  45. int rename( const char *oldname, const char * newname );
  46.  
  47. /* returns non-zero if the attempt fails. */
  48.  
  49. FILE * tmpfile(void);
  50.  
  51. /* creates a file of mode "wb+" that will removed automatically when closed
  52.  * or when the program terminates normally.
  53.  */
  54.  
  55. char * tmpname(char s[L_tmpname]);
  56.  
  57. /* creates a strings that is not the name of an existing file, can create
  58.  * at most TMP_MAX different names
  59.  */
  60.  
  61. int setvbuf( FILE * stream, char * buf, int mode, size_t size);
  62.  
  63. /* must be called after fopen, before any other operation
  64.  * mode of _IOFBF causes full buffering,  _IOLBF line buffering of text files
  65.  * and _IONBF no buffering.   If buf is NULL a buffer with be allocated
  66.  * retuns non-zero for any error.
  67.  */
  68.  
  69. void setbuf ( FILE * stream, char * buf );
  70.  
  71. /* if buf is NULL, buffering is turned off for the stream. Otherwise, is
  72.  * setvbuf(stream, buf, _IOFBF, BUFSIZ)
  73.  */
  74.  
  75. int fprintf( FILE * stream, const char * format, ... );
  76.  
  77. /* Flags:
  78.  * %-      left adjustment
  79.  * %+      numbers will always be printed with a sign
  80.  * %       if no sign, a space will be prefixed
  81.  * %0      leading zeros
  82.  * %#      alternate output. o first digit will be zero.  For x or X
  83.  *          0x or 0X will be prefixed for a non-zero result.  For e, E, f,
  84.  *          g, and G, will always have a decimal point, for g and G trailing
  85.  *          zeroes will not be removed.
  86.  * %NN     printed at least this wide, and if wider if necessary
  87.  *          padding with space or 0
  88.  * %NN.PP  Precision, maxnumber of characters to be printed from a string
  89.  *          number of digits after decimal point for e, E, or f conversions,
  90.  *          number of significant digits for g or G conversion,
  91.  *          minimum number of digits to be printed for an integer, 0 padded
  92.  *
  93.  * width or precision maybe *, which is taken from next arg, which must be int
  94.  *
  95.  * Argument Type Conversions:
  96.  * %d      int; signed decimal
  97.  * %i      int; signed decimal
  98.  * %o      unsigned int; unsigned octal
  99.  * %x      unsigned int; unsigned hexadecimal, using abcdef
  100.  * %X      unsigned int; unsigned hexadecimal, using ABCDEF
  101.  * %u      unsigned int; unsigned decimal notation
  102.  * %c      int; single character after conversion to unsigned char
  103.  * %s      string
  104.  * %f      double; decimal notation of  mmm.ddd d=precision default is 6
  105.  * %e      double; decimal notation of m.dddde+xx
  106.  * %E      double; decimal notation of m.ddddE+xx
  107.  * %g      double; either %f or %e if less than e-4, or >= precision
  108.  * %G      double; either %f or %e if less than e-4, or >= precision
  109.  * %p      void *; print as pointer
  110.  * %n      int *; number of characters written so far by, into argument
  111.  * %%      prints a %
  112.  *
  113.  * %hd     short; signed decimal
  114.  * %hi     short; signed decimal
  115.  * %ho     unsigned short; unsigned octal
  116.  * %hx     unsigned short; unsigned hexadecimal
  117.  * %hX     unsigned short; unsigned hexadecimal with ABCDEF
  118.  * %hu     unsigned short; unsigned decimal
  119.  *
  120.  * %ld     long; signed decimal  
  121.  * %li     long; signed decimal
  122.  * %lo     unsigned long; unsigned octal
  123.  * %lx     unsigned long; unsigned hexadecimal
  124.  * %lX     unsigned long; unsigned hexadecimal with ABCDEF
  125.  * %lu     unsigned long; unsigned decimal
  126.  *
  127.  * %Lf     long double; mmm.ddd
  128.  * %Le     long double; exponential
  129.  * %Lg     long double; see %g
  130.  * %LG     long double; see %G
  131.  
  132.  * returns number of characters written or negative if error
  133.  */
  134.  
  135. int printf( const char * format, ...);
  136. /* same as fprintf(stdout, ... ); */
  137.  
  138. int sprintf( char * s, const * format, ... );
  139. /* output is written to s, terminated with '\0' , return does not include '\0'
  140.  */
  141.  
  142. int vprintf( const char * format, va_list arg );
  143. int vfprintf( FILE * stream, const char * format, va_list arg );
  144. int vsprintf( char * s, const char * format, va_list arg);
  145.  
  146. /* similiar to printf, etc, except variable argument list, see stdarg.h */
  147.  
  148.  
  149. int fscanf( FILE * stream, const char * format, ... );
  150.  
  151.  
  152. /* returns EOF on end of file, or error, or otherwise returns number of
  153.  * conversions done.
  154.  *
  155.  * %d    decimal integer; int *
  156.  * %i    integer; int *  ( leading 0 as octal, and 0X, 0x as hex )
  157.  * %o    octal integer;  unsigned int * ( leading 0 optional )
  158.  * %u    unsigned decimal integer;  unsigned int *
  159.  * %x    hex integer; unsigned int *; ( leading 0x optional )
  160.  * %c    characters; char *; No '\0' is added. Skip over whitespace surpressed
  161.  * %s    string; char *;
  162.  * %e    floating point; float *
  163.  * %f    floating point; float *
  164.  * %g    floating point; float *
  165.  *
  166.  * %[...]  match longest input of set of chars in brackets
  167.  * %[^...] match longest input of set of chars not in brackets
  168.  *
  169.  * %NNNN maximum width
  170.  * %h, %l, %L width of the target type
  171.  * %*    supress assignment
  172.  *
  173.  * format string, blanks or tabs which are NOT ignored, chars that must match
  174.  * next non whitespace
  175.  *  
  176.  */
  177.  
  178. int scanf(const char * format, ...);  /* same as fscanf(stdin ...) */
  179. int sscanf(const char *s, const * format ...); /* chars taken from string s */
  180.  
  181.  
  182. int fgetc(FILE * stream );
  183.  
  184. /* returns the next character of stream converted to int, or EOF */
  185.  
  186. char * fgets( char *s, int n, FILE *stream);
  187.  
  188. /* reads at most n-1 characters into the array s, stopping after newline,
  189.  * which is included.  s is null terminated.
  190.  */
  191.  
  192. int fputc( int c, FILE * stream );
  193. /* writes c converted to unsigned char, it returns the character written,
  194.  * or EOF
  195.  */
  196.  
  197.  
  198. int fputs(const char *s, FILE * stream);
  199. /* returns EOF on error, nonnegative on success */
  200.  
  201. int getc(FILE *stream);  /* macro , same as fgetc */
  202.  
  203. int getchar(void); /* same as getc(stdin) */
  204.  
  205. char * gets(char * s);
  206.  
  207. /* reads the next input line into s, which is null terminated,
  208.  * newline is trimmed.
  209.  */
  210.  
  211. int putc(int c, FILE *stream);   /* macro form of fputc */
  212.  
  213. int puts(const char *s);
  214. /* writes s and newline to stdout.  returns non-negative on success, or EOF
  215.  * on error.
  216.  */
  217.  
  218. int ungetc(int c, FILE * stream);
  219. /* push c, back into the stream, where it will be returned on the next read
  220.  * EOF may not be pushed back, only 1 char per stream guaranteed, can't push
  221.  * EOF, returns EOF on error, or c.
  222.  */
  223.  
  224. size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream);
  225. /* reads into the array ptr at most nobj of size. Returns the number of
  226.  * objects read; this may be less than requested.  feof and ferror must be
  227.  * used to determine status.
  228.  */
  229.  
  230.  
  231.  
  232. size_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *stream);
  233. /* writes from the array ptr, nobj objects of size size on stream.
  234.  * It returns the number of objects written, which is less than nobj on error.
  235.  */
  236.  
  237.  
  238.  
  239. int fseek(FILE *stream, long offset, int origin);
  240. /* sets the file position for stream; a subsequent read or write will
  241.  * access data at the new position. fseek returns non-zero on error.
  242.  * For a binary file, the position is set to offset characters from origin,
  243.  * which may be SEEK_SET (beginning), SEEK_CUR (current position),
  244.  * or SEEK_END (end of file).  For a text stream, offset must be zero,
  245.  * or a value returned by ftell (inwhich case origin must be SEEK_SET).
  246.  */
  247.  
  248. long ftell(FILE *stream);
  249. /* ftell returns the current file position for stream, or -1 on error. */
  250.  
  251. void rewind(FILE *stream);
  252. /* rewind(fp) is equivalent to fseek(fp, 0L, SEEK_SET); clearerr(fp). */
  253.  
  254.  
  255. int fgetpos(FILE *stream, fpos_t *ptr);
  256. /* fgetpos records the current position in stream in *ptr, for subsequent use
  257.  * by fsetpos. The type fpos_t is suitable for recording such values.
  258.  * fgetpos returns non-zero on error.
  259.  */
  260.  
  261. int fsetpos(FILE *stream, const fpos_t *ptr);
  262. /* fsetpos positions stream at the position recorded by fgetpos in *ptr.
  263.  * returns non-zero on error.
  264.  */
  265.  
  266. void clearerr(FILE *stream);
  267. /* clears the end of file and error indicators for stream. */
  268.  
  269. int feof(FILE *stream);
  270. /* feof returns non-zero if the end of file indicator for stream is set. */
  271.  
  272. int ferror(FILE *stream);
  273. /* ferror returns non-zero if the error indicator for stream is set. */
  274.  
  275.  
  276. void perror(const char *s);
  277. /* perror(s) prints s and an implementation-defined error message
  278.  * corresponding to the integer in errno, as if by
  279.  * fprintf(stderr, "%s: %s\n", s, "error message");
  280.  */
  281.  
  282.  
  283. #include <errno.h>
  284.  
  285. /* integer expression errno contains an error number that gives further
  286.  * information about the most recent error.
  287.  * EDOM set when an argument is outside the domain of function
  288.  * ERANGE set when result cannot be represented by a double.
  289.  * then returns either 0 or HUGE_VAL ( appropriatel signed ).y
  290.  */
  291.  
  292.  
  293. #include <ctype.h>
  294.  
  295. /* c is either EOF or an unsigned char */
  296.  
  297. isalnum(c)  isalpha(c) or isdigit(c) is true
  298. isprint(c)  printing character including space
  299. isspace(c)  space, formfeed, newline, carriage return, tab,vertical tab
  300. isgraph(c)  printing except space
  301. ispunct(c)  printing character except space or letter or digit
  302. isalpha(c)  isupper(c) or islower(c) is true
  303. isupper(c)  upper-case letter
  304. islower(c)  lower-case letter
  305. iscntrl(c)  control character
  306. isdigit(c)  decimal digit
  307. isxdigit(c) hexadecimal digit
  308.  
  309. /* return is non-zero if true, or zero if false */
  310.  
  311. /* in 7-bit ASCII  printing chars are 0x20 to 0x7E ( ' ' to '~' )
  312.  * Control chars are 0 to 0x1F and 7F
  313.  */
  314.  
  315.  
  316. int tolower(c) ;  /* converts c to lowercase if uppercase, or returns c */
  317. int toupper(c) ;  /* converts c to uppercase if lowercase, or returns c */
  318.  
  319.  
  320. #include <string.h>
  321.  
  322. char * strcpy(char * s,const char * ct);
  323. /* copy string ct to string s, including '\0'; return s. */
  324.  
  325. char * strncpy(char *s,const char *ct, size_t n);
  326. /* copy at most n characters of string ct to s; return s.
  327.  * Pad with '\0''s if ct has fewer than n characters.
  328.  */
  329.    
  330. char * strcat(char * s,const char * ct);
  331. /* concatenate string ct to end of string s; return s. */
  332.                        
  333. char * strncat(char *s,const char * ct,size_t n);
  334. /* concatenate at most n characters of string ct to string s,
  335.  *terminate s with '\0'; return s.
  336.  */
  337. int strcmp(const char * cs, const char * ct);
  338. /* compare string cs to string ct, return <0 if cs<ct, 0 if cs==ct,
  339.  *or >0 if cs>ct.
  340.  */
  341.  
  342. int strncmp(const char * cs,const char * ct,size_t n);
  343. /* compare at most n characters of string cs to string ct; return <0 if cs<ct,
  344.  * if cs==ct, or >0 if cs>ct.
  345.  */
  346.  
  347. char *strchr(const char *cs, int c);
  348. /* return pointer to first occurrence of c in cs or NULL if not present.
  349.  */
  350.  
  351. char *strrchr(const char *cs, int c);
  352. /* return pointer to last occurrence of c in cs or NULL if not present.
  353.  */
  354.  
  355. size_t strspn(const char *cs, const char * ct);
  356. /* return length of prefix of cs consisting of characters in ct. */
  357.  
  358. size_t strcspn(const char *cs, const char * ct);
  359. /* return length of prefix of cs consisting of characters not in ct. */
  360.  
  361. char *strpbrk(const char * cs, const char *ct);
  362. /* return pointer to first occurrence in string cs of any character string ct,
  363.  * or NULL if not present.
  364.  */
  365.  
  366. char * strstr(const char * cs,const char *ct);
  367. /* return pointer to first occurrence of string ct in cs,
  368.  * or NULL if not present.
  369.  */
  370.  
  371. size_t strlen(const char * cs);
  372. /*return length of cs. */
  373.  
  374. char * strerror(size_t n);
  375. /* return pointer to implementation-defined string corresponding to error n. */
  376.  
  377. char * strtok(char *s, const char * ct);
  378. /* A sequence of calls of strtok(s,ct) splits s into tokens, each delimited
  379.  * by a character from ct. The first call in a sequence has a non-NULL s,
  380.  * it finds the first token in s consisting of characters not in ct; it
  381.  * terminates that by overwriting the next character of s with '\0' and
  382.  * returns a pointer to the token. Each subsequent call, indicated by a NULL
  383.  * value of s, returns the next such token, searching from just past the end
  384.  * of the previous one. strtok returns NULL when no further token is found.
  385.  * The string ct may be different on each call.
  386.  */
  387.  
  388.  
  389. void * memcpy(void * s, const void * ct, size_t n);
  390. /* copy n characters from ct to s, and return s */
  391.  
  392. void * memmove(void * s, const void * ct, size_t n);
  393. /* same as memcpy except that it works even if the objects overlap
  394.  * -- the only function in the lib that does
  395.  */
  396.  
  397. int memcmp(const void * cs, const void * ct, size_t n);
  398. /* compare the first n characters of cs with cs; return as with strcmp */
  399.  
  400. void * memchr(const void * cs, int c, size_t n);
  401. /* return pointer to first occurance of character c in cs, or NULL if not
  402.  * present among the first n chracters.
  403.  */
  404.  
  405. void * memset(void * s, int c, size_t n);
  406. /* place character c into the first n characters of s return s; */
  407.  
  408.  
  409. #include <math.h>
  410. /* Angles for trigonometric functions are expressed radians. */
  411.  
  412. double sin (double x);  /* sine of x */
  413. double cos(double x);   /* cosine of x */
  414. double tan(double x);   /* tangent of x */
  415. double asin(double x);  /* arcsin(x) in range [-pi/2,pi/2], x in [-1,1] */
  416. double acos(double x);          /* cos-1(x) in range [0,pi], x in [-1,1] */
  417. double atan(double x);  /* arctan(x) in range [-pi/2,pi/2] */
  418. double atan2(double y, double x); /* arctan(y/x) in range [-pi,pi] */
  419. double sinh(double x);  /* hyperbolic sine of x */
  420. double cosh(double x);  /* hyperbolic cosine of x */
  421. double tanh(double x);   /* hyperbolic tangent of x */
  422. double exp(double x);    /* exponential function ex */
  423. double log(double x);    /* natural logarithm ln(x), x>0. */
  424. double log10(double x);         /* base 10 logarithm log10(x), x>0 */
  425. double pow(double  x, double y);   /* x to the y  */
  426. /* A domain error occurs if x=0 and y<= or if x<0 and y is not an integer */
  427.  
  428. double sqrt(double x);  /* sqare root of x, x>=0 */
  429. double ceil(double x);  /* smallest integer not less than x, as a double. */
  430. double floor(double x); /* largest integer not greater than x, as a double. */
  431. double fabs(double x);  /* absolute value |x| */
  432. double ldexp(double x,int n);  /*  x*(2^n) , x times 2 to the nth */
  433. double frexp(double x, int *exp);
  434. /* splits x into a normalized fraction in the interval [1/2,1) which is
  435.  * returned, and a power of 2, which is stored in *exp. If x is zero,
  436.  *both parts of the result are zero. */
  437.  
  438. double modf(double x, double *ip);
  439. /* splits x into integral and fractional parts, each with the same sign as x.
  440.  * It stores the integral part in *ip, and returns the fractional part.
  441.  */
  442.  
  443. double fmod(double x, double y);
  444. /* floating-point remainder of x/y,   with the same sign as x.
  445.  * If y is zero, the result is implementation-defined.
  446.  */
  447.                                  
  448.  
  449. #include <stdlib.h>
  450.  
  451. double atof(const char *s);
  452. /* atof converts s to double; it is equivalent to strtod(s, (char**)NULL) */
  453.  
  454. int atoi(const char *s);
  455. /* converts s to int; it is equivalent to (int)strtol(s, (char**)NULL, 10) */
  456.  
  457. long atol(const char *s);
  458. /* converts s to long; it is equivalent to strtol(s, (char**)NULL, 10) */
  459.  
  460. double strtod(const char *s, char **endp);
  461. /* strtod converts s to double, ignoring leading white space, it stores a
  462.  * pointer to any unconverted characters in *endp unless endp is NULL.
  463.  * On overflow, returns HUGE_VAL is returned with the proper sign.
  464.  * On undeflow, returns zero.  In either case errno is set to ERANGE.
  465.  */
  466.  
  467. long strtol(const char *s, char **endp, int base);
  468. /* strtol converts s to long, ignoring leading white space; it stores a
  469.  * pointer  to any unconverted characters in *endp unless endp is NULL.  base
  470.  * is between 2 and 36, conversion is done assuming that the input is  written
  471.  * in that base.  If base is zero, the base is 8, 10, or 16; leading 0 implies
  472.  * octal and leading 0x or 0X hexadecimal.  Letters in either case represent
  473.  * digits from 10 to base-1; a leading 0x or 0X is permitted in base 16. If
  474.  * the answer would overflow, LONG_MAX or LONG_MIN is returned, depending on
  475.  * the sign of the result, and errno is set to ERANGE.
  476.  */
  477.  
  478. unsigned long strtoul(const char *s, char **endp, int base);
  479. /* strtoul is the same as strtol except that the result is unsigned long and
  480.  * the error value is ULONG_MAX.
  481.  */
  482.  
  483.  
  484. int rand(void);
  485. /* rand returns a pseudo-random integer in the range 0 to  RAND_MAX, which is
  486.  * at least 32767.
  487.  */
  488.  
  489. void srand(unsigned int seed);
  490. /* srand uses seed as the seed for a new sequence of pseudo-random numbers.
  491.  * The initial seed is 1.
  492.  */
  493.  
  494. void *calloc(size_t num, size_t size);
  495. /* calloc returns a pointer to space for an array of num  objects, each of
  496.  * size size, or NULL if the request cannot  be satisfied. The space is
  497.  * initialized to zero bytes.
  498.  */
  499.  
  500.  
  501. void *malloc(size_t size);
  502. /* malloc returns a pointer to space for an object of size size, or NULL if
  503.  * the request cannot be satisfied. The space is uninitialized.
  504.  */
  505.  
  506.  
  507. void *realloc(void *p, size_t size);
  508. /* realloc changes the size of the object pointed to by p to size. The
  509.  * contents will be unchanged up to the minimum of the old  and new sizes.
  510.  * If the new size is larger, the new space is uninitialized.  realloc returns
  511.  * a pointer to the new space, or NULL if  the request cannot be satisfied,
  512.  * in which case *p is unchanged.
  513.  */
  514.  
  515.                                              
  516. void free(void *p);
  517. /* free deallocates the space pointed to by p; it does nothing if p is NULL.
  518.  * p must be a pointer to space previously allocated by calloc, malloc,
  519.  * or realloc.
  520.  */
  521.  
  522.  
  523. void abort(void);
  524. /* abort causes the program to terminate abnormally,
  525.  * as if by  raise(SIGABRT).
  526.  */
  527.  
  528.  
  529. void exit(int status);
  530. /* exit causes normal program termination. atexit functions are called in
  531.  * reverse order of registration, open files are flushed, open streams are
  532.  * closed, and control is returned to the environment. How status is returned
  533.  * to the environment is implementation-dependent, but zero is taken as
  534.  * successful termination. The values EXIT_SUCCESS and EXIT_FAILURE may
  535.  * also be used.
  536.  */
  537.  
  538.  
  539. int atexit( void (*fcn)(void) );
  540. /* atexit registers the function fcn to be called when the program  terminates
  541.  * normally; it returns non-zero if the registration cannot be made.
  542.  */
  543.  
  544.  
  545. int system(const char *s);
  546. /* system passes the string s to the environment for  execution. If s is NULL,
  547.  * system returns non-zero if  there is a command processor. If s is not NULL,
  548.  * the return value is implementation-dependent.
  549.  */
  550.  
  551.  
  552. char *getenv(const char *name);
  553. /* getenv returns the environment string associated with name,  or NULL if no
  554.  * string exists. Details are implementation-dependent.
  555.  */
  556.  
  557.  
  558. void *bsearch(const void *key, const void *base,
  559.               size_t n, size_t size,
  560.               int (*cmp)(const void *keyval, const void *datum) );
  561. /* bsearch searches base[0]...base[n-1] for an item that matches  *key.  The
  562.  * function cmp must return negative if its first argument  (the search key) is
  563.  * less than its second (a table entry), zero if equal, and  positive if
  564.  * greater. Items in the array base must be in ascending order.  bsearch
  565.  * returns a pointer to a matching item, or NULL if none  exists.
  566.  */
  567.  
  568.  
  569. void qsort(void *base, size_t n, size_t size,
  570.            int (*cmp)(const void *, const void *) );
  571.  
  572. /* qsort sorts into ascending order an array base[0]...base[n-1]  of objects
  573.  * of size size. The comparison function cmp is as in  bsearch.
  574.  */
  575.  
  576.  
  577. int abs(int n);  /* abs returns the absolute value of its int argument. */
  578. long labs(long n); /* labs returns the absolute value of its long argument. */
  579.  
  580. div_t div(int num, int denom);
  581. /* div computes the quotient and remainder of num/denom. The results  are
  582.  * stored in the int members quot and rem of a structure  of type div_t.
  583.  */
  584.  
  585. ldiv_t ldiv(long num, long denom);
  586. /* ldiv computes the quotient and remainder of num/denom.  The results are
  587.  * stored in the long members quot and  rem of a structure of type ldiv_t
  588.  */
  589.  
  590.  
  591. #include <assert.h>
  592.  
  593. /* Defines assert macro, which, unless NDEBUG is defined before #include
  594.  * will print on stderr a message, such as
  595.  * Assertion failed: expression, file filename, line nnn
  596.  *
  597.  * It then calls abort to terminate execution. The source filename and
  598.  * line number come from the preprocessor macros __FILE__ and __LINE__.
  599.  *
  600.  * if expression is 0;
  601.  * assert(expression);
  602.  *
  603.  */
  604.  
  605.  
  606. #include <stdarg.h>
  607.  
  608. /* facilities for stepping through a list of function arguments of unknown
  609.  * number and type.  Suppose lastarg is the last named parameter of a function
  610.  * f with a variable number of arguments. Then declare within f a variable of
  611.  * type va_list that will point to each argument in turn.
  612.  *
  613.  *  va_list ap;
  614.  * ap must be initialized once with the macro va_start before any unnamed
  615.  * argument is accessed.
  616.  *  va_start(va_list ap, lastarg);
  617.  *
  618.  * Afterwards, each execution of the macro va_arg will produce a value that
  619.  * has the type and value of the next unnamed argument, and will also modify
  620.  * ap so the next use of va_arg returns the next argument:
  621.  *
  622.  *  type va_arg(va_list ap, type);
  623.  *
  624.  * void va_end(va_list ap);
  625.  * Macro which must be called once after the arguments have been processed
  626.  * but before f is exited.
  627.  */
  628.  
  629.  
  630. #include <setjmp.h>
  631.  
  632. int setjmp(jmp_buf env);
  633. /* The macro setjmp saves state information in env for use by longjmp.
  634.  * The return is zero from a direct call of setjmp, and non-zero from a
  635.  * subsequent call of longjmp. A call to setjmp can only occur in certain
  636.  * contexts, basically the test of if, switch, and loops, and only in simple
  637.  * relational expressions.
  638.  *  if (setjmp(env) == 0)
  639.  *         --get here on direct call--
  640.  *    else
  641.  *        --get here by calling longjmp--
  642.  */
  643.  
  644. void longjmp(jmp_buf env, int val);
  645. /* longjmp restores the state saved by the most recent call to setjmp, using
  646.  * the information saved in env, and execution resumes as if the setjmp
  647.  * function had just executed and returned the non-zero value val. The
  648.  * function containing the setjmp must not have terminated. Accessible objects
  649.  * have the values they had at the time longjmp was called, except that
  650.  * non-volatile automatic variables in the function calling setjmp become
  651.  * undefined if they were changed after the setjmp call.
  652.  */
  653.  
  654.  
  655. #include <signal.h>
  656.  
  657. void (*signal (int sig, void (*handler)(int)))(int);
  658. /* signal determines how subsequent signals will be handled. If handler is
  659.  * SIG_DFL, the implementation-defined default behavior is used, if it is
  660.  * SIG_IGN, the signal is ignored; otherwise, the function pointed to by
  661.  * handler will be called, with the argument of the type of signal. Valid
  662.  * signals include
  663.  *  SIGABRT abnormal termination,   (from abort)
  664.  *  SIGFPE  arithmetic error,       (zero divide or overflow)
  665.  *  SIGILL  illegal function image, (illegal instruction)
  666.  *  SIGINT  interactive attention,  (interrupt)
  667.  *  SIGSEGV illegal storage access, (access outside memory limits)
  668.  *  SIGTERM ermination request sent to this program
  669.  *
  670.  * signal returns the previous value of handler for the specific signal, or
  671.  * SIG_ERR if an error occurs.
  672.  *
  673.  * The initial state of signals is implementation-defined.
  674.  */
  675.  
  676. int raise(int sig);
  677. /* raise sends the signal sig to the program; it returns non-zero if
  678.  * unsuccessful.
  679.  */
  680.  
  681.  
  682.  
  683. #include <time.h>
  684.  
  685. struct tm {
  686.   int tm_sec;       /* seconds after the minute (0,61) */
  687.   int tm_min;       /* minutes after the hour (0,59)   */
  688.   int tm_hour;      /* hours since midnight (0,23)     */
  689.   int tm_mday;      /* day of the month (1,31)         */
  690.   int tm_mon;       /* months since January (0,11)     */
  691.   int tm_year;      /* years since 1900                */
  692.   int tm_wday;      /* days since Sunday (0,6)         */
  693.   int tm_yday;      /* days since January 1 (0,365)    */
  694.   int tm_isdst;     /* Daylight Saving Time flag       */
  695.   /* tm_isdst is positive if Daylight Saving Time is in effect, zero if not,
  696.    * and negative if the information is not available.
  697.    */
  698. };
  699.  
  700. clock_t clock(void);
  701. /* clock returns the processor time used by the program since the beginning of
  702.  * execution, or -1 if unavailable. clock()/CLOCKS_PER_SEC is a time in
  703.  * seconds.
  704.  */
  705.  
  706. time_t time(time_t *tp);
  707. /* time returns the current calendar time or -1 if the time is not available.
  708.  * If tp is not NULL, the return value is also assigned to *tp.
  709.  */
  710.  
  711.  
  712. double difftime(time_t time2, time_t time1);
  713. /* difftime returns time2-time1 expressed in seconds. */                      
  714.  
  715. time_t mktime(struct tm *tp);
  716. /* mktime converts the local time in the structure *tp into calendar time in
  717.  * the same representation used by time. The components will have values in
  718.  * the ranges shown. mktime returns the calendar time or -1 if it cannot be
  719.  * represented.  The next four functions return pointers to static objects
  720.  * that may be overwritten by other calls.
  721.  */
  722.  
  723. char *asctime(const struct tm *tp);
  724. /* converts tp into a string of the form "Sun Jan  3 15:14:13 1988\n\0" */
  725.  
  726. char *ctime(const time_t *tp);
  727. /* ctime converts the calendar time *tp to local time; it is equivalent to
  728.  *  asctime(localtime(tp))
  729.  */
  730.  
  731. struct tm *gmtime(const time_t *tp);
  732. /* gmtime converts the calendar time *tp into Coordinated Universal Time (UTC)
  733.  * It returns NULL if UTC is not available. The name gmtime has historical
  734.  * significance.
  735.  */
  736.  
  737. struct tm *localtime(const time_t *tp);
  738. /* localtime converts the calendar time *tp into local time. */
  739.  
  740.  
  741. size_t strftime(char *s, size_t smax, const char *fmt, const struct tm *tp);
  742. /* strftime formats date and time information from *tp into s according to fmt,
  743.  * which is analogous to a printf format.  Ordinary characters (including the
  744.  * terminating '\0') are copied into s. Each %c is replaced as described below,
  745.  * using values appropriate for the local environment. No more than smax
  746.  * characters are placed into s. strftime returns the number of characters,
  747.  * excluding the '\0', or zero if more than smax characters were produced.
  748.  *    %a    abbreviated weekday name.
  749.  *    %A    full weekday name.
  750.  *    %b    abbreviated month name.
  751.  *    %B    full month name.
  752.  *    %c    local date and time representation.
  753.  *    %d    day of the month (01-31).
  754.  *    %H    hour (24-hour clock) (00-23).
  755.  *    %I    hour (12-hour clock) (01-12).
  756.  *    %j    day of the year (001-366).
  757.  *    %m    month (01-12).
  758.  *    %M    minute (00-59).
  759.  *    %p    local equivalent of AM or PM.
  760.  *    %S    second (00-61).
  761.  *    %U    week number of the year (Sunday as 1st day of week) (00-53).
  762.  *    %w    weekday (0-6, Sunday is 0).
  763.  *    %W    week number of the year (Monday as 1st day of week) (00-53).
  764.  *    %x    local date representation.
  765.  *    %X    local time representation.
  766.  *    %y    year without century (00-99).
  767.  *    %Y    year with century.
  768.  *    %Z    time zone name, if any.
  769.  *    %%    %
  770.  */
  771.  
  772.  
  773. #include <limits.h>
  774.  
  775. /* minimum values, can be larger ( in magnitude ) */
  776. #define CHAR_BIT        8  /* bits in a char */
  777. #define CHAR_MAX        is either UCHAR_MAX or SCHAR_MAX
  778. #define INT_MAX         at least +32767
  779. #define INT_MIN         at most  -32767
  780. #define LONG_MAX        at least +2147483647
  781. #define LONG_MIN        at most  -2147483647
  782. #define SCHAR_MAX       at least +127
  783. #define SCHAR_MIN       at most  -127
  784. #define SHRT_MAX        at least +32767
  785. #define SHRT_MIN        at most  -32767
  786. #define UCHAR_MAX       at least 255
  787. #define UINT_MAX        at least 65535
  788. #define ULONG_MAX       at least 4294967295
  789. #define USHRT_MAX       at least 65535
  790.  
  791.  
  792. #include <float.h>
  793. /* minimum values, can be larger ( in magnitude ) */
  794. #define FLT_RADIX       2 /* radix of exponent representation */
  795. #define FLT_ROUNDS      ?  /* floating-point rounding mode for addition */
  796. #define FLT_DIG         6 /* decimal digits of precision */
  797. #define FLT_EPSILON     1E-5 /* smallest number such that 1.0 + x != 1.0 */
  798. #define FLT_MANT_DIG    ?    /* number of digits in mantissa (in FLT_RADIX) */
  799. #define FLT_MAX        1E+37 /* maximum floating point number */
  800. #define FLT_MAX_EXP     ?    /* maximum n such that (FLT_RADIX^(n-1)) */
  801. #define FLT_MIN        1E-37 /* min normalized floating point */
  802. #define FLT_MIN_EXP     ?    /* min n such that 10^n is normalized */
  803. #define DBL_DIG        10 /* decimal digits of precision */
  804. #define DBL_EPSILON    1E-9 /* smallest number such that 1.0 + X != 1.0 */
  805. #define DBL_MANT_DIG    ?   /* number of digits in mantissa */
  806. #define DBL_MAX        1E+37 /* max double */
  807. #define DBL_MIN        1E-37 /* min double */
  808. #define DBL_MAX_EXP     ?   /* maximum n such that (FLT_RADIX^(n-1)) */
  809. #define DBL_MIN_EXP     ?   /* min n such that 10^n is normalized */
  810.  
  811.  
  812. #include <stddef.h>
  813. /* defines:
  814.  *  ptr_diff_t
  815.  *  size_t
  816.  *  wchar_t
  817.  *  NULL
  818.  *  offsetof(type, member)
  819.  *  register_t
  820.  *  and c99/types?
  821.  *  int8_t, u_int8_t, int16_t, u_int32_t, int64t, u_int64_t
  822.  *  intptr_t, uintptr_t
  823.  */
  824.  
  825. /* ***************************************************************** */
  826. /*
  827.    Character Constants:
  828.    newline         NL (LF)  \n          backslash       \  \\
  829.    horizontal tab  HT       \t          question mark   ?  \?
  830.    veritical tab   VT       \v          single qoute    '  \'
  831.    backspace       BS       \b          double qoute    "  \"
  832.    carriage return CR       \r          octal number  ooo  \ooo
  833.    formfeed        FF       \f          hex number     hh  \xhh
  834.    audible alert   BEL      \a
  835.    null character  NUL      \0
  836.  
  837.    wide char constants L'x' of type wchar_t
  838.  
  839.    Trigraphs:
  840.     ??=   #        ??(   [        ??<  {
  841.     ??/   \        ??)   ]        ??>  }
  842.     ??'   ^        ??!   |        ??-  ~
  843.  
  844.    Trigraph replacement occurs before anything else.
  845.  
  846.    Predefined Names:
  847.    __LINE__          decimal constant containing source line number
  848.    __FILE__          string literal containing file being compiled
  849.    __DATE__          string lit. "Mmm dd yyyy" date of compilation
  850.    __TIME__          string lit. "hh:mm:ss"  times of compilation
  851.    __STDC__          Constant is 1 in standard-conforming implementations
  852.  
  853.  
  854.  ========================== Precedence and Associativity ===============
  855.  
  856.  ()   []    ->    .                                        left to right
  857.  !    ~     ++   --   -  *  &  (type)  sizeof              right to left
  858.  *    /     %                                              left to right
  859.  +    -                                                    left to right
  860.  <<   >>                                                   left to right
  861.  <    <=    >    >=                                        left to right
  862.   ==   !=                                                  left to right
  863.  &                                                         left to right
  864.  ^                                                         left to right
  865.  |                                                         left to right
  866.  &&                                                        left to right
  867.  ||                                                        left to right
  868.  ?:                                                        right to left
  869.  =  +=  -=  *=  /=  %=  &=  ^=  |=  !=  <<=  >>=           right to left
  870.  ,                                                         left to right
  871.  
  872.  =======================================================================
  873.   Unary +, -, and * have higher precedence that binary forms
  874.  
  875.  
  876.  
  877.  Identifiers:
  878.   Sequence of letters and digits.  First character must be a letter
  879.   ( or underscore )  At least 31 characters are significant.  Preprocessor
  880.   identifiers etc, can be as small as 6.
  881.  
  882.   Keywords:
  883.    auto, break, case, char, const, continue, default, do
  884.    double, else, enum, extern, float, for, goto, if
  885.    int, long, register, return, short, signed, sizeof, static
  886.    struct, switch, typedef, union, unsigned, void, volatile, while,
  887.   ( fortran, asm )
  888.  
  889.   Integer Constant:
  890.     Octal begin with 0                    01 02 03 04 05 06 07
  891.     Hexadecimal start with 0x, or 0X      0x1 0x9 0xA 0xB 0xC 0xd 0xe 0xf
  892.     Decimal otherwise
  893.     Suffixes:
  894.      unsigned     u U
  895.      long         l L
  896.  
  897.   Floating Constants:
  898.    Consists of integer part, a decimal point, a fraction part, an e or E
  899.    and integer exponent.  Either integer part or fraction may be missing.
  900.    Either the E or the decimal point may be missing.
  901.    Suffixes:
  902.     float         f F
  903.     long double   l L
  904.     double        (default)
  905.  
  906.   Enumeration Constants are ints.
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913. */
  914.  
  915.  
  916. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement