📄 uutcl.c
字号:
/* * This file is part of uudeview, the simple and friendly multi-part multi- * file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may * be contacted at fp@fpx.de * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *//* * The TCL Interface of UUDeview */#ifdef HAVE_CONFIG_H#include "config.h"#endif#if defined(HAVE_TCL) || defined(HAVE_TK)#ifdef SYSTEM_WINDLL#include <windows.h>#endif#ifdef SYSTEM_OS2#include <os2.h>#endif#ifdef STDC_HEADERS#include <stdlib.h>#include <string.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_ERRNO_H#include <errno.h>#endif#ifdef HAVE_TK#include <tk.h>#else#include <tcl.h>#endif/* * The following variable is a special hack that is needed in order for * Sun shared libraries to be used for Tcl. */extern int matherr();int *tclDummyMathPtr = (int *) matherr;#include <uudeview.h>#include <uuint.h>#include <fptools.h>/* * As Windows DLL, we need a DllEntryPoint */#ifdef SYSTEM_WINDLLBOOL _export WINAPI DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, LPVOID lpCmdLine){ /* Don't do anything, so just return true */ return TRUE;}#endif/* * Declare external functions as __cdecl for Watcom C */#ifdef __WATCOMC__#pragma aux (__cdecl) Tcl_Eval#pragma aux (__cdecl) Tcl_GetVar#pragma aux (__cdecl) Tcl_SetVar#pragma aux (__cdecl) Tcl_AppendResult#pragma aux (__cdecl) Tcl_SetResult#pragma aux (__cdecl) Tcl_CreateCommand#endif/* * cvs version */char * uutcl_id = "$Id: uutcl.c,v 1.14 2002/03/06 13:52:45 fp Exp $";/* * data for our Callbacks */static struct uutclcbdata { Tcl_Interp *interp; char tclproc[256];} theDMcbdata, theBusycbdata;/* * Don't let Uu_Init initialize us twice */static int uu_AlreadyInitialized = 0;/* * mail and news software */#ifdef PROG_INEWSchar * uue_inewsprog = PROG_INEWS;#elsechar * uue_inewsprog = NULL;#endif#ifdef PROG_MAILERchar * uue_mailprog = PROG_MAILER;#elsechar * uue_mailprog = NULL;#endif#ifdef MAILER_NEEDS_SUBJECTint uue_mpsubject = 1;#elseint uue_mpsubject = 0;#endif/* * Mail or Post a file. Remember to keep in sync with uuenview.c */static intSendAFile (Tcl_Interp *interp, FILE *infile, char *infname, int encoding, int linperfile, char *outfname, char *towhom, char *subject, char *from, char *replyto, int isemail){ char *command, *rcptlist, *ptr; FILE *thepipe, *theifile; int len, count, res, part; if (towhom==NULL || (outfname==NULL&&infname==NULL) || (infile&&infname==NULL) || (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { Tcl_SetResult (interp, "oops: Parameter check failed in SendAFile()", TCL_STATIC); return UURET_ILLVAL; }#ifndef HAVE_POPEN Tcl_SetResult (interp, "error: Your system does not support sending of files", TCL_STATIC); return UURET_ILLVAL;#else if (isemail && (uue_mailprog == NULL || *uue_mailprog == '\0')) { Tcl_SetResult (interp, "error: Cannot Email file: option not configured", TCL_STATIC); return UURET_ILLVAL; } else if (!isemail && (uue_inewsprog == NULL || *uue_inewsprog == '\0')) { Tcl_SetResult (interp, "error: Cannot Post file: option not configured", TCL_STATIC); return UURET_ILLVAL; } len = strlen ((isemail)?uue_mailprog:uue_inewsprog) + ((uue_mpsubject)?strlen(subject):0) + ((isemail)?0:strlen(towhom)) + 32; if ((command = (char *) malloc (len)) == NULL) { Tcl_SetResult (interp, "error: Out of memory allocating some bytes", TCL_STATIC); return UURET_NOMEM; } if ((rcptlist = (char *) malloc (strlen (towhom) + 16)) == NULL) { Tcl_SetResult (interp, "error: Out of memory allocating some bytes", TCL_STATIC); _FP_free (command); return UURET_NOMEM; } if (isemail) { if (uue_mpsubject) sprintf (command, "%s -s \"%s\"", uue_mailprog, subject); else sprintf (command, "%s", uue_mailprog); /* * Attach list of recipients to mailer command and compose another list * of recipients */ count = 0; rcptlist[0] = '\0'; ptr = _FP_strtok (towhom, ",; "); while (ptr) { strcat (command, " "); strcat (command, ptr); if (count++) strcat (rcptlist, ","); strcat (rcptlist, ptr); ptr = _FP_strtok (NULL, ",; "); } } else { sprintf (command, "%s", uue_inewsprog); count = 0; rcptlist[0] = '\0'; ptr = _FP_strtok (towhom, ";, "); while (ptr) { if (count++) strcat (rcptlist, ","); strcat (rcptlist, ptr); ptr = _FP_strtok (NULL, ";, "); } } if (from && *from == '\0') { from = NULL; } if (subject && *subject == '\0') { subject = NULL; } if (replyto && *replyto == '\0') { replyto = NULL; } /* * Get going ... */ if (infile == NULL) { if ((theifile = fopen (infname, "rb")) == NULL) { _FP_free (rcptlist); _FP_free (command); return UURET_IOERR; } } else { theifile = infile; } for (part=1; !feof (theifile); part++) { if ((thepipe = popen (command, "w")) == NULL) { if (infile==NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return UURET_IOERR; } if (UUGetOption(UUOPT_VERBOSE, NULL, NULL, 0)) {#if 0 fprintf (stderr, "%s part %03d of %s to %s ... ", (isemail)?"mailing":"posting", part, (infname)?infname:outfname, rcptlist); fflush (stderr);#endif } res = UUE_PrepPartialExt (thepipe, theifile, infname, encoding, outfname, 0, part, linperfile, 0, rcptlist, from, subject, replyto, isemail);#if 0 if (UUGetOption (UUOPT_VERBOSE, NULL, NULL, 0)) { if (res == UURET_OK) fprintf (stderr, "ok.\n"); else fprintf (stderr, "%s\n", UUstrerror (res)); }#endif pclose (thepipe); if (res != UURET_OK) { if (infile == NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return res; } } if (infile == NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return UURET_OK;#endif}/* * Display a Message in a dialog box */static voiduutcl_DisplayMessage (void *param, char *message, int level){ struct uutclcbdata *data = (struct uutclcbdata *) param; char tmpstring[2048]; if (data->interp && *data->tclproc) { sprintf (tmpstring, "%s %d {%s}\n", data->tclproc, level, message); Tcl_Eval (data->interp, tmpstring); }}/* * Our Busy Callback */static intuutcl_BusyCallback (void *param, uuprogress *progress){ struct uutclcbdata *data = (struct uutclcbdata *) param; if (data->interp && *data->tclproc) { Tcl_Eval (data->interp, data->tclproc); } return 0;}/* * exchage variables with the interpreter */static voiduutcl_UpdateParameter (Tcl_Interp *interp){ char *cval; if ((cval = Tcl_GetVar (interp, "OptionFast", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_FAST, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionBracket", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_BRACKPOL, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionDesperate",TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_DESPERATE, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionDebug", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_DEBUG, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionDumbness", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_DUMBNESS, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionUsetext", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_USETEXT, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "SaveFilePath", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_SAVEPATH, 0, cval); if ((cval = Tcl_GetVar (interp, "OptionRemove", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_REMOVE, atoi (cval), NULL); if ((cval = Tcl_GetVar (interp, "OptionMoreMime", TCL_GLOBAL_ONLY))!=NULL) UUSetOption (UUOPT_MOREMIME, atoi (cval), NULL);}/* * configuration info */static intuutcl_HaveArg (int argc, char *argv[], char *string){ int index; for (index=1; index<argc; index++) { if (_FP_stricmp (argv[index], string) == 0) return 1; } return 0;}static int UUTCLFUNCuutcl_Info (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]){ char temp[64], version[64]; if (argc==1 || uutcl_HaveArg (argc, argv, "version")) { UUGetOption (UUOPT_VERSION, NULL, version, 64); sprintf (temp, " { version %s } ", version); Tcl_AppendResult (interp, temp, NULL); } if (argc==1 || uutcl_HaveArg (argc, argv, "have_tcl"))#ifdef HAVE_TCL Tcl_AppendResult (interp, " { have_tcl 1 } ", NULL);#else Tcl_AppendResult (interp, " { have_tcl 0 } ", NULL);#endif if (argc==1 || uutcl_HaveArg (argc, argv, "have_tk"))#ifdef HAVE_TK Tcl_AppendResult (interp, " { have_tk 1 } ", NULL);#else Tcl_AppendResult (interp, " { have_tk 0 } ", NULL);#endif if (argc==1 || uutcl_HaveArg (argc, argv, "have_mail")) {#ifdef PROG_MAILER if (*PROG_MAILER) Tcl_AppendResult (interp, " { have_mail 1 } ", NULL); else Tcl_AppendResult (interp, " { have_mail 0 } ", NULL);#else Tcl_AppendResult (interp, " { have_mail 0 } ", NULL);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -