⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpdetex.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:
        that,
        response[LL];

   int  case1 = 0,
        case4 = 0,
        ip    = 0, 
        op    = 0,
        tp    = 0;

   printf("||%s", input_line);

   while(input_line[ip] != '\0'){
      case1 = 0;
      case4 = 0;
      this  = input_line[ip];
      that  = input_line[ip+1];

      if(this == '{')
         case1 = 1;
      if(this == PERCENT)
         case1 = 2;
      if(this == SLQOUTE  &&
         that == SLQOUTE)
         case1 = 3;
      if(this == BACKSLASH)
         case1 = 4;

      switch(case1){

         case 1:
            ip = ip + 4;
            while(input_line[ip] == ' ')
               ip++;
            copy_text_until(input_line, output_line, 
                            &ip, &op,
                            input_file, output_file, 
                            '}');
            break;

         case 2:
            output_line[op] = '\n';
            input_line[ip]  = '\0';
            break;

         case 3:
            output_line[op] = DBLQOUTE;
            op = op + 1;
            ip = ip + 2;
            copy_text_until(input_line, output_line,
                            &ip, &op, input_file,
                            output_file, SRQOUTE);
            break;

         case 4:  /* BACKSLASH */
            case4 = 0;
            if(input_line[ip+1] == '&'  ||
               input_line[ip+1] == '%'  ||
               input_line[ip+1] == '#'  ||
               input_line[ip+1] == '$'  ||
               input_line[ip+1] == '_')
               case4 = 1;

            strcpy(temp, input_line);
            tp = ip + 1;
            copy_word(temp, &tp, latex_word);
            if( (strcmp(latex_word, "begin") == 0)        ||
                (strcmp(latex_word, "end") == 0)          ||
                (strcmp(latex_word, "documentstyle") == 0)||
                (strcmp(latex_word, "makefile") == 0)     ||
                (strcmp(latex_word, "noindent") == 0)     ||
                (strcmp(latex_word, "tableofcontents") == 0))
               case4 = 2;

            if( (strcmp(latex_word, "chapter") == 0)    ||
                (strcmp(latex_word, "section") == 0)    ||
                (strcmp(latex_word, "subsection") == 0) ||
                (strcmp(latex_word, "item") == 0)       ||
                (strcmp(latex_word, "title") == 0)      ||
                (strcmp(latex_word, "author") == 0)     ||
                (strcmp(latex_word, "emph") == 0)     ||
                (strcmp(latex_word, "date") == 0))
               case4 = 3;

            if(is_ldots(input_line, ip))
               case4 = 4;

            if(that == BACKSLASH)
               case4 = 5;

            switch(case4){
               case 1:
                  output_line[op] = input_line[ip+1];
                  op++;
                  if(input_line[ip+1] == '_')
                     ip = ip + 4;
                  else
                     ip = ip + 2;
                  break;

               case 2:
                  output_line[op] = '\n';
                  input_line[ip]  = '\0';
                  break;

               case 3:
                  ip++;
                  copy_word(input_line, &ip, latex_word);
                  ip++;
                  if(input_line[ip] == '{')
                     ip++;
                  copy_text_until(input_line, output_line,
                                  &ip, &op, input_file,
                                  output_file, '}');
                  break;

               case 4:
                  output_line[op++] = '.';
                  output_line[op++] = '.';
                  output_line[op++] = '.';
                  ip = ip + 6;
                  break;

               case 5:
                  ip = ip + 2;
                  break;

            }  /* ends if switch case4 */
            break; /* ends case 4 */

         default:
            output_line[op++] = input_line[ip++];
            break;

      }  /* ends switch case1 */

   }  /* ends while input_line[ip] != NULL */

}  /* ends process_line */




/********************************************************/
/*
   fill_string(...
*/

void fill_string(char string[], int size, char fill)
{
   int i;
   for(i=0; i<size; i++)
      string[i] = fill;
}  /* ends fill_string */




/********************************************************/
/*
   is_ldots(...
*/

int is_ldots(char input[], int ip)
{
   char temp[LL];
   int  i,
        result = 0;
   fill_string(temp, LL, '\0');
   for(i=0; i<5; i++)
      temp[i] = input[ip+i+1];
   if(strcmp(temp, "ldots") == 0)
      result = 1;
   return(result);
}  /* ends is_ldots */


#ifdef NEVER





/********************************************************/
/*
   process_line(...

   This routine does the main part of the program.
   It processes each line in the input file, strips
   the Latex commands, and writes the result to the
   output file.

   This looks for five basic types of Latex commands.

   case 1: The command begins with a '{'.  Inside the {
   is a \xx command like em bf rm it sl sf sc.  Skip
   over the { and these three characters and copy 
   the text until you hit the }.  You may need
   to read several lines of input.

   case 2: Latex comment.  You hit a %, the rest
   of the line is a comment so delete it.

   case 3: You hit a single left qoute.  If the next
   character is another single left qoute, replace the
   two by a double qoute character and copy text until
   you hit two single right qoutes, then replace them
   by another double qoute character.  If the character
   just past the first single left qoute is not another
   single left qoute, just copy and go on.

   case 4: Simple case where you hit a \ then
   a & % # $ or _.  Delete the \ and keep the
   next character.

   case 5:  Two parts

   case 5.1: The kill all case.  The Latex command is a 
   \begin end documenstyle maketitle tableofcontents or
   %comments.  Delete this line.  Kill it all.

   case 5.2: Keep the insides of the {}.  The command is
   a \chapter{} or section subsection item title author or
   date.  Keep the text inside the {} and remove the rest.
*/

void process_line(char input_line[], char output_line[],
                  FILE *input_file, FILE *output_file)
{
   char latex_word[LL], response[LL];
   int  case4 = 0,
        ip    = 0, 
        op    = 0;

   while(input_line[ip] != '\0'){

         /* The nothing case */
      if(input_line[ip] != '{'       &&
         input_line[ip] != PERCENT   &&
         input_line[ip] != SLQOUTE   &&
         input_line[ip] != BACKSLASH){
         output_line[op] = input_line[ip];
         op++;
         ip++;
      }  /* ends nothing case */
      
         /* case  1 */
      if(input_line[ip] == '{'){
         ip = ip + 4;
         while(input_line[ip] == ' ')
            ip++;
         copy_text_until(input_line, output_line, &ip, &op,
                         input_file, output_file, '}');
      }  /* ends case 1 */

         /* case 2 */
      if(input_line[ip] == PERCENT){
         output_line[op] = '\n';
         input_line[ip]  = '\0';
      }  /* ends case 2 */

         /* case 3 */
      if(input_line[ip] == SLQOUTE){
         if(input_line[ip+1] == SLQOUTE){
            output_line[op] = DBLQOUTE;
            op = op + 1;
            ip = ip + 2;
            copy_text_until(input_line, output_line, 
                            &ip, &op,
                            input_file, output_file, 
                            SRQOUTE);
         }  /* ends second if SLQOUTE */
         else { /* else just 1 SLQOUTE */
            output_line[op++] = input_line[ip++];
         }  /* ends else just 1 SLQOUTE */
      }  /* ends case 3 */

      if(input_line[ip] == BACKSLASH){

            /* case 4 */
         if(input_line[ip+1] == '&'  ||
            input_line[ip+1] == '%'  ||
            input_line[ip+1] == '#'  ||
            input_line[ip+1] == '$'  ||
            input_line[ip+1] == '_'){
            case4 = 1;
            output_line[op] = input_line[ip+1];
            op++;
            if(input_line[ip+1] == '_')
               ip = ip + 4;  /* the _ case has a */
            else             /* \_{} ==> _       */
               ip = ip + 2;
         }  /* ends if case 4 */

            /* if you did case4, jump around cases 
               5.1 and 5.2 */

         if(case4 == 0){

            ip++;

            copy_word(input_line, &ip, latex_word);

               /* case 5.1 */
            if( (strcmp(latex_word, "begin") == 0)         ||
                (strcmp(latex_word, "end") == 0)           ||
                (strcmp(latex_word, "documentstyle") == 0) ||
                (strcmp(latex_word, "makefile") == 0)      ||
                (strcmp(latex_word, "tableofcontents") == 0)){
               output_line[op] = '\n';
               input_line[ip] = '\0';
            }  /* ends case 5.1 */

               /* case 5.2 */
            if( (strcmp(latex_word, "chapter") == 0)    ||
                (strcmp(latex_word, "section") == 0)    ||
                (strcmp(latex_word, "subsection") == 0) ||
                (strcmp(latex_word, "item") == 0)       ||
                (strcmp(latex_word, "title") == 0)      ||
                (strcmp(latex_word, "author") == 0)     ||
                (strcmp(latex_word, "date") == 0)){
               ip++; /* ip points to { so increment it */
               if(input_line[ip] == '{') ip++;
               copy_text_until(input_line, output_line, 
                               &ip, &op,
                               input_file, output_file, 
                               '}');
            }  /* ends case 5.2 */

         }  /* ends if case4 == 0 */

      }  /* ends if BACKSLASH */

   }  /* ends while input line is not null */

}  /* ends process_line */


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -