add explicit file-based entry point

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1491 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-12-28 04:24:33 +00:00
parent ceda19dfdb
commit 9e1b1f976e
2 changed files with 53 additions and 19 deletions

View File

@ -132,40 +132,67 @@ static char * searchpaths[] = {
AccountGroup *
xaccSessionBegin (Session *sess, char * sid)
{
struct stat statbuf;
char pathbuf[PATH_MAX];
char * filefrag, *path = NULL;
int namelen, len;
int i, rc;
AccountGroup *retval;
if (!sess) return NULL;
/* clear the error condition of previous errors */
sess->errtype = 0;
/* seriously invalid */
if (!sid) {
sess->errtype = EINVAL;
return NULL;
}
/* check to see if this session is already open */
if (sess->sessionid) {
sess->errtype = ETXTBSY;
return NULL;
}
/* seriously invalid */
if (!sid) {
sess->errtype = EINVAL;
return NULL;
}
/* check to see if this is a type we know how to handle */
if (strncmp (sid, "file:", 5)) {
sess->errtype = ENOSYS;
return NULL;
}
/* add 5 to space past 'file:' */
retval = xaccSessionBeginFile (sess, sid+5);
return retval;
}
AccountGroup *
xaccSessionBeginFile (Session *sess, char * filefrag)
{
struct stat statbuf;
char pathbuf[PATH_MAX];
char *path = NULL;
int namelen, len;
int i, rc;
if (!sess) return NULL;
/* clear the error condition of previous errors */
sess->errtype = 0;
/* check to see if this session is already open */
if (sess->sessionid) {
sess->errtype = ETXTBSY;
return NULL;
}
/* seriously invalid */
if (!filefrag) {
sess->errtype = EINVAL;
return NULL;
}
/* ---------------------------------------------------- */
/* OK, now we try to find or build an absolute file path */
/* check for an absolute file path */
filefrag = sess->sessionid + 5; /* space past 'file:' */
if ('/' == *filefrag) {
sess->fullpath = strdup (filefrag);
} else {
@ -256,8 +283,10 @@ xaccSessionBegin (Session *sess, char * sid)
}
assert (sess->fullpath); /* no one fucked with the code, yeah? */
/* OK, we've got a good string ... */
sess->sessionid = strdup (sid);
/* Store the sessionid URL also ... */
strcpy (pathbuf, "file:");
strcat (pathbuf, filefrag);
sess->sessionid = strdup (pathbuf);
/* ---------------------------------------------------- */
/* Yow! OK, after all of that, we've finnaly got a fully

View File

@ -66,6 +66,10 @@ void xaccSessionDestroy (Session *);
* If the file is succesfully opened and read, then a lock will have been
* obtained, and all other access to the file will be denied. This feature
* is intended to be a brute-force global lock to avoid multiple writers.
*
* The xaccSessionBeginFile() routine is identical to the xaccSessionBegin()
* routine, except that the argument is a filename (i.e. the five
* letters "file:" should not be prepended).
*
* The xaccSessionGetError() routine can be used to obtain the reason for
* any failure. Standard errno values are used. Calling this routine resets
@ -131,13 +135,14 @@ void xaccSessionDestroy (Session *);
*
*/
AccountGroup * xaccSessionBegin (Session *, char * sessionid);
int xaccSessionGetError (Session *);
AccountGroup * xaccSessionGetGroup (Session *);
void xaccSessionSetGroup (Session *, AccountGroup *topgroup);
AccountGroup * xaccSessionBegin (Session *, char * sessionid);
AccountGroup * xaccSessionBeginFile (Session *, char * filename);
int xaccSessionGetError (Session *);
AccountGroup * xaccSessionGetGroup (Session *);
void xaccSessionSetGroup (Session *, AccountGroup *topgroup);
void xaccSessionSave (Session *);
void xaccSessionEnd (Session *);
void xaccSessionEnd (Session *);
#endif /* __XACC_SESSION_H__ */