Skip to content

Commit

Permalink
article editation.
Browse files Browse the repository at this point in the history
some crap involving IList that I've forgotten.
  • Loading branch information
vogon committed Oct 21, 2002
1 parent 79b6253 commit 40a7c2e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 60 deletions.
85 changes: 54 additions & 31 deletions libinews/IList.c
Expand Up @@ -27,6 +27,9 @@ IList *ilist_append_data(IList *list, void *data);
IList *ilist_prepend(IList *list, IList *new_ptr);
IList *ilist_prepend_data(IList *list, void *data);

IList *ilist_insert(IList *insert_after, IList *new_ptr);
IList *ilist_insert_data(IList *insert_after, void *data);

IList *ilist_remove(IList *ptr);

IList *ilist_first(IList *list);
Expand All @@ -37,72 +40,92 @@ unsigned int ilist_length(IList *ptr);
IList *__get_last(IList *list);
IList *__get_first(IList *list);

/* FIXME: extremely quick implementation. probably 50 zillion bugs in the next
* 65 lines, but who's counting? -- vogon. */
/* FIXME: extremely quick implementation. probably 50 zillion bugs, but who's
* counting? -- vogon. */

IList *ilist_append(IList *list, IList *new_ptr) {
new_ptr->prev = __get_last(list);
if (new_ptr->prev) new_ptr->prev->next = new_ptr;
new_ptr->next = NULL;
new_ptr->prev = __get_last(list);
if (new_ptr->prev) new_ptr->prev->next = new_ptr;
new_ptr->next = NULL;

return __get_first(new_ptr);
return __get_first(new_ptr);
}

IList *ilist_append_data(IList *list, void *data) {
IList *new_ptr = (IList *)malloc(sizeof(IList));
IList *new_ptr = (IList *)malloc(sizeof(IList));

new_ptr->data = data;
new_ptr->data = data;

return ilist_append(list, new_ptr);
return ilist_append(list, new_ptr);
}

IList *ilist_prepend(IList *list, IList *new_ptr) {
new_ptr->next = __get_first(list);
if (new_ptr->next) new_ptr->next->prev = new_ptr;
new_ptr->prev = NULL;
new_ptr->next = __get_first(list);
if (new_ptr->next) new_ptr->next->prev = new_ptr;
new_ptr->prev = NULL;

return new_ptr;
return new_ptr;
}

IList *ilist_prepend_data(IList *list, void *data) {
IList *new_ptr = (IList *)malloc(sizeof(IList));
IList *new_ptr = (IList *)malloc(sizeof(IList));

new_ptr->data = data;

return ilist_prepend(list, new_ptr);
}

IList *ilist_insert(IList *insert_after, IList *new_ptr) {
new_ptr->prev = insert_after;

new_ptr->data = data;
if (insert_after) {
new_ptr->next = insert_after->next;
insert_after->next = new_ptr;
if (new_ptr->next) new_ptr->next->prev = new_ptr;
} else new_ptr->next = NULL;

return __get_first(new_ptr);
}

return ilist_prepend(list, new_ptr);
IList *ilist_insert_data(IList *insert_after, void *data) {
IList *new_ptr = (IList *)malloc(sizeof(IList));

new_ptr->data = data;

return ilist_insert(insert_after, new_ptr);
}

IList *ilist_remove(IList *ptr) {
if (ptr->prev) ptr->prev->next = ptr->next;
if (ptr->next) ptr->next->prev = ptr->prev;
if (ptr->prev) ptr->prev->next = ptr->next;
if (ptr->next) ptr->next->prev = ptr->prev;

return __get_first(ptr->next);
return __get_first(ptr->next);
}

unsigned int ilist_length(IList *ptr) {
int count = 0;
for (IList *iter = __get_first(ptr); iter != NULL; iter = iter->next) {
count++;
}
int count = 0;

for (IList *iter = __get_first(ptr); iter; iter = iter->next) {
count++;
}

return count;
return count;
}

IList *__get_last(IList *list) {
IList *last = list;
IList *last = list;

while (last && last->next) { last = last->next; }
while (last && last->next) { last = last->next; }

return last;
return last;
}

IList *__get_first(IList *list) {
IList *first = list;
IList *first = list;

while (first && first->prev) { first = first->prev; }
while (first && first->prev) { first = first->prev; }

return first;
return first;
}

IList *ilist_first(IList *list) { return __get_first(list); }
Expand Down
3 changes: 3 additions & 0 deletions libinews/IList.h
Expand Up @@ -35,6 +35,9 @@ extern IList *ilist_append_data(IList *list, void *data);
extern IList *ilist_prepend(IList *list, IList *new_ptr);
extern IList *ilist_prepend_data(IList *list, void *data);

extern IList *ilist_insert(IList *insert_after, IList *new_ptr);
extern IList *ilist_insert_data(IList *insert_after, void *data);

extern IList *ilist_remove(IList *ptr);

extern IList *ilist_first(IList *ptr);
Expand Down
55 changes: 29 additions & 26 deletions libinews/IcculusNews.h
Expand Up @@ -35,51 +35,51 @@ typedef signed long long Sint64;
typedef Uint8 bool;

#ifndef TRUE
#define TRUE 1
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#define FALSE 0
#endif

typedef struct {
Uint8 major;
Uint8 minor;
Uint8 rev;
Uint8 major;
Uint8 minor;
Uint8 rev;
} INEWS_Version;

typedef struct {
Uint8 qid;
char *name;
char *description;
char *digest;
char *singleitem;
char *home;
char *rdf;
struct tm ctime;
Uint8 owneruid;
char *ownername;
Uint8 qid;
char *name;
char *description;
char *digest;
char *singleitem;
char *home;
char *rdf;
struct tm ctime;
Uint8 owneruid;
char *ownername;
} QueueInfo;

typedef struct {
Uint16 aid;
char *title;
struct tm ctime;
Uint8 owneruid;
char *ownername;
char *dottedip;
bool approved;
bool deleted;
Uint16 aid;
char *title;
struct tm ctime;
Uint8 owneruid;
char *ownername;
char *dottedip;
bool approved;
bool deleted;
} ArticleInfo;

#define __INEWS_LINKTIME_MAJOR 0
#define __INEWS_LINKTIME_MINOR 0
#define __INEWS_LINKTIME_REV 1

#define INEWS_getLinktimeVersion() \
{ __INEWS_LINKTIME_MAJOR, \
__INEWS_LINKTIME_MINOR, \
__INEWS_LINKTIME_REV }
{ __INEWS_LINKTIME_MAJOR, \
__INEWS_LINKTIME_MINOR, \
__INEWS_LINKTIME_REV }

#define ERR_SUCCESS 0 /* success */
#define ERR_GENERIC -1 /* generic error; blame it on Gen. Protection */
Expand Down Expand Up @@ -145,6 +145,9 @@ extern ArticleInfo **INEWS_digest(int offset, int n);
/* submit an article. OMG */
extern Sint8 INEWS_submitArticle(char *title, char *body);

/* submit / edit an article. supersedes INEWS_submitArticle(). */
extern Sint8 INEWS_submitEditArticle(char *title, char *body, int aid);

/* change the approval status of article aid */
Sint8 INEWS_changeApprovalStatus(Uint32 aid, bool approve);

Expand Down
1 change: 1 addition & 0 deletions libinews/internals.h
Expand Up @@ -94,6 +94,7 @@ Sint8 INEWS_retrQueueInfo();
Sint8 INEWS_changeQueue(int qid);
ArticleInfo **INEWS_digest(int offset, int n);
Sint8 INEWS_submitArticle(char *title, char *body);
Sint8 INEWS_submitEditArticle(char *title, char *body, int aid);
Sint8 INEWS_changeApprovalStatus(Uint32 aid, bool approve);
Sint8 INEWS_changeDeletionStatus(Uint32 aid, bool deleteflag);
void INEWS_disconnect();
Expand Down
17 changes: 14 additions & 3 deletions libinews/net.c
Expand Up @@ -30,7 +30,10 @@
int __i; \
end_success: \
__i = 0; \
__inews_errno = ERR_SUCCESS; \
__inews_errno = (__inews_errno == \
ERR_STORYTOOLONG) ?\
ERR_STORYTOOLONG : \
ERR_SUCCESS; \
goto real_end; \
end_failure: \
__i = 1; \
Expand Down Expand Up @@ -328,7 +331,7 @@ ArticleInfo **INEWS_digest(int offset, int n) {

/* iterate through the cache, and set the offset to the lowest-numbered
* cached item. assume that the items are listed in descending order of
* article ID. */
* article ID, and that there are no gaps in the cache. */

for (IList *ptr = digestcache; ptr; ptr = ilist_next(ptr)) {
ArticleInfo *tempptr = (ArticleInfo *)malloc(sizeof(ArticleInfo));
Expand Down Expand Up @@ -451,6 +454,10 @@ ArticleInfo **INEWS_digest(int offset, int n) {
}

Sint8 INEWS_submitArticle(char *title, char *body) {
return INEWS_submitEditArticle(title, body, -1);
}

Sint8 INEWS_submitEditArticle(char *title, char *body, int aid) {
char tempstring[512];
Uint32 maxlen;

Expand All @@ -466,7 +473,11 @@ Sint8 INEWS_submitArticle(char *title, char *body) {

memset(tempstring, 0, 512);

sprintf(tempstring, "POST %s\n", title);
if (aid > 0) {
sprintf(tempstring, "EDIT %i %s\n", aid, title);
} else {
sprintf(tempstring, "POST %s\n", title);
}

pthread_mutex_lock(&net_mutex);

Expand Down

0 comments on commit 40a7c2e

Please sign in to comment.