2 * @file serviceOptions.c
6 * @author Copyright (c) 2004 - 2009 CERN. Georgievskiy Yury
8 * @date Created on 27/02/2004
10 #include "serviceOptions.h"
11 #include "driverGen.h"
13 static srvopt_c srv_opt_c
; /* container that holds command line args */
16 * @brief Arguments amount and their forman supposed to be correct! No
17 * checking is performed.
23 * @return 1 - error occurs.
25 int SetSrvOptArgs(srvarg cur_arg
, ...)
29 va_start(ap
, cur_arg
);
34 vsnprintf(srv_opt_c
.srv_vf_dir
, sizeof(srv_opt_c
.srv_vf_dir
),
47 * @brief All service driverGen options are processed here.
50 * @param pn -- prog name
52 * To call service option you should call dgII with -srv option:
55 * Supported service options are:
56 * 1. Creating of the version file within already existing driver directory.
59 * b. driver directory, where to create versioin files.
62 * @return negative value - error occurs.
64 int ProcessSrvOpt(srvarg cur_arg
, char *pn
)
70 FILETYPE cur_ft
; /* current file type */
71 rstat cc
; /* driverGen error codes */
76 /* version files will be created only if appropriate destanation
77 directory already exist and version file is not yet created.
78 Existing version files will not be corrupted in this case.
80 Parameters for this service command are:
83 3. Driver directory */
84 if (cur_arg
== SRV_VF_DRVR
) {
86 TranslationSetDriverType("DRVR");
87 TranslationSetFancyString("Driver");
90 TranslationSetDriverType("SIM");
91 TranslationSetFancyString("Simulator");
94 /* first, check if driver directory exist */
95 snprintf(file_path
, sizeof(file_path
), "%s/%s", get_mid(NULL
),
96 srv_opt_c
.srv_vf_dir
);
97 if (stat(file_path
, &status
)) {
98 fprintf(stderr
, "[%s] %s: Module driver directory"
99 " doesn't exist!\n", pn
, file_path
);
100 return -1; /* fail */
103 /* second, check if expected user directory is in the place */
104 snprintf(file_path
, sizeof(file_path
), "%s/%s/%s/%s",
105 get_mid(NULL
), srv_opt_c
.srv_vf_dir
, LOCAL_INCL_DIR
,
107 cc
= MakeSafeDir(file_path
);
111 /* now check if version file is already exist */
112 GenerateFilename(cur_ft
, file_path
, "Version", ".h", file_path
);
113 file_name
= rindex(file_path
, '/');
115 if (!stat(file_path
, &status
)) {
116 fprintf(stderr
, "%s Version file (%s) already exist!\n",
117 (cur_arg
== SRV_VF_DRVR
) ? "Driver" :
118 "Simulator", file_name
);
119 return -1; /* error */
122 /* ok - we are cool. Proceed... */
123 file
= fopen(file_path
, "w"); /* create version file */
124 Translate(file
, "common", "driver/userPart/uepVers.h");
131 return 0; /* success */