File: longline.c

package info (click to toggle)
csound 1%3A6.18.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 63,220 kB
  • sloc: ansic: 192,643; cpp: 14,149; javascript: 9,654; objc: 9,181; python: 3,376; java: 3,337; sh: 1,840; yacc: 1,255; xml: 985; perl: 635; lisp: 411; tcl: 341; lex: 217; makefile: 128
file content (67 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LIST "all_string_files"

void process(char *name, int width)
{
    FILE *ff = fopen(name, "r");
    char buffer[256];
    int count = 0;
    if (ff==NULL) {
      printf("File=%s does not exist\n", name);
      return;
    }
    while (1) {
      char *p;
      if (fgets(buffer, 255, ff)==NULL) break;
      count++;
      p = strchr(buffer, '\n');
      if (p==NULL || (p-buffer) > width) {
        printf("File=%s Line=%d long\n%s\n", name, count, buffer);
      }
      p = strchr(buffer, '\t');
      if (p!=NULL)
        printf("File=%s Line=%d TAB at %d\n%s\n", name, count, p-buffer, buffer);
      p = strstr(buffer, " \n");
      if (p!=NULL)
        printf("File=%s Line=%d extra space at %d\n%s\n",
               name, count, p-buffer, buffer);
      p = strstr(buffer,"if(");
      if (p!=NULL)
        printf("File=%s Line=%d if( at %d\n%s\n",
               name, count, p-buffer, buffer);
      p = strstr(buffer,"while(");
      if (p!=NULL)
        printf("File=%s Line=%d while( at %d\n%s\n",
               name, count, p-buffer, buffer);
      p = strstr(buffer,"for(");
      if (p!=NULL)
        printf("File=%s Line=%d for( at %d\n%s\n",
               name, count, p-buffer, buffer);
    }
    fclose(ff);
    return;
}

int main(int argc, char **argv)
{
    FILE *ff = fopen(LIST, "r");
    char buffer[128];
    int width = (argc==1 ? 85 : atoi(argv[1]));

    if (ff==NULL) {
      printf("No list of files\n");
      exit(1);
    }

    while (1) {
      char *p;
      if (fgets(buffer, 127, ff)==NULL) break;
      p = strchr(buffer, '\n');
      if (p) *p = '\0';
      process(buffer, width);
    }
    fclose(ff);
}