int main (int argc, char *argv[]) { uulist *item; int i, res; UUInitialize (); for (i=1; i<argc; i++) if ((res = UULoadFile (argv[i], NULL, 0)) != UURET_OK) fprintf (stderr, "could not load %s: %s\n", argv[i], (res==UURET_IOERR) ? strerror (UUGetOption (UUOPT_ERRNO, NULL, NULL, 0)) : UUstrerror(res)); for (i=0; (item=UUGetFileListItem(i)) != NULL; i++) { if ((item->state & UUFILE_OK) == 0) continue; if ((res = UUDecodeFile (item, NULL)) != UURET_OK) { fprintf (stderr, "error decoding %s: %s\n", (item->filename==NULL)?"oops":item->filename, (res==UURET_IOERR) ? strerror (UUGetOption (UUOPT_ERRNO, NULL, NULL, 0)) : UUstrerror(res)); } else { printf ("successfully decoded '%s'\n", item->filename); } } UUCleanUp (); return 0; }
int main (int argc, char *argv[]) { UUInitialize (); UULoadFile (argv[1], NULL, 0); UUDecodeFile (UUGetFileListItem (0), NULL); UUCleanUp (); return 0; }
static int UUTCLFUNC uutcl_GetListOfFiles (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { char tmpstring[1024], t2[42]; int count=0, index=0; uulist *iter; uutcl_UpdateParameter (interp); while ((iter=UUGetFileListItem(count))) { if (((iter->state & UUFILE_OK) || UUGetOption (UUOPT_DESPERATE, NULL, NULL, 0)) && iter->filename) { sprintf (tmpstring, " { %d %d {%s} %s %s {", count, iter->state, iter->filename, (iter->mimetype)?iter->mimetype:"{}", (iter->uudet == UU_ENCODED) ? "UUdata " : (iter->uudet == B64ENCODED) ? "Base64 " : (iter->uudet == XX_ENCODED) ? "XXdata " : (iter->uudet == BH_ENCODED) ? "Binhex " : (iter->uudet == YENC_ENCODED) ? "yEnc" : "Text"); if (iter->haveparts) { sprintf (t2, "%s%s%d ", (iter->begin&&iter->begin==iter->haveparts[0])?"begin ":"", (iter->end &&iter->end == iter->haveparts[0])?"end " :"", iter->haveparts[0]); strcat (tmpstring, t2); for (index=1; iter->haveparts[index]; index++) { sprintf (t2, "%s%s%d ", (iter->begin==iter->haveparts[index]) ? "begin " : "", (iter->end == iter->haveparts[index]) ? "end " : "", iter->haveparts[index]); strcat (tmpstring, t2); } } if (iter->state & UUFILE_OK) strcat (tmpstring, "OK"); strcat (tmpstring, "} }"); Tcl_AppendResult (interp, tmpstring, NULL); } count++; } return TCL_OK; }
static int UUTCLFUNC uutcl_InfoFile (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { struct uuInfoCBData data; char tmpstring[256]; uulist *iter; int res; uutcl_UpdateParameter (interp); if (argc != 3) { sprintf (tmpstring, "wrong # args: should be \"%s number textwidget\"", argv[0]); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) { Tcl_SetResult (interp, "invalid file number", TCL_STATIC); return TCL_ERROR; } sprintf (tmpstring, "%s delete 1.0 end", argv[2]); if (Tcl_Eval (interp, tmpstring) != TCL_OK) return TCL_ERROR; data.interp = interp; data.widget = argv[2]; if ((res = UUInfoFile (iter, &data, uutcl_InfoCallback)) != UURET_OK) { sprintf (tmpstring, "Error while getting info for %s (%s): %s (%s)", (iter->filename) ? iter->filename : "", (iter->subfname) ? iter->subfname : "", UUstrerror (res), (res==UURET_IOERR)? strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):""); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } return TCL_OK; }
static int UUTCLFUNC uutcl_GetTempFile (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { char tmpstring[256]; uulist *iter; int res; uutcl_UpdateParameter (interp); if (argc != 2) { sprintf (tmpstring, "wrong # args: should be \"%s number\"", argv[0]); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) { Tcl_SetResult (interp, "invalid file number", TCL_STATIC); return TCL_ERROR; } if ((res = UUDecodeToTemp (iter)) != UURET_OK) { sprintf (tmpstring, "Error while decoding %s (%s): %s (%s)", (iter->filename) ? iter->filename : "", (iter->subfname) ? iter->subfname : "", UUstrerror (res), (res==UURET_IOERR)? strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):""); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } if (iter->binfile == NULL) { Tcl_SetResult (interp, "unknown error while decoding", TCL_STATIC); return TCL_ERROR; } Tcl_SetResult (interp, iter->binfile, TCL_VOLATILE); return TCL_OK; }
static int UUTCLFUNC uutcl_Rename (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { char tmpstring[256]; uulist *iter; int res; uutcl_UpdateParameter (interp); if (argc != 3) { sprintf (tmpstring, "wrong # args: should be \"%s number newname\"", argv[0]); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } if (*argv[2] == '\0') { Tcl_SetResult (interp, "illegal file name", TCL_STATIC); return TCL_ERROR; } if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) { Tcl_SetResult (interp, "invalid file number", TCL_STATIC); return TCL_ERROR; } if ((res = UURenameFile (iter, argv[2])) != UURET_OK) { sprintf (tmpstring, "could not rename %s to %s: %s (%s)", (iter->filename) ? iter->filename : "", argv[2], UUstrerror (res), (res==UURET_IOERR)? strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):""); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } return TCL_OK; }
static int UUTCLFUNC uutcl_ListFile (ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { uulist *iter; struct uuInfoCBData data; char tmpstring[1024]; FILE *inpfile; int res; uutcl_UpdateParameter (interp); if (argc != 3) { sprintf (tmpstring, "wrong # args: should be \"%s number textwidget\"", argv[0]); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) { Tcl_SetResult (interp, "invalid file number", TCL_STATIC); return TCL_ERROR; } if ((res = UUDecodeToTemp (iter)) != UURET_OK) { sprintf (tmpstring, "Error while decoding %s (%s): %s (%s)", (iter->filename) ? iter->filename : "", (iter->subfname) ? iter->subfname : "", UUstrerror(res), (res==UURET_IOERR)? strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):""); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } sprintf (tmpstring, "%s delete 1.0 end", argv[2]); if (Tcl_Eval (interp, tmpstring) != TCL_OK) return TCL_ERROR; if (iter->binfile==NULL || (inpfile=fopen (iter->binfile, "r"))==NULL) { Tcl_SetResult (interp, "couldn't read file", TCL_STATIC); return TCL_ERROR; } if ((inpfile = fopen (iter->binfile, "r")) == NULL) { sprintf (tmpstring, "Could not open temp file %s of %s (%s): %s", iter->binfile, (iter->filename) ? iter->filename : "", (iter->subfname) ? iter->subfname : "", strerror (errno)); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); return TCL_ERROR; } data.interp = interp; data.widget = argv[2]; while (!feof (inpfile)) { if (_FP_fgets (tmpstring, 512, inpfile) == NULL) break; if (ferror (inpfile)) break; if (uutcl_InfoCallback (&data, tmpstring)) break; } if (ferror (inpfile)) { sprintf (tmpstring, "Error while reading from temp file %s of %s (%s): %s", iter->binfile, (iter->filename) ? iter->filename : "", (iter->subfname) ? iter->subfname : "", strerror (errno)); Tcl_SetResult (interp, tmpstring, TCL_VOLATILE); fclose (inpfile); return TCL_ERROR; } fclose (inpfile); return TCL_OK; }