2 * @file serviceOptions.c
6 * @author Copyright (C) 2004 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
8 * @date Created on 27/02/2004
10 * @section license_sec License
11 * Released under the GPL
13 #include "serviceOptions.h"
14 #include "driverGen.h"
16 static srvopt_c srv_opt_c
; /* container that holds command line args */
19 * @brief Arguments amount and their forman supposed to be correct! No
20 * checking is performed.
26 * @return 1 - error occurs.
28 int SetSrvOptArgs(srvarg cur_arg
, ...)
32 va_start(ap
, cur_arg
);
37 vsnprintf(srv_opt_c
.srv_vf_dir
, sizeof(srv_opt_c
.srv_vf_dir
),
50 * @brief All service driverGen options are processed here.
53 * @param pn -- prog name
55 * To call service option you should call dgII with -srv option:
58 * Supported service options are:
59 * 1. Creating of the version file within already existing driver directory.
62 * b. driver directory, where to create versioin files.
65 * @return negative value - error occurs.
67 int ProcessSrvOpt(srvarg cur_arg
, char *pn
)
73 FILETYPE cur_ft
; /* current file type */
74 rstat cc
; /* driverGen error codes */
79 /* version files will be created only if appropriate destanation
80 directory already exist and version file is not yet created.
81 Existing version files will not be corrupted in this case.
83 Parameters for this service command are:
86 3. Driver directory */
87 if (cur_arg
== SRV_VF_DRVR
) {
89 TranslationSetDriverType("DRVR");
90 TranslationSetFancyString("Driver");
93 TranslationSetDriverType("SIM");
94 TranslationSetFancyString("Simulator");
97 /* first, check if driver directory exist */
98 snprintf(file_path
, sizeof(file_path
), "%s/%s", get_mid(NULL
),
99 srv_opt_c
.srv_vf_dir
);
100 if (stat(file_path
, &status
)) {
101 fprintf(stderr
, "[%s] %s: Module driver directory"
102 " doesn't exist!\n", pn
, file_path
);
103 return -1; /* fail */
106 /* second, check if expected user directory is in the place */
107 snprintf(file_path
, sizeof(file_path
), "%s/%s/%s/%s",
108 get_mid(NULL
), srv_opt_c
.srv_vf_dir
, LOCAL_INCL_DIR
,
110 cc
= MakeSafeDir(file_path
);
114 /* now check if version file is already exist */
115 GenerateFilename(cur_ft
, file_path
, "Version", ".h", file_path
);
116 file_name
= rindex(file_path
, '/');
118 if (!stat(file_path
, &status
)) {
119 fprintf(stderr
, "%s Version file (%s) already exist!\n",
120 (cur_arg
== SRV_VF_DRVR
) ? "Driver" :
121 "Simulator", file_name
);
122 return -1; /* error */
125 /* ok - we are cool. Proceed... */
126 file
= fopen(file_path
, "w"); /* create version file */
127 Translate(file
, "common", "driver/userPart/uepVers.h");
134 return 0; /* success */