home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
b
/
bmh02src.zip
/
ALI.C
next >
Wrap
C/C++ Source or Header
|
1992-08-16
|
2KB
|
102 lines
/*
ali.c : Copyright Paul Healy, EI9GL, 1992.
920726 : Created
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dir.h>
#include <process.h>
#include "rc.h"
#include "help.h"
#include "misc.h"
#ifdef BMH
#define main ali_main
#endif
static void
dumpline(char *s)
{
rip(s);
while (*s)
if (isspace(*s))
s++;
else {
while (*s && !isspace(*s))
putchar(*s++);
putchar(' ');
}
}
static int
getalias(char *s)
{
FILE *fp = fopen(getrc(alias), "r");
char line[256], al[128];
if (fp == NULL)
return -1;
while (fgets(line, sizeof(line), fp) != NULL) {
newalias:
if ( isspace(line[0]) || (line[0] == '#') || (line[0] == '\0') )
continue;
sscanf(line, "%s", al);
if (s == NULL)
printf("%s: ", al);
if ( (s==NULL) || (strncmp(s, al, strlen(al)) == 0) ) {
dumpline(line+strlen(al));
while (fgets(line, sizeof(line), fp) != NULL) {
if (!isspace(line[0]))
if (s != NULL) {
fclose(fp);
return 0;
}
else {
putchar('\n');
goto newalias; /* Yeh! */
}
dumpline(line);
}
if (feof(fp) || (s != NULL)) {
fclose(fp);
return -1;
}
}
}
fclose(fp);
return -1;
}
int
main(int argc, char *argv[])
{
int i;
dohelp(argc, argv, "ali [alias1 alias2 ... aliasn]");
if (setupbm()==-1)
return -1;
if (argc == 1)
getalias(NULL);
else
for (i=1; i<argc; i++) {
if ( getalias(argv[i]) == -1)
fputs(argv[i], stdout);
if (i != (argc-1))
putchar('\n');
}
return 0;
}