home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
smapp100.zip
/
sm10.zip
/
smgoptio.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-14
|
7KB
|
220 lines
/* ------------------------------------------------------------------------
*
* File: smgoptio.c
* Project: Source Mapper.
* Created: April 8, 1992.
* Description: Kildekode for lagring av brukerens valg.
*
* Copyright (C) 2000 Leif-Erik Larsen.
* This file is part of the Source Mapper source package.
* Source Mapper is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, in version 2 as it comes in the
* "COPYING" file of the XWorkplace main distribution.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ------------------------------------------------------------------------ */
#include "smg.h"
tmpnTYPE tmpn;
o_totinfoTYPE o_totinfo ;
o_funcregTYPE o_funcreg;
o_funcallTYPE o_funcall;
o_idlistTYPE o_idlist;
o_flowTYPE o_flow;
o_lineinfoTYPE o_lineinfo;
o_variousTYPE o_various;
o_generateTYPE o_generate;
int SetDefaultOptions ( void )
/* Opprettet: Onsdag 8. april 1992.
Parameter:
Retur : E/O.
Beskriv : Setter alle brukerdynamiske valg til standard verdi.
See header file for more information on the different items.
*/
{
/* Totalinformasjon */
o_totinfo.incl = O_YES;
o_totinfo.lin_tot = O_YES;
o_totinfo.lin_emp = O_YES;
o_totinfo.lin_com = O_YES;
o_totinfo.lin_cod = O_YES;
o_totinfo.func = O_YES;
o_totinfo.com = O_YES;
/* Funksjonregister */
o_funcreg.incl = O_YES;
o_funcreg.sort = O_NAME;
/* Liste over funksjonkallere */
o_funcall.incl = O_NO;
o_funcall.sel = O_NO;
o_funcall.list[0] = 0;
o_funcall.riselnr = O_YES;
/* Liste over identifikatorer */
o_idlist.incl = O_NO;
o_idlist.sel = O_NO;
o_idlist.list[0] = 0;
o_idlist.riselnr = O_YES;
/* Liste over kall-sekvenser */
o_flow.incl = O_YES;
o_flow.graph = O_NO;
o_flow.format = O_LIST;
o_flow.indent = 5;
o_flow.index = O_YES;
o_flow.iIncExternals = O_YES;
strcpy (o_flow.deftoplev, "main");
/* Linjeinformasjon */
o_lineinfo.incl = O_YES;
o_lineinfo.r_llin = O_YES;
o_lineinfo.r_bloc = O_YES;
o_lineinfo.r_coml = O_YES;
/* Informasjon om funksjoner */
o_lineinfo.r_func = O_YES;
o_lineinfo.c_ltot = O_NO;
o_lineinfo.c_empl = O_NO;
o_lineinfo.c_coml = O_NO;
o_lineinfo.c_lcod = O_NO;
o_lineinfo.c_com = O_NO;
o_lineinfo.calist = O_YES;
/* Diverse */
o_various.np_str = O_NO;
o_various.np_fun = O_NO;
o_various.np_sect = O_NO;
o_various.column = O_TABULAT;
o_various.del = O_YES; /* Delete .smg-files after use */
o_various.gencom = O_YES;
o_various.twidth = 8;
o_various.iShowInfo = 3; /* Detailed information on screen */
o_various.newpag[0] = 0;
/* Generer */
o_generate.gen = O_ALL;
o_generate.met = O_MAKE;
strcpy (o_generate.obj, BigStr (2, ".", DIRSPLITSTR));
strcpy (o_generate.map, BigStr (2, ".", DIRSPLITSTR));
strcpy (o_generate.tmp, BigStr (2, ".", DIRSPLITSTR));
/* Midlertidig prosjektfil må alltid legges i samme katalog som
SM programmet ligger i, ikke i katalog for midlertidige filer.
Dette for å unngå at prosjektfil legges i katalog for midlertidige
filer f¢r midlertidig- katalogen eventuelt spesifiseres. */
#ifdef GUI
return OK;
#else
return (CreateUniqueFile (progdir, tmpn.projec, sizeof (tmpn.projec)));
#endif
} /* SetDefaultOptions (); */
int SetTmpFNames ( void )
/*
Function: Create the temporary files, and the filename of them, of this
program.
Date: April 21, 1993. 22:20. By LEL.
Interface:
Returns: E/O.
*/
{
if (!CreateUniqueFile (o_generate.tmp, tmpn.funcal, sizeof (tmpn.funcal)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.lininf, sizeof (tmpn.lininf)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.funreg, sizeof (tmpn.funreg)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.idlist, sizeof (tmpn.idlist)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.manobj, sizeof (tmpn.manobj)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.sortfi, sizeof (tmpn.sortfi)) ||
!CreateUniqueFile (o_generate.tmp, tmpn.indexf, sizeof (tmpn.indexf)))
{
RETURN_ERR;
}
return (OK);
} /* SetTmpFNames (); */
int CreateUniqueFile ( const char *pcDir, char *pPath, int iMaxPath )
/*
Function: Create an unique (temporary) file in specified directory.
The file will have the name "sm_zzzzz.tmp".
Created: December 12, 1995. 22:40. By Leif-Erik Larsen.
Interface: pcDir = Directory of where to create the temporary file.
pPath = Buffer of where to return the complete path.
iMaxPath = Size of the pPath buffer.
Retur: E/O.
Comment: This function do not test if the specified directory realy
exist. It is up to the caller to test this before calling
this function.
*/
{
FILE *pFile;
char *pPtr;
char cLegalChrs[] = "0123456789abcdefghijklmnopqrstuvw";
int iLegalChrsLen = strlen (cLegalChrs);
int iDirLen = strlen (pcDir);
int iMaxFile = iMaxPath - iDirLen - 2; /* Keep room for '\\' and '\0' */
if (iMaxFile < 12)
{
/* This should never happen, but in case (to prevent program crash) */
RETERR (5, NULL); /* A rare error due to a bug in the program ... */
}
strcpy (pPath, pcDir);
Slash (pPath);
strcat (pPath, "sm_");
iDirLen = strlen (pPath);
for (;;) /* Loop until we find an unique filename (maybe forever :-) */
{
/* Loop to build a random filename, using table of legal characters */
for (iMaxFile = 5, pPtr = pPath + iDirLen;
iMaxFile > 0;
iMaxFile--, *pPtr++ = cLegalChrs[rand () % iLegalChrsLen]);
*pPtr = '\0'; /* Terminate the path */
strcat (pPtr, ".tmp");
/* Try to open without create */
if ((pFile = FOpen (pPath, "r")) == NULL)
{
/* The suggested filename doesn't already exist, so safely create it */
if ((pFile = FOpen (pPath, "w")) == NULL)
{
/* Failed on create temporary file: %s */
RETERR (9, pPath);
}
FClose (pFile);
return OK;
}
FClose (pFile);
}
} /* CreateUniqueFile (); */