cmdline.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. /*
  2. Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2007-Mar-4 or later
  4. (the contents of which are also included in zip.h) for terms of use.
  5. If, for some reason, all these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. /*
  9. Test procedure:
  10. Compile and link (in [.VMS] directory):
  11. define vms SYS$DISK:[]
  12. set command /object ZIP_CLI.CLD
  13. cc /define = (TEST, VMSCLI) /include = [-] CMDLINE
  14. link link CMDLINE.OBJ, ZIP_CLI.OBJ
  15. Run:
  16. exec*ute == "$SYS$DISK:[]'"
  17. exec cmdline [options ...]
  18. */
  19. /* 2004-12-13 SMS.
  20. * Disabled the module name macro to accommodate old GNU C which didn't
  21. * obey the directive, and thus confused MMS/MMK where the object
  22. * library dependencies need to have the correct module name.
  23. */
  24. #if 0
  25. # define module_name VMS_ZIP_CMDLINE
  26. # define module_ident "02-006"
  27. #endif /* 0 */
  28. /*
  29. **
  30. ** Facility: ZIP
  31. **
  32. ** Module: VMS_ZIP_CMDLINE
  33. **
  34. ** Author: Hunter Goatley <goathunter@MadGoat.com>
  35. **
  36. ** Date: July 30, 1993
  37. **
  38. ** Abstract: Routines to handle a VMS CLI interface for Zip. The CLI
  39. ** command line is parsed and a new argc/argv are built and
  40. ** returned to Zip.
  41. **
  42. ** Modified by:
  43. **
  44. ** 02-007 Steven Schweda 09-FEB-2005
  45. ** Added /PRESERVE_CASE.
  46. ** 02-006 Onno van der Linden,
  47. ** Christian Spieler 07-JUL-1998 23:03
  48. ** Support GNU CC 2.8 on Alpha AXP (vers-num unchanged).
  49. ** 02-006 Johnny Lee 25-JUN-1998 07:40
  50. ** Fixed typo (superfluous ';') (vers-num unchanged).
  51. ** 02-006 Christian Spieler 12-SEP-1997 23:17
  52. ** Fixed bugs in /BEFORE and /SINCE handlers (vers-num unchanged).
  53. ** 02-006 Christian Spieler 12-JUL-1997 02:05
  54. ** Complete revision of the argv strings construction.
  55. ** Added handling of "-P pwd", "-R", "-i@file", "-x@file" options.
  56. ** 02-005 Patrick Ellis 09-MAY-1996 22:25
  57. ** Show UNIX style help screen when UNIX style options are used.
  58. ** 02-004 Onno van der Linden,
  59. ** Christian Spieler 13-APR-1996 20:05
  60. ** Removed /ENCRYPT=VERIFY ("-ee" option).
  61. ** 02-003 Christian Spieler 11-FEB-1996 23:05
  62. ** Added handling of /EXTRAFIELDS qualifier ("-X" option).
  63. ** 02-002 Christian Spieler 09-JAN-1996 22:25
  64. ** Added "#include crypt.h", corrected typo.
  65. ** 02-001 Christian Spieler 04-DEC-1995 16:00
  66. ** Fixed compilation in DEC CC's ANSI mode.
  67. ** 02-000 Christian Spieler 10-OCT-1995 17:54
  68. ** Modified for Zip v2.1, added several new options.
  69. ** 01-000 Hunter Goatley 30-JUL-1993 07:54
  70. ** Original version (for Zip v1.9p1).
  71. **
  72. */
  73. /* 2004-12-13 SMS.
  74. * Disabled the module name macro to accommodate old GNU C which didn't
  75. * obey the directive, and thus confused MMS/MMK where the object
  76. * library dependencies need to have the correct module name.
  77. */
  78. #if 0
  79. # if defined(__DECC) || defined(__GNUC__)
  80. # pragma module module_name module_ident
  81. # else
  82. # module module_name module_ident
  83. # endif
  84. #endif /* 0 */
  85. /* Accomodation for /NAMES = AS_IS with old header files. */
  86. #define lib$establish LIB$ESTABLISH
  87. #define lib$get_foreign LIB$GET_FOREIGN
  88. #define lib$get_input LIB$GET_INPUT
  89. #define lib$sig_to_ret LIB$SIG_TO_RET
  90. #define ots$cvt_tu_l OTS$CVT_TU_L
  91. #define str$concat STR$CONCAT
  92. #define str$find_first_substring STR$FIND_FIRST_SUBSTRING
  93. #define str$free1_dx STR$FREE1_DX
  94. #include "zip.h"
  95. #ifndef TEST
  96. #include "crypt.h" /* for VMSCLI_help() */
  97. #include "revision.h" /* for VMSCLI_help() */
  98. #endif /* !TEST */
  99. #include <ssdef.h>
  100. #include <descrip.h>
  101. #include <climsgdef.h>
  102. #include <clidef.h>
  103. #include <lib$routines.h>
  104. #include <ots$routines.h>
  105. #include <str$routines.h>
  106. #ifndef CLI$_COMMA
  107. globalvalue CLI$_COMMA;
  108. #endif
  109. /*
  110. ** "Macro" to initialize a dynamic string descriptor.
  111. */
  112. #define init_dyndesc(dsc) {\
  113. dsc.dsc$w_length = 0;\
  114. dsc.dsc$b_dtype = DSC$K_DTYPE_T;\
  115. dsc.dsc$b_class = DSC$K_CLASS_D;\
  116. dsc.dsc$a_pointer = NULL;}
  117. /*
  118. ** Memory allocation step for argv string buffer.
  119. */
  120. #define ARGBSIZE_UNIT 256
  121. /*
  122. ** Memory reallocation macro for argv string buffer.
  123. */
  124. #define CHECK_BUFFER_ALLOCATION(buf, reserved, requested) { \
  125. if ((requested) > (reserved)) { \
  126. char *save_buf = (buf); \
  127. (reserved) += ARGBSIZE_UNIT; \
  128. if (((buf) = (char *) realloc((buf), (reserved))) == NULL) { \
  129. if (save_buf != NULL) free(save_buf); \
  130. return (SS$_INSFMEM); \
  131. } \
  132. } \
  133. }
  134. /*
  135. ** Define descriptors for all of the CLI parameters and qualifiers.
  136. */
  137. $DESCRIPTOR(cli_delete, "DELETE"); /* -d */
  138. $DESCRIPTOR(cli_freshen, "FRESHEN"); /* -f */
  139. $DESCRIPTOR(cli_move, "MOVE"); /* -m */
  140. $DESCRIPTOR(cli_update, "UPDATE"); /* -u */
  141. $DESCRIPTOR(cli_exclude, "EXCLUDE"); /* -x */
  142. $DESCRIPTOR(cli_include, "INCLUDE"); /* -i */
  143. $DESCRIPTOR(cli_exlist, "EXLIST"); /* -x@ */
  144. $DESCRIPTOR(cli_inlist, "INLIST"); /* -i@ */
  145. $DESCRIPTOR(cli_adjust, "ADJUST_OFFSETS"); /* -A */
  146. $DESCRIPTOR(cli_append, "APPEND"); /* -g */
  147. $DESCRIPTOR(cli_batch, "BATCH"); /* -@ */
  148. $DESCRIPTOR(cli_before, "BEFORE"); /* -tt */
  149. $DESCRIPTOR(cli_comments, "COMMENTS"); /* -c,-z */
  150. $DESCRIPTOR(cli_comment_archive,"COMMENTS.ARCHIVE"); /* -z */
  151. $DESCRIPTOR(cli_comment_zipfile,"COMMENTS.ZIP_FILE"); /* -z */
  152. $DESCRIPTOR(cli_comment_files, "COMMENTS.FILES"); /* -c */
  153. $DESCRIPTOR(cli_compression, "COMPRESSION"); /* -Z */
  154. $DESCRIPTOR(cli_compression_b, "COMPRESSION.BZIP2"); /* -Zb */
  155. $DESCRIPTOR(cli_compression_d, "COMPRESSION.DEFLATE"); /* -Zd */
  156. $DESCRIPTOR(cli_compression_s, "COMPRESSION.STORE"); /* -Zs */
  157. $DESCRIPTOR(cli_copy_entries, "COPY_ENTRIES"); /* -U */
  158. $DESCRIPTOR(cli_descriptors, "DESCRIPTORS"); /* -fd */
  159. $DESCRIPTOR(cli_difference, "DIFFERENCE"); /* -DF */
  160. $DESCRIPTOR(cli_dirnames, "DIRNAMES"); /* -D */
  161. $DESCRIPTOR(cli_display, "DISPLAY"); /* -d? */
  162. $DESCRIPTOR(cli_display_bytes, "DISPLAY.BYTES"); /* -db */
  163. $DESCRIPTOR(cli_display_counts, "DISPLAY.COUNTS"); /* -dc */
  164. $DESCRIPTOR(cli_display_dots, "DISPLAY.DOTS"); /* -dd,-ds */
  165. $DESCRIPTOR(cli_display_globaldots, "DISPLAY.GLOBALDOTS"); /* -dg */
  166. $DESCRIPTOR(cli_display_usize, "DISPLAY.USIZE"); /* -du */
  167. $DESCRIPTOR(cli_display_volume, "DISPLAY.VOLUME"); /* -dv */
  168. $DESCRIPTOR(cli_dot_version, "DOT_VERSION"); /* -ww */
  169. $DESCRIPTOR(cli_encrypt, "ENCRYPT"); /* -e,-P */
  170. $DESCRIPTOR(cli_extra_fields, "EXTRA_FIELDS"); /* -X [/NO] */
  171. $DESCRIPTOR(cli_extra_fields_normal, "EXTRA_FIELDS.NORMAL"); /* no -X */
  172. $DESCRIPTOR(cli_extra_fields_keep, "EXTRA_FIELDS.KEEP_EXISTING"); /* -X- */
  173. $DESCRIPTOR(cli_filesync, "FILESYNC"); /* -FS */
  174. $DESCRIPTOR(cli_fix_archive, "FIX_ARCHIVE"); /* -F[F] */
  175. $DESCRIPTOR(cli_fix_normal, "FIX_ARCHIVE.NORMAL"); /* -F */
  176. $DESCRIPTOR(cli_fix_full, "FIX_ARCHIVE.FULL"); /* -FF */
  177. $DESCRIPTOR(cli_full_path, "FULL_PATH"); /* -p */
  178. $DESCRIPTOR(cli_grow, "GROW"); /* -g */
  179. $DESCRIPTOR(cli_help, "HELP"); /* -h */
  180. $DESCRIPTOR(cli_help_normal, "HELP.NORMAL"); /* -h */
  181. $DESCRIPTOR(cli_help_extended, "HELP.EXTENDED"); /* -h2 */
  182. $DESCRIPTOR(cli_junk, "JUNK"); /* -j */
  183. $DESCRIPTOR(cli_keep_version, "KEEP_VERSION"); /* -w */
  184. $DESCRIPTOR(cli_latest, "LATEST"); /* -o */
  185. $DESCRIPTOR(cli_level, "LEVEL"); /* -[0-9] */
  186. $DESCRIPTOR(cli_license, "LICENSE"); /* -L */
  187. $DESCRIPTOR(cli_log_file, "LOG_FILE"); /* -la,-lf,-li */
  188. $DESCRIPTOR(cli_log_file_append, "LOG_FILE.APPEND"); /* -la */
  189. $DESCRIPTOR(cli_log_file_file, "LOG_FILE.FILE"); /* -lf */
  190. $DESCRIPTOR(cli_log_file_info, "LOG_FILE.INFORMATIONAL"); /* -li */
  191. $DESCRIPTOR(cli_must_match, "MUST_MATCH"); /* -MM */
  192. $DESCRIPTOR(cli_output, "OUTPUT"); /* -O */
  193. $DESCRIPTOR(cli_patt_case, "PATTERN_CASE"); /* -ic[-] */
  194. $DESCRIPTOR(cli_patt_case_blind, "PATTERN_CASE.BLIND"); /* -ic */
  195. $DESCRIPTOR(cli_patt_case_sensitive, "PATTERN_CASE.SENSITIVE"); /* -ic- */
  196. $DESCRIPTOR(cli_pkzip, "PKZIP"); /* -k */
  197. $DESCRIPTOR(cli_pres_case, "PRESERVE_CASE"); /* -C */
  198. $DESCRIPTOR(cli_pres_case_no2, "PRESERVE_CASE.NOODS2");/* -C2- */
  199. $DESCRIPTOR(cli_pres_case_no5, "PRESERVE_CASE.NOODS5");/* -C5- */
  200. $DESCRIPTOR(cli_pres_case_ods2, "PRESERVE_CASE.ODS2"); /* -C2 */
  201. $DESCRIPTOR(cli_pres_case_ods5, "PRESERVE_CASE.ODS5"); /* -C5 */
  202. $DESCRIPTOR(cli_quiet, "QUIET"); /* -q */
  203. $DESCRIPTOR(cli_recurse, "RECURSE"); /* -r,-R */
  204. $DESCRIPTOR(cli_recurse_path, "RECURSE.PATH"); /* -r */
  205. $DESCRIPTOR(cli_recurse_fnames, "RECURSE.FILENAMES"); /* -R */
  206. $DESCRIPTOR(cli_show, "SHOW"); /* -s? */
  207. $DESCRIPTOR(cli_show_command, "SHOW.COMMAND"); /* -sc */
  208. $DESCRIPTOR(cli_show_debug, "SHOW.DEBUG"); /* -sd */
  209. $DESCRIPTOR(cli_show_files, "SHOW.FILES"); /* -sf */
  210. $DESCRIPTOR(cli_show_options, "SHOW.OPTIONS"); /* -so */
  211. $DESCRIPTOR(cli_since, "SINCE"); /* -t */
  212. $DESCRIPTOR(cli_split, "SPLIT"); /* -s,-sb,-sp,-sv */
  213. $DESCRIPTOR(cli_split_bell, "SPLIT.BELL"); /* -sb */
  214. $DESCRIPTOR(cli_split_pause, "SPLIT.PAUSE"); /* -sp */
  215. $DESCRIPTOR(cli_split_size, "SPLIT.SIZE"); /* -s */
  216. $DESCRIPTOR(cli_split_verbose, "SPLIT.VERBOSE"); /* -sv */
  217. $DESCRIPTOR(cli_store_types, "STORE_TYPES"); /* -n */
  218. $DESCRIPTOR(cli_sverbose, "SVERBOSE"); /* -sv */
  219. $DESCRIPTOR(cli_symlinks, "SYMLINKS"); /* -y */
  220. $DESCRIPTOR(cli_temp_path, "TEMP_PATH"); /* -b */
  221. $DESCRIPTOR(cli_test, "TEST"); /* -T */
  222. $DESCRIPTOR(cli_test_unzip, "TEST.UNZIP"); /* -TT */
  223. $DESCRIPTOR(cli_translate_eol, "TRANSLATE_EOL"); /* -l[l] */
  224. $DESCRIPTOR(cli_transl_eol_lf, "TRANSLATE_EOL.LF"); /* -l */
  225. $DESCRIPTOR(cli_transl_eol_crlf,"TRANSLATE_EOL.CRLF"); /* -ll */
  226. $DESCRIPTOR(cli_unsfx, "UNSFX"); /* -J */
  227. $DESCRIPTOR(cli_verbose, "VERBOSE"); /* -v (?) */
  228. $DESCRIPTOR(cli_verbose_normal, "VERBOSE.NORMAL"); /* -v */
  229. $DESCRIPTOR(cli_verbose_more, "VERBOSE.MORE"); /* -vv */
  230. $DESCRIPTOR(cli_verbose_debug, "VERBOSE.DEBUG"); /* -vvv */
  231. $DESCRIPTOR(cli_verbose_command,"VERBOSE.COMMAND"); /* (none) */
  232. $DESCRIPTOR(cli_vms, "VMS"); /* -V */
  233. $DESCRIPTOR(cli_vms_all, "VMS.ALL"); /* -VV */
  234. $DESCRIPTOR(cli_wildcard, "WILDCARD"); /* -nw */
  235. $DESCRIPTOR(cli_wildcard_nospan,"WILDCARD.NOSPAN"); /* -W */
  236. $DESCRIPTOR(cli_yyz, "YYZ_ZIP");
  237. $DESCRIPTOR(cli_zip64, "ZIP64"); /* -fz */
  238. $DESCRIPTOR(cli_zipfile, "ZIPFILE");
  239. $DESCRIPTOR(cli_infile, "INFILE");
  240. $DESCRIPTOR(zip_command, "zip ");
  241. static int show_VMSCLI_help;
  242. #if !defined(zip_clitable)
  243. # define zip_clitable ZIP_CLITABLE
  244. #endif
  245. #if defined(__DECC) || defined(__GNUC__)
  246. extern void *zip_clitable;
  247. #else
  248. globalref void *zip_clitable;
  249. #endif
  250. /* extern unsigned long LIB$GET_INPUT(void), LIB$SIG_TO_RET(void); */
  251. #ifndef __STARLET_LOADED
  252. #ifndef sys$bintim
  253. # define sys$bintim SYS$BINTIM
  254. #endif
  255. #ifndef sys$numtim
  256. # define sys$numtim SYS$NUMTIM
  257. #endif
  258. extern int sys$bintim ();
  259. extern int sys$numtim ();
  260. #endif /* !__STARLET_LOADED */
  261. #ifndef cli$dcl_parse
  262. # define cli$dcl_parse CLI$DCL_PARSE
  263. #endif
  264. #ifndef cli$present
  265. # define cli$present CLI$PRESENT
  266. #endif
  267. #ifndef cli$get_value
  268. # define cli$get_value CLI$GET_VALUE
  269. #endif
  270. extern unsigned long cli$dcl_parse ();
  271. extern unsigned long cli$present ();
  272. extern unsigned long cli$get_value ();
  273. unsigned long vms_zip_cmdline (int *, char ***);
  274. static unsigned long get_list (struct dsc$descriptor_s *,
  275. struct dsc$descriptor_d *, int,
  276. char **, unsigned long *, unsigned long *);
  277. static unsigned long get_time (struct dsc$descriptor_s *qual, char *timearg);
  278. static unsigned long check_cli (struct dsc$descriptor_s *);
  279. static int verbose_command = 0;
  280. #ifdef TEST
  281. char errbuf[ FNMAX+ 81]; /* Error message buffer. */
  282. void ziperr( int c, char *h) /* Error message display function. */
  283. {
  284. /* int c: error code from the ZE_ class */
  285. /* char *h: message about how it happened */
  286. printf( "%d: %s\n", c, h);
  287. }
  288. int
  289. main(int argc, char **argv) /* Main program. */
  290. {
  291. return (vms_zip_cmdline(&argc, &argv));
  292. }
  293. #endif /* def TEST */
  294. unsigned long
  295. vms_zip_cmdline (int *argc_p, char ***argv_p)
  296. {
  297. /*
  298. ** Routine: vms_zip_cmdline
  299. **
  300. ** Function:
  301. **
  302. ** Parse the DCL command line and create a fake argv array to be
  303. ** handed off to Zip.
  304. **
  305. ** NOTE: the argv[] is built as we go, so all the parameters are
  306. ** checked in the appropriate order!!
  307. **
  308. ** Formal parameters:
  309. **
  310. ** argc_p - Address of int to receive the new argc
  311. ** argv_p - Address of char ** to receive the argv address
  312. **
  313. ** Calling sequence:
  314. **
  315. ** status = vms_zip_cmdline (&argc, &argv);
  316. **
  317. ** Returns:
  318. **
  319. ** SS$_NORMAL - Success.
  320. ** SS$_INSFMEM - A malloc() or realloc() failed
  321. ** SS$_ABORT - Bad time value
  322. **
  323. */
  324. register unsigned long status;
  325. char options[ 64];
  326. char *the_cmd_line; /* buffer for argv strings */
  327. unsigned long cmdl_size; /* allocated size of buffer */
  328. unsigned long cmdl_len; /* used size of buffer */
  329. char *ptr;
  330. int x, len;
  331. int new_argc;
  332. char **new_argv;
  333. struct dsc$descriptor_d work_str;
  334. struct dsc$descriptor_d foreign_cmdline;
  335. init_dyndesc(work_str);
  336. init_dyndesc(foreign_cmdline);
  337. /*
  338. ** See if the program was invoked by the CLI (SET COMMAND) or by
  339. ** a foreign command definition. Check for /YYZ_ZIP, which is a
  340. ** valid default qualifier solely for this test.
  341. */
  342. show_VMSCLI_help = TRUE;
  343. status = check_cli(&cli_yyz);
  344. if (!(status & 1)) {
  345. lib$get_foreign(&foreign_cmdline);
  346. /*
  347. ** If nothing was returned or the first character is a "-", then
  348. ** assume it's a UNIX-style command and return.
  349. */
  350. if (foreign_cmdline.dsc$w_length == 0)
  351. return (SS$_NORMAL);
  352. if ((*(foreign_cmdline.dsc$a_pointer) == '-') ||
  353. ((foreign_cmdline.dsc$w_length > 1) &&
  354. (*(foreign_cmdline.dsc$a_pointer) == '"') &&
  355. (*(foreign_cmdline.dsc$a_pointer + 1) == '-'))) {
  356. show_VMSCLI_help = FALSE;
  357. return (SS$_NORMAL);
  358. }
  359. str$concat(&work_str, &zip_command, &foreign_cmdline);
  360. status = cli$dcl_parse(&work_str, &zip_clitable, lib$get_input,
  361. lib$get_input, 0);
  362. if (!(status & 1)) return (status);
  363. }
  364. /*
  365. ** There's always going to be a new_argv[] because of the image name.
  366. */
  367. if ((the_cmd_line = (char *) malloc(cmdl_size = ARGBSIZE_UNIT)) == NULL)
  368. return (SS$_INSFMEM);
  369. strcpy(the_cmd_line, "zip");
  370. cmdl_len = sizeof("zip");
  371. /*
  372. ** First, check to see if any of the regular options were specified.
  373. */
  374. options[0] = '-';
  375. ptr = &options[1]; /* Point to temporary buffer */
  376. /*
  377. ** Copy entries.
  378. */
  379. status = cli$present(&cli_copy_entries);
  380. if (status & 1)
  381. /* /COPY_ENTRIES */
  382. *ptr++ = 'U';
  383. /*
  384. ** Delete the specified files from the zip file?
  385. */
  386. status = cli$present(&cli_delete);
  387. if (status & 1)
  388. /* /DELETE */
  389. *ptr++ = 'd';
  390. /*
  391. ** Freshen (only changed files).
  392. */
  393. status = cli$present(&cli_freshen);
  394. if (status & 1)
  395. /* /FRESHEN */
  396. *ptr++ = 'f';
  397. /*
  398. ** Delete the files once they've been added to the zip file.
  399. */
  400. status = cli$present(&cli_move);
  401. if (status & 1)
  402. /* /MOVE */
  403. *ptr++ = 'm';
  404. /*
  405. ** Add changed and new files.
  406. */
  407. status = cli$present(&cli_update);
  408. if (status & 1)
  409. /* /UPDATE */
  410. *ptr++ = 'u';
  411. /*
  412. ** Check for the compression level (-0 through -9).
  413. */
  414. status = cli$present(&cli_level);
  415. if (status & 1) {
  416. /* /LEVEL = value */
  417. unsigned long binval;
  418. status = cli$get_value(&cli_level, &work_str);
  419. status = ots$cvt_tu_l(&work_str, &binval);
  420. if (!(status & 1) || (binval > 9)) {
  421. return (SS$_ABORT);
  422. }
  423. *ptr++ = binval + '0';
  424. }
  425. /*
  426. ** Adjust offsets of zip archive entries.
  427. */
  428. status = cli$present(&cli_adjust);
  429. if (status & 1)
  430. /* /ADJUST_OFFSETS */
  431. *ptr++ = 'A';
  432. /*
  433. ** Add comments?
  434. */
  435. status = cli$present(&cli_comments);
  436. if (status & 1)
  437. {
  438. int archive_or_zip_file = 0;
  439. if ((status = cli$present(&cli_comment_archive)) & 1)
  440. /* /COMMENTS = ARCHIVE */
  441. archive_or_zip_file = 1;
  442. if ((status = cli$present(&cli_comment_zipfile)) & 1)
  443. /* /COMMENTS = ZIP_FILE */
  444. archive_or_zip_file = 1;
  445. if (archive_or_zip_file != 0)
  446. /* /COMMENTS = ARCHIVE */
  447. *ptr++ = 'z';
  448. if ((status = cli$present(&cli_comment_files)) & 1)
  449. /* /COMMENTS = FILES */
  450. *ptr++ = 'c';
  451. }
  452. /*
  453. ** Preserve case in file names.
  454. */
  455. #define OPT_C "-C" /* Preserve case all. */
  456. #define OPT_CN "-C-" /* Down-case all. */
  457. #define OPT_C2 "-C2" /* Preserve case ODS2. */
  458. #define OPT_C2N "-C2-" /* Down-case ODS2. */
  459. #define OPT_C5 "-C5" /* Preserve case ODS5. */
  460. #define OPT_C5N "-C5-" /* Down-case ODS5. */
  461. status = cli$present( &cli_pres_case);
  462. if ((status & 1) || (status == CLI$_NEGATED))
  463. {
  464. /* /[NO]PRESERVE_CASE */
  465. char *opt;
  466. int ods2 = 0;
  467. int ods5 = 0;
  468. if (status == CLI$_NEGATED)
  469. {
  470. x = cmdl_len;
  471. cmdl_len += strlen( OPT_CN)+ 1;
  472. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  473. strcpy( &the_cmd_line[ x], OPT_CN);
  474. }
  475. else
  476. {
  477. if (cli$present( &cli_pres_case_no2) & 1)
  478. {
  479. /* /PRESERVE_CASE = NOODS2 */
  480. ods2 = -1;
  481. }
  482. if (cli$present( &cli_pres_case_no5) & 1)
  483. {
  484. /* /PRESERVE_CASE = NOODS5 */
  485. ods5 = -1;
  486. }
  487. if (cli$present( &cli_pres_case_ods2) & 1)
  488. {
  489. /* /PRESERVE_CASE = ODS2 */
  490. ods2 = 1;
  491. }
  492. if (cli$present( &cli_pres_case_ods5) & 1)
  493. {
  494. /* /PRESERVE_CASE = ODS5 */
  495. ods5 = 1;
  496. }
  497. if (ods2 == ods5)
  498. {
  499. /* Plain "-C[-]". */
  500. if (ods2 < 0)
  501. opt = OPT_CN;
  502. else
  503. opt = OPT_C;
  504. x = cmdl_len;
  505. cmdl_len += strlen( opt)+ 1;
  506. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  507. strcpy( &the_cmd_line[ x], opt);
  508. }
  509. else
  510. {
  511. if (ods2 != 0)
  512. {
  513. /* "-C2[-]". */
  514. if (ods2 < 0)
  515. opt = OPT_C2N;
  516. else
  517. opt = OPT_C2;
  518. x = cmdl_len;
  519. cmdl_len += strlen( opt)+ 1;
  520. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  521. strcpy( &the_cmd_line[ x], opt);
  522. }
  523. if (ods5 != 0)
  524. {
  525. /* "-C5[-]". */
  526. if (ods5 < 0)
  527. opt = OPT_C5N;
  528. else
  529. opt = OPT_C5;
  530. x = cmdl_len;
  531. cmdl_len += strlen( opt)+ 1;
  532. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  533. strcpy( &the_cmd_line[ x], opt);
  534. }
  535. }
  536. }
  537. }
  538. /*
  539. ** Pattern case sensitivity.
  540. */
  541. #define OPT_IC "-ic" /* Case-insensitive pattern matching. */
  542. #define OPT_ICN "-ic-" /* Case-sensitive pattern matching. */
  543. status = cli$present( &cli_patt_case);
  544. if (status & 1)
  545. {
  546. if (cli$present( &cli_patt_case_blind) & 1)
  547. {
  548. /* "-ic". */
  549. x = cmdl_len;
  550. cmdl_len += strlen( OPT_IC)+ 1;
  551. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  552. strcpy( &the_cmd_line[ x], OPT_IC);
  553. }
  554. else if (cli$present( &cli_patt_case_sensitive) & 1)
  555. {
  556. /* "-ic-". */
  557. x = cmdl_len;
  558. cmdl_len += strlen( OPT_ICN)+ 1;
  559. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  560. strcpy( &the_cmd_line[ x], OPT_ICN);
  561. }
  562. }
  563. /*
  564. ** Data descriptors.
  565. */
  566. #define OPT_FD "-fd"
  567. status = cli$present( &cli_descriptors);
  568. if (status & 1)
  569. {
  570. /* /DESCRIPTORS */
  571. x = cmdl_len;
  572. cmdl_len += strlen( OPT_FD)+ 1;
  573. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  574. strcpy( &the_cmd_line[ x], OPT_FD);
  575. }
  576. /*
  577. ** Difference archive. Add only new or changed files.
  578. */
  579. #define OPT_DF "-DF" /* Difference archive. */
  580. if ((status = cli$present( &cli_difference)) & 1)
  581. {
  582. /* /DIFFERENCE */
  583. x = cmdl_len;
  584. cmdl_len += strlen( OPT_DF)+ 1;
  585. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  586. strcpy( &the_cmd_line[ x], OPT_DF);
  587. }
  588. /*
  589. ** Do not add/modify directory entries.
  590. */
  591. status = cli$present(&cli_dirnames);
  592. if (!(status & 1))
  593. /* /DIRNAMES */
  594. *ptr++ = 'D';
  595. /*
  596. ** Encrypt?
  597. */
  598. status = cli$present(&cli_encrypt);
  599. if (status & 1)
  600. if ((status = cli$get_value(&cli_encrypt, &work_str)) & 1) {
  601. /* /ENCRYPT = value */
  602. x = cmdl_len;
  603. cmdl_len += work_str.dsc$w_length + 4;
  604. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  605. strcpy(&the_cmd_line[x], "-P");
  606. strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer,
  607. work_str.dsc$w_length);
  608. the_cmd_line[cmdl_len-1] = '\0';
  609. } else {
  610. /* /ENCRYPT */
  611. *ptr++ = 'e';
  612. }
  613. /*
  614. ** Fix the zip archive structure.
  615. */
  616. status = cli$present(&cli_fix_archive);
  617. if (status & 1) {
  618. *ptr++ = 'F';
  619. /* /FIX_ARCHIVE = NORMAL */
  620. if ((status = cli$present(&cli_fix_full)) & 1) {
  621. /* /FIX_ARCHIVE = FULL */
  622. *ptr++ = 'F';
  623. }
  624. }
  625. /*
  626. ** Filesync. Delete archive entry if no such file.
  627. */
  628. #define OPT_FS "-FS" /* Filesync. */
  629. if ((status = cli$present( &cli_filesync)) & 1)
  630. {
  631. /* /FILESYNC */
  632. x = cmdl_len;
  633. cmdl_len += strlen( OPT_FS)+ 1;
  634. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  635. strcpy( &the_cmd_line[ x], OPT_FS);
  636. }
  637. /*
  638. ** Append (allow growing of existing zip file).
  639. */
  640. status = cli$present(&cli_append);
  641. if (status & 1)
  642. /* /APPEND */
  643. *ptr++ = 'g';
  644. status = cli$present(&cli_grow);
  645. if (status & 1)
  646. /* /GROW */
  647. *ptr++ = 'g';
  648. /*
  649. ** Show the help.
  650. */
  651. #define OPT_H2 "-h2"
  652. status = cli$present(&cli_help);
  653. if (status & 1)
  654. {
  655. status = cli$present( &cli_help_normal);
  656. if (status & 1)
  657. {
  658. /* /HELP [= NORMAL] */
  659. *ptr++ = 'h';
  660. }
  661. status = cli$present( &cli_help_extended);
  662. if (status & 1)
  663. {
  664. /* /HELP = EXTENDED */
  665. x = cmdl_len;
  666. cmdl_len += strlen( OPT_H2)+ 1;
  667. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  668. strcpy( &the_cmd_line[ x], OPT_H2);
  669. }
  670. }
  671. /*
  672. ** Junk path names (directory specs).
  673. */
  674. status = cli$present(&cli_junk);
  675. if (status & 1)
  676. /* /JUNK */
  677. *ptr++ = 'j';
  678. /*
  679. ** Simulate zip file made by PKZIP.
  680. */
  681. status = cli$present(&cli_pkzip);
  682. if (status & 1)
  683. /* /KEEP_VERSION */
  684. *ptr++ = 'k';
  685. /*
  686. ** Translate end-of-line.
  687. */
  688. status = cli$present(&cli_translate_eol);
  689. if (status & 1) {
  690. /* /TRANSLATE_EOL [= LF]*/
  691. *ptr++ = 'l';
  692. if ((status = cli$present(&cli_transl_eol_crlf)) & 1) {
  693. /* /TRANSLATE_EOL = CRLF */
  694. *ptr++ = 'l';
  695. }
  696. }
  697. /*
  698. ** Show the software license.
  699. */
  700. status = cli$present(&cli_license);
  701. if (status & 1)
  702. /* /LICENSE */
  703. *ptr++ = 'L';
  704. /*
  705. ** Set zip file time to time of latest file in it.
  706. */
  707. status = cli$present(&cli_latest);
  708. if (status & 1)
  709. /* /LATEST */
  710. *ptr++ = 'o';
  711. /*
  712. ** Store full path (default).
  713. */
  714. status = cli$present(&cli_full_path);
  715. if (status == CLI$_PRESENT)
  716. /* /FULL_PATH */
  717. *ptr++ = 'p';
  718. else if (status == CLI$_NEGATED)
  719. /* /NOFULL_PATH */
  720. *ptr++ = 'j';
  721. /*
  722. ** Junk Zipfile prefix (SFX stub etc.).
  723. */
  724. status = cli$present(&cli_unsfx);
  725. if (status & 1)
  726. /* /UNSFX */
  727. *ptr++ = 'J';
  728. /*
  729. ** Recurse through subdirectories.
  730. */
  731. status = cli$present(&cli_recurse);
  732. if (status & 1) {
  733. if ((status = cli$present(&cli_recurse_fnames)) & 1)
  734. /* /RECURSE [= PATH] */
  735. *ptr++ = 'R';
  736. else
  737. /* /RECURSE [= FILENAMES] */
  738. *ptr++ = 'r';
  739. }
  740. /*
  741. ** Test Zipfile.
  742. */
  743. status = cli$present(&cli_test);
  744. if (status & 1) {
  745. /* /TEST */
  746. *ptr++ = 'T';
  747. }
  748. /*
  749. ** Be verbose.
  750. */
  751. status = cli$present(&cli_verbose);
  752. if (status & 1) {
  753. int i;
  754. int verbo = 0;
  755. /* /VERBOSE */
  756. if ((status = cli$present(&cli_verbose_command)) & 1)
  757. {
  758. /* /VERBOSE = COMMAND */
  759. verbose_command = 1;
  760. }
  761. /* Note that any or all of the following options may be
  762. specified, and the maximum one is used.
  763. */
  764. if ((status = cli$present(&cli_verbose_normal)) & 1)
  765. /* /VERBOSE [ = NORMAL ] */
  766. verbo = 1;
  767. if ((status = cli$present(&cli_verbose_more)) & 1)
  768. /* /VERBOSE = MORE */
  769. verbo = 2;
  770. if ((status = cli$present(&cli_verbose_debug)) & 1) {
  771. /* /VERBOSE = DEBUG */
  772. verbo = 3;
  773. }
  774. for (i = 0; i < verbo; i++)
  775. *ptr++ = 'v';
  776. }
  777. /*
  778. ** Quiet mode.
  779. ** (Quiet mode is processed after verbose, because a "-v" modifier
  780. ** resets "noisy" to 1.)
  781. */
  782. status = cli$present(&cli_quiet);
  783. if (status & 1)
  784. /* /QUIET */
  785. *ptr++ = 'q';
  786. /*
  787. ** Save the VMS file attributes (and all allocated blocks?).
  788. */
  789. status = cli$present(&cli_vms);
  790. if (status & 1) {
  791. /* /VMS */
  792. *ptr++ = 'V';
  793. if ((status = cli$present(&cli_vms_all)) & 1) {
  794. /* /VMS = ALL */
  795. *ptr++ = 'V';
  796. }
  797. }
  798. /*
  799. ** Keep the VMS version number as part of the file name when stored.
  800. */
  801. status = cli$present(&cli_keep_version);
  802. if (status & 1)
  803. /* /KEEP_VERSION */
  804. *ptr++ = 'w';
  805. /*
  806. ** Store symlinks as symlinks.
  807. */
  808. status = cli$present(&cli_symlinks);
  809. if (status & 1)
  810. /* /SYMLINKS */
  811. *ptr++ = 'y';
  812. /*
  813. ** `Batch' processing: read filenames to archive from stdin
  814. ** or the specified file.
  815. */
  816. status = cli$present(&cli_batch);
  817. if (status & 1) {
  818. /* /BATCH */
  819. status = cli$get_value(&cli_batch, &work_str);
  820. if (status & 1) {
  821. /* /BATCH = value */
  822. work_str.dsc$a_pointer[work_str.dsc$w_length] = '\0';
  823. if ((stdin = freopen(work_str.dsc$a_pointer, "r", stdin)) == NULL)
  824. {
  825. sprintf(errbuf, "could not open list file: %s",
  826. work_str.dsc$a_pointer);
  827. ziperr(ZE_PARMS, errbuf);
  828. }
  829. }
  830. *ptr++ = '@';
  831. }
  832. /*
  833. ** Now copy the final options string to the_cmd_line.
  834. */
  835. len = ptr - &options[0];
  836. if (len > 1) {
  837. options[len] = '\0';
  838. x = cmdl_len;
  839. cmdl_len += len + 1;
  840. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  841. strcpy(&the_cmd_line[x], options);
  842. }
  843. /*
  844. **
  845. ** OK. We've done all the regular options, so check for -b (temporary
  846. ** file path), -n (special suffixes), -O (output atchive file),
  847. ** -t (exclude before time), -Z (compression method), zipfile,
  848. ** files to zip, and exclude list.
  849. **
  850. */
  851. status = cli$present(&cli_temp_path);
  852. if (status & 1) {
  853. /* /TEMP_PATH = value */
  854. status = cli$get_value(&cli_temp_path, &work_str);
  855. x = cmdl_len;
  856. cmdl_len += work_str.dsc$w_length + 4;
  857. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  858. strcpy(&the_cmd_line[x], "-b");
  859. strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer,
  860. work_str.dsc$w_length);
  861. the_cmd_line[cmdl_len-1] = '\0';
  862. }
  863. status = cli$present(&cli_output);
  864. if (status & 1) {
  865. /* /OUTPUT = value */
  866. status = cli$get_value(&cli_output, &work_str);
  867. x = cmdl_len;
  868. cmdl_len += work_str.dsc$w_length + 4;
  869. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  870. strcpy(&the_cmd_line[x], "-O");
  871. strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer,
  872. work_str.dsc$w_length);
  873. the_cmd_line[cmdl_len-1] = '\0';
  874. }
  875. /*
  876. ** Handle "-db", "-dc", "-dd", "-ds".
  877. */
  878. #define OPT_DB "-db"
  879. #define OPT_DC "-dc"
  880. #define OPT_DD "-dd"
  881. #define OPT_DG "-dg"
  882. #define OPT_DS "-ds="
  883. #define OPT_DU "-du"
  884. #define OPT_DV "-dv"
  885. status = cli$present( &cli_display);
  886. if (status & 1)
  887. {
  888. if ((status = cli$present( &cli_display_bytes)) & 1)
  889. {
  890. /* /DISPLAY = BYTES */
  891. x = cmdl_len;
  892. cmdl_len += strlen( OPT_DB)+ 1;
  893. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  894. strcpy( &the_cmd_line[ x], OPT_DB);
  895. }
  896. if ((status = cli$present( &cli_display_counts)) & 1)
  897. {
  898. /* /DISPLAY = COUNTS */
  899. x = cmdl_len;
  900. cmdl_len += strlen( OPT_DC)+ 1;
  901. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  902. strcpy( &the_cmd_line[ x], OPT_DC);
  903. }
  904. if ((status = cli$present( &cli_display_dots)) & 1)
  905. {
  906. /* /DISPLAY = DOTS [= value] */
  907. status = cli$get_value( &cli_display_dots, &work_str);
  908. x = cmdl_len;
  909. cmdl_len += strlen( OPT_DD)+ 1;
  910. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  911. strcpy( &the_cmd_line[ x], OPT_DD);
  912. /* -dd[=value] now -dd -ds=value - 5/8/05 EG */
  913. if (work_str.dsc$w_length > 0) {
  914. x = cmdl_len;
  915. cmdl_len += strlen( OPT_DS);
  916. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  917. strcpy( &the_cmd_line[ x], OPT_DS);
  918. x = cmdl_len;
  919. cmdl_len += work_str.dsc$w_length+ 1;
  920. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  921. strncpy( &the_cmd_line[ x],
  922. work_str.dsc$a_pointer, work_str.dsc$w_length);
  923. }
  924. }
  925. if ((status = cli$present( &cli_display_globaldots)) & 1)
  926. {
  927. /* /DISPLAY = GLOBALDOTS */
  928. x = cmdl_len;
  929. cmdl_len += strlen( OPT_DG)+ 1;
  930. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  931. strcpy( &the_cmd_line[ x], OPT_DG);
  932. }
  933. if ((status = cli$present( &cli_display_usize)) & 1)
  934. {
  935. /* /DISPLAY = USIZE */
  936. x = cmdl_len;
  937. cmdl_len += strlen( OPT_DU)+ 1;
  938. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  939. strcpy( &the_cmd_line[ x], OPT_DU);
  940. }
  941. if ((status = cli$present( &cli_display_volume)) & 1)
  942. {
  943. /* /DISPLAY = VOLUME */
  944. x = cmdl_len;
  945. cmdl_len += strlen( OPT_DV)+ 1;
  946. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  947. strcpy( &the_cmd_line[ x], OPT_DV);
  948. }
  949. }
  950. /*
  951. ** Handle "-la", "-lf", "-li".
  952. */
  953. #define OPT_LA "-la"
  954. #define OPT_LF "-lf"
  955. #define OPT_LI "-li"
  956. status = cli$present( &cli_log_file);
  957. if (status & 1)
  958. {
  959. /* /SHOW */
  960. if ((status = cli$present( &cli_log_file_append)) & 1)
  961. {
  962. /* /LOG_FILE = APPEND */
  963. x = cmdl_len;
  964. cmdl_len += strlen( OPT_LA)+ 1;
  965. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  966. strcpy( &the_cmd_line[ x], OPT_LA);
  967. }
  968. status = cli$present(&cli_log_file_file);
  969. if (status & 1) {
  970. /* /LOG_FILE = FILE = file */
  971. status = cli$get_value(&cli_log_file_file, &work_str);
  972. x = cmdl_len;
  973. cmdl_len += strlen( OPT_LF)+ 2+ work_str.dsc$w_length;
  974. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  975. strcpy(&the_cmd_line[x], OPT_LF);
  976. strncpy(&the_cmd_line[x+strlen( OPT_LF)+ 1], work_str.dsc$a_pointer,
  977. work_str.dsc$w_length);
  978. the_cmd_line[cmdl_len-1] = '\0';
  979. }
  980. if ((status = cli$present( &cli_log_file_info)) & 1)
  981. {
  982. /* /LOG = INFO */
  983. x = cmdl_len;
  984. cmdl_len += strlen( OPT_LI)+ 1;
  985. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  986. strcpy( &the_cmd_line[ x], OPT_LI);
  987. }
  988. }
  989. /*
  990. ** Handle "-s", "-sb", "-sp", "-sv".
  991. */
  992. #define OPT_S "-s"
  993. #define OPT_SB "-sb"
  994. #define OPT_SP "-sp"
  995. #define OPT_SV "-sv"
  996. status = cli$present( &cli_split);
  997. if (status & 1)
  998. {
  999. status = cli$present( &cli_split_bell);
  1000. if (status & 1)
  1001. {
  1002. /* /SPLIT = BELL */
  1003. x = cmdl_len;
  1004. cmdl_len += strlen( OPT_SB)+ 1;
  1005. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1006. strcpy( &the_cmd_line[ x], OPT_SB);
  1007. }
  1008. status = cli$present( &cli_split_pause);
  1009. if (status & 1)
  1010. {
  1011. /* /SPLIT = PAUSE */
  1012. x = cmdl_len;
  1013. cmdl_len += strlen( OPT_SP)+ 1;
  1014. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1015. strcpy( &the_cmd_line[ x], OPT_SP);
  1016. }
  1017. status = cli$present( &cli_split_size);
  1018. if (status & 1)
  1019. {
  1020. /* /SPLIT = SIZE = size */
  1021. status = cli$get_value( &cli_split_size, &work_str);
  1022. x = cmdl_len;
  1023. cmdl_len += strlen( OPT_S)+ 1;
  1024. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1025. strcpy( &the_cmd_line[ x], OPT_S);
  1026. x = cmdl_len;
  1027. cmdl_len += work_str.dsc$w_length+ 1;
  1028. strncpy( &the_cmd_line[ x],
  1029. work_str.dsc$a_pointer, work_str.dsc$w_length);
  1030. }
  1031. status = cli$present( &cli_split_verbose);
  1032. if (status & 1)
  1033. {
  1034. /* /SPLIT = VERBOSE */
  1035. x = cmdl_len;
  1036. cmdl_len += strlen( OPT_SV)+ 1;
  1037. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1038. strcpy( &the_cmd_line[ x], OPT_SV);
  1039. }
  1040. }
  1041. /*
  1042. ** Handle "-sc", "-sd", "-sf", "-so".
  1043. */
  1044. #define OPT_SC "-sc"
  1045. #define OPT_SD "-sd"
  1046. #define OPT_SF "-sf"
  1047. #define OPT_SO "-so"
  1048. status = cli$present( &cli_show);
  1049. if (status & 1)
  1050. {
  1051. /* /SHOW */
  1052. if ((status = cli$present( &cli_show_command)) & 1)
  1053. {
  1054. /* /SHOW = COMMAND */
  1055. x = cmdl_len;
  1056. cmdl_len += strlen( OPT_SC)+ 1;
  1057. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1058. strcpy( &the_cmd_line[ x], OPT_SC);
  1059. }
  1060. if ((status = cli$present( &cli_show_debug)) & 1)
  1061. {
  1062. /* /SHOW = DEBUG */
  1063. x = cmdl_len;
  1064. cmdl_len += strlen( OPT_SD)+ 1;
  1065. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1066. strcpy( &the_cmd_line[ x], OPT_SD);
  1067. }
  1068. if ((status = cli$present( &cli_show_files)) & 1)
  1069. {
  1070. /* /SHOW = FILES */
  1071. x = cmdl_len;
  1072. cmdl_len += strlen( OPT_SF)+ 1;
  1073. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1074. strcpy( &the_cmd_line[ x], OPT_SF);
  1075. }
  1076. if ((status = cli$present( &cli_show_options)) & 1)
  1077. {
  1078. /* /SHOW = OPTIONS */
  1079. x = cmdl_len;
  1080. cmdl_len += strlen( OPT_SO)+ 1;
  1081. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1082. strcpy( &the_cmd_line[ x], OPT_SO);
  1083. }
  1084. }
  1085. /*
  1086. ** Handle "-fz".
  1087. */
  1088. #define OPT_FZ "-fz"
  1089. status = cli$present( &cli_zip64);
  1090. if (status & 1)
  1091. {
  1092. /* /ZIP64 */
  1093. x = cmdl_len;
  1094. cmdl_len += strlen( OPT_FZ)+ 1;
  1095. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1096. strcpy( &the_cmd_line[ x], OPT_FZ);
  1097. }
  1098. /*
  1099. ** Handle "-nw" and "-W".
  1100. */
  1101. #define OPT_NW "-nw"
  1102. #define OPT_W "-W"
  1103. status = cli$present( &cli_wildcard);
  1104. if (status & 1)
  1105. {
  1106. if ((status = cli$present( &cli_wildcard_nospan)) & 1)
  1107. {
  1108. /* /WILDCARD = NOSPAN */
  1109. x = cmdl_len;
  1110. cmdl_len += strlen( OPT_W)+ 1;
  1111. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1112. strcpy( &the_cmd_line[ x], OPT_W);
  1113. }
  1114. }
  1115. else if (status == CLI$_NEGATED)
  1116. {
  1117. /* /NOWILDCARD */
  1118. x = cmdl_len;
  1119. cmdl_len += strlen( OPT_NW)+ 1;
  1120. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1121. strcpy( &the_cmd_line[ x], OPT_NW);
  1122. }
  1123. /*
  1124. ** Handle "-MM".
  1125. */
  1126. #define OPT_MM "-MM"
  1127. status = cli$present( &cli_must_match);
  1128. if (status & 1)
  1129. {
  1130. /* /MUST_MATCH */
  1131. x = cmdl_len;
  1132. cmdl_len += strlen( OPT_MM)+ 1;
  1133. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1134. strcpy( &the_cmd_line[ x], OPT_MM);
  1135. }
  1136. /*
  1137. ** UnZip command for archive test.
  1138. */
  1139. #define OPT_TT "-TT"
  1140. status = cli$present(&cli_test);
  1141. if (status & 1) {
  1142. /* /TEST */
  1143. status = cli$present(&cli_test_unzip);
  1144. if (status & 1) {
  1145. /* /TEST = UNZIP = value */
  1146. status = cli$get_value(&cli_test_unzip, &work_str);
  1147. x = cmdl_len;
  1148. cmdl_len += strlen( OPT_TT)+ 2+ work_str.dsc$w_length;
  1149. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1150. strcpy(&the_cmd_line[x], OPT_TT);
  1151. strncpy(&the_cmd_line[x+strlen( OPT_TT)+ 1], work_str.dsc$a_pointer,
  1152. work_str.dsc$w_length);
  1153. the_cmd_line[cmdl_len-1] = '\0';
  1154. }
  1155. }
  1156. /*
  1157. ** Handle "-Z".
  1158. */
  1159. #define OPT_ZB "-Zb"
  1160. #define OPT_ZD "-Zd"
  1161. #define OPT_ZS "-Zs"
  1162. status = cli$present( &cli_compression);
  1163. if (status & 1)
  1164. {
  1165. if ((status = cli$present( &cli_compression_b)) & 1)
  1166. {
  1167. /* /COMPRESSION = BZIP2 */
  1168. x = cmdl_len;
  1169. cmdl_len += strlen( OPT_ZB)+ 1;
  1170. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1171. strcpy( &the_cmd_line[ x], OPT_ZB);
  1172. }
  1173. if ((status = cli$present( &cli_compression_d)) & 1)
  1174. {
  1175. /* /COMPRESSION = DEFLATE */
  1176. x = cmdl_len;
  1177. cmdl_len += strlen( OPT_ZD)+ 1;
  1178. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1179. strcpy( &the_cmd_line[ x], OPT_ZD);
  1180. }
  1181. if ((status = cli$present( &cli_compression_s)) & 1)
  1182. {
  1183. /* /COMPRESSION = STORE */
  1184. x = cmdl_len;
  1185. cmdl_len += strlen( OPT_ZS)+ 1;
  1186. CHECK_BUFFER_ALLOCATION( the_cmd_line, cmdl_size, cmdl_len)
  1187. strcpy( &the_cmd_line[ x], OPT_ZS);
  1188. }
  1189. }
  1190. /*
  1191. ** Handle "-t mmddyyyy".
  1192. */
  1193. status = cli$present(&cli_since);
  1194. if (status & 1) {
  1195. /* /SINCE = value */
  1196. char since_time[9];
  1197. status = get_time(&cli_since, &since_time[0]);
  1198. if (!(status & 1)) return (status);
  1199. /*
  1200. ** Now let's add the option "-t mmddyyyy" to the new command line.
  1201. */
  1202. x = cmdl_len;
  1203. cmdl_len += (3 + 9);
  1204. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1205. strcpy(&the_cmd_line[x], "-t");
  1206. strcpy(&the_cmd_line[x+3], since_time);
  1207. }
  1208. /*
  1209. ** Handle "-tt mmddyyyy".
  1210. */
  1211. status = cli$present(&cli_before);
  1212. if (status & 1) {
  1213. /* /BEFORE = value */
  1214. char before_time[9];
  1215. status = get_time(&cli_before, &before_time[0]);
  1216. if (!(status & 1)) return (status);
  1217. /*
  1218. ** Now let's add the option "-tt mmddyyyy" to the new command line.
  1219. */
  1220. x = cmdl_len;
  1221. cmdl_len += (4 + 9);
  1222. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1223. strcpy(&the_cmd_line[x], "-tt");
  1224. strcpy(&the_cmd_line[x+4], before_time);
  1225. }
  1226. /*
  1227. ** Handle "-n suffix:suffix:...". (File types to store only.)
  1228. */
  1229. status = cli$present(&cli_store_types);
  1230. if (status & 1) {
  1231. /* /STORE_TYPES = value_list */
  1232. x = cmdl_len;
  1233. cmdl_len += 3;
  1234. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1235. strcpy(&the_cmd_line[x], "-n");
  1236. status = get_list(&cli_store_types, &foreign_cmdline, ':',
  1237. &the_cmd_line, &cmdl_size, &cmdl_len);
  1238. if (!(status & 1)) return (status);
  1239. }
  1240. /*
  1241. ** Handle "-X", keep or strip extra fields.
  1242. */
  1243. #define OPT_X "-X"
  1244. #define OPT_XN "-X-"
  1245. status = cli$present(&cli_extra_fields);
  1246. if (status & 1) {
  1247. /* /EXTRA_FIELDS */
  1248. if ((status = cli$present( &cli_extra_fields_keep)) & 1) {
  1249. /* /EXTRA_FIELDS = KEEP_EXISTING */
  1250. x = cmdl_len;
  1251. cmdl_len += strlen( OPT_XN)+ 1;
  1252. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1253. strcpy( &the_cmd_line[ x], OPT_XN);
  1254. }
  1255. }
  1256. else if (status == CLI$_NEGATED) {
  1257. /* /NOEXTRA_FIELDS */
  1258. x = cmdl_len;
  1259. cmdl_len += strlen( OPT_X)+ 1;
  1260. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1261. strcpy( &the_cmd_line[ x], OPT_X);
  1262. }
  1263. /*
  1264. ** Now get the specified zip file name.
  1265. */
  1266. status = cli$present(&cli_zipfile);
  1267. /* zipfile */
  1268. if (status & 1) {
  1269. status = cli$get_value(&cli_zipfile, &work_str);
  1270. x = cmdl_len;
  1271. cmdl_len += work_str.dsc$w_length + 1;
  1272. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1273. strncpy(&the_cmd_line[x], work_str.dsc$a_pointer,
  1274. work_str.dsc$w_length);
  1275. the_cmd_line[cmdl_len-1] = '\0';
  1276. }
  1277. /*
  1278. ** Run through the list of input files.
  1279. */
  1280. status = cli$present(&cli_infile);
  1281. if (status & 1) {
  1282. /* infile_list */
  1283. status = get_list(&cli_infile, &foreign_cmdline, '\0',
  1284. &the_cmd_line, &cmdl_size, &cmdl_len);
  1285. if (!(status & 1)) return (status);
  1286. }
  1287. /*
  1288. ** List file containing exclude patterns present? ("-x@exclude.lst")
  1289. */
  1290. status = cli$present(&cli_exlist);
  1291. if (status & 1) {
  1292. /* /EXLIST = list */
  1293. status = cli$get_value(&cli_exlist, &work_str);
  1294. x = cmdl_len;
  1295. cmdl_len += work_str.dsc$w_length + 4;
  1296. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1297. strncpy(&the_cmd_line[x], "-x@", 3);
  1298. strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer,
  1299. work_str.dsc$w_length);
  1300. the_cmd_line[cmdl_len-1] = '\0';
  1301. }
  1302. /*
  1303. ** Any files to exclude? ("-x file file")
  1304. */
  1305. status = cli$present(&cli_exclude);
  1306. if (status & 1) {
  1307. /* /EXCLUDE = list */
  1308. x = cmdl_len;
  1309. cmdl_len += 3;
  1310. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1311. strcpy(&the_cmd_line[x], "-x");
  1312. status = get_list(&cli_exclude, &foreign_cmdline, '\0',
  1313. &the_cmd_line, &cmdl_size, &cmdl_len);
  1314. if (!(status & 1)) return (status);
  1315. }
  1316. /*
  1317. ** List file containing include patterns present? ("-x@exclude.lst")
  1318. */
  1319. status = cli$present(&cli_inlist);
  1320. if (status & 1) {
  1321. /* /INLIST = list */
  1322. status = cli$get_value(&cli_inlist, &work_str);
  1323. x = cmdl_len;
  1324. cmdl_len += work_str.dsc$w_length + 4;
  1325. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1326. strncpy(&the_cmd_line[x], "-i@", 3);
  1327. strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer,
  1328. work_str.dsc$w_length);
  1329. the_cmd_line[cmdl_len-1] = '\0';
  1330. }
  1331. /*
  1332. ** Any files to include? ("-i file file")
  1333. */
  1334. status = cli$present(&cli_include);
  1335. if (status & 1) {
  1336. /* /INCLUDE = list */
  1337. x = cmdl_len;
  1338. cmdl_len += 3;
  1339. CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len)
  1340. strcpy(&the_cmd_line[x], "-i");
  1341. status = get_list(&cli_exclude, &foreign_cmdline, '\0',
  1342. &the_cmd_line, &cmdl_size, &cmdl_len);
  1343. if (!(status & 1)) return (status);
  1344. }
  1345. /*
  1346. ** We have finished collecting the strings for the argv vector,
  1347. ** release unused space.
  1348. */
  1349. if ((the_cmd_line = (char *) realloc(the_cmd_line, cmdl_len)) == NULL)
  1350. return (SS$_INSFMEM);
  1351. /*
  1352. ** Now that we've built our new UNIX-like command line, count the
  1353. ** number of args and build an argv array.
  1354. */
  1355. for (new_argc = 0, x = 0; x < cmdl_len; x++)
  1356. if (the_cmd_line[x] == '\0')
  1357. new_argc++;
  1358. /*
  1359. ** Allocate memory for the new argv[]. The last element of argv[]
  1360. ** is supposed to be NULL, so allocate enough for new_argc+1.
  1361. */
  1362. if ((new_argv = (char **) calloc(new_argc+1, sizeof(char *))) == NULL)
  1363. return (SS$_INSFMEM);
  1364. /*
  1365. ** For each option, store the address in new_argv[] and convert the
  1366. ** separating blanks to nulls so each argv[] string is terminated.
  1367. */
  1368. for (ptr = the_cmd_line, x = 0; x < new_argc; x++) {
  1369. new_argv[x] = ptr;
  1370. ptr += strlen(ptr) + 1;
  1371. }
  1372. new_argv[new_argc] = NULL;
  1373. #if defined(TEST) || defined(DEBUG)
  1374. printf("new_argc = %d\n", new_argc);
  1375. for (x = 0; x < new_argc; x++)
  1376. printf("new_argv[%d] = %s\n", x, new_argv[x]);
  1377. #endif /* TEST || DEBUG */
  1378. /* Show the complete UNIX command line, if requested. */
  1379. if (verbose_command != 0)
  1380. {
  1381. printf( " UNIX command line args (argc = %d):\n", new_argc);
  1382. for (x = 0; x < new_argc; x++)
  1383. printf( "%s\n", new_argv[ x]);
  1384. printf( "\n");
  1385. }
  1386. /*
  1387. ** All finished. Return the new argc and argv[] addresses to Zip.
  1388. */
  1389. *argc_p = new_argc;
  1390. *argv_p = new_argv;
  1391. return (SS$_NORMAL);
  1392. }
  1393. static unsigned long
  1394. get_list (struct dsc$descriptor_s *qual, struct dsc$descriptor_d *rawtail,
  1395. int delim, char **p_str, unsigned long *p_size, unsigned long *p_end)
  1396. {
  1397. /*
  1398. ** Routine: get_list
  1399. **
  1400. ** Function: This routine runs through a comma-separated CLI list
  1401. ** and copies the strings to the argv buffer. The
  1402. ** specified separation character is used to separate
  1403. ** the strings in the argv buffer.
  1404. **
  1405. ** All unquoted strings are converted to lower-case.
  1406. **
  1407. ** Formal parameters:
  1408. **
  1409. ** qual - Address of descriptor for the qualifier name
  1410. ** rawtail - Address of descriptor for the full command line tail
  1411. ** delim - Character to use to separate the list items
  1412. ** p_str - Address of pointer pointing to output buffer (argv strings)
  1413. ** p_size - Address of number containing allocated size for output string
  1414. ** p_end - Address of number containing used length in output buf
  1415. **
  1416. */
  1417. register unsigned long status;
  1418. struct dsc$descriptor_d work_str;
  1419. init_dyndesc(work_str);
  1420. status = cli$present(qual);
  1421. if (status & 1) {
  1422. unsigned long len, old_len;
  1423. long ind, sind;
  1424. int keep_case;
  1425. char *src, *dst; int x;
  1426. /*
  1427. ** Just in case the string doesn't exist yet, though it does.
  1428. */
  1429. if (*p_str == NULL) {
  1430. *p_size = ARGBSIZE_UNIT;
  1431. if ((*p_str = (char *) malloc(*p_size)) == NULL)
  1432. return (SS$_INSFMEM);
  1433. len = 0;
  1434. } else {
  1435. len = *p_end;
  1436. }
  1437. while ((status = cli$get_value(qual, &work_str)) & 1) {
  1438. old_len = len;
  1439. len += work_str.dsc$w_length + 1;
  1440. CHECK_BUFFER_ALLOCATION(*p_str, *p_size, len)
  1441. /*
  1442. ** Look for the filename in the original foreign command
  1443. ** line to see if it was originally quoted. If so, then
  1444. ** don't convert it to lowercase.
  1445. */
  1446. keep_case = FALSE;
  1447. str$find_first_substring(rawtail, &ind, &sind, &work_str);
  1448. if ((ind > 1 && *(rawtail->dsc$a_pointer + ind - 2) == '"') ||
  1449. (ind == 0))
  1450. keep_case = TRUE;
  1451. /*
  1452. ** Copy the string to the buffer, converting to lowercase.
  1453. */
  1454. src = work_str.dsc$a_pointer;
  1455. dst = *p_str+old_len;
  1456. for (x = 0; x < work_str.dsc$w_length; x++) {
  1457. if (!keep_case && ((*src >= 'A') && (*src <= 'Z')))
  1458. *dst++ = *src++ + 32;
  1459. else
  1460. *dst++ = *src++;
  1461. }
  1462. if (status == CLI$_COMMA)
  1463. (*p_str)[len-1] = (char)delim;
  1464. else
  1465. (*p_str)[len-1] = '\0';
  1466. }
  1467. *p_end = len;
  1468. }
  1469. return (SS$_NORMAL);
  1470. }
  1471. static unsigned long
  1472. get_time (struct dsc$descriptor_s *qual, char *timearg)
  1473. {
  1474. /*
  1475. ** Routine: get_time
  1476. **
  1477. ** Function: This routine reads the argument string of the qualifier
  1478. ** "qual" that should be a VMS syntax date-time string. The
  1479. ** date-time string is converted into the standard format
  1480. ** "mmddyyyy", specifying an absolute date. The converted
  1481. ** string is written into the 9 bytes wide buffer "timearg".
  1482. **
  1483. ** Formal parameters:
  1484. **
  1485. ** qual - Address of descriptor for the qualifier name
  1486. ** timearg - Address of a buffer carrying the 8-char time string returned
  1487. **
  1488. */
  1489. register unsigned long status;
  1490. struct dsc$descriptor_d time_str;
  1491. struct quadword {
  1492. long high;
  1493. long low;
  1494. } bintimbuf = {0,0};
  1495. #ifdef __DECC
  1496. #pragma member_alignment save
  1497. #pragma nomember_alignment
  1498. #endif /* __DECC */
  1499. struct tim {
  1500. short year;
  1501. short month;
  1502. short day;
  1503. short hour;
  1504. short minute;
  1505. short second;
  1506. short hundred;
  1507. } numtimbuf;
  1508. #ifdef __DECC
  1509. #pragma member_alignment restore
  1510. #endif
  1511. init_dyndesc(time_str);
  1512. status = cli$get_value(qual, &time_str);
  1513. /*
  1514. ** If a date is given, convert it to 64-bit binary.
  1515. */
  1516. if (time_str.dsc$w_length) {
  1517. status = sys$bintim(&time_str, &bintimbuf);
  1518. if (!(status & 1)) return (status);
  1519. str$free1_dx(&time_str);
  1520. }
  1521. /*
  1522. ** Now call $NUMTIM to get the month, day, and year.
  1523. */
  1524. status = sys$numtim(&numtimbuf, (bintimbuf.low ? &bintimbuf : NULL));
  1525. /*
  1526. ** Write the "mmddyyyy" string to the return buffer.
  1527. */
  1528. if (!(status & 1)) {
  1529. *timearg = '\0';
  1530. } else {
  1531. sprintf(timearg, "%02d%02d%04d", numtimbuf.month,
  1532. numtimbuf.day, numtimbuf.year);
  1533. }
  1534. return (status);
  1535. }
  1536. static unsigned long
  1537. check_cli (struct dsc$descriptor_s *qual)
  1538. {
  1539. /*
  1540. ** Routine: check_cli
  1541. **
  1542. ** Function: Check to see if a CLD was used to invoke the program.
  1543. **
  1544. ** Formal parameters:
  1545. **
  1546. ** qual - Address of descriptor for qualifier name to check.
  1547. **
  1548. */
  1549. lib$establish(lib$sig_to_ret); /* Establish condition handler */
  1550. return (cli$present(qual)); /* Just see if something was given */
  1551. }
  1552. #ifndef TEST
  1553. void VMSCLI_help(void) /* VMSCLI version */
  1554. /* Print help (along with license info) to stdout. */
  1555. {
  1556. extent i; /* counter for help array */
  1557. /* help array */
  1558. static char *text[] = {
  1559. "Zip %s (%s). Usage: (zip :== $ dev:[dir]zip_cli.exe)",
  1560. "zip archive[.zip] [list] [/EXCL=(xlist)] /options /modifiers",
  1561. " The default action is to add or replace archive entries from list, except",
  1562. " those in xlist. The include file list may contain the special name \"-\" to",
  1563. " compress standard input. If both archive and list are omitted, Zip",
  1564. " compresses stdin to stdout.",
  1565. " Type zip -h for Unix-style flags.",
  1566. " Major options include:",
  1567. " /COPY, /DELETE, /DIFFERENCE, /FILESYNC, /FRESHEN, /GROW, /MOVE, /UPDATE,",
  1568. " /ADJUST_OFFSETS, /FIX_ARCHIVE[={NORMAL|FULL}], /TEST[=UNZIP=cmd], /UNSFX,",
  1569. " Modifiers include:",
  1570. " /BATCH[=list_file], /BEFORE=creation_time, /COMMENTS[={ARCHIVE|FILES}],",
  1571. " /EXCLUDE=(file_list), /EXLIST=file, /INCLUDE=(file_list), /INLIST=file,",
  1572. " /LATEST, /OUTPUT=out_archive, /SINCE=creation_time, /TEMP_PATH=directory,",
  1573. " /LOG_FILE=(FILE=log_file[,APPEND][,INFORMATIONAL]), /MUST_MATCH,",
  1574. " /PATTERN_CASE={BLIND|SENSITIVE}, /NORECURSE|/RECURSE[={PATH|FILENAMES}],",
  1575. " /STORE_TYPES=(type_list),",
  1576. #if CRYPT
  1577. "\
  1578. /QUIET, /VERBOSE[={MORE|DEBUG}], /[NO]DIRNAMES, /JUNK, /ENCRYPT[=\"pwd\"],\
  1579. ",
  1580. #else /* !CRYPT */
  1581. " /QUIET, /VERBOSE[={MORE|DEBUG}], /[NO]DIRNAMES, /JUNK,",
  1582. #endif /* ?CRYPT */
  1583. " /COMPRESSION = {BZIP2|DEFLATE|STORE}, /LEVEL=[0-9], /NOVMS|/VMS[=ALL],",
  1584. " /STORE_TYPES=(type_list), /[NO]PRESERVE_CASE[=([NO]ODS{2|5}[,...])],",
  1585. " /[NO]PKZIP, /[NO]KEEP_VERSION, /DOT_VERSION, /TRANSLATE_EOL[={LF|CRLF}],",
  1586. " /DISPLAY=([BYTES][,COUNTS][,DOTS=mb_per_dot][,GLOBALDOTS][,USIZE]",
  1587. " [,VOLUME]), /DESCRIPTORS, /[NO]EXTRA_FIELDS, /ZIP64,",
  1588. #ifdef S_IFLNK
  1589. " /SPLIT = (SIZE=ssize [,BELL] [,PAUSE] [,VERBOSE]), /SYMLINKS"
  1590. #else /* S_IFLNK */
  1591. " /SPLIT = (SIZE=ssize [,BELL] [,PAUSE] [,VERBOSE])"
  1592. #endif /* S_IFLNK [else] */
  1593. };
  1594. if (!show_VMSCLI_help) {
  1595. help();
  1596. return;
  1597. }
  1598. for (i = 0; i < sizeof(copyright)/sizeof(char *); i++)
  1599. {
  1600. printf(copyright[i], "zip");
  1601. putchar('\n');
  1602. }
  1603. for (i = 0; i < sizeof(text)/sizeof(char *); i++)
  1604. {
  1605. printf(text[i], VERSION, REVDATE);
  1606. putchar('\n');
  1607. }
  1608. } /* end function VMSCLI_help() */
  1609. #endif /* !TEST */