1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
* TYPE.C - type internal command
*
* Comments:
*
* 07/08/1998 (John P. Price)
* started.
*
* 07/12/98 (Rob Lake)
* - Changed error messages
*
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* - added config.h include
*
* 10-Aug-1998 ska
* - added ^Break checking
*
* 1999/01/24 ska
* add: support for CP/M style device names (openf.h)
*/
#include "../config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "../include/cmdline.h"
#include "../include/command.h"
#include "../err_fcts.h"
#include "../include/openf.h"
#include "../strings.h"
int cmd_type(char *param)
{
char buf[256];
char **argv;
int argc, opts, ec = E_None;
FILE *f;
if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
return 1;
/* Because no option was passed into scanCmdline() no
option can have been processed */
assert(opts == 0);
if(!argc) {
error_req_param_missing();
ec = E_Useage;
goto errRet;
}
for(argc = 0; argv[argc]; ++argc) {
if((f = fdevopen(argv[argc], "rt")) == 0) {
error_sfile_not_found(argv[argc]);
ec = E_Other;
break;
}
while(fgets(buf, sizeof(buf), f)) {
if(cbreak) {
fclose(f);
ec = E_CBreak;
goto errRet;
}
fputs(buf, stdout);
}
fclose(f);
if(cbreak) {
ec = E_CBreak;
break;
}
}
errRet:
freep(argv);
return ec;
}
|