有点乱...嘿嘿
第一次用c编写Windows的窗口程序。
SubTitleCombination.cpp关于窗口界面的,足足花了我一个星期,在上班的时候自己偷偷写的。
StrCombination.cpp,处理字幕整合。花了我一天的时间,主要是malloc的问题。
写好之后,很不满意,如果有时间的话,再把代码好好整理整理。
ps:
用vs编译代码之前,要先将unicode 改成 multicode。
在项目属性里面。
程序运行效果见:
http://blog.csdn.net/zhanjh/archive/2008/11/09/3261000.aspx
下载地址(在csdn上下东西还真够麻烦的,可惜找不到其他的地方):
http://d.download.csdn.net/down/762283/zhanjh
StrCombination.cpp
第一次用c编写Windows的窗口程序。
SubTitleCombination.cpp关于窗口界面的,足足花了我一个星期,在上班的时候自己偷偷写的。
StrCombination.cpp,处理字幕整合。花了我一天的时间,主要是malloc的问题。
写好之后,很不满意,如果有时间的话,再把代码好好整理整理。
ps:
用vs编译代码之前,要先将unicode 改成 multicode。
在项目属性里面。
程序运行效果见:
http://blog.csdn.net/zhanjh/archive/2008/11/09/3261000.aspx
下载地址(在csdn上下东西还真够麻烦的,可惜找不到其他的地方):
http://d.download.csdn.net/down/762283/zhanjh
StrCombination.cpp
- #include "StrCombination.h"
- #include <stdlib.h>
- #define ST_SIZE 50
- #define ST_TIME_SIZE 29
- #define ST_NUM_SIZE 10
- #define ST_CONTENT_SIZE 250
- #define ST_MALLOC_SIZE 50
- typedef struct tagSubTitle {
- unsigned long index;
- unsigned long time;
- unsigned int csize;
- char strTime[ST_TIME_SIZE];
- char *content;
- tagSubTitle *next;
- }SubTitle, *PSubtitile;
- typedef struct tagSTNode {
- PSubtitile item;
- tagSTNode *next;
- }STNode, *PSTNode;
- unsigned int stm_index = 0;
- unsigned int stm_size = 0;
- PSubtitile head = NULL;
- int error;
- int delay;
- char *allchars;
- unsigned long allcIndex = 0;
- unsigned long mergedSize = 0;
- unsigned long subtIndex = 0;
- PSTNode pstNodeHead = NULL;
- PSTNode pstNode = NULL;
- bool getSubTitle(PSubtitile pst, char *subT, unsigned long &index);
- void extendPChar(PSubtitile pst,int oldSize, int newSize);
- void st_free(PSubtitile pst);
- PSubtitile mergeSubTitle(PSubtitile pst1, PSubtitile pst2);
- PSubtitile newPst()
- {
- if(stm_index == 0 || stm_index >= ST_MALLOC_SIZE)
- {
- if(pstNodeHead == NULL)
- {
- pstNodeHead = (PSTNode)malloc(sizeof(tagSTNode));
- pstNodeHead->item = NULL;
- pstNodeHead->next = NULL;
- pstNode =pstNodeHead;
- }
- stm_size += ST_MALLOC_SIZE;
- PSTNode pstnode = (PSTNode)malloc(sizeof(tagSTNode));
- pstnode->item = (PSubtitile)malloc(ST_MALLOC_SIZE * sizeof(tagSubTitle));
- pstnode->next = NULL;
- pstNode->next = pstnode;
- pstNode = pstnode;
- stm_index = 0;
- }
- PSubtitile pst = pstNode->item + stm_index;
- pst->content = NULL;
- pst->next = NULL;
- stm_index++;
- return pst;
- }
- int tenExp(unsigned int i)
- {
- if(i==0)
- return 0;
- int result = 10;
- while(i>0)
- {
- result *= 10;
- i --;
- }
- }
- char *getMergedChars()
- {
- unsigned long tempSBTIndex = subtIndex;
- int tempDigitSize = 0;
- while(tempSBTIndex != 0)
- {
- tempSBTIndex /= 10;
- tempDigitSize ++;
- }
- unsigned long numberSize = 0;
- for(int i = 1; i<tempDigitSize; i++)
- {
- numberSize += i * (tenExp(i) - tenExp(i-1));
- }
- numberSize += tempDigitSize * (subtIndex - tenExp(tempDigitSize-1));
- mergedSize += numberSize;
- char *result = (char *)malloc(mergedSize * sizeof(char));
- unsigned long stIndex = 1;
- unsigned long index = 0;
- while(head->next != NULL)
- {
- head = head->next;
- int digitSize = 0;
- int tempIndex = stIndex;
- while(tempIndex != 0)
- {
- for(int i= 0; i < digitSize; i++)
- {
- result[index - i] = result[index -i - 1];
- }
- result[index - digitSize] = tempIndex % 10 + 48;
- tempIndex /= 10;
- index ++;
- digitSize ++;
- }
- stIndex ++;
- result[index++] = 13;
- result[index++] = 10;
- for(int i = 0; i < ST_TIME_SIZE; i++)
- {
- result[index++] = head->strTime[i];
- }
- result[index++] = 13;
- result[index++] = 10;
- for(int i = 0; i < head->csize; i++)
- {
- result[index++] = head->content[i];
- }
- result[index++] = 13;
- result[index++] = 10;
- result[index++] = 13;
- result[index++] = 10;
- }
- result[index] = 0;
- mergedSize = index + 1;
- return result;
- }
- char *newPChar()
- {
- char *result = allchars + allcIndex;
- return result;
- }
- void addToAllChars(char c)
- {
- allchars[allcIndex] = c;
- allcIndex ++;
- }
- char* ST_Merge(char subT1[], char subT2[],unsigned long &mgSize, int stcSize,int parameterDelay, int parameterError)
- {
- allchars = (