📄 getcmd.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)getcmd.c 4.2 (ULTRIX) 10/10/90";#endif lint/** .TITLE GETCMD - Parse and verify a command line.* .IDENT /1-001/** COPYRIGHT (C) 1985 DIGITAL EQUIPMENT CORP.,* CSSE SOFTWARE ENGINEERING* MARLBOROUGH, MASSACHUSETTS** THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY ON A * SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH THE INCLUSION* OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE, OR ANY OTHER* COPIES THEREOF, MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE* TO ANY OTHER PERSON EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO* AGREES TO THESE LICENSE TERMS. TITLE TO AND OWNERSHIP OF THE* SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.** THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT* NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL* EQUIPMENT CORPORATION.** DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF* ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.**++** FACILITY: [ FMA Software Tools - Detail Design ]** ABSTRACT:** These functions are used to read an ULTRIX command line* and to parse it into a parse tree that can be verified* * ENVIRONMENT: ULTRIX-32 C* * AUTHOR: Luis Arce, CREATION DATE: 19-Nov-85** MODIFIED BY:***--*/#include "ueliterals.h"#include "uestruct.h"#include "uerror.h"#include "eiliterals.h"#include "erms.h"#include "generic_dsd.h"#include "std_dsd.h"#include <stdio.h>#include <sys/time.h>/**++*=*=*=MODULE FLOW - getcmd.c*=*= a - parse_cmd(argc,argv) Validates syntax,*= builds parse tree.*= while (args)*= {*= if (flag)*= {*= validate flags*= make_tree(root_tree,flag) (* b)*= }*= if (param)*= {*= malloc(param struct)*= chain to tree*= }*= }*= return(UE$SUCC)*=*= b - make_tree(tree,flag) Recursive routine *= searches tree for dup*= entry, alloc new branch.*= if(tree == NULL)*= malloc(param struct)*= else*= make_tree(root_tree,flag) (* b)*= return(tree)*=*= c - valid_tool(tree) Validates branches*= if (get_tree(UE$FLG_n)) socket (* f)*= {*= es$open(ctx,event,mailbox,NULL,segs...) (esopen.c)*= }*= if (get_tree(UE$FLG_f)) file (* f)*= {*= fopen(config_file)*= get path*= fclose()*= gethostname(string)*= es$open(ctx,event,stat,f_name,segs...) (esopen.c)*= }*= if (get_tree(UE$FLG_b)) bin output (* f)*= es$open(ctx,event,append,f_name,segs...) (esopen.c)*=*= if (get_tree(UE$FLG_o | Z | S)) (* f)*= set flags on in_structure*= return(UE$SUCC)*=*= d - valid_gen(parse_tree) Validates all other flags.*= Builds a selection tree.*= Lets es$parse validate tree.*= if (get_tree(UE$FLG_?)) (* f)*= {*= get_devtype(device,status) (* e)*= asctotime(asc_date) (* h)*= es$parse(stat,item_id,input) (select.c)*= es$mkselectnode(op,new_node,old_node,NULL) (select.c)*= es$select(ctx,ES$AND,sel_tree) (esopen.c)*= }*= return(UE$SUCC)*=*= e - get_devtype(label,status) find label in bin file.*= find_std_item_dsd(item_id) (dsd_access.c)*= find_std_code_dsd(item_dsd_ptr,index) (dsd_access.c)*= dsd_get_label(LABEL_IX) (dsd_access.c)*= es$parse(stat,item_id,input) (select.c)*= es$mkselectnode(op,new_node,old_node,NULL) (select.c)*= return(node)*= *= g - help() Prints the file 'uerf.hlp'.*= find_file(UE$HLP_FILE) (uerf.c)*= fopen()*= while(fgets(line))*= printf(line)*= return(UE$SUCC)*=*= f - get_tree(flag) Searches for tree node*= return(tree)*=*= h - asctotime(asc_date) Converts ascii time to*= unsigned long.*= gettimeofday()*= localtime()*= parsetime(asc_date,time_struct) (* i)*= return(date)*=*= i - parsetime(asc_date,time_struct) Fills in time structure*=*--*/extern struct in_struc in_st;ES$DECLARE(extern,EIS,ueis);ES$DECLARE(extern,DIS,udis);ES$DECLARE(extern,SDS,usds);ES$DECLARE(extern,CDS,ucds);ES$DECLARE(extern,ADS,uads);ES$DECLARE(extern,SIS,usis);ES$STREAM(extern,uctx);/** .SBTTL parse_cmd - function to parse ULTRIX command line.*++* FUNCTIONAL DESCRIPTION: ** - Validates command syntax.* - Builds parse tree.* - Returns syntax validated or error code.** FORMAL PARAMETERS: ** argc argument count* argv command line arguments** IMPLICIT INPUTS: none** IMPLICIT OUTPUTS: none** COMPLETION STATUS: UE$SUCC = successful* UE$FAIL = failure** SIDE EFFECTS: none**--*//*... FUNCTION parse_cmd (argc,argv) */long parse_cmd (argc,argv)short argc;char *argv[];{struct parse_tree *tree;struct parm_struc *parm, *xparm;char *malloc();static char flg_tbl[] = { UE$FLG_f, UE$FLG_r, UE$FLG_t, UE$FLG_h, UE$FLG_n, UE$FLG_x, UE$FLG_c, UE$FLG_D, UE$FLG_T, UE$FLG_u, UE$FLG_e, UE$FLG_O, UE$FLG_M, UE$FLG_A, UE$FLG_o, UE$FLG_H, UE$FLG_s, UE$FLG_R, UE$FLG_Z, UE$FLG_S, UE$FLG_b, '\0' };long status;char *f;short i,j;short plen, len;in_st.root = UE$NULL;while (--argc > 0) { *++argv; if (*argv[0] == '-') { if (strlen(argv[0]) == 1) return(UE$ERR_INVFLG); for (f = argv[0]+1; *f != '\0'; f++) { for (i=0;;i++) { if (flg_tbl[i] == *f) break; if (flg_tbl[i] == '\0') return(UE$ERR_INVFLG); if (*f == UE$FLG_h) { if ((status = help()) != UE$SUCC) return(status); else return(UE$DONE); } } status = make_tree(in_st.root,*f); if (status == UE$ERR_DUPFLG) return(UE$ERR_DUPFLG); in_st.root = (struct parse_tree *)status; } } else { if (in_st.last == UE$NULL) return(UE$ERR_INVPAR); tree = in_st.last; plen = strlen(*argv); j = 0; while (j < plen) { if (tree->parm_list == UE$NULL) { parm = (struct parm_struc *) malloc(sizeof(struct parm_struc)); tree->parm_list = parm; } else { while (parm->next_parm != UE$NULL) { parm = parm->next_parm; } parm->next_parm = (struct parm_struc *) malloc(sizeof(struct parm_struc)); parm = parm->next_parm; } parm->next_parm = UE$NULL; parm->parm_string = *argv+j; j += (1 + (len = strcspn(*argv+j,","))); (*argv)[j-1] = '\0'; } } } return(UE$SUCC);}/*... ENDFUNCTION parse_cmd *//** .SBTTL make_tree - Function to create a parse tree limb.*++* FUNCTIONAL DESCRIPTION: ** - Searches to end of tree for duplicate entry.* - Allocates space for next tree structure.* - Returns valid tree address or error code.** FORMAL PARAMETERS: *** IMPLICIT INPUTS: NONE** IMPLICIT OUTPUTS: New tree branch** COMPLETION STATUS: Address of tree branch if successful* UE$FAIL = failure** SIDE EFFECTS: NONE**--*//*... FUNCTION make_tree(flag) */int make_tree (nx,fl)struct parse_tree *nx;char fl;{long status;char *malloc();if (nx == UE$NULL) /* find end of chain */ { /* Make a new node */ nx = (struct parse_tree *) malloc(sizeof(struct parse_tree)); in_st.last = nx; nx->flag[0] = fl; /* Save the flag ident */ nx->parm_list = UE$NULL; /* NULL param list ptr */ nx->next_tree = UE$NULL; /* NULL next tree point */ }else { if (nx->flag[0] == fl) /* Duplicate flag? */ { return(UE$ERR_DUPFLG); } /* get next branch */ status = make_tree(nx->next_tree,fl); if (status == UE$ERR_DUPFLG) return(UE$ERR_DUPFLG); nx->next_tree = (struct parse_tree *)status; }return((int)nx);}/*... ENDFUNCTION make_treee(root, flag) *//** .SBTTL valid_tool - Function to validate UERF specific input.*++* FUNCTIONAL DESCRIPTION: ** - Validates all UERF specific input.* - Calls erm_open who validates input files.* - Returns valid UERF info or error code.** FORMAL PARAMETERS: ** IMPLICIT INPUTS: none** IMPLICIT OUTPUTS: validated UERF specific input** COMPLETION STATUS: UE$SUCC = successful* UE$FAIL = failure** SIDE EFFECTS: NONE**--*//*... FUNCTION valid_tool () */long valid_tool (){struct parse_tree *get_tree();struct parse_tree *tree;struct parm_struc *parm;char pstring[UE$XFF];int i, j;FILE *cfp;char *cp, *cp2;char line[256];int dataflg = 0;long status;/************** PROCESS "n" FLAG ********************************/ /* get "n" flag tree */if (( tree = get_tree(UE$FLG_n)) != UE$NULL) { if (tree->parm_list != UE$NULL) return(UE$ERR_INVPAR); in_st.kernel = TRUE; if (get_tree(UE$FLG_f) != UE$NULL) return(UE$ERR_INCOMP); if (get_tree(UE$FLG_t) != UE$NULL) return(UE$ERR_INCOMP); if (get_tree(UE$FLG_R) != UE$NULL) return(UE$ERR_INCOMP); if (get_tree(UE$FLG_S) != UE$NULL) return(UE$ERR_INCOMP); if (es$open(&uctx,ES$EVENT,ES$MAILBOX,NULL, &ueis,&udis,&usds,&ucds,&uads,&usis) != ES$SUCC) { return(UE$ERR_K_OPEN); /* unable to open socket*/ } }else {/************** PROCESS "f" FLAG ********************************/ in_st.kernel = FALSE; cfp = fopen(UE$FILE_CONF,"r"); if (cfp == NULL) return(UE$ERR_NOCONF); i = 0; while (fgets(line,sizeof(line),cfp) != NULL) { cp = line; if (*cp == '#' && dataflg == 0) continue; if (*cp == '}') break; if (*cp == '{') { dataflg++; continue; } if (dataflg > 0) { if ( i == 2) { while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '#') /* no data string */ { (void)fclose(cfp); return(UE$ERR_CONFIG); } cp2 = cp; while (*cp2 != ' ' && *cp2 != '\t' && *cp2 != '\n' && *cp2 != '#') cp2++; *cp2 = '\0'; (void)strcpy(pstring,cp); (void)strcat(pstring,"/syserr."); break; } i++; } } (void)fclose(cfp); gethostname(pstring+strlen(pstring), UE$HST_LEN); /* get "f" flag tree */ if (( tree = get_tree(UE$FLG_f)) != UE$NULL) { if (( parm = tree->parm_list) == UE$NULL) return(UE$ERR_INVPAR); (void)strcpy(pstring, parm->parm_string); if (parm->next_parm != UE$NULL) return(UE$ERR_INVPAR); } if (get_tree(UE$FLG_R) != UE$NULL) status = EI$REVERSE; else status = ES$VIEW; if (es$open(&uctx,ES$EVENT,status,pstring,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -