<span span标签class属性=emoji emoji1f311></span>

Raver狂欢季:剁手不如来蹦迪 - 专栏文章 - 网易云音乐
喜欢电音的盆友有福啦,5位电音大咖,全球顶级DJ:Hardwell,KSHMR,Nicky Romero,Steve Aoki,DJ Snake,即将震撼登陆北京举办个人专场演出,轮番轰炸你的耳际爆点,为中国观众带来前所未有的电音盛宴!
不用去世界顶级电子音乐节Tomorrowland和Ultra音乐节,在家门口就能感受到电音大咖的震撼现场~ 狂戳下方购票链接,等你来high!
喜欢电音的你一定不会不知道Hardwell这位以Tomorrowland和Ultra的现场演出闻名的超级巨星,他在Youtube频道上的演出视频吸引了超过一亿的点阅率,被认为是塑造了当下EDM(电子舞曲)音乐形态的DJ之一。
被中国歌迷亲切的称为“硬好”的Hardwell有着迷人的声线和强大的控场力。燃爆的现场绝对是一次难忘的体验。
Hardwell时隔四年后再度空降京城,前所未有的震撼现场,你准备好了吗!
KSHMR,来自美国加州的鬼才制作人。出道不久的K神在短短两年间就横扫各大排行榜,成为全球电子音乐的领军人物,圈粉无数。网友更戏称他为“Hits Machine”(热单收割机)。
作为一位印度裔美国人,k神的很多歌都极具异域风情,将电子元素与印度特有的民族风格融合,韵味十足。另一方面,他的歌极具故事性和人文内核,人称“KSHMR Style”。
万众期待的K神现场,等你来high!
Nicky Romero
Nicky Romero,6岁学习架子鼓,18岁出道,21岁开始走红国际舞台。这个来自电音王国荷兰的王牌级DJ ,现在已是电音界家喻户晓的代表人物。
爆红歌曲《Toulouse》为他积累了超高人气。拥有俊朗外形的Nicky更是客串演出了电音电影“We Are Your Friends”。
不仅颜值高,Nicky的曲风更是节奏强劲,名副其实的Live之王,令全世界粉丝为之疯狂。
Nicky的迷弟迷妹们,购票链接速戳起来!
Steve Aoki
Steve Aoki,史蒂夫·青木,来自美国加洲,是位不折不扣的富二代,父亲是风靡全美的日式铁板烧连锁餐厅Benihama创始人,妹妹是超模,然而他的音乐之路却十分艰难,父亲的反对一度使他没有经济来源。而现在,潮爷Steve Aoki 打造了DimMak这个拥有唱片兼服饰双重身份的厂牌,无论在音乐界还是时尚界都做的风生水起。
潮爷的现场可是出了名的好玩:“我酷爱一切极限运动,刺激的我都愿意尝试。我爱在舞台上做些戏剧性的事,比如蛋糕大战、皮划艇人浪、喷香槟什么的。我希望通过我的热情,能为我的粉丝带来最棒以及最难忘的夜晚。”
想成为被潮爷用蛋糕砸中的幸运儿吗,现场等你来!
DJ Snake出生于巴黎郊区,受到法国电影《La Haine》以及嘻哈歌手KRS-One与Cypress Hill的影响,他常在街头涂鸦,因为善于躲避警察,朋友给他取了“Snake”的外号。
才华横溢的蛇叔曾为Lady Gaga、阿肯打造了极具个性的唱片,前卫和融汇多种风格的乐风受到众多年轻人的追捧和音乐人的肯定,还获得了两项格莱美奖提名,是当之无愧的新生代EDM天王。
气场超强的蛇叔的现场从来都是燥翻high炸的盛况。他还曾登上巴黎市中心的地标凯旋门,成为第一位在凯旋门顶端表演的艺人。
这一次,蛇叔即将登陆京城,再次引爆沸点,绝对不容错过!
{var showResult = resource.end}
{if !showResult}
{var tempQuestion = resource.questions[0]}
{list tempQuestion.choices as choice}
{if choice.voted && choice.voted}
{var showResult = true}
{if resource.questions.length > 1}
{var singleQuestion = false}
{var singleQuestion = true}
{list resource.questions as question}
${comJST('m-topic-detail-vote-question', question, showResult, resource.displayType, singleQuestion)}
{if !showResult}
{if singleQuestion}
${question.title|escape}
{if !question.single}
(最多选${question.maxChoice}项)
${question.title}
{if !question.single}
(最多选${question.maxChoice}项)
${comJST('m-topic-detail-vote-question-choice-list', question.choices, showResult, displayType, question.id)}
{var tempChoice = choices[0]}
{var choiceType = 0}
{var choiceListClass = "list-text"}
{if tempChoice.text}
{if (tempChoice.resId > 0)}
{var choiceType = 1}
{var choiceListClass = "list-mix"}
{elseif tempChoice.picId > 0}
{var choiceType = 2}
{var choiceListClass = "list-pic"}
{var choiceType = 0}
{var choiceListClass = "list-text"}
{elseif (tempChoice.resId > 0)}
{var choiceType = 3}
{var choiceListClass = "list-resource"}
{var choiceType = 0}
{var choiceListClass = "list-text"}
{if showResult}
{var total = 0}
{list choices as choice}
{var total = choice.count + total}
{if total <= 0}
{var total = 1}
{var showOrder = displayType==1}
{if showOrder}
{var sortChoices = sort(choices)}
{list sortChoices as choice}
{var order = choice_index + 1}
${comJST('m-topic-detail-vote-question-choice-result', choice, choiceType, showOrder, order, total)}
{list choices as choice}
{var order = choice_index + 1}
${comJST('m-topic-detail-vote-question-choice-result', choice, choiceType, showOrder, order, total)}
{list choices as choice}
${comJST('m-topic-detail-vote-question-choice', choice, choiceType, questionid)}
{if choiceType == 0}
${choice.text|escape}
{elseif choiceType == 1 && choice.resource}
{if choice.resType == 4}
{var picUrl = choice.resource.album.picUrl}
{var artists = ""}
{list choice.resource.artists as artist}
{var artists = artists + artist.name}
{if artist_index < artist_length - 1}
{var artists = artists + ", "}
{var picUrl = choice.resource.coverUrl}
{var artists = choice.resource.radio.name}
${choice.text|escape}
${choice.resource.name|escape} - ${artists|escape}
{elseif choiceType == 2}
{var isGif = choice.picType == "gif"}
${choice.text|escape}
{elseif choiceType == 3 && choice.resource}
{if choice.resType == 4}
{var picUrl = choice.resource.album.picUrl}
{var artists = ""}
{list choice.resource.artists as artist}
{var artists = artists + artist.name}
{if artist_index < artist_length - 1}
{var artists = artists + ", "}
{var picUrl = choice.resource.coverUrl}
{var artists = choice.resource.radio.name}
${choice.resource.name|escape}
${artists|escape}
{if choiceType == 0}
{if showOrder}${order}{/if}
${choice.text|escape}
${comJST('m-topic-detail-vote-question-choice-result-bar', choice, total)}
{elseif choiceType == 1 && choice.resource}
{if choice.resType == 4}
{var picUrl = choice.resource.album.picUrl}
{var artists = ""}
{list choice.resource.artists as artist}
{var artists = artists + artist.name}
{if artist_index < artist_length - 1}
{var artists = artists + ", "}
{var picUrl = choice.resource.coverUrl}
{var artists = choice.resource.radio.name}
{if showOrder}${order}{/if}
${choice.text|escape}
${choice.resource.name|escape} - ${artists|escape}
${comJST('m-topic-detail-vote-question-choice-result-bar', choice, total)}
{elseif choiceType == 2}
{if showOrder}${order}{/if}
{var isGif = choice.picType == "gif"}
${choice.text|escape}
${comJST('m-topic-detail-vote-question-choice-result-bar', choice, total)}
{elseif choiceType == 3}
{if choice.resType == 4}
{var picUrl = choice.resource.album.picUrl}
{var artists = ""}
{list choice.resource.artists as artist}
{var artists = artists + artist.name}
{if artist_index < artist_length - 1}
{var artists = artists + ", "}
{var picUrl = choice.resource.coverUrl}
{var artists = choice.resource.radio.name}
{if showOrder}${order}{/if}
${choice.resource.name|escape} - ${artists|escape}
${comJST('m-topic-detail-vote-question-choice-result-bar', choice, total)}
{var count = 0}
{if choice.count}
{if choice.count > 1000000}
{var count = "100万+"}
{var count = choice.count}
${count}票
{macro testSong(resource)}
{if !detail.result}${detail.quiz.title|escape}{else}${detail.quiz.currentResultDesc|escape}{/if}
{if !detail.result}
{var result = detail.result}
{if detail.quiz.type===2}
${result.currentResult.score}
${result.currentResult.title}
{list result.currentResult.desc as item}
{if item.type === 1}
${item.content}
{elseif item.type === 2}
${testSong(item.content)}
${result.currentResult.percent}% 的人和你一样
{if detail.result && detail.result.otherResult.otherTestResultUnits.length > 0}
{var result = detail.result}
${detail.quiz.otherResultDesc|escape}
{list result.otherResult.otherTestResultUnits as rslt}
{if detail.quiz.type===2}
{if rslt.lowScore==rslt.highScore}${rslt.lowScore}{else}${rslt.lowScore}-${rslt.highScore}{/if}分:&nbsp
${rslt.title}
{list rslt.desc as item}
{if item.type === 1}
${item.content}
{elseif item.type === 2}
${testSong(item.content)}
${rslt.percent}% 的人得出这个结果
网易公司版权所有(C)杭州乐读科技有限公司运营:CMPSC 311, Project Example
CMPSC 311, Project Example
Author: Don Heller
# CMPSC 311, Project Example
SRC = c2html.c
LIB = cmpsc311.c names.c
INC = cmpsc311.h names.h
AUTHOR = "Don Heller"
C99 = c99 -v
GCC = gcc -std=c99 -Wall -Wextra -pedantic
POSIX_OPTIONS
= -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600
SOLARIS_OPTIONS = -D_XOPEN_SOURCE=600
LINUX_OPTIONS
= -D_XOPEN_SOURCE=700
MACOSX_OPTIONS
solaris: $(SRC) $(LIB) $(INC)
$(C99) $(SOLARIS_OPTIONS) -o c2html $(SRC) $(LIB)
$(GCC) $(SOLARIS_OPTIONS) -o c2html $(SRC) $(LIB)
# lint is only available on Solaris
lint: $(SRC) $(LIB) $(INC)
lint -Xc99 $(SOLARIS_OPTIONS)
$(SRC) $(LIB)
linux: $(SRC) $(LIB) $(INC)
$(GCC) $(LINUX_OPTIONS)
-o c2html $(SRC) $(LIB)
mac: $(SRC) $(LIB) $(INC)
$(GCC) $(MACOSX_OPTIONS)
-o c2html $(SRC) $(LIB)
c2html.html: $(SRC) $(LIB) $(INC) c2html.display
./c2html -o c2html.html -f c2html.display -t "CMPSC 311, Project Example" -a $(AUTHOR)
chmod 644 c2html.html
cmpsc311.html: cmpsc311.test.c $(LIB) $(INC) cmpsc311.display
$(GCC) $(POSIX_OPTIONS) -o cmpsc311.test cmpsc311.test.c $(LIB)
./cmpsc311.test & cmpsc311.test.out
./c2html -o cmpsc311.html -f cmpsc311.display -t "CMPSC 311, base library" -a $(AUTHOR)
names.html: names.test.c $(LIB) $(INC) names.display
$(GCC) $(POSIX_OPTIONS) -o names.test names.test.c $(LIB)
./names.test & names.test.out
./c2html -o names.html -f names.display -t "CMPSC 311, list of names" -a $(AUTHOR)
./c2html -o trial.html -f namelist -t "trial" -a $(AUTHOR)
# Valgrind is available on Linux and Mac OS X.
# For a basic intro, see http://www.valgrind.org/docs/manual/quick-start.html
linux-trial:
$(GCC) $(LINUX_OPTIONS) -g -O0 -o c2html $(SRC) $(LIB)
valgrind --leak-check=full --track-origins=yes ./c2html -o trial.html -f namelist -t "trial" -a $(AUTHOR)
rm -f c2html *.o
rm -f cmpsc311.test cmpsc311.test.out
rm -f names.test names.test.out
Clean: clean
rm -f c2html.html cmpsc311.html names.html
rm -f trial.html
cmpsc311.h
/* base library for CMPSC 311 projects
* version of 25 Feb. 2013
#ifndef CMPSC311_H
#define CMPSC311_H
#include &stdio.h&
#include &stdbool.h&
//------------------------------------------------------------------------------
// global variables set from the command line
extern char *
// program name
// -v option, extra output
// -v can be repeated for even more output
// verbosity levels
off, default
normal, behavioral info
extra, functionality info
memory allocation info, from Malloc(), Strdup()
too much, information overload
//------------------------------------------------------------------------------
// utility functions
safe_string(() -- guard against null pointer for character string output
const char *safe_string(const char *str);
//------------------------------------------------------------------------------
// check function arguments
verify() -- tf is if not, print msg and quit
#define verify(tf, msg) cmpsc311_verify(tf, msg, __func__, __LINE__)
void cmpsc311_verify(const bool tf,
const char *msg, const char *func, const int line);
//------------------------------------------------------------------------------
// check function return values
C and Posix
C and Posix
// We follow the standard protoypes of the original functions.
// Compare these to the error-checking wrappers in CS:APP, csapp.h and csapp.c.
#define Malloc(size)
cmpsc311_malloc(size, __func__, __LINE__)
#define Strdup(s)
cmpsc311_strdup(s, __func__, __LINE__)
#define Fopen(filename,mode) cmpsc311_fopen(filename, mode, __func__, __LINE__)
void *cmpsc311_malloc(size_t size,
const char *func, const int line);
char *cmpsc311_strdup(const char *s,
const char *func, const int line);
FILE *cmpsc311_fopen(const char * restrict filename, const char * restrict mode,
const char *func, const int line);
//------------------------------------------------------------------------------
cmpsc311.c
/* base library for CMPSC 311 projects
* version of 25 Feb. 2013
#include &stdio.h&
#include &stdlib.h&
#include &unistd.h&
#include &stdbool.h&
#include &errno.h&
#include &string.h&
#include "cmpsc311.h"
//------------------------------------------------------------------------------
// global variables set from the command line
char *prog = "[no name]";
// program name
int verbose = 0;
// -v option, extra output
// -v can be repeated for even more output
// verbosity levels
off, default
normal, behavioral info
extra, functionality info
memory allocation info, from Malloc(), Strdup()
too much, information overload
//------------------------------------------------------------------------------
// utility functions
safe_string(() -- guard against null pointer for character string output
const char *safe_string(const char *str)
if (str == NULL) return "(null)";
/* The Solaris C library doesn't like printf("%s", p) when p is a null pointer.
* It will generate a segmentation fault, and end the program.
* an acceptable implementation according to the C and Posix Standards.
* The GNU C library (on Linux and Mac OS X) it will print
* the string "(null)" and keep going.
* If you compile with GCC with all the warnings turned on, there are complaints
* about printf("%s", NULL); but none about printf("%s", p) when p happens to be
* a null pointer.
* With the safe_string() function, we can act like the GNU C library version of
* printf(), even on Solaris.
* Of course, we could also use assert() or verify() to catch NULL pointers,
* which is often a better idea, unless you really want the program to keep
//------------------------------------------------------------------------------
// check function arguments
verify() -- tf is if not, print msg and quit
// #define verify(tf, msg) cmpsc311_verify(tf, msg, __func__, __LINE__)
void cmpsc311_verify(const bool tf, const char *msg,
const char *func, const int line)
if (tf == false)
fprintf(stderr, "%s: %s() at line %d failed: %s\n", prog, func, line, msg);
exit(EXIT_FAILURE);
//------------------------------------------------------------------------------
// check function return values
C and Posix
C and Posix
// We follow the standard protoypes of the original functions.
// Compare these to the error-checking wrappers in CS:APP, csapp.h and csapp.c.
// #define Malloc(size) cmpsc311_malloc(size, __func__, __LINE__)
void *cmpsc311_malloc(size_t size,
const char *func, const int line)
void *p = malloc(size);
if (p == NULL)
fprintf(stderr, "%s: %s() at line %d failed: malloc(): %s\n",
prog, func, line, strerror(errno));
exit(EXIT_FAILURE);
if (verbose & 2)
{ // which address?
fprintf(stderr, "%s: malloc(%zd) at %p from %s line %d\n",
prog, size, p, func, line);
// #define Strdup(s) cmpsc311_strdup(s, __func__, __LINE__)
char *cmpsc311_strdup(const char *s,
const char *func, const int line)
char *p = strdup(s);
if (p == NULL)
fprintf(stderr, "%s: %s() at line %d failed: strdup(): %s\n",
prog, func, line, strerror(errno));
exit(EXIT_FAILURE);
if (verbose & 2)
{ // which address?
fprintf(stderr, "%s: strdup(%zd) at %p from %s line %d\n",
prog, strlen(s)+1, (void *) p, func, line);
// #define Fopen(filename,mode) cmpsc311_fopen(filename, mode, __func__, __LINE__)
FILE *cmpsc311_fopen(const char * restrict filename, const char * restrict mode,
const char *func, const int line)
FILE *f = fopen(filename, mode);
if (f == NULL)
fprintf(stderr, "%s: %s() at line %d failed: fopen(%s): %s\n",
prog, func, line, filename, strerror(errno));
exit(EXIT_FAILURE);
//------------------------------------------------------------------------------
/* base library for CMPSC 311 projects
* version of 25 Feb. 2013
#ifndef CMPSC311_NAMES_H
#define CMPSC311_NAMES_H
//------------------------------------------------------------------------------
// singly-linked list of names
struct name
struct name *
// NULL indicates end-of-list
// from strdup()
struct list_names
struct name *
// NULL indicates empty list
struct name *
int reference_
// for delayed deallocation of the list
// from strdup()
//------------------------------------------------------------------------------
void list_names_init(struct list_names * const list, const char *listname);
struct list_names *list_names_allocate(const char *listname);
struct list_names *list_names_reference(struct list_names * const list);
void list_names_deallocate(struct list_names * const list);
void list_names_print(const struct list_names * const list);
void list_names_append(struct list_names * const list, const char *name);
int list_names_append_if_new(struct list_names * const list, const char *name);
void list_names_append_from_file(struct list_names * const list, const char *filename);
void list_names_iterate(struct list_names *list, void (*func)(void *));
//------------------------------------------------------------------------------
* The assumption is that a struct name can appear on only one list, but the
* list itself could have more than one reference to it.
* list_names_allocate()
list_names_reference() creates
* another reference to an existing list.
* Do not apply list_names_deallocate() to something that did not come from
* list_names_allocate() or list_names_reference().
* list_names_append_if_new() works as follows:
if (name is on the list already) { return 1 }
else { put name on the list and return 0 }
* If list_names_allocate() or one of the list_names_append() functions
* can't allocate enough memory, the program ends with an error message.
//------------------------------------------------------------------------------
/* Examples
* Declare, initialize and print a list
struct list_
list_names_init(&list, "something");
list_names_print(&list);
* Declare and initialize a list (incorrect)
struct list_names list = { "something", NULL, NULL, 0 };
* Allocate a list, initialized
struct list_names *list = list_names_allocate("something");
if (list == NULL) { ... allocation failed ... }
list_names_print(list);
* Deallocate a list
struct list_names *list = list_names_allocate("something");
list_names_deallocate(list);
list = NULL;
* Deallocate a list (incorrect)
struct list_
list_names_init(&list, "something");
list_names_deallocate(list);
list = NULL;
* Put a name on the end of the list (assume a declared list)
list_names_append(&list1, "one");
* Put a name on the end of the list (assume an allocated list)
list_names_append(list2, "two");
//------------------------------------------------------------------------------
/* base library for CMPSC 311 projects
* version of 25 Feb. 2013
#include &stdio.h&
#include &stdlib.h&
#include &unistd.h&
#include &stdbool.h&
#include &errno.h&
#include &string.h&
#include &ctype.h&
#include "cmpsc311.h"
#include "names.h"
//------------------------------------------------------------------------------
void list_names_init(struct list_names * const list, const char *listname)
verify(list != NULL, "null arg list");
verify(listname != NULL, "null arg listname");
verify(listname[0] != '\0', "empty arg listname");
list-&head = list-&tail = NULL;
list-&reference_count = 0;
list-&name = Strdup(listname);
//------------------------------------------------------------------------------
struct list_names *list_names_allocate(const char *listname)
verify(listname != NULL, "null arg listname");
verify(listname[0] != '\0', "empty arg listname");
struct list_names *list = Malloc(sizeof(struct list_names));
list-&head = list-&tail = NULL;
list-&reference_count = 0;
list-&name = Strdup(listname);
//------------------------------------------------------------------------------
struct list_names *list_names_reference(struct list_names * const list)
verify(list != NULL, "null arg list");
list-&reference_count++;
//------------------------------------------------------------------------------
void list_names_deallocate(struct list_names * const list)
verify(list != NULL, "null arg list");
if (--list-&reference_count & 0)
struct name *prev = NULL;
for (struct name *p = list-& p != NULL; p = p-&next)
free(prev);
// free(NULL) is harmless
free(p-&name);
free(prev);
// now, prev == list-&tail
free(list-&name);
free(list);
//------------------------------------------------------------------------------
void list_names_print(const struct list_names * const list)
verify(list != NULL, "null arg list");
printf("list of names: %s\n", safe_string(list-&name));
if (list-&head == NULL)
{ printf("
&empty&\n"); }
for (struct name *p = list-& p != NULL; p = p-&next)
{ printf("
%s\n", p-&name); }
//------------------------------------------------------------------------------
void list_names_append(struct list_names * const list, const char *name)
verify(list != NULL, "null arg list");
verify(name != NULL, "null arg name");
verify(name[0] != '\0', "empty arg name");
struct name *p = Malloc(sizeof(struct name));
p-&next = NULL;
p-&name = Strdup(name);
if (list-&head == NULL)
// empty list, list-&tail is also NULL
list-&head = list-&tail =
list-&tail-&next =
list-&tail =
//------------------------------------------------------------------------------
// if (name is on the list already) { return 1 }
// else { put name on the list and return 0 }
int list_names_append_if_new(struct list_names * const list, const char *name)
verify(list != NULL, "null arg list");
verify(name != NULL, "null arg name");
verify(name[0] != '\0', "empty arg name");
for (struct name *p = list-& p != NULL; p = p-&next)
if (strcmp(p-&name, name) == 0)
{ return 1; }
// name is on the list already
list_names_append(list, name);
//------------------------------------------------------------------------------
void list_names_append_from_file(struct list_names * const list, const char *filename)
verify(list != NULL, "null arg list");
verify(filename != NULL, "null arg filename");
verify(filename[0] != '\0', "empty arg filename");
FILE *infile = NULL;
if (strcmp(filename, "-") == 0)
{ infile = }
infile = fopen(filename, "r");
if (infile == NULL)
fprintf(stderr, "%s: failed: could not open file %s: %s\n",
prog, filename, strerror(errno));
exit(EXIT_FAILURE);
#define MAXLINE 256
char buffer[MAXLINE+2];
// extra space for newline
buffer[MAXLINE+2-2] = '\n';
// force a newline
buffer[MAXLINE+2-1] = '\0';
// to end the string
char whsp[] = " \t\n\v\f\r";
// whitespace characters
char comm[] = "#\n";
// comment, newline
while (fgets(buffer, MAXLINE, infile) != NULL)
/* Note that fgets() places a newline in buffer, if the input line
was short enough to fit.
Line-too-long is probably an error,
to be caught later.
We work around the rare case by forcing a
newline and not overwriting it.
* NULL from fgets() indicates end-of-file or error, so in that case
we just quit.
// remove comment, if present
// remove trailing newline
int m = strcspn(buffer, comm);
// index of # or newline
buffer[m] = '\0';
// remove the tail
m = strspn(buffer, whsp);
// index of first non-whitespace character
char *buf = &buffer[m];
// remove trailing whitespace, by working backward from the end of string
char *p = strchr(buf, '\0');
// *p is '\0', or p is NULL
if (p == NULL)
fprintf(stderr, "%s: strange string\n", prog);
exit(EXIT_FAILURE);
// *p is '\0', so back up one position
while (p & buf && isspace(*p))
{ *p = '\0'; p--; }
if (*buf == '\0')
// empty line
list_names_append(list, buf);
// get ready for the next iteration
buffer[MAXLINE+2-2] = '\n';
// force a newline
buffer[MAXLINE+2-1] = '\0';
// to end the string
if (infile != stdin && fclose(infile) != 0)
fprintf(stderr, "%s: failed: could not close input file %s: %s\n",
prog, filename, strerror(errno));
exit(EXIT_FAILURE);
//------------------------------------------------------------------------------
// unfinished -- seemed like a good idea, but we didn't actually need it
void list_names_iterate(struct list_names *list, void (*func)(void *))
verify(list != NULL, "null arg list");
verify(func != NULL, "null arg func");
for (struct name *p = list-& p != NULL; p = p-&next)
printf("calling func on %s\n", p-&name);
//------------------------------------------------------------------------------
// CMPSC 311, Project Example
produce HTML from C
// possible extensions or additional tools
generate list for use with -f option, from the #include "file" lines (easy)
syntax-oriented HTML highlighting (not easy - requires a parser)
comment-tags that control HTML highlighting, as in /*c2html prototype */ (ugly hack)
table-structured HTML (easy? not easy?)
#include &stdio.h&
#include &stdlib.h&
#include &unistd.h&
#include &stdbool.h&
#include &errno.h&
#include &string.h&
#include &time.h&
#include "cmpsc311.h"
#include "names.h"
static void read_file(const char *infile, FILE *out);
static void read_lines(FILE *in, FILE *out);
static void spacetab_expand(const char *str, FILE *out);
//------------------------------------------------------------------------------
static void usage(int status)
if (status == EXIT_SUCCESS)
printf("usage: %s [-h] [-v] [-a author] [-f file] [-i ifile] [-o ofile] [-t title]\n", prog);
print help\n");
can be repeated for more output\n");
page author\n");
filename, contains list of input file names\n");
-i ifile default is stdin, which is also represented by -i -\n");
default is stdout\n");
page title\n");
You probably want to use quotes as in -t \"long title\".\n");
Multiple authors can be given, but only the first gets meta-credit.\n");
Multiple input files can be given.\n");
Tabs are expanded in the output.\n");
fprintf(stderr, "%s: Try '%s -h' for usage information.\n", prog, prog);
exit(status);
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
// for use with getopt(3)
extern char *
// option flags and option-arguments set from the command line
prog = argv[0];
int status = EXIT_SUCCESS;
int a_flag = 0;
// number of -a options supplied
int f_flag = 0;
// number of -f options supplied
int i_flag = 0;
// number of -i options supplied
int o_flag = 0;
// only the last -o option has effect
int t_flag = 0;
// only the last -t option has effect
char *a_val = "no name";
char *o_val = "stdout";
char *t_val = "no title";
FILE *ofile =
// first, see if the -v option is given
// we'll catch all the other cases on the next pass over argv
while ((ch = getopt(argc, argv, ":hva:f:i:o:t:")) != -1)
if (ch == 'v') verbose++;
struct list_names *filenames = list_names_allocate("filenames");
// scan the argv array again, from the beginning
optind = 1;
while ((ch = getopt(argc, argv, ":hva:f:i:o:t:")) != -1)
switch (ch) {
usage(EXIT_SUCCESS);
// verbose++;
// number of -a options supplied
if (a_flag == 1) a_val =
// number of -f options supplied
list_names_append_from_file(filenames, optarg);
// number of -i options supplied
list_names_append(filenames, optarg);
if (o_flag == 1) fprintf(stderr, "%s: disregarding -o %s\n", prog, o_val);
o_flag = 1;
if (t_flag == 1) fprintf(stderr, "%s: disregarding -t %s\n", prog, t_val);
t_flag = 1;
fprintf(stderr, "%s: invalid option '%c'\n", prog, optopt);
usage(EXIT_FAILURE);
fprintf(stderr, "%s: invalid option '%c' (missing argument)\n", prog, optopt);
usage(EXIT_FAILURE);
usage(EXIT_FAILURE);
// loop over all the input files, verify input file != output file
// ignore the default cases of stdin and stdout
if ((i_flag + f_flag) & 0 && o_flag & 0)
bool failed =
for (struct name *p = filenames-& p != NULL; p = p-&next)
if (strcmp(p-&name, o_val) == 0)
fprintf(stderr, "%s: failed: input file %s == output file %s\n", prog, p-&name, o_val);
if (failed) exit(EXIT_FAILURE);
if (o_flag & 0)
ofile = fopen(o_val, "w");
if (ofile == NULL)
fprintf(stderr, "%s: failed: could not open output file %s: %s\n", prog, o_val, strerror(errno));
exit(EXIT_FAILURE);
fprintf(ofile, "&!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"&\n");
fprintf(ofile, "&html&\n");
fprintf(ofile, "&head&\n");
fprintf(ofile, "
&meta content=\"text/ charset=ISO-8859-1\" http-equiv=\"Content-Type\"&\n");
fprintf(ofile, "
&meta content=\"%s\" name=\"author\"&\n", a_val);
fprintf(ofile, "
&title&%s&/title&\n", t_val);
fprintf(ofile, "&/head&\n");
fprintf(ofile, "&body&\n");
fprintf(ofile, "%s&br&\n", t_val);
// loop over all the author names
if (a_flag & 2)
{ fprintf(ofile, "&br&Author: %s&br&\n", a_val); }
fprintf(ofile, "&br&Authors: &br&\n");
optind = 1;
while ((ch = getopt(argc, argv, ":hva:f:i:o:t:")) != -1)
if (ch == 'a')
{ fprintf(ofile, "&& %s&br&\n", optarg); }
// loop over all the input files, list the names
if (i_flag == 0 && f_flag == 0)
// default is stdin
{ fprintf(ofile, "&br&File: &span style=\"font-family:\"&[stdin]&/span&&br&\n"); }
fprintf(ofile, "&br&Files: &br&\n");
for (struct name *p = filenames-& p != NULL; p = p-&next)
fprintf(ofile, "&& &a href=\"");
spacetab_expand(p-&name, ofile);
fprintf(ofile, "\"&&span style=\"font-family:\"&");
spacetab_expand(p-&name, ofile);
fprintf(ofile, "&/span&&/a&&br&\n");
// loop over all the input files, list the file contents
if (i_flag == 0 && f_flag == 0)
// default is stdin
{ read_file("-", ofile); }
for (struct name *p = filenames-& p != NULL; p = p-&next)
{ read_file(p-&name, ofile); }
fprintf(ofile, "&br&&hr style=\"width: 100%%; height: 2\"&&br&\n");
time_t now = time(NULL);
char buf[26];
ctime_r(&now, buf);
buf[24] = '\0';
// clean up the newline
fprintf(ofile, "This page generated %s by &span style=\"font-family:\"&%s&/span&&br&\n", buf, prog);
fprintf(ofile, "&br&\n");
fprintf(ofile, "&/body&\n");
fprintf(ofile, "&/html&\n");
if (ofile != stdout && fclose(ofile) != 0)
fprintf(stderr, "%s: failed: could not close output file %s: %s\n", prog, o_val, strerror(errno));
// exit(EXIT_FAILURE);
list_names_deallocate(filenames);
//------------------------------------------------------------------------------
static void read_file(const char *infile, FILE *out)
verify(infile != NULL, "null arg infile");
verify(out != NULL, "null arg out");
int errnum = 0;
if (strcmp(infile, "-") == 0)
in = fopen(infile, "r");
if (in == NULL)
{ errnum = }
fprintf(out, "&br&&hr style=\"width: 100%%; height: 2\"&&br&\n");
fprintf(out, "&span style=\"font-style:\"&file:&/span&&\n");
fprintf(out, "&span style=\"font-family: font-weight:\"&");
spacetab_expand(infile, out);
fprintf(out, "&/span&&br&\n");
fprintf(out, "&pre&\n");
if (in == NULL)
{ fprintf(out, "ERROR: could not open %s: %s\n", infile, strerror(errnum)); }
{ read_lines(in, out); }
fprintf(out, "&/pre&\n");
if (in != NULL && in != stdin && fclose(in) != 0)
fprintf(stderr, "%s: failed: could not close input file %s: %s\n", prog, infile, strerror(errno));
// exit(EXIT_FAILURE);
//------------------------------------------------------------------------------
// the output of this function appears inside a &pre& section,
so we don't need to translate ' ' to "&",
but we do need to translate tabs to spaces, to compensate for the leading line number
static void read_lines(FILE *in, FILE *out)
verify(in != NULL, "null arg in");
verify(out != NULL, "null arg out");
int line_number = 0;
// current character
int p = '\n';
// previous character
int tab_count = 8;
while ((c = getc(in)) != EOF)
if (p == '\n')
fprintf(out, "&span style=\"font-style:\"&%3d&/span&
", ++line_number);
tab_count = 8;
switch (c) {
case '\t':
for (int i = 0; i & tab_ i++) { fprintf(out, " "); }
tab_count = 0;
fprintf(out, "&");
tab_count -= 1;
fprintf(out, "&");
tab_count -= 1;
fprintf(out, "&");
tab_count -= 1;
fprintf(out, "%c", c);
tab_count -= 1;
if (tab_count &= 0) tab_count += 8;
if (feof(in))
// end of file
{ fprintf(out, "EOF\n"); }
if (ferror(in))
// error when reading the file
{ fprintf(out, "EOF -- read error: %s\n", strerror(errno)); }
//------------------------------------------------------------------------------
static void spacetab_expand(const char *str, FILE *out)
int tab_count = 8;
for (char *p = (char *) *p != '\0'; p++)
switch(*p) {
case '\t':
for (int i = 0; i & tab_ i++) { fprintf(out, "&"); }
tab_count = 0;
fprintf(out, "&");
tab_count -= 1;
fprintf(out, "%c", *p);
tab_count -= 1;
if (tab_count &= 0) tab_count += 8;
//------------------------------------------------------------------------------
This page generated Mon Feb 25 08:48:36 2013 by ./c2html

我要回帖

更多关于 span标签class属性 的文章

 

随机推荐