home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / dirutl / go.arc / GO.C next >
Encoding:
C/C++ Source or Header  |  1987-11-04  |  3.6 KB  |  140 lines

  1. /*
  2.  
  3.        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.        ;                                  ;
  5.        ;                                  ;
  6.        ;       ~~          ~~         ~~        ~~    ;
  7.        ;    ~~~~~~~        ~~~~~~~          ~~~~~~~         ~~~~~~~  ;
  8.        ;     ~~~~~~   ~     ~~~~~~   ~       ~~~~~~   ~      ~~~~~~   ~  ;
  9.        ;    ~~~~~~       ~~~~~~      ~~~~~~     ~~~~~~       ;
  10.        ;   ~~~~~~~~      ~~~~~~~~     ~~~~~~~~    ~~~~~~~~      ;
  11.        ;  ~~~~~~~~~~~    ~~~~~~~~~~~~~    ~~~~~~~~~~~~   ~~~~~~~~~~~~   ;
  12.        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  13.        ;~~ copyright ~~~~ (c) ~ 1982 ~~~ oceanwave ~~~~ softworks ~~~~;
  14.        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  15.        ;~~ 516    forward street ~~~~~~~~~ la jolla  ca ~~~~~~~ 92037 ~~;
  16.        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  17.        ;~~~~~ all information contained herein is proprietary ~~~~~~~~;
  18.        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  19.        ;~~~~~~~~~~~~~~~ to oceanwave softworks ~~~~~~~~~~~~~~~~~~~~~~~;
  20.        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  21.        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.  
  23.  
  24.  
  25. WRITTEN BY:    DION HOLLENBECK       hollen@megatek.UUCP
  26. DATE:        NOVEMBER 3, 1987
  27.         
  28.  
  29. This program is placed in the public domain and may be freely copied and
  30. distributed with the following stipulations.  It is not to be sold.  It
  31. is to be distributed in its entirety with all files listed herein included.
  32.  
  33. Please contact me with suggestions for improvements and reports of
  34. problems.  If you enjoy using this program and feel it is worth it,
  35. a donation would appreciated.
  36.  
  37. Written for Microsoft C 4.0.
  38.  
  39. */
  40. #include <local.h>
  41. #include <dos.h>
  42. #include <process.h>
  43. #include <stdio.h>
  44. #include <ctype.h>
  45. #include <direct.h>
  46. #include <string.h>
  47.  
  48. #define MAXLINE 80
  49.  
  50. main(argc,argv)
  51. int    argc;
  52. char    *argv[];
  53. {
  54.     char        exepath[80];
  55.     char        *goptr;
  56.     int        gopos;
  57.     FILE        *godat;
  58.     char        line[81];
  59.     int        result;
  60.  
  61. /*  check for proper usage  */
  62.  
  63.     if (argc < 2)
  64.     {
  65.         printf("Go:  Usage:  go directory_mnemonic \n");
  66.         exit(1);
  67.     }
  68.  
  69.  
  70. /*  parse argv[0] for pathname of where this program was executed from    */
  71.  
  72.     strcpy(exepath, argv[0]);
  73.     goptr = strstr(exepath, "GO.EXE");
  74.     gopos = (int)(goptr - exepath);
  75.     exepath[gopos] = '\0';
  76.     strcat(exepath,"GO.DAT");
  77.  
  78. /*  open data file GO.DAT in same directory that program was found  */
  79.  
  80.     if ((godat = fopen(exepath,"rt")) == NULL)
  81.     {
  82.         fprintf(stderr,"Could not open file %s", exepath);
  83.         exit(1);
  84.     }
  85.  
  86. /*  scan file for match on directory mnemonic and do chdir if found  */
  87.  
  88.     result = 1;
  89.     while ((fgets(line, MAXLINE, godat) != NULL) && (result != NULL))
  90.     {
  91.         result = dodir(line, argv[1]);
  92.     }
  93.     if (result != NULL)
  94.         fprintf(stderr,"Mnemonic  '%s'  not found\n",argv[1]);
  95.     fflush(godat);
  96.     fclose(godat);
  97.     exit(0);
  98. }
  99.  
  100.  
  101.  
  102. int
  103. dodir(line,argptr)
  104.  
  105. char    *line;
  106. char    *argptr;
  107. {
  108.  
  109.     char    *token0;
  110.     char    *token1;
  111.     char    *token2;
  112.     char    newpath[80];
  113.     char    newdrive[4];
  114.     unsigned int    dosdx;
  115.  
  116. /*   parse first token and compare to command line argument  */
  117. /*   if it matches, parse other tokens and set drive and path    */
  118.  
  119.  
  120.     token0 = strtok(line, " ,;");
  121.     if (token0[0] == '#')
  122.         return(1);
  123.     if (strcmpi(argptr, token0) == 0)
  124.     {
  125.         token1 = strtok(NULL, " ,;");
  126.         strcpy(newpath, token1);
  127.         token2 = strtok(NULL, " ,;");
  128.         if ((token2 != NULL) && (token2[0] != '#'))
  129.         {
  130.             strcpy(newdrive,token2);
  131.             dosdx = (unsigned int) (toupper (newdrive[0]) - 64 - 1);
  132.             bdos (14, dosdx, 0);
  133.  
  134.         }
  135.         chdir(newpath);
  136.         return(NULL);
  137.     }
  138.     return(1);
  139. }
  140.