home *** CD-ROM | disk | FTP | other *** search
- /* open.c
-
- This program impliments an open command for batch files.
- What open actually does is simply remember a file name and
- initialize a file position. Both of these are saved as strings
- in the environment string. It is up to READ and WRITE to
- re-open the file each time, position it in the right place,
- read a line, and update the position in the environment.
-
- To use open in a batch file type:
-
- OPEN <handle> <pathname>
-
- handle is any unique identifer to keep track of this file.
- pathname is the name of the file to open.
-
- OPEN returns errorlevel=0 for failure, 1 for success
-
- See READ and WRITE for how to manipulate these files.
- */
-
- #include <stdio.h>
-
- extern char *env; /*pointer to start of environment string*/
- extern char *tem; /*temporary pointer for searching*/
- extern int enl; /*length of environment in bytes*/
-
- extern char *search_for(); /*searches environment for string*/
- extern del_string(); /*deletes a string from the environment*/
- extern int ins_string(); /*insert a new string in the environment*/
-
- char name[128]="n_"; /*space for the file name string*/
- char pos[64]="p_"; /*space for the file position string*/
-
- main(argc,argv) /*main part of open program*/
- int argc;
- char *argv[];
- {
- int arg=1; /*where to look for arguments*/
-
- if (argc<2) /*do I have enough arguments?*/
- {
- printf("Usage: OPEN <handle> <pathname>\r\n");
- exit(1); /*exit if no file name*/
- }
- if (argc<3) /*if there is only one argument,*/
- arg=0; /*use it as the file name*/
- enl=getenv(&env); /*get the environment string*/
- strcat(name,argv[arg]); /*build the file name string*/
- strcat(name,"=");
- del_string(name); /*delete any old string with same handle*/
- strcat(name,argv[arg+1]);
- ins_string(name); /*insert this name into environment*/
- strcat(pos,argv[arg]); /*build the file position string*/
- strcat(pos,"=");
- del_string(pos); /*delete any old string with same handle*/
- strcat(pos,"0"); /*initial position is zero*/
- ins_string(pos); /*insert this into the environment*/
- exit(0);
- }