KvArt

dz5_process

Jun 1st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "dz5.h"
  5. /*Brisanje na osnovu e-mail adrese*/
  6. User *Delete(User *head, char *EmailCMP) {
  7.     char c;
  8.     User *CurrUser, *DelUser;
  9.     Field *HeadField, *MailField;
  10.     int k;
  11.  
  12.  
  13.     k = strlen(EmailCMP);
  14.     CurrUser = head;
  15.     HeadField = CurrUser->values;
  16.     while (CurrUser) {
  17.         MailField = Search(HeadField, 5);
  18.         if (!(strncmp(MailField->FieldValue, EmailCMP, k))) {
  19.             /*Ako je element na kraju*/
  20.             if ((CurrUser->previous) && (CurrUser->next == NULL)) {
  21.                 CurrUser->previous->next = CurrUser->next;
  22.                 free(CurrUser);
  23.                 CurrUser = NULL;
  24.                 continue;
  25.             }
  26.  
  27.             /*Ako je element na pocetku*/
  28.             if ((CurrUser->previous == NULL) && (CurrUser->next)) {
  29.                 head = head->next;
  30.                 head->previous = NULL;
  31.                 DelUser = CurrUser;
  32.                 CurrUser = head;
  33.                 if (CurrUser) HeadField = CurrUser->values;
  34.                 free(DelUser);
  35.                 continue;
  36.             }
  37.  
  38.             /*Ako je jedini element*/
  39.             if ((CurrUser->next == CurrUser->previous)) {
  40.                 head = NULL;
  41.                 free(CurrUser);
  42.                 CurrUser = NULL;
  43.                 continue;
  44.             }
  45.  
  46.             /*Ako je element u sredini*/
  47.             if ((CurrUser->next) && (CurrUser->previous)) {
  48.                 CurrUser->previous->next = CurrUser->next;
  49.                 CurrUser->next->previous = CurrUser->previous;
  50.                 DelUser = CurrUser;
  51.                 CurrUser = CurrUser->next;
  52.                 if (CurrUser) HeadField = CurrUser->values;
  53.                 free(DelUser);
  54.                 continue;
  55.             }
  56.         }
  57.         CurrUser = CurrUser->next;
  58.         if (CurrUser) HeadField = CurrUser->values;
  59.     }
  60.     return(head);
  61. }
  62. /*Potraga za odgovarajucim poljem*/
  63. Field *Search(Field *CurrField, int i) {
  64.     Field *target;
  65.     int j = 1;
  66.     target = CurrField;
  67.     while (target)
  68.         if (j == i) return (target);
  69.         else {
  70.             target = target->next;
  71.             j++;
  72.         }
  73. }
  74.  
  75. void Brisi(char *InputName, char *OutputName, User *head, Ldif_f *LDIFFields) {
  76.     User *CurrUser;
  77.     Field *CurrField, *HeadField;
  78.     Ldif_f *CurrLDIF;
  79.     if (InputName) free(InputName);
  80.     if (OutputName) free(OutputName);
  81.  
  82.     if (head)
  83.         while (head) {
  84.             CurrUser = head;
  85.             head = head->next;
  86.             HeadField = CurrUser->values;
  87.             while (HeadField) {
  88.                 CurrField = HeadField;
  89.                 HeadField = HeadField->next;
  90.                 free(CurrField->FieldValue);
  91.                 free(CurrField);
  92.             }
  93.             free(CurrUser);
  94.         }
  95.  
  96.     if (LDIFFields)
  97.         while (LDIFFields) {
  98.             CurrLDIF = LDIFFields;
  99.             LDIFFields = LDIFFields->next;
  100.             free(CurrLDIF->FieldName);
  101.             free(CurrLDIF);
  102.         }
  103. }
Add Comment
Please, Sign In to add comment