Przeglądaj źródła

style: 修改部分函数的形参

函数原型使用了void形参
修改了memStrcpy为memStrCharcpy, 简化memStrcpy
SongZihuan 4 lat temu
rodzic
commit
24d2d8b2d7
14 zmienionych plików z 48 dodań i 45 usunięć
  1. 4 4
      argument/argument.c
  2. 1 1
      include/arguement.h
  3. 2 1
      include/mem.h
  4. 2 2
      include/parameter.h
  5. 9 7
      memory/mem.c
  6. 1 1
      parser/__grammar.c
  7. 9 9
      parser/syntax.c
  8. 2 2
      parser/token.c
  9. 1 1
      src/__run.c
  10. 4 4
      src/inter.c
  11. 3 3
      src/parameter.c
  12. 5 5
      src/statement.c
  13. 4 4
      src/value.c
  14. 1 1
      src/var.c

+ 4 - 4
argument/argument.c

@@ -43,10 +43,10 @@ int getArgs(int argc, char *argv[])
             case 0:
                 break;
             case 'i':
-                args.file = memStrcpy(optarg, 0, false, false);
+                args.file = memStrcpy(optarg);
                 break;
             case 'l':
-                args.log_file = memStrcpy(optarg, 0, false, false);
+                args.log_file = memStrcpy(optarg);
                 break;
             case 's':
                 args.stdout_inter = true;
@@ -60,7 +60,7 @@ int getArgs(int argc, char *argv[])
     }
     if (args.file == NULL){
         if (argc > optind){
-            args.file = memStrcpy(argv[optind], 0, false, false);
+            args.file = memStrcpy(argv[optind]);
         }
         else{
             return -1;
@@ -72,7 +72,7 @@ int getArgs(int argc, char *argv[])
 /**
  * 释放args的成员而不包括其本身
  */
-void freeArgs(){
+void freeArgs(void){
     memFree(args.file);
     memFree(args.file);
 }

+ 1 - 1
include/arguement.h

@@ -11,6 +11,6 @@ struct Args{
 typedef struct Args Args;
 
 int getArgs(int argc, char *argv[]);
-void freeArgs();
+void freeArgs(void);
 
 #endif //VIRTUALMATH_ARGUEMENT_H

+ 2 - 1
include/mem.h

@@ -6,7 +6,8 @@
 void *memFreeCore(void *p);
 void *memCalloc(size_t num, size_t size);
 void *memRealloc(void *old, size_t size);
-char *memStrcpy(char *str, size_t nsize, int free_old, int write, ...);
+char *memStrcpy(char *str);
+char *memStrCharcpy(char *str, size_t nsize, int free_old, int write, ...);
 char *memString(size_t size);
 size_t memStrlen(char *p);
 char *memStrcat(char *first, char *second, bool free_old);

+ 2 - 2
include/parameter.h

@@ -38,7 +38,7 @@ struct Argument{
 typedef struct Parameter Parameter;
 typedef struct Argument Argument;
 
-Argument *makeArgument();
+Argument *makeArgument(void);
 Argument *makeValueArgument(LinkValue *value);
 Argument *makeStatementNameArgument(LinkValue *value, struct Statement *name);
 Argument *makeCharNameArgument(LinkValue *value, LinkValue *name_value, char *name);
@@ -48,7 +48,7 @@ Argument *connectStatementNameArgument(LinkValue *value, struct Statement *name,
 Argument *connectCharNameArgument(LinkValue *value, LinkValue *name_value, char *name, Argument *base);
 void freeArgument(Argument *at, bool free_st);
 
-Parameter *makeParameter();
+Parameter *makeParameter(void);
 Parameter *copyParameter(Parameter *base);
 Parameter *makeValueParameter(struct Statement *st);
 Parameter *makeNameParameter(struct Statement *value, struct Statement *name);

+ 9 - 7
memory/mem.c

@@ -25,12 +25,10 @@ void *memRealloc(void *old, size_t size){
 }
 
 size_t memStrlen(char *p){  // 可以读取NULL的strlen
-    if (p == NULL){
+    if (p == NULL)
         return 0;
-    }
-    else{
+    else
         return strlen(p);
-    }
 }
 
 char *memString(size_t size) {  // 比memCalloc多了一个设置\0的步骤
@@ -42,7 +40,11 @@ char *memString(size_t size) {  // 比memCalloc多了一个设置\0的步骤
     return tmp;
 }
 
-char *memStrcpy(char *str, size_t nsize, bool free_old, bool write, ...) {  // 复制str到新的空间,nszie是要扩展的大小。该函数支持让str=NULL,则变为单纯的memString
+char *memStrcpy(char *str){
+    return memStrCharcpy(str, 0, false ,false);
+}
+
+char *memStrCharcpy(char *str, size_t nsize, bool free_old, bool write, ...) {  // 复制str到新的空间,nszie是要扩展的大小。该函数支持让str=NULL,则变为单纯的memString
     char *tmp = memString(memStrlen(str) + nsize + 1);
     if (str != NULL){
         strcpy(tmp, str);
@@ -70,7 +72,7 @@ char *memStrcat(char *first, char *second, bool free_old) {
         free_old = false;
     }
 
-    char *new = memStrcpy(first, memStrlen(second), false, false);
+    char *new = memStrCharcpy(first, memStrlen(second), false, false);
     if (second != NULL){
         strcat(new, second);
     }
@@ -86,7 +88,7 @@ char *memStrcpySelf(char *str, NUMBER_TYPE times){
         times = -times;
         need_free = true;
     }
-    char *new_str = memStrcpy(str, 0, false, false), *tmp;
+    char *new_str = memStrcpy(str), *tmp;
     for (NUMBER_TYPE i=0; i < times - 1; i++){
         tmp = memStrcat(new_str, str, false);
         memFree(new_str);

+ 1 - 1
parser/__grammar.c

@@ -126,7 +126,7 @@ void syntaxError(ParserMessage *pm, int status, long int line, int num, ...) {
     if (pm->status != success)
         return;
     if (status <= 0){
-        message = memStrcpy("Not Message", 0, false, false);
+        message = memStrcpy("Not Message");
         goto not_message;
     }
 

+ 9 - 9
parser/syntax.c

@@ -15,7 +15,7 @@
 void numberMather(int p, LexMather *mather){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING || mather->status == LEXMATHER_INGPOINT){
         if (isdigit(p) || '.' == p && mather->status == LEXMATHER_ING){
-            mather->str = memStrcpy(mather->str, 1, true, true, p);
+            mather->str = memStrCharcpy(mather->str, 1, true, true, p);
             mather->len += 1;
             if ('.' == p)
                 mather->status = LEXMATHER_INGPOINT;
@@ -24,7 +24,7 @@ void numberMather(int p, LexMather *mather){
         }
         else if(mather->status == LEXMATHER_ING || mather->status == LEXMATHER_INGPOINT){
             if (isalpha(p) ||'_' == p){
-                mather->second_str = memStrcpy(mather->second_str, 1, true, true, p);
+                mather->second_str = memStrCharcpy(mather->second_str, 1, true, true, p);
                 mather->status = LEXMATHER_INGSECOND;
             }
             else{
@@ -37,7 +37,7 @@ void numberMather(int p, LexMather *mather){
     }
     else if (mather->status == LEXMATHER_INGSECOND){
         if (isalnum(p) ||'_' == p){
-            mather->second_str = memStrcpy(mather->second_str, 1, true, true, p);
+            mather->second_str = memStrCharcpy(mather->second_str, 1, true, true, p);
         }
         else{
             mather->status = LEXMATHER_END;
@@ -59,7 +59,7 @@ void numberMather(int p, LexMather *mather){
 void varMather(int p, LexMather *mather){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING){
         if (isalpha(p) ||'_' == p || isdigit(p) && mather->status == LEXMATHER_ING){
-            mather->str = memStrcpy(mather->str, 1, true, true, p);
+            mather->str = memStrCharcpy(mather->str, 1, true, true, p);
             mather->len ++;
             mather->status = LEXMATHER_ING;
         }
@@ -101,14 +101,14 @@ void stringMather(int p, LexMather *mather){
             mather->status = LEXMATHER_MISTAKE;
         }
         else{
-            mather->str = memStrcpy(mather->str, 1, true, true, p);
+            mather->str = memStrCharcpy(mather->str, 1, true, true, p);
             mather->len ++;
             mather->status = LEXMATHER_ING;
         }
     }
     else if (mather->status == LEXMATHER_INGSECOND){
         if (isalnum(p) ||'_' == p){
-            mather->second_str = memStrcpy(mather->second_str, 1, true, true, p);
+            mather->second_str = memStrCharcpy(mather->second_str, 1, true, true, p);
         }
         else{
             mather->status = LEXMATHER_END;
@@ -116,7 +116,7 @@ void stringMather(int p, LexMather *mather){
     }
     else if(mather->status == LEXMATHER_INGPASS){
         if (isalpha(p) ||'_' == p){
-            mather->second_str = memStrcpy(mather->second_str, 1, true, true, p);
+            mather->second_str = memStrCharcpy(mather->second_str, 1, true, true, p);
             mather->status = LEXMATHER_INGSECOND;
         }
         else{
@@ -137,7 +137,7 @@ void stringMather(int p, LexMather *mather){
 void strMather(int p, LexMather *mather, const char *dest_p){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING){
         if (p == dest_p[mather->len]){
-            mather->str = memStrcpy(mather->str, 1, true, true, p);
+            mather->str = memStrCharcpy(mather->str, 1, true, true, p);
             mather->len ++;
             mather->status = LEXMATHER_ING;
         }
@@ -161,7 +161,7 @@ void strMather(int p, LexMather *mather, const char *dest_p){
  */
 void charMather(int p, LexMather *mather, int dest_p){
     if (p == dest_p && mather->status == LEXMATHER_START){
-        mather->str = memStrcpy(mather->str, 1, true, true, p);
+        mather->str = memStrCharcpy(mather->str, 1, true, true, p);
         mather->len ++;
         mather->status = LEXMATHER_ING;
     }

+ 2 - 2
parser/token.c

@@ -15,8 +15,8 @@ Token *makeToken(long int line) {
 Token *makeLexToken(int type, char *str, char *second_str, long int line) {
     Token *tmp = makeToken(line);
     tmp->token_type = type;
-    tmp->data.str = memStrcpy(str, 0, false, false);
-    tmp->data.second_str = memStrcpy(second_str, 0, false, false);
+    tmp->data.str = memStrcpy(str);
+    tmp->data.second_str = memStrcpy(second_str);
     return tmp;
 }
 

+ 1 - 1
src/__run.c

@@ -97,6 +97,6 @@ char *getNameFromValue(Value *value, INTER_FUNCTIONSIG_CORE) {
         case number:
             return setNumVarName(value->data.num.num, CALL_INTER_FUNCTIONSIG_CORE(var_list));
         default:
-            return memStrcpy(inter->data.var_defualt, 0, false, false);
+            return memStrcpy(inter->data.var_defualt);
     }
 }

+ 4 - 4
src/inter.c

@@ -44,7 +44,7 @@ Inter *makeInter(char *code_file, char *debug) {
     tmp->link_base = NULL;
     tmp->statement = makeStatement(0, code_file);
     tmp->var_list = makeVarList(tmp);
-    tmp->data.log_dir = memStrcpy(debug, 0, false, false);
+    tmp->data.log_dir = memStrcpy(debug);
 
     if (debug != NULL && !args.stdout_inter){
         char *debug_dir = memStrcat(debug, INTER_LOG, false), *error_dir = memStrcat(debug, INTER_ERROR, false);
@@ -64,9 +64,9 @@ Inter *makeInter(char *code_file, char *debug) {
 }
 
 void setBaseInterData(struct Inter *inter){
-    inter->data.var_str_prefix = memStrcpy("str_", 0, false, false);
-    inter->data.var_num_prefix = memStrcpy("num_", 0, false, false);
-    inter->data.var_defualt = memStrcpy("default_var", 0, false, false);
+    inter->data.var_str_prefix = memStrcpy("str_");
+    inter->data.var_num_prefix = memStrcpy("num_");
+    inter->data.var_defualt = memStrcpy("default_var");
     inter->data.debug = NULL;
     inter->data.log_dir = NULL;
 }

+ 3 - 3
src/parameter.c

@@ -6,7 +6,7 @@ goto return_; \
 } \
 }while(0)
 
-Argument *makeArgument(){
+Argument *makeArgument(void){
     Argument *tmp = memCalloc(1, sizeof(Argument));
     tmp->type = value_arg;
     tmp->data.value = NULL;
@@ -39,7 +39,7 @@ Argument *makeCharNameArgument(LinkValue *value, LinkValue *name_value, char *na
     tmp->type = name_arg;
     tmp->name_type = name_char;
     tmp->data.value = value;
-    tmp->data.name_ = memStrcpy(name, 0, false, false);
+    tmp->data.name_ = memStrcpy(name);
     tmp->data.name_value = name_value;
     gcAddTmp(&value->gc_status);
     gcAddTmp(&name_value->gc_status);
@@ -88,7 +88,7 @@ void freeArgument(Argument *at, bool free_st) {
     }
 }
 
-Parameter *makeParameter(){
+Parameter *makeParameter(void){
     Parameter *tmp = memCalloc(1, sizeof(Parameter));
     tmp->type = value_par;
     tmp->data.value = NULL;

+ 5 - 5
src/statement.c

@@ -5,7 +5,7 @@ Statement *makeStatement(long int line, char *file) {
     tmp->type = start;
     tmp->next = NULL;
     tmp->line = line;
-    tmp->code_file = memStrcpy(file, 0, false, false);
+    tmp->code_file = memStrcpy(file);
     return tmp;
 }
 
@@ -50,14 +50,14 @@ Statement *makeBaseStrValueStatement(char *value, enum BaseValueType type, long
     tmp->type = base_value;
     tmp->u.base_value.type = type;
     tmp->u.base_value.value = NULL;
-    tmp->u.base_value.str = memStrcpy(value, 0, false, false);
+    tmp->u.base_value.str = memStrcpy(value);
     return tmp;
 }
 
 Statement *makeBaseVarStatement(char *name, Statement *times, long int line, char *file) {
     Statement *tmp = makeStatement(line, file);
     tmp->type = base_var;
-    tmp->u.base_var.name = memStrcpy(name, 0, false, false);
+    tmp->u.base_var.name = memStrcpy(name);
     tmp->u.base_var.times = times;
     return tmp;
 }
@@ -326,7 +326,7 @@ Statement *copyStatementCore(Statement *st){
                 gcAddStatementLink(&new->u.base_value.value->gc_status);
             }
             else
-                new->u.base_value.str = memStrcpy(st->u.base_value.str, 0, false, false);
+                new->u.base_value.str = memStrcpy(st->u.base_value.str);
             break;
         case operation:
             new->u.operation.OperationType = st->u.operation.OperationType;
@@ -334,7 +334,7 @@ Statement *copyStatementCore(Statement *st){
             new->u.operation.left = copyStatement(st->u.operation.left);
             break;
         case base_var:
-            new->u.base_var.name = memStrcpy(st->u.base_var.name, 0, false, false);
+            new->u.base_var.name = memStrcpy(st->u.base_var.name);
             new->u.base_var.times = copyStatement(st->u.base_var.times);
             break;
         case base_svar:

+ 4 - 4
src/value.c

@@ -35,7 +35,7 @@ Value *makeStringValue(char *str, Inter *inter) {
     Value *tmp;
     tmp = makeValue(inter);
     tmp->type = string;
-    tmp->data.str.str = memStrcpy(str, 0, false, false);
+    tmp->data.str.str = memStrcpy(str);
     return tmp;
 }
 
@@ -285,9 +285,9 @@ void printLinkValue(LinkValue *value, char *first, char *last, FILE *debug){
 Error *makeError(char *type, char *message, long int line, char *file) {
     Error *tmp = memCalloc(1, sizeof(Error));
     tmp->line = line;
-    tmp->type = memStrcpy(type, 0, false, false);
-    tmp->messgae = memStrcpy(message, 0, false, false);
-    tmp->file = memStrcpy(file, 0, false, false);
+    tmp->type = memStrcpy(type);
+    tmp->messgae = memStrcpy(message);
+    tmp->file = memStrcpy(file);
     tmp->next = NULL;
     return tmp;
 }

+ 1 - 1
src/var.c

@@ -3,7 +3,7 @@
 Var *makeVar(char *name, LinkValue *value, LinkValue *name_) {
     Var *tmp;
     tmp = memCalloc(1, sizeof(Var));
-    tmp->name = memStrcpy(name, 0, false, false);
+    tmp->name = memStrcpy(name);
     tmp->value = value;
     tmp->name_ = name_;
     tmp->next = NULL;