00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define NEXT_ARG { curr_arg++; argc--; }
00029
00030 static int tcl_compress_file STDVAR
00031 {
00032 int mode_num = compress_level, result, curr_arg = 1;
00033 char *fn_src = NULL, *fn_target = NULL;
00034
00035 BADARGS(2, 5, " ?options...? src-file ?target-file?");
00036
00037 while ((argc > 1) && ((argv[curr_arg])[0] == '-')) {
00038 if (!strcmp(argv[curr_arg], "-level")) {
00039 argc--;
00040 if (argc <= 1) {
00041 Tcl_AppendResult(irp, "option `-level' needs parameter", NULL);
00042 return TCL_ERROR;
00043 }
00044 curr_arg++;
00045 mode_num = atoi(argv[curr_arg]);
00046 } else {
00047 Tcl_AppendResult(irp, "unknown option `", argv[curr_arg], "'", NULL);
00048 return TCL_ERROR;
00049 }
00050 NEXT_ARG;
00051 }
00052 if (argc <= 1) {
00053 Tcl_AppendResult(irp, "expecting src-filename as parameter", NULL);
00054 return TCL_ERROR;
00055 }
00056 fn_src = argv[curr_arg];
00057 NEXT_ARG;
00058 if (argc > 1) {
00059 fn_target = argv[curr_arg];
00060 NEXT_ARG;
00061 }
00062 if (argc > 1) {
00063 Tcl_AppendResult(irp, "trailing, unexpected parameter to command", NULL);
00064 return TCL_ERROR;
00065 }
00066
00067 if (fn_target)
00068 result = compress_to_file(fn_src, fn_target, mode_num);
00069 else
00070 result = compress_file(fn_src, mode_num);
00071
00072 if (result)
00073 Tcl_AppendResult(irp, "1", NULL);
00074 else
00075 Tcl_AppendResult(irp, "0", NULL);
00076 return TCL_OK;
00077 }
00078
00079 static int tcl_uncompress_file STDVAR
00080 {
00081 int result;
00082
00083 BADARGS(2, 3, " src-file ?target-file?");
00084
00085 if (argc == 2)
00086 result = uncompress_file(argv[1]);
00087 else
00088 result = uncompress_to_file(argv[1], argv[2]);
00089
00090 if (result)
00091 Tcl_AppendResult(irp, "1", NULL);
00092 else
00093 Tcl_AppendResult(irp, "0", NULL);
00094 return TCL_OK;
00095 }
00096
00097 static int tcl_iscompressed STDVAR
00098 {
00099 int result;
00100
00101 BADARGS(2, 2, " compressed-file");
00102
00103 result = is_compressedfile(argv[1]);
00104 if (result == COMPF_UNCOMPRESSED)
00105 Tcl_AppendResult(irp, "0", NULL);
00106 else if (result == COMPF_COMPRESSED)
00107 Tcl_AppendResult(irp, "1", NULL);
00108 else
00109 Tcl_AppendResult(irp, "2", NULL);
00110 return TCL_OK;
00111 }
00112
00113 static tcl_cmds my_tcl_cmds[] = {
00114 {"compressfile", tcl_compress_file},
00115 {"uncompressfile", tcl_uncompress_file},
00116 {"iscompressed", tcl_iscompressed},
00117 {NULL, NULL}
00118 };