[net.sources] Yet Another Push for

cxd@genrad.UUCP (Craig Dawson X2267) (08/06/86)

-------

    Below is a shar for push, pop, and dirs for the PC/AT.
They are written in Microsoft 'C'.  I wrote (reads: hacked)
them because the public domain version I had wouldn't work with
the JOIN command.  To compile use the 'cl' or 'msc' with your
favorite options (I didn't use any).  Please E-Mail any questions,
I will try to reply promptly.


		Enjoy,

			Craig


---------------------------------------------------------
...decvax!genrad!cxd    (Craig Dawson x2267)

 What's a little metamorphosis between friends?

 Disclaimer: all standard one's apply

----------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	dirs.c
#	pop.c
#	push.c
# This archive created: Tue Aug  5 16:19:41 1986
# By:	Craig Dawson X2267 (GenRad, Inc. Test Systems & Instruments Group Concord, MA)
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'dirs.c'" '(841 characters)'
if test -f 'dirs.c'
then
	echo shar: "will not over-write existing file 'dirs.c'"
else
cat << \Yet-Another-Tool > 'dirs.c'
/* dirs.c              Thu Jul 31 16:48:52 1986  cxd  Author                */

#include <stdio.h>
#include <direct.h>
#include <stdlib.h>

#define     BUF_LEN     100


main(argc, argv)

int argc;
char *argv[];
{
   char buffer[BUF_LEN + 1];
   FILE *fid_in;
   char storage_for_stack_file[13], *stack_file;

   if ((stack_file = getenv("DIRS")) == NULL)
      {
      strcpy(storage_for_stack_file, "\\%%dirs.dat");
      stack_file = storage_for_stack_file;
      }

   if ((fid_in = fopen(stack_file, "r")) == NULL)
      {
      printf("dirs: directory stack empty.\n");
      exit(1);
      }

   while (!feof(fid_in))
      {
      if (fgets(buffer, BUF_LEN, fid_in) != NULL)
         {
         buffer[strlen(buffer) - 1] = '\0';
         printf("%s ", buffer);
         }
      }
   printf("\n");

   fclose(fid_in);
   exit(0);
}

Yet-Another-Tool
fi
echo shar: "extracting 'pop.c'" '(1462 characters)'
if test -f 'pop.c'
then
	echo shar: "will not over-write existing file 'pop.c'"
else
cat << \Yet-Another-Tool > 'pop.c'
/* pop.c               Thu Jul 31 16:48:52 1986  cxd  Author                */

#include <stdio.h>
#include <direct.h>
#include <stdlib.h>

#define     BUF_LEN     100


main(argc, argv)

int argc;
char *argv[];
{
   char buffer[BUF_LEN + 1], dir[BUF_LEN + 1];
   int wrote_out = 0;
   FILE *fid_in, *fid_out;
   char storage_for_stack_file[13], *stack_file;

   if ((stack_file = getenv("DIRS")) == NULL)
      {
      strcpy(storage_for_stack_file, "\\%%dirs.dat");
      stack_file = storage_for_stack_file;
      }

   if ((fid_in = fopen(stack_file, "r")) == NULL)
      {
      printf("pop: directory stack empty.\n");
      exit(1);
      }

   if ((fid_out = fopen(stack_file, "w")) == NULL)
      {
      perror("couldn't open data file");
      exit(1);
      }
    
   fgets(buffer, BUF_LEN, fid_in);
   buffer[strlen(buffer) - 1] = '\0';
   strcpy(dir, buffer);

   while (!feof(fid_in))
      {
      if (fgets(buffer, BUF_LEN, fid_in) != NULL)
         {
         buffer[strlen(buffer) - 1] = '\0';
         fprintf(fid_out, "%s\n", buffer);
         printf("%s ", buffer);
         wrote_out = 1;
         }
      }
   printf("\n");

   fclose(fid_in);
   fclose(fid_out);
   if (!wrote_out)
      {
      if (unlink(stack_file))
         {
         perror("couldn't delete empty data file");
         exit(1);
         }
      }

   if (chdir(dir) != NULL)
      {
      perror("couldn't change directory");
      exit(1);
      }

   exit(0);
}
Yet-Another-Tool
fi
echo shar: "extracting 'push.c'" '(2322 characters)'
if test -f 'push.c'
then
	echo shar: "will not over-write existing file 'push.c'"
else
cat << \Yet-Another-Tool > 'push.c'
/* push.c              Mon Jul 28 16:59:59 1986  cxd  Author                */

#include <stdio.h>
#include <direct.h>
#include <stdlib.h>

#define     BUF_LEN     100


main(argc, argv)

int argc;
char *argv[];
{
   char buffer[BUF_LEN + 1], dir[BUF_LEN + 1];
   FILE *fid_in, *fid_out;
   int file_there = 1, first_dir = 1;
   char storage_for_stack_file[13], *stack_file;
   void chkdir();

   if (argc > 2)
      {
      printf("usage: push [dirspec]\n");
      exit(0);
      }

   if (argc == 2)
      {
      chkdir(argv[1]);
      }

   if ((stack_file = getenv("DIRS")) == NULL)
      {
      strcpy(storage_for_stack_file, "\\%%dirs.dat");
      stack_file = storage_for_stack_file;
      }

   if ((fid_in = fopen(stack_file, "r")) == NULL)
      {
      if (argc == 1)
         {
         printf("push: directory stack empty.\n");
         exit(1);
         }
      else
         file_there = 0;
      }

   if ((fid_out = fopen(stack_file, "w")) == NULL)
      {
      perror("couldn't open data file");
      exit(1);
      }
    
   if (getcwd(buffer,BUF_LEN) == NULL)
      {
      perror("error getting current working directory");
      exit(1);
      }

   fprintf(fid_out, "%s\n", buffer);
   printf("%s ", buffer);

   if (file_there)
      {
      while (!feof(fid_in))
         {
         if (fgets(buffer, BUF_LEN, fid_in) != NULL)
            {
            buffer[strlen(buffer) - 1] = '\0';
            if (!(first_dir && argc == 1))
               {
               fprintf(fid_out, "%s\n", buffer);
               printf("%s ", buffer);
               }
            if (first_dir)
               strcpy(dir, buffer);
            first_dir = 0;
            }
         }
      }
   printf("\n");

   if (argc > 1)
      strcpy(dir, argv[1]);

   if (chdir(dir) != NULL)
      {
      perror("couldn't change directory");
      exit(1);
      }

   if (file_there)
      fclose(fid_in);
   fclose(fid_out);
   exit(0);
}


void chkdir( dirnm )

char *dirnm;
{
   char buffer[100];
   FILE *stream;

   strcpy(buffer, dirnm);
   if (strcmp(buffer, "\\") == 0)
      strcat(buffer, "%%dirs.tst", 11);
   else
      strcat(buffer, "\\%%dirs.tst", 13);
   if ((stream = fopen(buffer, "w")) == NULL)
      {
      perror(dirnm);
      exit(1);
      }
   fclose(stream);
   unlink(buffer);
   return;
}
Yet-Another-Tool
fi
exit 0
#	End of shell archive
-- 
---------------------------------------------------------
...decvax!genrad!cxd    (Craig Dawson x2267)

 What's a little metamorphosis between friends?