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; }
static int UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc) { unsigned char *itemp = (unsigned char *) uuestr_itemp; unsigned char *otemp = (unsigned char *) uuestr_otemp; unsigned char *optr, *table, *tptr; int index, count; long line=0; size_t llen; if (outfile==NULL || infile==NULL || (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeStream()"); return UURET_ILLVAL; } /* * Special handling for plain text and quoted printable. Text is * read line oriented. */ if (encoding == PT_ENCODED || encoding == QP_ENCODED) { while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { if (_FP_fgets ((char*)itemp, 255, infile) == NULL) { break; } itemp[255] = '\0'; count = strlen ((char*)itemp); llen = 0; optr = otemp; /* * Busy Callback */ if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, uustring (S_ENCODE_CANCEL)); return UURET_CANCEL; } if (encoding == PT_ENCODED) { /* * If there is a line feed, replace by eolstring */ if (count > 0 && itemp[count-1] == '\n') { const size_t n = strlen ((char*) eolstring); itemp[--count] = '\0'; if (fwrite (itemp, 1, count, outfile) != count || fwrite ((char *) eolstring, 1, n, outfile) != n) { return UURET_IOERR; } } else { if (fwrite (itemp, 1, count, outfile) != llen) { return UURET_IOERR; } } } else if (encoding == QP_ENCODED) { for (index=0; index<count; index++) { if (llen == 0 && itemp[index] == '.') { /* * Special rule: encode '.' at the beginning of a line, so * that some mailers aren't confused. */ *optr++ = '='; *optr++ = HexEncodeTable[itemp[index] >> 4]; *optr++ = HexEncodeTable[itemp[index] & 0x0f]; llen += 3; } else if ((itemp[index] >= 33 && itemp[index] <= 60) || (itemp[index] >= 62 && itemp[index] <= 126) || itemp[index] == 9 || itemp[index] == 32) { *optr++ = itemp[index]; llen++; } else if (itemp[index] == '\n') { /* * If the last character before EOL was a space or tab, * we must encode it. If llen > 74, there's no space to do * that, so generate a soft line break instead. */ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32)) { *(optr-1) = '='; if (llen <= 74) { *optr++ = HexEncodeTable[itemp[index-1] >> 4]; *optr++ = HexEncodeTable[itemp[index-1] & 0x0f]; llen += 2; } } if (fwrite (otemp, 1, llen, outfile) != llen || fwrite ((char *) eolstring, 1, strlen((char*)eolstring), outfile) != strlen ((char*)eolstring)) { return UURET_IOERR; } /* * Fix the soft line break condition from above */ if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) && *(optr-1) == '=') { otemp[0] = '='; otemp[1] = HexEncodeTable[itemp[index-1] >> 4]; otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f]; if (fwrite (otemp, 1, 3, outfile) != 3 || fwrite ((char *) eolstring, 1, strlen((char*)eolstring), outfile) != strlen ((char*)eolstring)) { return UURET_IOERR; } } optr = otemp; llen = 0; }