home *** CD-ROM | disk | FTP | other *** search
- /* ASK v2.1 A CLI command written in C. June 25,1987
- * (c)Copyright 1987 by Ed Holzknecht
- *
- * This is based on a assembly program by Dewi Williams called "ask".
- * I wrote Ask1.0 as a C version of the assembly program.
- * This is my new version of ASK. It has one main difference from the old
- * version. This one is user-definable. In other words, you can define
- * any test string you want, without the need to re-compile the code.
- *
- * EXAMPLE: ask d newtest
- * Ask would now be set to test for 'newtest' in a batch file:
- *
- * echo "Load oldtest or newtest"
- * failat 20
- * ask
- * if not error
- * run newtest
- * else
- * run oldtest
- * NOTE: The test string should be 7 characters or less in length.
- * When ASK is re-defined, it MUST be in the root directory, or the
- * file won't be found!!
- * The test string IS case dependent - Test is NOT the same as test!
- * A carriage return as a response will NOT return an error from ASK.
- *
- * Compiled with Manx Aztec C, version 3.20.
- * Use, abuse, misuse, or copy this to your heart's content; as long as it
- * is a non-commercial application. If you can re-write it so the program
- * is better or smaller, let me know how you did it!
- *
- * Ed Holzknecht
- * CIS 70357,3331
- * or call Blacksmith's Shoppe BBS 502-776-4313 11:00pm - 9:00am
- * Louisville, Ky.
- ***************************************************************************/
- #include "stdio.h"
-
- char *defstr = "\0\0\0\0\0\0\0\0"; /* The string that gets re-defined */
- FILE *fp;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int c,i=0;
- char a[8];
- void rewrite_it();
-
- if(argc > 1) {
- if(strcmp(argv[1], "d")) {
- puts("USAGE...ASK d newtest");
- puts("Newtest must be 7 characters or less.");
- _exit(10);
- }
- rewrite_it(argv);
- }
- while((a[i++] = getchar()) != '\n') /* This gets the string to be */
- ; /* tested and NULL terminates */
- a[--i] = '\0'; /* it. Then strncmp tests the */
- if((strncmp(defstr,a,i)) == 0) /* string against 'defstr' for */
- _exit(0); /* a length of 'i' characters. */
- else
- _exit(10);
- }
-
- void rewrite_it(argv)
- char *argv[];
- {
- long offset = 0x002e; /* Offset for the re-write from start*/
- int count,space; /* of file. */
-
- count = strlen(argv[2]); /* This may be sloppy, but it's the */
- if(count > 7) { /* only way I could figure out how */
- puts("Too many characters. Limit 7.");
- _exit(10); /* to pad the string with NULLs so */
- } /* the string test would work. */
- space = 8-count;
- for(;space == 0; space--)
- argv[2][++count] = '\0';
- if((fp = fopen("ask", "r+")) == NULL) {
- puts("Can't open ASK for re-definition.");
- _exit(10);
- }
- fseek(fp,offset,0); /* This finds the place on the */
- if(fwrite(argv[2],1,8,fp)== -1) { /* disk where the string lives */
- puts("ERROR. Write failed."); /* and writes the replacement. */
- exit(10);
- }
- puts("ASK re-defined.");
- exit(0);
-
- }
-
-
-