home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------*/
- /* */
- /* setlink */
- /* */
- /* Author: */
- /* Ted H. Emigh 23 June 1989 */
- /* */
- /* Usage: */
- /* setlink -n[filename]|-a[filename] [options and files for linker] */
- /* */
- /* Description: */
- /* setlink creates (with option -n) or appends to (with option -a) a */
- /* file with name filename. If the filename is not given (blank after */
- /* -n or -a, then the name used is FILENAME. The remainder of the */
- /* line is copied to this file. The Turbo Linker can use this file: */
- /* tlink @FILENAME (e.g., tlink @makefile.lnk). */
- /* */
- /* Return Value: */
- /* exit = 0 if no errors */
- /* 1 if the usage is incorrect. */
- /* 2 if there is a disk file error. */
- /* */
- /* Bugs: */
- /* Due to a limitation of argv, program is unable to output adjacent */
- /* <SPACE> characters to the file. Multiple spaces on the command */
- /* line are translated as a single space. */
- /* */
- /*------------------------------------------------------------------------*/
-
- #include <stdio.h>
-
- /*
- FILENAME is the default name of the file to be used.
- This name must match with the corresponding name used by the linker.
- */
- #define FILENAME "makefile.lnk"
-
- void error(int err_type); /* display error message and exit */
-
- char *fn=FILENAME;
-
- void main(int argc, char *argv[])
- {
- register int i,c;
- FILE *fp;
- char *argp;
-
- /* Get the file creation option */
- argp=argv[1];
- if( *argp=='-' || *argp=='/' ) {
- c=*++argp;
- if(*++argp) fn=argp; /* file name is given */
- switch(c) {
- case 'n': /* create file or erase existing one */
- case 'N':
- if((fp=fopen(fn,"wt"))==NULL) error(2); /* error opening file */
- break;
- case 'a': /* append to an existing file */
- case 'A':
- if((fp=fopen(fn,"at"))==NULL) error(2); /* error opening file */
- break;
- default:
- error(1); /* unknown option */
- } /* switch(*argp) */
- } /* if( *argp== ) */
- else error(1); /* no setlink file option */
-
- for(i=2;i<argc;++i) {
- if(i!=2) if(fputc(' ',fp)==EOF) error(2);
- if(fputs(argv[i],fp)==EOF) error(2);
- }
- if(fputc('\n',fp)==EOF) error(2);
- fclose(fp);
- }
-
-
- /*------------------------------------------------------------------------*/
- /* */
- /* error */
- /* */
- /* Usage: */
- /* void error(int err_type); */
- /* */
- /* Description: */
- /* Display error message and exit. */
- /* err_type = 1 command syntax. Display usage message. */
- /* 2 file error. Unable to create or write to file. */
- /* */
- /* Return Value: */
- /* Routine exits to DOS with value err_type. */
- /* */
- /*------------------------------------------------------------------------*/
-
- void error(int err_type)
- {
- switch(err_type) {
- case 1: /* misuse of command -- display correct usage */
- /* display first line of error text */
- puts("usage: setlink -n[filename]|-a[filename] [options for linker]");
-
- /* display second line of error text with file name */
- /* fputs is used rather than puts, since puts appends a newline */
- /* fputs/puts used rather than printf to save space */
- fputs("-n to create a new file ",stdout);
- puts(fn);
-
- /* display third line of error text */
- puts("-a to append to existing file");
- exit(1);
- case 2:
- puts("fatal file error");
- exit(2);
- } /* switch(err_type) */
-
- } /* error */