home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ezview / util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-06  |  20.6 KB  |  484 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. /* ********************************************************************** *\
  16.  *         Copyright IBM Corporation 1988,1989 - All Rights Reserved      *
  17.  *        For full copyright information see:'andrew/config/COPYRITE'     *
  18. \* ********************************************************************** */
  19. /* $Header: /afs/.andrew.cmu.edu/itc/src/andrew/overhead/util/hdrs/RCS/util.h,v 2.24 89/12/14 14:35:17 cfe Exp $ */
  20. /* $ACIS: $ */
  21. /* $Source: /afs/.andrew.cmu.edu/itc/src/andrew/overhead/util/hdrs/RCS/util.h,v $ */
  22.  
  23. #ifndef _UTIL_H_
  24. #define _UTIL_H_ 1
  25. #if !defined(lint) && !defined(LOCORE) && defined(RCS_HDRS)
  26. static char    *rcsid_h = "$Header: /afs/.andrew.cmu.edu/itc/src/andrew/overhead/util/hdrs/RCS/util.h,v 2.24 89/12/14 14:35:17 cfe Exp $ ";
  27.  
  28. #endif                                 /* !defined(lint) && !defined(LOCORE)
  29.                                         * && defined(RCS_HDRS) */
  30.  
  31. /* ************************************************************ *\
  32.  
  33.         Declarations for miscellaneous routines in libutil.a
  34.         $Header: /afs/.andrew.cmu.edu/itc/src/andrew/overhead/util/hdrs/RCS/util.h,v 2.24 89/12/14 14:35:17 cfe Exp $
  35.  
  36. \* ************************************************************ */
  37.  
  38. #include <andyenv.h>
  39.  
  40. extern int getpty();            /* opens up both ends of a pty */
  41.  
  42. #ifdef WHITEPAGES_ENV
  43. /* Compatibility routines */
  44. extern int      getvuid();             /* returns ViceID or -1 (sets errno on
  45.                                         * error) */
  46. extern struct passwd *getvpwuid();     /* These work a lot like the non-V
  47.                                         * versions */
  48. extern struct passwd *getvpwnam();
  49. extern int      setvpwent(), endvpwent();
  50. extern struct passwd *getvpwent();
  51.  
  52. extern struct passwd *getcpwuid();     /* Take TWO arguments: a uid/nam and a
  53.                                         * Vice cell name. */
  54. extern struct passwd *getcpwnam();
  55. extern int      cpw_error;
  56.  
  57. #else                                  /* WHITEPAGES_ENV */
  58. /* Real backwards compatibility. */
  59. #define getvuid getuid
  60. #define getvpwuid getpwuid
  61. #define getvpwnam getpwnam
  62. #define getvpwent getpwent
  63. #define setvpwent setpwent
  64. #define endvpwent endpwent
  65. #define getcpwuid(X, Y) getpwuid(X)
  66. #define getcpwnam(X, Y) getpwnam(X)
  67. #define cpw_error errno
  68. #endif                                 /* WHITEPAGES_ENV */
  69.  
  70. extern char     FoldTRT[256];
  71.  
  72. #define FOLDEDEQ(s1,s2) (FoldTRT[s1[0]]==FoldTRT[s2[0]] && FoldedEQ(s1,s2))
  73. #define FOLDEDEQN(s1,s2,n) (n <= 0 || (FoldTRT[s1[0]]==FoldTRT[s2[0]] && FoldedEQn(s1,s2,n)))
  74.  
  75. extern char    *gethome(), *getMyHome();
  76.  
  77. extern int GetHostDomainName();    /* works like gethostname() but extends with getdomainname() if necessary. */
  78.  
  79. struct configurelist {
  80.     char           *programName;
  81.     char           *key;
  82.     char           *value;
  83.     struct configurelist *next;
  84. };
  85.  
  86. #define CONFIG_EOF -1
  87. #define CONFIG_FOUNDENTRY 0
  88. #define CONFIG_BADENTRY 1
  89. #define CONFIG_COMMENT 2
  90. #define CONFIG_FALSECONDITION 3
  91. #define CONFIG_EMPTYLINE 4
  92. #define CONFIG_NOKEY 5
  93. #define CONFIG_NOVALUE 6
  94.  
  95. extern int      ReadConfigureLine();   /* Reads a line from a file in
  96.                                         * configure file format - returns one
  97.                                         * of the above values */
  98. extern struct configurelist *ReadConfigureFile();       /* reads a configure
  99.                                                          * file given by
  100.                                                          * filename */
  101. extern char    *GetConfig();           /* returns the value corresponding to a
  102.                                         * key for a given configurelist */
  103. extern char    *GetConfiguration();    /* returns the value for a key in the
  104.                                         * AndrewSetup file */
  105. extern          FreeConfigureList();   /* frees a configure list */
  106.  
  107. extern char    *getprofile(), *getprofilestring();
  108. extern int      getprofileint(), getprofileswitch();
  109. extern char    *GetProfileFileName();
  110. extern char    *GetFirstProfileFileName();
  111. extern          refreshprofile();
  112.  
  113. extern          setprofilestring();
  114.  
  115. extern char    *ap_Shorten();          /* ap_Shorten(path) tries to shorten
  116.                                         * path using the current home dir */
  117. extern char    *ap_ShortenAlso();      /* (path, otherID, otherHD does the
  118.                                         * same but with otherID/otherHD also. */
  119. extern char    *ap_ShortenTo();        /* (pathname, maxlen) shortens to a
  120.                                         * maximum length, abbreviating the
  121.                                         * path prefix to hyphens. */
  122. extern char    *ap_ShortenAlsoTo();    /* (pathname, otherID, otherHD, maxlen)
  123.                                         * does both things. */
  124.  
  125. extern int      fwriteallchars();      /* pass (text, num, stream) and it
  126.                                         * retries fwrite on interruption */
  127. extern int      writeall();            /* pass (fd, buf, nbytes) and it
  128.                                         * retries write on interruption */
  129.  
  130. extern char    *NiceTime();            /* Converts long arg to printable time
  131.                                         * string without newline */
  132.  
  133. struct LinePromState {
  134.     int             BeginDataLevel;
  135.     char            InDefine, Promoting, SawBlankLine;
  136. };
  137.  
  138. extern int      BE2LinePromoteInit();
  139.  
  140.  /*
  141.   * int BE2LinePromoteInit(refstate) struct LinePromState **refstate; Returns
  142.   * < 0 for (malloc) failure, 0 for OK.  Initializes *refstate to point to
  143.   * malloc'ed storage that will hold the LinePromote state.
  144.   */
  145.  
  146. extern int      BE2LinePromote();
  147.  
  148.  /*
  149.   * int BE2LinePromote(line, state) char *Line; struct LinePromState *state;
  150.   * Works only on BE2 Datastream messages* Returns 2 if this line (including
  151.   * the newline) should be ``promoted'' from the beginning of a message to the
  152.   * beginning of an error message that encapsulates the message.  Returns 0 if
  153.   * the line should stay where it is. Returns 1 if this line should be
  154.   * ``demoted'' to the very tail end of the encapsulated message.  Returns < 0
  155.   * on errors.
  156.   */
  157.  
  158. extern int      BE2LinePromoteEnd();
  159.  
  160.  /*
  161.   * int BE2LinePromoteEnd(state) struct LinePromState *state; Cleans up the
  162.   * malloc'ed storage and returns 0 if OK, non-zero on errors.
  163.   */
  164.  
  165. extern char    *UnixSignal();          /* Pass it a signal and it returns a
  166.                                         * static string giving its name */
  167.  
  168. extern int      VenusFlush();          /* Hand it the name of a file to flush
  169.                                         * from Venus cache */
  170. extern int      VenusFlushCallback();  /* Hand it the name of a file for which
  171.                                         * to flush the callback */
  172. extern int      VenusFetch();          /* Hand it the name of a file to
  173.                                         * pre-fetch into the Venus cache */
  174.  
  175. /* Caveat: the CancelStore function is no longer implemented in in-kernel AFS (10/11/88) */
  176. extern int      VenusCancelStore();    /* Hand it a fid and Venus won't store
  177.                                         * the file on its close */
  178.  
  179. /* Functions to describe a user's authentication in multiple cells */
  180. struct CellAuth {
  181.     char           *CellName;          /* description for this cell */
  182.     int             ViceID;            /* the ViceID within that cell */
  183.     char           *UserName;          /* pw_name (login ID) for user in this
  184.                                         * cell */
  185.     char           *PersonName;        /* pw_gecos (personal name) for user in
  186.                                         * this cell */
  187.     char           *homeDir;           /* pwdir (home directory) for user in
  188.                                         * this cell */
  189.     int             WpError;           /* White pages error, if any, from
  190.                                         * trying to get UserName and
  191.                                         * PersonName. -1 means UserName,
  192.                                         * PersonName, and homeDir not
  193.                                         * initialized; 0 (wperr_NoError) means
  194.                                         * that all are OK. */
  195.     int             IsPrimary;         /* whether this cell is the primary one
  196.                                         * for the user. */
  197.     int             UsesAMSDelivery;   /* 0 initially; -1 for no, +1 for yes */
  198.     unsigned long   ExpireTime;        /* When this token will expire (or 0 if
  199.                                         * it's not valid now) */
  200.     int             IsLocal;           /* whether this auth is local or
  201.                                         * AFS-based. */
  202. };
  203. extern void     EraseCellMemory();     /* Makes us get a new array of auth
  204.                                         * descriptors next time. */
  205. extern int      FindCell();            /* int FindCell(cellName, ppCellAuth)
  206.                                         * char *cellName; struct CellAuth
  207.                                         * **ppCellAuth; Return a pointer to
  208.                                         * our authentication for cell
  209.                                         * cellName, via ppCellAuth. Return 0
  210.                                         * if it was found, or an error code
  211.                                         * (>0 for permanent, <0 for
  212.                                         * temporary). Return 1 if we don't
  213.                                         * have any authentication in that
  214.                                         * cell, or if there's no such cell.
  215.                                         * Return 2 if we're completely
  216.                                         * unauthenticated. */
  217.  
  218. extern int      FindHomeCell();        /* int FindHomeCell(ppCellAuth) struct
  219.                                         * CellAuth **ppCellAuth; Like
  220.                                         * FindCell, except that it returns a
  221.                                         * pointer to the $HOME cell, if there
  222.                                         * is one. Return 1 if there's no home
  223.                                         * cell. */
  224.  
  225. extern int      FindAnyCell();         /* int FindAnyCell(ppCellAuth) struct
  226.                                         * CellAuth **ppCellAuth; Like
  227.                                         * FindCell, except that it returns a
  228.                                         * pointer to any authenticated cell,
  229.                                         * if there is one. */
  230.  
  231. extern int      FindNextCell();        /* int FindNextCell(ppCellAuth) struct
  232.                                         * CellAuth **ppCellAuth; Generate the
  233.                                         * authenticated cells.  Starts and
  234.                                         * ends with *ppCellAuth == NULL. */
  235.  
  236. extern void     FillInCell();          /* void FillInCell(cellAuth) struct
  237.                                         * CellAuth *cellAuth; Fill in the
  238.                                         * white pages values for the given
  239.                                         * cell pointer; an error (or success)
  240.                                         * code is left in cellAuth->WpError. */
  241. extern int      ca_UpdateCellAuths();  /* int ca_UpdateCellAuths(); Update the
  242.                                         * ExpireTime fields in our CellAuth
  243.                                         * structures. */
  244.  
  245. extern int      vclose();              /* Close a fileid and wait for it to
  246.                                         * complete in Vice */
  247. extern int      vfclose();             /* fclose a FILE* and wait for it to
  248.                                         * complete in Vice */
  249. extern int      vdown();               /* return TRUE iff the errno value
  250.                                         * passed as argument says that Vice or
  251.                                         * Venus was down */
  252. extern int      tfail();               /* return TRUE iff the errno value
  253.                                         * passed as arg is a temp failure */
  254.  
  255. #ifdef FILE
  256. extern FILE    *topen();               /* like popen() but enable timeouts for
  257.                                         * the close */
  258. extern FILE    *qopen();               /* topen() with simplified calling
  259.                                         * sequence */
  260.  
  261. #endif                                 /* FILE */
  262. extern int      tclose();              /* pclose() sensitive to subprocess
  263.                                         * timeouts */
  264. extern int      qclose();              /* tclose() with simplified calling
  265.                                         * sequence */
  266. extern int      t2open();              /* topen() with both reading and
  267.                                         * writing of subprocesses */
  268. extern int      t2close();             /* close the t2open() */
  269.  
  270. extern char    *ULsindex();            /* Searches for substring of arg1 that
  271.                                         * matches arg2, ignoring alpha case,
  272.                                         * and returns a pointer to this
  273.                                         * substr. If no match is found,
  274.                                         * returns a 0. */
  275. extern int      ULstrcmp();            /* Compares two arg strings, ignoring
  276.                                         * alpha case, like strcmp. */
  277. extern int      ULstrncmp();           /* Compares two arg strings, ignoring
  278.                                         * alpha case, like strncmp. */
  279. extern int      ULstlmatch();          /* Returns 1 iff initial characters of
  280.                                         * arg1 match arg2, ignoring alpha
  281.                                         * case, else 0. */
  282.  
  283. extern char    *NewString();           /* Return a dynamically-allocated copy
  284.                                         * of the single arg string, or 0 if
  285.                                         * allocation fails. */
  286.  
  287. extern char    *UnixError();           /* Pass it an errno value and it
  288.                                         * returns a static (canned) string
  289.                                         * describing the error */
  290.  
  291. extern int      GetCurrentWSCell();    /* (Buf, size) */
  292. extern int      GetCellFromFileName(); /* (Filename, Buf, size) */
  293.  
  294. extern void     SetInitialArgs();      /* SetInitialArgs(argc, argv,
  295.                                         * envp|NULL)--pass proc title stuff
  296.                                         * after copying everything wanted from
  297.                                         * argv, and from envp, too, if that's
  298.                                         * passed also. */
  299. extern void     SetProcTitle();        /* SetProcTitle(str, a1, a2, a3, a4,
  300.                                         * a5)--like printf into the process
  301.                                         * title. */
  302.  
  303. extern void     Verbose_SetUp();       /* Verbose_SetUp(FILE *stream, char
  304.                                         * *prefix, int *threshold, int *mask)
  305.                                         * -- Initialize the "Verbose" call
  306.                                         * (see /usr/andy/doc/verbose.d) */
  307. extern int      Verbose();             /* Verbose([FILE *stream], [int level],
  308.                                         * [unsigned int bits], char *fmt,
  309.                                         * datum1, datum2, ..., datumN) -- like
  310.                                         * printf for "debugging"-type
  311.                                         * messages.  See
  312.                                         * /usr/andy/doc/verbose.d */
  313.  
  314. extern unsigned long getaddr();           /* Return our internet address as a 
  315.                         * long in network byte order.  
  316.                     * Returns zero if it can't find one. */
  317.  
  318. #define ORDINALIZE(i) \
  319.   (((((i)%100)==11)||(((i)%100)==12)||(((i)%100)==13))?"th": \
  320.    (((i)%10)==1)?"st": \
  321.    (((i)%10)==2)?"nd": \
  322.    (((i)%10)==3)?"rd":"th")
  323. /* Use ORDINALIZE like this:
  324.    printf("the %d%s element is %s,\n",
  325.           i, ORDINALIZE(i), a[i]);
  326. */
  327.  
  328. #define CARDINALIZE(i,z,o,m) \
  329.   (((i)==0)?(z): \
  330.    ((i)==1)?(o):m)
  331. /* Use CARDINALIZE like this:
  332.    printf(CARDINALIZE(n, 
  333.                       "There are no elements.\n",
  334.               "There is one element.\n",
  335.               "There are %d elements.\n"),
  336.       n); */
  337.  
  338.  
  339. #ifndef ERRHDLR_H
  340. #define ERRHDLR_H
  341.  
  342. #include <setjmp.h>
  343. #ifndef AMIGA
  344. #include <sys/param.h>
  345. #endif
  346.  
  347. #define EH_ERR_MSG_BUF_SIZE (4*MAXPATHLEN)
  348.  
  349. typedef struct {
  350.   jmp_buf jb;
  351. } EH_environment;
  352.  
  353. extern char EH_Error_Msg[];
  354. extern EH_environment *_error_handler_env;
  355.  
  356. #define ABS(x) ((x)<0?-(x):(x))
  357.  
  358. #define EH_ret_code(module, code) ((int)(((int)(module)*0x10000)+(ABS((int)(code))&0xffff)))
  359. #define EH_module(ehcode) (((int)ehcode)/0x10000)
  360. #define EH_code(ehcode) (((int)ehcode)%0x10000)
  361.  
  362. #define EH_err(errcode, errmsg) \
  363.   (strncpy(EH_Error_Msg, (errmsg), EH_ERR_MSG_BUF_SIZE), \
  364.    longjmp(_error_handler_env->jb, (errcode)))
  365.  
  366. #define EH_cond_error_on(test, errcode, errmsg) \
  367.   if (test) EH_err((errcode),(errmsg))
  368.  
  369. #define EH_propagate_error(comment) \
  370.   (strncat(EH_Error_Msg, ", ", EH_ERR_MSG_BUF_SIZE-strlen(EH_Error_Msg)-1), \
  371.    strncat(EH_Error_Msg, (comment), EH_ERR_MSG_BUF_SIZE-strlen(EH_Error_Msg)-1), \
  372.    longjmp(_error_handler_env->jb, _err_code))
  373.  
  374. #define EH_restore_handler \
  375.   _error_handler_env = _saved_handler_env
  376.  
  377. #define EH_begin \
  378. { \
  379.   int _err_code; \
  380.   EH_environment *_saved_handler_env, _new_handler_env; \
  381.   _saved_handler_env = _error_handler_env; \
  382.   if ((_err_code = setjmp(_new_handler_env.jb)) == 0) { \
  383.     _error_handler_env = &(_new_handler_env);
  384.  
  385. #define EH_handle \
  386.   } else { \
  387.     EH_restore_handler;
  388.  
  389. #define EH_end \
  390.   } \
  391.   EH_restore_handler; \
  392. }
  393.  
  394. #define EH_break         EH_restore_handler; break
  395. #define EH_continue      EH_restore_handler; continue
  396. #define EH_goto          EH_restore_handler; goto
  397. #define EH_return        EH_restore_handler; return
  398. #define EH_return_val(x) EH_restore_handler; return(x)
  399.  
  400. /*
  401.   Standard routines:
  402.      These routines will signal errors, so be prepared to catch those errors.
  403. */
  404.  
  405. extern char *emalloc(/* long size */);
  406. extern char *erealloc(/* char *old, long size */);
  407. extern char *CopyString(/* char *old */);
  408.  
  409. /*
  410.   Module definitions:
  411. */
  412.  
  413. #define EH_module_system 0
  414. #define EH_module_prs 1
  415. #define EH_module_alq 2
  416.  
  417. #endif /* ERRHDLR_H */
  418.  
  419.  
  420. #ifdef AFS30_ENV
  421. /* Error codes for aq_XXX functions.  Actually, their negatives are returned. */
  422. #define ALQ_ERRNO 1
  423. #define ALQ_ENONAME 2
  424. #define ALQ_EPARSEACL 3
  425. #define ALQ_NOT_GROUP 4
  426. #define ALQ_SYSTEM_GROUP 5
  427. #define ALQ_EPRS_BASE 20
  428.  
  429. extern int aq_GroupP(/*
  430.                IN char *group, 
  431.                IN char *groupcell */);
  432. /* Returns 1 if the name "group" is a groupname, 0 if not, <0 on errors. */
  433.  
  434. extern int aq_GetGroupMembers(/* 
  435.                 IN char *group, 
  436.                 IN char *groupcell, 
  437.                 OUT char **outBuf */);  
  438. /* Return the members of the given group as a newline-separated list in 
  439.    outBuf, which is modified to point to a malloc'd string.  The return 
  440.    value is 0 if all is OK and negative on errors: a return value of -1 
  441.    means to look in errno. */
  442.  
  443. extern int aq_UserInGroup(/* 
  444.                 IN char *user, 
  445.                 IN char *usercell, 
  446.                 IN char *group, 
  447.                 IN char *groupcell */);
  448. /* Return whether the given user is in the given group in the given cell.  
  449.    1 means YES, 0 means NO, negative numbers are error codes; 
  450.    -1 means to look in errno. */
  451.  
  452.  
  453. extern long int aq_UserRightsToDir(/*
  454.                      IN char *user,
  455.                      IN char *usercell, 
  456.                      IN char *dir */);
  457. /* Return the access rights that the given user has to the given dir.  
  458.    Negative numbers are error codes; -1 means to look in errno. */
  459.  
  460. extern int aq_CheckUserAllRightsToDir(/*
  461.                     IN char *user,
  462.                     IN char *usercell,
  463.                     IN char *dir, 
  464.                     IN long int rights */);
  465. /* Check whether the given user has all of a collection of rights to 
  466.    the given directory.  Return 1 if YES, 0 if NO; negative numbers 
  467.    are error codes, and -1 means to look in errno. */
  468.  
  469. extern int aq_CheckUserAnyRightToDir(/*
  470.                        IN char *user, 
  471.                        IN char *usercell,
  472.                        IN char *dir,
  473.                        IN long int rights */);
  474. /* Check whether the given user has any of a collection of rights to the 
  475.    given directory.  Return 1 if YES, 0 if NO; negative numbers are 
  476.    error codes, and -1 means to look in errno. */
  477.  
  478. extern char *aq_GetLastErrorMessage(/* void */);
  479. /* Returns the text string of the last error message.  Points to static 
  480.    storage, do NOT free. */
  481.  
  482. #endif /* AFS30_ENV */
  483. #endif /* _UTIL_H_ */
  484.