home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / smapp100.zip / sm10.zip / smgoptio.c < prev    next >
C/C++ Source or Header  |  2000-05-14  |  7KB  |  220 lines

  1. /* ------------------------------------------------------------------------
  2.  *
  3.  *        File: smgoptio.c
  4.  *     Project: Source Mapper.
  5.  *     Created: April 8, 1992.
  6.  * Description: Kildekode for lagring av brukerens valg.
  7.  *
  8.  * Copyright (C) 2000 Leif-Erik Larsen.
  9.  * This file is part of the Source Mapper source package.
  10.  * Source Mapper is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published
  12.  * by the Free Software Foundation, in version 2 as it comes in the
  13.  * "COPYING" file of the XWorkplace main distribution.
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * ------------------------------------------------------------------------ */
  20.  
  21.  
  22.  
  23.  
  24. #include "smg.h"
  25.  
  26.  
  27.  
  28.  
  29. tmpnTYPE       tmpn;
  30. o_totinfoTYPE  o_totinfo ;
  31. o_funcregTYPE  o_funcreg;
  32. o_funcallTYPE  o_funcall;
  33. o_idlistTYPE   o_idlist;
  34. o_flowTYPE     o_flow;
  35. o_lineinfoTYPE o_lineinfo;
  36. o_variousTYPE  o_various;
  37. o_generateTYPE o_generate;
  38.  
  39.  
  40.  
  41.  
  42. int SetDefaultOptions ( void )
  43. /* Opprettet: Onsdag 8. april 1992.
  44.    Parameter:
  45.    Retur    : E/O.
  46.    Beskriv  : Setter alle brukerdynamiske valg til standard verdi.
  47.  
  48.               See header file for more information on the different items.
  49. */
  50. {
  51.    /* Totalinformasjon */
  52.    o_totinfo.incl    = O_YES;
  53.    o_totinfo.lin_tot = O_YES;
  54.    o_totinfo.lin_emp = O_YES;
  55.    o_totinfo.lin_com = O_YES;
  56.    o_totinfo.lin_cod = O_YES;
  57.    o_totinfo.func    = O_YES;
  58.    o_totinfo.com     = O_YES;
  59.  
  60.    /* Funksjonregister */
  61.    o_funcreg.incl    = O_YES;
  62.    o_funcreg.sort    = O_NAME;
  63.  
  64.    /* Liste over funksjonkallere */
  65.    o_funcall.incl       = O_NO;
  66.    o_funcall.sel        = O_NO;
  67.    o_funcall.list[0]    = 0;
  68.    o_funcall.riselnr    = O_YES;
  69.  
  70.    /* Liste over identifikatorer */
  71.    o_idlist.incl     = O_NO;
  72.    o_idlist.sel      = O_NO;
  73.    o_idlist.list[0]  = 0;
  74.    o_idlist.riselnr  = O_YES;
  75.  
  76.    /* Liste over kall-sekvenser */
  77.    o_flow.incl   = O_YES;
  78.    o_flow.graph  = O_NO;
  79.    o_flow.format = O_LIST;
  80.    o_flow.indent = 5;
  81.    o_flow.index  = O_YES;
  82.    o_flow.iIncExternals = O_YES;
  83.    strcpy (o_flow.deftoplev, "main");
  84.  
  85.    /* Linjeinformasjon */
  86.    o_lineinfo.incl   = O_YES;
  87.    o_lineinfo.r_llin = O_YES;
  88.    o_lineinfo.r_bloc = O_YES;
  89.    o_lineinfo.r_coml = O_YES;
  90.  
  91.    /* Informasjon om funksjoner */
  92.    o_lineinfo.r_func = O_YES;
  93.    o_lineinfo.c_ltot = O_NO;
  94.    o_lineinfo.c_empl = O_NO;
  95.    o_lineinfo.c_coml = O_NO;
  96.    o_lineinfo.c_lcod = O_NO;
  97.    o_lineinfo.c_com  = O_NO;
  98.    o_lineinfo.calist = O_YES;
  99.  
  100.    /* Diverse */
  101.    o_various.np_str    = O_NO;
  102.    o_various.np_fun    = O_NO;
  103.    o_various.np_sect   = O_NO;
  104.    o_various.column    = O_TABULAT;
  105.    o_various.del       = O_YES;    /* Delete .smg-files after use */
  106.    o_various.gencom    = O_YES;
  107.    o_various.twidth    = 8;
  108.    o_various.iShowInfo = 3;        /* Detailed information on screen */
  109.    o_various.newpag[0] = 0;
  110.  
  111.    /* Generer */
  112.    o_generate.gen        = O_ALL;
  113.    o_generate.met        = O_MAKE;
  114.    strcpy (o_generate.obj, BigStr (2, ".", DIRSPLITSTR));
  115.    strcpy (o_generate.map, BigStr (2, ".", DIRSPLITSTR));
  116.    strcpy (o_generate.tmp, BigStr (2, ".", DIRSPLITSTR));
  117.  
  118.    /* Midlertidig prosjektfil må alltid legges i samme katalog som
  119.       SM programmet ligger i, ikke i katalog for midlertidige filer.
  120.       Dette for å unngå at prosjektfil legges i katalog for midlertidige
  121.       filer f¢r midlertidig-    katalogen eventuelt spesifiseres. */
  122.  
  123.    #ifdef GUI
  124.    return OK;
  125.    #else
  126.    return (CreateUniqueFile (progdir, tmpn.projec, sizeof (tmpn.projec)));
  127.    #endif
  128. } /* SetDefaultOptions (); */
  129.  
  130.  
  131.  
  132.  
  133. int SetTmpFNames ( void )
  134. /*
  135.     Function: Create the temporary files, and the filename of them, of this
  136.               program.
  137.         Date: April 21, 1993. 22:20. By LEL.
  138.    Interface:
  139.      Returns: E/O.
  140. */
  141. {
  142.    if (!CreateUniqueFile (o_generate.tmp, tmpn.funcal, sizeof (tmpn.funcal)) ||
  143.        !CreateUniqueFile (o_generate.tmp, tmpn.lininf, sizeof (tmpn.lininf)) ||
  144.        !CreateUniqueFile (o_generate.tmp, tmpn.funreg, sizeof (tmpn.funreg)) ||
  145.        !CreateUniqueFile (o_generate.tmp, tmpn.idlist, sizeof (tmpn.idlist)) ||
  146.        !CreateUniqueFile (o_generate.tmp, tmpn.manobj, sizeof (tmpn.manobj)) ||
  147.        !CreateUniqueFile (o_generate.tmp, tmpn.sortfi, sizeof (tmpn.sortfi)) ||
  148.        !CreateUniqueFile (o_generate.tmp, tmpn.indexf, sizeof (tmpn.indexf)))
  149.    {
  150.       RETURN_ERR;
  151.    }
  152.  
  153.    return (OK);
  154. } /* SetTmpFNames (); */
  155.  
  156.  
  157.  
  158.  
  159. int CreateUniqueFile ( const char *pcDir, char *pPath, int iMaxPath )
  160. /*
  161.     Function: Create an unique (temporary) file in specified directory.
  162.               The file will have the name "sm_zzzzz.tmp".
  163.      Created: December 12, 1995. 22:40. By Leif-Erik Larsen.
  164.    Interface: pcDir    = Directory of where to create the temporary file.
  165.               pPath    = Buffer of where to return the complete path.
  166.               iMaxPath = Size of the pPath buffer.
  167.        Retur: E/O.
  168.      Comment: This function do not test if the specified directory realy
  169.               exist. It is up to the caller to test this before calling
  170.               this function.
  171. */
  172. {
  173.    FILE *pFile;
  174.    char *pPtr;
  175.    char cLegalChrs[] = "0123456789abcdefghijklmnopqrstuvw";
  176.    int iLegalChrsLen = strlen (cLegalChrs);
  177.    int iDirLen = strlen (pcDir);
  178.    int iMaxFile = iMaxPath - iDirLen - 2; /* Keep room for '\\' and '\0' */
  179.  
  180.    if (iMaxFile < 12)
  181.    {
  182.       /* This should never happen, but in case (to prevent program crash) */
  183.       RETERR (5, NULL);   /* A rare error due to a bug in the program ... */
  184.    }
  185.  
  186.    strcpy (pPath, pcDir);
  187.    Slash (pPath);
  188.    strcat (pPath, "sm_");
  189.    iDirLen = strlen (pPath);
  190.  
  191.    for (;;)  /* Loop until we find an unique filename (maybe forever :-) */
  192.    {
  193.       /* Loop to build a random filename, using table of legal characters */
  194.       for (iMaxFile = 5, pPtr = pPath + iDirLen;
  195.            iMaxFile > 0;
  196.            iMaxFile--, *pPtr++ = cLegalChrs[rand () % iLegalChrsLen]);
  197.  
  198.       *pPtr = '\0'; /* Terminate the path */
  199.  
  200.       strcat (pPtr, ".tmp");
  201.  
  202.       /* Try to open without create */
  203.       if ((pFile = FOpen (pPath, "r")) == NULL)
  204.       {
  205.          /* The suggested filename doesn't already exist, so safely create it */
  206.          if ((pFile = FOpen (pPath, "w")) == NULL)
  207.          {
  208.             /* Failed on create temporary file: %s */
  209.             RETERR (9, pPath);
  210.          }
  211.  
  212.          FClose (pFile);
  213.  
  214.          return OK;
  215.       }
  216.  
  217.       FClose (pFile);
  218.    }
  219. } /* CreateUniqueFile (); */
  220.