Example #1
0
//secstr == NULL: all boards
//secstr == "": boards that doesnn't belong to any group
//return the bnum of one of the match boards
static int
searchlist_alphabetical(const char *sectitle, const char *secstr, char *match,
			int showintro, int *bnum)
{
	struct boardmem *(data[MAXBOARD]), *bx;
	int i, len = 0, total = 0;
	if (secstr) {
		len = strlen(secstr);
		if (len == 0)
			len = 1;
	}
	for (i = 0; i < MAXBOARD && i < shm_bcache->number; i++) {
		bx = &shm_bcache->bcache[i];
		if (secstr && strncmp(bx->header.sec1, secstr, len)
		    //&& strncmp(bx->header.sec2, secstr, len)
		    )
			continue;
		if (!strcasestr(bx->header.filename, match) &&
		    !strcasestr(bx->header.title, match) &&
		    !strcasestr(getboardaux(i)->intro, match))
			continue;
		if (has_view_perm_x(currentuser, bx)) {
			*bnum = i;
			data[total] = bx;
			total++;
		}
	}
	if (!total)
		return 0;

	printhr();
	printf("<b>·ÖÇø: <a href=boa?secstr=%s>%s</a></b>", secstr,
	       nohtml(sectitle));
	qsort(data, total, sizeof (struct boardmem *), (void *) cmpboard);
	printf("<table width=100%%>\n");
	for (i = 0; i < total; i++) {
		if (showintro || (i && i % 3 == 0))
			printf("</tr>");
		if (showintro || i % 3 == 0)
			printf("\n<tr valign=top bgcolor=%x>",
			       0xf0f0d0 | (unsigned) (i % 2) * 0x0f0f0f);
		printf
		    ("<td><a href='javascript:setEl(\"%s\")'><nobr>%s(%s)</nobr></a></td>",
		     data[i]->header.filename, data[i]->header.filename,
		     nohtml(data[i]->header.title));
		if (showintro) {
			struct boardaux *baux;
			baux = getboardaux(getbnumx(data[i]));
			if (baux != NULL)
				printf("<td>%s</td>", nohtml(baux->intro));
		}
	}
	printf("</table>\n");
	return total;
}
Example #2
0
int
bbsbknsel_main()
{
	FILE *fp;
	char board[80], dir[160], genbuf[STRLEN];
	struct boardmem *x1;
	struct bknheader x;
	int i, start, total;
	html_header(1);
	printf("<script src=" BBSJS "></script>\n");
	//check_msg();
	changemode(SELBACKNUMBER);
	getparmboard(board, sizeof (board));
	x1 = getboard(board);
	if (x1 == 0)
		nosuchboard(board, "bbsbknsel");
	else {
		strcpy(board, x1->header.filename);
		sprintf(dir, "boards/.backnumbers/%s/.DIR", board);
		fp = fopen(dir, "r");
		if (fp == NULL)
			http_fatal("错误的讨论区");
		total = file_size(dir) / sizeof (struct bknheader);
		start = getdocstart(total, w_info->t_lines);
		printf("<body topmargin=0><nobr><center>\n");
		sprintf(genbuf, "选择过刊 过刊数[%d]", total);
		printboardtop(x1, 5, genbuf);
		if (total <= 0) {
			fclose(fp);
			http_fatal("本讨论区目前没有过刊");
		}
		printf("<table cellSpacing=0 cellPadding=2>\n");
		printf
		    ("<tr class=docbgcolor><td>序号</td><td>讨论区</td><td>建立日期</td><td>标题              </td></tr>\n");
		if (fp) {
			fseek(fp, (start - 1) * sizeof (struct bknheader),
			      SEEK_SET);
			for (i = 0; i < w_info->t_lines; i++) {
				if (fread(&x, sizeof (x), 1, fp) <= 0)
					break;
				printf("<tr><td>%d</td><td>%s</td>",
				       start + i, x.boardname);
				if (!i)
					printf("<td><nobr>%12.12s</td>",
					       Ctime(x.filetime) + 4);
				else
					printf("<td>%12.12s</td>",
					       Ctime(x.filetime) + 4);
				printf
				    ("<td><a href=bbsbkndoc?B=%d&bkn=%s&num=%d>○ %s </a></td></tr>",
				     getbnumx(x1), bknh2bknname(&x), start + i - 1,
				     void1(titlestr(x.title)));
			}
			printf("</table>");
			printhr();
			fclose(fp);
		}
		printf("选择过刊 过刊数[%d] ", total);
		sprintf(genbuf, "bbsbknsel?B=%d", getbnumx(x1));
		bbsdoc_helper(genbuf, start, total, w_info->t_lines);
		printdocform("bbsbknsel", getbnumx(x1));
		http_quit();
	}
	return 0;
}
Example #3
0
int
bbsbkndoc_main()
{
	FILE *fp;
	char board[80], bkn[80], dir[160], *ptr, genbuf[STRLEN];
	struct boardmem *x1;
	struct fileheader x;
	int i, start, total;
	html_header(1);
	printf("<script src=" BBSJS "></script>\n");
	changemode(BACKNUMBER);
	//check_msg();
	getparmboard(board, sizeof(board));
	strsncpy(bkn, getparm("bkn"), 32);
	ptr = bkn;
	while (*ptr) {
		if (*ptr != 'B' && *ptr != '.' && !isdigit(*ptr))
			http_fatal("错误的过刊号");
		ptr++;
	}
	if (strlen(bkn) < 3)
		http_fatal("错误的过刊号");

	x1 = getboard(board);
	if (x1 == 0)
		nosuchboard(board, "bbsbkndoc");
	else {
		updateinboard(x1);
		strcpy(board, x1->header.filename);
		sprintf(dir, "boards/.backnumbers/%s/%s", board, bkn);
		if (!file_exist(dir))
			http_fatal("没有这卷过刊");
		sprintf(dir, "boards/.backnumbers/%s/%s/.DIR", board, bkn);
		fp = fopen(dir, "r");
		total = file_size(dir) / sizeof (struct fileheader);
		start = getdocstart(total, w_info->t_lines);
		printf("<body topmargin=0>");
		printf("<nobr><center>\n");
		sprintf(genbuf, "阅览过刊 文章数[%d]", total);
		printboardtop(x1, 5, genbuf);
		if (total <= 0)
			http_fatal("本卷过刊目前没有文章");
		printf("<table cellSpacing=0 cellPadding=2>\n");
		printf
		    ("<tr class=docbgcolor><td>序号<td>状态<td>作者<td>日期<td>标题<td>星级<td>评价</td>\n");
		if (fp) {
			fseek(fp, (start - 1) * sizeof (struct fileheader),
			      SEEK_SET);
			for (i = 0; i < w_info->t_lines; i++) {
				char filename[255];
				char *ptr;
				if (fread(&x, sizeof (x), 1, fp) <= 0)
					break;
				if (x.accessed & FH_HIDE) {
					printf
					    ("<tr><td>%d<td>&nbsp;<td>不详<td>不详<td>-本文已经被删除-<td>\n",
					     start + i);
					continue;
				}
				ptr = flag_str2(x.accessed, 1);
				sprintf(filename,
					"boards/.backnumbers/%s/%s/%s", board,
					bkn, fh2fname(&x));
				printf("<tr><td>%d<td>%s<td>%s", start + i, ptr,
				       userid_str(x.owner));
				printf("<td>%12.12s", Ctime(x.filetime) + 4);
				x.title[40] = 0;
				printf
				    ("<td><a href=bbsbkncon?B=%d&bkn=%s&file=%s&num=%d>%s%s </a>%s",
				     getbnumx(x1), bkn, fh2fname(&x), start + i - 1,
				     strncmp(x.title, "Re: ", 4) ? "○ " : "",
				     void1(titlestr(x.title)),
				     size_str(eff_size(filename)));
				printf("<td><font color=%s>%d</font>\n",
				       x.staravg50 ? "red" : "black",
				       x.staravg50 / 50);
				printf("<td><font color=%s>%d人</font>\n",
				       x.hasvoted ? "red" : "black",
				       x.hasvoted);
			}
			printf("</table>");
			printhr();
			fclose(fp);
		}
		sprintf(genbuf, "bbsbkndoc?B=%d&bkn=%s", getbnumx(x1), bkn);
		bbsdoc_helper(genbuf, start, total, w_info->t_lines);
		printf("<table><tr><td><form name=form1 action=bbsbkndoc>\n");
		printf("<input type=hidden name=B value=%d>", getbnumx(x1));
		printf("<input type=hidden name=bkn value=%s>", bkn);
		printf
		    ("<input type=submit value=跳转到> 第 <input type=text name=start size=4> 篇");
		printf("</form>\n");
		printf("</td><td><form name=form2 action=bbsdoc>\n");
		printf
		    ("<input type=submit value=跳转到><input type=text name=board size=5> 讨论区");
		printf("</form></td></tr></table>\n");
		showfile(MY_BBS_HOME "/wwwtmp/googleanalytics");
		printf("</body>");
		http_quit();
	}
	return 0;
}
Example #4
0
int main(int argc, const char * argv[])
{
    int size;
    printf("Enter a number of bytes plz: ");
    scanf("%d", &size);
    
    unsigned char *p = (unsigned char *)malloc(size);
    if (!p) {
        printf("shit the bed");
        exit(1);
    }

    
    int i;
    printf("Ok, please enter UNSIGNED DECIMAL value for each byte: \n");
    for (i = 0; i < size; i++) {
        scanf("%hhu", p+i);
        //printf("Printing: %hhu, %hhd, %c\n", *(p+i), *(p+i), *(p+i));
    }
    

    
    

    printf("Ok, wrote those %d bytes into malloc'd memory at %p\n", size, p);

    
    /* CHAR */
    char *charp = p;
    int width = 4;
    printhr(PREFIX, size / sizeof(char), 4);
    printf("%21s", "char as unsigned hex");
    
    for (i = 0; i < size / sizeof(char); i++) {
        printf("|0x%02hhx", charp[i]);
    }

    printf("\n%21s", "unsigned dec");
    for (i = 0; i < size / sizeof(char); i++) {
        printf("|%4hhu", charp[i]);
    }

    printf("\n%21s", "signed dec");
    for (i = 0; i < size / sizeof(char); i++) {
        printf("|%4hhd", charp[i]);
    }

    printf("\n%21s", "character");
    for (i = 0; i < size / sizeof(char); i++) {
        printf("|");
        printchar(charp[i]);
    }
    printf("\n");
    
    
    /* SHORT */
    short *shortp = p;
    printhr(PREFIX, size / sizeof(short), 9);
    
    printf("%21s", "short as unsigned hex");
    for (i = 0; i < size / sizeof(short); i++) {
        printf("|   0x%04hx", shortp[i]);
    }
    
    printf("\n%21s", "unsigned dec");
    for (i = 0; i < size / sizeof(short); i++) {
        printf("|%9hu", shortp[i]);
    }
    
    printf("\n%21s", "signed dec");
    for (i = 0; i < size / sizeof(short); i++) {
        printf("|%9hd", shortp[i]);
    }
    printf("\n");
    
    
    
    /* INT */
    int *intp = p;
    float *floatp = p;
    printhr(PREFIX, size / sizeof(int), 19);
    
    printf("%21s", "int as unsigned hex");
    for (i = 0; i < size / sizeof(int); i++) {
        printf("|         0x%08x", intp[i]);
    }
    
    printf("\n%21s", "unsigned dec");
    for (i = 0; i < size / sizeof(int); i++) {
        printf("|%19u", intp[i]);
    }
    
    printf("\n%21s", "signed dec");
    for (i = 0; i < size / sizeof(int); i++) {
        printf("|%19d", intp[i]);
    }

    printf("\n%21s", "float");
    for (i = 0; i < size / sizeof(float); i++) {
        printf("|%19.4f", floatp[i]);
    }
    printf("\n");
    
    
    
    
    
    /* LONG */
    long *longp = p;
    double *doublep = p;
    printhr(PREFIX, size / sizeof(long), 39);
    
    printf("%21s", "long as unsigned hex");
    for (i = 0; i < size / sizeof(long); i++) {
        printf("|                     0x%016lx", longp[i]);
    }
    
    printf("\n%21s", "unsigned dec");
    for (i = 0; i < size / sizeof(long); i++) {
        printf("|%39lu", longp[i]);
    }
    
    printf("\n%21s", "signed dec");
    for (i = 0; i < size / sizeof(long); i++) {
        printf("|%39ld", longp[i]);
    }
    
    printf("\n%21s", "double");
    for (i = 0; i < size / sizeof(double); i++) {
        printf("|%39lf", doublep[i]);
    }
    printf("\n");
    
    printhr(PREFIX, size / sizeof(long), 39);
    
    
    
    free(p);
    
    
//    double pi = 3.141592653589793;
//    printf("%72s%lx\n", " ", *((long *)&pi));
//    p = (unsigned char *)&pi;
//    printf("%72s", " ");
//    for (i = 0; i < sizeof(double); i++) {
//        printf("%5hhu ", *p++);
//    }
//    printf("\n");

   return 0; 
}