static void imStatus(IMFILE *imf) { #ifdef UDEBUG if (imf->buffer != NULL) printmsg(18,"imStatus: " #ifdef BIT32ENV "%p" #else "%Fp" #endif " buffer address, %ld bytes used, %ld bytes capacity, " "current position %ld%s%s", imf->buffer, imf->inUse, imf->length, imf->position, imeof(imf) ? ", EOF" : "", imerror(imf) ? ", ERROR" : ""); #endif else if (imf->filename != NULL) { /* Only report the file is on disk once */ if ((imf->flag & IM_FLAG_DISKR) == 0) { imf->flag |= IM_FLAG_DISKR; printmsg(5,"imStatus: File resides on disk as %s with %ld bytes", imf->filename, imlength( imf )); } } else printmsg(5,"imstatus: No backing store exists for file"); } /* imStatus */
size_t imread(void *userBuffer, size_t objectSize, size_t objectCount, IMFILE * imf) { size_t bytes = objectSize * objectCount; imStatus(imf); if (imf->buffer == NULL) return fread(userBuffer, objectSize, objectCount, imf->stream); if ((objectSize <= 0) || (objectCount <= 0)) { printmsg(0, "imread: Requested read of less than one byte"); panic(); /* Die! */ errno = EINVAL; return 0; } if (imeof(imf)) return 0; if (imerror(imf)) return 0; if ((unsigned long) bytes <= (imf->inUse - imf->position)) { MEMCPY(userBuffer, imf->buffer + (size_t) imf->position, bytes); imf->position += bytes; return objectCount; } else return imread(userBuffer, objectSize, (size_t) (imf->inUse - imf->position ) / objectSize, imf); } /* imread */
void writePopMessage(SMTPClient *client, MailMessage *current, long bodyLines) { static const char mName[] = "writePopMessage"; static const char crlf[] = "\r\n"; KWBoolean networkError = KWFalse; /* We're dead, Jim */ KWBoolean continued = KWFalse; /* Previous line incomplete */ long octets = 0; const long bufferLength = min(32, (current->octets / 1024) + 1) * 1024; char *buffer; long bufferUsed = 0; if (imseek(client->transaction->imf, current->startPosition, SEEK_SET) == -1) { printerr("imfile"); SMTPResponse(client, PR_ERROR_GENERIC, "Seek failed"); return; } /* Allocate our buffer for processing */ buffer = malloc(bufferLength); checkref(buffer); /* Send the header line announcing a message follows */ sprintf(buffer, "%ld Octets", current->octets); if (!SMTPResponse(client, PR_OK_GENERIC, buffer)) { free(buffer); return; } /* Loop for entire header and as many lines of body as required */ for (;;) { KWBoolean incomplete = KWFalse; #ifdef UDEBUG KWBoolean quotedPeriod = KWFalse; #endif long position = imtell(client->transaction->imf); char *linePointer = buffer + bufferUsed; size_t length; if (position < 0) break; if (position >= current->endPosition) break; if ((position >= current->startBodyPosition) && (bodyLines-- < 0)) break; /* - 3 == Leave room for period, carriage-return, linefeed */ if (imgets(linePointer, bufferLength - bufferUsed - 3, client->transaction->imf) == NULL) { /* Jump out of loop on EOF */ break; } length = strlen(linePointer); if (linePointer[length - 1] == '\n') { /* Trim off LF we found (normal case); we'll add */ /* an Internet standard CR/LF period below if needed. */ linePointer[--length] = '\0'; } else { /* Line must be too long for normal use. */ incomplete = KWTrue; } /* Unlike SMTP, POP3 only checks first octet of each line for */ /* quoting a leading period; this makes an easy check. */ if (!continued && (linePointer[0] == '.')) { /* * Shift the entire buffer over one octet to byte stuff an * extra leading period. This quotes the original leading * perdiod. */ memmove(linePointer + 1, linePointer, length++); linePointer[0] = '.'; #ifdef UDEBUG quotedPeriod = KWTrue; #endif } #ifdef UDEBUG printmsg(5,"--> [%03d] %s%s%s%s", bufferUsed, linePointer, quotedPeriod ? " (quoted period)" : "", continued ? " (continued)" : "", incomplete ? " (incomplete)" : ""); #endif bufferUsed += length; /* Terminate the line */ if (! incomplete) { strcat(linePointer, crlf); /* Update our running total */ bufferUsed += 2; } /* Determine if we wand to flush buffer */ if ((bufferLength - bufferUsed) < 80) { if (SMTPResponse(client, PR_TEXT, buffer)) { octets += bufferUsed; bufferUsed = 0; } else { networkError = KWTrue; break; } } /* if ((bufferLength - bufferUsed) < 80) */ /* If this cycle is incomplete, we continue next cycle ... */ continued = incomplete; } /* for (;;) */ /*--------------------------------------------------------------------*/ /* End of our loop, clean up */ /*--------------------------------------------------------------------*/ /* Flush final information in buffer */ if (!networkError && (bufferUsed > 0)) { if (SMTPResponse(client, PR_TEXT, buffer)) { octets += bufferUsed; bufferUsed = 0; } else networkError = KWTrue; } /* if (bufferUsed > 0) */ if (imerror(client->transaction->imf)) printerr(client->transaction->mailboxName); /* Drop allocated resources */ free(buffer); /* Terminate the message with a line only consisting of a period (.) */ if (!networkError && !SMTPResponse(client, PR_DATA, ".")) networkError = KWTrue; if (networkError) { printmsg(3, "%s: Unable to send message %ld to %s " "because of network error.", mName, current->sequence, client->clientName); } else { printmsg(3, "%s: Sent message %ld to %s (%ld of %ld octets)", mName, current->sequence, client->clientName, octets, current->octets); } } /* writePopMessage */
int main( int argc, char **argv) { char fname[256]; char nom[256]; struct image *nf; Fort_int lfmt[9]; unsigned char *buf , *buf2; int sb = 0, i, j,z; struct pt_x* pt; struct pt_x *res; struct pt_x * tabPt_x; char reponse; float hr , hs; hr = 20; hs = 20; /* Initialisation */ inr_init( argc, argv, version, usage, detail); /* Lecture des options */ infileopt( fname); igetopt1("-hs", "%f", &hs); igetopt1("-hr", "%f", &hr); igetopt1("-max","%d", &max); igetopt1("-v","%d",&VOSIN); igetopt1("-n","%d",&noyau); igetopt1("-m","%d",&mode); igetopt1("-d","%d",&debug); outfileopt(nom); /*affichage the options */ fprintf(stderr, "=============OPTIONS===========\n"); fprintf(stderr, "hr = %f hs = %f\n",hr,hs); fprintf(stderr, "Voisnage = %d\n",VOSIN); if(noyau == 1){ fprintf(stderr, "Noyau = gaussian\n"); }else{ fprintf(stderr, "Noyau = epankovic\n"); } if(mode == 1){ fprintf(stderr, "Mode = segmentation\n"); }else{ fprintf(stderr, "Mode = debruit\n"); } printf("Image src = %s\n",fname); printf("Image target = %s\n",nom); printf("Mode debug = %d\n",debug); fprintf(stderr, "===============================\n"); fprintf(stderr, "would you like to continue the execution with current options ? (y,n)\n"); scanf("%c",&reponse); if(reponse!='y'){ return 0; } fprintf(stderr, "Start of execution\n"); /* Ouverture et lecture des images */ nf = image_(fname, "e", "", lfmt); /* verification du format */ if(TYPE == FIXE && BSIZE==1){ /* allocation memoire adequat */ buf = (unsigned char*)i_malloc( NDIMX * NDIMY* NDIMV *sizeof(unsigned char)); /* cree tableau de pt_x */ tabPt_x = malloc(NDIMX* NDIMY* NDIMV *sizeof(pt_x)); /* lecture image */ c_lect( nf, NDIMY, buf); }else{ imerror( 6, "codage non conforme\n"); } /* Remplir de Struct Special */ if(NDIMV == 1){ remplir_basic(buf,tabPt_x,NDIMX,NDIMY); } if(NDIMV == 3){ remplir_rgb(buf,tabPt_x,NDIMX,NDIMY); } /* Traitement */ /*debruit*/ buf2 = (unsigned char*)i_malloc( NDIMX * NDIMY*NDIMV*sizeof(unsigned char)); if(mode == 0){ if(NDIMV == 1){ debruit_basic(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); }else{ debruit_rgb(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); } }else{ segmentation(tabPt_x , buf2 , hs , hr , 0.1 , NDIMX, NDIMY); } /*sauvgarde*/ printf("sortir \n"); nf = c_image(nom,"c","",lfmt); c_ecr(nf,DIMY,buf2); /* fermeture image */ fermnf_( &nf); //free(&his); i_Free((void*)&buf); i_Free((void*)&buf2); return 0; }
int imunload(FILE *output, IMFILE *imf) { char *ioBuf = NULL; size_t ioBufSize = (28 * 1024); /*--------------------------------------------------------------------*/ /* We invert our normal logic, because 16 bit allocated in */ /* FAR memory cannot be blasted directly to disk. Thus, we */ /* handle the simple (and fast) 32 bit copy first and save */ /* the funky disk logic for last. */ /*--------------------------------------------------------------------*/ #ifdef BIT32ENV if (imf->buffer != NULL) { while (! imeof(imf)) { size_t bytes = imf->inUse - imf->position; if (bytes > fwrite(imf->buffer + imf->position, sizeof (char), bytes, output)) return -1; /* Report error to caller */ imf->position += bytes; } /* for */ return 0; /* Return success to caller */ } /* if (imf->buffer != NULL) */ #endif /* BIT32ENV */ /*--------------------------------------------------------------------*/ /* We need to buffer the input to output, process as normal */ /* files */ /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ /* Allocate a nice I/O bufer */ /*--------------------------------------------------------------------*/ while ((ioBuf == NULL) && (ioBufSize >= BUFSIZ)) { ioBuf = malloc(ioBufSize); if (ioBuf == NULL) { if (debuglevel > 2) printerr("imunload: malloc:"); ioBufSize /= 2; /* Try for half the buffer */ } } /* while ((ioBuf == NULL) && (ioBufSize >= BUFSIZ)) */ if (ioBuf == NULL) { printmsg(0,"imunload: Unable to allocate I/O buffer for copy"); panic(); } /*--------------------------------------------------------------------*/ /* Now copy the file */ /*--------------------------------------------------------------------*/ while (! imeof(imf)) { size_t bytes = imread(ioBuf, sizeof (char), ioBufSize, imf); if (imerror(imf)) { free(ioBuf); return -1; } if (bytes > fwrite(ioBuf, sizeof (char), (size_t) bytes, output)) { free(ioBuf); return -1; /* Report error to caller */ } } /* for */ free(ioBuf); return 0; /* Return success to caller */ } /* imunload */
char *imgets(char *userBuffer, int userLength, IMFILE *imf) { char UUFAR *p; size_t subscript = 0; imStatus(imf); if (imf->buffer == NULL) return fgets(userBuffer, userLength, imf->stream); if (imerror(imf) || imeof(imf)) return NULL; if (userLength < 2) /* Need room for \n and \0 */ { printmsg(0, "imgets: Requested read of less than two bytes"); panic(); /* Die! */ errno = EINVAL; return NULL; } /*--------------------------------------------------------------------*/ /* Select the string from our own buffer */ /*--------------------------------------------------------------------*/ p = imf->buffer + (size_t) imf->position; while ((subscript+1) < (size_t) userLength) { if (p[subscript] == '\0') { printmsg(2,"imgets: Encountered null byte %ld bytes into search", (long) subscript); } imf->position++; if (p[subscript++] == '\n') break; if (imeof(imf)) break; } MEMCPY(userBuffer, p, subscript); userBuffer[subscript++] = '\0'; #ifdef UDEBUG2 printmsg(5,"imgets: Returning %d bytes = \"%s\"", subscript, userBuffer); #endif if (subscript > (size_t) userLength) { printmsg(0,"imgets: Attempt to return overlength buffer" ); panic(); } return userBuffer; } /* imgets */