home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE50.TAR / mbase / src / blast.c next >
Encoding:
C/C++ Source or Header  |  1992-11-25  |  2.3 KB  |  114 lines

  1. /*
  2.  * METALBASE 5.0
  3.  *
  4.  * Released October 1st, 1992 by Huan-Ti [ richid@owlnet.rice.edu ]
  5.  *                                       [ t-richj@microsoft.com ]
  6.  */
  7.  
  8. #include "stdinc.h"
  9.  
  10. #ifndef linux
  11. #ifndef MSDOS
  12. #ifdef LONGARGS
  13.    extern char *getenv (char _FAR_ *);
  14. #else
  15.    extern char *getenv();
  16. #endif
  17. #endif
  18. #endif
  19.  
  20. void
  21. main  (argc, argv)
  22. int    argc;
  23. char **argv;
  24. {
  25.    char  buf[128], name[128], *pch;
  26.    int   i;
  27.  
  28.    if (argc == 1)
  29.       {
  30.       fprintf (stderr, "format: blast relation [relation]*\n");
  31.       exit (1);
  32.       }
  33.  
  34.    for (--argc, argv++; argc; argc--, argv++)
  35.       {
  36.       if ((*argv)[0] == '-')
  37.          {
  38.          fprintf (stderr, "blast: unrecognized switch -%c\n", (*argv)[1]);
  39.          exit (2);
  40.          }
  41.  
  42.       if (access (*argv, 0) == -1)
  43.          {
  44.          fprintf (stderr, "blast: cannot find relation %s\n", *argv);
  45.          continue;
  46.          }
  47.  
  48. /*
  49.  * First, get the basename for the relation (take off the path and/or
  50.  * extension)--put it in buf:
  51.  *
  52.  */
  53.  
  54.       name[0] = 0;
  55.  
  56.       if ((pch = strrchr (*argv, DIRSEP)) == NULL)
  57.          pch = *argv;
  58.       else
  59.          pch++;
  60.       strcpy (buf, pch);
  61.  
  62.       if (! strcmp (buf, ".rel") || ! strcmp (buf, ".REL"))
  63.          {
  64.          *(strrchr (buf, '.')) = 0;
  65.          }
  66.  
  67. /*
  68.  * Great.  Now get the temporary directory where the lockfile will be...
  69.  *
  70.  */
  71.  
  72.       if ((pch = getenv ("TMP")) != NULL || (pch = getenv ("TEMP")) != NULL)
  73.          {
  74.          strcpy (name, pch);  /* If they define a directory, use it. */
  75.          }
  76.       else                   /* Otherwise, try to guess a default directory. */
  77.          {
  78. #ifdef UNIX
  79.          strcpy (name, "/tmp");
  80. #endif
  81.          }
  82.       if (! name[0])
  83.          {
  84.          fputs ("blast: you must have a TMP directory defined.\n", stderr);
  85.          exit (3);
  86.          }
  87.       if (name[(i = strlen(name))-1] != DIRSEP)
  88.          {
  89.          name[i] = DIRSEP;
  90.          name[i+1] = 0;
  91.          }
  92.  
  93. /*
  94.  * And attach the filename + .LCK to get a lockfile name.  Then delete the
  95.  * stupid thing.
  96.  *
  97.  */
  98.  
  99.       strcat (name, buf);
  100.       strcat (name, ".lck");
  101.  
  102.       if (access (name, 0) == -1)
  103.          {
  104.          fprintf (stderr, "blast: %s was not locked\n", *argv);
  105.          continue;
  106.          }
  107.  
  108.       unlink (name);
  109.  
  110.       fprintf (stderr, "%s blasted successfully\n", *argv);
  111.       }
  112. }
  113.  
  114.